<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://kb.rvmgroup.it/index.php?action=history&amp;feed=atom&amp;title=Template_di_un_plugin_Nagios_in_Bash</id>
	<title>Template di un plugin Nagios in Bash - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://kb.rvmgroup.it/index.php?action=history&amp;feed=atom&amp;title=Template_di_un_plugin_Nagios_in_Bash"/>
	<link rel="alternate" type="text/html" href="https://kb.rvmgroup.it/index.php?title=Template_di_un_plugin_Nagios_in_Bash&amp;action=history"/>
	<updated>2026-05-06T17:26:18Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://kb.rvmgroup.it/index.php?title=Template_di_un_plugin_Nagios_in_Bash&amp;diff=9400&amp;oldid=prev</id>
		<title>Gabriele.vivinetto: Created page with &quot;Questo template supporta getopt:  &lt;pre&gt; #!/bin/bash  #   This program is free software; you can redistribute it and/or modify #   it under the terms of the GNU General Public ...&quot;</title>
		<link rel="alternate" type="text/html" href="https://kb.rvmgroup.it/index.php?title=Template_di_un_plugin_Nagios_in_Bash&amp;diff=9400&amp;oldid=prev"/>
		<updated>2015-10-08T11:41:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;Questo template supporta getopt:  &amp;lt;pre&amp;gt; #!/bin/bash  #   This program is free software; you can redistribute it and/or modify #   it under the terms of the GNU General Public ...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Questo template supporta getopt:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
&lt;br /&gt;
#   This program is free software; you can redistribute it and/or modify&lt;br /&gt;
#   it under the terms of the GNU General Public License as published by&lt;br /&gt;
#   the Free Software Foundation; version 2 of the License only.&lt;br /&gt;
#&lt;br /&gt;
#   This program is distributed in the hope that it will be useful,&lt;br /&gt;
#   but WITHOUT ANY WARRANTY; without even the implied warranty of&lt;br /&gt;
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the&lt;br /&gt;
#   GNU General Public License for more details.&lt;br /&gt;
#&lt;br /&gt;
#   You should have received a copy of the GNU General Public License&lt;br /&gt;
#   along with this program; if not, write to the Free Software&lt;br /&gt;
#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA&lt;br /&gt;
&lt;br /&gt;
PROGNAME=`basename $0`&lt;br /&gt;
VERSION=&amp;quot;Version 1.0&amp;quot;&lt;br /&gt;
AUTHOR=&amp;quot;2011, Tyler Allen (http://www.the-tech-tutorial.com/)&amp;quot;&lt;br /&gt;
&lt;br /&gt;
LV_W=100;&lt;br /&gt;
LV_C=100;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#Print Version&lt;br /&gt;
print_version() {&lt;br /&gt;
    echo &amp;quot;$VERSION $AUTHOR&amp;quot;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#Print Help&lt;br /&gt;
usage(){&lt;br /&gt;
        echo $PROGNAME $VERSION&lt;br /&gt;
        echo $AUTHOR&lt;br /&gt;
	echo &lt;br /&gt;
	echo This is a Nagios plugin that will check the curremt memory usage of the system.&lt;br /&gt;
	echo &lt;br /&gt;
	echo OPTIONS:&lt;br /&gt;
	echo  -h Shows this help&lt;br /&gt;
	echo  -v Shows the Version&lt;br /&gt;
	echo  -w sets the warning level&lt;br /&gt;
	echo  -c sets the critical level&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#Parmature Getter&lt;br /&gt;
while getopts &amp;quot;hvw:c:&amp;quot; opt; do&lt;br /&gt;
  case $opt in&lt;br /&gt;
    h)&lt;br /&gt;
      usage&lt;br /&gt;
      exit&lt;br /&gt;
      ;;&lt;br /&gt;
    v)&lt;br /&gt;
      print_version&lt;br /&gt;
      exit&lt;br /&gt;
      ;;&lt;br /&gt;
    w)&lt;br /&gt;
      LV_W=$OPTARG&lt;br /&gt;
      ;;&lt;br /&gt;
    c)&lt;br /&gt;
      LV_C=$OPTARG &lt;br /&gt;
      ;;&lt;br /&gt;
&lt;br /&gt;
    \?)&lt;br /&gt;
      echo &amp;quot;Invalid option: -$OPTARG&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
      exit 1&lt;br /&gt;
      ;;&lt;br /&gt;
    :)&lt;br /&gt;
      echo &amp;quot;Option -$OPTARG requires an argument.&amp;quot; &amp;gt;&amp;amp;2&lt;br /&gt;
      exit 1&lt;br /&gt;
      ;;&lt;br /&gt;
  esac&lt;br /&gt;
