Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# elastizabbix
Down and dirty elastic / elasticsearch monitoring plugin for zabbix

> Forked from: https://github.com/mkhpalm/elastizabbix

## Features:

- Stats cache to avoid saturating nodes with monitoring requests
Expand All @@ -11,20 +13,23 @@ Down and dirty elastic / elasticsearch monitoring plugin for zabbix
## Requirements

- Python 2/3 on an elastic node with zabbix agent installed
- or you can install on your Zabbix server and set up the remote URL to be monitored

## Installation

This only needs to be setup on one of the elasticsearch nodes
This only needs to be setup on one of the elasticsearch nodes or on the Zabbix server

#### Zabbix Agent

- Copy elastizabbix to agent scripts folder
- Copy elastizabbix.conf to conf.d or add UserParameter to your agent config
- Restart the Zabbix Agent

#### Zabbix Frontend

- Import the XML template (supports zabbix 2.4 and greater)
- Import the XML template (tested on Zabbix 3.0)
- Add node to the newly imported template
- Change the node macro `{$ES.CLUSTER.URL}` to your cluster address `http://localhost:9200`

## The MIT License (MIT)

Expand Down
40 changes: 29 additions & 11 deletions agent/elastizabbix
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,30 @@ import json
import urllib2
import time
import errno
import hashlib

if len(sys.argv[1:]) != 3:
print 'ZBX_NOTSUPPORTED'
sys.exit(1)

ttl = 60

stats = {
'cluster': 'http://localhost:9200/_cluster/stats',
'nodes' : 'http://localhost:9200/_nodes/stats',
'indices': 'http://localhost:9200/_stats',
'health' : 'http://localhost:9200/_cluster/health'
'cluster': sys.argv[3]+'/_cluster/stats',
'nodes' : sys.argv[3]+'/_nodes/stats',
'indices': sys.argv[3]+'/_stats',
'health' : sys.argv[3]+'/_cluster/health'
}

def exception_handler(exception_type, exception, traceback, debug_hook=sys.excepthook):
if sys.argv[2] == 'reachable':
print '0'
else:
#print "%s: %s" % (exception_type.__name__, exception)
print 'ZBX_NOTSUPPORTED'

sys.excepthook = exception_handler

def created_file(name):
try:
fd = os.open(name, os.O_WRONLY | os.O_CREAT | os.O_EXCL)
Expand All @@ -30,26 +44,27 @@ def is_older_then(name, ttl):
return age > ttl

def get_cache(api):
cache = '/tmp/elastizabbix-{0}.json'.format(api)
lock = '/tmp/elastizabbix-{0}.lock'.format(api)
md5digest = hashlib.md5(sys.argv[3]).hexdigest()
cache = '/tmp/elastizabbix-'+md5digest+'-{0}.json'.format(api)
lock = '/tmp/elastizabbix-'+md5digest+'-{0}.lock'.format(api)
should_update = (not os.path.exists(cache)) or is_older_then(cache, ttl)
if should_update and created_file(lock):
try:
d = urllib2.urlopen(stats[api]).read()
with open(cache, 'w') as f: f.write(d)
except Exception as e:
pass
pass
if os.path.exists(lock):
os.remove(lock)
if os.path.exists(lock) and is_older_then(lock, 300):
os.remove(lock)
ret_data = {}
try:
with open(cache) as data_file:
ret_data = json.load(data_file)
with open(cache) as data_file:
ret_data = json.load(data_file)
except Exception as e:
ret_data = json.loads(urllib2.urlopen(stats[api]).read())
return ret_data
return ret_data

def get_stat(api, stat):
d = get_cache(api)
Expand Down Expand Up @@ -87,6 +102,9 @@ if __name__ == '__main__':
else:
stat = get_stat(api, stat)
if isinstance(stat, dict):
print ''
if sys.argv[2] == 'reachable':
print '1'
else:
print 'ZBX_NOTSUPPORTED'
else:
print stat
2 changes: 1 addition & 1 deletion agent/elastizabbix.conf
Original file line number Diff line number Diff line change
@@ -1 +1 @@
UserParameter=elastizabbix[*],/etc/zabbix/externalscripts/elastizabbix $1 $2
UserParameter=elastizabbix[*],/etc/zabbix/externalscripts/elastizabbix $1 $2 $3
Loading