Coding a host that will have SNMP polling services. I have a mib file and get the OID heading and then perform a snmpwalk to get the specific OID's. Problem is I have to perform that process on each and every Host as some OID's change from server to server.
Example:
Monitoring File System Free Space. Have the "parent" OID of 1.3.6.1.4.1.2.6.191.6.2.1.6. Did an snmp walk on three different hosts and got three different results...
Host #1 = IBM-AIX-MIB::aixFsSize.20
Host #2 = IBM-AIX-MIB::aixFsSize.21
Host #3 = IBM-AIX-MIB::aixFsSize.22
I have 37 servers I need to monitor this file system on and do not relish the idea of doing this process for all of them. BTW - Same thing for aixPagePercentUsed and a couple other things. And I found out these can change of the server (aka host) is changed.
There has to be an easier way!
Changing OID Solution?
Re: Changing OID Solution?
You could probably apply some clever sed/awk and Bash trickery on an snmpwalk output and feed it in as a delimited list into a check_snmp execution. check_snmp is able to support multiple OIDs, just not in the generic way your use case demands -- so, enter Bash or some other sort of helper scripting.
Dunno what the behavior of check_snmp is for absent OIDs in a multi-OID check, but you might also just be able to hardcode the known range of your OIDs under that tree -- if it's like 1-255 or something for the individual drive labels. If it's some sort of unique identifier, this probably won't work. Inelegant, but potentially cheaper time-wise than writing a Bash script.
Dunno what the behavior of check_snmp is for absent OIDs in a multi-OID check, but you might also just be able to hardcode the known range of your OIDs under that tree -- if it's like 1-255 or something for the individual drive labels. If it's some sort of unique identifier, this probably won't work. Inelegant, but potentially cheaper time-wise than writing a Bash script.
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
Re: Changing OID Solution?
Thanks @mcapra!
@mkeey, let us know if mcapra's suggestion helped. Thank you!
@mkeey, let us know if mcapra's suggestion helped. Thank you!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Changing OID Solution?
If I understand you correctly, I did that already. Here is an example of using the “parent” OID.
Did the walk command to see how many, and what, OID's were under the parent...
[USERID@NAGIOSXI]:[/home/nagiosxi]# cd /usr/bin
[USERID@NAGIOSXI]:[/usr/bin]# ./snmpwalk -v 3 -l authPriv -u USER -a md5 -A 'AUTHPASSWRD' -X 'PRIVPASSWRD' -x des -M /usr/share/snmp/mibs -m ALL 127.0.0.1 .1.3.6.1.4.1.2.6.191.2.4.2.1.5
IBM-AIX-MIB::aixPagePercentUsed.1 = INTEGER: 0
IBM-AIX-MIB::aixPagePercentUsed.2 = INTEGER: 3
Ran the check command via Nagios XI in the CCM…
[NAGIOS@NAGIOSXI ~]$ /usr/local/nagios/libexec/check_snmp -H 127.0.0.1 -o .1.3.6.1.4.1.2.6.191.2.4.2.1.5 -P 3 --seclevel=authPriv --secname=USER --authproto=md5 --authpasswd='AUTHPASSWRD' --privpasswd='PRIVPASSWRD' --privproto=des -l " aixPagePercentUsed" -m IBM-AIX-MIB.mib -w 95 -c 99
No valid data returned (NULL)
But, when I single out one of the “child” OID’s the check command works…
[NAGIOS@NAGIOSXI ~]$ /usr/local/nagios/libexec/check_snmp -H 1127.0.0.1 -o .1.3.6.1.4.1.2.6.191.2.4.2.1.5.2 -P 3 --seclevel=authPriv --secname=USER --authproto=md5 --authpasswd='AUTHPASSWRD' --privpasswd='PRIVPASSWRD' --privproto=des -l " aixPagePercentUsed" -m IBM-AIX-MIB.mib -w 95 -c 99
SNMP OK - aixPagePercentUsed 1 | aixPagePercentUsed=1;95;99;
BTW - Changed a lot of information to protect the company. Please don't take user id's and passwords literally.
Did the walk command to see how many, and what, OID's were under the parent...
[USERID@NAGIOSXI]:[/home/nagiosxi]# cd /usr/bin
[USERID@NAGIOSXI]:[/usr/bin]# ./snmpwalk -v 3 -l authPriv -u USER -a md5 -A 'AUTHPASSWRD' -X 'PRIVPASSWRD' -x des -M /usr/share/snmp/mibs -m ALL 127.0.0.1 .1.3.6.1.4.1.2.6.191.2.4.2.1.5
IBM-AIX-MIB::aixPagePercentUsed.1 = INTEGER: 0
IBM-AIX-MIB::aixPagePercentUsed.2 = INTEGER: 3
Ran the check command via Nagios XI in the CCM…
[NAGIOS@NAGIOSXI ~]$ /usr/local/nagios/libexec/check_snmp -H 127.0.0.1 -o .1.3.6.1.4.1.2.6.191.2.4.2.1.5 -P 3 --seclevel=authPriv --secname=USER --authproto=md5 --authpasswd='AUTHPASSWRD' --privpasswd='PRIVPASSWRD' --privproto=des -l " aixPagePercentUsed" -m IBM-AIX-MIB.mib -w 95 -c 99
No valid data returned (NULL)
But, when I single out one of the “child” OID’s the check command works…
[NAGIOS@NAGIOSXI ~]$ /usr/local/nagios/libexec/check_snmp -H 1127.0.0.1 -o .1.3.6.1.4.1.2.6.191.2.4.2.1.5.2 -P 3 --seclevel=authPriv --secname=USER --authproto=md5 --authpasswd='AUTHPASSWRD' --privpasswd='PRIVPASSWRD' --privproto=des -l " aixPagePercentUsed" -m IBM-AIX-MIB.mib -w 95 -c 99
SNMP OK - aixPagePercentUsed 1 | aixPagePercentUsed=1;95;99;
BTW - Changed a lot of information to protect the company. Please don't take user id's and passwords literally.
Re: Changing OID Solution?
With check_snmp you can query multiple OIDs, but you would need to specify each one with the "-o" option in your command, for example:
where you substitute <OID#1> and <OID#2> with actual OIDs./usr/local/nagios/libexec/check_snmp -H 127.0.0.1 -o <OID#1> -o <OID#2> -P 3 --seclevel=authPriv --secname=USER --authproto=md5 --authpasswd='AUTHPASSWRD' --privpasswd='PRIVPASSWRD' --privproto=des
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Changing OID Solution?
Ok, I tried two OID's for Page Percent Used. I first ran the SNMPWALK on the Nagios XI server...
[USERID@NAGIOSXI]:[/home/mkeey]# cd /usr/bin[USERID@NAGIOSXI]:[/usr/bin]# ./snmpwalk -v 3 -l authPriv -u USER -a md5 -A 'AUTHPASSWRD' -X 'PRIVPASSWRD' -x des -M /usr/share/snmp/mibs -m ALL 127.0.0.1 .1.3.6.1.4.1.2.6.191.2.4.2.1.5
IBM-AIX-MIB::aixPagePercentUsed.1 = INTEGER: 0
IBM-AIX-MIB::aixPagePercentUsed.2 = INTEGER: 3
I then trued the two OID's in the CHECK_SNMP command...
[NAGIOS@NAGIOSXI ~]$ /usr/local/nagios/libexec/check_snmp -H 127.0.0.1 -o .1.3.6.1.4.1.2.6.191.2.4.2.1.5.1 -o .1.3.6.1.4.1.2.6.191.2.4.2.1.5.2 -P 3 --seclevel=authPriv --secname=NAME --authproto=md5 --authpasswd='AUTHPASSWRD' --privpasswd='PRIVPASSWRD' --privproto=des -l " aixPagePercentUsed" -m IBM-AIX-MIB.mib -w 95 -c 99
SNMP OK - aixPagePercentUsed 4 1 | aixPagePercentUsed=4;95;99; iso.3.6.1.4.1.2.6.191.2.4.2.1.5.2=1
Seemed to work good. But, how can I do the SNMPWALK dynamically? I believe you mentioned a BASH script but I've never done one of those. Then how do I feed that into the Nagios CHECK_SNMP?
[USERID@NAGIOSXI]:[/home/mkeey]# cd /usr/bin[USERID@NAGIOSXI]:[/usr/bin]# ./snmpwalk -v 3 -l authPriv -u USER -a md5 -A 'AUTHPASSWRD' -X 'PRIVPASSWRD' -x des -M /usr/share/snmp/mibs -m ALL 127.0.0.1 .1.3.6.1.4.1.2.6.191.2.4.2.1.5
IBM-AIX-MIB::aixPagePercentUsed.1 = INTEGER: 0
IBM-AIX-MIB::aixPagePercentUsed.2 = INTEGER: 3
I then trued the two OID's in the CHECK_SNMP command...
[NAGIOS@NAGIOSXI ~]$ /usr/local/nagios/libexec/check_snmp -H 127.0.0.1 -o .1.3.6.1.4.1.2.6.191.2.4.2.1.5.1 -o .1.3.6.1.4.1.2.6.191.2.4.2.1.5.2 -P 3 --seclevel=authPriv --secname=NAME --authproto=md5 --authpasswd='AUTHPASSWRD' --privpasswd='PRIVPASSWRD' --privproto=des -l " aixPagePercentUsed" -m IBM-AIX-MIB.mib -w 95 -c 99
SNMP OK - aixPagePercentUsed 4 1 | aixPagePercentUsed=4;95;99; iso.3.6.1.4.1.2.6.191.2.4.2.1.5.2=1
Seemed to work good. But, how can I do the SNMPWALK dynamically? I believe you mentioned a BASH script but I've never done one of those. Then how do I feed that into the Nagios CHECK_SNMP?
Re: Changing OID Solution?
This is out of scope of nagios support. It falls in the realm of custom development. So, you will be on your own here.
Having said that, here's an example of a bash script that can get you started.
Here's the service that was created by running the above script:
Note: This is a very "specific" example for my test environment. Yours would be different. I hope this at least will point you to the right direction, but again, this is out of scope of nagios support.
Having said that, here's an example of a bash script that can get you started.
Code: Select all
#!/bin/bash
# Setting up a variable that can be used in the service definition
OIDS=`snmpwalk -On -v 3 -l authPriv -u xxx -a md5 -A 'xxx' -X 'xxx' -x des -M /usr/share/snmp/mibs -m ALL 192.168.x.x .1.3.6.1.2.1.25.3.2.1.3 | grep volume | awk '{print $1}' | sed 's/^/-o /' | tr -s '\n' ' '`
# Dropping a config in the import directory
cd /usr/local/nagios/etc/import
cat <<EOF >> CentOS-SNMP.cfg
define service {
host_name CentOS-SNMP
service_description TEST
use xiwizard_generic_service
check_command check_snmp! $OIDS -P 3 --seclevel=authPriv --secname=xxx --authproto=md5 --authpasswd='xxx' --privpasswd='xxx' --privproto=des!!!!!!!
max_check_attempts 5
check_interval 5
retry_interval 1
check_period 24x7
notification_interval 60
notification_period 24x7
notification_options w,c,u,r,f,s,
notifications_enabled 1
contacts nagiosadmin
register 1
}
EOF
# Running the reconfigure_nagios.sh on import the CentOS-SNMP.cfg config
/usr/local/nagiosxi/scripts/reconfigure_nagios.shNote: This is a very "specific" example for my test environment. Yours would be different. I hope this at least will point you to the right direction, but again, this is out of scope of nagios support.
You do not have the required permissions to view the files attached to this post.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: Changing OID Solution?
Thanks for the head start, I guess you can close this case.
Re: Changing OID Solution?
I am glad I could help! 
Be sure to check out our Knowledgebase for helpful articles and solutions!