Command line format for external notification.

Andreas Ericsson ae at op5.se
Wed Jun 29 14:22:39 CEST 2005


krimo wrote:
> Paul L. Allen a écrit :
> 
>> Andreas Ericsson writes:
>>
>>> aait at free.fr wrote:
>>>
>>>> Example:
>>>> define command{
>>>>    command_name    notify-by-xmlrpc
>>>>    command_line    /usr/lib/nagios/myagent/notification/my_script
>>>> $HOSTNAME$ CRITICAL $OUTPUT$ $SERVICEDESC$ $DATETIME$
>>>>    }
>>>
>>>
>>>
>>> Put single quotes around each macro.
>>
>>
> This solution does not work ;).
> 
>>
>> As the perl motto has it, "there's more than one way to do it."  An
>> alternative solution would be to rearrange the parameters so that
>> $OUTPUT$ is the last parameter.  Then after shifting out the hostname,
>> etc., what is left is $OUTPUT$.
>> $hostname = shift;
>> $status = shift;
>> $servicedesc = shift;
>> $datetime = shift;
>> $output = join(' ', @ARGV);
>> Back in the days before perl had references, this sort of trick was the
>> standard way of coding subroutines which took multiple parameters, one of
>> which was an array - pass the scalars first and the array last.
>> This approach is not better than yours, it's just one that I'd hope a
>> competent perl coder would have used instinctively.  Mr Aait didn't...
> 

This won't work if $SERVICEDESC$ also has spaces, which it legally can 
have. I can't remember exactly what $DATETIME$ does, but one of those 
can have spaces as well.

> 
> Thanks for your reply. I have already considered this solution but this 
> is not the one I prefer. If I choose this solution, that means I would 
> have failed in the optimal configuration of Nagios (I can't admit it ;) 
> ). Also my script can't be used anymore if Ihave two macros containing 
> strings.
> 
> The best solution is to correcftly configure Nagios command line and 
> Iknow there 's a way to do that.

Put single quotes around the macros (outside the dollar signs). This 
will fail if any of the parameters contains single quotes as well, but 
will work otherwise, unless your shell is broken. You'll need to restart 
nagios for changes to take effect, but it will work.

> It's not a problem of perl code but 
> Nagios configuration (it's why I post in the nagios mailing list and not 
> perl one). Finally, I'm not a perl coder as you have seen ;) (I prefer C 
> lang. but in this case I do not decide any).
> 
> Regards
> aaits
> 
> 
> 
> 
> 
> 
> 
> 
> -------------------------------------------------------
> SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
> from IBM. Find simple to follow Roadmaps, straightforward articles,
> informative Webcasts and more! Get everything you need to get up to
> speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
> _______________________________________________
> Nagios-users mailing list
> Nagios-users at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/nagios-users
> ::: Please include Nagios version, plugin version (-v) and OS when 
> reporting any issue. ::: Messages without supporting info will risk 
> being sent to /dev/null
> 

-- 
Andreas Ericsson                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Lead Developer


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list