<?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>Matejunkie &#187; gplv2</title>
	<atom:link href="http://www.matejunkie.com/tag/gplv2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.matejunkie.com</link>
	<description>"Look behind you, a Three-Headed Monkey!"</description>
	<lastBuildDate>Thu, 07 Jan 2010 14:26:10 +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>PNP template for check_apache2.sh</title>
		<link>http://www.matejunkie.com/pnp-template-for-check_apache2-sh/</link>
		<comments>http://www.matejunkie.com/pnp-template-for-check_apache2-sh/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 20:07:52 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[apache webserver]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[pnp template]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1246</guid>
		<description><![CDATA[This is a PNP template which works quite well for me when there&#8217;s need to identify possible bottlenecks or unexpected behavior of the Apache webserver. It shows the CPU usage, req/sec, byte/req and the amount of busy/idle workers in a single graph. Feel free to copy the template from below or head over to Nagios [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.matejunkie.com/wp-content/uploads/2009/09/check_apache2.png"><img class="alignleft size-medium wp-image-1248" title="check_apache2 PNP Template" src="http://www.matejunkie.com/wp-content/uploads/2009/09/check_apache2-300x125.png" alt="check_apache2 PNP Template" width="180" height="75" /></a>This is a PNP template which works quite well for me when there&#8217;s need to identify possible bottlenecks or unexpected behavior of the Apache webserver. It shows the CPU usage, req/sec, byte/req and the amount of busy/idle workers in a single graph. Feel free to copy the template from below or head over <a href="http://exchange.nagios.org/directory/Plugins/Web-Servers/Apache/check_apache2-2Esh/details" title="Nagios Exchange - check_apache2.sh">to Nagios Exchange</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify
</span><span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by
</span><span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or
</span><span style="color: #666666; font-style: italic;">#   (at your option) any later version.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,
</span><span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of
</span><span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
</span><span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License
</span><span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software
</span><span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
</span>
<span style="color: #666666; font-style: italic;">#   PNP Template for check_apache2.sh
</span><span style="color: #666666; font-style: italic;">#   Author: Mike Adolphs (http://www.matejunkie.com/)
</span>
<span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;--vertical-label <span style="color: #000099; font-weight: bold;">\&quot;</span>Various stats <span style="color: #000099; font-weight: bold;">\&quot;</span> -l 0 -r --title <span style="color: #000099; font-weight: bold;">\&quot;</span>Apache metrics for <span style="color: #006699; font-weight: bold;">$hostname</span> / <span style="color: #006699; font-weight: bold;">$servicedesc</span><span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;DEF:cpu=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[1]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:reqpsec=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[2]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:bytepreq=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[4]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:wbusy=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[5]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:widle=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[6]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;--vertical-label <span style="color: #000099; font-weight: bold;">\&quot;</span>Byte/sec <span style="color: #000099; font-weight: bold;">\&quot;</span> -l 0 -r --title <span style="color: #000099; font-weight: bold;">\&quot;</span>Apache metrics for <span style="color: #006699; font-weight: bold;">$hostname</span> / <span style="color: #006699; font-weight: bold;">$servicedesc</span><span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;DEF:bytepsec=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[3]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;COMMENT:<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tLAST<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tAVERAGE<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tMAX<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:cpu#008000:<span style="color: #000099; font-weight: bold;">\&quot;</span>CPU usage [%]<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cpu:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cpu:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cpu:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:reqpsec#0C64E8:<span style="color: #000099; font-weight: bold;">\&quot;</span>Requests/sec<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:reqpsec:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:reqpsec:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:reqpsec:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:bytepreq#FFA500:<span style="color: #000099; font-weight: bold;">\&quot;</span>Byte/req<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepreq:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepreq:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepreq:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:wbusy#1CC8E8:<span style="color: #000099; font-weight: bold;">\&quot;</span>Busy workers<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:wbusy:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:wbusy:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:wbusy:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:widle#E80C8C:<span style="color: #000099; font-weight: bold;">\&quot;</span>Idle workers<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:widle:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:widle:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:widle:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;COMMENT:<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tLAST<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tAVERAGE<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tMAX<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:bytepsec#E80C3E:<span style="color: #000099; font-weight: bold;">\&quot;</span>Byte/sec<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t <span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepsec:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepsec:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:bytepsec:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span> %6.0lf<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/pnp-template-for-check_apache2-sh/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Update 1.3: Apache check plugin for Nagios</title>
		<link>http://www.matejunkie.com/update-1-3-apache-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/update-1-3-apache-check-plugin-for-nagios/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 22:49:16 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[apache webserver]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[ssl]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1240</guid>
		<description><![CDATA[Long time no see. Sorry for the long downtime, but I&#8217;ve been on vacation for quite some time and spent my time out of reach of any electronical device except my phone. Anyway, strength and motivation for work during spare time is back again! Expect a few updates of various plugins I&#8217;ve written in the [...]]]></description>
			<content:encoded><![CDATA[<p>Long time no see. Sorry for the long downtime, but I&#8217;ve been on vacation for quite some time and spent my time out of reach of any electronical device except my phone. Anyway, strength and motivation for work during spare time is back again! Expect a few updates of various plugins I&#8217;ve written in the past within the next weeks.</p>
<p>For the beginning here&#8217;s the revised version of the Apache check plugin for Nagios. It now doesn&#8217;t write temporary files anymore, the code is cleaner and it should be a bit faster. Note that I haven&#8217;t done much testing for now (will be done tomorrow and on Wednesday). Therefore it might won&#8217;t work out of the box for you. At least in my environments it works well. Let me know if you have any problems or if you stumble upon something which is completely nonsense.</p>
<p>Copy&#8217;n'paste below or svn co via svn.matejunkie.com/nagios-plugins/trunk/check_apache/.</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family:monospace;">#!/bin/sh
&nbsp;
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
&nbsp;
PROGNAME=`basename $0`
VERSION=&quot;Version 1.3,&quot;
AUTHOR=&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;
&nbsp;
print_version() {
    echo &quot;$VERSION $AUTHOR&quot;
}
&nbsp;
print_help() {
    print_version $PROGNAME $VERSION
    echo &quot;&quot;
    echo &quot;Description:&quot;
    echo &quot;$PROGNAME is a Nagios plugin to check the Apache's server status.&quot;
    echo &quot;It monitors requests per second, bytes per second/request, &quot;
    echo &quot;amount of busy/idle workers and its CPU load.&quot;
    echo &quot;&quot;
    echo &quot;Example call:&quot;
    echo &quot;./$PROGNAME -H localhost -P 80 -t 3 -b /usr/sbin -p /var/run \\&quot;
    echo &quot;-n apache2.pid -s status_page [-S] [-R] [-wr] 100 [-cr] 250&quot;
    echo &quot;&quot;
    echo &quot;Options:&quot;
    echo &quot;  -H|--hostname)&quot;
    echo &quot;    Sets the hostname. Default is: localhost&quot;
    echo &quot;  -P|--port)&quot;
    echo &quot;    Sets the port. Default is: 80&quot;
    echo &quot;  -t|--timeout)&quot;
    echo &quot;    Sets a timeout within the server's status page must've been&quot;
    echo &quot;    accessed. Otherwise the check will go into an error state.&quot;
    echo &quot;    Default is: 3&quot;
    echo &quot;  -b|--binary-path)&quot;
    echo &quot;    Sets the path to the apache binary. Used for getting Apache's&quot;
    echo &quot;    CPU load. Default is: /usr/sbin&quot;
    echo &quot;  -p|--pid-path)&quot;
    echo &quot;    Path to Apache's pid file. Default is: /var/run&quot;
    echo &quot;  -n|--pid-name)&quot;
    echo &quot;    Name of Apache's pid file. Default is: apache2.pid&quot;
    echo &quot;  -s|--status-page)&quot;
    echo &quot;    Defines the name of the status page. Default is: server-status&quot;
    echo &quot;  -R|--remote-server)&quot;
    echo &quot;    Disabled the pid check so that remote Apaches can be queried.&quot;
    echo &quot;    Default is: off&quot;
    echo &quot;  -S|--secure)&quot;
    echo &quot;    Enables HTTPS (no certificate check though). Default is: off&quot;
    echo &quot;  -wr|--warning-req)&quot;
    echo &quot;    Sets a warning level for requests per second. Default is: off&quot;
    echo &quot;  -cr|--critical-req)&quot;
    echo &quot;    Sets a critical level for requests per second. Default is: off&quot;
    exit $ST_UK
}
&nbsp;
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
&nbsp;
hostname=&quot;localhost&quot;
port=80
remote_srv=0
path_binary=&quot;/usr/sbin&quot;
path_pid=&quot;/var/run&quot;
name_pid=&quot;apache2.pid&quot;
status_page=&quot;server-status&quot;
timeout=3
secure=0
running=0
&nbsp;
wcdiff_req=0
wclvls_req=0
&nbsp;
while test -n &quot;$1&quot;; do
    case &quot;$1&quot; in
        --help|-h)
            print_help
            exit $ST_UK
            ;;
        --version|-v)
            print_version $PROGNAME $VERSION
            exit $ST_UK
            ;;
        --hostname|-H)
            hostname=$2
            shift
            ;;
        --port|-P)
            port=$2
            shift
            ;;
        --timeout|-t)
            timeout=$2
            shift
            ;;
        --remote-server|-R)
            remote_srv=1
            ;;
        --binary_path|-b)
            path_binary=$2
            shift
            ;;
        --pid_path|-p)
            path_pid=$2
            shift
            ;;
        --pid_name|-n)
            name_pid=$2
            shift
            ;;
        --status-page|-s)
            status_page=$2
            shift
            ;;
        --secure|-S)
            secure=1
            ;;
        --warning-req|-wr)
            warn_req=$2
            shift
            ;;
        --critical-req|-cr)
            crit_req=$2
            shift
            ;;
        *)
            echo &quot;Unknown argument: $1&quot;
            print_help
            exit $ST_UK
            ;;
    esac
    shift
