fix(core): update

This commit is contained in:
Philipp Kunz 2023-07-05 10:22:53 +02:00
parent b0cf4bb27f
commit ad24ba2f5d
3 changed files with 10 additions and 27 deletions

View File

@ -10,9 +10,9 @@ 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_DOMAIN'),
user: '',
pass: '',
});
expect(testElasticLog).toBeInstanceOf(elasticsearch.ElasticSearch);
});

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@apiclient.xyz/elasticsearch',
version: '1.0.39',
version: '1.0.40',
description: 'log to elasticsearch in a kibana compatible format'
}

View File

@ -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({
node: 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()}.${(