Plugin usage

35 views
Skip to first unread message

Tim Hartmann

unread,
Oct 22, 2012, 5:07:21 PM10/22/12
to pynag-...@googlegroups.com
Hey guys,

I think i'm missing something with how .Plugin is supposed to work... weirdly I had this pluging working...

Running this:

./check_netbot_probes.py -H <host> -C <string> -w 85 -c 95
CRITICAL: Temp 80.96 is within critical range: 95 | 'Temp'=80.96;;;;


Throws a critical every time... I'm not sure exactly what I'm missing... any help would be apreachated!

import netsnmp,os,sys
import pynag.Plugins
from pynag.Plugins import WARNING, CRITICAL, OK, UNKNOWN, simple as Plugin

## Create the plugin option
np = Plugin()
## Add a command line argument
np.add_arg('C','COMM', 'Enter a SNMP Community String', required=True)
## This starts the actual plugin activation
np.activate()

internal_snsr = '1095346743'
oid = '.1.3.6.1.4.1.5528.100.4.1.1.1.10'
# snmpwalk -v 2c -c batanen 10.240.129.15 .1.3.6.1.4.1.5528.100.4.1.1.1.1
#tempSensorValueIntF = '.1.3.6.1.4.1.5528.100.4.1.1.1.9.'
tempSensorValueIntF = '.1.3.6.1.4.1.5528.100.4.1.1.1.2.'

warn = int(np['warning'])
crit = int(np['critical'])
temps = []


np.add_message( OK, "Temp" )
np.add_message( WARNING, "Temp" )
np.add_message( CRITICAL, "Temp" )

probes = netsnmp.snmpwalk(oid, Version = 2, DestHost = np['host'], Community = np['COMM'])
for s in probes:
if s == internal_snsr:
continue
else:
DegF = netsnmp.snmpget(tempSensorValueIntF+s,Version = 2, DestHost = np['host'], Community = np['COMM'])
temp = int(DegF[0]) * .18 + 32
temps.append(DegF[0])
np.add_perfdata('Temp', temp)

temps.sort()
temps.reverse()
foo = str(', '.join(temps))
for x in temps:
temp = int(x) * .18 + 32
np.check_range(temp)


Tommi

unread,
Oct 22, 2012, 5:40:55 PM10/22/12
to pynag-...@googlegroups.com
Hi T

I've taken a look at this and you are absolutely right, it is weird and a bug. I'll take a closer look at this tomorrow.

---
Tommi

Tim Hartmann

unread,
Oct 23, 2012, 9:26:07 AM10/23/12
to pynag-...@googlegroups.com
Thanks Tommi!

Tim Hartmann

unread,
Oct 23, 2012, 10:26:14 AM10/23/12
to pynag-...@googlegroups.com
So on  Plugin's what would people think of being able to pass a list into check_range?  I'm looping through a list of temperatures right now and really only acting on the hottest.. my output looks something like this 

  ./check_netbot_probes.py -H <HOST> -C <COMM> -w 90 -c 95
OK: 72.86 does not meet the range: > 90 | 'Temp'=72.86;;;; 'Temp'=66.92;;;; 'Temp'=66.02;;;; 'Temp'=66.92;;;; 'Temp'=64.4;;;; 'Temp'=67.46;;;; 'Temp'=66.56;;;; 'Temp'=62.96;;;; 'Temp'=71.6;;;; 'Temp'=64.76;;;; 'Temp'=64.4;;;; 'Temp'=63.5;;;; 'Temp'=68.9;;;; 'Temp'=62.6;;;; 'Temp'=62.6;;;; 'Temp'=69.62;;;; 'Temp'=70.16;;;;

This is because our netbotz can have a varying number of external probes,   right now I sort em, and check on the hightest value first,  but it would be cool to just pass a list to check_range and have it check them all, then alert or not alert after it had looped through the list...

Not sure if that would be useful to anyone else, and I'm totally not opposed to writing my code another way if it makes more sense either! Just thought I'd throw it out there!

-Tim



On Oct 22, 2012, at 5:40 PM, Tommi <tomas.ed...@gmail.com> wrote:

Tommi

unread,
Oct 24, 2012, 7:45:45 AM10/24/12
to pynag-...@googlegroups.com
OK, this was an inversion bug on np.check_range(), thanks Tim.

Fixed in git, https://github.com/pynag/pynag.git

---
Tommi


commit ba9fff51e4e984d7c5fa4bc054ba8c06099ee2de
Author: Tomas Edwardsson <to...@XXXXX.org>
Date:   Wed Oct 24 10:38:40 2012 +0000

    Fixed inversion bug on check_range
   
    Thanks to Tim Hartmann for reporting this.

diff --git a/pynag/Plugins/__init__.py b/pynag/Plugins/__init__.py
index fbf64e0..01a6ca7 100644
--- a/pynag/Plugins/__init__.py
+++ b/pynag/Plugins/__init__.py
@@ -182,12 +182,12 @@ class simple:
         warning = self.data['warning']
         self.hr_range = ""
 
-        if critical and self._range_checker(value, critical):
-            self.add_message(CRITICAL,"%s is within critical range: %s" % (value, critical))
-        elif warning and self._range_checker(value, warning):
-            self.add_message(WARNING,"%s is within warning range: %s" % (value, warning))
+        if critical and not self._range_checker(value, critical):
+            self.add_message(CRITICAL,"%s is outside critical range: %s" % (value, critical))
+        elif warning and not self._range_checker(value, warning):
+            self.add_message(WARNING,"%s is outside warning range: %s" % (value, warning))
         else:
-            self.add_message(OK,"%s is outside warning=%s and critical=%s" % (value, warning, critical))
+            self.add_message(OK,"%s is inside warning=%s and critical=%s" % (value, warning, critical))
 
         # Get all messages appended and exit code
         (code, message) = self.check_messages()

Tim Hartmann

unread,
Dec 7, 2012, 11:15:03 AM12/7/12
to pynag-...@googlegroups.com
Is there any word when this fix is going to be added to the EPEL RPM? 

Tommi

unread,
Dec 7, 2012, 11:28:59 AM12/7/12
to pynag-...@googlegroups.com
I think the fixes to pynag.Plugins by itself warrant a new release. Anyone have any patches to include before we want to roll out? If not I suggest a new release in the coming week.

---
Tommi

Tim Hartmann

unread,
Dec 7, 2012, 12:07:54 PM12/7/12
to pynag-...@googlegroups.com
thanks Tommi!

Páll Sigurðsson

unread,
Dec 10, 2012, 6:02:34 AM12/10/12
to pynag-...@googlegroups.com
I see nothing wrong with rolling out a new release as long as Plugins.simple() behavior is consistent with its intended purposes.

There is a fair bit of new code next release including:

* MK Livestatus integration
* Command Pipe integration
* New threshold format support for plugins
* PluginHelper() alternative class to simple()
* Perfdata Parsing

Not all of it has been field tested a lot so these are considered 'tech preview' :)
Reply all
Reply to author
Forward
0 new messages