done
&nbsp;
# check functions
val_wcdiff_req() {
    if [ ! -z &quot;$warn_req&quot; -a ! -z &quot;$crit_req&quot; ]
    then
        wclvls_req=1
&nbsp;
        if [ ${warn_req} -gt ${crit_req} ]
        then
            wcdiff_req=1
        fi
    elif [ ! -z &quot;$warn_req&quot; -a -z &quot;$crit_req&quot; ]
    then
        wcdiff_req=2
    elif [ -z &quot;$warn_req&quot; -a ! -z &quot;$crit_req&quot; ]
    then
        wcdiff_req=3
    fi
}
&nbsp;
check_pid() {
    if [ -f &quot;$path_pid/$name_pid&quot; ]
    then
        retval=0
    else
        retval=1
    fi
}
&nbsp;
check_processes() {
    if [ $1 -lt 1 ]
    then
        echo &quot;UNKNOWN - Your Apache server seems not to run. Is your Nagios \
privileged to run 'ps ax' and is the Apache2 binary really located in \
$path_binary?&quot;
        exit $ST_UK
    fi
}
&nbsp;
check_output() {
    stat_output=`stat -c %s ${output_dir}/server-status`
    if [ &quot;$stat_output&quot; = 0 ]
    then
        echo &quot;UNKNOWN - Local copy of server-status is empty. Are we \
allowed to access http://${hostname}:${port}/server-status?&quot;
        exit $ST_UK
    fi
}
&nbsp;
# get functions
get_status() {
    if [ &quot;$secure&quot; = 1 ]
    then
        server_status1=`wget -qO- --no-check-certificate -t 3 \
-T ${timeout} https://${hostname}:${port}/${status_page}?auto`
    sleep 1
        server_status2=`wget -qO- --no-check-certificate -t 3 \
-T ${timeout} https://${hostname}:${port}/${status_page}?auto`
    else
        server_status1=`wget -qO- -t 3 -T ${timeout} \
http://${hostname}:${port}/${status_page}?auto`
        sleep 1
        server_status2=`wget -qO- -t 3 -T ${timeout} \
http://${hostname}:${port}/${status_page}?auto`
    fi
}
&nbsp;
get_vals() {
    cpu_load=&quot;$(cpu_load=0; ps -Ao pcpu,args | grep &quot;$path_binary/apache2&quot; \
| awk '{print $1}' | while read line
    do
        cpu_load=`echo &quot;scale=3; $cpu_load + $line&quot; | bc -l`
    echo $cpu_load
    done)&quot;
    cpu_load=`echo $cpu_load | awk '{print $NF}' | sed 's/^\./0./'`
&nbsp;
    tmp1_req_psec=`echo ${server_status1} | awk '{print $3}'`
    tmp2_req_psec=`echo ${server_status2} | awk '{print $3}'`
    req_psec=`echo &quot;scale=2; ${tmp2_req_psec} - ${tmp1_req_psec}&quot; | bc -l \
| sed 's/^\./0./'`
&nbsp;
    bytes_psec=`echo ${server_status1} | awk '{print $14}' | sed 's/^\./0./'`
    bytes_preq=`echo ${server_status1} | awk '{print $16}' | sed 's/^\./0./'`
    wkrs_busy=`echo ${server_status1} | awk '{print $18}' | sed 's/^\./0./'`
    wkrs_idle=`echo ${server_status1} | awk '{print $20}' | sed 's/^\./0./'`
}
&nbsp;
do_output() {
    output=&quot;Apache serves $req_psec Requests per second with an average CPU \
utilization of $cpu_load%. Busy workers: $wkrs_busy, idle: $wkrs_idle&quot;
}
&nbsp;
do_perfdata() {
    perfdata=&quot;'cpu_load'=$cpu_load 'req_psec'=$req_psec \
'bytes_psec'=$bytes_psec 'bytes_preq'=$bytes_preq 'workers_busy'=$wkrs_busy \
'workers_idle'=$wkrs_idle&quot;
}
&nbsp;
# Let's go
val_wcdiff_req
&nbsp;
if [ &quot;$wcdiff_req&quot; = 1 ]
then
    echo &quot;Please adjust your warning/critical thresholds. The warning must \
be lower than the critical level!&quot;
    exit $ST_UK
elif [ &quot;$wcdiff_req&quot; = 2 ]
then
    echo &quot;Please also set a critical value when you want to use \
warning/critical thresholds!&quot;
    exit $ST_UK
elif [ &quot;$wcdiff_req&quot; = 3 ]
then
    echo &quot;Please also set a warning value when you want to use \
warning/critical thresholds!&quot;
    exit $ST_UK
else
    if [ &quot;$remote_srv&quot; = 0 ]
    then
        running=`check_pid`
        check_pid $running
    fi
&nbsp;
    get_status
    get_vals
&nbsp;
    do_output
    do_perfdata
&nbsp;
    if [ ${wclvls_req} = 1 ]
    then
        if [ ${req_psec} -ge ${warn_req} -a ${req_psec} -lt ${crit_req} ]
        then
            echo &quot;WARNING - ${output} | ${perfdata}&quot;
            exit $ST_WR
        elif [ ${req_psec} -ge ${crit_req} ]
        then
            echo &quot;CRITICAL - ${output} | ${perfdata}&quot;
        exit $ST_CR
        else
            echo &quot;OK - ${output} | ${perfdata}&quot;
            exit $ST_OK
        fi
    else
        echo &quot;OK - ${output} | ${perfdata}&quot;
        exit $ST_OK
    fi
fi</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/update-1-3-apache-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Update 1.1: nginx Check Plugin for Nagios</title>
		<link>http://www.matejunkie.com/update-1-1-nginx-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/update-1-1-nginx-check-plugin-for-nagios/#comments</comments>
		<pubDate>Tue, 16 Jun 2009 07:51:24 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1166</guid>
		<description><![CDATA[Last week I&#8217;ve got an E-Mail by Jordi, who&#8217;s blogging at terraquis.net, with a few suggestions to the nginx check plugin I&#8217;ve recently released. He made two significant changes to the plugin: His version runs with bash only, but except bc all external calls have been replaced by bash built-ins There&#8217;s no temporary file anymore [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-193" title="logo_nagios" src="http://www.matejunkie.com/wp-content/uploads/2008/05/logo_nagios.gif" alt="logo_nagios" width="150" height="40" />Last week I&#8217;ve got an E-Mail by Jordi, who&#8217;s blogging <a title="terraquis.net" href="http://www.terraquis.net/" target="_blank">at terraquis.net</a>, with a few suggestions to the nginx check plugin I&#8217;ve recently released. He made two significant changes to the plugin:</p>
<ol>
<li>His version runs with bash only, but except bc all external calls have been replaced by bash built-ins</li>
<li>There&#8217;s no temporary file anymore which has to be written to a temporary directory, nginx_status page output is saved into a variable</li>
</ol>
<p>The plugin therefore runs much faster than my initial version of the plugin: 14-16ms plus the 1 second sleep interval between the two nginx_status checks.</p>
<p>And then I realized that writing output to a temporary file is just one thing: plain stupid. Why writing files when an information can be stored in a variable where it stays in memory?<br />
Well, I can&#8217;t really say why I walked this way when I&#8217;ve written the first plugins, but I eventually had the right idea when I&#8217;ve written the <a title="Matejunkie - Hadoop DFS Check" href="http://www.matejunkie.com/hadoop-dfs-check-plugin-for-nagios/" target="_blank">Hadoop DFS check</a>. There I already store the information within variables. The only guess why I did this is that I&#8217;ve assumed that storing longer output in variables just would be too much.</p>
<p>But anyway, there has to be room for improvements, right? Therefore, expect a few reworks within the next days, &#8230;</p>
<h3>The script</h3>
<p>Below is the revised script I&#8217;ve already uploaded yesterday to <a title="Nagios Exchange - check_nginx.sh" href="http://exchange.nagios.org/directory/Plugins/Web-Servers/nginx/check_nginx-2Esh/details" target="_blank">Nagios</a> and <a title="MonitoringExchange - check_nginx.sh" href="http://www.monitoringexchange.org/cgi-bin/page.cgi?g=Detailed%2F3089.html;d=1" target="_blank">MonitoringExchange</a>. It runs much faster than the initial version and doesn&#8217;t write files anymore. You may also stick to the output below or do the SVN way.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> <span style="color: #c20cb9; font-weight: bold;">svn</span>:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_nginx<span style="color: #000000; font-weight: bold;">/</span> check_nginx<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.1,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">hostname</span></span>=<span style="color: #ff0000;">&quot;localhost&quot;</span>
<span style="color: #007800;">port</span>=<span style="color: #000000;">80</span>
<span style="color: #007800;">path_pid</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run
<span style="color: #007800;">name_pid</span>=<span style="color: #ff0000;">&quot;nginx.pid&quot;</span>
<span style="color: #007800;">status_page</span>=<span style="color: #ff0000;">&quot;nginx_status&quot;</span>
<span style="color: #007800;">pid_check</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">secure</span>=<span style="color: #000000;">0</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to check whether nginx is running.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;It also parses the nginx's status page to get requests and&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;connections per second as well as requests per connection. You&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;may have to alter your nginx configuration so that the plugin&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;can access the server's status page.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The plugin is highly configurable for this reason. See below for&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;available options.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> -H localhost -P 80 -p /var/run -n nginx.pid &quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -s nginx_statut -o /tmp [-w INT] [-c INT] [-S] [-N]&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -H/--hostname)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the hostname. Default is: localhost&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -P/--port)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the port. Default is: 80&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -p/--path-pid)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Path where nginx's pid file is being stored. You might need&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     to alter this path according to your distribution. Default&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     is: /var/run&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -n/--name_pid)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Name of the pid file. Default is: nginx.pid&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -N/--no-pid-check)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Turn this on, if you don't want to check for a pid file&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     whether nginx is running, e.g. when you're checking a&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     remote server. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -s/--status-page)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Name of the server's status page defined in the location&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     directive of your nginx configuration. Default is:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     nginx_status&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -S/--secure)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     In case your server is only reachable via SSL, use this&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     this switch to use HTTPS instead of HTTP. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -w/--warning)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Sets a warning level for requests per second. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -c/--critical)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Sets a critical level for requests per second. Default is:&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        -help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --hostname<span style="color: #000000; font-weight: bold;">|</span>-H<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">hostname</span></span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --port<span style="color: #000000; font-weight: bold;">|</span>-P<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">port</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --path-pid<span style="color: #000000; font-weight: bold;">|</span>-p<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">path_pid</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --name-pid<span style="color: #000000; font-weight: bold;">|</span>-n<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">name_pid</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --no-pid-check<span style="color: #000000; font-weight: bold;">|</span>-N<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">pid_check</span>=<span style="color: #000000;">0</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --status-page<span style="color: #000000; font-weight: bold;">|</span>-s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">status_page</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --secure<span style="color: #000000; font-weight: bold;">|</span>-S<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">secure</span>=<span style="color: #000000;">1</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warning</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">critical</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
get_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wclvls</span>=<span style="color: #000000;">1</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warning}</span> <span style="color: #660033;">-ge</span> <span style="color: #800000;">${critical}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">2</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">3</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please adjust your warning/critical thresholds. The warning <span style="color: #000099; font-weight: bold;">\
</span>must be lower than the critical level!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a critical value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a warning value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
check_pid<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$path_pid</span>/<span style="color: #007800;">$name_pid</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">retval</span>=<span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #007800;">retval</span>=<span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_status<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$secure</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wget_opts</span>=<span style="color: #ff0000;">&quot;-O- -q -t 3 -T 3 --no-check-certificate&quot;</span>
        <span style="color: #007800;">out1</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #800000;">${wget_opts}</span> http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${hostname}</span>:<span style="color: #800000;">${port}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${status_page}</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        <span style="color: #007800;">out2</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #800000;">${wget_opts}</span> http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${hostname}</span>:<span style="color: #800000;">${port}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${status_page}</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #000000; font-weight: bold;">else</span>        
        <span style="color: #007800;">wget_opts</span>=<span style="color: #ff0000;">&quot;-O- -q -t 3 -T 3&quot;</span>
        <span style="color: #007800;">out1</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #800000;">${wget_opts}</span> http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${hostname}</span>:<span style="color: #800000;">${port}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${status_page}</span><span style="color: #000000; font-weight: bold;">`</span>
        <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
        <span style="color: #007800;">out2</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #800000;">${wget_opts}</span> http:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #800000;">${hostname}</span>:<span style="color: #800000;">${port}</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${status_page}</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$out1</span>&quot;</span> <span style="color: #660033;">-o</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$out2</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;UNKNOWN - Local copy/copies of <span style="color: #007800;">$status_page</span> is empty.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_vals<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">tmp1_reqpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${out1}</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $10}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_reqpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${out2}</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $10}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">reqpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$tmp2_reqpsec</span> - <span style="color: #007800;">$tmp1_reqpsec</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">tmp1_conpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${out1}</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $9}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_conpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${out2}</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $9}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">conpsec</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$tmp2_conpsec</span> - <span style="color: #007800;">$tmp1_conpsec</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">reqpcon</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; <span style="color: #007800;">$reqpsec</span> / <span style="color: #007800;">$conpsec</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpcon</span>&quot;</span> = <span style="color: #ff0000;">&quot;.99&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">reqpcon</span>=<span style="color: #ff0000;">&quot;1.00&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_output<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">output</span>=<span style="color: #ff0000;">&quot;nginx is running. <span style="color: #007800;">$reqpsec</span> requests per second, <span style="color: #007800;">$conpsec</span> <span style="color: #000099; font-weight: bold;">\
</span>connections per second (<span style="color: #007800;">$reqpcon</span> requests per connection)&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_perfdata<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">perfdata</span>=<span style="color: #ff0000;">&quot;'reqpsec'=<span style="color: #007800;">$reqpsec</span> 'conpsec'=<span style="color: #007800;">$conpsec</span> 'conpreq'=<span style="color: #007800;">$reqpcon</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Here we go!</span>
get_wcdiff
val_wcdiff
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${pid_check}</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    check_pid
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$retval</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;There's no pid file for nginx. Is nginx running? Please <span style="color: #000099; font-weight: bold;">\
</span>also make sure whether your pid path and name is correct.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
get_status
get_vals
do_output
do_perfdata
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpsec</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpsec</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpsec</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span> ]&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<h3>Jordi&#8217;s script</h3>
<p>This is Jordi&#8217;s bash built-in (plus bc) version which runs even faster. Feel free to copy the output below.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.0,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
<span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">hostname</span></span>=<span style="color: #ff0000;">&quot;localhost&quot;</span>
<span style="color: #007800;">port</span>=<span style="color: #000000;">80</span>
<span style="color: #007800;">path_pid</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run
<span style="color: #007800;">name_pid</span>=<span style="color: #ff0000;">&quot;nginx.pid&quot;</span>
<span style="color: #007800;">status_page</span>=<span style="color: #ff0000;">&quot;nginx_status&quot;</span>
<span style="color: #007800;">pid_check</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">secure</span>=<span style="color: #000000;">0</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to check whether nginx is running.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;It also parses the nginx's status page to get requests and&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;connections per second as well as requests per connection. You&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;may have to alter your nginx configuration so that the plugin&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;can access the server's status page.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The plugin is highly configurable for this reason. See below for&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;available options.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> -H localhost -P 80 -p /var/run -n nginx.pid &quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -s nginx_statut -o /tmp [-w INT] [-c INT] [-S] [-N]&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -H/--hostname)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the hostname. Default is: localhost&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -P/--port)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the port. Default is: 80&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -p/--path-pid)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Path where nginx's pid file is being stored. You might need&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     to alter this path according to your distribution. Default&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     is: /var/run&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -n/--name_pid)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Name of the pid file. Default is: nginx.pid&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -N/--no-pid-check)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Turn this on, if you don't want to check for a pid file&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     whether nginx is running, e.g. when you're checking a&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     remote server. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -s/--status-page)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Name of the server's status page defined in the location&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     directive of your nginx configuration. Default is:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     nginx_status&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -o/--output-directory)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Unneeded. The option is preserved for backwards compatibility.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -S/--secure)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     In case your server is only reachable via SSL, use this&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     this switch to use HTTPS instead of HTTP. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -w/--warning)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Sets a warning level for requests per second. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -c/--critical)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Sets a critical level for requests per second. Default is:&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        -help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --hostname<span style="color: #000000; font-weight: bold;">|</span>-H<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">hostname</span></span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --port<span style="color: #000000; font-weight: bold;">|</span>-P<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">port</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --path-pid<span style="color: #000000; font-weight: bold;">|</span>-p<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">path_pid</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --name-pid<span style="color: #000000; font-weight: bold;">|</span>-n<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">name_pid</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --no-pid-check<span style="color: #000000; font-weight: bold;">|</span>-N<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">pid_check</span>=<span style="color: #000000;">0</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --status-page<span style="color: #000000; font-weight: bold;">|</span>-s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">status_page</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --output-directory<span style="color: #000000; font-weight: bold;">|</span>-o<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">output_dir</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --secure<span style="color: #000000; font-weight: bold;">|</span>-S<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">secure</span>=<span style="color: #000000;">1</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warning</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">critical</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
get_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wclvls</span>=<span style="color: #000000;">1</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warning}</span> <span style="color: #660033;">-gt</span> <span style="color: #800000;">${critical}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">2</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">3</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please adjust your warning/critical thresholds. The warning <span style="color: #000099; font-weight: bold;">\
</span>must be lower than the critical level!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a critical value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a warning value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
check_pid<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$path_pid</span>/<span style="color: #007800;">$name_pid</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">retval</span>=<span style="color: #000000;">0</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #007800;">retval</span>=<span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_status<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">url</span>=<span style="color: #ff0000;">&quot;http://<span style="color: #007800;">${hostname}</span>:<span style="color: #007800;">${port}</span>/<span style="color: #007800;">${status_page}</span>&quot;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$secure</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wget_opts</span>=<span style="color: #ff0000;">&quot;-O- -q -t 3 -t 3 --no-check-certificate&quot;</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #007800;">wget_opts</span>=<span style="color: #ff0000;">&quot;-O- -q -t 3 -t 3&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #007800;">out1</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #800000;">${wget_opts}</span> <span style="color: #800000;">${url}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
    <span style="color: #007800;">out2</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #800000;">${wget_opts}</span> <span style="color: #800000;">${url}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;"># Both commands must return some content.</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${out1}</span>&quot;</span> <span style="color: #660033;">-o</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${out2}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> ; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;UNKNOWN - Local copy/copies of <span style="color: #007800;">$status_page</span> is empty.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_vals<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #666666; font-style: italic;"># Convert into an array.</span>
    <span style="color: #007800;">values1</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #800000;">${out1}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #007800;">values2</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #800000;">${out2}</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #007800;">reqpsec</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${values2[9]}</span> - <span style="color: #800000;">${values1[9]}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
    <span style="color: #007800;">conpsec</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #800000;">${values2[8]}</span> - <span style="color: #800000;">${values1[8]}</span> <span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
    <span style="color: #007800;">reqpcon</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; <span style="color: #007800;">$reqpsec</span> / <span style="color: #007800;">$conpsec</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpcon</span>&quot;</span> = <span style="color: #ff0000;">&quot;.99&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">reqpcon</span>=<span style="color: #ff0000;">&quot;1.00&quot;</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_output<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">output</span>=<span style="color: #ff0000;">&quot;nginx is running. <span style="color: #007800;">$reqpsec</span> requests per second, <span style="color: #007800;">$conpsec</span> <span style="color: #000099; font-weight: bold;">\
