<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=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-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;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</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-AU link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal>Hi, I need to be able to send notifications via SMS in the
event that the email servers are unavailable, or the internet connection is
down. There is a server on the same network as the Nagios host that has a modem
installed and uses SMS Tools 3 to send messages. To send a message all I need
to do is place a file in a certain directory on that server, in a simple
format, and it does the rest.<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>So, I created a script called 'notify-by-sms' in
/usr/local/nagios/libexec which is as follows:<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>TMPFILE=`/bin/mktemp notify.XXXXXX`<o:p></o:p></p>

<p class=MsoNormal>/bin/echo -e $1 > $TMPFILE<o:p></o:p></p>

<p class=MsoNormal>/usr/bin/scp $TMPFILE sms-server:/var/spool/sms/outgoing/<o:p></o:p></p>

<p class=MsoNormal>rm $TMPFILE<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>The script is owned by the user nagios and is executable. To
run it I just need to pass it a string like "To:
<phonenumber>\n\n<messagebody>" as the only parameter. If I
run it from the command line while logged in as nagios it works fine.<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>I have the following in commands.cfg which I adapted from
notify-service-by-email and notify-host-by-email:<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal># 'notify-host-by-sms' command definition<o:p></o:p></p>

<p class=MsoNormal>define command{<o:p></o:p></p>

<p class=MsoNormal>command_name notify-host-by-sms<o:p></o:p></p>

<p class=MsoNormal>command_line /usr/local/nagios/libexec/notify-by-sms
"To: $CONTACTPAGER$\n\n***** Nagios *****\n\nNotification Type:
$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: HOSTSTATE$\nAddress:
$HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"<o:p></o:p></p>

<p class=MsoNormal>}<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal># 'notify-service-by-sms' command definition<o:p></o:p></p>

<p class=MsoNormal>define command{<o:p></o:p></p>

<p class=MsoNormal>command_name notify-service-by-sms<o:p></o:p></p>

<p class=MsoNormal>command_line /usr/local/nagios/libexec/notify-by-sms
"To: $CONTACTPAGER$\n\n***** Nagios *****\n\nNotification Type:
$NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: HOSTALIAS$\nAddress:
$HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional
Info:\n\n$SERVICEOUTPUT$"<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>}<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>I see the following in /usr/local/nagios/var/nagios.log, as
an example (I have replaced some things with <...>):<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>[1196327641] SERVICE NOTIFICATION:
<contactname>;<servername>;SyncServer;CRITICAL;notify-service-by-sms;CRITICAL
- Error Fetching http://<ipaddress>/sync/ds [503] Service Temporarily
Unavailable<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>however the sms is not received. It does not even appear in
the log on the SMS server which indicates the script isn't running or isn't
able to scp the file to that server. I am using public key authentication to
negate the need for a SSH password to be entered.<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Any ideas what the problem could be, when it runs manually
from the command line but not through the nagios daemon?<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal>Thank you,<o:p></o:p></p>

<p class=MsoNormal>Nick<o:p></o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

<p class=MsoNormal><o:p> </o:p></p>

</div>

</body>

</html>