$SERVICEOUTPUT$ macro

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
oz123
Posts: 42
Joined: Thu Jun 09, 2011 10:21 am

$SERVICEOUTPUT$ macro

Post by oz123 »

Hi,

I'm using the check_nt plugin to monitor disk space.
The output is generated with "%" sign which need to eliminate (not acceptable when sending to an some external sms provider)
I can't do by manipulating the plugin command so I thought of customize the $SERVICEOUTPUT$ and eliminiate the "%" sigh from there.
Is it possible ?
Example:


Service: Drive C: Disk Usage
Host: Inwise
Address: 10.4.10.6
State: WARNING
Info:
C:\ - total: 20.00 Gb - used: 16.53 Gb (83%) - free 3.47 Gb (17%)
Date/Time: 26/07/2012 14:47:11
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: $SERVICEOUTPUT$ macro

Post by mguthrie »

I'd try experimenting with wrapping the macro in either single or double quotes and see if it will let the characters through.
oz123
Posts: 42
Joined: Thu Jun 09, 2011 10:21 am

Re: $SERVICEOUTPUT$ macro

Post by oz123 »

I need to prevent the "%'" sign from accessing the macro, eliminating afterwards want help me.
Maybe writing a macro which want accept it at the first place ? how ?

Thanks
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: $SERVICEOUTPUT$ macro

Post by lmiltchev »

You may try to create a custom macro, which will output for example "percent" instead of "%". I am not sure how (and if) it can be done, but here is our documentation on notification variables in Nagios XI:

http://assets.nagios.com/downloads/nagi ... iables.pdf

Hope this helps.
Be sure to check out our Knowledgebase for helpful articles and solutions!
User avatar
CGraham
Posts: 115
Joined: Tue Aug 16, 2011 2:43 pm

Re: $SERVICEOUTPUT$ macro

Post by CGraham »

You could use a script like this..

Code: Select all

####BEGIN OUTPUT EDITOR SCRIPT
#!/usr/bin/perl -w

####SET VARIABLES
$args = "";
$pathtocommand = "/usr/local/nagios/libexec/check_nt";

####COLLECT COMMAND LINE ARGS
foreach (@ARGV) {
        $args .= $_ . " ";
}

####RUN THE COMMAND
$output = `$pathtocommand $args`;

####FILTER OUTPUT
$output =~ s/%/ percent/gi;

####PRINT THE RETURN STRING
print "$output";

####END OUTPUT EDITOR SCRIPT
Save it in the libexec folder as "check_nt_sms". Then run "chmod +x check_nt_sms" to make it executable. Verify the $pathtocommand is correct. Then you can run it in place of your original command.

**Note: this is just an example. No guarantees.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: $SERVICEOUTPUT$ macro

Post by scottwilkerson »

CGraham,

Thanks for sharing!
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
oz123
Posts: 42
Joined: Thu Jun 09, 2011 10:21 am

Re: $SERVICEOUTPUT$ macro

Post by oz123 »

Thanks CGraham, but your suggestion return (null) :
Aug 12 06:13:43 nagios nagios: SERVICE ALERT: Inwise;Drive D: Disk Usage;CRITICAL;HARD;2;(null)

Anyway, I did somthing simular and used "sed" on the command itself:
$USER1$/check_nt -H $HOSTADDRESS$ -s "$ARG1$" -p 12489 -v $ARG2$ $ARG3$ | sed -e 's/%/ percent/g'
This is not good as from some reason when I simulate now "WARNING" it returns "OK". maybe the % "sign" is hardcoded somewhere ?

without sed:
Aug 12 07:18:15 nagios nagios: SERVICE NOTIFICATION: _Test;Inwise;Drive D: Disk Usage;WARNING;notify-oz_test-ser
vice;D:\ - total: 10.00 Gb - used: 3.33 Gb (33%) - free 6.67 Gb (67%)

With sed:

Aug 12 07:22:10 nagios nagios: SERVICE NOTIFICATION: _Test;Inwise;Drive D: Disk Usage;OK;notify-oz_test-ser
vice;C:\ - total: 10.00 Gb - used: 3.33 Gb (33 percent) - free 6.67 Gb (67 percent)
--------------------------------------------------------------------------------------------------------------------------
In general, I want the save some costs by converting the SMS notifications into smartphone push notification.
So I have an external company proccess which runs in the backround and collects events.
The command which generates the event:

/usr/bin/printf "Destination:oz_test|\nSubject: $NOTIFICATIONTYPE$ : $HOSTNAME$ \nBody: $SERVICESTATE$ - $HOSTALIAS$ - $SERVICEDESC$ - $SERVICEOUTPUT$ - $HOSTADDRESS$ - $LONGDATETIME$\n\n"> `mktemp -p /usr/local/test_Nagios/eventfiles/ nagioseventfile_XXXXXXXXX`

Now, the "printf' command doesn't returns "%" so the it just cuts every thing after that sign.
the event generated:

Aug 12 07:18:15 nagios nagios: SERVICE NOTIFICATION: _Test;Inwise;Drive D: Disk Usage;WARNING;notify-oz_test-by-TeamTilt-ser
vice;D:\ - total: 10.00 Gb - used: 3.33 Gb (33

I can use the "echo" command instead of "printf" and then the event turns out ok with the "%" but somehow thier proccess won't accept it (they can't help with that).

I have tried also sed on the "SERVICEOUTPUT" inside that command but it's not working also:

usr/bin/printf "Destination:oz_test|\nSubject: $NOTIFICATIONTYPE$ : $HOSTNAME$ \nBody: $SERVICESTATE$ - $HOSTALIAS$ - $SERVICEDESC$ - $(echo $SERVICEOUTPUT$ | sed -r 's/[%]+/&&/') - $HOSTADDRESS$ - $LONGDATETIME$\n\n"> `mktemp -p /usr/local/test_Nagios/eventfiles/ nagioseventfile_XXXXXXXXX`.
----------------------------------------------------------------------------------------------------------------------------
I can't understand how I can customize a macro for my needs according to the below link:

http://assets.nagios.com/downloads/nagi ... iables.pdf

I need that "SERVICEOUTPUT" to not contain any "%".
Maybe you can also help to understand why the "sed" manipulation on the "check_nt" returns "OK" instead of "WARNING"

Thanks a lot.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: $SERVICEOUTPUT$ macro

Post by scottwilkerson »

Try changing the command to the following

Code: Select all

usr/bin/printf "Destination:oz_test|\nSubject: $NOTIFICATIONTYPE$ : $HOSTNAME$ \nBody: $SERVICESTATE$ - $HOSTALIAS$ - $SERVICEDESC$ - $(echo $SERVICEOUTPUT$ | sed -r 's/[%]+//') - $HOSTADDRESS$ - $LONGDATETIME$\n\n"> `mktemp -p /usr/local/test_Nagios/eventfiles/ nagioseventfile_XXXXXXXXX`.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
oz123
Posts: 42
Joined: Thu Jun 09, 2011 10:21 am

Re: $SERVICEOUTPUT$ macro

Post by oz123 »

Tried that already it's just puts $ on all fields after that echo.

Nagios Event:
-----------------
Aug 14 09:26:50 nagios nagios: SERVICE NOTIFICATION: TeamTilt_Test;Inwise;Drive D: Disk Usage;WARNING;notify-oz_test;D:\ - total: 10.00 Gb - used: 3.46 Gb (35%) - free 6.53 Gb (65%)

Corresponded smartphone Event:
----------------------------------------
Subject: PROBLEM : Inwise
Body: WARNING - Inwise - Drive D: Disk Usage - $ - $ - $

Thanks
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: $SERVICEOUTPUT$ macro

Post by scottwilkerson »

You realize that the command I posted is different than the one you posted, right? The echo with the sed changed from

Code: Select all

$(echo $SERVICEOUTPUT$ | sed -r 's/[%]+/&&/')
to

Code: Select all

$(echo $SERVICEOUTPUT$ | sed -r 's/[%]+//')
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked