summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorNishanth Thomas <nthomas@redhat.com>2014-04-08 20:12:14 +0530
committerBala.FA <barumuga@redhat.com>2014-04-29 10:21:37 +0530
commitb40621bc3f1253adaa154428ddef758638b5d175 (patch)
tree9232b9b080ded9d4d2aeb37cec1c2a7ce24a8127 /plugins
parent644a9617c9d31a76c0b217950d53355d14b54daf (diff)
SNMP Trap Support : SNMP notification on status change
These plugins will generate SNMP traps when there is a host or service state change in Nagios. Plugged into the Nagios Notification mechanism and uses netsnmp utils to generate SNMP traps Addressed the review comments Change-Id: I42c4d1968a48bc80e767f6fbc24d1637a92d21b0 Signed-off-by: Nishanth Thomas <nthomas@redhat.com>
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Makefile.am2
-rwxr-xr-xplugins/hostsnmptrapgenerator.py.in109
-rwxr-xr-xplugins/servicesnmptrapgenerator.py.in108
3 files changed, 219 insertions, 0 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 9779c2d..39893e3 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -5,10 +5,12 @@ dist_glusternagiosplugins_PYTHON = \
check_remote_host.py \
check_vol_server.py \
gluster_host_service_handler.py \
+ hostsnmptrapgenerator.py \
livestatus.py \
notify_ovirt_engine_handler.py \
discovery.py \
config_generator.py \
+ servicesnmptrapgenerator.py \
$(NULL)
EXTRA_DIST = \
diff --git a/plugins/hostsnmptrapgenerator.py.in b/plugins/hostsnmptrapgenerator.py.in
new file mode 100755
index 0000000..b884974
--- /dev/null
+++ b/plugins/hostsnmptrapgenerator.py.in
@@ -0,0 +1,109 @@
+#!/usr/bin/python
+# hostsnmptrapgenerator.py.in -- nagios plugin for generating the
+#SNMP traps on host status change
+# Copyright (C) 2014 Red Hat Inc
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+#
+
+import argparse
+import commands
+
+from glusternagios import utils
+
+
+varbindlist = {'nHostNotifyType': ' nHostNotifyType i ',
+ 'nHostAckAuthor': ' nHostAckAuthor s ',
+ 'nHostAckComment': ' nHostAckComment s ',
+ 'nHostname': ' nHostname s ',
+ 'nHostStateID': ' nHostStateID i ',
+ 'nHostStateType': ' nHostStateType i ',
+ 'nHostAttempt': ' nHostAttempt i ',
+ 'nHostDurationSec': ' nHostDurationSec i ',
+ 'nHostGroupName': ' nHostGroupName s ',
+ 'nHostLastCheck': ' nHostLastCheck i ',
+ 'nHostLastChange': ' nHostLastChange i ',
+ 'nHostOutput': ' nHostOutput s '}
+
+
+def buildandsendsnmptrap(args):
+ command = ""
+ path = "@snmpmanagerlist@"
+ listofmanagers = utils.getsnmpmanagers(path)
+ for manager in listofmanagers:
+ command = utils.sudoCmdPath.cmd + " " \
+ + utils.trapCmdPath.cmd + " -v 2c -c "
+ command += manager['community'] + " " + manager['host'] + ''' '' ''' +\
+ "NAGIOS-NOTIFY-MIB::nHostNotify" +\
+ varbindlist['nHostNotifyType'] + args.nHostNotifyType + \
+ varbindlist['nHostname'] + args.nHostname +\
+ varbindlist['nHostStateID'] + args.nHostStateID +\
+ varbindlist['nHostStateType'] + args.nHostStateType +\
+ varbindlist['nHostAttempt'] + args.nHostAttempt +\
+ varbindlist['nHostDurationSec'] + args.nHostDurationSec +\
+ varbindlist['nHostGroupName'] + args.nHostGroupName +\
+ varbindlist['nHostLastCheck'] + args.nHostLastCheck +\
+ varbindlist['nHostLastChange'] + args.nHostLastChange +\
+ varbindlist['nHostOutput'] + args.nHostOutput
+ commands.getoutput(command)
+
+
+def parse_input():
+ parser = argparse.ArgumentParser(
+ usage='%(prog)s [-h] <nHostNotifyType> < nHostNotifyNum> '
+ '<nHostname> '
+ '<nHostStateID> <nHostStateType> <nHostAttempt> '
+ '< nHostDurationSec> <nHostGroupName> <nHostLastCheck> '
+ '<nHostLastChange> <nHostOutput>')
+ parser.add_argument("nHostNotifyType")
+ parser.add_argument("nHostNotifyNum")
+ parser.add_argument("nHostname")
+ parser.add_argument("nHostStateID")
+ parser.add_argument("nHostStateType")
+ parser.add_argument("nHostAttempt")
+ parser.add_argument("nHostDurationSec")
+ parser.add_argument("nHostGroupName")
+ parser.add_argument("nHostLastCheck")
+ parser.add_argument("nHostLastChange")
+ parser.add_argument("nHostOutput")
+
+ args = parser.parse_args()
+
+ return args
+
+
+def formatargs(args):
+ #convert nHostNotifyType to enum value
+ hostnotifytype = {'problem': '0',
+ 'recovery': '1',
+ 'acknowledgement': '2',
+ 'flappingstart': '3',
+ 'flappingstop': '4'}
+ args.nHostNotifyType = hostnotifytype[args.nHostNotifyType.lower()]
+ #convert nHostStateType to enum value
+ hoststatetype = {'hard': '0', 'soft': '1'}
+ args.nHostStateType = hoststatetype[args.nHostStateType.lower()]
+ #Add quotes to string parameters to handle
+ #parameters with multiple words separated with
+ #spaces
+ args.nHostname = '''"'''+args.nHostname+'''"'''
+ args.nHostGroupName = '''"'''+args.nHostGroupName+'''"'''
+ args.nHostOutput = '''"'''+args.nHostOutput+'''"'''
+
+
+if __name__ == '__main__':
+ args = parse_input()
+ formatargs(args)
+ buildandsendsnmptrap(args)
diff --git a/plugins/servicesnmptrapgenerator.py.in b/plugins/servicesnmptrapgenerator.py.in
new file mode 100755
index 0000000..1a4661f
--- /dev/null
+++ b/plugins/servicesnmptrapgenerator.py.in
@@ -0,0 +1,108 @@
+#!/usr/bin/python
+# servicesnmptrapgenerator.py.in -- nagios plugin for generating the
+#SNMP traps on service status change
+# Copyright (C) 2014 Red Hat Inc
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+#
+
+import argparse
+import commands
+
+from glusternagios import utils
+
+
+varbindlist = {'nSvcNotifyType': ' nSvcNotifyType i ',
+ 'nSvcNotifyNum': ' nSvcNotifyNum i ',
+ 'nHostname': ' nHostname s ',
+ 'nHostStateID': ' nHostStateID i ',
+ 'nSvcDesc': ' nSvcDesc s ',
+ 'nSvcStateID': ' nSvcStateID i ',
+ 'nSvcAttempt': ' nSvcAttempt i ',
+ 'nSvcDurationSec': ' nSvcDurationSec i ',
+ 'nSvcGroupName': ' nSvcGroupName s ',
+ 'nSvcLastCheck': ' nSvcLastCheck i ',
+ 'nSvcLastChange': ' nSvcLastChange i ',
+ 'nSvcOutput': ' nSvcOutput s '}
+
+
+def parse_input():
+ parser = argparse.ArgumentParser(
+ usage='%(prog)s [-h] <nSvcNotifyType> < nSvcNotifyNum> '
+ '<nHostname> '
+ '<nHostStateID> <nSvcDesc> <nSvcStateID> '
+ '<nSvcAttempt> <nSvcDurationSec> <nSvcGroupName> '
+ '<nSvcLastCheck> <nSvcLastChange> <nSvcOutput>')
+ parser.add_argument("nSvcNotifyType")
+ parser.add_argument("nSvcNotifyNum")
+ parser.add_argument("nHostname")
+ parser.add_argument("nHostStateID")
+ parser.add_argument("nSvcDesc")
+ parser.add_argument("nSvcStateID")
+ parser.add_argument("nSvcAttempt")
+ parser.add_argument("nSvcDurationSec")
+ parser.add_argument("nSvcGroupName")
+ parser.add_argument("nSvcLastCheck")
+ parser.add_argument("nSvcLastChange")
+ parser.add_argument("nSvcOutput")
+
+ args = parser.parse_args()
+
+ return args
+
+
+def buildandsendsnmptrap(args):
+ command = ""
+ path = "@snmpmanagerlist@"
+ listofmanagers = utils.getsnmpmanagers(path)
+ for manager in listofmanagers:
+ command = utils.sudoCmdPath.cmd + " " \
+ + utils.trapCmdPath.cmd + " -v 2c -c "
+ command += manager['community'] + " " + manager['host'] + ''' '' ''' +\
+ "NAGIOS-NOTIFY-MIB::nSvcNotify" +\
+ varbindlist['nSvcNotifyType'] + args.nSvcNotifyType + \
+ varbindlist['nHostname'] + args.nHostname +\
+ varbindlist['nHostStateID'] + args.nHostStateID +\
+ varbindlist['nSvcDesc'] + args.nSvcDesc +\
+ varbindlist['nSvcStateID'] + args.nSvcStateID +\
+ varbindlist['nSvcAttempt'] + args.nSvcAttempt +\
+ varbindlist['nSvcGroupName'] + args.nSvcGroupName +\
+ varbindlist['nSvcLastCheck'] + args.nSvcLastCheck +\
+ varbindlist['nSvcLastChange'] + args.nSvcLastChange +\
+ varbindlist['nSvcOutput'] + args.nSvcOutput
+ commands.getoutput(command)
+
+
+def formatargs(args):
+ #convert nSvcNotifyType to enum value
+ svcnotifytype = {'problem': '0',
+ 'recovery': '1',
+ 'acknowledgement': '2',
+ 'flappingstart': '3',
+ 'flappingstop': '4'}
+ args.nSvcNotifyType = svcnotifytype[args.nSvcNotifyType.lower()]
+ #Add quotes to string parameters to handle
+ #parameters with multiple words separated with
+ #spaces
+ args.nHostname = '''"'''+args.nHostname+'''"'''
+ args.nSvcDesc = '''"'''+args.nSvcDesc+'''"'''
+ args.nSvcGroupName = '''"'''+args.nSvcGroupName+'''"'''
+ args.nSvcOutput = '''"'''+args.nSvcOutput+'''"'''
+
+
+if __name__ == '__main__':
+ args = parse_input()
+ formatargs(args)
+ buildandsendsnmptrap(args)