Automatic alias creation

(Krzysztof) #1

in our ELK cluster we have various systems sending their logs to ES. I the Logstash configuration we enforced that only events with some mandatory fileds (that allow to identify the source of an event) are passed to the ES index.
One of this fields is called "server".
I want to automatically create aliases named after server names, which will do nothing but filter the logs coming form a particular server

"filter": {
    "bool": {
        "must": [
                "term": {
                    "server": "sample_server_name"
            } ]

To do it, I wrote a small Python script, which I plan to run on a daily basis:

from elasticsearch import Elasticsearch
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])
res ="logstash-*", body={"size":0,"aggs":{"servers":{"terms":{"field":"server.raw"}}}})
for server in res['aggregations']['servers']['buckets']:
    if server["key"] and not server["key"].isspace():
        print("Creating alias for server: {}".format(server["key"]))

First question is if there is a simpler solution to achieve this.

Second question is, how to add these aliases as new index patterns in Kibana? Do I have to simulate from my script the sequence of GETs and POSTs which are normally performed when an index pattern is created?


(Mark Walkom) #2

As hackish as this may feel, I don't think there is a better way.

(system) #3