Added NTP template, updates, new memcached.trap.py

This commit is contained in:
Eric Renfro 2013-07-15 11:17:26 -04:00
parent db47e1d472
commit b49d28ecf3
3 changed files with 274 additions and 0 deletions

125
scripts/memcached.trap.py Executable file
View file

@ -0,0 +1,125 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
from subprocess import call
from telnetlib import Telnet
from tempfile import NamedTemporaryFile
# memcached server to check
MEMCACHED_SERVER = '127.0.0.1'
MEMCACHED_PORT = 11211
# containing zabbix_sender configuration
ZABBIX_CONFIG = '/etc/zabbix/zabbix_sender.conf'
LOGFILE = '/tmp/zabbix_memcached.log'
ITEMS = (
'bytes',
'cmd_get',
'cmd_set',
'curr_items',
'curr_connections',
'limit_maxbytes',
'uptime',
'get_hits',
'get_misses',
)
########################################################################
class Item(object):
"""Simple data container"""
#----------------------------------------------------------------------
def __init__(self, key, value):
self.key = key
self.value = value
########################################################################
class MemcachedStatsReader(object):
""""""
#----------------------------------------------------------------------
def __init__(self, server, port):
self._server = server
self._port = port
self._stats_raw = None
self._stats = None
#----------------------------------------------------------------------
def read(self):
self._read_stats()
self._parse_stats()
return self._stats
#----------------------------------------------------------------------
def _read_stats(self):
connection = Telnet(self._server, self._port)
connection.write('stats\n')
connection.write('quit\n')
self._stats_raw = connection.read_all()
#----------------------------------------------------------------------
def _parse_stats(self):
self._stats = list()
for line in self._stats_raw.splitlines():
if not line.startswith('STAT'):
continue
parts = line.split()
if not parts[1] in ITEMS:
continue
item = Item(parts[1], parts[2])
self._stats.append(item)
########################################################################
class ZabbixSender(object):
""""""
#----------------------------------------------------------------------
def __init__(self, config, logfile):
self._config = config
self._logfile = logfile
self._tempfile = None
#----------------------------------------------------------------------
def send(self, stats):
self._print_items
#self._write_temporary_file(stats)
#self._send_data_to_zabbix()
def _print_items(self, stats):
for item in stats:
print "- memcached[%s] %s\n" % (item.key, item.value)
#----------------------------------------------------------------------
def _write_temporary_file(self, stats):
self._tempfile = NamedTemporaryFile()
for item in stats:
self._tempfile.write(u'- memcached[%s] %s\n' % (item.key, item.value))
self._tempfile.flush()
#----------------------------------------------------------------------
def _send_data_to_zabbix(self):
cmd = [u'zabbix_sender', u'-c', self._config, u'-i', self._tempfile.name]
logfile = open(self._logfile, 'a')
call(cmd, stdout=logfile)
logfile.close()
self._tempfile.close()
#----------------------------------------------------------------------
def main():
reader = MemcachedStatsReader(MEMCACHED_SERVER, MEMCACHED_PORT)
items = reader.read()
sender = ZabbixSender(ZABBIX_CONFIG, LOGFILE)
sender.send(items)
if __name__ == '__main__':
main()

149
templates/Template_NTP.xml Normal file
View file

@ -0,0 +1,149 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>2013-07-15T14:45:14Z</date>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<templates>
<template>
<template>Template NTP</template>
<name>Template NTP</name>
<groups>
<group>
<name>Templates</name>
</group>
</groups>
<applications>
<application>
<name>NTP</name>
</application>
</applications>
<items>
<item>
<name>NTP Offset</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>ntp.offset</key>
<delay>0</delay>
<history>30</history>
<trends>90</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>NTP</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>NTP Peers</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>ntp.peers</key>
<delay>0</delay>
<history>30</history>
<trends>90</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>NTP</name>
</application>
</applications>
<valuemap/>
</item>
<item>
<name>NTP Stratum</name>
<type>2</type>
<snmp_community/>
<multiplier>0</multiplier>
<snmp_oid/>
<key>ntp.stratum</key>
<delay>0</delay>
<history>30</history>
<trends>90</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<delta>0</delta>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authpassphrase/>
<snmpv3_privpassphrase/>
<formula>1</formula>
<delay_flex/>
<params/>
<ipmi_sensor/>
<data_type>0</data_type>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications>
<application>
<name>NTP</name>
</application>
</applications>
<valuemap/>
</item>
</items>
<discovery_rules/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
</zabbix_export>