Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
9c767d07e4 | |||
f3aa94dcb7 | |||
a0be0edd9d | |||
ad24ba2f5d |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@apiclient.xyz/elasticsearch",
|
||||
"version": "1.0.39",
|
||||
"version": "1.0.41",
|
||||
"private": false,
|
||||
"description": "log to elasticsearch in a kibana compatible format",
|
||||
"main": "dist_ts/index.js",
|
||||
|
3
qenv.yml
3
qenv.yml
@ -1,5 +1,4 @@
|
||||
required:
|
||||
- ELK_DOMAIN
|
||||
- ELK_PORT
|
||||
- ELK_NODE
|
||||
- ELK_USER
|
||||
- ELK_PASS
|
@ -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_NODE'),
|
||||
user: '',
|
||||
pass: '',
|
||||
});
|
||||
expect(testElasticLog).toBeInstanceOf(elasticsearch.ElasticSearch);
|
||||
});
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@apiclient.xyz/elasticsearch',
|
||||
version: '1.0.39',
|
||||
version: '1.0.41',
|
||||
description: 'log to elasticsearch in a kibana compatible format'
|
||||
}
|
||||
|
@ -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()}.${(
|
||||
|
Reference in New Issue
Block a user