</span>connections per second (<span style="color: #007800;">$reqpcon</span> requests per connection)&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_perfdata<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">perfdata</span>=<span style="color: #ff0000;">&quot;'reqpsec'=<span style="color: #007800;">$reqpsec</span> 'conpsec'=<span style="color: #007800;">$conpsec</span> 'conpreq'=<span style="color: #007800;">$reqpcon</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Here we go!</span>
get_wcdiff
val_wcdiff
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${pid_check}</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    check_pid
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$retval</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;There's no pid file for nginx. Is nginx running? Please <span style="color: #000099; font-weight: bold;">\
</span>also make sure whether your pid path and name is correct.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
get_status
get_vals
do_output
do_perfdata
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpsec</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpsec</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$reqpsec</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span> ]&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<h3>License</h3>
<p>As always this little script is ment to be sh-compliant and released under the terms of the GPL Version 2 only. Feel free to subscribe via rss to get updates on this one. More options will be added in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/update-1-1-nginx-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nagios Exchange opens up</title>
		<link>http://www.matejunkie.com/nagios-exchange-opens-up/</link>
		<comments>http://www.matejunkie.com/nagios-exchange-opens-up/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 11:45:46 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[monitoringexchange]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[nagios exchange]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1135</guid>
		<description><![CDATA[Just a short note from my side: A week ago Ethan launched Nagios Exchange, an addon and plugin repository similar to MonitoringExchange, which is part of the whole Nagios website framework. I began to add all of my plugins to it as well, but due to the approval process it might take a while till [...]]]></description>
			<content:encoded><![CDATA[<p>Just a short note from my side:<br />
A week ago Ethan launched <a title="Nagios Exchange" href="http://exchange.nagios.org/" target="_blank">Nagios Exchange</a>, an addon and plugin repository similar <a title="MonitoringExchange" href="http://www.monitoringexchange.org/" target="_blank">to MonitoringExchange</a>, which is part of the whole <a title="Nagios" href="http://www.nagios.org/" target="_blank">Nagios</a> website framework. I began to add all of my plugins to it as well, but due to the approval process it might take a while till they&#8217;re downloadable. I&#8217;ll let you know when it&#8217;s done.</p>
<p>Nevertheless, from now on you&#8217;re even more free from where to download the plugins I&#8217;ve written. From now on they&#8217;re available via this blog, via SVN, via MonitoringExchange and via Nagios Exchange. I&#8217;ll update them on all sources.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/nagios-exchange-opens-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hadoop DFS Check Plugin for Nagios</title>
		<link>http://www.matejunkie.com/hadoop-dfs-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/hadoop-dfs-check-plugin-for-nagios/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 22:46:45 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[hadoop]]></category>
		<category><![CDATA[HDFS]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1110</guid>
		<description><![CDATA[Since I&#8217;m currently occupied with kicking off a several terabytes large Hadoop cluster I thought it&#8217;d be a good idea to provide a few Nagios plugins related to Hadoop. Just in case you don&#8217;t know: Hadoop is a free Java software framework that supports data intensive distributed applications. It got its own filesystem called HDFS [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-193" title="logo_nagios" src="http://www.matejunkie.com/wp-content/uploads/2008/05/logo_nagios.gif" alt="logo_nagios" width="150" height="40" />Since I&#8217;m currently occupied with kicking off a several terabytes large Hadoop cluster I thought it&#8217;d be a good idea to provide a few Nagios plugins related to Hadoop.</p>
<p>Just in case you don&#8217;t know: Hadoop is a <a title="Wikipedia - Hadoop" href="http://en.wikipedia.org/wiki/Hadoop" target="_blank">free Java software framework</a> that supports data intensive distributed applications. It got its own filesystem called HDFS which scales up to petabytes of storage running on top of the operating system&#8217;s filesystem. Hadoop is inspired by Google&#8217;s MapReduce and GFS, the Google File System.</p>
<p>Yahoo for example uses several Hadoop Clusters with <strong>100.000 CPUs total in 20.000 boxes</strong> (2.000 boxes per cluster) according to the <a title="Hadoop website" href="http://wiki.apache.org/hadoop/PoweredBy" target="_blank">official Hadoop website</a>. If you haven&#8217;t checked it out yet, do so! This is &#8211; sorry for that &#8211; crazy shit and it&#8217;s working!<br />
For the beginning I&#8217;d recommend reading the <a title="Wikipedia - Hadoop" href="http://en.wikipedia.org/wiki/Hadoop" target="_blank">Wikipedia article</a>, the <a title="Hadoop - Official documentation 0.18.3" href="http://hadoop.apache.org/core/docs/r0.18.3/" target="_blank">offical documentation</a> and, of course, watching the Hadoop related lectures over <a title="Cloudera" href="http://www.cloudera.com/" target="_blank">at Cloudera</a>.</p>
<p>Anyway, the first plugin is almost finished and checks the amount of running DataNodes and the capacity of the DFS. It&#8217;s working, but I want to add a few more features so that the plugin become more flexible. Nevertheless, feel free to give it a try if you&#8217;re in the mood.</p>
<h3>The Script</h3>
<p>Hadoop is completely operated by the hadoop user and since it got its own filesystem it got its own permissions as well. To keep things clean and safe we won&#8217;t give hadoop related permissions to the Nagios user. We&#8217;ll rather enable the Nagios user to run a small shell script as root which contains a command ran by the hadoop user to get information about the cluster.</p>
<p>Add the following small script to a directory of your choice, e.g. /usr/local/sbin:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #c20cb9; font-weight: bold;">su</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">bash</span> - hadoop <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'hadoop dfsadmin -report'</span></pre></div></div>

<p>Afterwards alter its permissions so that it&#8217;s only read-, write and accessible by root:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">700</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>get-dfsreport.sh</pre></div></div>

<p>Then enable the Nagios user to sudo run the script via /etc/sudoers (or better visudo):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">nagios          <span style="color: #007800;">ALL</span>=<span style="color: #7a0874; font-weight: bold;">&#40;</span>ALL<span style="color: #7a0874; font-weight: bold;">&#41;</span>       NOPASSWD: <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>get-dfsreport.sh</pre></div></div>

<p>This is it for the prerequisites. You may then run the script provided for copy&#8217;n'pasting below (or svn co, your choice).<br />
If you&#8217;ve chosen another directory than /usr/local/sbin you have to provide the path via -s/&#8211;path-sh when running the script.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> <span style="color: #c20cb9; font-weight: bold;">svn</span>:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs<span style="color: #000000; font-weight: bold;">/</span> check_hadoop-dfs<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.0,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #007800;">path_sh</span>=<span style="color: #ff0000;">&quot;/usr/local/sbin&quot;</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to check the status of HDFS, Hadoop's&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;underlying, redundant, distributed file system.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> -s /usr/local/sbin [-w 10] [-c 5]&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -s|--path-sh)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Path to the shell script that is mentioned in the&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     documentation. Default is: /usr/local/sbin&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -w|--warning)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the warning level for available datanodes. Default&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -c|--critical)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines the critical level for available datanodes. Default&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        -help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --path-sh<span style="color: #000000; font-weight: bold;">|</span>-s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">path_sh</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warning</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">critical</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
get_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wclvls</span>=<span style="color: #000000;">1</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warning}</span> <span style="color: #660033;">-lt</span> <span style="color: #800000;">${critical}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">2</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">3</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please adjust your warning/critical thresholds. The warning <span style="color: #000099; font-weight: bold;">\
</span>must be higher than the critical level!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a critical value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a warning value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_vals<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">tmp_vals</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #800000;">${path_sh}</span><span style="color: #000000; font-weight: bold;">/</span>get-dfsreport.sh<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dn_avail</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_vals</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">&quot;Datanodes available:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_used</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_vals</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">&quot;Used raw bytes:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_used</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${dfs_used}</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1024</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1024</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_used_p</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_vals</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">&quot;% used:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_vals</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">&quot;Total raw bytes:&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">dfs_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${dfs_total}</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1024</span> <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000;">1024</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_output<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">output</span>=<span style="color: #ff0000;">&quot;Datanodes up and running: <span style="color: #007800;">${dn_avail}</span>, DFS total: <span style="color: #000099; font-weight: bold;">\
</span><span style="color: #007800;">${dfs_total}</span> MB, DFS used: <span style="color: #007800;">${dfs_used}</span> MB (<span style="color: #007800;">${dfs_used_p}</span>)&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_perfdata<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">perfdata</span>=<span style="color: #ff0000;">&quot;'datanodes_available'=<span style="color: #007800;">${dn_avail}</span> 'dfs_total'=<span style="color: #007800;">${dfs_total}</span> <span style="color: #000099; font-weight: bold;">\
</span>'dfs_used'=<span style="color: #007800;">${dfs_used}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Here we go!</span>
get_wcdiff
val_wcdiff
&nbsp;
get_vals
&nbsp;
do_output
do_perfdata
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dn_avail</span>&quot;</span> <span style="color: #660033;">-le</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dn_avail</span>&quot;</span> <span style="color: #660033;">-gt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$dn_avail</span>&quot;</span> <span style="color: #660033;">-le</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span> &quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<h3>Output example:</h3>
<p>If everything went fine you should see output like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin
OK - Datanodes up and running: <span style="color: #000000;">50</span>, DFS total: <span style="color: #000000;">20147365</span> MB, DFS used: <span style="color: #000000;">0</span> MB <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">'datanodes_available'</span>=<span style="color: #000000;">50</span> <span style="color: #ff0000;">'dfs_total'</span>=<span style="color: #000000;">20147365</span> <span style="color: #ff0000;">'dfs_used'</span>=<span style="color: #000000;">0</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">40</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">30</span>
OK - Datanodes up and running: <span style="color: #000000;">50</span>, DFS total: <span style="color: #000000;">20147365</span> MB, DFS used: <span style="color: #000000;">0</span> MB <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">'datanodes_available'</span>=<span style="color: #000000;">50</span> <span style="color: #ff0000;">'dfs_total'</span>=<span style="color: #000000;">20147365</span> <span style="color: #ff0000;">'dfs_used'</span>=<span style="color: #000000;">0</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">60</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">40</span>
WARNING - Datanodes up and running: <span style="color: #000000;">50</span>, DFS total: <span style="color: #000000;">20147365</span> MB, DFS used: <span style="color: #000000;">0</span> MB <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">'datanodes_available'</span>=<span style="color: #000000;">50</span> <span style="color: #ff0000;">'dfs_total'</span>=<span style="color: #000000;">20147365</span> <span style="color: #ff0000;">'dfs_used'</span>=<span style="color: #000000;">0</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">70</span>-c <span style="color: #000000;">60</span>
CRITICAL - Datanodes up and running: <span style="color: #000000;">50</span>, DFS total: <span style="color: #000000;">20147365</span> MB, DFS used: <span style="color: #000000;">0</span> MB <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #ff0000;">'datanodes_available'</span>=<span style="color: #000000;">50</span> <span style="color: #ff0000;">'dfs_total'</span>=<span style="color: #000000;">20147365</span> <span style="color: #ff0000;">'dfs_used'</span>=<span style="color: #000000;">0</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">20</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">40</span>
Please adjust your warning<span style="color: #000000; font-weight: bold;">/</span>critical thresholds. The warning must be higher than the critical level<span style="color: #000000; font-weight: bold;">!</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-w</span> <span style="color: #000000;">30</span>
Please also <span style="color: #000000; font-weight: bold;">set</span> a critical value when you want to use warning<span style="color: #000000; font-weight: bold;">/</span>critical thresholds<span style="color: #000000; font-weight: bold;">!</span>
user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ .<span style="color: #000000; font-weight: bold;">/</span>check_hadoop-dfs.sh <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bin <span style="color: #660033;">-c</span> <span style="color: #000000;">30</span>
Please also <span style="color: #000000; font-weight: bold;">set</span> a warning value when you want to use warning<span style="color: #000000; font-weight: bold;">/</span>critical thresholds<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<h3>The License</h3>
<p>As always this little script is ment to be sh-compliant and released under the terms of the GPL Version 2 only. Feel free to subscribe via rss to get updates on this one. More options will be added in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/hadoop-dfs-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Process Check Plugin for Nagios</title>
		<link>http://www.matejunkie.com/process-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/process-check-plugin-for-nagios/#comments</comments>
		<pubDate>Sat, 30 May 2009 17:07:24 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1086</guid>
		<description><![CDATA[This is a sh-compliant check plugin for Nagios which enables you to monitor a specific process whether it&#8217;s running or not and to see how much cpu/memory it&#8217;s wasting. This can be accomplished with the check_procs plugin which is included in the official Nagios-Plugins package as well, but it doesn&#8217;t generate any performance output. At [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-193" title="logo_nagios" src="http://www.matejunkie.com/wp-content/uploads/2008/05/logo_nagios.gif" alt="logo_nagios" width="150" height="40" />This is a sh-compliant check plugin for Nagios which enables you to monitor a specific process whether it&#8217;s running or not and to see how much cpu/memory it&#8217;s wasting. This can be accomplished with the check_procs plugin which is included in the<a title="Nagios Plugins" href="http://nagiosplugins.org/" target="_blank"> official Nagios-Plugins package</a> as well, but it doesn&#8217;t generate any performance output. At least that&#8217;s what I&#8217;ve experienced lately (I&#8217;d have written the plugin anyway for training purposes).</p>
<h3>The script</h3>
<p>No special needs, just the basic stuff. The script parses the output of ps aux in different ways. You need to provide a specific process via -p/&#8211;process, if warning/critical thresholds are wanted you may also choose between cpu or memory thresholds via -t/&#8211;target (default is memory).<br />
As always, you may grab the plugin <a title="MonitoringExchange - check_ps.sh" href="http://www.monitoringexchange.org/cgi-bin/page.cgi?g=Detailed%2F3102.html" target="_blank">at MonitoringExchange</a> or directly from here via SVN and the copy&#8217;n'paste way below.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> <span style="color: #c20cb9; font-weight: bold;">svn</span>:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_ps<span style="color: #000000; font-weight: bold;">/</span> check_ps<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.0,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #007800;">process</span>=<span style="color: #ff0000;">&quot;cron&quot;</span>
<span style="color: #007800;">target</span>=<span style="color: #ff0000;">&quot;mem&quot;</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to check a specific process via ps.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;You may provide any string as an argument to match a specific&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;process. Please note that the output could be distorted if the&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;argument matches various processes, so please make sure to use&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;unique strings to match a process.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> -p firefox [-w 10] [-c 20] [-t cpu]&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -p/--process)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     You need to provide a string for which the ps output is then&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     then <span style="color: #000099; font-weight: bold;">\&quot;</span>greped<span style="color: #000099; font-weight: bold;">\&quot;</span>.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -w/--warning)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines a warning level for a target which is explained&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     below. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -c/--critical)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Defines a critical level for a target which is explained&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     below. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  -t/--target)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     A target can be defined via -t. Choose between cpu and mem.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;     Default is: mem&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        -help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --process<span style="color: #000000; font-weight: bold;">|</span>-p<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">process</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --target<span style="color: #000000; font-weight: bold;">|</span>-t<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">target</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warning</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">critical</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
get_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wclvls</span>=<span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warning}</span> <span style="color: #660033;">-gt</span> <span style="color: #800000;">${critical}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">2</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">3</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please adjust your warning/critical thresholds. The warning <span style="color: #000099; font-weight: bold;">\
</span>must be lower than the critical level!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a critical value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please also set a warning value when you want to use <span style="color: #000099; font-weight: bold;">\
</span>warning/critical thresholds!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_vals<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">process</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${process}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^.\|[a-z][A-Z] /\[&amp;]/g'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">tmp_output</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$process</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_output</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - Process is not running!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
    <span style="color: #007800;">ps_user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${tmp_output}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">ps_pid</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${tmp_output}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span> <span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">ps_cpu</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${tmp_output}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">ps_mem</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${tmp_output}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span> <span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">ps_start</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${tmp_output}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $9}'</span> <span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">tmp_ps_cputime</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${tmp_output}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $10}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp_ps_cpuhours</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${tmp_ps_cputime}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> \: <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp_ps_cpumin</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${tmp_ps_cputime}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> \: <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">ps_cputime</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=0; (<span style="color: #007800;">${tmp_ps_cpuhours}</span> * 60) + <span style="color: #000099; font-weight: bold;">\
</span><span style="color: #007800;">${tmp_ps_cpumin}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_wccalc<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$target</span>&quot;</span> = <span style="color: #ff0000;">&quot;cpu&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">tmp_wc_target</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${ps_cpu}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> \. <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_wc_target</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #000000;">5</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
            <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">wc_target</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${ps_cpu}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> \. <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #007800;">wc_target</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${wc_target}</span> + <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #007800;">wc_target</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${ps_cpu}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> \. <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">fi</span>
                <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$target</span>&quot;</span> = <span style="color: #ff0000;">&quot;mem&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
                <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #007800;">tmp_wc_target</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${ps_mem}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> \. <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$tmp_wc_target</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #000000;">5</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
            <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #007800;">wc_target</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${ps_mem}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> \. <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
                <span style="color: #007800;">wc_target</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #800000;">${wc_target}</span> + <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #007800;">wc_target</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${ps_mem}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span> \. <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
            <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_output<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">process</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${process}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\[//g'</span> <span style="color: #000000; font-weight: bold;">|</span>  <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/\]//g'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">output</span>=<span style="color: #ff0000;">&quot;Process: <span style="color: #007800;">${process}</span>, User: <span style="color: #007800;">${ps_user}</span>, CPU: <span style="color: #007800;">${ps_cpu}</span>%, <span style="color: #000099; font-weight: bold;">\
