Page 1 of 1

Truncate %serviceoutput% for text notification

Posted: Fri May 29, 2015 1:00 pm
by dfmco
Is there a way to process and rewrite the %alertsummary% variable (maybe copy pieces into a new variable) for sending in a text message? I would like to possibly change occurrences of Serial to S and Gigabit to G to make it short enough to be sent to a sat phone. I can do the processing, I was just hoping to see if that was even possible and where to start looking. I figure I could possibly send the contents of the variable to Perl, pull out what I need and copy into a new variable that I can use as a custom alert variable. Does what I want to do make sense? Is there a better way possibly?

I would like the final solution to be portable and survive upgrades without having to change a lot of baked in system files so this would be easy to transport across installations and make support easier.

Re: Truncate %alertsummary% for text notification

Posted: Fri May 29, 2015 1:17 pm
by lmiltchev
Have you tried using a custom notification host or service macros as described in this document:

https://assets.nagios.com/downloads/nag ... iables.pdf

Re: Truncate %alertsummary% for text notification

Posted: Fri May 29, 2015 1:19 pm
by abrist
A custom notification script is your best option as the %alertsummary% macro is an XI built-in notification macro and it's code most likely resides in a protected file. Not to mention your changes to the macro would not persist through upgrades.

Re: Truncate %serviceoutput% for text notification

Posted: Sun May 31, 2015 10:13 pm
by dfmco
So the notification variables look like they need to be hard set (like the MAC example given). Maybe I am missing something but when an SNMP trap is sent to Nagios, the %serviceoutput% variable contains the text from that trap (or so I think). So what I need is to process the text of the SNMP trap to pull out the most basic of information to send to my sat phone. The custom variable does not seem to be of value. Please let me know if I am missing something. Here is what I need to do exactly.

The %serviceoutput% in the example below contains the following text:
LINK DOWN 6 Serial 0/0/0:0 ds1 / ifIndex.6 (INTEGER32):6 ifDescr.6 (OCTETSTR):T1 0/0/0 ifType.6 (INTEGER):ds1
This text needs to be modified on the alert to look like this:
DOWN s0/0/0

I can figure out the regex or perl processing to get this done, I just need to know how to get the text in the first place to process and how to then send the processed output to a text alert.

Ideas?

Re: Truncate %serviceoutput% for text notification

Posted: Sun May 31, 2015 10:46 pm
by Box293
With SNMP Traps, EXEC lines are how the information is sent to Nagios.

EXEC are normally defined in /etc/snmp/snmptt.conf

Here is an example EXEC line:

Code: Select all

EXEC /usr/local/bin/snmptraphandling.py "$r" "SNMP Traps" "$s" "$@" "$-*" "The SNMP trap that is generated as a result of an event with the service $*"
snmptraphandling.py needs 6 arguments.

snmptraphandling.py <HOST> <SERVICE> <SEVERITY> <TIME> <PERFDATA> <DATA>

And they should be surrounded by double quotes. If you don't want to submit a value, like perfdata, you still need double quotes with no value between them.

$-* and $* are ways of expanding and printing ALL the variables. If you just want one varable, you can use $1 or $2 etc

Hence your EXEC line could look like:

Code: Select all

EXEC /usr/local/bin/snmptraphandling.py "$r" "SNMP Traps" "$s" "$@" "" "DOWN $1"
Here's the snmptt documentation:
http://snmptt.sourceforge.net/docs/snmp ... ONF-FORMAT

Does this help?