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 all plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
bigbrozer committed Jan 4, 2011
1 parent 5a1fed4 commit bc0493f
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 265 deletions.
68 changes: 37 additions & 31 deletions check_cisco_config.py
Expand Up @@ -21,7 +21,7 @@
# 94105, USA.
#===============================================================================
#
import os, sys
import os, sys, traceback
from time import strftime, localtime, time

from nagios.plugin.snmp import NagiosPluginSNMP
Expand All @@ -47,34 +47,40 @@ def checkPluginArguments(self):

# The main procedure
if __name__ == '__main__':
progname = os.path.basename(sys.argv[0])
progdesc = 'Check config last change and last saved date time.'
progversion = '$Revision: 1 $'

plugin = CheckCiscoConfig(progname, progversion, progdesc)

oid_uptime = '1.3.6.1.2.1.1.3.0'
oid_config_last_changed = '1.3.6.1.4.1.9.9.43.1.1.1.0'
oid_config_last_saved = '1.3.6.1.4.1.9.9.43.1.1.2.0'
try:
progname = os.path.basename(sys.argv[0])
progdesc = 'Check config last change and last saved date time.'
progversion = '$Revision: 1 $'

uptime = plugin.querySnmpOid(oid_uptime)
config_last_changed = plugin.querySnmpOid(oid_config_last_changed)
config_last_saved = plugin.querySnmpOid(oid_config_last_saved)

# Date calculations
delta_time_changed = (long(uptime[1]) - long(config_last_changed[1])) / 100
delta_time_saved = (long(uptime[1]) - long(config_last_saved[1])) / 100

config_last_changed_date = strftime('%d/%m/%Y %H:%M', localtime(time()-delta_time_changed))
config_last_saved_date = strftime('%d/%m/%Y %H:%M', localtime(time()-delta_time_saved))

# Formating output
longoutput = 'Config last changed: %s\nConfig last saved: %s' % (config_last_changed_date, config_last_saved_date)

# Checking state of config date
if config_last_changed[1] > config_last_saved[1]:
output = 'Config was changed without saving on %s !\n' % config_last_changed_date
plugin.warning(output + longoutput)
else:
output = 'Running configuration was saved on %s.\n' % config_last_saved_date
plugin.ok(output + longoutput)
plugin = CheckCiscoConfig(progname, progversion, progdesc)

oid_uptime = '1.3.6.1.2.1.1.3.0'
oid_config_last_changed = '1.3.6.1.4.1.9.9.43.1.1.1.0'
oid_config_last_saved = '1.3.6.1.4.1.9.9.43.1.1.2.0'

uptime = plugin.querySnmpOid(oid_uptime)
config_last_changed = plugin.querySnmpOid(oid_config_last_changed)
config_last_saved = plugin.querySnmpOid(oid_config_last_saved)

# Date calculations
delta_time_changed = (long(uptime[1]) - long(config_last_changed[1])) / 100
delta_time_saved = (long(uptime[1]) - long(config_last_saved[1])) / 100

config_last_changed_date = strftime('%d/%m/%Y %H:%M', localtime(time()-delta_time_changed))
config_last_saved_date = strftime('%d/%m/%Y %H:%M', localtime(time()-delta_time_saved))

# Formating output
longoutput = 'Config last changed: %s\nConfig last saved: %s' % (config_last_changed_date, config_last_saved_date)

# Checking state of config date
if config_last_changed[1] > config_last_saved[1]:
output = 'Config was changed without saving on %s !\n' % config_last_changed_date
plugin.warning(output + longoutput)
else:
output = 'Running configuration was saved on %s.\n' % config_last_saved_date
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)
120 changes: 63 additions & 57 deletions check_cisco_cpu.py
Expand Up @@ -21,7 +21,7 @@
#===============================================================================
#
#
import os, sys
import os, sys, traceback

from nagios.plugin.snmp import NagiosPluginSNMP

Expand Down Expand Up @@ -50,64 +50,70 @@ def checkPluginArguments(self):

# The main procedure
if __name__ == '__main__':
progname = os.path.basename(sys.argv[0])
progdesc = 'Check all CPUs usage on Cisco devices supporting CISCO-PROCESS-MIB.'
progversion = '$Revision: 1 $'

plugin = CheckCiscoCPU(progname, progversion, progdesc)

oid_entity_name = '1.3.6.1.2.1.47.1.1.1.1.7'
oid_cpu_indexes = '1.3.6.1.4.1.9.9.109.1.1.1.1.2'
oid_cpu_usages = '1.3.6.1.4.1.9.9.109.1.1.1.1.8'
try:
progname = os.path.basename(sys.argv[0])
progdesc = 'Check all CPUs usage on Cisco devices supporting CISCO-PROCESS-MIB.'
progversion = '$Revision: 1 $'

