Compare commits

...

2 Commits

Author SHA1 Message Date
1ab582db51 1.0.25 2018-11-26 12:24:38 +01:00
9c87f5ee5e fix(core): update 2018-11-26 12:24:37 +01:00
3 changed files with 58 additions and 41 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/elasticsearch", "name": "@mojoio/elasticsearch",
"version": "1.0.24", "version": "1.0.25",
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {

View File

@ -1,6 +1,6 @@
{ {
"name": "@mojoio/elasticsearch", "name": "@mojoio/elasticsearch",
"version": "1.0.24", "version": "1.0.25",
"private": false, "private": false,
"description": "log to elasticsearch in a kibana compatible format", "description": "log to elasticsearch in a kibana compatible format",
"main": "dist/index.js", "main": "dist/index.js",

View File

@ -23,20 +23,62 @@ export class ElasticIndex {
format: 'json', format: 'json',
bytes: 'm' bytes: 'm'
}, },
async (err, response: any[]) => { async (err, responseArg: any[]) => {
if(err) {
console.log(err);
return;
}
// lets delete indexes that violate the retention // lets delete indexes that violate the retention
const filteredIndices = response.filter(indexObjectArg => { if(Array.isArray(responseArg)) {
const filteredIndices = responseArg.filter(indexObjectArg => {
return indexObjectArg.index.startsWith('smartlog'); return indexObjectArg.index.startsWith('smartlog');
}); });
const filteredIndexNames = filteredIndices.map(indexObjectArg => { const filteredIndexNames = filteredIndices.map(indexObjectArg => {
return indexObjectArg.index; return indexObjectArg.index;
}); });
this.deleteOldIndices(filteredIndexNames);
}
let index = null;
if(Array.isArray(responseArg)) {
index = responseArg.find(indexObject => {
return indexObject.index === indexArg;
});
}
if (!index) {
const done2 = plugins.smartpromise.defer();
this.elasticSearchRef.client.indices.create(
{
waitForActiveShards: '2',
index: indexArg
},
(error, response) => {
// console.lof(response)
done2.resolve();
}
);
await done2.promise;
}
this.stringmap.addString(indexArg);
done.resolve();
}
);
await done.promise;
}
public createNewIndex(indexNameArg: string) {
}
public async deleteOldIndices(indicesArray: string[]) {
const todayAsUnix: number = Date.now(); const todayAsUnix: number = Date.now();
const rententionPeriodAsUnix: number = plugins.smarttime.units.days( const rententionPeriodAsUnix: number = plugins.smarttime.units.days(
this.elasticSearchRef.indexRetention this.elasticSearchRef.indexRetention
); );
console.log(filteredIndexNames); for (const indexName of indicesArray) {
for (const indexName of filteredIndexNames) {
const regexResult = /^smartlog-([0-9]*)\.([0-9]*)\.([0-9]*)$/.exec(indexName); const regexResult = /^smartlog-([0-9]*)\.([0-9]*)\.([0-9]*)$/.exec(indexName);
const dateAsUnix: number = new Date( const dateAsUnix: number = new Date(
`${regexResult[1]}-${regexResult[2]}-${regexResult[3]}` `${regexResult[1]}-${regexResult[2]}-${regexResult[3]}`
@ -59,30 +101,5 @@ export class ElasticIndex {
await done2.promise; await done2.promise;
} }
} }
// console.log(response);
const index = response.find(indexObject => {
return indexObject.index === indexArg;
});
if (!index) {
const done2 = plugins.smartpromise.defer();
this.elasticSearchRef.client.indices.create(
{
waitForActiveShards: '2',
index: indexArg
},
(error, response) => {
// console.lof(response)
done2.resolve();
}
);
await done2.promise;
}
this.stringmap.addString(indexArg);
done.resolve();
}
);
await done.promise;
} }
} }