TECHZEN Zenoss User Community ARCHIVE  

Collecting String data from SNMP during performance cycle?

Subject: Collecting String data from SNMP during performance cycle?
Author: Pheripheral Pheripheral
Posted: 2017-08-14 10:47

Hi,

I'm creating an snmp zenpack to monitor a device and have the performance data update the component info when things change.

 

The device returns in its data for each component:

A status integer – 1,2, or 3 (representing Up, Down or Degraded)

A status string that contains further info on the status when the status is not 1 ( i.e. not Up)

 

I've successfully retrieved the status integer via a SNMP motinoring datasource and a minmax threshold, which fires an event which then updates the value of the status data on the component and alters the event severity depending on the status. This works fine and my component display updates when the atstus changes and suitable events are raised.

 

I'm struggling to work out how to also collect the status string information to be able update the component when it changes.

I did try using the value change threshold to track when the status string data changes, but this seems to only work if the status string contains numbers as the threshold seems to assume it's a number.

 

Help or guidance of how this can be achieved is welcome.

 

I guess the question is ultimately how do you collect strings from snmp during the performance cycle rather than at monitoring time.

(I can get the status string at monitoring time ok!)

 

Thanks

Dafydd



Subject: RE: Collecting String data from SNMP during performance cycle?
Author: Jane Curry
Posted: 2017-08-14 12:34

Sorry but I don't know of a way to do this.  Fundamentally, performance monitoring templates collect numbers.  You can do "sums" on those numbers; with the help of the Calculated Performance ZenPack you can combine numbers from device attributes and other collected performance numbers.

But, fundamentally, they all have to be numbers!

The only way I know of to include strings as an attribute of a device, is in a modeler plugin.

Cheers,
Jane

------------------------------
Jane Curry
Skills 1st United Kingdom
jane.curry@skills-1st.co.uk
------------------------------

Subject: RE: Collecting String data from SNMP during performance cycle?
Author: Patrick McMahon
Posted: 2017-08-15 10:26

If the values possible in the status string are a list of known strings you could apply some mapping logic to turn it into a number (easier said than done)

"Unknown": 0
"Known Reason String 1": 1
"Known Reason String 2": 2

Assuming that's true, a rough suggestion at implementing this would be...

Create a script you can call through a command type datasource (I would suggest you write the script in python so you can leverage pynetsnmp.twistedsnmp).
The script you're calling would need to make the SNMP call (so you would need to pass in the various SNMP zProperties to the script and the OID and possibly the snmpindex captured in model).
Within the script you would need to take the returned string from the SNMP call and do a lookup in a dictionary to get the corresponding number. The script would then print that number as a datapoint to standard out in nagios format (see http://wiki.zenoss.org/Writing_Command_Data_Sources)

There might be other solutions like a Python Datasource

------------------------------
Patrick McMahon
Sr. Client Services Engineer
Zenoss
------------------------------


Subject: RE: Collecting String data from SNMP during performance cycle?
Author: Pheripheral Pheripheral
Posted: 2017-08-15 14:26

Thanks for the suggestions / clarification that it's not something obvious I have missed.

Unfortunately, they are not a discrete set of strings, or at least the set of strings is not known to me.

I did find a bit of old zenpack code in our zenoss instance, that someone else created a while back, that uses a custom command datasource to essentially just do an snmp walk on the target device and then uses a custom parser to parse the return data.
It then fires an event off containing the desired data (including strings ) and then event updates the component, so in theory this would work. The downside being the extra legwork to set it up and the overhead of running a command data source every cycle.


(One other question / idea / longshot... is it possible to call the zenmodeler from within an event transform or similar?
As the string i'm after is only set/ updated when a numeric status is changed, i could have the zenmodeler run when a certain numeric data value changes to pick up the new string perhaps...)

Thanks
Dafydd

------------------------------
Pheripheral Pheripheral
------------------------------


Subject: RE: Collecting String data from SNMP during performance cycle?
Author: Jane Curry
Posted: 2017-08-16 06:32

I have tried a wee test of this.  As you say, the performance hit on running the transform may not be nice.  However, I have this working as a transform:

from subprocess import Popen,PIPE
import os

zenhome = os.environ['ZENHOME']
cmdparts = [zenhome + '/bin/zenmodeler run']
myDev = '-d ' + evt.device
cmdparts.append(myDev)
if evt.component:
     collect = '--collect FileSystem'
     cmdparts.append(collect)

evt.cmd = ' '.join(cmdparts)
p = Popen(evt.cmd, shell=True, stdout=PIPE,stderr=PIPE)
evt.myOut = 'Done'
#myOut = []
#for line in p.stdout.readlines():
# myOut.append(line)
#evt.myOut = ' '.join(myOut)
#evt.cmdExit = p.wait()

I used this as a transform against an event generated on a filesystem threshold so I have limited the modeler run with the --collect parameter to specify the single modeler I want to run.  The Model Time for the device shows it being updated every 5 minutes and, when I had freed up a load of space, the modeler data for that filesystem had been updated.

I couldn't make the commented lines at the end work - just never got a value for evt.cmdExit (which I tried first) or for evt.myOut (which I then inserted).  You do need the shell=True in the Popen or you get an event transform error.

Be interested if you make this work...
Cheers,
Jane

------------------------------
Jane Curry
Skills 1st United Kingdom
jane.curry@skills-1st.co.uk
------------------------------


Subject: RE: Collecting String data from SNMP during performance cycle?
Author: Pheripheral Pheripheral
Posted: 2017-08-17 13:03

This is great! Thanks

I've done a quick test of this by updating my transform to fire this modeler code off when it updates the numeric status data on the component and it sucessfully runs the modeler and grabs the status string and updates the component successfully.

It's only fired once when the numeric status changes value, so it doesn't get called every collection cycle. The numeric status changing should be a very rare event, so this should be a feasible solution I think.

The only possible situation that could get complicated, is if many of the components change numeric state at the same time, each of them will trigger an event, and each event will fire off the modeler, so it may be called several times in quick succession, but hopefully zenoss will take care of the consequences of that. We're not talking 100's of times, just possibly very worst case scenario 20 to 30 times...
I may have a play with the --collage option on the zenmodeler to check the previous collect time perhaps...


Thanks
Dafydd

------------------------------
Pheripheral Pheripheral
------------------------------

Hi,

I'm creating an snmp zenpack to monitor a device and have the performance data update the component info when things change.

 

The device returns in its data for each component:

A status integer – 1,2, or 3 (representing Up, Down or Degraded)

A status string that contains further info on the status when the status is not 1 ( i.e. not Up)

 

I've successfully retrieved the status integer via a SNMP motinoring datasource and a minmax threshold, which fires an event which then updates the value of the status data on the component and alters the event severity depending on the status. This works fine and my component display updates when the atstus changes and suitable events are raised.

 

I'm struggling to work out how to also collect the status string information to be able update the component when it changes.

I did try using the value change threshold to track when the status string data changes, but this seems to only work if the status string contains numbers as the threshold seems to assume it's a number.

 

Help or guidance of how this can be achieved is welcome.

 

I guess the question is ultimately how do you collect strings from snmp during the performance cycle rather than at monitoring time.

(I can get the status string at monitoring time ok!)

 

Thanks

Dafydd



Subject: RE: Collecting String data from SNMP during performance cycle?
Author: Jane Curry
Posted: 2017-08-18 03:53

Good-o. If you are worried about multiple component updates, there is a method on the device (sorry can't remember it exactly and not got access to my Zenoss at present), that looks up when the last model was done for the device.  You could compare that with the current time (need to import the time module too) and then not do the model if it has been modeled in the last, say, 5 minutes.
Cheers,
Jane

------------------------------
Jane Curry
Skills 1st United Kingdom
jane.curry@skills-1st.co.uk
------------------------------


< Previous
SNMP traps no longer being reported after installing Cisco MIB zenpack
  Next
Can I add the trigger to the notification body?
>