<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
h3
{mso-style-priority:9;
mso-style-link:"Heading 3 Char";
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:13.5pt;
font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
{mso-style-priority:99;
mso-style-link:"Balloon Text Char";
margin:0in;
margin-bottom:.0001pt;
font-size:8.0pt;
font-family:"Tahoma","sans-serif";}
span.Heading3Char
{mso-style-name:"Heading 3 Char";
mso-style-priority:9;
mso-style-link:"Heading 3";
font-family:"Times New Roman","serif";
font-weight:bold;}
span.BalloonTextChar
{mso-style-name:"Balloon Text Char";
mso-style-priority:99;
mso-style-link:"Balloon Text";
font-family:"Tahoma","sans-serif";}
span.EmailStyle20
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.EmailStyle21
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle22
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle23
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle24
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle25
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle26
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle27
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle28
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:#1F497D;}
span.EmailStyle29
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">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.
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Jamie<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Parkman, Mikhail [mailto:Mikhail_Parkman@cable.comcast.com]
<br>
<b>Sent:</b> Friday, March 30, 2012 8:43 PM<br>
<b>To:</b> Nagios Users List<br>
<b>Subject:</b> Re: [Nagios-users] how to associate /bin/bash with shell script in Nagios<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">The script represents in Nagios terms external application.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">It runs on the local (monitoring) box.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Script due to its content makes connection to the mbeans on the remote server (target box),<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">receives notifications from mbeans, and then writes to the external fifo file (usr/local/nagios/var/rw/nagios.cmd)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">message in the predefined format:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal">PROCESS_SERVICE_CHECK_RESULT;<host_name>;<service_description>;<return_code>;<plugin_output><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">One message for one notification.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">It looks to me that “remote stuff” is not applicable in that case.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">When I run this script manually on the local monitoring host, it runs and writes data to the file.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">When it is initiated by service defined on the same monitoring host in the .cfg file, nothing happens.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">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?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Mikhail.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> James Pratt [mailto:jpratt@norwich.edu]
<br>
<b>Sent:</b> Friday, March 30, 2012 12:19 PM<br>
<b>To:</b> Nagios Users List<br>
<b>Subject:</b> Re: [Nagios-users] how to associate /bin/bash with shell script in Nagios<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">Yes I agree with Ed as well on the remote stuff -
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">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.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I would definitely try and execute it as the nagios user - that is all that is left in your case it seems (?)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Edwin Zoeller
<a href="mailto:[mailto:Edwin.Zoeller@ama-assn.org]">[mailto:Edwin.Zoeller@ama-assn.org]</a>
<br>
<b>Sent:</b> Friday, March 30, 2012 3:11 PM<br>
<b>To:</b> 'nagios-users@lists.sourceforge.net'<br>
<b>Subject:</b> Re: [Nagios-users] how to associate /bin/bash with shell script in Nagios<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">If this is run on a remote host using nrpe this what I would check:<br>
<br>
- type "which bash" on the remote host and make sure the path matches what's in your script.<br>
<br>
- verify your nrpe.cfg has an entry in it for your script I.e "check_myscript"<br>
<br>
- verify on the master that check commands matches the remote entry<br>
<br>
Ed</span><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><br>
<o:p></o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">: Parkman, Mikhail
<a href="mailto:[mailto:Mikhail_Parkman@cable.comcast.com]">[mailto:Mikhail_Parkman@cable.comcast.com]</a>
<br>
<b>Sent</b>: Friday, March 30, 2012 01:50 PM<br>
<b>To</b>: Nagios Users List <<a href="mailto:nagios-users@lists.sourceforge.net">nagios-users@lists.sourceforge.net</a>>
<br>
<b>Subject</b>: Re: [Nagios-users] how to associate /bin/bash with shell script in Nagios
<br>
</span><span style="font-size:12.0pt;font-family:"Times New Roman","serif""> <o:p></o:p></span></p>
</div>
<p class="MsoNormal"><span style="color:#1F497D">Actually I verified that this script runs fine manually using default (Bourne) shell too.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">So now I have "#!/bin/sh" in the beginning of my script and it still is not being picked up by service.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">And I restart Nagios to initiate the service attempt.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Do you refer to Bourne shell ("#!/bin/sh" ) in this part of your explanation:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">“ (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)?”<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">If you do, and since I still can’t initiate the script should I su - nagios user anyway?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">And responding to Edwin’s question, it is on local host.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Mikhail.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> James Pratt
<a href="mailto:[mailto:jpratt@norwich.edu]">[mailto:jpratt@norwich.edu]</a> <br>
<b>Sent:</b> Friday, March 30, 2012 11:33 AM<br>
<b>To:</b> Nagios Users List<br>
<b>Subject:</b> Re: [Nagios-users] how to associate /bin/bash with shell script in Nagios<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">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)?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">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...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Cheers,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Jamie<o:p></o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Parkman, Mikhail
<a href="mailto:[mailto:Mikhail_Parkman@cable.comcast.com]">[mailto:Mikhail_Parkman@cable.comcast.com]</a>
<br>
<b>Sent:</b> Friday, March 30, 2012 1:28 PM<br>
<b>To:</b> Nagios Users List<br>
<b>Subject:</b> Re: [Nagios-users] how to associate /bin/bash with shell script in Nagios<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">Sorry for confusion - I was just trying different combinations.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">But initially my command definition was following:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">define command{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> command_name dlg_notifications<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> command_line /usr/local/nagios/libexec/nagios-msg-broker.sh<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I have "#!/bin/bash" in the top of my shell script, and shell script is set to be executable.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">perfserver-10:/usr/local/nagios/libexec$ ls -l nagios-msg-broker.sh<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">-rwxrwxrwx 1 nagios nagcmd 149 Mar 30 10:04 nagios-msg-broker.sh<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Thanks.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Mikhail.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> James Pratt
<a href="mailto:[mailto:jpratt@norwich.edu]">[mailto:jpratt@norwich.edu]</a> <br>
<b>Sent:</b> Friday, March 30, 2012 9:53 AM<br>
<b>To:</b> Nagios Users List<br>
<b>Subject:</b> Re: [Nagios-users] how to associate /bin/bash with shell script in Nagios<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">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)?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Cheers,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Jamie<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Parkman, Mikhail
<a href="mailto:[mailto:Mikhail_Parkman@cable.comcast.com]">[mailto:Mikhail_Parkman@cable.comcast.com]</a>
<br>
<b>Sent:</b> Friday, March 30, 2012 12:43 PM<br>
<b>To:</b> <a href="mailto:nagios-users@lists.sourceforge.net">nagios-users@lists.sourceforge.net</a><br>
<b>Subject:</b> [Nagios-users] how to associate /bin/bash with shell script in Nagios<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="color:#1F497D">Hello,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">I have the following command:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">define command{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> command_name dlg_notifications<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> command_line /bin/bash /usr/local/nagios/libexec/nagios-msg-broker.sh<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">And the following service<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">define service{<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> use mypc<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> service_description dlg_Alerts_notifications<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> check_command dlg_notifications<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> max_check_attempts 1<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> retain_status_information 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> retain_nonstatus_information 0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"> }<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">/bin/bash /usr/local/nagios/libexec/nagios-msg-broker.sh<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">runs fine manually.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Service defined above can’t run it though.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">While googling around, I found out that apparently Nagios does not know that script should be executed by /bin/bash<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">How would I let Nagios know about /bin/bash<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal">Thanks.<o:p></o:p></p>
<p class="MsoNormal">Mikhail.<o:p></o:p></p>
</div>
</body>
</html>