</span>RAM: <span style="color: #007800;">${ps_mem}</span>%, Start: <span style="color: #007800;">${ps_start}</span>, CPU Time: <span style="color: #007800;">${ps_cputime}</span> min&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_perfdata<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">perfdata</span>=<span style="color: #ff0000;">&quot;'cpu'=<span style="color: #007800;">${ps_cpu}</span> 'memory'=<span style="color: #007800;">${ps_mem}</span> 'cputime'=<span style="color: #007800;">${ps_cputime}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Here we go!</span>
get_wcdiff
val_wcdiff
&nbsp;
get_vals
do_wccalc
do_output
do_perfdata
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wc_target</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warning</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wc_target</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wc_target</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$critical</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<h3>PNP Template</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify
</span><span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by
</span><span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or
</span><span style="color: #666666; font-style: italic;">#   (at your option) any later version.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,
</span><span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of
</span><span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
</span><span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License
</span><span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software
</span><span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
</span>
<span style="color: #666666; font-style: italic;">#   PNP Template for check_ps.sh
</span><span style="color: #666666; font-style: italic;">#   Author: Mike Adolphs (http://www.matejunkie.com/
</span>
<span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;--vertical-label <span style="color: #000099; font-weight: bold;">\&quot;</span>percent<span style="color: #000099; font-weight: bold;">\&quot;</span> -u 100 -l 0 -r --title <span style="color: #000099; font-weight: bold;">\&quot;</span>CPU/Memory Usage for <span style="color: #006699; font-weight: bold;">$hostname</span> / <span style="color: #006699; font-weight: bold;">$servicedesc</span><span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;--vertical-label <span style="color: #000099; font-weight: bold;">\&quot;</span>minutes<span style="color: #000099; font-weight: bold;">\&quot;</span> -u 100 -l 0 -r --title <span style="color: #000099; font-weight: bold;">\&quot;</span>cputime for <span style="color: #006699; font-weight: bold;">$hostname</span> / <span style="color: #006699; font-weight: bold;">$servicedesc</span><span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;DEF:cpu=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[1]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:memory=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[2]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:cputime=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[3]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;COMMENT:<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tLAST<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tAVERAGE<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tMAX<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;COMMENT:<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tLAST<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tAVERAGE<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tMAX<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:cpu#E80C3E:<span style="color: #000099; font-weight: bold;">\&quot;</span>CPU<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cpu:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cpu:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cpu:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;LINE2:memory#008000:<span style="color: #000099; font-weight: bold;">\&quot;</span>Memory<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:memory:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:memory:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:memory:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:cputime#E80C3E:<span style="color: #000099; font-weight: bold;">\&quot;</span>CPUTime<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cputime:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf min<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cputime:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf min<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:cputime:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf min<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span></pre></div></div>

