After some pleas in other similar threads, and some prodding in the right 
direction by kgoedtel and jamesroman, I finally have thresholds working for my 
custom OIDs. I'm still not sure why some of it works, but I figured I'd just 
post my findings for anyone who is trying to do the same thing, and if anyone 
can point out a refined solution, it will be welcomed.

It turns out my problem is the output of a script driven by exec (in 
snmpd.conf) will always be a String. If Zenoss collects data as a string, you 
can't compare the data to a number (like a threshold does). The answer is to 
set your script's output to a Gauge (or whatever type is appropriate). kgoedtel 
pointed me towards using pass.

pass is another way to extend snmpd.conf and is similar to exec. However, 
instead of executing a script directly, you tell snmp that when a specific OID 
is requested, to pass the request to a script and the script can define what 
the output looks like.

kgoedtel was kind enough to give me a script of his, but unfortunately, I'm not 
comfortable enough with Perl to tweak it. However, while rereading the 
snmpd.conf man pages, I noticed a script called passtest was mentioned. After 
some searching, I found a copy of it:

passtest

Code:
#!/bin/sh -f

PATH=$PATH:/bin:/usr/bin:/usr/ucb

PLACE=".1.3.6.1.4.1.2021.255"
REQ="$2"

if [ "$1" = "-s" ]; then
  echo $* >> /tmp/passtest.log
  exit 0
fi

if [ "$1" = "-n" ]; then
  case "$REQ" in
    $PLACE)      RET=$PLACE.1 ;;
    $PLACE.1)    RET=$PLACE.2.1 ;;
    $PLACE.2.1)  RET=$PLACE.2.2 ;;
    $PLACE.2.2)  RET=$PLACE.3 ;;
    $PLACE.3)    RET=$PLACE.4 ;;
    $PLACE.4)    RET=$PLACE.5 ;;
    $PLACE.5)    RET=$PLACE.6 ;;
    *)           exit 0 ;;
  esac
else
  case "$REQ" in
    $PLACE)    exit 0 ;;
    *)         RET=$REQ ;;
  esac
fi

echo "$RET"
case "$RET" in
  $PLACE.1) echo "string"; echo "life the universe and everything"; exit 0 ;;
  $PLACE.2.1) echo "integer"; echo "42"; exit 0 ;;
  $PLACE.2.2) echo "objectid"; echo ".1.3.6.1.4.42.42.42"; exit 0 ;;
  $PLACE.3) echo "timeticks"; echo "363136200"; exit 0 ;;
  $PLACE.4) echo "ipaddress"; echo "127.0.0.1" ;;
  $PLACE.5) echo "counter"; echo "42"; exit 0 ;;
  $PLACE.6) echo "gauge"; echo "42"; exit 0 ;;
  *) echo "string"; echo "ack... $RET $REQ"; exit 0 ;;
esac




I figured my best first step was to get the example working, and then modify 
it. I used the same settings outlined in the man pages:

snmpd.conf

Code:

pass .1.3.6.1.4.1.2021.255 /usr/local/bin/passtest




So running:

Code:

snmpwalk -c public -v2c zenoss .1.3.6.1.4.1.2021.255




gave me the expected output:

Code:

UCD-SNMP-MIB::ucdavis.255.1 = STRING: "life the universe and everything"
UCD-SNMP-MIB::ucdavis.255.2.1 = INTEGER: 42
UCD-SNMP-MIB::ucdavis.255.2.2 = OID: SNMPv2-SMI::private.42.42.42
UCD-SNMP-MIB::ucdavis.255.3 = Timeticks: (363136200) 42 days, 0:42:42.00
UCD-SNMP-MIB::ucdavis.255.4 = IpAddress: 127.0.0.1
UCD-SNMP-MIB::ucdavis.255.5 = Counter32: 42




Looking at passtest I see that is has the base OID hardcoded and stored in 
PLACE. Then, depending on the request type (-n -g or -s), it compares the base 
OID to the requested OID and figures out which value to send. So if you ran:


Code:

snmpget -c public -v2c zenoss .1.3.6.1.4.1.2021.255.1




passtest would see you requested an OID equal to $PLACE.1 and would output 
"life the universe and everything". Notice passtest needs to return 3 lines: 
the OID, the type for the value, and the value.

So my next thought was I could just remove the entries from the case condition 
at the bottom of passtest and write one for each of the scripts I want to use 
with Zenoss. I tried this, but ended up getting the message:

> 
> UCD-SNMP-MIB::ucdavis.255.1 = No Such Instance currently exists at this OID
> 

I backed out my changes and tried adding new conditions to the case. So to 
check our room temp, and return the value as a gauge, I added this line:


Code:

  $PLACE.7) echo "gauge"; /usr/local/bin/readtemp -d /dev/ttyUSB0 -1 -q; exit 0 
;;




I also added this line to the first case block in passtest:

Code:

    $PLACE.6)    RET=$PLACE.7 ;;




And it worked! I added my other scripts, changed the OID in the data sources in 
Zenoss, and my custom thresholds started working as expected! I'm not sure why 
replacing all of the cases with my custom scripts didn't work, but perhaps I 
made a mistake, or I'm making an assumption that isn't true. I know that I can 
replace the existing gauge ($PLACE.6) with my own and I'll keep playing with it 
and report my findings here.

Anyway, I hope this can be of help to someone who is trying the same thing I am!

Nate




-------------------- m2f --------------------

Read this topic online here:
http://community.zenoss.com/forums/viewtopic.php?p=12744#12744

-------------------- m2f --------------------



_______________________________________________
zenoss-users mailing list
[email protected]
http://lists.zenoss.org/mailman/listinfo/zenoss-users

Reply via email to