<?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>Marcus Nyberg &#187; nagios</title>
	<atom:link href="http://www.marcusnyberg.com/category/nagios/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marcusnyberg.com</link>
	<description>Digital and dangerous</description>
	<lastBuildDate>Mon, 26 Jul 2010 11:00:16 +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>Nagios plugin for checking ping in bash</title>
		<link>http://www.marcusnyberg.com/2010/06/24/nagios-plugin-for-checking-ping-in-bash/</link>
		<comments>http://www.marcusnyberg.com/2010/06/24/nagios-plugin-for-checking-ping-in-bash/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 08:16:19 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[nagios]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=589</guid>
		<description><![CDATA[Everyone that uses Nagios knows about the basic check_ping plugin. However, today I needed a light version in bash with the same functionality that its easy to modify&#8230; The result is seen below. My Nagios ping-plugin checks the rtt avg time against the treshold values for critical and warning. I never bothered to check for [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone that uses <a href="http://www.nagios.org/">Nagios</a> knows about the basic <strong>check_ping</strong> plugin. However, today I needed a light version in bash with the same functionality that its easy to modify&#8230;</p>
<p>The result is seen below. My Nagios ping-plugin checks the rtt avg time against the treshold values for critical and warning. I never bothered to check for packet losses because that wasn&#8217;t the purpose for this script. It only checks ping avg time but could easily be customized to check other things as well.</p>
<p><strong>nagios-check-ping.sh</strong></p>
<pre name="code" class="xml">
#!/bin/bash

# This script pings a host and compares critical and warning tresholds against avg rtt (ms)
# Syntax: nagios-check-ping.sh HOST CRITICAL WARNING
# Example: nagios-check-ping.sh www.sunet.se 10 20

if [ ! -n "$1" ]
then
	echo "UNKNOWN: Missing argument HOSTNAME..."
	exit 3
fi   

if [ ! -n "$2" ]
then
	echo "UNKNOWN: Missing argument WARNING..."
	exit 3
fi   

if [ ! -n "$3" ]
then
	echo "UNKNOWN: Missing argument CRITICAL..."
	exit 3
fi   

AVG=`ping -n -c 5 $1 | awk -F/ '/^rtt/ { print $5 }' | awk -F '.' '{ print $1; }'`

if [ ! -n "$AVG" ]
then
	echo "CRITICAL: Error pinging"
	exit 2
elif [ $AVG -le "$2" ]
then
	SC="OK"
	EX=0
elif [ $AVG -le "$3" ]
then
	SC="WARNING"
	EX=1
else
	SC="CRITICAL"
	EX=2
fi

echo "$SC: Average response time is $AVG ms"
exit $EX
</pre>
<p><strong>Run it like this:</strong><br />
> nagios-check-ping.sh www.sunet.se 10 20</p>
<p><strong>Example output:</strong><br />
WARNING Average response time is 20 ms</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2010/06/24/nagios-plugin-for-checking-ping-in-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Nagios check_nt over ssh-tunnel</title>
		<link>http://www.marcusnyberg.com/2010/01/04/nagios-check_nt-over-ssh-tunnel/</link>
		<comments>http://www.marcusnyberg.com/2010/01/04/nagios-check_nt-over-ssh-tunnel/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 14:21:02 +0000</pubDate>
		<dc:creator>marcus</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://www.marcusnyberg.com/?p=374</guid>
		<description><![CDATA[I am a big fan of Nagios for host and service monitoring and this is my first post on the subject. My task was to check services on a Windows Server with Nagios and NSClient++. But the firewall only allowed me to use ssh and thats why I could not connect to port 12489 (that [...]]]></description>
			<content:encoded><![CDATA[<p>I am a big fan of <a href="http://www.nagios.org/">Nagios</a> for host and service monitoring and this is my first post on the subject. My task was to check services on a Windows Server with Nagios and <a href="http://nsclient.org/nscp/">NSClient++</a>. But the firewall only allowed me to use ssh and thats why I could not connect to port 12489 (that NSClient listens to) from my Nagios server. The only way to solve the problem was to use a <a href="http://www.marcusnyberg.com/2010/01/04/bash-script-that-open-and-close-an-ssh-tunnel-automagically/">SSH-tunnel that I can open and close</a> whenever I needed to.</p>
<p><strong>Workflow for my solution</strong><br />
1. Nagios initiates that a service should be checked.<br />
2. Nagios executes the check_nt_by_ssh_tunnel check-command with additional parameters<br />
3. The script creates a ssh-tunnel<br />
4. The script checks the Windows server with the Nagios builtin command check_nt<br />
5. The script returns the check_nt output<br />
6. The script closes the ssh-tunnel<br />
7. Nagios does its processing.</p>
<p><strong>Prerequisites</strong><br />
* A fully working Nagios installation<br />
* NSClient installed and working on the Windows Server that should be monitored<br />
* <a href="http://bloggerdigest.blogspot.com/2006/11/ssh-auto-login-or-passwordless-login.html">SSH autologin</a> is configured between the two machines<br />
* Read <a href="http://www.marcusnyberg.com/2010/01/04/bash-script-that-open-and-close-an-ssh-tunnel-automagically/">my other article</a> for details about the SSH-tunnel used in this solution.</p>
<p>First you have to create the check-script on the Nagios server (in the Nagios libexec-folder). See below:</p>
<p><strong>check_nt_by_ssh_tunnel.sh</strong></p>
<pre name="code" class="html">
#!/bin/bash

# $1 = HOSTNAME, 83.121.233.2
# $2 = LOCAL PORT, 14880
# $3 = USERNAME, ex: someusername
# $4 = CHECK PARAMETERS, ex: -w 80 -c 90 -v MEMUSE

if [ -z "$1" ]
then
        echo "Missing HOSTNAME"
        exit
fi

if [ -z "$2" ]
then
        echo "Missing LOCAL PORT"
        exit
fi

if [ -z "$3" ]
then
        echo "Missing USERNAME"
        exit
fi

# Open ssh-tunnel and wait for it to open
ssh -f -N -L $2:localhost:12489 $3@$1 &#038;
sleep 30

# Run check_nt command
CHECK="/usr/local/nagios/libexec/check_nt -H localhost -p $2 $4"
#echo $CHECK
eval $CHECK

# Close ssh-tunnel
sleep 5
CMD="ps -eo pid,args | grep 'ssh -f -N -L $2:localhost' | grep -v  'grep' | cut -c1-6"
#echo $CMD
PID=`eval $CMD`
#echo $PID
kill -9 $PID
</pre>
<p>Make it executable:<br />
chmod 755 check_nt_by_ssh_tunnel.sh</p>
<p>Then verify that i works by running the command:<br />
./check_nt_by_ssh_tunnel.sh 83.121.233.2 14880 someusername &#8221;-w 80 -c 90 -v MEMUSE&#8221;</p>
<p>You should then either see a valid Nagios plugin-output or get an error-message. Make sure that is works! You may have to modify the script depending on your *nix OS.</p>
<p>Next modify Nagios checkcommands.cfg or similiar and add the following. This makes the command available for use in Nagios.</p>
<pre name="code" class="html">
# USAGE: check_nt_by_ssh_tunnel!11101!username!"-l 5,80,90 -v CPULOAD"
define command{
	command_name		check_nt_by_ssh_tunnel
	command_line		PATH_TO_COMMAND/check_nt_by_ssh_tunnel.sh $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$
}
</pre>
<p>Next add a service definition that uses the check-command.</p>
<pre name="code" class="html">
define service{
	use				       generic-service
        host_name                        MY_HOSTNAME
        service_description             Memory usage
        check_command                 check_nt_by_ssh_tunnel!11100!username!"-w 80 -c 90 -v MEMUSE"
}
</pre>
<p>The last step you need to do is to restart Nagios and check if it works.</p>
<p>* I recommend you to change the portnumber for each service-definition to avoid collisions. Make them unique to the service-check.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marcusnyberg.com/2010/01/04/nagios-check_nt-over-ssh-tunnel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
