<?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; linux</title>
	<atom:link href="http://www.matejunkie.com/tag/linux/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>How to find a proper monitoring solution</title>
		<link>http://www.matejunkie.com/how-to-find-a-proper-monitoring-solution/</link>
		<comments>http://www.matejunkie.com/how-to-find-a-proper-monitoring-solution/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 22:03:54 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[cacti]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mrtg]]></category>
		<category><![CDATA[munin]]></category>
		<category><![CDATA[nagios]]></category>
		<category><![CDATA[nagvis]]></category>
		<category><![CDATA[ndoutils]]></category>
		<category><![CDATA[network monitoring]]></category>
		<category><![CDATA[npcd]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[pnp4nagios]]></category>
		<category><![CDATA[snmp]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[unix]]></category>
		<category><![CDATA[zabbix]]></category>
		<category><![CDATA[zenoss]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1282</guid>
		<description><![CDATA[As in our own environment at nugg.ad every startup/HA environment needs a proper monitoring solution to fit the minimum requirements to fullfill the high availability demands of your customers. Without a proper solution you can trust on you&#8217;re screwed. It&#8217;s simple as that. You just need to know first whether your application servers are melting, [...]]]></description>
			<content:encoded><![CDATA[<p>As in our own environment <a title="nugg.ad AG predictive behavioral targeting" href="http://www.nugg.ad/" target="_blank">at nugg.ad</a> every startup/HA environment needs a proper monitoring solution to fit the minimum requirements to fullfill the high availability demands of your customers. Without a proper solution you can trust on you&#8217;re screwed. It&#8217;s simple as that.<br />
You just need to know first whether your application servers are melting, your database/nosql backend begins to burst or someone accidentally the whole thing (you know the meme, <a title="Encyclopedia Dramatica - I accidentally" href="http://encyclopediadramatica.com/I_accidentally_X" target="_blank">do you?</a>). Not only to inform customers before they call you, but also to be able to plan further growth of your environment.</p>
<p>Since I&#8217;m currently rewriting our whole monitoring environment based on 3 1/2 years experience with Nagios and its competitors I thought to share that knowledge with you. Just in case someone has a use for this.</p>
<h3>Choosing a monitoring solution</h3>
<p>First rule: Stick with the monitoring solution you&#8217;re at least a bit experienced with and which fits to your environment. In huge environments <a title="Zabbix" href="http://www.zabbix.com/" target="_blank">Zabbix is capable</a> of doing the monitoring work for you and <a title="Zenoss" href="http://www.zenoss.com/" target="_blank">so is Zenoss</a> or <a title="Nagios" href="http://www.nagios.org/" target="_blank">Nagios</a> as well. In smaller environments <a title="MRTG" href="http://oss.oetiker.ch/mrtg/" target="_blank">MRTG</a> or <a title="Munin" href="http://munin.projects.linpro.no/" target="_blank">Munin</a> might also do the job.<br />
All big Open Source monitoring solutions are highly customizable and extendable. You just need to know how to find the right plugins or to ask properly within the community how something can be achieved.<br />
If you&#8217;re not experienced with Open Source monitoring solutions at all, get a first look on <a title="Wikipedia - Comparison of network monitoring tools" href="http://en.wikipedia.org/wiki/Comparison_of_network_monitoring_systems" target="_blank">the feature set of various solutions</a> at Wikipedia. Choose wisely afterwards and most important: Stick to that solution for quite a while to explore its advantages and to get better at anger management when facing its disadvantages as well. Sooner or later you&#8217;ll get the big picture.</p>
<p>It&#8217;s not that important which software you choose. It&#8217;s more important what you make out of it for your environment!</p>
<h3>The user&#8217;s demands</h3>
<p>What I&#8217;ve expierienced within the last years is that the demands are quite comprehensive:</p>
<ol>
<li>The operations team needs to get informed almost instantly in case of a real emergency via various contact possibilities<br />
&#8230; and it&#8217;ll let you stay longer at the office to fix this when they get woken up each night due to false alarms</li>
<li>The CTO needs proper escalation methods to get informed when something&#8217;s broken and not taken care of</li>
<li>The executives and its board need a nice and shiny visualization of the platform to present the company&#8217;s growth and its state</li>
<li>The consulting or support team needs a simple read only web-interface to get a proper impression whether everything&#8217;s allright in case of a unexpected customer call.</li>
</ol>
<p>All of these demands have something in common: <strong>The basis of all operations is trust</strong>.</p>
<p>The operations team has to trust your monitoring solution to fix problems in a fast, but advised way instead of ignoring problems after the fourth false alarm during a week. The CTO needs to know that your escalation strategies are working and that you don&#8217;t screw him. The executives need proper graphs without spikes or even downtimes which they&#8217;re not able to explain within meetings and the consulting or support team&#8217;s need is to get an overview of an almost real time state of your environment without getting confused.</p>
<h3>My monitoring environment</h3>
<p>I&#8217;m currently using <a title="Nagios" href="http://www.nagios.org/" target="_blank">Nagios</a> as the basic monitoring solution for our environment with several plugins attached to it.</p>
<p>To reuse all the data provided by Nagios I let it write its information to a MySQL database <a title="Nagios - ndoutils" href="http://www.nagios.org/download/addons" target="_blank">via ndoutils</a>. This enables you to use almost any software which understands the ndoutils database layout, e.g. nice and shiny web-interfaces or visualization tools like nagvis.<br />
For the graphing I&#8217;m currently using two solutions. <a title="pnp4nagios" href="http://www.pnp4nagios.org/" target="_blank">pnp4nagios 0.6x</a> with its highly recommended NPCD daemon acts as the basis for proper graphing of various system information. Since the pnp4nagios web-interface is only recommended for Unix/Linux system administrators I&#8217;m reusing the rrd databases <a title="Cacti" href="http://www.cacti.net/" target="_blank">within Cacti</a> to provide a better overview of the whole platform. Cacti again is mostly being used for SNMP based checks which needs no alerting.</p>
<p>You&#8217;ll now see the difference: System metrics which needs a proper alerting are handled by Nagios itself and metrics that only needs to be monitored for its statistics are realized via Cacti (and therefore mostly SNMP). This eases your configuration work, keeps system resources in balance and avoids misunderstandings within the team that needs to take care of your environment while enjoying your Martini on the Keys.</p>
<p>To enable the consultants to get a good overview of the platform&#8217;s health, I&#8217;m using two different tools. At first <a title="NagVis" href="http://www.nagvis.org/" target="_blank">NagVis provides</a> a graphic overview of the system&#8217;s health without providing too detailed data. A traffic light based graphic with three states (green, yellow and red) might be too few information, but a Google Maps based view of your various datacenter locations with green, yellow or red icons will do the job. The supporters then are able to explain to the customer that datacenter 123 is down due to a failure within the system which is enough in most cases. All other cases with demand of a clearer view will be redirected to you, no worries. They know their job.<br />
For the consultants which are more experienced with the system itself I provide a nice and shiny <a title="Nagios Plugin for Cacti" href="http://trac2.assembla.com/npc" target="_blank">Nagios interface within Cacti</a> itself. They&#8217;re able then to access Cacti&#8217;s performance graphs and the metrics provided by Nagios as well.</p>
<h3>Conclusion</h3>
<p>Maintaining an Open Source monitoring solution means a lot of work and you have to grapple with your favorite monitoring solution for quite a while before achieving your goals. But if you do, you&#8217;re the peacekeeper that lets your colleagues sleep during the night, the magician that casts nice and shiny graphs instantly and the master who has a global overview of your platform.<br />
I hope, this gave you a basic view on how to find the right monitoring solution for you without going into the technical details. If you&#8217;ve got any questions let me know.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 342px; width: 1px; height: 1px;">http://www.youtube.com/watch?v=JmS0Kjxs2v4</div>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/how-to-find-a-proper-monitoring-solution/feed/</wfw:commentRss>
		<slash:comments>1</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>The Top 10 of your most used UNIX commands</title>
		<link>http://www.matejunkie.com/the-top-10-of-your-most-used-unix-commands/</link>
		<comments>http://www.matejunkie.com/the-top-10-of-your-most-used-unix-commands/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 09:30:30 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[IBM]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[shell commands]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1192</guid>
		<description><![CDATA[Almost three years ago Uwe Hermann posted a one-liner in his blog which was mentioned in an article from IBM called UNIX Productivity tips. It shows you the ten most used commands on your local machine and I think it&#8217;s time to revive this habit. Do the following on your console and see what you&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>Almost three years ago Uwe Hermann <a title="Uwe Hermann - The Top Ten Unix shell commands you use" href="http://www.hermann-uwe.de/blog/the-top-ten-unix-shell-commands-you-use" target="_blank">posted a one-liner</a> in his blog which was mentioned in an <a title="IBM - UNIX Productivity tips" href="http://www.ibm.com/developerworks/aix/library/au-productivitytips.html?ca=dgr-lnxw07UNIX-Office-Tips" target="_blank">article from IBM</a> called UNIX Productivity tips. It shows you the ten most used commands on your local machine and I think it&#8217;s time to revive this habit.</p>
<p>Do the following on your console and see what you&#8217;re frequently using:</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: #7a0874; font-weight: bold;">history</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: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'BEGIN {FS=&quot;|&quot;} {print $1}'</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sort</span><span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">uniq</span> -c<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">sort</span> -rn<span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">head</span> <span style="color: #660033;">-10</span></pre></div></div>

<p>This is the result of my workstation which now runs for about 1 1/2 months with a current total of 8.000 commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">   <span style="color: #000000;">1987</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span>
    <span style="color: #000000;">767</span> <span style="color: #c20cb9; font-weight: bold;">ls</span>
    <span style="color: #000000;">746</span> <span style="color: #c20cb9; font-weight: bold;">sudo</span>
    <span style="color: #000000;">349</span> <span style="color: #000000; font-weight: bold;">for</span>
    <span style="color: #000000;">267</span> <span style="color: #7a0874; font-weight: bold;">cd</span>
    <span style="color: #000000;">259</span> <span style="color: #7a0874; font-weight: bold;">exit</span>
    <span style="color: #000000;">231</span> <span style="color: #c20cb9; font-weight: bold;">vim</span>
    <span style="color: #000000;">156</span> <span style="color: #c20cb9; font-weight: bold;">svn</span>
    <span style="color: #000000;">154</span> <span style="color: #c20cb9; font-weight: bold;">ping</span>
    <span style="color: #000000;">130</span> <span style="color: #7a0874; font-weight: bold;">pwd</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/the-top-10-of-your-most-used-unix-commands/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>To get Songbird 1.2 up and running under Ubuntu 9.04</title>
		<link>http://www.matejunkie.com/to-get-songbird-1-2-up-and-running-under-ubuntu-9-04/</link>
		<comments>http://www.matejunkie.com/to-get-songbird-1-2-up-and-running-under-ubuntu-9-04/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 08:44:04 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[equalizer]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[interoperability]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[songbird]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[wmii]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1171</guid>
		<description><![CDATA[For those about to rock: Songbird is an Open Source iTunes alternative which aims to be interoperable between Windows, Mac and Linux operating systems. When I checked out Songbird 1.1 a few weeks ago I was quite astonished in the first place. It comes with a nice and shiny interface, it&#8217;s fast and quite stable [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.matejunkie.com/wp-content/uploads/2009/06/ninja-heroes.png"><img class="alignleft size-thumbnail wp-image-1172" title="Get Songbird" src="http://www.matejunkie.com/wp-content/uploads/2009/06/ninja-heroes-150x150.png" alt="Get Songbird" width="150" height="150" /></a>For those about to rock: Songbird is an Open Source iTunes alternative which aims to be interoperable between Windows, Mac and Linux operating systems.</p>
<p>When I checked out <a title="Get Songbird" href="http://getsongbird.com/" target="_blank">Songbird</a> 1.1 a few weeks ago I was quite astonished in the first place. It comes with a nice and shiny interface, it&#8217;s fast and quite stable as well and, of course, there&#8217;re various web-services like Shoutcast or Last.fm integrated. The only thing that Songbird 1.1 really lacked off was the non-existing equalizer, which is indispensable in my opinion. Therefore, I switched back to Amarok 1.4 on my Ubuntu desktop (Gnome) and to audacious on my Gentoo desktop (wmii).</p>
<p>Yesterday Songbird 1.2 has been released and besides a lot of <a title="Get Songbird - Features" href="http://getsongbird.com/features/" target="_blank">other improvements</a>&#8230; hell yes, it now has an equalizer onboard which works well at least for my sense of hearing.</p>
<p>To get it running under Ubuntu simply download the tar.gz from the Songbird website, extract it and remove two libvisual plugins that otherwise prevent Songbird from starting up.</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;">aptitude</span> remove libvisual-<span style="color: #000000;">0.4</span>-plugins libvisual-projectm</pre></div></div>

<p>If you haven&#8217;t checked it out yet, <a title="Get Songbird" href="http://getsongbird.com/" target="_blank">give it a go</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/to-get-songbird-1-2-up-and-running-under-ubuntu-9-04/feed/</wfw:commentRss>
		<slash:comments>1</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>How to fix NetworkManager&#8217;s OpenVPN plugin in Ubuntu 9.04</title>
		<link>http://www.matejunkie.com/how-to-fix-networkmanagers-openvpn-plugin-in-ubuntu-904/</link>
		<comments>http://www.matejunkie.com/how-to-fix-networkmanagers-openvpn-plugin-in-ubuntu-904/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 13:07:06 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[gnome]]></category>
		<category><![CDATA[launchpad]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[network manager]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[openvpn]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1139</guid>
		<description><![CDATA[The OpenVPN plugin for Gnome&#8217;s NetworkManager is somewhat broken, at least in various Ubuntu releases. Even with proper configuration it runs into an &#8220;NeedSecrets&#8221; error although the same command with the same configuration from shell via sudo work&#8217;s just fine. But fear not mighty roadwarrior! Here&#8217;s a fix to let the NetworkManager get back to [...]]]></description>
			<content:encoded><![CDATA[<p>The OpenVPN plugin for Gnome&#8217;s NetworkManager is somewhat broken, at least in various Ubuntu releases. Even with proper configuration it runs into an &#8220;NeedSecrets&#8221; error although the same command with the same configuration from shell via sudo work&#8217;s just fine.<br />
But fear not mighty roadwarrior! Here&#8217;s a fix to let the NetworkManager get back to work.</p>
<p>Needless to say that this is just a temporary solution (a fix is in the making), but the only thing you have to do is to add an at_console policy to /etc/dbus-1/system.d/nm-openvpn-service.conf right between the two already existing policies.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;policy</span> <span style="color: #000066;">user</span>=<span style="color: #ff0000;">&quot;at_console&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.vpnc&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.vpnc&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Then the file should look like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #00bbdd;">&lt;!DOCTYPE busconfig PUBLIC</span>
<span style="color: #00bbdd;"> &quot;-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN&quot;</span>
<span style="color: #00bbdd;"> &quot;http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd&quot;&gt;</span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;busconfig<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;policy</span> <span style="color: #000066;">user</span>=<span style="color: #ff0000;">&quot;root&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.openvpn&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.openvpn&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;policy</span> <span style="color: #000066;">user</span>=<span style="color: #ff0000;">&quot;at_console&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.vpnc&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;allow</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.vpnc&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;policy</span> <span style="color: #000066;">context</span>=<span style="color: #ff0000;">&quot;default&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;deny</span> <span style="color: #000066;">own</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.openvpn&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
		<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;deny</span> <span style="color: #000066;">send_destination</span>=<span style="color: #ff0000;">&quot;org.freedesktop.NetworkManager.openvpn&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/policy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/busconfig<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Afterwards simply restart the NetworkManager via &#8220;sudo /etc/init.d/NetworkManager restart&#8221; and it&#8217;ll work. For Solutions for other VPN technologies you may also consider <a href="https://bugs.launchpad.net/ubuntu/+source/network-manager-vpnc/+bug/360818" title="Launchpad - NetworkManager vpn plugin bug" title="_blank">Ubuntu&#8217;s Launchpad</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/how-to-fix-networkmanagers-openvpn-plugin-in-ubuntu-904/feed/</wfw:commentRss>
		<slash:comments>5</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>PNP Template for Process Check Plugin</title>
		<link>http://www.matejunkie.com/pnp-template-for-process-check-plugin/</link>
		<comments>http://www.matejunkie.com/pnp-template-for-process-check-plugin/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 12:35:07 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></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[pnp template]]></category>
		<category><![CDATA[rrd]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1103</guid>
		<description><![CDATA[Just a short note: Here&#8217;s the appropriate PNP Template to the process check plugin which I&#8217;ve recently written to create nice and shiny graphs: # 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; [...]]]></description>
			<content:encoded><![CDATA[<p>Just a short note:<br />
Here&#8217;s the appropriate PNP Template to the <a title="Matejunkie - Process Check Plugin for Nagios" href="http://www.matejunkie.com/process-check-plugin-for-nagios/" target="_blank">process check plugin</a> which I&#8217;ve recently written to create nice and shiny graphs:</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_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>

]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/pnp-template-for-process-check-plugin/feed/</wfw:commentRss>
		<slash:comments>0</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>howto: Let nginx serve the Nagios web-interface</title>
		<link>http://www.matejunkie.com/howto-let-nginx-serve-the-nagios-web-interface/</link>
		<comments>http://www.matejunkie.com/howto-let-nginx-serve-the-nagios-web-interface/#comments</comments>
		<pubDate>Thu, 21 May 2009 15:33:45 +0000</pubDate>
		<dc:creator>Mike Adolphs</dc:creator>
				<category><![CDATA[Binary Talks]]></category>
		<category><![CDATA[apache webserver]]></category>
		<category><![CDATA[fcgiwrap]]></category>
		<category><![CDATA[icinga]]></category>
		<category><![CDATA[lighttpd]]></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[spawn_fcgi]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.matejunkie.com/?p=1045</guid>
		<description><![CDATA[For serving the Nagios web-interface it&#8217;s not necessary to run an Apache webserver. It also works quite well with others like lighttpd or nginx. Here&#8217;s how to configure nginx with basic auth so that Nagios knows who you are. Prerequisites Almost any package management system like apt pulls the Apache webserver as a dependency. I [...]]]></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" />For serving the <a title="Nagios - Official Website" href="http://www.nagios.org/" target="_blank">Nagios</a> web-interface it&#8217;s not necessary to run an Apache webserver. It also works quite well with others like <a title="Lighttpd - Official website" href="http://www.lighttpd.net/" target="_blank">lighttpd</a> or <a title="Nginx - Official website" href="http://nginx.net/" target="_blank">nginx</a>. Here&#8217;s how to configure nginx with basic auth so that Nagios knows who you are.</p>
<h3>Prerequisites</h3>
<p>Almost any package management system like apt pulls the Apache webserver as a dependency. I therefore strongly suggest you to compile and install Nagios manually since then you&#8217;ve got way more options to play with. Stick to the official documentation if you consider to do so. The following config files are all based on Nagios&#8217; default configure options.</p>
<h3>Get CGI going</h3>
<p>nginx isn&#8217;t capable to serve dynamic content by default. You have to send this through a wrapper like we did in the last <a title="Matejunkie - Howto nginx with php and passenger at once" href="http://www.matejunkie.com/howto-nginx-with-php-and-passenger-mod_rails-at-once/" target="_blank">howto to get PHP and Passenger going</a>. Therefore download a copy of the lighttpd source, unpack, configure and make it. Then copy the spawn-fcgi from the src directory to a local directory, e.g. /usr/bin:</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;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.lighttpd.net<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>lighttpd-1.4.18.tar.bz2
user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">tar</span> xvjf lighttpd-1.4.18.tar.bz2
user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #7a0874; font-weight: bold;">cd</span> lighttpd-1.4.18<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>lighttpd-1.4.18 $ .<span style="color: #000000; font-weight: bold;">/</span>configure
user<span style="color: #000000; font-weight: bold;">@</span>host ~<span style="color: #000000; font-weight: bold;">/</span>lighttpd-1.4.18 $ <span style="color: #c20cb9; font-weight: bold;">make</span>
user<span style="color: #000000; font-weight: bold;">@</span>host ~<span style="color: #000000; font-weight: bold;">/</span>lighttpd-1.4.18 $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> src<span style="color: #000000; font-weight: bold;">/</span>spawn-fcgi <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>spawn-fcgi</pre></div></div>

<p>Then download the actual fcgiwrapper from github, unpack and make it. Afterwards copy the binary to a local directory, e.g. /usr/bin, 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;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>gnosek<span style="color: #000000; font-weight: bold;">/</span>fcgiwrap<span style="color: #000000; font-weight: bold;">/</span>tarball<span style="color: #000000; font-weight: bold;">/</span>master
user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">tar</span> xzf gnosek-fcgiwrap-cdd6b8475744989940f9ce8322999e9ed4f0a6ec.tar.gz
user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #7a0874; font-weight: bold;">cd</span> gnosek-fcgiwrap-cdd6b8475744989940f9ce8322999e9ed4f0a6ec<span style="color: #000000; font-weight: bold;">/</span>
user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">make</span>
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;">mv</span> fcgiwrap <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>
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;">chown</span> root:root <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>fcgiwrap</pre></div></div>

<p>Create a wrapper script to let the spawn-fcgi binary run a fcgiwrap instance and make it executable.</p>
<h4>/usr/bin/c-fcgi.sh</h4>

<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: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>spawn-fcgi <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>fcgiwrap <span style="color: #660033;">-a</span> 127.0.0.1 <span style="color: #660033;">-p</span> <span style="color: #000000;">49233</span> <span style="color: #660033;">-P</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>fastcgi-c.pid <span style="color: #660033;">-u</span> www-data <span style="color: #660033;">-g</span> www-data</pre></div></div>


<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> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>c-fcgi.sh</pre></div></div>

<p>You may also create an init script to let the spawner run the fcgiwrap instance during boot.</p>
<h4>/etc/init.d/c-fcgi</h4>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #007800;">C_SCRIPT</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>c-fcgi
<span style="color: #007800;">RETVAL</span>=<span style="color: #000000;">0</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>
	start<span style="color: #7a0874; font-weight: bold;">&#41;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting fastcgi&quot;</span>
		<span style="color: #007800;">$C_SCRIPT</span>
		<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
	stop<span style="color: #7a0874; font-weight: bold;">&#41;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Stopping fastcgi&quot;</span>
		<span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-9</span> fcgiwrap
		<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</span>
  <span style="color: #000000; font-weight: bold;">;;</span>
	restart<span style="color: #7a0874; font-weight: bold;">&#41;</span>
		<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Restarting fastcgi&quot;</span>
		<span style="color: #c20cb9; font-weight: bold;">killall</span> <span style="color: #660033;">-9</span> fcgiwrap
		<span style="color: #007800;">$C_SCRIPT</span>
		<span style="color: #007800;">RETVAL</span>=<span style="color: #007800;">$?</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;Usage: c-fastcgi {start|stop|restart}&quot;</span>
		<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</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;">exit</span> <span style="color: #007800;">$RETVAL</span></pre></div></div>

<p>Then start the spawner and put it in the default runlevel:</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> update-rc.d c-fcgi defaults
user<span style="color: #000000; font-weight: bold;">@</span>host ~ $ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>c-fcgi start</pre></div></div>

<h3>Configuring nginx</h3>
<p>Assuming Nagios&#8217; static html files reside in /usr/local/nagios/share and its cgi&#8217;s in /usr/local/nagios/sbin the configuration for an nginx vhost looks like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">server <span style="color: #7a0874; font-weight: bold;">&#123;</span>
	listen   <span style="color: #000000;">80</span>;
	server_name  www.example.com;
&nbsp;
	access_log  <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www<span style="color: #000000; font-weight: bold;">/</span>example.com<span style="color: #000000; font-weight: bold;">/</span>logs<span style="color: #000000; font-weight: bold;">/</span>access.log;
&nbsp;
	location <span style="color: #000000; font-weight: bold;">/</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		root   <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>nagios<span style="color: #000000; font-weight: bold;">/</span>share;
		index  index.html;
&nbsp;
		rewrite	^<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>\.png <span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span>$1.png <span style="color: #7a0874; font-weight: bold;">break</span>;
&nbsp;
		auth_basic		<span style="color: #ff0000;">&quot;Restricted&quot;</span>;
		auth_basic_user_file	conf<span style="color: #000000; font-weight: bold;">/</span>htpasswd;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
	location ~ \.cgi$ <span style="color: #7a0874; font-weight: bold;">&#123;</span>
		root	<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>nagios<span style="color: #000000; font-weight: bold;">/</span>sbin;
		rewrite	^<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>cgi-bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>.<span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>\.cgi <span style="color: #000000; font-weight: bold;">/</span>$1.cgi <span style="color: #7a0874; font-weight: bold;">break</span>;
&nbsp;
		include <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>nginx<span style="color: #000000; font-weight: bold;">/</span>fastcgi_params;
&nbsp;
        	fastcgi_pass   127.0.0.1:<span style="color: #000000;">49233</span>;
	        fastcgi_param  SCRIPT_FILENAME  <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>nagios<span style="color: #007800;">$fastcgi_script_name</span>;  <span style="color: #666666; font-style: italic;"># same path as above</span>
&nbsp;
		auth_basic		<span style="color: #ff0000;">&quot;Restricted&quot;</span>;
		auth_basic_user_file	conf<span style="color: #000000; font-weight: bold;">/</span>htpasswd;
&nbsp;
		fastcgi_param  AUTH_USER          <span style="color: #007800;">$remote_user</span>;
		fastcgi_param  REMOTE_USER	  <span style="color: #007800;">$remote_user</span>;
	<span style="color: #7a0874; font-weight: bold;">&#125;</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Be sure to have the following fastcgi parameters configured in /etc/nginx/fastcgi_params.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">fastcgi_param  QUERY_STRING       <span style="color: #007800;">$query_string</span>;
fastcgi_param  REQUEST_METHOD     <span style="color: #007800;">$request_method</span>;
fastcgi_param  CONTENT_TYPE       <span style="color: #007800;">$content_type</span>;
fastcgi_param  CONTENT_LENGTH     <span style="color: #007800;">$content_length</span>;
&nbsp;
fastcgi_param  SCRIPT_NAME        <span style="color: #007800;">$fastcgi_script_name</span>;
fastcgi_param  REQUEST_URI        <span style="color: #007800;">$request_uri</span>;
fastcgi_param  DOCUMENT_URI       <span style="color: #007800;">$document_uri</span>;
fastcgi_param  DOCUMENT_ROOT      <span style="color: #007800;">$document_root</span>;
fastcgi_param  SERVER_PROTOCOL    <span style="color: #007800;">$server_protocol</span>;
&nbsp;
fastcgi_param  GATEWAY_INTERFACE  CGI<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">1.1</span>;
fastcgi_param  SERVER_SOFTWARE    nginx<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$nginx_version</span>;
&nbsp;
fastcgi_param  REMOTE_ADDR        <span style="color: #007800;">$remote_addr</span>;
fastcgi_param  REMOTE_PORT        <span style="color: #007800;">$remote_port</span>;
fastcgi_param  SERVER_ADDR        <span style="color: #007800;">$server_addr</span>;
fastcgi_param  SERVER_PORT        <span style="color: #007800;">$server_port</span>;
fastcgi_param  SERVER_NAME        <span style="color: #007800;">$server_name</span>;
&nbsp;
<span style="color: #666666; font-style: italic;"># PHP only, required if PHP was built with --enable-force-cgi-redirect</span>
<span style="color: #666666; font-style: italic;">#fastcgi_param  REDIRECT_STATUS    200;</span></pre></div></div>

<h3>Configuring Nagios</h3>
<p>In /usr/local/nagios/etc/cgi.cfg you should turn use_authentication on:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">use_authentication</span>=<span style="color: #000000;">1</span></pre></div></div>

<h3>Almost finished</h3>
<p>After starting Nagios via its init script and a reload of your nginx webserver. it should show you an authentification dialogue window when you point your browser to the server&#8217;s url. To get authentication going, you need to provide credentials in /etc/nginx/conf/htpasswd in the following format:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">user:password</pre></div></div>

<p><a href="http://www.matejunkie.com/wp-content/uploads/2009/05/icinga_service-detail.png"><img class="alignright size-thumbnail wp-image-1059" title="Icinga - Service detail" src="http://www.matejunkie.com/wp-content/uploads/2009/05/icinga_service-detail-150x150.png" alt="Icinga - Service detail" width="150" height="150" /></a>Note that the password must be encrypted, plain text in this file wouldn&#8217;t work (for good reasons). You may want to have an Apache webserver around to use the htpasswd binary for that or you could use a solution from the web like <a title="htaccesstools.com - htpasswd Generator" href="http://www.htaccesstools.com/htpasswd-generator/" target="_blank">the htpasswd generator</a>, but keep in mind that using a service in the web may cause security troubles.</p>
<p>That should do the job. You&#8217;re now able to access your Nagios web-interface via nginx with proper authentication.</p>
<p>This guide also works for <a title="Icinga - Official website" href="http://www.icinga.org/" target="_blank">Icinga</a>, a nice and shiny Nagios fork which came up two weeks ago. Simply change all names from nagios to icinga and you&#8217;re good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.matejunkie.com/howto-let-nginx-serve-the-nagios-web-interface/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