<h3>The License</h3>
<p>As always this little script is ment to be sh-compliant and released under the terms of the GPL Version 2 only. Feel free to subscribe via rss to get updates on this one. More options will be added in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/process-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Update 1.3: Bind check plugin for Nagios</title>
		<link>http://www.matejunkie.com/update-13-bind-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/update-13-bind-check-plugin-for-nagios/#comments</comments>
		<pubDate>Wed, 20 May 2009 08:06:52 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[BIND]]></category>
		<category><![CDATA[bugfix]]></category>
		<category><![CDATA[dns]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1038</guid>
		<description><![CDATA[Thanks to Gareth&#8217;s feedback and advice I fixed a small, but nerving bug which raised an error when the plugin was called on a Debian based distribution. The main problem here was, that the awk snippet failed because of an unescaped metacharacter when using mawk (Debian default awk alternative), but worked like a charm with [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to Gareth&#8217;s feedback and advice I fixed a small, but nerving bug which raised an error when the plugin was called on a Debian based distribution.<br />
The main problem here was, that the awk snippet failed because of an unescaped metacharacter when using mawk (Debian default awk alternative), but worked like a charm with gawk (Gentoo default). Apparently gawk is just more loose than mawk, it should&#8217;ve failed on both.</p>
<p>Anyway, this shouldn&#8217;t be a problem anymore. As always, the updated script is available <a title="MonitoringExchange - check_bind.sh" href="http://www.monitoringexchange.org/cgi-bin/page.cgi?g=Detailed%2F3003.html" target="_blank">at MonitoringExchange</a>, or via svn. Please consider that the svn checkout is only possible via svnserve at the moment.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host: ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> <span style="color: #c20cb9; font-weight: bold;">svn</span>:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_bind<span style="color: #000000; font-weight: bold;">/</span> check_bind<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/update-13-bind-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CPU check plugin for Nagios</title>
		<link>http://www.matejunkie.com/cpu-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/cpu-check-plugin-for-nagios/#comments</comments>
		<pubDate>Wed, 13 May 2009 10:48:13 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[cpu]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[jiffies]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[pnp template]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=970</guid>
		<description><![CDATA[I&#8217;ve just finished version 1.0 of a CPU check plugin which is sh-compliant (as always) and calculates utilization through Jiffies rather than using another third party tool like iostat or top. This means it should work on all Linux machines right out of the box without the need to install additional software. Frankly speaking the [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-193" title="logo_nagios" src="http://www.matejunkie.com/wp-content/uploads/2008/05/logo_nagios.gif" alt="logo_nagios" width="150" height="40" />I&#8217;ve just finished version 1.0 of a CPU check plugin which is sh-compliant (as always) and calculates utilization <a title="Wikipedia - Jiffy" href="http://en.wikipedia.org/wiki/Jiffy_(time)#Use_in_computing" target="_blank">through Jiffies</a> rather than using another third party tool like iostat or top. This means it should work on all Linux machines right out of the box without the need to install additional software.<br />
<a href="http://www.matejunkie.com/wp-content/uploads/2009/05/check_cpu_example01.png"><img class="alignright size-thumbnail wp-image-972" title="check_cpu_example01" src="http://www.matejunkie.com/wp-content/uploads/2009/05/check_cpu_example01-150x150.png" alt="check_cpu_example01" width="150" height="150" /></a>Frankly speaking the performance of the script is slightly worse than the performance of most of the other CPU check plugins due to the sacrifice of parsing iostat or top output, but I nevertheless wanted to do this since calculating CPU utilization through Jiffies instead of parsing another tool&#8217;s output is somewhat different and interesting. I didn&#8217;t take a look into iostat&#8217;s or top&#8217;s source code yet, but I guess these tools doesn&#8217;t do it in another way than parsing /proc/stat as well. The difference in performance isn&#8217;t that huge anyway, a double-digit amount of milliseconds, but not more.</p>
<p>For getting along with the Jiffies, I crawled through the web, especially <a title="Paul Colby's weblog - Calculating cpu utilization via /proc/stat" href="http://colby.id.au/node/39" target="_blank">Paul Colby&#8217;s article</a> about calculating CPU utilization through /proc/stat helped a lot!</p>
<h3>The script</h3>
<p>As always, the script is downloadable <a title="Nagiosexchange - check_cpu.sh" href="http://www.monitoringexchange.org/cgi-bin/page.cgi?g=Detailed%2F3077.html" target="_blank">from NagiosExchange</a>, via svn directly from here or the copy&#8217;n'paste way below. A proper PNP template is included as well.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> https:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_cpu<span style="color: #000000; font-weight: bold;">/</span> check_cpu<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.0,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #007800;">interval</span>=<span style="color: #000000;">1</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to monitor CPU utilization. It makes&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;use of /proc/stat and calculates it through Jiffies rather than&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;using another frontend tool like iostat or top.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;When using optional warning/critical thresholds all values except&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;idle are aggregated and compared to the thresholds. There's&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;currently no support for warning/critical thresholds for specific&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;usage parameters.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> [-i/--interval] [-w/--warning] [-c/--critical]&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --interval|-i)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Defines the pause between the two times /proc/stat is being&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    parsed. Higher values could lead to more accurate result.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Default is: 1 second&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --warning|-w)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets a warning level for CPU user. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --critical|-c)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets a critical level for CPU user. Default is: off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        --help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --interval<span style="color: #000000; font-weight: bold;">|</span>-i<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">interval</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warn</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">crit</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warn}</span> <span style="color: #660033;">-gt</span> <span style="color: #800000;">${crit}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_cpuvals<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">tmp1_cpu_user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_nice</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_sys</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_idle</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_iowait</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $6}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_irq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $7}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_softirq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $8}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp1_cpu_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$tmp1_cpu_user</span> + <span style="color: #007800;">$tmp1_cpu_nice</span> + <span style="color: #007800;">$tmp1_cpu_sys</span> + \
<span style="color: #007800;">$tmp1_cpu_idle</span> + <span style="color: #007800;">$tmp1_cpu_iowait</span> + <span style="color: #007800;">$tmp1_cpu_irq</span> + <span style="color: #007800;">$tmp1_cpu_softirq</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #007800;">$interval</span>
&nbsp;
    <span style="color: #007800;">tmp2_cpu_user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_nice</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $3}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_sys</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $4}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_idle</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $5}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_iowait</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $6}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_irq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $7}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_softirq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'^cpu'</span> <span style="color: #000000; font-weight: bold;">/</span>proc<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">stat</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $8}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">tmp2_cpu_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$tmp2_cpu_user</span> + <span style="color: #007800;">$tmp2_cpu_nice</span> + <span style="color: #007800;">$tmp2_cpu_sys</span> + \
<span style="color: #007800;">$tmp2_cpu_idle</span> + <span style="color: #007800;">$tmp2_cpu_iowait</span> + <span style="color: #007800;">$tmp2_cpu_irq</span> + <span style="color: #007800;">$tmp2_cpu_softirq</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">diff_cpu_user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_user}</span> - <span style="color: #007800;">${tmp1_cpu_user}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_nice</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_nice}</span> - <span style="color: #007800;">${tmp1_cpu_nice}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_sys</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_sys}</span> - <span style="color: #007800;">${tmp1_cpu_sys}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_idle</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_idle}</span> - <span style="color: #007800;">${tmp1_cpu_idle}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_iowait</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_iowait}</span> - <span style="color: #007800;">${tmp1_cpu_iowait}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_irq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_irq}</span> - <span style="color: #007800;">${tmp1_cpu_irq}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_softirq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_softirq}</span> - <span style="color: #007800;">${tmp1_cpu_softirq}</span>&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">diff_cpu_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${tmp2_cpu_total}</span> - <span style="color: #007800;">${tmp1_cpu_total}</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> -l<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
    <span style="color: #007800;">cpu_user</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_user}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_nice</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_nice}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_sys</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_sys}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_idle</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_idle}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_iowait</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_iowait}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)\<span style="color: #000099; font-weight: bold;">\