cpu_indexes = plugin.queryNextSnmpOid(oid_cpu_indexes)
cpu_usages = plugin.queryNextSnmpOid(oid_cpu_usages)

cpu_data = {}
for i in range(0, len(cpu_indexes)):
cpu_name = str(plugin.querySnmpOid('%s.%s' % (oid_entity_name, cpu_indexes[i][1]))[1])

# Test if there is a description, if not generate one
if len(cpu_name) == 0:
cpu_name = 'CPU%d' % i
plugin = CheckCiscoCPU(progname, progversion, progdesc)

oid_entity_name = '1.3.6.1.2.1.47.1.1.1.1.7'
oid_cpu_indexes = '1.3.6.1.4.1.9.9.109.1.1.1.1.2'
oid_cpu_usages = '1.3.6.1.4.1.9.9.109.1.1.1.1.8'

cpu_indexes = plugin.queryNextSnmpOid(oid_cpu_indexes)
cpu_usages = plugin.queryNextSnmpOid(oid_cpu_usages)

cpu_data = {}
for i in range(0, len(cpu_indexes)):
cpu_name = str(plugin.querySnmpOid('%s.%s' % (oid_entity_name, cpu_indexes[i][1]))[1])

# Test if there is a description, if not generate one
if len(cpu_name) == 0:
cpu_name = 'CPU%d' % i

cpu_data[cpu_name] = int(cpu_usages[i][1])

cpu_data[cpu_name] = int(cpu_usages[i][1])

# Checking values if in thresholds and formatting output
output = ""
longoutput = ""
exit_code = 0
nbr_error = 0
i = 1
for cpu in cpu_data:
if plugin.params.warnthr < cpu_data[cpu] < plugin.params.critthr:
longoutput += '* %s: %d%% * (>%d)\n' % (cpu, cpu_data[cpu], plugin.params.warnthr)
if exit_code != 2: exit_code = 1
nbr_error+=1
elif cpu_data[cpu] > plugin.params.critthr:
longoutput += '** %s: %d%% ** (>%d)\n' % (cpu, cpu_data[cpu], plugin.params.critthr)
exit_code = 2
nbr_error+=1
elif cpu_data[cpu] < plugin.params.warnthr:
longoutput += '%s: %d%% (<%d)\n' % (cpu, cpu_data[cpu], plugin.params.warnthr)

# Checking values if in thresholds and formatting output
output = ""
longoutput = ""
exit_code = 0
nbr_error = 0
i = 1
for cpu in cpu_data:
if plugin.params.warnthr < cpu_data[cpu] < plugin.params.critthr:
longoutput += '* %s: %d%% * (>%d)\n' % (cpu, cpu_data[cpu], plugin.params.warnthr)
if exit_code != 2: exit_code = 1
nbr_error+=1
elif cpu_data[cpu] > plugin.params.critthr:
longoutput += '** %s: %d%% ** (>%d)\n' % (cpu, cpu_data[cpu], plugin.params.critthr)
exit_code = 2
nbr_error+=1
elif cpu_data[cpu] < plugin.params.warnthr:
longoutput += '%s: %d%% (<%d)\n' % (cpu, cpu_data[cpu], plugin.params.warnthr)

# Formatting perfdata
perfdata = " | "
for cpu in cpu_data:
perfdata += '%s=%d%%;%d;%d;0;100 ' % (cpu.replace(' ', '_'), cpu_data[cpu], plugin.params.warnthr, plugin.params.critthr)
# Formatting perfdata
perfdata = " | "
for cpu in cpu_data:
perfdata += '%s=%d%%;%d;%d;0;100 ' % (cpu.replace(' ', '_'), cpu_data[cpu], plugin.params.warnthr, plugin.params.critthr)

# Output to Nagios
longoutput = longoutput.rstrip('\n')
if exit_code == 0:
output = 'All CPU usage are below thresholds.\n'
longoutput += perfdata
plugin.ok(output + longoutput)
elif exit_code == 1:
output = '%d CPU are above %d%% of usage !\n' % (nbr_error, plugin.params.warnthr)
longoutput += perfdata
plugin.warning(output + longoutput)
elif exit_code == 2:
output = '%d CPU are above %d%% of usage !\n' % (nbr_error, plugin.params.critthr)
longoutput += perfdata
plugin.critical(output + longoutput)
# Output to Nagios
longoutput = longoutput.rstrip('\n')
if exit_code == 0:
output = 'All CPU usage are below thresholds.\n'
longoutput += perfdata
plugin.ok(output + longoutput)
elif exit_code == 1:
output = '%d CPU are above %d%% of usage !\n' % (nbr_error, plugin.params.warnthr)
longoutput += perfdata
plugin.warning(output + longoutput)
elif exit_code == 2:
output = '%d CPU are above %d%% of usage !\n' % (nbr_error, plugin.params.critthr)
longoutput += perfdata
plugin.critical(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)
100 changes: 53 additions & 47 deletions check_cisco_hard.py
@@ -1,4 +1,4 @@
#!/usr/local/bin/python2.6 -O
#!/usr/local/bin/python2.6
# -*- coding: UTF-8 -*-
#
#===============================================================================
Expand All @@ -21,7 +21,7 @@
#===============================================================================
#
#
import os, sys
import os, sys, traceback

