Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
9c767d07e4 | |||
f3aa94dcb7 | |||
a0be0edd9d | |||
ad24ba2f5d | |||
b0cf4bb27f | |||
fd29ceab80 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiclient.xyz/elasticsearch",
|
||||
"version": "1.0.38",
|
||||
"version": "1.0.41",
|
||||
"private": false,
|
||||
"description": "log to elasticsearch in a kibana compatible format",
|
||||
"main": "dist_ts/index.js",
|
||||
@ -27,8 +27,7 @@
|
||||
"@pushrocks/smartdelay": "^3.0.1",
|
||||
"@pushrocks/smartlog-interfaces": "^3.0.0",
|
||||
"@pushrocks/smartpromise": "^4.0.2",
|
||||
"@pushrocks/smarttime": "^4.0.1",
|
||||
"@types/elasticsearch": "^5.0.40"
|
||||
"@pushrocks/smarttime": "^4.0.1"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
7
pnpm-lock.yaml
generated
7
pnpm-lock.yaml
generated
@ -23,9 +23,6 @@ dependencies:
|
||||
'@pushrocks/smarttime':
|
||||
specifier: ^4.0.1
|
||||
version: 4.0.1
|
||||
'@types/elasticsearch':
|
||||
specifier: ^5.0.40
|
||||
version: 5.0.40
|
||||
|
||||
devDependencies:
|
||||
'@gitzone/tsbuild':
|
||||
@ -1244,10 +1241,6 @@ packages:
|
||||
resolution: {integrity: sha512-tpu0hp+AOIzwdAHyZPzLE5pCf9uT0pb+xZ76T4S7MrY2YTVq918Q7Q2VQ3KCVQqYxM7nxuCK/SL3X97jBEIeKQ==}
|
||||
dev: true
|
||||
|
||||
/@types/elasticsearch@5.0.40:
|
||||
resolution: {integrity: sha512-lhnbkC0XorAD7Dt7X+94cXUSHEdDNnEVk/DgFLHgIZQNhixV631Lj4+KpXunTT5rCHyj9RqK3TfO7QrOiwEeUQ==}
|
||||
dev: false
|
||||
|
||||
/@types/express-serve-static-core@4.17.35:
|
||||
resolution: {integrity: sha512-wALWQwrgiB2AWTT91CB62b6Yt0sNHpznUXeZEcnPU3DRdlDIz74x8Qg1UUYKSVFi+va5vKOLYRBI1bRKiLLKIg==}
|
||||
dependencies:
|
||||
|
3
qenv.yml
3
qenv.yml
@ -1,5 +1,4 @@
|
||||
required:
|
||||
- ELK_DOMAIN
|
||||
- ELK_PORT
|
||||
- ELK_NODE
|
||||
- ELK_USER
|
||||
- ELK_PASS
|
@ -10,14 +10,14 @@ tap.test('first test', async () => {
|
||||
testElasticLog = new elasticsearch.ElasticSearch({
|
||||
indexPrefix: 'smartlog',
|
||||
indexRetention: 7,
|
||||
domain: testQenv.getEnvVarOnDemand('ELK_DOMAIN'),
|
||||
port: parseInt(testQenv.getEnvVarOnDemand('ELK_PORT'), 10),
|
||||
ssl: true,
|
||||
node: testQenv.getEnvVarOnDemand('ELK_NODE'),
|
||||
user: '',
|
||||
pass: '',
|
||||
});
|
||||
expect(testElasticLog).toBeInstanceOf(elasticsearch.ElasticSearch);
|
||||
});
|
||||
|
||||
tap.test('should send a message to Elasticsearch', async () => {
|
||||
tap.skip.test('should send a message to Elasticsearch', async () => {
|
||||
testElasticLog.log({
|
||||
timestamp: Date.now(),
|
||||
type: 'increment',
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiclient.xyz/elasticsearch',
|
||||
version: '1.0.38',
|
||||
version: '1.0.41',
|
||||
description: 'log to elasticsearch in a kibana compatible format'
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
// interfaces
|
||||
import { Client as ElasticClient } from 'elasticsearch';
|
||||
import { Client as ElasticClient } from '@elastic/elasticsearch';
|
||||
import type { ILogContext, ILogPackage, ILogDestination } from '@pushrocks/smartlog-interfaces';
|
||||
|
||||
// other classes
|
||||
@ -14,9 +14,7 @@ export interface IStandardLogParams {
|
||||
export interface IElasticSearchConstructorOptions {
|
||||
indexPrefix: string;
|
||||
indexRetention: number;
|
||||
port: number;
|
||||
domain: string;
|
||||
ssl: boolean;
|
||||
node: string;
|
||||
user?: string;
|
||||
pass?: string;
|
||||
}
|
||||
@ -35,31 +33,16 @@ export class ElasticSearch<T> {
|
||||
*/
|
||||
constructor(optionsArg: IElasticSearchConstructorOptions) {
|
||||
this.client = new ElasticClient({
|
||||
host: this.computeHostString(optionsArg),
|
||||
// log: 'trace'
|
||||
node: optionsArg.node,
|
||||
auth: {
|
||||
username: optionsArg.user,
|
||||
password: optionsArg.pass,
|
||||
}
|
||||
});
|
||||
this.indexPrefix = optionsArg.indexPrefix;
|
||||
this.indexRetention = optionsArg.indexRetention;
|
||||
}
|
||||
|
||||
/**
|
||||
* computes the host string from the constructor options
|
||||
* @param optionsArg
|
||||
*/
|
||||
private computeHostString(optionsArg: IElasticSearchConstructorOptions): string {
|
||||
let hostString = `${optionsArg.domain}:${optionsArg.port}`;
|
||||
if (optionsArg.user && optionsArg.pass) {
|
||||
hostString = `${optionsArg.user}:${optionsArg.pass}@${hostString}`;
|
||||
}
|
||||
if (optionsArg.ssl) {
|
||||
hostString = `https://${hostString}`;
|
||||
} else {
|
||||
hostString = `http://${hostString}`;
|
||||
}
|
||||
console.log(hostString);
|
||||
return hostString;
|
||||
}
|
||||
|
||||
public async log(logPackageArg: ILogPackage, scheduleOverwrite = false) {
|
||||
const now = new Date();
|
||||
const indexToUse = `${this.indexPrefix}-${now.getFullYear()}.${(
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as elasticsearch from 'elasticsearch';
|
||||
import * as elasticsearch from '@elastic/elasticsearch';
|
||||
import * as lik from '@pushrocks/lik';
|
||||
import * as smartdelay from '@pushrocks/smartdelay';
|
||||
import * as smartlogInterfaces from '@pushrocks/smartlog-interfaces';
|
||||
|
Reference in New Issue
Block a user