</span>/10&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_irq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_irq}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)/10&quot;</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_softirq</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_softirq}</span>/<span style="color: #007800;">${diff_cpu_total}</span>\<span style="color: #000099; font-weight: bold;">\
</span>+5)/10&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_total</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;scale=2; (1000*<span style="color: #007800;">${diff_cpu_total}</span>/<span style="color: #007800;">${diff_cpu_total}</span>+5)\<span style="color: #000099; font-weight: bold;">\
</span>/10&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'s/^\./0./'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #007800;">cpu_usage</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;(<span style="color: #007800;">${cpu_user}</span>+<span style="color: #007800;">${cpu_nice}</span>+<span style="color: #007800;">${cpu_sys}</span>+<span style="color: #007800;">${cpu_iowait}</span>+\<span style="color: #000099; font-weight: bold;">\
</span><span style="color: #007800;">${cpu_irq}</span>+<span style="color: #007800;">${cpu_softirq}</span>)/1&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bc</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_output<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">output</span>=<span style="color: #ff0000;">&quot;user: <span style="color: #007800;">${cpu_user}</span>, nice: <span style="color: #007800;">${cpu_nice}</span>, sys: <span style="color: #007800;">${cpu_sys}</span>, <span style="color: #000099; font-weight: bold;">\
</span>iowait: <span style="color: #007800;">${cpu_iowait}</span>, irq: <span style="color: #007800;">${cpu_irq}</span>, softirq: <span style="color: #007800;">${cpu_softirq}</span> <span style="color: #000099; font-weight: bold;">\
</span>idle: <span style="color: #007800;">${cpu_idle}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
do_perfdata<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">perfdata</span>=<span style="color: #ff0000;">&quot;'user'=<span style="color: #007800;">${cpu_user}</span> 'nice'=<span style="color: #007800;">${cpu_nice}</span> 'sys'=<span style="color: #007800;">${cpu_sys}</span> <span style="color: #000099; font-weight: bold;">\
</span>'softirq'=<span style="color: #007800;">${cpu_softirq}</span> 'iowait'=<span style="color: #007800;">${cpu_iowait}</span> 'irq'=<span style="color: #007800;">${cpu_irq}</span> <span style="color: #000099; font-weight: bold;">\
</span>'idle'=<span style="color: #007800;">${cpu_idle}</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    val_wcdiff
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Please adjust your warning/critical thresholds. The warning\<span style="color: #000099; font-weight: bold;">\
</span>must be lower than the critical level!&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
get_cpuvals
do_output
do_perfdata
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$cpu_usage</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$cpu_usage</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$cpu_usage</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">${output}</span> | <span style="color: #007800;">${perfdata}</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify
</span><span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by
</span><span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or
</span><span style="color: #666666; font-style: italic;">#   (at your option) any later version.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,
</span><span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of
</span><span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
</span><span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.
</span><span style="color: #666666; font-style: italic;">#
</span><span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License
</span><span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software
</span><span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
</span>
<span style="color: #666666; font-style: italic;">#   PNP Template for check_cpu.sh
</span><span style="color: #666666; font-style: italic;">#   Author: Mike Adolphs (http://www.matejunkie.com/
</span>
<span style="color: #000088;">$opt</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;--vertical-label <span style="color: #000099; font-weight: bold;">\&quot;</span>CPU [%]<span style="color: #000099; font-weight: bold;">\&quot;</span> -u 100 -l 0 -r --title <span style="color: #000099; font-weight: bold;">\&quot;</span>CPU Usage for <span style="color: #006699; font-weight: bold;">$hostname</span> / <span style="color: #006699; font-weight: bold;">$servicedesc</span><span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span>  <span style="color: #0000ff;">&quot;DEF:used=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[1]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:nice=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[2]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:sys=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[3]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:iowait=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[4]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:irq=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[5]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:softirq=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[6]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span>  <span style="color: #0000ff;">&quot;DEF:idle=<span style="color: #006699; font-weight: bold;">$rrdfile</span>:<span style="color: #006699; font-weight: bold;">$DS[7]</span>:AVERAGE &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;COMMENT:<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tLAST<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tAVERAGE<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>tMAX<span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:used#E80C3E:<span style="color: #000099; font-weight: bold;">\&quot;</span>user<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span> 
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:used:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:used:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:used:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:nice#E8630C:<span style="color: #000099; font-weight: bold;">\&quot;</span>nice<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span> 
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:nice:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:nice:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:nice:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:sys#008000:<span style="color: #000099; font-weight: bold;">\&quot;</span>sys<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:sys:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:sys:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:sys:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:iowait#0CE84D:<span style="color: #000099; font-weight: bold;">\&quot;</span>iowait<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:iowait:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:iowait:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:iowait:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:irq#3E00FF:<span style="color: #000099; font-weight: bold;">\&quot;</span>irq<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\t</span><span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:irq:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:irq:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:irq:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:softirq#1CC8E8:<span style="color: #000099; font-weight: bold;">\&quot;</span>softirq<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:softirq:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:softirq:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:softirq:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;AREA:idle#FFFF00:<span style="color: #000099; font-weight: bold;">\&quot;</span>idle<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span>:STACK &quot;</span> <span style="color: #339933;">;</span> 
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:idle:LAST:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #009933; font-weight: bold;">%%</span><span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:idle:AVERAGE:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\\</span>t<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000088;">$def</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;GPRINT:idle:MAX:<span style="color: #000099; font-weight: bold;">\&quot;</span>%6.2lf <span style="color: #000099; font-weight: bold;">\\</span>n<span style="color: #000099; font-weight: bold;">\&quot;</span> &quot;</span> <span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h3>The License</h3>
<p><a href="http://www.matejunkie.com/wp-content/uploads/2009/05/check_cpu_example02.png"><img class="alignright size-thumbnail wp-image-973" title="check_cpu_example02" src="http://www.matejunkie.com/wp-content/uploads/2009/05/check_cpu_example02-150x150.png" alt="check_cpu_example02" width="150" height="150" /></a>As always this little script is ment to be sh-compliant and released under the terms of the GPL Version 2 only. Feel free to subscribe via rss to get updates on this one. More options will be added in the future.<br />
I&#8217;ll probably add an option to make use of iostat or top and to calculate utilization per CPU soon so that you&#8217;re able to choose your own way.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/cpu-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Update 1.1: UDP Packet Loss Check Plugin for Nagios</title>
		<link>http://www.matejunkie.com/update-11-udp-packet-loss-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/update-11-udp-packet-loss-check-plugin-for-nagios/#comments</comments>
		<pubDate>Mon, 11 May 2009 09:36:39 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[icinga]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[netstat]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[udp]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=966</guid>
		<description><![CDATA[I&#8217;ve changed the small UDP packet loss script yesterday so that it&#8217;s now showing the total requests, requests sent to an unknown port and receive errors per check interval. That means, if you&#8217;d choose a check interval of 5 minutes, the script shows the amount of the previous mentioned for this time frame. It now [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-193" title="logo_nagios" src="http://www.matejunkie.com/wp-content/uploads/2008/05/logo_nagios.gif" alt="logo_nagios" width="150" height="40" />I&#8217;ve changed the small UDP packet loss script yesterday so that it&#8217;s now showing the total requests, requests sent to an unknown port and receive errors per check interval. That means, if you&#8217;d choose a check interval of 5 minutes, the script shows the amount of the previous mentioned for this time frame. It now creates two temporary files in a directory which you may define via -t/&#8211;path-tmp. The file is automatically deleted when it&#8217;s size got over 32Kb.<br />
Feel free to grab it <a title="MonitoringExchange - check_udp-packet-loss.sh" href="http://www.monitoringexchange.org/cgi-bin/page.cgi?g=Detailed%2F3063.html" target="_blank">from MonitoringExchange</a> (they&#8217;ve changed their name due to legal problems with <a title="Nagios Enterprises" href="http://www.nagios.com/" target="_blank">Nagios Enterprises</a> and because of Nagios&#8217; <a title="Icinga" href="http://www.icinga.org/" target="_blank">new fork Icinga</a>), via svn or copy&#8217;n'paste below.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> https:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-loss<span style="color: #000000; font-weight: bold;">/</span> check_udp-packet-loss<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.1,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #007800;">path_tmp</span>=<span style="color: #ff0000;">&quot;/tmp&quot;</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to monitor the UDP packet&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;loss via netstat. It writes a temporary file to a configurable&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;directory and compares it's values against the ones from the check&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;before.&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;That means the actual result shows the amount of overall packets,&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;received, receive errors and/or packets recieved to unknown port&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;for the last check interval you've chosen.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> check_udp-packet-loss.sh&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --warning|-w)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets a warning level for packet receive errors. Default is:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --critical|-c)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets a critical level for packet receive errors. Default is:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --path-tmp|-t)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets the path for the temporary file. Default is: /tmp&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        --help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --path-tmp<span style="color: #000000; font-weight: bold;">|</span>-t<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">path_tmp</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warn</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">crit</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
check_filesize<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">size</span></span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$size</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">32</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log
            <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log
    <span style="color: #000000; font-weight: bold;">fi</span>   
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
get_packet_loss<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #007800;">date_beg</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;+++ <span style="color: #007800;">$date_beg</span> +++&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log
    <span style="color: #c20cb9; font-weight: bold;">netstat</span> -us<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'packets received'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log
    <span style="color: #c20cb9; font-weight: bold;">netstat</span> -us<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'to unknown port'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log
    <span style="color: #c20cb9; font-weight: bold;">netstat</span> -us<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'packet receive errors'</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log
	<span style="color: #007800;">date_end</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;--- <span style="color: #007800;">$date_end</span> ---&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log
	<span style="color: #c20cb9; font-weight: bold;">tac</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>udp-errors.log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'/---/{p=1} p{print} /+++/{p=0;if \
(count++==1) exit}'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log.tmp
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
chk_packet_loss<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	<span style="color: #007800;">p_receive_1st</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tac</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log.tmp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'packets \
received'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;">p_receive_2nd</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tac</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log.tmp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'packets \
received'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'packets received'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;">p_unknown_1st</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tac</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log.tmp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'to unknown \
port'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;">p_unknown_2nd</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tac</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log.tmp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'to unknown \
port'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'to unknown port'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;">p_errors_1st</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tac</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log.tmp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'receive \
errors'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #007800;">p_errors_2nd</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">tac</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>udp-errors.log.tmp <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'receive errors'</span> \
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sort</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-m1</span> <span style="color: #ff0000;">'receive errors'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #007800;">$p_receive_2nd</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #007800;">p_receive</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$p_receive_2nd</span> - <span style="color: #007800;">$p_receive_1st</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #007800;">p_receive</span>=<span style="color: #000000;">0</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p_unknown_2nd</span>&quot;</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #007800;">p_unknown</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$p_unknown_2nd</span> - <span style="color: #007800;">$p_unknown_1st</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #007800;">p_unknown</span>=<span style="color: #000000;">0</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p_errors_2nd</span>&quot;</span> = <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
	<span style="color: #000000; font-weight: bold;">then</span>
		<span style="color: #007800;">p_errors</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">expr</span> <span style="color: #007800;">$p_errors_2nd</span> - <span style="color: #007800;">$p_errors_1st</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">else</span>
		<span style="color: #007800;">p_errors</span>=<span style="color: #000000;">0</span>
	<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warn}</span> <span style="color: #660033;">-gt</span> <span style="color: #800000;">${crit}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
check_filesize
get_packet_loss
chk_packet_loss
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    val_wcdiff
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The warning level should be lower than the critical level. <span style="color: #000099; font-weight: bold;">\
</span>Please adjust them.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p_unknown</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p_unknown</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">$p_receive</span> total packets received, <span style="color: #007800;">$p_unknown</span> \ 
went to unknown port, <span style="color: #007800;">$p_errors</span> receive errors! | <span style="color: #000099; font-weight: bold;">\
</span>'received'=<span style="color: #007800;">$p_receive</span> 'unknown_port'=<span style="color: #007800;">$p_unknown</span> 'errors'=<span style="color: #007800;">$p_errors</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p_unknown</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">$p_receive</span> total packets received, <span style="color: #007800;">$p_unknown</span> <span style="color: #000099; font-weight: bold;">\
</span>went to unknown port, <span style="color: #007800;">$p_errors</span> receive errors! | <span style="color: #000099; font-weight: bold;">\
</span>'received'=<span style="color: #007800;">$p_receive</span> 'unknown_port'=<span style="color: #007800;">$p_unknown</span> 'errors'=<span style="color: #007800;">$p_errors</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">$p_receive</span> total packets received, <span style="color: #007800;">$p_unknown</span> <span style="color: #000099; font-weight: bold;">\
</span>went to unknown port, <span style="color: #007800;">$p_errors</span> receive errors! | <span style="color: #000099; font-weight: bold;">\
</span>'received'=<span style="color: #007800;">$p_receive</span> 'unknown_port'=<span style="color: #007800;">$p_unknown</span> 'errors'=<span style="color: #007800;">$p_errors</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">$p_receive</span> total packets received, <span style="color: #007800;">$p_unknown</span> went to unknown <span style="color: #000099; font-weight: bold;">\
</span>port, <span style="color: #007800;">$p_errors</span> receive errors! | 'received'=<span style="color: #007800;">$p_receive</span> <span style="color: #000099; font-weight: bold;">\
</span>'unknown_port'=<span style="color: #007800;">$p_unknown</span> 'errors'=<span style="color: #007800;">$p_errors</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/update-11-udp-packet-loss-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UDP Packet Loss Check Plugin for Nagios</title>
		<link>http://www.matejunkie.com/udp-packet-loss-check-plugin-for-nagios/</link>
		<comments>http://www.matejunkie.com/udp-packet-loss-check-plugin-for-nagios/#comments</comments>
		<pubDate>Tue, 05 May 2009 22:20:10 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[gplv2]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[netstat]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[udp]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=953</guid>
		<description><![CDATA[I just needed to rewrite a small check plugin I&#8217;ve written a few months ago to check possible UDP data loss on a host which serves an application that constantly has to process tens of thousand UDP packets at a time. Otherwise we just wouldn&#8217;t know in time when the application or the host&#8217;s network [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-193" title="logo_nagios" src="http://www.matejunkie.com/wp-content/uploads/2008/05/logo_nagios.gif" alt="logo_nagios" width="150" height="40" />I just needed to rewrite a small check plugin I&#8217;ve written a few months ago to check possible UDP data loss on a host which serves an application that constantly has to process tens of thousand UDP packets at a time. Otherwise we just wouldn&#8217;t know in time when the application or the host&#8217;s network stack become somewhat limited because of UDP&#8217;s stateless nature and that&#8217;s what you better wanna know for sure if the transmitted data is valuable for the company.</p>
<h3>The script</h3>
<p>As always, the script is downloadable <a title="Nagiosexchange - check_udp-packet-loss.sh" href="http://www.nagiosexchange.org/cgi-bin/page.cgi?g=Detailed%2F3063.html" target="_blank">from NagiosExchange</a>, via svn directly from here or the copy&#8217;n'paste way below.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">svn</span> <span style="color: #c20cb9; font-weight: bold;">co</span> https:<span style="color: #000000; font-weight: bold;">//</span>svn.matejunkie.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>nagios-plugins<span style="color: #000000; font-weight: bold;">/</span>stable<span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-loss<span style="color: #000000; font-weight: bold;">/</span> check_udp-packet-loss<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>It makes use of netstat to check for packets received to an unknown port or receive errors and to monitor the overall count of UDP packets received. This information is being put into a file in a temporary directory which is not being used at all for now, I must confess. The idea behind that is to rather monitor UDP packet receive errors over a period of time instead of its total count, but since there&#8217;s other heavy stuff going on at the moment, I just don&#8217;t have the time to finish this at the moment. I&#8217;ll do this within the next weeks.<br />
The script checks by itselfs whether the file grows over 32K, then deletes and re-creates it. So no worries about broken hard drives here.</p>
<p>The term &#8220;packets to unknown port received&#8221; is explained as the following: &#8220;Displays the total number of UDP datagrams received for which there was no application at the destination port&#8221; which means that e.g. those will increase when you&#8217;d temporarily shutdown your application. &#8220;packet receive errors&#8221; will mostly occur when the host&#8217;s buffer is bursting. For additional information I&#8217;d suggest reading <a title="29west.com - UDP Buffer Sizing" href="http://www.29west.com/docs/THPM/udp-buffer-sizing.html" target="_blank">&#8220;UDP Buffer sizing&#8221;</a> at 29west.com and <a title="kernel.org - udp man page" href="http://www.kernel.org/doc/man-pages/online/pages/man7/udp.7.html" target="_blank">UDP&#8217;s man page</a> at kernel.org.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#   This program is free software; you can redistribute it and/or modify</span>
<span style="color: #666666; font-style: italic;">#   it under the terms of the GNU General Public License as published by</span>
<span style="color: #666666; font-style: italic;">#   the Free Software Foundation; either version 2 of the License, or</span>
<span style="color: #666666; font-style: italic;">#   (at your option) any later version.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   This program is distributed in the hope that it will be useful,</span>
<span style="color: #666666; font-style: italic;">#   but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span style="color: #666666; font-style: italic;">#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span style="color: #666666; font-style: italic;">#   GNU General Public License for more details.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#   You should have received a copy of the GNU General Public License</span>
<span style="color: #666666; font-style: italic;">#   along with this program; if not, write to the Free Software</span>
<span style="color: #666666; font-style: italic;">#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA</span>
&nbsp;
<span style="color: #007800;">PROGNAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> $<span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">VERSION</span>=<span style="color: #ff0000;">&quot;Version 1.0,&quot;</span>
<span style="color: #007800;">AUTHOR</span>=<span style="color: #ff0000;">&quot;2009, Mike Adolphs (http://www.matejunkie.com/)&quot;</span>
&nbsp;
<span style="color: #007800;">ST_OK</span>=<span style="color: #000000;">0</span>
<span style="color: #007800;">ST_WR</span>=<span style="color: #000000;">1</span>
<span style="color: #007800;">ST_CR</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">ST_UK</span>=<span style="color: #000000;">3</span>
&nbsp;
<span style="color: #007800;">path_tmp</span>=<span style="color: #ff0000;">&quot;/tmp&quot;</span>
&nbsp;
print_version<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$VERSION</span> <span style="color: #007800;">$AUTHOR</span>&quot;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
print_help<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> is a Nagios plugin to monitor the UDP packet loss via&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;netstat.&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$PROGNAME</span> check_udp-packet-loss.sh&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Options:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --warning|-w)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets a warning level for packet receive errors. Default is:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --critical|-c)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets a critical level for packet receive errors. Default is:&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    off&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;  --path-tmp|-t)&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;    Sets the path for the temporary file. Default is: /tmp&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">test</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;$1&quot;</span>; <span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
        --help<span style="color: #000000; font-weight: bold;">|</span>-h<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --version<span style="color: #000000; font-weight: bold;">|</span>-v<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            print_version <span style="color: #007800;">$PROGNAME</span> <span style="color: #007800;">$VERSION</span>
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --path-tmp<span style="color: #000000; font-weight: bold;">|</span>-t<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">path_tmp</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --warning<span style="color: #000000; font-weight: bold;">|</span>-w<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">warn</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        --critical<span style="color: #000000; font-weight: bold;">|</span>-c<span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #007800;">crit</span>=$<span style="color: #000000;">2</span>
            <span style="color: #7a0874; font-weight: bold;">shift</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
            <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown argument: $1&quot;</span>
            print_help
            <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
            <span style="color: #000000; font-weight: bold;">;;</span>
    <span style="color: #000000; font-weight: bold;">esac</span>
    <span style="color: #7a0874; font-weight: bold;">shift</span>
<span style="color: #000000; font-weight: bold;">done</span>
&nbsp;
check_filesize<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-errors.log <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">size</span></span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-errors.log <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
	<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$size</span> <span style="color: #660033;">-gt</span> <span style="color: #000000;">32</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
        <span style="color: #000000; font-weight: bold;">then</span>
            <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-errors.log
            <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-errors.log
        <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-errors.log
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
check_packet_loss<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #007800;">p_receive</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">netstat</span> -us<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'packets received'</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Received: <span style="color: #007800;">$p_receive</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-errors.log
    <span style="color: #007800;">p_unknown</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">netstat</span> -us<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'to unknown port'</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Unknown: <span style="color: #007800;">$p_unknown</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-errors.log
    <span style="color: #007800;">p_errors</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">netstat</span> -us<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'packet receive errors'</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #000000; font-weight: bold;">`</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Errors: <span style="color: #007800;">$p_errors</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$path_tmp</span><span style="color: #000000; font-weight: bold;">/</span>check_udp-packet-errors.log
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
val_wcdiff<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #800000;">${warn}</span> <span style="color: #660033;">-gt</span> <span style="color: #800000;">${crit}</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #007800;">wcdiff</span>=<span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
check_filesize
check_packet_loss
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    val_wcdiff
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$wcdiff</span>&quot;</span> = <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The warning level should be lower than the critical level. Please adjust them.&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_UK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p_unknown</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$warn</span>&quot;</span> <span style="color: #660033;">-a</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p_unknown</span>&quot;</span> <span style="color: #660033;">-lt</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;WARNING - <span style="color: #007800;">$p_receive</span> total packets received, <span style="color: #007800;">$p_unknown</span> went to unknown port, <span style="color: #007800;">$p_errors</span> receive errors! | 'received'=<span style="color: #007800;">$p_receive</span> 'unknown_port'=<span style="color: #007800;">$p_unknown</span> 'errors'=<span style="color: #007800;">$p_errors</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_WR</span>
    <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$p_unknown</span>&quot;</span> <span style="color: #660033;">-ge</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$crit</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;CRITICAL - <span style="color: #007800;">$p_receive</span> total packets received, <span style="color: #007800;">$p_unknown</span> went to unknown port, <span style="color: #007800;">$p_errors</span> receive errors! | 'received'=<span style="color: #007800;">$p_receive</span> 'unknown_port'=<span style="color: #007800;">$p_unknown</span> 'errors'=<span style="color: #007800;">$p_errors</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_CR</span>
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">$p_receive</span> total packets received, <span style="color: #007800;">$p_unknown</span> went to unknown port, <span style="color: #007800;">$p_errors</span> receive errors! | 'received'=<span style="color: #007800;">$p_receive</span> 'unknown_port'=<span style="color: #007800;">$p_unknown</span> 'errors'=<span style="color: #007800;">$p_errors</span>&quot;</span>
        <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;OK - <span style="color: #007800;">$p_receive</span> total packets received, <span style="color: #007800;">$p_unknown</span> went to unknown port, <span style="color: #007800;">$p_errors</span> receive errors! | 'received'=<span style="color: #007800;">$p_receive</span> 'unknown_port'=<span style="color: #007800;">$p_unknown</span> 'errors'=<span style="color: #007800;">$p_errors</span>&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #007800;">$ST_OK</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<h3>The License</h3>
<p>As always this little script is ment to be sh-compliant and released under the terms of the GPL Version 2 only. Feel free to subscribe via rss to get updates on this one. More options will be added in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/udp-packet-loss-check-plugin-for-nagios/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