done&lt;br /&gt;
&lt;br /&gt;
#Check the diffrence between the LV values&lt;br /&gt;
    if [ ${LV_W} -gt ${LV_C} ]&lt;br /&gt;
    then&lt;br /&gt;
        echo &amp;quot;Please adjust levels. The critical level must be higher than the warning level!&amp;quot;&lt;br /&gt;
	exit 666&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
#Values must be between 0 and 100&lt;br /&gt;
    if [ &amp;quot;$LV_W&amp;quot; -lt 0 -o &amp;quot;$LV_W&amp;quot; -gt 100 -o &amp;quot;$LV_C&amp;quot; -lt 0 -o &amp;quot;$LV_C&amp;quot; -gt 100 ]&lt;br /&gt;
    then&lt;br /&gt;
	echo &amp;quot;Warning and critical level values must be between 0 and 100.&amp;quot;&lt;br /&gt;
    	exit 666&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
#Get the figures&lt;br /&gt;
MEM_TOTAL=`grep &amp;quot;^MemTotal&amp;quot; /proc/meminfo|awk &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
TMP_MEM_FREE=`grep &amp;quot;^MemFree&amp;quot; /proc/meminfo|awk &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
TMP_MEM_USED=`expr $MEM_TOTAL - $TMP_MEM_FREE`&lt;br /&gt;
BUFFERS=`grep &amp;quot;^Buffers&amp;quot; /proc/meminfo|awk &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
CACHED=`grep &amp;quot;^Cached&amp;quot; /proc/meminfo|awk &amp;#039;{print $2}&amp;#039;`&lt;br /&gt;
&lt;br /&gt;
P_MEM_FREE=`echo &amp;quot;scale=2; $TMP_MEM_FREE / $MEM_TOTAL * 100&amp;quot; | bc -l | sed &amp;#039;s/.[0-9][0-9]//&amp;#039;`&lt;br /&gt;
P_MEM_USED=`echo &amp;quot;scale=0; 100 - $P_MEM_FREE&amp;quot; | bc -l`&lt;br /&gt;
&lt;br /&gt;
if [ ! -z &amp;quot;$LV_W&amp;quot; -a ! -z &amp;quot;$LV_C&amp;quot; ]&lt;br /&gt;
    then&lt;br /&gt;
        if [ ${P_MEM_USED} -ge ${LV_W} -a ${P_MEM_USED} -lt ${LV_C} ]&lt;br /&gt;
        then&lt;br /&gt;
            echo &amp;quot;WARNING - Used: $P_MEM_USED%, Free: $P_MEM_FREE% | &amp;#039;mem_used&amp;#039;=$P_MEM_USED;$LV_W;$LV_C &amp;#039;mem_free&amp;#039;=$P_MEM_FREE&amp;quot;&lt;br /&gt;
            exit $ST_WR&lt;br /&gt;
        elif [ ${P_MEM_USED} -ge ${LV_C} ]&lt;br /&gt;
        then&lt;br /&gt;
            echo &amp;quot;CRITICAL - Used: $P_MEM_USED%, Free: $P_MEM_FREE% | &amp;#039;mem_used&amp;#039;=$P_MEM_USED;$LV_W;$LV_C &amp;#039;mem_free&amp;#039;=$P_MEM_FREE&amp;quot;&lt;br /&gt;
            exit $ST_CR&lt;br /&gt;
        else&lt;br /&gt;
            echo &amp;quot;OK - Used: $P_MEM_USED%, Free: $P_MEM_FREE% | &amp;#039;mem_used&amp;#039;=$P_MEM_USED;$LV_W;$LV_C &amp;#039;mem_free&amp;#039;=$P_MEM_FREE&amp;quot;&lt;br /&gt;
            exit $ST_OK&lt;br /&gt;
        fi&lt;br /&gt;
    else&lt;br /&gt;
            echo &amp;quot;OK - Used: $P_MEM_USED%, Free: $P_MEM_FREE% | &amp;#039;mem_used&amp;#039;=$P_MEM_USED &amp;#039;mem_free&amp;#039;=$P_MEM_FREE&amp;quot;&lt;br /&gt;
            exit $ST_OK&lt;br /&gt;
    fi&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Gabriele.vivinetto</name></author>
	</entry>
</feed>