]> git.uio.no Git - uio-zabbix.git/blame - zabbix_logstash_autodiscovery.py
Bugfix: Fix at logstash autodiscovery returnerer en pipeline som har blitt deaktivert...
[uio-zabbix.git] / zabbix_logstash_autodiscovery.py
CommitLineData
5a8e85a8
RM
1#!/usr/bin/env python
2#
3# Authors:
4# rafael@E-MC2.NET / https://e-mc2.net/
5#
6# Copyright (c) 2018 USIT-University of Oslo
7#
8# zabbix_logstash_autodiscovery.py is free software: you can
9# redistribute it and/or modify it under the terms of the GNU General
10# Public License as published by the Free Software Foundation, either
11# version 3 of the License, or (at your option) any later version.
12#
13# zabbix_logstash_autodiscovery.py is distributed in the hope that it
14# will be useful, but WITHOUT ANY WARRANTY; without even the implied
15# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16# See the GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with sms_send. If not, see <http://www.gnu.org/licenses/>.
20#
21
22import requests
23import json
24import sys
25import os
26
27
28# ############################################
29# get_logstash_stats_data()
30# ############################################
31
32def get_logstash_stats_data():
33 """
34 Get logstash stats data
35 """
36
37 try:
38 request_data = requests.get("http://localhost:9600/_node/stats")
39
40 if request_data.status_code != 200:
41 raise Exception("[ERROR]: Problems connecting to logstash stats API\n")
42
43 stats_data = request_data.json()
44
45 return stats_data
46
47 except Exception as e:
48 raise Exception("[ERROR]: %s\n" % e)
49
50
51# ############################################
52# generate_zabbix_autodiscovery()
53# ############################################
54
55def generate_zabbix_autodiscovery(stats):
56
57 try:
58
59 pipelines_list = []
60
61 for pipeline in stats['pipelines']:
62
153b63e3
RM
63 if stats['pipelines'][pipeline]['events'] != None:
64 pipelines = {"{#PIPELINE}": pipeline}
65 pipelines_list.append(pipelines)
5a8e85a8
RM
66
67 result = {"data":pipelines_list}
68 print json.dumps(result,sort_keys=True,indent=2)
69
70 except Exception as e:
71 raise Exception("[ERROR]: %s\n" % e)
72
73
74if __name__ == '__main__':
75
76 try:
77
78 stats = get_logstash_stats_data()
79 generate_zabbix_autodiscovery(stats)
80
81 except Exception, e:
82 print e
83 sys.exit(1)