Why dos Nagios not execute the EventHandler Script

eventcommand

(Chris) #1

I’ve got a problem with executing an event handler in my Nagios. I am locking for a possibility to check what nagios is doing. I can see, in the nagios.log, that it should be executed. But nothing happens.

Screenshot of Nagios.log:

I write this script to restart the spooler service on our Server. Her it is:
script

I created it in the "/usr/lib/nagios/Plugins/RemoteRestartNTServices.cmd". To avoid access-problems, I changed the owner an give anybody access to it.
ls

To debug the script, I write every step in a log-File called RemoteRestartNTServices.log. Bevor any command is executed, an “echo start >> RemoteRestartNTServices.log” would be executed.

But the RemoteRestartNTServices.log will not be written und even if I create a RemoteRestartNTServices.log nothing will be written in it.

How can I debug this?

Dos anyone see any failure?

Thanks for your help,

Reards

Chris


(Chris) #2

Additional information from Nagios:
-in nagios.cfg the switch enable_event_handlers=1
-this is the service:
Check
-this is the command:


#3

The location of the log file should be absolute. So far it’s probably somewhere in your file system.

The event_handler definition contains an argument (“Spooler”) which isn’t used in the command_line definition. The three parameters passed to your script are the host address and two variables from resources.cfg ($USER10$ and $USER9$).


(Chris) #4

Hi Wolfgang

Thank you for your replay and help.

Sadly I discovered a syntax failure. Behind the !Spooler! there was an exclamation mark, that should not be there. Now it works.
Thanks for your hints.

Now I’ve got another Problem. The servicename contains a $. The Name of the real service is "MicrosoftDynamicsNavServer$NAV_PROD”.
Nagios uses $ as a control character for arguments. So I have to workout how to use escaping characters in the commands.cfg. :wink:
“$ARG1” Quotation marks doesn’t help.

But that’s another story for another threat.

Regards,

Chris


#5

I’m not sure but something like MicrosoftDynamicsNavServer$$NAV_PROD should help.

I don’t hope so. :wink:


(Chris) #6

Hi Wolfgang,

Nope, if I use “MicrosoftDynamicsNavServer$$NAV_PROD” it delets both dollar signs. The script only gets “MicrosoftDynamicsNavServerNAV_PROD"
:cry:

same case if I use a Backslash infront of the$:
“MicrosoftDynamicsNavServer\$NAV_PROD” >> “MicrosoftDynamicsNavServerNAV_PROD


#7

Depending on how often the name is passed you might have to add additional $$ to get some leftovers (MicrosoftDynamicsNavServer$$$$NAV_PROD instead of MicrosoftDynamicsNavServer$$NAV_PROD).


(Chris) #8

oh, even with 6 dollar signes, it won’t work
MicrosoftDynamicsNavServer$$$$$$NAV_PROD >> MicrosoftDynamicsNavServerNAV_PROD

The chain:
-services.cfg = MicrosoftDynamicsNavServer$$$$$$NAV_PROD
-commands.cfg = “$ARG1$”
-script = MicrosoftDynamicsNavServerNAV_PROD

I don’t want to work with 2 Arguments in services.cfg to combine it in the script:

  1. Spit the Name = !MicrosoftDynamicsNavServer !NAV_PROD
  2. combine it in the script = “$1”$"$2"

I think it would work, but bevor i do this i would rather write it hardcodeed in one script and create another universal script for normal services. :slight_smile:


#9

Please show your definition and use copy/paste instead of a screenshot.


(Chris) #10

Okay,
here is the services.cfg:

define service{
host_name AS-IAS-127-W
service_description Check_WMI_CheckService NAV_PROD_1
_SERVICE_ID 687
_CRITICALITY_LEVEL
_CRITICALITY_ID
use generic-service
check_command check_wmi_plus_win_service!Microsoft Dynamics NAV Server .NAV.PROD.
max_check_attempts 3
normal_check_interval 5
retry_check_interval 1
event_handler event_RemoteRestartNAVServices!MicrosoftDynamicsNavServer$$$$$$NAV_PROD
event_handler_enabled 1
notification_interval 240
notification_period 24x7
notification_options w,c,r,f
notifications_enabled 1
contact_groups Anwendungsbetreuung-NAV
stalking_options o
}

that’s my commands.cfg:

define command{
command_name event_RemoteRestartNAVServices
command_line $USER1$/RemoteRestartNAVServices.cmd $HOSTADDRESS$ $USER10$ $USER9$ “$ARG1$”
}


#11

Having definitions like

define command{
command_name   restart_svc
command_line   $USER1$/restart_svc.sh '$ARG1$' "$ARG2$"
}

define service {
   ...
   check_command           restart_svc!MicrosoftDynamicsNavServer$$NAV_PROD!MicrosoftDynamicsNavServer$$NAV_TEST
}

#!/bin/ksh
echo OUT:$*:

shows “OUT:MicrosoftDynamicsNavServer$NAV_PROD :” in the “Service Information” in the “Service State Information” so having $$ works as expected (when using single quotes).

[edit]$ARGV2$ -> $ARG2$ :-(.[/edit]


(Chris) #12

Hi Wolfgang,

I changed the double quote into a single quote and only used two dollar signs.

The script only receives MicrosoftDynamicsNavServerNAV_PROD without the dollar sign.
Why does it work on our Nagios, what’s the difference between our installations? :thinking:
I am running an old Nagios 3.5.1

……………………………….
I don’t get the colouring green at the Arguments. What’s the connection between the green $ARGV2$ and the green $NAV_PROD and $NAV_TEST

In my state of knowledge, $ARGV2$ has to be the complete string “MicrosoftDynamicsNavServer$$NAV_TEST“.

Thank you for your patience. I’m learning a lot from you and this case.
Chris :+1:


#13

As shown above the argument is passed correctly when used in a command_line definition. I’d guess that the behaviour is identical for event_handler.
The next point would be to check whether the arguments are correct in your cmd-script. Please try something like I showed above or post the contents of your script.


(Chris) #14

Hi,
okay let’s do this

that’s the service defintion:

that’s the commands.cfg:

to avoid complexity, I created a simple script called “RemoteRestartNTServicesTest.cmd” . It Job is to write the Arguments in a log-File:

and that’s the output, without dollar sign

regards,
Chris


#15
define service {
   ...
   check_command           restart_svc!MicrosoftDynamicsNavServer$$NAV_PROD!'MicrosoftDynamicsNavServer$$NAV_TEST'
   ...
}

define command{
   command_name   restart_svc
   command_line   $USER1$/restart_svc.sh '$ARG1$' "$ARG2$"
}

restart_svc.sh:

#!/bin/ksh
echo OUT:$*:$1:$2:

Plugin ouput in the GUI:
OUT:MicrosoftDynamicsNavServer$NAV_PROD 'MicrosoftDynamicsNavServer':MicrosoftDynamicsNavServer$NAV_PROD:'MicrosoftDynamicsNavServer':

As you can see it’s important to use quotes at some places.


(Chris) #16

Hi,

I copied your lines:

How can I display the output as seen in your posting:


#17

… as described above


(Chris) #18

Okay, now I know that my Linux doesn’t know anything about KornShell. I had to change the shebang into: #!/bin/sh

It still erases the dollar sign.

OUT:MicrosoftDynamicsNavServerNAV_PROD MicrosoftDynamicsNavServerNAV_TEST:MicrosoftDynamicsNavServerNAV_PROD:MicrosoftDynamicsNavServerNAV_TEST:


#19

Please check the setting of illegal_macro_output_chars in nagios.cfg. I’d expect that it contains a dollar sign.


(Chris) #20

That’s right, it contained a $

illegal_object_name_chars=~!$%^&*"|'<>?,()=

I deleted it