Monday, April 27, 2009

Zenoss monitor customized application via SNMP

Zenoss can monitor remote customized applications by various methods e.g SSH/NRPE/SNMP, this note demonstrates SNMP method
#==Summary
if your targent host doesn't support SSH/NRPE mentioned in last two posts, SNMP is a good option. Even your app doesn't have built-in SNMP OID, net-snmp allows you to map an OID to your app. The solution is not perfect, the drawback is that the alarm will be triggered whenever the app fails but the detailed error message given by the app is not available.
#== ENV
Zenoss 2.3.3 + Centos 5.2 + Net-snmp 5.3.1
#== Setup SNMP
Please make sure you have basic snmp working, refer to my post
Set up Net-snmp on CentOS
The OID definition to be used is: /usr/share/snmp/mibs/UCD-SNMP-MIB.txt
Its OID range is .1.3.6.1.4.1.2021.x, some values have been used, let's start with.1.3.6.1.4.1.2021.200
There are specifications about the OID, the ID of interest is 2021.ID.100.

2021.ID.1 : an integer index value. In scalers, this is always
of value 1. In tables it is a row index.
2021.ID.2 : a name of the script, process, etc. that this row represents.
2021.ID.100 : An error flag indicating if an error is present on
that row (a threshold value was crossed, etc).
2021.ID.101 : An error string describing why the error flag is non-0

#==== Create a test script

$vi /usr/local/bin/check_test.sh
#!/bin/sh
flag=1
if [ $flag -eq 0 ]; then
echo "SNMP check test -OK"
exit 0
else
echo "SNMP check test -FAILED"
exit 1
fi

$chmod +rx /usr/local/bin/check_test.sh
#==== Map a OID to the script
$vi /etc/snmp/snmp.conf
exec .1.3.6.1.4.1.2021.200 check_test /usr/local/bin/check_test.sh
#====exec the script by run query to the OID
$snmpwalk -v2c -c public localhost .1.3.6.1.4.1.2021.200
UCD-SNMP-MIB::ucdavis.200.1.1 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.200.2.1 = STRING: "check_test"
UCD-SNMP-MIB::ucdavis.200.3.1 = STRING: "/usr/local/bin/check_test.sh"
UCD-SNMP-MIB::ucdavis.200.100.1 = INTEGER: 1
UCD-SNMP-MIB::ucdavis.200.101.1 = STRING: "SNMP check test -FAILED"
UCD-SNMP-MIB::ucdavis.200.102.1 = INTEGER: 0
UCD-SNMP-MIB::ucdavis.200.103.1 = ""
#==Create template under Devices/Server to use the script
(You can create template under any scope e.g Devices/Server/linux)
Classes->Devices->Server(sub-Devices)Templates->Add Template (add template is hidden drop down menu brought up by clicking the small triangle button)

New data Source ( ID: userdefined TYPE: SNMP)
NAME:check_test_SNMP
Enabled:true
OID 1.3.6.1.4.1.2021.200.100.1
New data Point
name: check_test_SNMP
type: GAUGE
New Thresholds
name: check_test_SNMP
Datapoint: check_test_SNMP_check_test_SNMP
min value: 0
max value: 0
Event Class: /perf/snmp (can be anyting)
Severity: error
Enabled: true

#==Bind the template to your Device
Device List->yourdevice->Open->
Click the small triangle button->More->Template
Click the small triangle button->Bind Templates->add new template to selection (You can select multiple templates)


#== Test, you should be able to see the new datasource was picked up by Zenoss
$/opt/zenoss/zenoss/bin/zenperfsnmp run -d 10.248.248.22 -v10
..
DEBUG:zen.thresholds:Updating threshold ('check_test_SNMP', ('10.248.248.22', ''))
..

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.