We are trying to get more information from our SNMP traps and we are looking for a way to find more detail. We trap on up/down of interfaces but is there a way to get more information (like a description) from the trap for link down (.1.3.6.1.6.3.1.1.5.3) and link up (.1.3.6.1.6.3.1.1.5.4)? I know the data is not contained within the trap itself but I was possibly looking for a way to pull the corresponding description entry from the ifxAlias table at this OID: 1.3.6.1.2.1.31.1.1.1.18. I am thinking that since the trap shows the ifindex, we can strip that ifindex number off and do an snmp get of 1.3.6.1.2.1.31.1.1.1.18.[ifindex], then we could return the interface description with the trap.
From some research, I found that I may be able to do a PREEXEC in SNMPTT like this:
PREEXEC /usr/bin/snmpget -v2c -Ovq -c snmppassword $aA 1.3.6.1.2.1.31.1.1.1.18.$1
and then have the EXEC line use that output like this:
EXEC /usr/local/bin/snmptraphandling.py "$r" "SNMP Traps" "$s" "$p1" "$@" "$-*" "LINK DOWN, $*"
If I go this route, I would likely have to do some preprocessing as that OID returns "description" at the beginning and I would likely want to strip that out.
Also, since the PREEXEC requires the sending of the SNMP credentials (we use v2 and v3), is there some way to get that information from the Nagios system since we had to configure that in the system? I know the interface check command includes it like so: "check_xi_service_ifoperstatus!snmppassword!7!-v 2 -p 161" but is that "snmppassword" value stored as a variable anywhere where I can get my hands on it for a script?
We are looking for best practices or some recommendations to getting this working the best way possible.
SNMPTT PREEXEC questions
Re: SNMPTT PREEXEC questions
I am including a link for the SNMP Trap Tutorial as it has a lot of information for customizing the Traps.
https://support.nagios.com/kb/article/n ... al-77.html
The script that you use to poll the description, you could use that to format the string that is sent in to XI or you could use a REGEX in the snmptt.conf file to do that for you.
For Example, this regex should replace Description with an empty string.
REGEX (Description)()ig
More details can be found here.
To get the snmppassword from the system, you could use the XI API to get the information from XI, parse the data and use that in the snmpget.
You would use the following example to get the service status of one service called Port 11 Status for the localhost host.
Then you can parse the password out of the check_command data.
One thing to note, if the service name has a space in it, you will have to replace the space with %20 as shown in the above example of the name="Port$2011%20Status" option.
For more details on the API, in the XI GUI, go to the Help > REST API Docs menu.
https://support.nagios.com/kb/article/n ... al-77.html
The script that you use to poll the description, you could use that to format the string that is sent in to XI or you could use a REGEX in the snmptt.conf file to do that for you.
For Example, this regex should replace Description with an empty string.
REGEX (Description)()ig
More details can be found here.
To get the snmppassword from the system, you could use the XI API to get the information from XI, parse the data and use that in the snmpget.
You would use the following example to get the service status of one service called Port 11 Status for the localhost host.
Code: Select all
curl -XGET "https://192.168.1.1/nagiosxi/api/v1/objects/servicestatus?apikey=j8hf9ss5&host_name=localhost&name="Port$2011%20Status"&pretty=1" -kOne thing to note, if the service name has a space in it, you will have to replace the space with %20 as shown in the above example of the name="Port$2011%20Status" option.
For more details on the API, in the XI GUI, go to the Help > REST API Docs menu.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Re: SNMPTT PREEXEC questions
I had read through the guide already but you mentioned REGEX and that was not in there. Did you mean to add a link after the "more details can be found here."? None of the words are hot-linked and there is no URL there but what you are saying does seem like it would work for us.
The XML may be an option but if I get some interface in the trap, I am not sure that the name needed for the API could be tied to the name of the particular service associated with the interface that the trap arrives so I don't see a way to do that pragmatically. Can I send variables to an executable or batch file in SNMPTT? I thought the $r, @a, $1 etc, were only available at the PREEXEC command line. How could I send those arguments to a batch file or python script to output data back to the EXEC call as $p1? I am definitely not an expert programmer by any stretch of the imagination and if what I am asking is too basic, do you offer paid development support to do what we want for us?
The XML may be an option but if I get some interface in the trap, I am not sure that the name needed for the API could be tied to the name of the particular service associated with the interface that the trap arrives so I don't see a way to do that pragmatically. Can I send variables to an executable or batch file in SNMPTT? I thought the $r, @a, $1 etc, were only available at the PREEXEC command line. How could I send those arguments to a batch file or python script to output data back to the EXEC call as $p1? I am definitely not an expert programmer by any stretch of the imagination and if what I am asking is too basic, do you offer paid development support to do what we want for us?
Re: SNMPTT PREEXEC questions
More than likely tgriep was just going to link to the SNMPTT docs:
http://snmptt.sourceforge.net/docs/snmp ... CONF-REGEX
We do offer paid custom development, if that is something you're interested in you'd need to reach out to [email protected] to get more information/a quote.
http://snmptt.sourceforge.net/docs/snmp ... CONF-REGEX
You would just call the script with the PREEXEC passing any variables into the script you'd like and the returned output from your script would become $p1. Note: You can have multiple PREEXEC lines.Can I send variables to an executable or batch file in SNMPTT? I thought the $r, @a, $1 etc, were only available at the PREEXEC command line. How could I send those arguments to a batch file or python script to output data back to the EXEC call as $p1?
We do offer paid custom development, if that is something you're interested in you'd need to reach out to [email protected] to get more information/a quote.