Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

Commit

Permalink
Add traceback handler to the plugin and fix dictionnary for states.
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbrozer committed Jan 4, 2011
1 parent 2e9f689 commit 5a1fed4
Showing 1 changed file with 41 additions and 37 deletions.
78 changes: 41 additions & 37 deletions check_cisco_hsrp.py
@@ -1,11 +1,9 @@
#!/usr/local/bin/python2.6 -O
#!/usr/local/bin/python2.6
# -*- coding: UTF-8 -*-
#
#===============================================================================
# Name : check_cisco_hsrp.py
# Author : Vincent BESANCON aka 'v!nZ' <elguapito@free.fr>
# Version : $Revision$
# Last Modified : $Date$
# License : Creative Commons Attribution-Noncommercial-Share Alike 2.0 France
# Description : Check HSRP on Cisco devices. Check if the router must be the
# active or standby router for VLANs.
Expand All @@ -21,16 +19,16 @@
# 94105, USA.
#===============================================================================

import os, sys
import os, sys, traceback

from nagios.plugin.snmp import NagiosPluginSNMP

# Specific class for this plugin
class CheckCiscoHSRP(NagiosPluginSNMP):
def __init__(self, name, version, description):
super(CheckCiscoHSRP, self).__init__(name, version, description)
self.roleid = {'active': 6, 'standby': 5}
self.rolename = {6: 'active', 5: 'standby'}
self.roleid = {'initial': 1, 'learn': 2, 'listen': 3, 'speak': 4, 'standby': 5, 'active': 6}
self.rolename = {1: 'initial', 2: 'learn', 3: 'listen', 4: 'speak', 5: 'standby', 6: 'active'}

def setPluginArguments(self):
'''Define arguments for the plugin'''
Expand All @@ -51,37 +49,43 @@ def checkPluginArguments(self):

# The main procedure
if __name__ == '__main__':
progname = os.path.basename(sys.argv[0])
progdesc = 'Check HSRP on Cisco devices. Check if the router must be the active or standby router for VLANs.'
progversion = '$Revision: 1 $'

plugin = CheckCiscoHSRP(progname, progversion, progdesc)

oid_hsrp_states = '1.3.6.1.4.1.9.9.106.1.2.1.1.15'
oid_if_descr = '1.3.6.1.2.1.2.2.1.2'
try:
progname = os.path.basename(sys.argv[0])
progdesc = 'Check HSRP on Cisco devices. Check if the router must be the active or standby router for VLANs.'
progversion = '$Revision: 1 $'

plugin = CheckCiscoHSRP(progname, progversion, progdesc)

oid_hsrp_states = '1.3.6.1.4.1.9.9.106.1.2.1.1.15'
oid_if_descr = '1.3.6.1.2.1.2.2.1.2'

hsrp_states = plugin.queryNextSnmpOid(oid_hsrp_states)
hsrp_states = plugin.queryNextSnmpOid(oid_hsrp_states)

# Checking state of HSRP for all interfaces
longoutput = ""
output = ""
exit_code = 0
nbr_error = 0
for state in hsrp_states:
ifIndex = state[0][-2]
ifDescr = plugin.querySnmpOid('%s.%s' % (oid_if_descr, ifIndex))
# Checking state of HSRP for all interfaces
longoutput = ""
output = ""
exit_code = 0
nbr_error = 0
for state in hsrp_states:
ifIndex = state[0][-2]
ifDescr = plugin.querySnmpOid('%s.%s' % (oid_if_descr, ifIndex))

if state[1] != plugin.roleid[plugin.params.role]:
longoutput += '** %s is %s (must be %s) **\n' % (ifDescr[1], plugin.rolename[state[1]], plugin.params.role)
nbr_error+=1
exit_code = 1
else:
longoutput += '%s is %s\n' % (ifDescr[1], plugin.params.role)

longoutput = longoutput.rstrip('\n')
if exit_code == 1:
output = '%d HRSP interface error !\n' % nbr_error
plugin.warning(output + longoutput)
elif exit_code == 0:
output = 'Role for HSRP is %s.\n' % plugin.params.role
plugin.ok(output + longoutput)
if state[1] != plugin.roleid[plugin.params.role]:
longoutput += '** %s is in state %s (must be %s) **\n' % (ifDescr[1], plugin.rolename[state[1]], plugin.params.role)
nbr_error+=1
exit_code = 1
else:
longoutput += '%s is in state %s\n' % (ifDescr[1], plugin.params.role)

longoutput = longoutput.rstrip('\n')
if exit_code == 1:
output = '%d HRSP interface error !\n' % nbr_error
plugin.warning(output + longoutput)
elif exit_code == 0:
output = 'Role for HSRP is %s.\n' % plugin.params.role
plugin.ok(output + longoutput)
except Exception as e:
print "Arrrgh... exception occured ! Please contact DL-ITOP-MONITORING."
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback, limit=2, file=sys.stdout)
raise SystemExit(3)

0 comments on commit 5a1fed4

Please sign in to comment.