slanatech/swagger-stats

change elk index

Closed this issue · 2 comments

I want to use different index!
well!
if change the


change to

 "template": "server-1-*",

ok?

or


app.use(swStats.getMiddleware({
    elasticsearch: "http://10.40.2.89:9200",
    elasticsearchIndex: "server-1-*"  // Configuration els index
}));

module.exports.supportedOptions = {

// swagger-stats supported options
module.exports.supportedOptions = {

    // ....
    // ElasticSearch URL. Enables storing of request response records in Elasticsearch.
    // Default is empty (disabled).
    elasticsearch: "elasticsearch",
    elasticsearchIndex: "api-*", // elk default index

   //...

};

swsElasticEmitter.prototype.initialize = function (swsOptions) {

// Initialize
swsElasticEmitter.prototype.initialize = function(swsOptions) {

    if (typeof swsOptions === 'undefined') return;
    if (!swsOptions) return;

    this.options = swsOptions;

    // Set or detect hostname
    if (!(swsUtil.supportedOptions.elasticsearch in swsOptions)) {
        debug('Elasticsearch is disabled');
        return;
    }
    if (this.options.elasticsearchIndex) {
        indexTemplate.template = this.options.elasticsearchIndex
    }

   //......

};

swsElasticEmitter.prototype.processRecord = function(rrr){

// Index Request Response Record
swsElasticEmitter.prototype.processRecord = function(rrr) {

    //...
    // Create metadata
    var indexName = this.options.elasticsearchIndex + moment(rrr['@timestamp']).utc().format('YYYY.MM.DD');
    var meta = { index: { _index: indexName, _type: this.options.elasticsearchIndex, _id: rrr.id } };
    // console.log(indexTemplate)
    // Add to buffer
    // .....
};

it is ok?

sv2 commented

Looks right, thanks ! Will add soon

sv2 commented

new option elasticsearchIndexPrefix is added. Use this option to specify desired index prefix, for example:

        // Enable swagger-stats middleware
        app.use(swStats.getMiddleware({
            name: 'swagger-stats-testapp',
            version: '0.95.6',
            timelineBucketDuration: tlBucket,
            uriPath: '/swagger-stats',
            swaggerSpec:swaggerSpec,
            elasticsearch:'http://127.0.0.1:9200',
            elasticsearchIndexPrefix:'swagger-stats-',
            onResponseFinish: function(req,res,rrr){
                debug('onResponseFinish: %s', JSON.stringify(rrr));
            }
        }));