Tutorials:SNMPAgentExtension
From Wiki Centreon
| Languages: |
English |
SNMP help us to grab useful hardware and software informations about a given device.
But sometimes you don't have to something you need because it's simply not implemented into a MIB file. The first solution is to use NRPE, but it needs to install one more deamon on servers, and it opens ore more port.
Fortunately, the Net-SNMP package allow us to execute a script located on the managed server, and then collect the exit code and the output of the command !
This feature was tested under GNU/Linux systems, and I don't know if you can use it under Windows. Maybe i will test later.
Here is how to do this :
Configure the Agent
First, we need to tell the agent which script he has to keep available on request. It's quite simple.
- Place the local script you want to use into a directory. Warning : choose this folder in order to be sure that the script won't move, or won't be deleted !!
- Edit your agent standard configuration file named snmpd.conf to add a line like this :
exec <Script_Name> <Script_Full_Path> <Script_Arguments>
Be aware to edit the standard snmpd.conf, and not the persistent one. For example with a compiled Net-SNMP 5.4, my standard file is /usr/local/share/snmpd/snmpd.conf, and the persistent one is /var/net-snmp/snmpd.conf
- Then you need to restart your SNMP daemon in order to take change into account.
Use the Script
Name and result of the script will automatically be rooted under OID .1.3.6.1.4.1.2021.8, that is to say the "Net-SNMP Agent Extension Table" (called extTable).
To run the script, you just have to read OID extTable.extIndex
Each script corresponding to an exec token has its own index, depending of the declaration order.
Then you can grab the results :
- exit code of the script is OID extTable.extIndex.extResult (.1.3.6.1.4.1.2021.8.index.4.1)
- output string of the script is OID extTable.extIndex.extOutput (.1.3.6.1.4.1.2021.8.index.5.1)
Results are automatically cached for 30 seconds by the agent.
Working Example 1
I've used this feature to monitor hard drive health :
- the SmartMonTools package need to be installed on the system
- I use the check_smart.pl local perl script to easy check hard drive health by running S.M.A.R.T. self-tests using the smartctl command, so I've placed it into a /root/snmp_local_scripts folder
- I add this exec token into my /usr/local/share/snmp/snmpd.conf :
exec CheckSmart /root/snmp_local_scripts/check_smart.pl -t -d /dev/hda
- finally I could read the extTable of the agent :
# snmpwalk -v3 -u login -n "" -l authNoPriv -A password monIP .1.3.6.1.4.1.2021.8.1 UCD-SNMP-MIB::extIndex.1 = INTEGER: 1 UCD-SNMP-MIB::extNames.1 = STRING: CheckSmart UCD-SNMP-MIB::extCommand.1 = STRING: /root/check_smart.pl UCD-SNMP-MIB::extResult.1 = INTEGER: 0 UCD-SNMP-MIB::extOutput.1 = STRING: SMART overall-health self-assessment test result: PASSED UCD-SNMP-MIB::extErrFix.1 = INTEGER: noError(0) UCD-SNMP-MIB::extErrFixCmd.1 = STRING:

