<?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>An It-Slave in the digital saltmine &#187; bash</title>
	<atom:link href="http://www.it-slav.net/blogs/category/bash/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.it-slav.net/blogs</link>
	<description>Another Blog from a Geek that has no life</description>
	<lastBuildDate>Fri, 02 Jul 2010 07:33:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Enable Huawei E1750 in Ubuntu 10.04</title>
		<link>http://www.it-slav.net/blogs/2010/05/23/enable-huawei-e1750-in-ubuntu-10-04/</link>
		<comments>http://www.it-slav.net/blogs/2010/05/23/enable-huawei-e1750-in-ubuntu-10-04/#comments</comments>
		<pubDate>Sun, 23 May 2010 07:10:27 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Cool things]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Huawei]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=1792</guid>
		<description><![CDATA[&#160;
I&#8217;m the happay owner of a Huawei E1750 modem and it is real easy to get it running in Ubuntu. This guide will probably work with many other 3G USB&#160;modems.
Just type from the command line:

sudo apt-get install usb-modeswitch

Plug in the modem
Go to the Network manager and enter your Mobile Broadband credentials and now it works!
]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<p>I&#8217;m the happay owner of a Huawei E1750 modem and it is real easy to get it running in Ubuntu. This guide will probably work with many other 3G USB&nbsp;modems.</p>
<p>Just type from the command line:</p>
<pre>
sudo apt-get install usb-modeswitch
</pre>
<p>Plug in the modem</p>
<p>Go to the Network manager and enter your Mobile Broadband credentials and now it works!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2010/05/23/enable-huawei-e1750-in-ubuntu-10-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Share your internet connection</title>
		<link>http://www.it-slav.net/blogs/2010/02/12/share-your-internet-connection/</link>
		<comments>http://www.it-slav.net/blogs/2010/02/12/share-your-internet-connection/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 18:32:06 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Cool things]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[english]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=1592</guid>
		<description><![CDATA[&#160;
Background
I&#160;was with my geekfriends at a ski resort and I&#160;managed to get an Internet connection using a cellphone. Of course I&#160;wanted to share it with my friends. As geeks we brought a switch and a couple of ethernetcables.
&#160;
Solution
Using this script on a Ubuntu 9.10 I&#160;managed to share my connection:

sudo ifconfig eth0 10.8.16.1
sudo sysctl -w net.ipv4.ip_forward=1
sudo [...]]]></description>
			<content:encoded><![CDATA[<p>&nbsp;</p>
<h2>Background</h2>
<p>I&nbsp;was with my geekfriends at a ski resort and I&nbsp;managed to get an Internet connection using a cellphone. Of course I&nbsp;wanted to share it with my friends. As geeks we brought a switch and a couple of ethernetcables.</p>
<p>&nbsp;</p>
<h2>Solution</h2>
<p>Using this script on a Ubuntu 9.10 I&nbsp;managed to share my connection:</p>
<pre>
sudo ifconfig eth0 10.8.16.1
sudo sysctl -w net.ipv4.ip_forward=1
sudo sysctl -w net.ipv4.conf.default.forwarding=1
sudo sysctl -w net.ipv4.conf.all.forwarding=1
sudo iptables -P FORWARD ACCEPT
sudo iptables --table nat -A POSTROUTING -o ppp0 -j MASQUERADE</pre>
<p>Conmnect everymachine with the switch and the clients just needed to use a 10.0.0.0/8 network adress and add 10.8.16.1 as default gateway and it works!</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2010/02/12/share-your-internet-connection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use Bluetooth phone to connect to Internet on Linux</title>
		<link>http://www.it-slav.net/blogs/2010/01/31/use-bluetooth-phone-to-connect-to-internet-on-linux/</link>
		<comments>http://www.it-slav.net/blogs/2010/01/31/use-bluetooth-phone-to-connect-to-internet-on-linux/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 18:50:52 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Cool things]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Bluetoth]]></category>
		<category><![CDATA[Cell Phone]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Phone]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=1567</guid>
		<description><![CDATA[My laptop and cellular phone has both Bluetooth and it has annoyed me for a while that I have not managed to get a working Internet connection using Bluetooth. I have only managed to get it working with a USB&#160;cable between my phone and laptop.
&#160;
After some Google search and reading of man pages I finally [...]]]></description>
			<content:encoded><![CDATA[<p>My laptop and cellular phone has both Bluetooth and it has annoyed me for a while that I have not managed to get a working Internet connection using Bluetooth. I have only managed to get it working with a USB&nbsp;cable between my phone and laptop.</p>
<p>&nbsp;</p>
<p>After some Google search and reading of man pages I finally get it working.</p>
<p><span id="more-1567"></span></p>
<p>&nbsp;</p>
<p>My setup is a <a href="http://www.it-slav.net/blogs/2009/11/19/review-nokia-e52/" target="_blank">Nokia E52</a> and a IBM T60 laptop running Ubuntu 9.10. I have tested it with a Ericsson P1i and a Dell D630 aswell and I think the guidlines below will work with many other setups. One exception is probably iPhone <img src='http://www.it-slav.net/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>&nbsp;</p>
<p>From a bash shell run:</p>
<pre>
peter@svarten:~$ sdptool search DUN
Inquiring ...
Searching for DUN on A8:7E:33:20:40:0F ...
Service Name: Dial-Up Networking
Service RecHandle: 0x10030
Service Class ID List:
  &quot;Dialup Networking&quot; (0x1103)
Protocol Descriptor List:
  &quot;L2CAP&quot; (0x0100)
  &quot;RFCOMM&quot; (0x0003)
    Channel: 5
Language Base Attr List:
  code_ISO639: 0x454e
  encoding:    0x6a
  base_offset: 0x100
Profile Descriptor List:
  &quot;Dialup Networking&quot; (0x1103)
    Version: 0x0100

peter@svarten:~$ sudo rfcomm connect 1 A8:7E:33:20:40:0F 5
[sudo] password for peter:
Connected /dev/rfcomm1 to A8:7E:33:20:40:0F on channel 5
Press CTRL-C for hangup
</pre>
<p>Now my phone asks if I accept the connection and I choose &quot;yes&quot;.</p>
<p>&nbsp;</p>
<p>And now the networkmanager has a new &quot;Mobile Broadband connection&quot;. Just choose your operator and it will work.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2010/01/31/use-bluetooth-phone-to-connect-to-internet-on-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Nagios or op5 Monitor eventhandler to start a service that has stopped</title>
		<link>http://www.it-slav.net/blogs/2009/06/15/using-nagios-or-op5-monitor-eventhandler-to-start-a-service-that-has-stopped/</link>
		<comments>http://www.it-slav.net/blogs/2009/06/15/using-nagios-or-op5-monitor-eventhandler-to-start-a-service-that-has-stopped/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 19:03:01 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Cool things]]></category>
		<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[MythTV]]></category>
		<category><![CDATA[Nagios]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[op5 Monitor]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=1138</guid>
		<description><![CDATA[Background
I use MythTV quite frequently and noticed that it is instable when using sasc-ng as a decoder to decrypt encrypted DVB-T channels. So approximatly every third day the MythTVbackend server stops and need to be started again. I have wriiten an earlier article about howto monitor MythTV with Nagios or op5 Monitor so I get [...]]]></description>
			<content:encoded><![CDATA[<h2>Background</h2>
<p>I use MythTV quite frequently and noticed that it is instable when using <a target="_blank" href="https://opensvn.csie.org/traccgi/sascng/">sasc-ng</a> as a decoder to decrypt encrypted DVB-T channels. So approximatly every third day the MythTVbackend server stops and need to be started again. I have wriiten an <a target="_blank" href="http://www.it-slav.net/blogs/?p=651">earlier article</a> about howto monitor MythTV with Nagios or op5 Monitor so I get noticed that it has stopped. But I need to manually start it again. This article describe howto make Nagios or op5 Monitor to start a stopped MythTVbackend. It can be used for starting almost any service.</p>
<p>I have used the examples provided by Ethan at <a target="_blank" href="http://support.nagios.com/knowledge-base/official-documentation">Nagios official documentation</a> describing <a target="_blank" href="http://nagios.sourceforge.net/docs/3_0/eventhandlers.html">eventhandlers</a>.</p>
<p>Normally it is not recommended to let a tool like Nagios or op5 Monitor start a service that has stopped, because it is probably a reason why the service has stopped and the correct procedure is to fix the root cause of the problem, not the symptom.</p>
<p>The MythTV backend runs on one machine called lala (after a character in Teletubbies) which is not the same as the Nagios or op5 Monitor server. I use nrpe to run the start script i.e.</p>
<pre>
 /etc/init.d/mythtv-backend start
</pre>
<p>There is several options here but I already setup the nrpe agent and it is simple to make Nagios or op5 Monitor to use nrpe to run a script.<span id="more-1138"></span></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>Implementation</h2>
<p>I used the script I found at Nagios documentation about <a target="_blank" href="http://nagios.sourceforge.net/docs/3_0/eventhandlers.html">eventhandlers</a> as a base and modiied it slightly.</p>
<p>&nbsp;</p>
<h3>At my op5 Monitor machine</h3>
<pre>
/opt/plugins/custom/restart-mythtv-lala.sh
</pre>
<pre>
#!/bin/sh
#
# Event handler script for restarting the mythTVbackend server on lala
#
# Note: This script will only restart the mythtvbackend if the service is
#       retried 2 times (in a &quot;soft&quot; state) or if the service somehow
#       manages to fall into a &quot;hard&quot; error state.
#

# What state is the mythbackend service in?
case &quot;$1&quot; in
OK)
	# The service just came back up, so don't do anything...
	;;
WARNING)
	# We don't really care about warning states, since the service is probably still running...
	;;
UNKNOWN)
	# We don't know what might be causing an unknown error, so don't do anything...
	;;
CRITICAL)
	# Aha!  The HTTP service appears to have a problem - perhaps we should restart the server...

	# Is this a &quot;soft&quot; or a &quot;hard&quot; state?
	case &quot;$2&quot; in

	# We're in a &quot;soft&quot; state, meaning that Nagios is in the middle of retrying the
	# check before it turns into a &quot;hard&quot; state and contacts get notified...
	SOFT)

		# What check attempt are we on?  We don't want to restart the web server on the first
		# check, because it may just be a fluke!
		case &quot;$3&quot; in

		# Wait until the check has been tried 3 times before restarting the web server.
		# If the check fails on the 4th time (after we restart the web server), the state
		# type will turn to &quot;hard&quot; and contacts will be notified of the problem.
		# Hopefully this will restart the web server successfully, so the 4th check will
		# result in a &quot;soft&quot; recovery.  If that happens no one gets notified because we
		# fixed the problem!
		2)
			echo &quot;`date` Restarting mythtv service (2rd soft critical state)...&quot; &gt;&gt; /tmp/mythtvstart
			# Call the init script to restart the mythbackend server
			#/etc/rc.d/init.d/httpd restart
			#date &gt;&gt; /tmp/mythtvstart
			/opt/plugins/check_nrpe -H lala -c start_mythtvbackend
			;;
			esac
		;;

	# The mythtvbackend service somehow managed to turn into a hard error without getting fixed.
	# It should have been restarted by the code above, but for some reason it didn't.
	# Let's give it one last try, shall we?
	# Note: Contacts have already been notified of a problem with the service at this
	# point (unless you disabled notifications for this service)
	HARD)
		echo &quot;`date` Restarting mythtv service (hard state)...&quot; &gt;&gt; /tmp/mythtvstart
		# Call the init script to restart the HTTPD server
		#/etc/rc.d/init.d/httpd restart
		#date &gt;&gt; /tmp/mythtvstart
		/opt/plugins/check_nrpe -H lala -c start_mythtvbackend
		;;
	esac
	;;
esac
exit 0
</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<pre>
/opt/monitor/misccomands.cfg</pre>
<pre>
# command 'restart-mythtv-lala'
define command{
    command_name                   restart-mythtv-lala
    command_line                   /opt/plugins/custom/start-mythtv-lala.sh $SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
    }
</pre>
<p>&nbsp;</p>
<pre>
/opt/monitor/etc/services.cfg

# service 'Mythbackend'
define service{
    use                            default-service
    host_name                      lala
    service_description            Mythbackend
    check_command                  check_tcp!6543
    servicegroups                  MythTV,it-slav
    event_handler                  restart-mythtv-lala!$SERVICESTATE$ $SERVICESTATETYPE$ $SERVICEATTEMPT$
    contact_groups                 it-slav_sms,it-slav_jabber,it_slav_mail
    }
</pre>
<h3>At my mythbackend machine lala</h3>
<pre>
/etc/nrpe.d/mycommands.cfg
command[start_mythtvbackend]=/usr/bin/sudo /etc/init.d/mythtv-backend start

/etc/sudoers
nobody ALL= (root) NOPASSWD:/etc/init.d/mythtv-backend start
</pre>
<address>Notice that my nrpe agent run as user nobody</address>
<address>&nbsp;</address>
<address>&nbsp;</address>
<address>&nbsp;</address>
<address>&nbsp;</address>
<h2>Test</h2>
<p>I stopped the mythtvbackend by running:</p>
<pre>
peter@lala:/etc/nrpe.d$ date
Mon Jun 15 20:40:55 CEST 2009
peter@lala:/etc/nrpe.d$ sudo /etc/init.d/mythtv-backend stop
 * Stopping MythTV server: mythbackend
