<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>BarryODonovan.com &#187; Recipes</title>
	<atom:link href="http://www.barryodonovan.com/index.php/category/recipes/feed" rel="self" type="application/rss+xml" />
	<link>http://www.barryodonovan.com</link>
	<description>The thoughts, ramblings and rants of Barry O&#039;Donovan</description>
	<lastBuildDate>Wed, 09 Dec 2009 14:30:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Linux on a Dell Vostro 200</title>
		<link>http://www.barryodonovan.com/index.php/2008/02/07/linux-dell-vostro-200</link>
		<comments>http://www.barryodonovan.com/index.php/2008/02/07/linux-dell-vostro-200#comments</comments>
		<pubDate>Thu, 07 Feb 2008 20:10:24 +0000</pubDate>
		<dc:creator>Barry O'Donovan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[Recipes]]></category>

		<guid isPermaLink="false">http://www.barryodonovan.com/index.php/2008/02/07/linux-dell-vostro-200/</guid>
		<description><![CDATA[Following a recent post to ILUG asking about setting Linux up on a Dell Vostro 200, I followed up with my notes from the time I had to do it a few months back. This is just a copy of my notes rather than a how-to but any competent Linux user should have no problem. [...]]]></description>
			<content:encoded><![CDATA[<p>Following <a href="http://mail.linux.ie/pipermail/ilug/2008-February/096736.html">a recent post</a> to <a href="http://mail.linux.ie/mailman/listinfo/ilug/">ILUG</a> asking about setting Linux up on a Dell Vostro 200, I <a href="http://mail.linux.ie/pipermail/ilug/2008-February/096741.html">followed up</a> with my notes from the time I had to do it a few months back.</p>
<p>This is just a copy of my notes rather than a how-to but any competent Linux user should have no problem. Apologies in advance for the brevity; with luck you&#8217;ll be using a later version of Linux which will already have solved the network issue&#8230; </p>
<p>The two main issues and fixes were:</p>
<ul>
<li> The SATA CD-ROM was not recognised initially and the fix was set the following parameter in the BIOS:
<p><code>BIOS -> Integrated Peripherals -> SATA Mode -> RAID</code></p>
<li> The network card is not recognised during a Linux install. Allow install to complete without network and then download Intel&#8217;s e1000 driver from <a href="http://downloadcenter.intel.com/">http://downloadcenter.intel.com/</a> or specifically <a href="http://downloadcenter.intel.com/Detail_Desc.aspx?agr=Y&#038;Inst=Yes&#038;ProductID=839&#038;DwnldID=9180&#038;strOSs=39&#038;OSFullName=Linux*&#038;lang=eng">by clicking here</a>. The one I used then was e1000-7.6.9.tar.gz but the current version appears to be e1000-7.6.15.tar.gz (where the above link heads to &#8211; check for later versions).
<p>My only notes of the install just say &#8220;essentially follow instructions in README&#8221; so I assume they were good enough! Obviously you&#8217;ll need Linux kernel headers at least as well as gcc and related tools.</p>
<p>Once built and installed, a:</p>
<p><code>modprobe e1000</code></p>
<p>should have you working. Use <code>dmesg</code> to confirm.
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.barryodonovan.com/index.php/2008/02/07/linux-dell-vostro-200/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Recovering an LVM Physical Volume</title>
		<link>http://www.barryodonovan.com/index.php/2007/12/08/lvm-recovery</link>
		<comments>http://www.barryodonovan.com/index.php/2007/12/08/lvm-recovery#comments</comments>
		<pubDate>Sat, 08 Dec 2007 18:28:24 +0000</pubDate>
		<dc:creator>Barry O'Donovan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[Recipes]]></category>

		<guid isPermaLink="false">http://www.barryodonovan.com/index.php/2007/12/08/lvm-recovery/</guid>
		<description><![CDATA[Yesterday disaster struck &#8211; during a CentOS/RedHat installation, the installer asked (not verbatim): &#8220;Cannot read partition information for /dev/sda. The drive must be initialized before continuing.&#8221;. Now on this particular server, sda and sdb were/are a RAID1 (containing the OS) and a RAID5 partition respectively and sdc was/is a 4TB RAID5 partition from an externally [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday disaster struck &#8211; during a CentOS/RedHat installation, the installer asked (not verbatim): &#8220;Cannot read partition information for <tt>/dev/sda</tt>. The drive must be initialized before continuing.&#8221;.</p>
<p>Now on this particular server, <tt>sda</tt> and <tt>sdb</tt> were/are a RAID1 (containing the OS) and a RAID5 partition respectively and <tt>sdc</tt> was/is a 4TB RAID5 partition from an externally attached disk chassis. This was a server re-installation and all data from <tt>sda</tt> and <tt>sdb</tt> had multiple snapshots off site. <tt>sdc</tt> had no backups of its 4TBs of data.</p>
<p>The installer discovered the drives in a different order and <tt>sda</tt> became the externally attached drive. I, believing it to be the internal RAID1 array, allowed the installer to initialise it. Oh shit&#8230;</p>
<p>Now this wouldn&#8217;t be the end of the world. It wasn&#8217;t backed up because a copy of the data exists on removable drives in the UK. It would mean someone flying in with the drives, handing them off to me at the airport, bringing them to the data center and copying all the data back. Then returning the drives to the UK again. A major inconvenience. And it&#8217;s also an embarrassment as I should have ensured that <tt>sda</tt> is what I thought it was via the installers other screens.</p>
<p>Anyway &#8211; from what I could make out, the installer initialised the drive with a single partition spanning the entire drive.</p>
<p>Once I got the operating system reinstalled, I needed to try and recover the LVM partitions. There&#8217;s not a whole lot of obvious information on the Internet for this and hence why I&#8217;m writing this post.</p>
<p>The first thing I needed to do was recreate the physical volume. Now, as I said above, I had backups of the original operating system. LVM creates a file containing the metadata of each volume group in <tt>/etc/lvm/backup</tt> in a file named the same as the volume group name. In this file, there is a section listing the physical volumes and their ids that make up the volume group. For example (the id is fabricated):</p>
<pre>
physical_volumes {
        pv0 {
                id = "fvrw-GHKde-hgbf43-JKBdew-rvKLJc-cewbn"
                device = "/dev/sdc"     # Hint only

                status = ["ALLOCATABLE"]
                pe_start = 384
                pe_count = 1072319      # 4.09057 Terabytes
        }
}
</pre>
<p>Note that after I realised my mistake, I installed the OS on the correct partition and after booting, the external drive became <tt>/dev/sdc</tt><sup>*</sup> again. Now, to recreate the physical volume <strong>with the same id</strong>, I tried:</p>
<pre>
# pvcreate -u fvrw-GHKde-hgbf43-JKBdew-rvKLJc-cewbn /dev/sdc
  Device /dev/sdc not found (or ignored by filtering).
</pre>
<p>Eh? By turning on verbosity, you find the reason among a few hundred lines of debugging:</p>
<pre>
# pvcreate -vvvv -u fvrw-GHKde-hgbf43-JKBdew-rvKLJc-cewbn /dev/sdc
...
#filters/filter.c:121         /dev/sdc: Skipping: Partition table signature found
#device/dev-io.c:486         Closed /dev/sdc
#pvcreate.c:84   Device /dev/sdc not found (or ignored by filtering).
</pre>
<p>So pvcreate will not create a physical volume using the entire disk unless I remove partition(s) first. I do this with <tt>fdisk</tt> and try again:</p>
<pre>
# pvcreate -u fvrw-GHKde-hgbf43-JKBdew-rvKLJc-cewbn /dev/sdc
  Physical volume "/dev/sdc" successfully created
</pre>
<p>Great. Now to recreate the volume group on this physical volume:</p>
<pre>
# vgcreate -v md1000 /dev/sdc
    Wiping cache of LVM-capable devices
    Adding physical volume '/dev/sdc' to volume group 'md1000'
    Archiving volume group "md1000" metadata (seqno 0).
    Creating volume group backup "/etc/lvm/backup/md1000" (seqno 1).
  Volume group "md1000" successfully created
</pre>
<p>Now I have an &#8220;empty&#8221; volume group but with no logical volumes. I know all the data is there as the initialization didn&#8217;t format or wipe the drive. I&#8217;ve retrieved the LVM backup file called <tt>md1000</tt> and placed it in <tt>/tmp/lvm-md1000</tt>. When I try to restore it to the new volume group I get:</p>
<pre>
# vgcfgrestore -f /tmp/lvm-md1000 md1000
  /tmp/lvm-md1000: stat failed: Permission denied
  Couldn't read volume group metadata.
  Restore failed.
</pre>
<p>After a lot of messing, I copied it to <tt>/etc/lvm/backup/md1000</tt> and tried again:</p>
<pre>
# vgcfgrestore -f /etc/lvm/backup/md1000 md1000
  Restored volume group md1000
</pre>
<p>I don&#8217;t know if it was the location, the renaming or both but it worked. </p>
<p>Now the last hurdle is that on a <tt>lvdisplay</tt>, the logical volumes show up but are marked as:</p>
<pre>
  LV Status              NOT available
</pre>
<p>This is easily fixed by marking the logical volumes as available:</p>
<pre>
#  vgchange -ay
  2 logical volume(s) in volume group "md1000" now active
</pre>
<p>Agus sin é. My logical volumes are recovered with all data intact.</p>
<p><sup>*</sup> <em>how these are assigned is not particularly relevant to this story.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryodonovan.com/index.php/2007/12/08/lvm-recovery/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Nagios Plugin to Check the Status of PRI Lines in Asterisk</title>
		<link>http://www.barryodonovan.com/index.php/2007/11/02/asterisk-pri-nagios</link>
		<comments>http://www.barryodonovan.com/index.php/2007/11/02/asterisk-pri-nagios#comments</comments>
		<pubDate>Fri, 02 Nov 2007 21:15:57 +0000</pubDate>
		<dc:creator>Barry O'Donovan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[Recipes]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[VoIP]]></category>

		<guid isPermaLink="false">http://www.barryodonovan.com/index.php/2007/11/02/nagios-plugin-to-check-the-status-of-pri-lines-in-asterisk/</guid>
		<description><![CDATA[I have a number of Asterisk implementations that I keep an eye on that have multiple PRI connections. Knowing if and when they ever go down has the obvious benefits of alerting me to a problem in near real time. But besides that, it allows my customers and I to verify SLAs, track and log [...]]]></description>
			<content:encoded><![CDATA[<p>I have a number of Asterisk implementations that I keep an eye on that have multiple PRI connections. Knowing if and when they ever go down has the obvious benefits of alerting me to a problem in near real time. But besides that, it allows my customers and I to verify SLAs, track and log issues, etc.</p>
<p>To this end, I have written <a href="http://www.opensolutions.ie/misc/check_asterisk_pri.php.txt">a Nagios plugin</a> which queries Asterisk&#8217;s manager interface and executes the <code>pri show spans</code> CLI command (this is Asterisk 1.4 by the way). The script then parses the output to ascertain whether a PRI is up or not. </p>
<p>The actual code to connect to the manager interface and execute the query is simply:</p>
<pre>
if( ( $astsock = fsockopen( $host, $port, $errno, $errstr, $timeout ) ) === false )
{
    echo "Could not connect to Asterisk manager: $errstr";
    exit( STATUS_CRITICAL );
}

fputs( $astsock, "Action: Login\r\n");
fputs( $astsock, "UserName: $username\r\n");
fputs( $astsock, "Secret: $password\r\n\r\n"); 

fputs( $astsock, "Action: Command\r\n");
fputs( $astsock, "Command: pri show spans\r\n\r\n");

fputs( $astsock, "Action: Logoff\r\n\r\n");

while( !feof( $astsock ) )
{
    $asttext .= fread( $astsock, 8192 );
}

fclose( $astsock );

if( strpos( $asttext, "Authentication failed" ) !== false )
{
    echo "Asterisk manager authentication failed.";
    exit( STATUS_CRITICAL );
}
</pre>
<p>This plugin is hard coded to English and expects to find <code>Provisioned, Up, Active</code> for a good PRI. For example, the Asterisk implementations that support the <code>pri show spans</code> command that I have access to return one of:</p>
<ul>
<li> <code>PRI span 1/0: Provisioned, In Alarm, Down, Active</code> </li>
<li> <code>PRI span 3/0: Provisioned, Up, Active</code> </li>
</ul>
<p>I&#8217;m actually running a slightly older version of Nagios at the moment, version 1.3. To integrate the plugin, first add the following command definition to an appropriate existing or new file under <code>/etc/nagios-plugings/config/</code>:</p>
<pre>
define command{
        command_name    check_asterisk_pri
        command_line    /usr/lib/nagios/plugins/check_asterisk_pri.php \\
             -H $HOSTADDRESS$ -U $ARG1$ -P $ARG2$ -w $ARG3$ \\
             -c $ARG4$ -n $ARG5$
}
</pre>
<p>where <code>$ARG1$</code> is the Asterisk manager username and <code>$ARG2$</code> is the password. <code>$ARG3$</code> and <code>$ARG4$</code> are the warning and critical thresholds respectively whereby if the number of available PRIs reaches one of these values, the appropriate error condition will be set. Lastly, <code>$ARG5$</code> is the number of PRIs the plugin should <string>expect</strong> to find. </p>
<p><strong>NB:</strong> the <code>command_line</code> line above is split for readability but it should all be on the one line.</p>
<p>Now create a test for a host in an appropriate file in <code>/etc/nagios/config/</code>:</p>
<pre>
define service{
        use                             core-service
        host_name                       hostname.domain.ie
        service_description             Asterisk PRIs
        check_command                   check_asterisk_pri!user!pass!2!1!4
}
</pre>
<p>Ensure that your Nagios server has permissions to access the Asterisk server via TCP on the Asterisk manager port (5038 by default). If on a public network, this should be done via stunnel or a VPN for security reasons. </p>
<p>Lastly, you&#8217;ll need a user with the appropriate permissions and host allow statements in your Asterisk configuration (<code>/etc/asterisk/manager.conf</code>):</p>
<pre>
[username]
secret = password
deny=0.0.0.0/0.0.0.0
permit=1.2.3.4/255.255.255.255
read = command
write = command
</pre>
<p>The next version may include support for BRI and Zap FXO ports also. I also plan on a Cacti plug in to show the channels on each PRI (up &#8211; on a call, down, etc). In any case, updates will be posted here.</p>
<p>The plug in can be download from: <a href="http://www.opensolutions.ie/misc/check_asterisk_pri.php.txt">http://www.opensolutions.ie/misc/check_asterisk_pri.php.txt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryodonovan.com/index.php/2007/11/02/asterisk-pri-nagios/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Easy PHP Search in Firefox</title>
		<link>http://www.barryodonovan.com/index.php/2007/10/25/kde-shortcut</link>
		<comments>http://www.barryodonovan.com/index.php/2007/10/25/kde-shortcut#comments</comments>
		<pubDate>Thu, 25 Oct 2007 13:48:36 +0000</pubDate>
		<dc:creator>Barry O'Donovan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[Recipes]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.barryodonovan.com/index.php/2007/10/25/kde-shortcut/</guid>
		<description><![CDATA[Niall has created a quick Opensearch file to add the PHP Function search to the search bar of Firefox 2 And IE7. If anyone is interested it&#8217;s available here. For those that don&#8217;t know, this feature has existing in KDE in multiple forms for some time. For example, pressing ALT-F2 opens the Run Command dialog [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.moybella.net/">Niall</a> <a href="http://blog.moybella.net/2007/10/25/php-manual-open-search-for-firefox-2-and-ie7/">has created</a> a quick <a href="http://www.opensearch.org/">Opensearch</a> file to add the PHP Function search to the search bar of Firefox 2 And IE7. If anyone is interested it&#8217;s available <a href="javascript:window.external.AddSearchProvider('http://blog.moybella.net/uploads/php.xml');">here</a>.</p>
<p>For those that don&#8217;t know, this feature has existing in KDE in multiple forms for some time. For example, pressing ALT-F2 opens the <em>Run Command</em> dialog and typing, for example:</p>
<pre>
php:fopen
</pre>
<p>will bring up PHP.net&#8217;s own search page. The same goes for the location bar in Konqueror.</p>
<p>By the way, other nice short cuts in the <em>Run Command</em> dialog include:</p>
<ul>
<li> <code>gg: &lt;keywords&gt;</code> for a quick Google search; </li>
<li> <code>wp: &lt;keywords&gt;</code> for a quick Wikipedia search; </li>
<li> <code>dict: &lt;keyword&gt;</code> for a quick dictionary look-up; </li>
<li> <code>man: &lt;keyword&gt;</code> for a man page look-up; </li>
<li> <code>info: &lt;keyword&gt;</code> for an info page look-up; </li>
<li> <code>rfc: &lt;number&gt;</code> to be brought to the relevant RFC page; </li>
</ul>
<p>Of course, entering a command will execute it and just entering a URL will open it in Konqueror.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryodonovan.com/index.php/2007/10/25/kde-shortcut/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Nagios Plugin for the Promise VTrak 200i</title>
		<link>http://www.barryodonovan.com/index.php/2007/06/06/nagios-promise-vtrak</link>
		<comments>http://www.barryodonovan.com/index.php/2007/06/06/nagios-promise-vtrak#comments</comments>
		<pubDate>Wed, 06 Jun 2007 20:03:53 +0000</pubDate>
		<dc:creator>Barry O'Donovan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[Recipes]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.barryodonovan.com/index.php/2007/06/06/nagios-promise-vtrak/</guid>
		<description><![CDATA[For a project I was working on, I installed a Promise VTrak M200i disk shelf (i for iSCSI but then that&#8217;s a whole other blog post!) and needed to add it into the customers management systems. Unfortunately there didn&#8217;t seem to be a lot of information out there on Promise&#8217;s SNMP MIBs so with a [...]]]></description>
			<content:encoded><![CDATA[<p>For a project I was working on, I installed a <a href="http://www.promise.com/product/product_detail_eng.asp?segment=VTrak&#038;product_id=151">Promise VTrak M200i</a> disk shelf (i for iSCSI but then that&#8217;s a whole other blog post!) and needed to add it into the customers management systems. </p>
<p>Unfortunately there didn&#8217;t seem to be a lot of information out there on Promise&#8217;s SNMP MIBs so with a bit of playing about, I was able to dig out the ones I needed. The Nagios plug-in I wrote and am making available here will monitor the shelf via SNMP and alert on the following chassis issues:</p>
<ul>
<li> critical if any of the shelf&#8217;s disk states changes from &#8220;OK&#8221;;
<li>
<li> warning if the battery state changes from &#8220;FullyCharged&#8221;; </li>
<li> critical if either of the PSU states change from &#8220;Powered On and Functional&#8221;; </li>
<li> critical is any of the cooling devices (fans) change from &#8220;Functional&#8221;; </li>
<li> critical if any of the temperature sensors&#8217; states change from &#8220;normal&#8221;; </li>
<li> critical if any of the drives go offline or are missing; and </li>
<li> warning if any of the drives go into the rebuilding state or have their PFA flag set. </li>
</ul>
<p>While this is specifically designed for a single M200i, it should be easily customisable for other models.</p>
<p>It can be downloaded from <a href="http://www.opensolutions.ie/misc/check_promise_chassis.pl">here</a> (<a href="http://www.opensolutions.ie/">http://www.opensolutions.ie/</a>). It will also appear on the <a href="http://www.barryodonovan.com/index.php/development/">development</a> section of this site and <a href="http://www.nagiosexchange.org/RAID_Controller.58.0.html?&#038;tx_netnagext_pi1[p_view]=1000&#038;tx_netnagext_pi1[page]=10%3A10">Nagios Plugins</a>.</p>
<h4>OIDs Used</h4>
<p></p>
<dl>
<dt><strong><tt>1.3.6.1.4.1.7933.1.10.2.1.1.1.8</tt></strong></dt>
<dd>The table of physical disk statuses.</dd>
<dt><strong><tt>.1.3.6.1.4.1.7933.2.1.7.1.1.14.1.1</tt></strong></dt>
<dd>The battery status.</dd>
<dt><strong><tt>.1.3.6.1.4.1.7933.2.1.4.1.1.2.1</tt></strong></dt>
<dd>The table of Power Supply Unit statuses.</dd>
<dt><strong><tt>.1.3.6.1.4.1.7933.2.1.3.1.1.3.1</tt></strong></dt>
<dd>The table of cooling device/fan statuses.</dd>
<dt><strong><tt>.1.3.6.1.4.1.7933.2.1.5.1.1.3</tt></strong></dt>
<dd>The table of temperature sensor statuses.</dd>
<dt><strong><tt>.1.3.6.1.4.1.7933.1.10.1.2.1.1.22.1</tt></strong></dt>
<dd>The number of drives that are offline.</dd>
<dt><strong><tt>.1.3.6.1.4.1.7933.1.10.1.2.1.1.23.1</tt></strong></dt>
<dd>The number of drives in the PFA status set.</dd>
<dt><strong><tt>.1.3.6.1.4.1.7933.1.10.1.2.1.1.24.1</tt></strong></dt>
<dd>The number of drives in rebuild status.</dd>
<dt><strong><tt>.1.3.6.1.4.1.7933.1.10.1.2.1.1.25.1</tt></strong></dt>
<dd>The number of drives that are missing.</dd>
</dl>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryodonovan.com/index.php/2007/06/06/nagios-promise-vtrak/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Nagios Alerts via SMS with Kapow</title>
		<link>http://www.barryodonovan.com/index.php/2007/05/19/nagios-sms-kapow</link>
		<comments>http://www.barryodonovan.com/index.php/2007/05/19/nagios-sms-kapow#comments</comments>
		<pubDate>Sat, 19 May 2007 11:12:50 +0000</pubDate>
		<dc:creator>Barry O'Donovan</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[OSS]]></category>
		<category><![CDATA[Recipes]]></category>

		<guid isPermaLink="false">http://www.barryodonovan.com/index.php/2007/05/19/nagios-sms-kapow/</guid>
		<description><![CDATA[I have a client who required a Nagios installation with alerting via SMS (*). They use Kapow as their SMS gateway. There were two aspects required: The sending of alerts via the SMS gateway; The monitoring of available credits on the SMS gateway; &#160; 1. Send Alerts via SMS Gateway The sendsms script is: #! [...]]]></description>
			<content:encoded><![CDATA[<p>I have a client who required a <a href="http://nagios.org/">Nagios</a> installation with alerting via SMS (*). They use <a href="http://www.kapow.co.uk/">Kapow</a> as their SMS gateway.</p>
<p>There were two aspects required:</p>
<ol>
<li> The sending of alerts via the SMS gateway; </li>
<li> The monitoring of available credits on the SMS gateway; </li>
</ol>
<p>&nbsp;</p>
<h4>1. Send Alerts via SMS Gateway</h4>
<p>The <code>sendsms</code> script is:</p>
<pre>
#! /bin/bash

USERNAME=username
PASSWORD=password
SENDSMSADDRESS="https://www.kapow.co.uk/scripts/sendsms.php"
MAXMSGLENGTH=320

read -n $MAXMSGLENGTH -r MSG

MSG=`php -r "echo urlencode( \"$MSG\" );"`

wget -q -O - "$SENDSMSADDRESS?username=$USERNAME&#038;password=$PASSWORD&#038;mobile=$1&#038;sms=$MSG"
</pre>
<p>I use a quick hack with PHP to URL encode the string. I didn&#8217;t know a shell command off hand but I&#8217;m open to suggestions. This can be tested with:</p>
<pre>
echo This is a test message | sendsms 353861234567
</pre>
<p>Edit <code>/etc/nagios/misccommands.cfg</code> to include the following:</p>
<pre>
# 'host-notify-by-sms' command definition
define command{
        command_name    host-notify-by-sms
        command_line    /usr/bin/printf "%b" "Host '$HOSTALIAS$' is $HOSTSTATE$: $OUTPUT$" | /usr/local/bin/sendsms $CONTACTPAGER$
        }

# 'notify-by-sms' command definition
define command{
        command_name    notify-by-sms
        command_line    /usr/bin/printf "%b" "$NOTIFICATIONTYPE$: $SERVICEDESC$@$HOSTNAME$: $SERVICESTATE$ ($OUTPUT$)" | /usr/local/bin/sendsms $CONTACTPAGER$
        }
</pre>
<p>Ensure your <code>/etc/nagios/contacts.cfg</code> is updated to include notification by SMS with your mobile number:</p>
<pre>
define contact{
        contact_name                    barryo
        alias                           Barry O'Donovan
        service_notification_period     barryoworkhours
        host_notification_period        barryoworkhours
        service_notification_options    w,u,c,r
        host_notification_options       d,u,r
        service_notification_commands   notify-by-email,notify-by-sms
        host_notification_commands      host-notify-by-email,host-notify-by-sms
        email                           joe@bloggs.com
        pager                           353868017669
}
</pre>
<p>Sin é.</p>
<p>&nbsp;</p>
<h4>2. Monitor SMS Gateway Credits</h4>
<p>The plugin code is:</p>
<pre>
#! /bin/bash

USERNAME=username
PASSWORD=password
CHECKCREDITSADDRES="https://www.kapow.co.uk/scripts/chk_credit.php"

CRIT=$1
WARN=$2

CREDITS=`wget -q -O - "$CHECKCREDITSADDRES?username=$USERNAME&#038;password=$PASSWORD"`

if [[ -z $CREDITS || ! $CREDITS -ge 0 ]]; then
        echo -e "$CREDITS\\n";
        exit 3;
elif [[ $CREDITS -le $CRIT ]]; then
        echo -e "$CREDITS SMS credits remaining\\n";
        exit 2;
elif [[ $CREDITS -le $WARN ]]; then
        echo -e "$CREDITS SMS credits remaining\\n";
        exit 1;
else
        echo -e "$CREDITS SMS credits remaining\\n";
        exit 0;
fi
</pre>
<p>Create a plugin configuration file for Nagios, say <code>/etc/nagios-plugins/config/sms_credits.cfg</code>:</p>
<pre>
# 'check_sms_credits' command definition
define command{
        command_name    check_sms_credits
        command_line    /usr/local/bin/check_sms_credit $ARG2$ $ARG1$
        }
</pre>
<p>Where <code>$ARG1$</code> is the warning threshold and <code>$ARG2$</code> is the critical threshold.</p>
<p>I add the service to the Nagios monitoring box via <code>/etc/nagios/config/sms_credit.cfg</code>:</p>
<pre>
#
# check sms credits on Kapow - barryo 20070519
#

define service{
        use                             core-service
        host_name                       noc
        service_description             SMS Credits
        check_command                   check_sms_credits!50!100
}
</pre>
<p>And I believe that&#8217;s it.</p>
<p>*) The monitoring box is in a different country to the servers it monitors so a network failure will not prevent the alert getting out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryodonovan.com/index.php/2007/05/19/nagios-sms-kapow/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
