Writing a plugin
Posted: Sun Jul 21, 2013 10:40 pm
Is this the right place for help with writing a plugin? I couldn't find a forum on exchange.nagios.org, so I'll try here.
I'm working on fine tuning the warning/critical threshold definition. My script is being written in Python and so far this is what I have. I'm hoping that someone can put a second (or third or fourth
) set of eyes on it to make sure I have the logic figured out correctly. There's some debug code as well so if I pass -d to my plugin it will print the extra information for debugging.
I'm writing the warning/critical thresholds because I want my plugin to obey the standard Nagios warning/critical usage defined at http://nagiosplug.sourceforge.net/devel ... HOLDFORMAT.
Thanks for taking a look!
I'm working on fine tuning the warning/critical threshold definition. My script is being written in Python and so far this is what I have. I'm hoping that someone can put a second (or third or fourth
I'm writing the warning/critical thresholds because I want my plugin to obey the standard Nagios warning/critical usage defined at http://nagiosplug.sourceforge.net/devel ... HOLDFORMAT.
Thanks for taking a look!
Code: Select all
def get_status(item):
if iscritical(item):
nagios_status(critical)
elif iswarning(item):
nagios_status(warning)
else:
nagios_status(ok)
def iscritical(criticalvalue):
debug("opts.critical=%s" % opts.critical)
if opts.critical[:1] == "@":
inclusive = True
opts.critical = opts.critical[1:]
else:
inclusive = False
debug("@=%s" % inclusive)
try:
criticallow,criticalhigh = opts.critical.split(":",1)
except ValueError:
if inclusive:
if int(criticalvalue) >= int(opts.critical):
debug("%s >= %s is critical" %(criticalvalue,opts.critical))
return True
else:
debug("%s >= %s not critical" %(criticalvalue,opts.critical))
return False
else:
if int(criticalvalue) > int(opts.criticalvalue):
debug("%s > %s is critical" %(criticalvalue,opts.critical))
return True
else:
debug("%s > %s not critical" %(criticalvalue,opts.critical))
return False
else:
debug("criticallow=*%s*,criticalhigh=*%s*" %(criticallow,criticalhigh))
if inclusive:
if criticallow == "":
debug("criticallow=*%s*" %criticallow)
if int(criticalvalue) >= int(criticalhigh):
debug("%s >= %s" %(criticalvalue,criticalhigh))
debug("%s is critical" %criticalvalue)
return True
elif criticalhigh == "":
debug("criticalhigh=*%s*" %criticalhigh)
if int(criticalvalue) <= int(criticallow):
debug("%s <= %s" %(criticalvalue,criticallow))
debug("%s is critical" %criticalvalue)
return True
elif int(criticalvalue) >= int(criticallow) and int(criticalvalue) <= int(criticalhigh):
debug("%s >= %s and %s <= %s" %(int(criticalvalue),int(criticallow),int(criticalvalue),int(criticalhigh)))
debug("%s is critical" %criticalvalue)
return True
else:
debug("%s >= %s and %s <= %s" %(int(criticalvalue),int(criticallow),int(criticalvalue),int(criticalhigh)))
debug("%s is not critical" %criticalvalue)
return False
else:
if criticallow == "":
debug("criticallow=*%s*" %criticallow)
if int(criticalvalue) > int(criticalhigh):
debug("%s > %s" %(criticalvalue,criticalhigh))
debug("%s is critical" %criticalvalue)
return True
elif criticalhigh == "":
debug("criticalhigh=*%s*" %criticalhigh)
if int(criticalvalue) < int(criticallow):
debug("%s < %s" %(criticalvalue,criticallow))
debug("%s is critical" %criticalvalue)
return True
elif int(criticalvalue) < int(criticallow) or int(criticalvalue) > int(criticalhigh):
debug("%s < %s or %s > %s" %(int(criticalvalue),int(criticallow),int(criticalvalue),int(criticalhigh)))
debug("%s is critical" %criticalvalue)
return True
else:
debug("%s < %s or %s > %s" %(int(criticalvalue),int(criticallow),int(criticalvalue),int(criticalhigh)))
debug("%s is not critical" %criticalvalue)
return False
def iswarning(warningvalue):
debug("opts.warning=%s" % opts.warning)
if opts.warning[:1] == "@":
inclusive = True
opts.warning = opts.warning[1:]
else:
inclusive = False
debug("@=%s" % inclusive)
try:
warninglow,warninghigh = opts.warning.split(":",1)
except ValueError:
if inclusive:
if int(warningvalue) >= int(opts.warning):
debug("%s >= %s is warning" %(warningvalue,opts.warning))
return True
else:
debug("%s >= %s not warning" %(warningvalue,opts.warning))
return False
else:
if int(warningvalue) > int(opts.warning):
debug("%s > %s is warning" %(warningvalue,opts.warning))
return True
else:
debug("%s > %s not warning" %(warningvalue,opts.warning))
return False
else:
debug("warninglow=*%s*, warninghigh=*%s*" %(warninglow,warninghigh))
if inclusive:
if warninglow == "":
debug("warninglow=*%s*" %warninglow)
if int(warningvalue) >= int(warninghigh):
debug("%s >= %s is warning" %(warningvalue,warninghigh))
return True
elif warninghigh == "":
debug("warninghigh=*%s*" %warninghigh)
if int(warningvalue) <= int(warninglow):
debut("%s <= %s is warning" %(warningvalue,warninglow))
return True
elif int(warningvalue) >= int(warninglow) and int(warningvalue) <= int(warninghigh):
debug("%s >= %s and %s <= %s is warning" %(int(warningvalue),int(warninglow),int(warningvalue),int(warninghigh)))
return True
else:
debug("%s >= %s and %s <= %s is not warning" %(int(warningvalue),int(warninglow),int(warningvalue),int(warninghigh)))
return False
else:
if warninglow == "":
if int(warningvalue) > int(warninghigh):
debug("%s > %s is warning" %(warningvalue,warninghigh))
return True
elif warninghigh == "":
if int(warningvalue) < int(warninglow):
debug("%s < %s is warning" %(warningvalue,warninglow))
return True
elif int(warningvalue) < int(warninglow) or int(warningvalue) > int(warninghigh):
debug("%s < %s or %s > %s is warning" %(int(warningvalue),int(warninglow),int(warningvalue),int(warninghigh)))
return True
else:
debug("%s < %s or %s > %s is not warning" %(int(warningvalue),int(warninglow),int(warningvalue),int(warninghigh)))
return False