</pre>
<p>And run</p>
<pre>
[root@op5 ~]# tail -f /tmp/mythtvstart
Mon Jun 15 20:47:09 CEST 2009 Restarting mythtv service (2rd soft critical state)...
</pre>
<p>YES it works!</p>
<p>&nbsp;</p>
<h2>Links:</h2>
<ul>
<li><a target="_blank" href="http://www.op5.com/op5/products/monitor">op5 Monitor</a> a Nagios based supported enterprise Monitoring software.</li>
<li><a target="_blank" href="http://www.mythtv.org">MythTV</a> a free OpenSource Digital Video Recorder</li>
<li><a href="http://www.nagios.org">Nagios</a> Open Source Monitoring</li>
</ul>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2009/06/15/using-nagios-or-op5-monitor-eventhandler-to-start-a-service-that-has-stopped/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ssh blocker OpenBSD</title>
		<link>http://www.it-slav.net/blogs/2009/02/09/ssh-blocker-openbsd/</link>
		<comments>http://www.it-slav.net/blogs/2009/02/09/ssh-blocker-openbsd/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 19:36:53 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Geek stuff]]></category>
		<category><![CDATA[OpenBSD]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[it-slav.net]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[firewall]]></category>
		<category><![CDATA[packetfilter]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=183</guid>
		<description><![CDATA[My firewall get alot of failed ssh logins.
This is a typical log message in /var/log/authlog
Feb  9 20:15:49 pedro sshd[30934]: Failed password for root from 67.205.85.119 port 35603 ssh2
Feb  9 20:15:49 pedro sshd[2656]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:51 pedro sshd[15299]: Failed password for root from 67.205.85.119 port 35753 ssh2
Feb  9 20:15:51 pedro [...]]]></description>
			<content:encoded><![CDATA[<p>My firewall get alot of failed ssh logins.</p>
<p>This is a typical log message in /var/log/authlog</p>
<pre>Feb  9 20:15:49 pedro sshd[30934]: Failed password for root from 67.205.85.119 port 35603 ssh2
Feb  9 20:15:49 pedro sshd[2656]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:51 pedro sshd[15299]: Failed password for root from 67.205.85.119 port 35753 ssh2
Feb  9 20:15:51 pedro sshd[15791]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:53 pedro sshd[9043]: Failed password for root from 67.205.85.119 port 35882 ssh2
Feb  9 20:15:53 pedro sshd[31484]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:54 pedro sshd[27717]: Failed password for root from 67.205.85.119 port 36030 ssh2
Feb  9 20:15:55 pedro sshd[30185]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:56 pedro sshd[27718]: Failed password for root from 67.205.85.119 port 36164 ssh2
Feb  9 20:15:56 pedro sshd[28005]: Received disconnect from 67.205.85.119: 11: Bye Bye
Feb  9 20:15:58 pedro sshd[30648]: Failed password for root from 67.205.85.119 port 36314 ssh2
Feb  9 20:15:58 pedro sshd[21087]: Received disconnect from 67.205.85.119: 11: Bye Bye
</pre>
<p>Of course this is a script kiddie that tries to break into my firewall just because it answers on port 22 and it is annoying. One way of make it a little harder to break in is by let the packetfilter drop all packages that comes from an ip-address that did this.</p>
<p>This one way of doing it.</p>
<p><span id="more-183"></span></p>
<p><br class="spacer_" /></p>
<h3>Create a pf blacklist /etc/pf.conf<br />
</h3>
<p>&#8211;snipp&#8211;</p>
<pre>table &lt;ssh_blacklist&gt; persist file "/var/pf/ssh_blacklist"
...</pre>
<pre>block in quick log on $ext_if from &lt;ssh_blacklist&gt; to any</pre>
<p>&#8211;snipp&#8211;</p>
<p><br class="spacer_" /></p>
<h3>Create a script that detects failed ssh breakin attempts and updates the blacklist</h3>
<pre>root@pedro:/var/log# cat /root/scripts/blockbadssh.sh
#!/bin/sh
logger "Check for bad ssh behavior"
PATH=/bin:/usr/bin
BL=/var/pf/ssh_blacklist
TEMPFILE=$(mktemp /tmp/bl_XXXXXX) || exit 1
TEMPFILE2=$(mktemp /tmp/bl2_XXXXXX) || exit 1

#cp $BL $TEMPFILE
grep "Invalid user" /var/log/authlog | awk '{print $10}' | sort | uniq &gt; $TEMPFILE2
grep "Failed password for invalid" /var/log/authlog | awk '{print $13}' | sort | uniq  &gt;&gt; $TEMPFILE2
grep "Failed password for root" /var/log/authlog | awk '{print $11}' | sort | uniq  &gt;&gt; $TEMPFILE2

sort $TEMPFILE2 |uniq &gt; $TEMPFILE
#echo "Nu är TEMPFILE"
#cat $TEMPFILE

#cat $BL &gt;&gt; $TEMPFILE
for i in `cat $TEMPFILE`
do
  grep $i $BL&gt;/dev/null
  if [ "$?" == "1" ]
  then
    logger "Added $i to ssh-blacklist"
    echo "Added $i to ssh-blacklist"
  fi
done

cat $BL &gt;&gt; $TEMPFILE
sort $TEMPFILE | uniq &gt; $BL

rm $TEMPFILE
rm $TEMPFILE2

/sbin/pfctl -t ssh_blacklist -Treplace -f $BL 2&gt;&amp;1 | grep -v "no changes"
</pre>
<h3>Make it run every minute</h3>
<pre>root@pedro:/var/log# crontab -l </pre>
<pre>*     *       *       *       *       /root/scripts/blockbadssh.sh
</pre>
<p>I know this is a dirty way of doing it and it is a good idea to have another pf rule that accept traffic from well known hosts so you do not get blocked because you failed a login.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2009/02/09/ssh-blocker-openbsd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HowTo using passive checks with Nagios or op5 Monitor</title>
		<link>http://www.it-slav.net/blogs/2008/12/10/howto-using-passive-checks-with-nagios-or-op5-monitor/</link>
		<comments>http://www.it-slav.net/blogs/2008/12/10/howto-using-passive-checks-with-nagios-or-op5-monitor/#comments</comments>
		<pubDate>Wed, 10 Dec 2008 18:49:30 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Cool things]]></category>
		<category><![CDATA[Hints]]></category>
		<category><![CDATA[Links]]></category>
		<category><![CDATA[Nagios]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[graph]]></category>
		<category><![CDATA[op5 Monitor]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[nsca]]></category>
		<category><![CDATA[passive]]></category>
		<category><![CDATA[passive checks]]></category>
		<category><![CDATA[send_nsca]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=392</guid>
		<description><![CDATA[In some cases the &#34;Normal&#34; way of running checks does not work, passive checks might do the job. I have a script the runs every night that backup my MySQL database. If this script fails I would like op5 Monitor or Nagios to send a notification. An active check will not work in this case [...]]]></description>
			<content:encoded><![CDATA[<p>In some cases the &quot;Normal&quot; way of running checks does not work, passive checks might do the job. I have a script the runs every night that backup my MySQL database. If this script fails I would like op5 Monitor or Nagios to send a notification. An active check will not work in this case or is very cumbersome to get it to work. A more elegant solution is to let the backup script send in the result to op5 Monitor or Nagios. This is where passive checks is handy. A passive check trust that some external program will send in the result. It is possible to set check_freshness so if nothing has been sent in to op5 Monitor or Nagios it will react, typically set the status to UNKOWN or CRITICAL.</p>
<p><span id="more-392"></span></p>
<p>In my case the backup script is started on another host then op5 Monitor or Nagios server, so I also will need a way of sending the data from the passive check over the network, the recommended way is to use nsca. Read the theory at <a target="_blank" href="http://nagios.sourceforge.net/docs/3_0/addons.html#nsca">http://nagios.sourceforge.net/docs/3_0/addons.html#nsca</a></p>
<p>In my op5 Monitor system the nsca daemon to recieve nsca information was installed so I only had to start it:</p>
<p>/etc/init.d/nsca start</p>
<p>This is the steps I did to install it on the client:</p>
<p>1. Download nsca from <a target="_blank" href="http://sourceforge.net/project/showfiles.php?group_id=26589&amp;package_id=40242">here</a>.</p>
<p>&nbsp;</p>
<p>2. Untar and compile nsca</p>
<p>&nbsp;</p>
<p>3. Create a ncsa config file i.e. send_nsca.cfg</p>
<pre>
encryption_method=0
</pre>
<p>Now the data will be transmitted unencrypted over the network, this might not be what you want. Make sure that the corresponding nsca config file on the Nagios or op5 Monitor host has the same encryption method.</p>
<p>4. Create a passive check for testing.</p>
<pre>
# service 'Passive check test'</pre>
<pre>
define service{</pre>
<pre>
    use                            default-service</pre>
<pre>
    host_name                      dull</pre>
<pre>
    service_description            Passive check test</pre>
<pre>
    check_command                  check_dummy!3 &quot;No Data from passive check&quot;</pre>
<pre>
    max_check_attempts             1</pre>
<pre>
    active_checks_enabled          0</pre>
<pre>
    check_freshness                1</pre>
<pre>
    freshness_threshold            300</pre>
<pre>
    flap_detection_options         n</pre>
<pre>
    contact_groups                 it-slav_mail,call_it-slav,it-slav_msn</pre>
<pre>
    stalking_options               n</pre>
<pre>
    }</pre>
<p>Explanation:</p>
<p>The check_dummy command will be run if no passive check has been recieved within 5 minutes (300 seconds).</p>
<p>4. test</p>
<p>-First test, wait 5 minutes and your service &quot;Passive check test&quot; should be in status UNKNOWN</p>
<p>-Second test, create  a file passive_file_test_critical (the separator is TAB):</p>
<pre>
dull    Passive check test      2       CRITICAL:test critical</pre>
<p>run command:</p>
<pre>
send_nsca -H nagios_host  -c  send_nsca.cfg &lt; passive_check_data_critical</pre>
<p>and the status should change to CRITICAL</p>
<p>-Third test, create a file passive_check_data_ok (the separator is TAB):</p>
<pre>
dull    Passive check test      0       OK: test ok</pre>
<p>Run the command</p>
<pre>
send_nsca -H  nagios_host -c  send_nsca.cfg &lt; passive_check_data_ok</pre>
<p>And the status should change to OK</p>
<p>&nbsp;</p>
<p>Now you can set the status of a Nagios or op5 Monitor service by using commands that can be used in scripts. I will in a later article describe how I use it in my MySQL backup script.</p>
<p>Links:</p>
<ul>
<li><a target="_blank" href="http://nagios.sourceforge.net/docs/3_0/addons.html#nsca">NSCA</a></li>
<li>Nagios <a href="http://nagios.sourceforge.net/docs/3_0/passivechecks.html">passive check</a> theory</li>
<li><a target="_blank" href="http://www.op5.com/op5/products/monitor">op5 Monitor</a></li>
<li>An <a target="_blank" href="http://www.it-slav.net/blogs/?p=319">article</a> about monitor automysqlbackup with passive checks</li>
</ul>
<p>Troubleshooting hint:</p>
<p>If it does not work, a good hint is to take a look into nagios.log</p>
]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2008/12/10/howto-using-passive-checks-with-nagios-or-op5-monitor/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>MySQL database backup automysqlbackup</title>
		<link>http://www.it-slav.net/blogs/2008/11/17/mysql-database-backup-automysqlbackup/</link>
		<comments>http://www.it-slav.net/blogs/2008/11/17/mysql-database-backup-automysqlbackup/#comments</comments>
		<pubDate>Mon, 17 Nov 2008 08:04:08 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Hints]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=305</guid>
		<description><![CDATA[Now when my blog is growing a need for backup is growing. After a short google search I found exactly what I want, automysqlbackup.
It is a shell script that has very modest requirements list:

mysqldump, included in mysql client
gzip or bzip2 if you want it compressed.
mail if you want the status of the script to be [...]]]></description>
			<content:encoded><![CDATA[<p>Now when my blog is growing a need for backup is growing. After a short google search I found exactly what I want, <a href="http://members.lycos.co.uk/wipe_out/automysqlbackup/" target="_blank">automysqlbackup</a>.</p>
<p>It is a shell script that has very modest requirements list:</p>
<ul>
<li>mysqldump, included in mysql client</li>
<li>gzip or bzip2 if you want it compressed.</li>
<li>mail if you want the status of the script to be emailed.</li>
</ul>
<p>Features:</p>
<ul>
<li>Backup mutiple MySQL databases with one script. (Now able to backup ALL databases on a server easily. no longer need to specify each database seperately)</li>
<li>Backup all databases to a single backup file or to a seperate directory and file for each database. </li>
<li>Automatically compress the backup files to save disk space using either gzip or bzip2 compression. </li>
<li>Can backup remote MySQL servers to a central server. </li>
<li>Runs automatically using cron or can be run manually. </li>
<li>Can e-mail the backup log to any specified e-mail address instead of &#8220;root&#8221;. (Great for hosted websites and databases). </li>
<li>Can email the compressed database backup files to the specified email address. </li>
<li>Can specify maximun size backup to email. </li>
<li>Can be set to run PRE and POST backup commands. </li>
<li>Choose which day of the week to run weekly backups.</li>
</ul>
<p>Download it, modify some parameters and put in /etc/cron.daily and now your database is backuped.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2008/11/17/mysql-database-backup-automysqlbackup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>check_mounts plugin for op5 Monitor or Nagios</title>
		<link>http://www.it-slav.net/blogs/2008/11/07/check_mounts-plugin-for-op5-monitor-or-nagios/</link>
		<comments>http://www.it-slav.net/blogs/2008/11/07/check_mounts-plugin-for-op5-monitor-or-nagios/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 20:16:17 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Nagios]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[op5 Monitor]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[kernel]]></category>
		<category><![CDATA[xfs]]></category>

		<guid isPermaLink="false">http://www.it-slav.net/blogs/?p=184</guid>
		<description><![CDATA[When I updated my CentOS system and could not mount XFS file system and my op5 Monitor did not react. I even run check_disk on these mount points but op5 Monitor did not tell me that anything was wrong. So when I managed to get the system to boot and my monitoring system tell me [...]]]></description>
			<content:encoded><![CDATA[<p>When I updated my CentOS system and could not mount XFS file system and my op5 Monitor did not react. I even run check_disk on these mount points but op5 Monitor did not tell me that anything was wrong. So when I managed to get the system to boot and my monitoring system tell me everything was alright I went to bed.<br />
When I checked my email this morning I noticed that my backup script had failed and complained &#8220;file does not exist&#8221; and so on. I investigated this and found that my XFS file system was not mounted because of the missing XFS kernel module. I also looked in to why my monitor system has not warned me and figured out that check_disk check the file system you point it to and if that is not mounted it will take the parent and the thresholds for that was not reached.<br />
After taken a look at http://www.nagiosexchange.org and found a ruby script that probably would do the job. But I do not want to install ruby on all my monitored systems, so I decided to write my own. It is written in bash and works on CentOS, and probably on most *nix systems.</p>
<p>The script looks in /etc/fstab and compares it with the file systems mounted. If anything is missing, return CRITICAL and the name of the missed mountpoint. The script does not check that some system file systems are mounted i.e. /proc</p>
<p>I have uploaded this script to nagios exchange.</p>
<pre>#!/bin/sh
#By peter@it-slav.net
#GPLv2

RESULT=0
TMPFILE=`mktemp /tmp/mount.XXXXXXXXXX`
FSTABMOUNTS=`grep -e '^#' -v /etc/fstab|grep -v  tmpfs |grep -v devpts|grep -v sysfs|grep -v proc|grep -v swap| awk '{print $2}'`
for i in $FSTABMOUNTS
do
        mountpoint $i &gt; /dev/null
        if [ $? != "0" ]
        then
                echo -n "$i " &gt;&gt;$TMPFILE
                RESULT=2
        fi

done
#echo $RESULT
if [ $RESULT != "0" ]
then
        echo "is not mounted" &gt;&gt; $TMPFILE
        echo -n "CRITICAL: "
        cat $TMPFILE
else
        echo "OK: All disks mounted"
fi
rm $TMPFILE
exit $RESULT</pre>
<p>Links:</p>
<ul>
<li><a href="http://www.nagiosexchange.org/cgi-bin/page.cgi?g=Detailed%2F2792.html;d=1" target="_blank">check_mounts.sh</a> at <a href="http://www.nagiosexchange.org" target="_blank">Nagiosexchange</a></li>
<li><a href="http://www.op5.com/op5/products/monitor" target="_blank">op5 Monitor </a></li>
<li>My <a href="http://www.it-slav.net/blogs/?p=179" target="_blank">other</a> blog about the problems when I did a kernel upgrade</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.it-slav.net/blogs/2008/11/07/check_mounts-plugin-for-op5-monitor-or-nagios/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
