mirror of
https://github.com/VerosK/nagios-snmp-tortilla.git
synced 2024-11-22 02:13:48 +01:00
Imported plugin and basic configs
This commit is contained in:
parent
0416533c6a
commit
132b9a08a3
8
.gitignore
vendored
8
.gitignore
vendored
@ -33,3 +33,11 @@ nosetests.xml
|
|||||||
.mr.developer.cfg
|
.mr.developer.cfg
|
||||||
.project
|
.project
|
||||||
.pydevproject
|
.pydevproject
|
||||||
|
|
||||||
|
# VIM
|
||||||
|
.*.swp
|
||||||
|
.*.swo
|
||||||
|
|
||||||
|
# packages
|
||||||
|
*.rpm
|
||||||
|
*.deb
|
||||||
|
4
LICENSE
4
LICENSE
@ -1,4 +1,4 @@
|
|||||||
Copyright (c) 2013, Věroš Kaplan
|
Copyright (c) 2013, Veros Kaplan
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
@ -11,7 +11,7 @@ are permitted provided that the following conditions are met:
|
|||||||
list of conditions and the following disclaimer in the documentation and/or
|
list of conditions and the following disclaimer in the documentation and/or
|
||||||
other materials provided with the distribution.
|
other materials provided with the distribution.
|
||||||
|
|
||||||
Neither the name of the {organization} nor the names of its
|
Neither the name of the organization nor the names of its
|
||||||
contributors may be used to endorse or promote products derived from
|
contributors may be used to endorse or promote products derived from
|
||||||
this software without specific prior written permission.
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
10
README.md
10
README.md
@ -1,4 +1,12 @@
|
|||||||
nagios-snmp-tortilla
|
nagios-snmp-tortilla
|
||||||
====================
|
====================
|
||||||
|
|
||||||
Nagios SNMP plugin for dummies
|
Nagios/Icinga SNMP plugin for dummies (and/or lazy administrators).
|
||||||
|
|
||||||
|
This script contains prepackaged definitions of miscellaneous
|
||||||
|
hardware/software which can be modified by Nagios.
|
||||||
|
|
||||||
|
Just use:
|
||||||
|
$ check_snmp_tortilla -c config_file.ini -C community -H host_address
|
||||||
|
|
||||||
|
Feel free to send updates.
|
||||||
|
17
ini/apc-pdu-environment.ini
Normal file
17
ini/apc-pdu-environment.ini
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# APC PDU with SNMP - http://goo.gl/KkiEg2
|
||||||
|
#
|
||||||
|
# temperature, humidity
|
||||||
|
#
|
||||||
|
[value:temperature]
|
||||||
|
oid = .1.3.6.1.4.1.318.1.1.26.10.2.2.1.8.1
|
||||||
|
units = C
|
||||||
|
func = lambda x: float(x)/10
|
||||||
|
warning = temperature > 21
|
||||||
|
critical = temperature > 25
|
||||||
|
name = Teplota
|
||||||
|
|
||||||
|
[value:humidity]
|
||||||
|
oid = .1.3.6.1.4.1.318.1.1.26.10.2.2.1.10.1
|
||||||
|
units = %
|
||||||
|
warning = (humidity > 60)
|
||||||
|
|
12
ini/apc-pdu-temperature.ini
Normal file
12
ini/apc-pdu-temperature.ini
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
# APC PDU with SNMP - http://goo.gl/KkiEg2
|
||||||
|
#
|
||||||
|
# only temperature
|
||||||
|
#
|
||||||
|
[value:temperature]
|
||||||
|
oid = .1.3.6.1.4.1.318.1.1.26.10.2.2.1.8.1
|
||||||
|
units = C
|
||||||
|
func = lambda x: float(x)/10
|
||||||
|
warning = temperature > 21
|
||||||
|
critical = temperature > 25
|
||||||
|
name = Teplota
|
||||||
|
|
27
ini/apc-pdu.ini
Normal file
27
ini/apc-pdu.ini
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# APC PDU with SNMP - http://goo.gl/KkiEg2
|
||||||
|
#
|
||||||
|
# voltage, current and power
|
||||||
|
#
|
||||||
|
|
||||||
|
[value:current]
|
||||||
|
oid = .1.3.6.1.4.1.318.1.1.26.6.3.1.5.1
|
||||||
|
func = lambda x: float(x)/10
|
||||||
|
warning = current > 9
|
||||||
|
critical = current > 15
|
||||||
|
name = Current
|
||||||
|
units = A
|
||||||
|
|
||||||
|
[value:voltage]
|
||||||
|
oid = .1.3.6.1.4.1.318.1.1.26.6.3.1.6.1
|
||||||
|
warning = (voltage < 231) or (voltage > 232)
|
||||||
|
critical = (voltage < 229) or (voltage > 235)
|
||||||
|
units = V
|
||||||
|
name = Voltage
|
||||||
|
|
||||||
|
[value:power]
|
||||||
|
oid = .1.3.6.1.4.1.318.1.1.26.6.3.1.7.1
|
||||||
|
units = W
|
||||||
|
func = lambda x: float(x)*10
|
||||||
|
warning = (power > 1800)
|
||||||
|
critical = (power > 2000)
|
||||||
|
name = Power
|
48
make_packages_fpm
Executable file
48
make_packages_fpm
Executable file
@ -0,0 +1,48 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# prepare RPM a DEB packages using
|
||||||
|
# Effing Package Manager ( see https://github.com/jordansissel/fpm )
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
TARGET_DIR=/opt/nagios-plugins
|
||||||
|
PACKAGE_NAME=snmp-tortilla
|
||||||
|
TMPDIR=`mktemp -d /tmp/tmp.fpm.XXXXXXXXXX`
|
||||||
|
RELEASE=`date +%Y%m%d`
|
||||||
|
EPOCH=$[ $(date +%s ) - 1363388400 ]
|
||||||
|
|
||||||
|
mkdir ${TMPDIR}/bin
|
||||||
|
mkdir ${TMPDIR}/ini
|
||||||
|
mkdir ${TMPDIR}/cfg
|
||||||
|
cp -r src/check_snmp_tortilla ${TMPDIR}/bin/check_snmp_tortilla
|
||||||
|
cp -r ini/*.ini ${TMPDIR}/ini
|
||||||
|
for fname in ini/*.ini; do
|
||||||
|
base=$( basename $fname .ini )
|
||||||
|
cat > $TMPDIR/cfg/check-${base}.cfg <<EOF
|
||||||
|
# from $fname
|
||||||
|
define command {
|
||||||
|
command_name check-${base}
|
||||||
|
command_line $TARGET_DIR/$PACKAGE_NAME/bin/check_snmp_tortilla -c $TARGET_DIR/$PACKAGE_NAME/ini/$base.ini -H \$HOSTADDRESS\$ -C public
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
if ! which fpm; then # prepare fpm
|
||||||
|
module add fpm
|
||||||
|
fi
|
||||||
|
fpm -s dir -t rpm -C ${TMPDIR} --prefix ${TARGET_DIR}/${PACKAGE_NAME} \
|
||||||
|
-n ${PACKAGE_NAME} -v1 --iteration ${RELEASE} --epoch ${EPOCH} \
|
||||||
|
--license 3BSD -d python -d net-snmp-utils -d python-pysnmp -d python-pyasn1 -a all \
|
||||||
|
--url https://github.com/VerosK/nagios-snmp-tortilla \
|
||||||
|
--verbose \
|
||||||
|
bin ini cfg
|
||||||
|
|
||||||
|
fpm -s dir -t deb -C ${TMPDIR} --prefix ${TARGET_DIR}/${PACKAGE_NAME} \
|
||||||
|
-n ${PACKAGE_NAME} -v1 --iteration ${RELEASE} --epoch ${EPOCH} \
|
||||||
|
--license 3BSD -d python -d net-snmp-utils -a all -d python-pysnmp4-apps \
|
||||||
|
--url https://github.com/VerosK/nagios-snmp-tortilla \
|
||||||
|
--verbose \
|
||||||
|
bin ini cfg
|
||||||
|
|
||||||
|
rm -rf ${TMPDIR}
|
||||||
|
|
134
src/check_snmp_tortilla
Executable file
134
src/check_snmp_tortilla
Executable file
@ -0,0 +1,134 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import pysnmp
|
||||||
|
from ConfigParser import ConfigParser, NoOptionError
|
||||||
|
from optparse import OptionParser
|
||||||
|
|
||||||
|
import time
|
||||||
|
import string
|
||||||
|
|
||||||
|
OK = 0
|
||||||
|
WARNING = 1
|
||||||
|
CRITICAL = 2
|
||||||
|
UNKNOWN = 3
|
||||||
|
ERROR = 4
|
||||||
|
|
||||||
|
CONFIG = 'pdu.ini'
|
||||||
|
|
||||||
|
class Device(object):
|
||||||
|
def __init__(self, config, host, snmp_community='public'):
|
||||||
|
self.config = config
|
||||||
|
self.host = host
|
||||||
|
self.snmp_community = snmp_community
|
||||||
|
self.output = []
|
||||||
|
self.extra = []
|
||||||
|
|
||||||
|
def run_checks(self):
|
||||||
|
config = self.config
|
||||||
|
retv = OK
|
||||||
|
for i in config.sections():
|
||||||
|
if not i.startswith('value:'):
|
||||||
|
continue
|
||||||
|
value = i.split(':',1)[1]
|
||||||
|
retv = max(retv, self.check_value(value))
|
||||||
|
print '%s' % '; '.join(self.output),
|
||||||
|
if self.extra:
|
||||||
|
print '|',' '.join(self.extra)
|
||||||
|
return retv
|
||||||
|
|
||||||
|
def _config_get(self, section, key, default=None):
|
||||||
|
try:
|
||||||
|
return self.config.get(section, key)
|
||||||
|
except NoOptionError:
|
||||||
|
return default
|
||||||
|
|
||||||
|
def check_value(self, value):
|
||||||
|
config = self.config
|
||||||
|
config_get = self._config_get
|
||||||
|
section = 'value:%s' % value
|
||||||
|
oid = config.get(section, 'oid')
|
||||||
|
func = config_get(section, 'func', default=None)
|
||||||
|
if not func:
|
||||||
|
func = lambda x: x
|
||||||
|
else:
|
||||||
|
func = eval(func)
|
||||||
|
assert callable(func), func
|
||||||
|
units = config_get(section, 'units', '')
|
||||||
|
# obtain value and cook it
|
||||||
|
try:
|
||||||
|
raw_value = self._get_snmp_value(oid)
|
||||||
|
except ValueError:
|
||||||
|
self.output.append('%(value)s UNKNOWN' % locals())
|
||||||
|
return UNKNOWN
|
||||||
|
cooked = func(raw_value)
|
||||||
|
# check limits
|
||||||
|
is_warning = is_critical = False
|
||||||
|
warning = config_get(section, 'warning')
|
||||||
|
critical = config_get(section, 'critical')
|
||||||
|
variables = {value: cooked}
|
||||||
|
#
|
||||||
|
if critical:
|
||||||
|
is_critical = eval(critical, {}, variables)
|
||||||
|
if warning:
|
||||||
|
is_warning = eval(warning, {}, variables)
|
||||||
|
if is_critical:
|
||||||
|
retv = CRITICAL
|
||||||
|
elif is_warning:
|
||||||
|
retv = WARNING
|
||||||
|
else:
|
||||||
|
retv = OK
|
||||||
|
#
|
||||||
|
return_str = []
|
||||||
|
return_str.append('%(value)s = %(cooked)s %(units)s' % \
|
||||||
|
locals())
|
||||||
|
self.extra.append('%(value)s=%(cooked)s%(units)s' % \
|
||||||
|
locals())
|
||||||
|
if is_critical:
|
||||||
|
return_str.append('[CRITICAL %(critical)s]' % locals())
|
||||||
|
elif is_warning:
|
||||||
|
return_str.append('[WARNING %(warning)s]' % locals())
|
||||||
|
self.output.append(' '.join(return_str))
|
||||||
|
return retv
|
||||||
|
|
||||||
|
|
||||||
|
def _get_snmp_value(self, oid):
|
||||||
|
from pysnmp.entity.rfc3413.oneliner import cmdgen
|
||||||
|
from pysnmp.proto.api.v1 import ObjectIdentifier as OID
|
||||||
|
errorIndication, errorStatus, errorIndex, values \
|
||||||
|
= cmdgen.CommandGenerator().getCmd(
|
||||||
|
cmdgen.CommunityData(self.host, self.snmp_community, 0),
|
||||||
|
cmdgen.UdpTransportTarget((self.host, 161)),
|
||||||
|
OID(oid)
|
||||||
|
)
|
||||||
|
if errorIndication or errorStatus:
|
||||||
|
raise ValueError, errorIndication or errorStatus
|
||||||
|
assert len(values) == 1, values
|
||||||
|
return values[0][1]
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = OptionParser()
|
||||||
|
parser.add_option("-H", "--host", dest="host",
|
||||||
|
help="connect to HOSTNAME", metavar="HOSTNAME")
|
||||||
|
parser.add_option("-c", "--config-file", dest="config_file",
|
||||||
|
help="use config file")
|
||||||
|
parser.add_option("-C", "--community", dest="snmp_community",
|
||||||
|
metavar = 'SNMP_COMMUNITY',
|
||||||
|
default = 'public', help="SNMP community to use")
|
||||||
|
(options, args) = parser.parse_args()
|
||||||
|
if options.host is None:
|
||||||
|
print 'Error: Need to set HOSTNAME\n\n'
|
||||||
|
parser.print_help()
|
||||||
|
raise SystemExit(ERROR)
|
||||||
|
if options.config_file is None:
|
||||||
|
print 'Error: Need to set config file\n\n'
|
||||||
|
parser.print_help()
|
||||||
|
raise SystemExit(ERROR)
|
||||||
|
config = ConfigParser()
|
||||||
|
config.read([options.config_file])
|
||||||
|
test = Device(config=config, host=options.host,
|
||||||
|
snmp_community=options.snmp_community)
|
||||||
|
raise SystemExit, test.run_checks()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
Reference in New Issue
Block a user