ok it's really very simple - find the exact command definition string you want 
to execute in your commands.cfg, and su - nagios (as root) and then 
interactively (like actually type it right?) the same exact command that the 
command definition is attempting to execute as the nagios user, and see if it 
works -  Note, this is only to debug, or test your configuration - you do not 
want to setup your script to su - nagios  or anything like that ... sorry if i 
was not clear on that - what you want to do is "mimic exactly" the command 
nagios is attempting to execute, that is all, it's just for testing. if you can 
figure out why that is not working as the nagios user (This is the account the 
nagios program runs as right?), then that is where your problem is, so i'm 
sorry - it's not a solution, it's only the best way to find your problem, as 
that is the apparent issue  - as you say - it runs correctly otherwise.

Jamie

From: Parkman, Mikhail [mailto:mikhail_park...@cable.comcast.com]
Sent: Friday, March 30, 2012 8:43 PM
To: Nagios Users List
Subject: Re: [Nagios-users] how to associate /bin/bash with shell script in 
Nagios

The script represents in Nagios terms external application.
It runs on the local (monitoring) box.
Script due to its content makes connection to the mbeans on the remote server 
(target box),
receives notifications from mbeans, and then writes to the external fifo file 
(usr/local/nagios/var/rw/nagios.cmd)

message in the predefined format:

PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<return_code>;<plugin_output>

One message for one notification.

It looks to me that “remote stuff” is not applicable in that case.

When I run this script manually on the local monitoring host, it runs and 
writes data to the file.
When it is initiated by service defined on the same monitoring host in the .cfg 
file, nothing happens.

If I want this script to be initiated by “su – nagios”, how exactly I 
incorporate it within existing command and service definitions on the 
monitoring host?

Thanks.
Mikhail.

From: James Pratt [mailto:jpr...@norwich.edu]
Sent: Friday, March 30, 2012 12:19 PM
To: Nagios Users List
Subject: Re: [Nagios-users] how to associate /bin/bash with shell script in 
Nagios

Yes I agree with Ed as well on the remote stuff -

And yes, the *nix OS determines what shell/program (eg perl/bash/sh/zsh etc) to 
execute the script with by the shebang line in the top of the file, and whether 
or not it's executable.

I would definitely try and execute it as the nagios user - that is all that is 
left in your case it seems (?)

From: Edwin Zoeller 
[mailto:edwin.zoel...@ama-assn.org]<mailto:[mailto:edwin.zoel...@ama-assn.org]>
Sent: Friday, March 30, 2012 3:11 PM
To: 'nagios-users@lists.sourceforge.net'
Subject: Re: [Nagios-users] how to associate /bin/bash with shell script in 
Nagios

If this is run on a remote host using nrpe this what I would check:

- type "which bash" on the remote host and make sure the path matches what's in 
your script.

- verify your nrpe.cfg has an entry in it for your script I.e "check_myscript"

- verify on the master that check commands matches the remote entry

Ed

From: Parkman, Mikhail 
[mailto:mikhail_park...@cable.comcast.com]<mailto:[mailto:mikhail_park...@cable.comcast.com]>
Sent: Friday, March 30, 2012 01:50 PM
To: Nagios Users List 
<nagios-users@lists.sourceforge.net<mailto:nagios-users@lists.sourceforge.net>>
Subject: Re: [Nagios-users] how to associate /bin/bash with shell script in 
Nagios

Actually I verified that this script runs fine manually using default (Bourne) 
shell too.
So now I have "#!/bin/sh" in the beginning of my script and it still is not 
being picked up by service.
And I restart Nagios to initiate the service attempt.
Do you refer to Bourne shell ("#!/bin/sh" ) in  this part of your explanation:

“ (If it's a shell script, nagios will execute it using the proper interpreter, 
so there is no way to "tell" nagios to use bash if that makes sense)?”

If you do, and since I still  can’t initiate the script should I su - nagios 
user anyway?

And responding to Edwin’s question, it is on local host.

Thanks.
Mikhail.

From: James Pratt 
[mailto:jpr...@norwich.edu]<mailto:[mailto:jpr...@norwich.edu]>
Sent: Friday, March 30, 2012 11:33 AM
To: Nagios Users List
Subject: Re: [Nagios-users] how to associate /bin/bash with shell script in 
Nagios

Ok, so it's working fine when you run it from the command line, but not for 
nagios user, correct? (If it's a shell script, nagios will execute it using the 
proper interpreter, so there is no way to "tell" nagios to use bash if that 
makes sense)?

I usually su - nagios user, then try and run it from that user account - that's 
usually where the problem is, it runs fine  for root or whoever, but fails for 
the nagios user for whatever reason...

Cheers,
Jamie
From: Parkman, Mikhail 
[mailto:mikhail_park...@cable.comcast.com]<mailto:[mailto:mikhail_park...@cable.comcast.com]>
Sent: Friday, March 30, 2012 1:28 PM
To: Nagios Users List
Subject: Re: [Nagios-users] how to associate /bin/bash with shell script in 
Nagios

Sorry for confusion - I was just trying different combinations.

But initially my command definition was following:

define command{
        command_name    dlg_notifications
        command_line    /usr/local/nagios/libexec/nagios-msg-broker.sh
        }

I have "#!/bin/bash" in the top of my shell script, and shell script is set to 
be executable.

perfserver-10:/usr/local/nagios/libexec$ ls -l nagios-msg-broker.sh
-rwxrwxrwx 1 nagios nagcmd 149 Mar 30 10:04 nagios-msg-broker.sh

Thanks.
Mikhail.

From: James Pratt 
[mailto:jpr...@norwich.edu]<mailto:[mailto:jpr...@norwich.edu]>
Sent: Friday, March 30, 2012 9:53 AM
To: Nagios Users List
Subject: Re: [Nagios-users] how to associate /bin/bash with shell script in 
Nagios

I'm slightly confused - Do you have "#!/bin/bash" in the top of your shell 
script, and is it set to be executable by (at least) the nagios user?  (Not 
sure why you are calling bash then the script name as an arg, that is odd to 
me, but maybe I'm missing something)?

Cheers,
Jamie

From: Parkman, Mikhail 
[mailto:mikhail_park...@cable.comcast.com]<mailto:[mailto:mikhail_park...@cable.comcast.com]>
Sent: Friday, March 30, 2012 12:43 PM
To: 
nagios-users@lists.sourceforge.net<mailto:nagios-users@lists.sourceforge.net>
Subject: [Nagios-users] how to associate /bin/bash with shell script in Nagios

Hello,

I have the following command:

define command{
        command_name    dlg_notifications
        command_line    /bin/bash /usr/local/nagios/libexec/nagios-msg-broker.sh
        }

And the following service

define service{
       use                             mypc
       service_description                                 
dlg_Alerts_notifications
       check_command                                      dlg_notifications
       max_check_attempts                             1
       retain_status_information                    0
       retain_nonstatus_information            0
       }

/bin/bash /usr/local/nagios/libexec/nagios-msg-broker.sh
runs fine manually.

Service defined above can’t run it though.
While googling around, I found out that apparently Nagios does not know that 
script should be executed by /bin/bash

How would I let Nagios know about /bin/bash

Thanks.
Mikhail.
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Nagios-users mailing list
Nagios-users@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

Reply via email to