from nagios.plugin.snmp import NagiosPluginSNMP

Expand Down Expand Up @@ -51,52 +51,58 @@ def checkPluginArguments(self):

# The main procedure
if __name__ == '__main__':
progname = os.path.basename(sys.argv[0])
progdesc = 'Check hardware (sensors, fans, power) of Cisco devices.'
progversion = '$Revision: 1 $'

plugin = CheckCiscoHard(progname, progversion, progdesc)

oid_sensors_names = '1.3.6.1.4.1.9.9.13.1.3.1.2'
oid_fans_names = '1.3.6.1.4.1.9.9.13.1.4.1.2'
oid_powers_names = '1.3.6.1.4.1.9.9.13.1.5.1.2'

oid_sensors_status = '1.3.6.1.4.1.9.9.13.1.3.1.6'
oid_fans_status = '1.3.6.1.4.1.9.9.13.1.4.1.3'
oid_powers_status = '1.3.6.1.4.1.9.9.13.1.5.1.3'
try:
progname = os.path.basename(sys.argv[0])
progdesc = 'Check hardware (sensors, fans, power) of Cisco devices.'
progversion = '$Revision: 1 $'

if plugin.params.type == 'sensor':
oid_hard_names = oid_sensors_names
oid_hard_status = oid_sensors_status
elif plugin.params.type == 'fan':
oid_hard_names = oid_fans_names
oid_hard_status = oid_fans_status
elif plugin.params.type == 'power':
oid_hard_names = oid_powers_names
oid_hard_status = oid_powers_status
plugin = CheckCiscoHard(progname, progversion, progdesc)

hard_status = plugin.queryNextSnmpOid(oid_hard_status)

# Checking state of HSRP for all interfaces
longoutput = ""
output = ""
exit_code = 0
nbr_error = 0
for state in hard_status:
stateIndex = state[0][-1]
stateDescr = plugin.querySnmpOid('%s.%s' % (oid_hard_names, stateIndex))
oid_sensors_names = '1.3.6.1.4.1.9.9.13.1.3.1.2'
oid_fans_names = '1.3.6.1.4.1.9.9.13.1.4.1.2'
oid_powers_names = '1.3.6.1.4.1.9.9.13.1.5.1.2'

if state[1] > 1:
longoutput += '** %s: %s **\n' % (stateDescr[1], plugin.statusname[1])
if exit_code != 2: exit_code = 1
nbr_error+=1
else:
longoutput += '%s: %s\n' % (stateDescr[1], plugin.statusname[1])
oid_sensors_status = '1.3.6.1.4.1.9.9.13.1.3.1.6'
oid_fans_status = '1.3.6.1.4.1.9.9.13.1.4.1.3'
oid_powers_status = '1.3.6.1.4.1.9.9.13.1.5.1.3'

longoutput = longoutput.rstrip('\n')
if exit_code == 1:
output = '%d %s in error !\n' % (nbr_error, plugin.params.type.title())
plugin.critical(output + longoutput)
elif exit_code == 0:
output = '%s health is good.\n' % plugin.params.type.title()
plugin.ok(output + longoutput)
if plugin.params.type == 'sensor':
oid_hard_names = oid_sensors_names
oid_hard_status = oid_sensors_status
elif plugin.params.type == 'fan':
oid_hard_names = oid_fans_names
oid_hard_status = oid_fans_status
elif plugin.params.type == 'power':
oid_hard_names = oid_powers_names
oid_hard_status = oid_powers_status

hard_status = plugin.queryNextSnmpOid(oid_hard_status)

# Checking state of HSRP for all interfaces
longoutput = ""
output = ""
exit_code = 0
nbr_error = 0
for state in hard_status:
stateIndex = state[0][-1]
stateDescr = plugin.querySnmpOid('%s.%s' % (oid_hard_names, stateIndex))

if state[1] > 1:
longoutput += '** %s: %s **\n' % (stateDescr[1], plugin.statusname[1])
if exit_code != 2: exit_code = 1
nbr_error+=1
else:
longoutput += '%s: %s\n' % (stateDescr[1], plugin.statusname[1])

longoutput = longoutput.rstrip('\n')
if exit_code == 1:
output = '%d %s in error !\n' % (nbr_error, plugin.params.type.title())
plugin.critical(output + longoutput)
elif exit_code == 0:
output = '%s health is good.\n' % plugin.params.type.title()
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 bc0493f

Please sign in to comment.