"Fossies" - the Fresh Open Source Software Archive

Member "mosshe/functions.localchecks" (26 Sep 2020, 55395 Bytes) of package /linux/privat/old/mosshe.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    4 #
    5 #   function library - please call with external script
    6 #
    7 #!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    8 
    9 #############################################################################
   10 # MoSSHe: remote server monitoring environment
   11 #
   12 # Copyright (C) 2003- Volker Tanger
   13 #
   14 # This program is free software; you can redistribute it and/or
   15 # modify it under the terms of the GNU General Public License
   16 # as published by the Free Software Foundation; either version 2
   17 # of the License, or (at your option) any later version.
   18 #
   19 # For bug reports and suggestions or if you just want to talk to me please
   20 # contact me at volker.tanger@wyae.de
   21 #
   22 # Updates will be available at  http://www.wyae.de/software/mosshe/
   23 # please check there for updates prior to submitting patches!
   24 #
   25 # For list of changes please refer to the HISTORY file. Thanks.
   26 #############################################################################
   27 
   28 
   29 
   30 #############################################################################
   31 ### System: uptime and updates
   32 #############################################################################
   33 
   34 #---------------------------------------------------------
   35 # ServerInfo - just prints process output to info file
   36 #---------------------------------------------------------
   37 ServerInfo () {
   38     echo 'deprecated ServerInfo - please remove from your local MOSSHE'
   39 }
   40 
   41 
   42 #---------------------------------------------------------
   43 # Days Up Check - warn;alert - days
   44 #---------------------------------------------------------
   45 DaysUpCheck () {
   46     MossheLog "DaysUpCheck"
   47     DAYSUP=$(($(cut -d '.' -f 1 /proc/uptime)/60/60/24))
   48     if [ "$DAYSUP" -le $2 ]; then
   49         STATUS="ALERT"
   50     elif [ "$DAYSUP" -le $1 ]; then
   51         STATUS="WARN"
   52     else
   53         STATUS="OK"
   54     fi
   55     echo "${DATIM};$MYGROUP;$MYNAME;Days Up;$STATUS;$DAYSUP;Uptime (in days): $DAYSUP" >> $TEMPDIR/tmp.$$.collected.tmp
   56 }
   57 
   58 #---------------------------------------------------------
   59 # DebianUpdatesAvailable - if true alert; if false ok
   60 #---------------------------------------------------------
   61 DebianUpdatesAvailable () {
   62     MossheLog "DebianUpdatesAvailable"
   63     if [ -x /etc/cron.hourly/mosshe_hourly ]; then
   64         if [ -s /tmp/mosshe.DebianUpdatesAvailable ]; then
   65         echo "${DATIM};$MYGROUP;$MYNAME;DebianUpdates;WARN;2;Debian updates are available" >> $TEMPDIR/tmp.$$.collected.tmp
   66     else
   67         echo "${DATIM};$MYGROUP;$MYNAME;DebianUpdates;OK;0;Your Debian is up to date" >> $TEMPDIR/tmp.$$.collected.tmp
   68     fi
   69     else    
   70     echo "${DATIM};$MYGROUP;$MYNAME;DebianUpdates;UNDEF;1;Debian updates need hourly check - which is missing" >> $TEMPDIR/tmp.$$.collected.tmp
   71     fi
   72 }
   73 
   74 #---------------------------------------------------------
   75 # FedoraYumUpdatesAvailable - if true alert; if false ok
   76 #---------------------------------------------------------
   77 FedoraYumUpdatesAvailable () {
   78     MossheLog "FedoraYumUpdatesAvailable"
   79     if [ -x /etc/cron.hourly/mosshe_hourly ]; then
   80         if [ -s /tmp/mosshe.FedoraYumUpdatesAvailable ]; then
   81             echo "${DATIM};$MYGROUP;$MYNAME;FedoraYumUpdates;WARN;2;Fedora updates are available" >> $TEMPDIR/tmp.$$.collected.tmp
   82         else
   83             echo "${DATIM};$MYGROUP;$MYNAME;FedoraYumUpdates;OK;0;Your Fedora is up to date" >> $TEMPDIR/tmp.$$.collected.tmp
   84         fi
   85     else
   86         echo "${DATIM};$MYGROUP;$MYNAME;FedoraYumUpdates;UNDEF;1;Fedora updates need hourly check - which is missing" >> $TEMPDIR/tmp.$$.collected.tmp
   87     fi
   88 }
   89 
   90 
   91 
   92 #---------------------------------------------------------
   93 # FedoraDnfUpdatesAvailable - if true alert; if false ok
   94 #---------------------------------------------------------
   95 FedoraDnfUpdatesAvailable () {
   96     MossheLog "FedoraDnfUpdatesAvailable"
   97     if [ -x /etc/cron.hourly/mosshe_hourly ]; then
   98         if [ -s /tmp/mosshe.FedoraDnfUpdatesAvailable ]; then
   99             echo "${DATIM};$MYGROUP;$MYNAME;FedoraDnfUpdates;WARN;2;Fedora updates are available" >> $TEMPDIR/tmp.$$.collected.tmp
  100         else
  101             echo "${DATIM};$MYGROUP;$MYNAME;FedoraDnfUpdates;OK;0;Your Fedora is up to date" >> $TEMPDIR/tmp.$$.collected.tmp
  102         fi
  103     else
  104         echo "${DATIM};$MYGROUP;$MYNAME;FedoraDnfUpdates;UNDEF;1;Fedora updates need hourly check - which is missing" >> $TEMPDIR/tmp.$$.collected.tmp
  105     fi
  106 }
  107 
  108 
  109 
  110 #---------------------------------------------------------
  111 # ArchlinuxUpdatesAvailable - if true alert; if false ok
  112 #---------------------------------------------------------
  113 ArchlinuxUpdatesAvailable () {
  114     MossheLog "ArchlinuxUpdatesAvailable"
  115     if [ -x /etc/cron.hourly/mosshe_hourly ]; then
  116         if [ -s /tmp/mosshe.ArchlinuxUpdatesAvailable ]; then
  117             echo "${DATIM};$MYGROUP;$MYNAME;ArchlinuxUpdates;WARN;2;Archlinux updates are available" >> $TEMPDIR/tmp.$$.collected.tmp
  118         else
  119             echo "${DATIM};$MYGROUP;$MYNAME;ArchlinuxUpdates;OK;0;Your Archlinux is up to date" >> $TEMPDIR/tmp.$$.collected.tmp
  120         fi
  121     else
  122         echo "${DATIM};$MYGROUP;$MYNAME;ArchlinuxUpdates;UNDEF;1;Archlinux updates need hourly check - which is missing" >> $TEMPDIR/tmp.$$.collected.tmp
  123     fi
  124 }
  125 
  126 
  127 
  128 #---------------------------------------------------------
  129 # Ubuntu Updates Available - if true alert; if false ok
  130 #---------------------------------------------------------
  131 UbuntuUpdatesAvailable () {
  132     MossheLog "UbuntuUpdatesAvailable"
  133     # Ubuntu
  134     if [ -x /usr/lib/update-notifier/update-motd-updates-available ]; then
  135         RR=`/usr/lib/update-notifier/update-motd-updates-available | sed 's/\*/#/g'`
  136         [ -z "$RR" ] && STATUS1=OK || STATUS1=ALERT
  137         [ -z "$RR" ] && STATUS2=0 || STATUS2=1
  138         RR=${RR:-No updates available}
  139         echo "${DATIM};$MYGROUP;$MYNAME;Updates Available?;$STATUS1;$STATUS2;$RR" >> $TEMPDIR/tmp.$$.collected.tmp
  140     fi
  141 }
  142 
  143 #---------------------------------------------------------
  144 # Ubuntu Release Upgrade Check - if true alert; if false ok
  145 #---------------------------------------------------------
  146 UbuntuReleaseUpgrade () {
  147     MossheLog "UbuntuReleaseUpgrade"
  148     # Ubuntu
  149     if [ -x /usr/lib/update-manager/release-upgrade-motd ]; then
  150         RR=`/usr/lib/update-manager/release-upgrade-motd | sed 's/\*/#/g'`
  151         [ -z "$RR" ] && STATUS1=OK || STATUS1=ALERT
  152         [ -z "$RR" ] && STATUS2=0 || STATUS2=1
  153         RR=${RR:-No upgrades available}
  154         echo "${DATIM};$MYGROUP;$MYNAME;Upgrades available?;$STATUS1;$STATUS2;$RR" >> $TEMPDIR/tmp.$$.collected.tmp
  155     fi
  156 }
  157 
  158 #---------------------------------------------------------
  159 # Ubuntu Reboot Required Check - if true alert; if false ok
  160 #---------------------------------------------------------
  161 UbuntuRebootRequired () {
  162     MossheLog "UbuntuRebootRequired"
  163     # Ubuntu
  164     if [ -x /usr/lib/update-notifier/update-motd-reboot-required ]; then
  165         RR=`/usr/lib/update-notifier/update-motd-reboot-required | sed 's/\*/#/g'`
  166         [ -z "$RR" ] && STATUS1=OK || STATUS1=ALERT
  167         [ -z "$RR" ] && STATUS2=0 || STATUS2=1
  168         RR=${RR:-No reboot required}
  169         echo "${DATIM};$MYGROUP;$MYNAME;Reboot Required?;$STATUS1;$STATUS2;$RR" >> $TEMPDIR/tmp.$$.collected.tmp
  170     fi
  171 }
  172 
  173 ################################################################
  174 ###  File system and files
  175 ################################################################
  176 
  177 
  178 #---------------------------------------------------------
  179 # HDCheck - device;warn;alert - MB free
  180 #---------------------------------------------------------
  181 HDCheck () {
  182     MossheLog "HDCheck $1"
  183     HD=$1
  184     typeset -i WARN ALERT; WARN=$2; ALERT=$3
  185     typeset -i VALUE 
  186     STATUS="OK"
  187     
  188     # Device MBtotal MBused MBfree Percent Mount
  189     # /dev/sda1 98428 8823 84606 10% /
  190     DF=`df -Plm | fgrep "$HD" | sed -e "s/  */ /g"`
  191     if [ "$DF" ]; then
  192         VALUE=`echo $DF | cut -d " " -f 4`
  193         MOUNT=`echo $DF | cut -d " " -f 6`
  194         MESSAGE="Disk free : $VALUE MB"
  195         if [ $VALUE -lt $WARN ]; then STATUS="WARN"; MESSAGE="Disk tight : $VALUE MB"; fi
  196         if [ $VALUE -lt $ALERT ]; then STATUS="ALERT"; MESSAGE="Disk critically full : $VALUE MB"; fi
  197     else
  198         STATUS=DOWN
  199         VALUE=0
  200         MOUNT=$HD
  201         MESSAGE="HDD not mounted??"
  202     fi
  203     echo "${DATIM};$MYGROUP;$MYNAME;HDD$HD;$STATUS;$VALUE;$MOUNT $MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  204 }
  205 
  206 
  207 #---------------------------------------------------------
  208 # HDCheckGB - device;warn;alert - GB free
  209 #---------------------------------------------------------
  210 HDCheckGB () {
  211     MossheLog "HDCheckGB $1"
  212     HD=$1
  213     typeset -i WARN ALERT; WARN=$2; ALERT=$3
  214     typeset -i VALUE GBVALUE
  215     STATUS="OK"
  216     
  217     # Device MBtotal MBused MBfree Percent Mount
  218     # /dev/sda1 98428 8823 84606 10% /
  219     DF=`df -Plm | fgrep "$HD" | sed -e "s/  */ /g"`
  220     if [ "$DF" ]; then
  221         VALUE=`echo $DF | cut -d " " -f 4`
  222     GBVALUE=$(( VALUE / 1024 ))
  223         MOUNT=`echo $DF | cut -d " " -f 6`
  224         MESSAGE="Disk free : $GBVALUE GB"
  225         if [ $GBVALUE -lt $WARN ]; then STATUS="WARN"; MESSAGE="Disk tight : $VALUE GB"; fi
  226         if [ $GBVALUE -lt $ALERT ]; then STATUS="ALERT"; MESSAGE="Disk critically full : $VALUE GB"; fi
  227     else
  228         STATUS=DOWN
  229         VALUE=0
  230         MOUNT=$HD
  231         MESSAGE="HDD not mounted??"
  232     fi
  233     echo "${DATIM};$MYGROUP;$MYNAME;HDD-GB$HD;$STATUS;$GBVALUE;$MOUNT $MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  234 }
  235 
  236 
  237 #---------------------------------------------------------
  238 # HDfreeGB - device;warn;alert - GB free
  239 #---------------------------------------------------------
  240 HDfreeGB () {
  241     MossheLog "HDfreeGB $1"
  242     HD=$1
  243     typeset -i WARN ALERT; WARN=$2; ALERT=$3
  244     typeset -i VALUE GBVALUE
  245     STATUS="OK"
  246     
  247     # Device MBtotal MBused MBfree Percent Mount
  248     # /dev/sda1 98428 8823 84606 10% /
  249     DF=`df -Plm $HD | fgrep "/" | sed -e "s/  */ /g"`
  250     if [ "$DF" ]; then
  251         VALUE=`echo $DF | cut -d " " -f 4`
  252     GBVALUE=$(( VALUE / 1024 ))
  253         MOUNT=`echo $DF | cut -d " " -f 6`
  254         MESSAGE="Disk free : $GBVALUE GB"
  255         if [ $GBVALUE -lt $WARN ]; then STATUS="WARN"; MESSAGE="Disk tight : $VALUE GB"; fi
  256         if [ $GBVALUE -lt $ALERT ]; then STATUS="ALERT"; MESSAGE="Disk critically full : $VALUE GB"; fi
  257     else
  258         STATUS=DOWN
  259         VALUE=0
  260         MOUNT=$HD
  261         MESSAGE="HDD not mounted??"
  262     fi
  263     echo "${DATIM};$MYGROUP;$MYNAME;HDfreeGB$HD;$STATUS;$GBVALUE;$MOUNT $MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  264 }
  265 
  266 
  267 #---------------------------------------------------------
  268 # HDfreeMB - device;warn;alert - MB free
  269 #---------------------------------------------------------
  270 HDfreeMB () {
  271     MossheLog "HDfreeMB $1"
  272     HD=$1
  273     typeset -i WARN ALERT; WARN=$2; ALERT=$3
  274     typeset -i VALUE GBVALUE
  275     STATUS="OK"
  276     
  277     DF=`df -Plm $HD | fgrep '/' | sed -e "s/  */ /g"`
  278     if [ "$DF" ]; then
  279         MOUNT=`echo $DF | cut -d " " -f 6`
  280         VALUE=`echo $DF | cut -d " " -f 4`
  281         MESSAGE="Disk free : $VALUE MB"
  282         if [ $VALUE -lt $WARN ]; then STATUS="WARN"; MESSAGE="Disk tight : $VALUE MB"; fi
  283         if [ $VALUE -lt $ALERT ]; then STATUS="ALERT"; MESSAGE="Disk critically full : $VALUE MB"; fi
  284     else
  285     STATUS=DOWN
  286     VALUE=0
  287     MESSAGE="HDD not mounted??"
  288     fi
  289     echo "${DATIM};$MYGROUP;$MYNAME;HDfreeMB$HD;$STATUS;$VALUE;$HD $MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  290 }
  291                                             
  292                                             
  293                                             
  294 #---------------------------------------------------------
  295 # HDhardwareSmart  -- device;value_to_check;warn;alert - max. counter
  296 #---------------------------------------------------------
  297 HDhardwareSmart () {
  298     echo "${DATIM};$MYGROUP;$MYNAME;0;UNDEF;0;HDhardwareSmart check is deprecated - use HDhardwareSmartRaw or HDhardwareSmartValue instead." >> $TEMPDIR/tmp.$$.collected.tmp 
  299 }
  300 
  301 
  302 #---------------------------------------------------------
  303 # HDhardwareSmartValue  -- device;value_to_check;warn;alert - max. counter
  304 #---------------------------------------------------------
  305 HDhardwareSmartValue () {
  306   MossheLog "HDhardwareSmartValue $1 $2"
  307   HD=$1
  308   KEY=$2
  309   typeset -i COUNT
  310   if ! [ -x /usr/sbin/smartctl ]; then
  311     STATUS="UNDEF"
  312     COUNT=0
  313     MESSAGE="SMARTCTL not installed - cannot perform HDhardwareSmartValue check."
  314   else
  315     typeset -i WARN ALERT; WARN=$3; ALERT=$4
  316     STATUS="OK"
  317     VALUE=`/usr/sbin/smartctl -A $HD | fgrep "$KEY" | sed -e "s/  */ /g" | sed -e "s/^ *//g" | sed -e "s/ 000 /xXx/g" | sed -e "s/ 0*/ /g" | sed -e "s/xXx/ 0 /g"`
  318     if [ "$VALUE" ]; then
  319         COUNT=`echo $VALUE | cut -d " " -f 4`
  320         MESSAGE="Disk free : $GBVALUE GB"
  321         if [ $COUNT -gt $ALERT ]; then 
  322         STATUS="ALERT"
  323         MESSAGE="$HD failing hardware: $COUNT $KEY"
  324     elif [ $COUNT -gt $WARN ]; then 
  325         STATUS="WARN"
  326         MESSAGE="$HD worn-out hardware status: $COUNT $KEY"
  327     else
  328         STATUS="OK"
  329         MESSAGE="$HD hardware is okay: $COUNT $KEY"
  330     fi
  331     else
  332         STATUS="UNDEF"
  333         COUNT=0
  334         MESSAGE="HDD not installed or key $KEY invalid??"
  335     fi
  336   fi    
  337   echo "${DATIM};$MYGROUP;$MYNAME;HDhardwareSmartValue_${HD}_$KEY;$STATUS;$COUNT;$HD $MESSAGE ($COUNT)" >> $TEMPDIR/tmp.$$.collected.tmp
  338 }
  339 
  340 
  341 #---------------------------------------------------------
  342 # HDhardwareSmartRaw  -- device;value_to_check;warn;alert - max. counter
  343 #---------------------------------------------------------
  344 HDhardwareSmartRaw () {
  345   MossheLog "HDhardwareSmartRaw $1 $2"
  346   HD=$1
  347   KEY=$2
  348   typeset -i COUNT
  349   if ! [ -x /usr/sbin/smartctl ]; then
  350     STATUS="UNDEF"
  351     COUNT=0
  352     MESSAGE="SMARTCTL not installed - cannot perform HDhardwareSmartRaw check."
  353   else
  354     typeset -i WARN ALERT; WARN=$3; ALERT=$4
  355     STATUS="OK"
  356     VALUE=`/usr/sbin/smartctl -A $HD | fgrep "$KEY" | sed -e "s/  */ /g" | sed -e "s/^ *//g"`
  357     if [ "$VALUE" ]; then
  358         COUNT=`echo $VALUE | cut -d " " -f 10`
  359         MESSAGE="Disk free : $GBVALUE GB"
  360         if [ $COUNT -gt $ALERT ]; then 
  361         STATUS="ALERT"
  362         MESSAGE="$HD failing hardware: $COUNT $KEY"
  363     elif [ $COUNT -gt $WARN ]; then 
  364         STATUS="WARN"
  365         MESSAGE="$HD worn-out hardware status: $COUNT $KEY"
  366     else
  367         STATUS="OK"
  368         MESSAGE="$HD hardware is okay: $COUNT $KEY"
  369     fi
  370     else
  371         STATUS="UNDEF"
  372         COUNT=0
  373         MESSAGE="HDD not installed or key $KEY invalid??"
  374     fi
  375   fi    
  376   echo "${DATIM};$MYGROUP;$MYNAME;HDhardwareSmartRaw_${HD}_$KEY;$STATUS;$COUNT;$HD $MESSAGE ($COUNT)" >> $TEMPDIR/tmp.$$.collected.tmp
  377 }
  378 
  379 
  380 #---------------------------------------------------------
  381 # HDparmState - device 
  382 #---------------------------------------------------------
  383 HDparmState () {
  384     MossheLog "HDparmState $1"
  385     HD=$1
  386     if [ -b "$HD" ]; then
  387     # /sbin/hdparm -C /dev/sda 
  388     # /dev/sda:
  389     #  drive state is:  active/idle
  390     STAT=`/sbin/hdparm -C $HD | fgrep 'drive state is:  active/idle'`
  391     if [ -n "$STAT" ]; then
  392             STATUS="OK"
  393         VALUE=100
  394         MESSAGE="$HD is active"
  395     else
  396             STATUS="OK"
  397         VALUE=0
  398         MESSAGE="$HD is in standby"
  399     fi
  400     else
  401         STATUS="UNDEF"
  402         VALUE=-100
  403         MOUNT=$HD
  404         MESSAGE="HDD $HD not a device??"
  405     fi
  406     echo "${DATIM};$MYGROUP;$MYNAME;hdparm$HD;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  407 }
  408 
  409 
  410 #---------------------------------------------------------
  411 # FileCheck: does file exist (e.g. Unix socket)
  412 #---------------------------------------------------------
  413 FileCheck () {
  414     MossheLog "FileCheck $1"
  415      FN="$1"     
  416 
  417      if [ -e $FN ]; then
  418          MESSAGE="Files $FN exists"
  419      STATUS="OK"
  420          CODE=0
  421      else
  422          STATUS="ALERT";
  423          MESSAGE="File $FN does not exist"
  424          CODE=999
  425      fi
  426      echo "${DATIM};$MYGROUP;$MYNAME;file_${FN};$STATUS;$CODE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  427 }
  428 
  429 
  430 #---------------------------------------------------------
  431 # FileTooOld: file last changed more than ... minutes ago?
  432 #---------------------------------------------------------
  433 FileTooOld () {
  434     MossheLog "FileTooOld $1"
  435     FILENAME=$1
  436     MAXAGE=$2
  437 
  438     STATUS="UNDEF"
  439     MESSAGE="Something wrong with FileTooOld check for file $FILENAME"
  440     VALUE=0
  441     
  442     if [ ! -f "$FILENAME" ]; then
  443         STATUS="ALERT"
  444     MESSAGE="Error: file $FILENAME does not exist "
  445     VALUE=3
  446     else
  447         typeset -i FTIME=`ls -l --time-style=+%s $FILENAME | cut -d " " -f 6`
  448         typeset -i LTIME=`date +%s --date="$MAXAGE minutes ago"`
  449         if [ $FTIME -lt $LTIME ]; then 
  450             STATUS="WARN"
  451         MESSAGE="Problem: file $FILENAME older than $MAXAGE minutes "
  452         VALUE=2
  453     else
  454             STATUS="OK"
  455         MESSAGE="file $FILENAME seems to be quite current "
  456         VALUE=1
  457     fi
  458     fi
  459 
  460     echo "${DATIM};$MYGROUP;$MYNAME;filetooold_$FILENAME;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  461 }
  462 
  463 #---------------------------------------------------------
  464 # FileTooBig: filesize bigger than WARN KiloBytes
  465 #---------------------------------------------------------
  466 FileTooBig () {
  467     MossheLog "FileTooBig $1"
  468     FILENAME=$1
  469     typeset -i WARN=$2
  470 
  471     STATUS="UNDEF"
  472     MESSAGE="Something wrong with FileTooBig check for file $FILENAME"
  473     VALUE=0
  474     
  475     if [ ! -f "$FILENAME" ]; then
  476         STATUS="ALERT"
  477     MESSAGE="Error: file $FILENAME does not exist "
  478     else
  479         typeset -i VALUE=`ls -sk1 $FILENAME | cut -d " " -f 1`
  480         if [ $VALUE -gt $WARN ]; then 
  481             STATUS="WARN"
  482         MESSAGE="Problem: file $FILENAME (${VALUE}kB) bigger tham $WARN kB "
  483     else
  484             STATUS="OK"
  485         MESSAGE="file $FILENAME seems to be small enough (${VALUE} KB)"
  486     fi
  487     fi
  488 
  489     echo "${DATIM};$MYGROUP;$MYNAME;filetoobig_$FILENAME;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  490 }
  491 
  492 
  493 #---------------------------------------------------------
  494 # FileLines: lines in file bigger than WARN / ALERT
  495 #---------------------------------------------------------
  496 FileLines () {
  497     MossheLog "FileLines $1 $2"
  498     FILENAME=$1
  499     typeset -i WARN=$2
  500 
  501     STATUS="UNDEF"
  502     MESSAGE="Something wrong with FileLines check for file $FILENAME"
  503     VALUE=0
  504     
  505     if [ ! -f "$FILENAME" ]; then
  506         STATUS="ALERT"
  507     MESSAGE="Error: file $FILENAME does not exist "
  508     else
  509         typeset -i VALUE=`wc -l $FILENAME | cut -d ' ' -f 1`
  510         if [ $VALUE -gt $WARN ]; then 
  511             STATUS="WARN"
  512         MESSAGE="Problem: file $FILENAME (${VALUE} lines) longer tham $WARN kB "
  513     else
  514             STATUS="OK"
  515         MESSAGE="file $FILENAME seems to be short enough (${VALUE} lines)"
  516     fi
  517     fi
  518 
  519     echo "${DATIM};$MYGROUP;$MYNAME;filelines_$FILENAME;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  520 }
  521 
  522 
  523 
  524 ################################################################
  525 ###  CPU and processes
  526 ################################################################
  527 
  528 
  529 #---------------------------------------------------------
  530 # LoadCheck 5min: Warning / Alert
  531 #---------------------------------------------------------
  532 LoadCheck () {
  533     MossheLog "LoadCheck"
  534     typeset -i WARN ALERT; WARN=$1; ALERT=$2
  535     typeset -i LOAD
  536     MESSAGE=`cat /proc/loadavg | cut -d " " -f 3 | sed -e "s/ //g"`
  537     LOAD=`echo $MESSAGE | cut -d "." -f 1`
  538     STATUS="OK"
  539     STAT="Normal Load";
  540     if [ $LOAD -ge $WARN ]; then STATUS="WARN"; STAT="High Load"; fi
  541     if [ $LOAD -ge $ALERT ]; then STATUS="ALERT"; STAT="Critical Load"; fi
  542     echo "${DATIM};$MYGROUP;$MYNAME;load;$STATUS;$LOAD;$STAT: $MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  543 }
  544 
  545 
  546 #---------------------------------------------------------
  547 # LoadCheckPercent 5min: Warning / Alert
  548 #---------------------------------------------------------
  549 LoadCheckPercent () {
  550     MossheLog "LoadCheckPercent"
  551     typeset -i WARN ALERT; WARN=$1; ALERT=$2
  552     typeset -i LOAD
  553     MESSAGE=`cat /proc/loadavg | cut -d " " -f 3 | sed -e "s/ //g"`
  554     LOAD=`echo $MESSAGE | sed -e "s/\.//" | sed -e "s/^0*//g"`
  555     STATUS="OK"
  556     STAT="Normal Load";
  557     if [ $LOAD -ge $WARN ]; then STATUS="WARN"; STAT="High Load"; fi
  558     if [ $LOAD -ge $ALERT ]; then STATUS="ALERT"; STAT="Critical Load"; fi
  559     echo "${DATIM};$MYGROUP;$MYNAME;loadpercent;$STATUS;$LOAD;$STAT: $MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  560 }
  561 
  562 
  563 #---------------------------------------------------------
  564 # LoadPercentHektoCheck 5min: Warning / Alert
  565 #---------------------------------------------------------
  566 LoadHektoCheck () {
  567     echo "${DATIM};$MYGROUP;$MYNAME;loadhekto;UNDEF;0;LoadHektoCheck is wrong prefix - use LoadPercentCheck instead." >> $TEMPDIR/tmp.$$.collected.tmp 
  568 }
  569 
  570 
  571 #---------------------------------------------------------
  572 # Processes: Warning / Alert
  573 #---------------------------------------------------------
  574 ProcessCheck () {
  575     MossheLog "ProcessCheck"
  576     typeset -i WARN ALERT; WARN=$1; ALERT=$2
  577     typeset -i PROCESSES
  578     PROCESSES=`ps -A | wc -l`
  579     STATUS="OK"
  580     MESSAGE="Normal processes count"
  581     if [ $PROCESSES -ge $WARN ]; then STATUS="WARN"; MESSAGE="Many processes running"; fi
  582     if [ $PROCESSES -ge $ALERT ]; then STATUS="ALERT"; MESSAGE="Abnormal processes count"; fi
  583     echo "${DATIM};$MYGROUP;$MYNAME;processes;$STATUS;$PROCESSES;$MESSAGE: $PROCESSES" >> $TEMPDIR/tmp.$$.collected.tmp
  584 }
  585 
  586 
  587 #---------------------------------------------------------
  588 # Zombie Processes: Warning Alert
  589 #---------------------------------------------------------
  590 ZombieCheck () {
  591     MossheLog "ZombieCheck"
  592     typeset -i WARN ALERT; WARN=$1; ALERT=$2
  593     typeset -i PROCESSES
  594     TMPFILE="$TEMPDIR/tmp.$$.$HOSTNAME.PSSTATUS" 
  595     ps -A | fgrep "defunct" > $TMPFILE
  596     
  597     PROCESSES=`cat $TMPFILE | wc -l`    
  598 
  599     if [ $PROCESSES -eq 0 ]; then 
  600     PROCNAMES='ok'
  601     else
  602     PROCNAMES=""
  603     for A in `cat $TMPFILE | cut -d ":" -f 2- |cut -d " " -f 2-`; do
  604             PROCNAMES="$PROCNAMES +++ $A"
  605     done
  606     fi
  607     rm $TMPFILE
  608 
  609     MESSAGE="Zombie processes: $PROCESSES = $PROCNAMES"
  610     STATUS="OK"
  611     if [ $PROCESSES -gt $WARN ]; then STATUS="WARN"; fi
  612     if [ $PROCESSES -ge $ALERT ]; then STATUS="ALERT"; fi
  613 
  614     echo "${DATIM};$MYGROUP;$MYNAME;zombies;$STATUS;$PROCESSES;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  615 }
  616 
  617 
  618 #---------------------------------------------------------
  619 # ProcCheck: does a process with this string run?
  620 #---------------------------------------------------------
  621 ProcCheck () {
  622     MossheLog "ProcCheck"
  623      typeset -i PSNUM=`ps ax | fgrep "$1" | wc -l`     
  624 
  625      if [ $PSNUM -gt 0 ]; then 
  626          MESSAGE="Process $1 running"
  627      STATUS="OK"
  628      else
  629          STATUS="ALERT";
  630          MESSAGE="No process $1 found"
  631      fi
  632      echo "${DATIM};$MYGROUP;$MYNAME;proc_$1;$STATUS;$PSNUM;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  633 }
  634 
  635 
  636 #---------------------------------------------------------
  637 # Users: Warning interact.shell / Critical root+shell/su
  638 #---------------------------------------------------------
  639 ShellCheck () {
  640     MossheLog "ShellCheck"
  641     typeset -i RMAX UMAX; RMAX=$1; UMAX=$2
  642     typeset -i RUSERS RUSERSB RUSERSS
  643     typeset -i USERS
  644     RUSERSS=`ps -eo pid,user,ruser,tty,args | fgrep " -bash" | fgrep root | fgrep -v fgrep | wc -l`
  645     RUSERSB=`ps -eo pid,user,ruser,tty,args | fgrep " -su" | fgrep -v fgrep | wc -l`
  646     RUSERS=${RUSERSB}+${RUSERSS}
  647     USERS=`ps -eo pid,user,ruser,tty,args | fgrep " -bash" | wc -l`
  648 
  649     MESSAGE="No notable interactive shells"
  650     STATUS="OK"
  651     if [ $USERS -gt $UMAX ]; then 
  652     STATUS="WARN";
  653     MESSAGE="$USERS interactive shells running"
  654     fi
  655     if [ $RUSERS -gt $RMAX ]; then 
  656     STATUS="ALERT"; 
  657     MESSAGE="$RUSERS root shells (bash, su) running"
  658     USERS="$RUSERS"
  659     fi
  660     echo "${DATIM};$MYGROUP;$MYNAME;shells;$STATUS;$USERS;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  661 }
  662 
  663 #---------------------------------------------------------
  664 # Memory: min. free (buffer/cache corrected)
  665 #---------------------------------------------------------
  666 MemCheck () {
  667   MossheLog "MemCheck"
  668   if [ -z `which free` ]; then
  669      echo "${DATIM};$MYGROUP;$MYNAME;memory (general);UNDEF;0;FREE not installed - cannot perform MEMORY/RAM check" >> $TEMPDIR/tmp.$$.collected.tmp
  670   else
  671      typeset -i WMAX=$1; 
  672      typeset -i AMAX=$2;
  673      typeset -i TOTAL=`free -m | fgrep "buffers/cache:" | sed -e "s/  */ /g" | cut -d " " -f 4`
  674      
  675      MESSAGE="Memory free ($TOTAL MB)"
  676      STATUS="OK"
  677      if [ $TOTAL -lt $WMAX ]; then 
  678          STATUS="WARN";
  679          MESSAGE="Memory congested ($TOTAL MB free)"
  680      fi
  681      if [ $TOTAL -lt $AMAX ]; then
  682          STATUS="ALERT";
  683          MESSAGE="Memory tight ($TOTAL MB free)"
  684      fi
  685      echo "${DATIM};$MYGROUP;$MYNAME;memory;$STATUS;$TOTAL;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  686   fi
  687 }
  688 
  689 #---------------------------------------------------------
  690 # Memory: min. free (buffer/cache corrected)
  691 #---------------------------------------------------------
  692 MemCheckLinux () {
  693   MossheLog "MemCheck"
  694   if [ -e /proc/meminfo ]; then
  695      typeset -i WMAX=$1;
  696      typeset -i AMAX=$2;
  697      typeset -i TOTAL=`fgrep MemAvailable /proc/meminfo | sed -e "s/  */ /g" | cut -d " " -f 2 | head -c -4`
  698 
  699      MESSAGE="Memory free ($TOTAL MB)"
  700      STATUS="OK"
  701      if [ $TOTAL -lt $WMAX ]; then
  702          STATUS="WARN";
  703          MESSAGE="Memory congested ($TOTAL MB free)"
  704      fi
  705      if [ $TOTAL -lt $AMAX ]; then
  706          STATUS="ALERT";
  707          MESSAGE="Memory tight ($TOTAL MB free)"
  708      fi
  709      echo "${DATIM};$MYGROUP;$MYNAME;memory;$STATUS;$TOTAL;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  710   else
  711      echo "${DATIM};$MYGROUP;$MYNAME;memory Linux (general);UNDEF;0;MemCheckLinux only works under Linux" >> $TEMPDIR/tmp.$$.collected.tmp
  712   fi
  713 }
  714 
  715 
  716 
  717 
  718 #---------------------------------------------------------
  719 # Swap:  page in/out per second
  720 #---------------------------------------------------------
  721 SwapCheck () {
  722   MossheLog "SwapCheck"
  723   if [ -z `which vmstat` ]; then
  724      echo "${DATIM};$MYGROUP;$MYNAME;swapping;UNDEF;0;VMSTAT not installed - cannot perform swap activity check" >> $TEMPDIR/tmp.$$.collected.tmp
  725   else
  726      typeset -i WMAX=$1; 
  727      typeset -i AMAX=$2;
  728      typeset -i SI=`vmstat | tail -1 | sed -e "s/  */ /g" | cut -d " " -f 8`
  729      typeset -i SO=`vmstat | tail -1 | sed -e "s/  */ /g" | cut -d " " -f 9`
  730      typeset -i SWAPS=${SI}+${SO}
  731      
  732      MESSAGE="System memory seldomly swapping ($SWAPS pages/s)"
  733      STATUS="OK"
  734      if [ $TOTAL -lt $WMAX ]; then 
  735          STATUS="WARN";
  736          MESSAGE="System memory swapping ($SWAPS pages/s)"
  737      fi
  738      if [ $TOTAL -lt $AMAX ]; then
  739          STATUS="ALERT";
  740          MESSAGE="System memory heavily swapping ($SWAPS pages/s)"
  741      fi
  742      echo "${DATIM};$MYGROUP;$MYNAME;swapping;$STATUS;$TOTAL;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  743   fi
  744 }
  745 
  746 
  747 ################################################################
  748 ###  Queues
  749 ################################################################
  750 
  751 
  752 #---------------------------------------------------------
  753 # Printers: Queuename / max queue size (999=offline)
  754 #---------------------------------------------------------
  755 PrintCheck () {
  756   MossheLog "PrintCheck"
  757   if [ -z `which lpq` ]; then
  758      echo "${DATIM};$MYGROUP;$MYNAME;printer (general);UNDEF;0;LPQ not installed - cannot perform PRINTER check" >> $TEMPDIR/tmp.$$.collected.tmp
  759   else
  760      LP="$1"
  761      
  762 
  763      typeset -i MAXQUEUE=$2
  764      typeset -i QUEUELEN=`lpq -P $LP | wc -l`
  765      QUEUELEN=${QUEUELEN}-2
  766      
  767      MESSAGE="Printer $LP ok with $QUEUELEN print jobs in queue"
  768      STATUS="OK"
  769      
  770      if [ $QUEUELEN -gt $MAXQUEUE ]; then 
  771          STATUS="WARN";
  772          MESSAGE="More than $MAXQUEUE jobs (${QUEUELEN}) for printer $LP"
  773      fi
  774      
  775      lpq -P $1 | fgrep "is ready" > /dev/null
  776      if [ $? -gt 0 ]; then
  777          STATUS="ALERT";
  778          MESSAGE="Printer $LP is down - $QUEUELEN jobs pending"
  779          QUEUELEN=999
  780      fi
  781      echo "${DATIM};$MYGROUP;$MYNAME;lpt_${LP};$STATUS;$QUEUELEN;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  782   fi
  783 }
  784 
  785 
  786 #---------------------------------------------------------
  787 # Mail-Queue: max queue size (warn alert)
  788 #---------------------------------------------------------
  789 MailqCheck () {
  790   MossheLog "MailqCheck"
  791   if [ -z `which mailq` ]; then
  792      echo "${DATIM};$MYGROUP;$MYNAME;mailq (general);UNDEF;0;MAILQ not installed - cannot perform MailQueue check"  >> $TEMPDIR/tmp.$$.collected.tmp
  793   else
  794      typeset -i WARN="$1"
  795      typeset -i ALERT=$2
  796      typeset -i QUEUELEN=`mailq | wc -l`
  797      QUEUELEN=${QUEUELEN}/4
  798      
  799      MESSAGE="Mail Queue length: ok with $QUEUELEN mails in queue"
  800      STATUS="OK"
  801      
  802      if [ $QUEUELEN -gt $WARN ]; then 
  803         STATUS="WARN";
  804     MESSAGE="Notable Mail Queue size: $QUEUELEN mails in queue"
  805     if [ $QUEUELEN -gt $ALERT ]; then   
  806             STATUS="ALERT";
  807         MESSAGE="Excessive Mail Queue size: $QUEUELEN mails in queue"
  808     fi
  809      fi
  810      
  811      echo "${DATIM};$MYGROUP;$MYNAME;mailq;$STATUS;$QUEUELEN;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  812   fi
  813 }
  814 
  815 
  816 ################################################################
  817 ###  Hardware
  818 ################################################################
  819 
  820 
  821 #---------------------------------------------------------
  822 # Check for CPU temp / fan speed / MB voltage...  :  Param  Warn  Alert  "Description"
  823 # Uses mbmon program (http://freshmeat.net/projects/xmbmon)
  824 #---------------------------------------------------------
  825 MBMonCheck () {
  826     MossheLog "MBMonCheck $1 $4"
  827     PARAM=$1                # TEMP0, TEMP1...
  828     SWARNVAL=$2             # 38.0
  829     SALERTVAL=$3            # 40.0
  830     DESCRIP=$4              # "CPU temp"
  831     
  832     if ! [ -z `which mbmon` ]; then
  833     echo "${DATIM};$MYGROUP;$MYNAME;$PARAM;UNDEF;0;MBMON not installed - cannot perform $PARAM check" >> $TEMPDIR/tmp.$$.collected.tmp
  834     else
  835         SVALUE=`$MBMON -c 1 -r | grep "$PARAM" | sed -e "s/$PARAM *: *//"`
  836     FLOATP=`expr index $SVALUE \.`
  837     if [ "$FLOATP" != "" ] ; then
  838             typeset -i VALUE=${SVALUE/./}
  839         typeset -i ALERTVAL=${SALERTVAL/./}
  840         typeset -i WARNVAL=${SWARNVAL/./}
  841     else
  842             typeset -i VALUE=${SVALUE}
  843         typeset -i ALERTVAL=$SALERTVAL
  844         typeset -i WARNVAL=$SWARNVAL
  845     fi
  846                                                
  847         if [ "$VALUE" -gt $ALERTVAL ]; then
  848         STATUS="ALERT"
  849         MESSAGE="$DESCRIP: $SVALUE exceeds ALERT value $SALERTVAL"
  850         elif [ "$VALUE" -gt $WARNVAL ]; then
  851         STATUS="WARN"
  852         MESSAGE="$DESCRIP: $SVALUE exceeds WARN value $SWARNVAL"
  853         else
  854         STATUS="OK"
  855         MESSAGE="$DESCRIP: $SVALUE in range"
  856         fi
  857     echo "${DATIM};$MYGROUP;$MYNAME;$PARAM;$STATUS;$SVALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  858     fi
  859 }
  860     
  861 
  862 #---------------------------------------------------------
  863 # Check for hardware sensor :  "Match" TempSensorNr  "Description"  Warn  Alert
  864 # Uses "sensors" program (lm-sensors packet, first run "sensors-probe")
  865 #---------------------------------------------------------
  866 HardwareSensor () {      # Match  Description  WarnTemp  AlertTemp
  867     MossheLog "HardwareSensor $1 $2"
  868     typeset PARAM=$1
  869     DESCR=`echo $2 | sed -e "s/ /_/g"`
  870     typeset -i WARN=$3
  871     typeset -i ALERT=$4
  872 
  873     if [ -z `which sensors` ]; then
  874         echo "${DATIM};$MYGROUP;$MYNAME;$PARAM;UNDEF;0;LM-SENSORS not installed - cannot perform temperature check" >> $TEMPDIR/tmp.$$.collected.tmp
  875     else
  876         typeset -i VALUE=`sensors | grep "^${PARAM}:" | cut -d ":" -f 2 | sed -e "s/^ *//g" | cut -d "." -f 1 | cut -d " " -f 1 | sed -e "s/\+//g" `
  877         if [ "$VALUE" -gt $ALERT ]; then
  878             STATUS="ALERT"
  879             MESSAGE="Hardware failing? $DESCR (${PARAM}) = $VALUE is too high"
  880         elif [ "$VALUE" -gt $WARN ]; then
  881             STATUS="WARN"
  882             MESSAGE="Hardware problematic: $DESCR (${PARAM}) with $VALUE above $WARN"
  883         else
  884             STATUS="OK"
  885             MESSAGE="Hardware ok $DESCR (${PARAM}) ok: $VALUE"
  886         fi
  887         echo "${DATIM};$MYGROUP;$MYNAME;Sensor_$DESCR;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  888     fi
  889 }
  890 
  891 
  892 #---------------------------------------------------------
  893 # Check for hardware sensor :  "Match" TempSensorNr  "Description"  Warn  Alert
  894 # Uses "sensors" program (lm-sensors packet, first run "sensors-probe")
  895 #---------------------------------------------------------
  896 HardwareSensorBetween () {      # Match  Description  AlertLow  WarnHigh
  897     MossheLog "HardwareSensorBetween $1 $2"
  898     typeset PARAM=$1
  899     DESCR=`echo $2 | sed -e "s/ /_/g"`
  900     typeset -i ALERTLOW=$3
  901     typeset -i WARNHIGH=$4
  902 
  903     if [ -z `which sensors` ]; then
  904         echo "${DATIM};$MYGROUP;$MYNAME;$PARAM;UNDEF;0;LM-SENSORS not installed - cannot perform temperature check" >> $TEMPDIR/tmp.$$.collected.tmp
  905     else
  906         typeset -i VALUE=`sensors | grep "^${PARAM}:" | cut -d ":" -f 2 | sed -e "s/^ *//g" | cut -d "." -f 1 | cut -d " " -f 1 | sed -e "s/\+//g" `
  907         if [ "$VALUE" -lt $ALERTLOW ]; then
  908             STATUS="ALERT"
  909             MESSAGE="Hardware failing? $DESCR (${PARAM}) = $VALUE too low"
  910         elif [ "$VALUE" -gt $WARNHIGH ]; then
  911             STATUS="WARN"
  912             MESSAGE="Hardware problematic: $DESCR (${PARAM}) = $VALUE too high"
  913         else
  914             STATUS="OK"
  915             MESSAGE="Hardware ok $DESCR (${PARAM}) ok: $VALUE"
  916         fi
  917         echo "${DATIM};$MYGROUP;$MYNAME;SensorBetween_$DESCR;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  918     fi
  919 }
  920 
  921 
  922 #---------------------------------------------------------
  923 # Deprecated Hardware* checks
  924 #---------------------------------------------------------
  925 HardwareTemp () {  
  926     echo "${DATIM};$MYGROUP;$MYNAME;Temp$1;UNDEF;0;HardwareTemp check is deprecated - use HardwareSensor instead." >> $TEMPDIR/tmp.$$.collected.tmp 
  927 }
  928 HardwareFan () {  
  929     echo "${DATIM};$MYGROUP;$MYNAME;Fan$1;UNDEF;0;HardwareFan check is deprecated - use HardwareSensor instead." >> $TEMPDIR/tmp.$$.collected
  930 }
  931 
  932 
  933 #---------------------------------------------------------
  934 # SmartMonHealth:  health status passed or not  DEVTYPE   DEVICE
  935 #---------------------------------------------------------
  936 SmartMonHealth () {
  937     MossheLog "SmartMonHealth $1 $2"
  938     DEVTYPE=$1
  939     DEVICE=$2
  940 
  941     if [ -z `which smartctl` ]; then
  942         echo "${DATIM};$MYGROUP;$MYNAME;hd_$DEVICE_$DEVTYPE;UNDEF;0;SMARTCTL (smartmontools) not installed - cannot perform disk health check" >> $TEMPDIR/tmp.$$.collected.tmp
  943         VALUE=0
  944     else
  945         STATE=`smartctl -H -d $DEVTYPE $DEVICE | grep "^SMART overall-health self-assessment test result: " | cut -d " " -f 6-`
  946         if [ "$STATE" = "PASSED" ]; then
  947             STATUS="OK"
  948             MESSAGE="Disk $DEVTYPE on $DEVICE healthy"
  949             VALUE=1
  950         else
  951             STATUS="ALERT"
  952             MESSAGE="Disk $DEVTYPE on $DEVICE failing: $STATE"
  953             VALUE=3
  954         fi
  955         echo "${DATIM};$MYGROUP;$MYNAME;hd_$DEVICE_$DEVTYPE;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  956     fi
  957 }
  958 
  959 
  960 #---------------------------------------------------------
  961 # Raid3ware:  health status passed or not   ControllerNo.  Partition
  962 #---------------------------------------------------------
  963 Raid3ware () {
  964     MossheLog "Raid3ware $1 $2"
  965     CTRL=$1
  966     UNIT=$2
  967 
  968     if [ -z `which tw_cli` ]; then
  969         echo "${DATIM};$MYGROUP;$MYNAME;3ware_$CTRL_$UNIT;UNDEF;0;tw_cli not installed - cannot perform 3ware RAID check" >> $TEMPDIR/tmp.$$.collected.tmp
  970         VALUE=0
  971     else
  972         STATE=`tw_cli /c$CTRL show | grep "^$UNIT " | fgrep "RAID-"  | cut -d " " -f 8-9`
  973         if [ "$STATE" = " OK" -o "$STATE" = "OK " ]; then
  974             STATUS="OK"
  975             MESSAGE="3ware Controller $CTRL unit $UNIT healthy"
  976             VALUE=1
  977         else
  978             STATUS="ALERT"
  979             MESSAGE="3ware Controller $CTRL unit $UNIT has problem: $STATE"
  980             VALUE=3
  981         fi
  982         echo "${DATIM};$MYGROUP;$MYNAME;3ware_$RAID_$UNIT;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
  983     fi
  984 }
  985 
  986 
  987 
  988 #---------------------------------------------------------
  989 # Software-RAID status:  (none)
  990 #   Depends on /proc existence. 
  991 #   Works with md0 (should be extended for more than one device)
  992 #   but running more than one software RAID array is not recommended anyway. 
  993 #   WARN when syncing, ALERT when a partition has failed.
  994 #---------------------------------------------------------
  995 RaidCheck () {
  996     MossheLog "RaidCheck"
  997     typeset -i NUM=0
  998     MDSTAT="/proc/mdstat"
  999     if ! [ -f $MDSTAT ]; then
 1000     echo "${DATIM};$MYGROUP;$MYNAME;RAID;UNDEF;0;$MDSTAT not present - cannot perform RAID check" >> $TEMPDIR/tmp.$$.collected.tmp
 1001     else
 1002     BLOCKS=$(grep blocks $MDSTAT)
 1003     DEVICE=$(grep md $MDSTAT)
 1004     #    easier but more processes:
 1005     #    typeset -i FAIL=0
 1006     #    typeset -i SYNC=0
 1007     #    FAIL=$(grep blocks $MDSTAT | grep -c _)
 1008     #    SYNC=$(grep -c resync $MDSTAT)
 1009     XBLOCKS="${BLOCKS/_/}"
 1010     XDEVICE="${DEVICE/resync/}"
 1011     STATUS="OK"
 1012     MESSAGE="$DEVICE - $BLOCKS"
 1013     if [ "$DEVICE" != "$XDEVICE" ]; then
 1014         STATUS="WARN"
 1015         MESSAGE="RESYNC "${DEVICE}
 1016         NUM=1
 1017     fi
 1018     if [ "$BLOCKS" != "$XBLOCKS" ]; then
 1019         STATUS="ALERT"
 1020         MESSAGE="FAILED "${DEVICE}
 1021         NUM=2
 1022     fi
 1023     echo "${DATIM};$MYGROUP;$MYNAME;RAID;$STATUS;$NUM;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
 1024     fi
 1025 }
 1026 
 1027 #---------------------------------------------------------
 1028 # ApcUpsValueTooLow:  KEY warnvalue alertvalue
 1029 #---------------------------------------------------------
 1030 
 1031 ApcUpsValueTooLow () {
 1032     MossheLog "ApcUpsValueLow $1 $2 $3"
 1033     KEY=$1
 1034     typeset -i WARNVAL=$2
 1035     typeset -i ALERTVAL=$3
 1036 
 1037     if [ -z `which apcaccess` ]; then
 1038         echo "${DATIM};$MYGROUP;$MYNAME;ApcUpsValueTooLow_$KEY;UNDEF;0;APCACCESS not installed - cannot perform APC UPS health check" >> $TEMPDIR/tmp.$$.collected.tmp
 1039     else
 1040         typeset -i VALUE=`apcaccess -h 127.0.0.1 | fgrep $KEY | cut -d ':' -f 2 | cut -d ' ' -f 2 | cut -d '.' -f 1`
 1041         if [ "$VALUE" -lt $ALERTVAL ]; then
 1042             STATUS="ALERT"
 1043             MESSAGE="APC parameter $KEY = $VALUE critically low"
 1044         elif [ "$VALUE" -lt $WARNVAL ]; then
 1045             STATUS="WARN"
 1046             MESSAGE="APC parameter $KEY = $VALUE too low"
 1047         else
 1048             STATUS="OK"
 1049             MESSAGE="APC parameter $KEY ok : $VALUE"
 1050         fi
 1051         echo "${DATIM};$MYGROUP;$MYNAME;ApcUpsValueTooLow_$KEY;${STATUS};${VALUE};$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
 1052     fi
 1053 }
 1054 
 1055 
 1056 #---------------------------------------------------------
 1057 # ApcUpsValueTooHigh:  KEY warnvalue alertvalue
 1058 #---------------------------------------------------------
 1059 
 1060 ApcUpsValueTooHigh () {
 1061     MossheLog "ApcUpsValueTooHigh $1 $2 $3"
 1062     KEY=$1
 1063     typeset -i WARNVAL=$2
 1064     typeset -i ALERTVAL=$3
 1065 
 1066     if [ -z `which apcaccess` ]; then
 1067         echo "${DATIM};$MYGROUP;$MYNAME;ApcUpsValueTooHigh_$KEY;UNDEF;0;APCACCESS not installed - cannot perform APC UPS health check" >> $TEMPDIR/tmp.$$.collected.tmp
 1068     else
 1069         typeset -i VALUE=`apcaccess -h 127.0.0.1 | fgrep $KEY | cut -d ':' -f 2 | cut -d ' ' -f 2 | cut -d '.' -f 1`
 1070         if [ "$VALUE" -gt $ALERTVAL ]; then
 1071             STATUS="ALERT"
 1072             MESSAGE="APC parameter $KEY = $VALUE critically high"
 1073         elif [ "$VALUE" -gt $WARNVAL ]; then
 1074             STATUS="WARN"
 1075             MESSAGE="APC parameter $KEY = $VALUE too high"
 1076         else
 1077             STATUS="OK"
 1078             MESSAGE="APC parameter $KEY ok : $VALUE"
 1079         fi
 1080         echo "${DATIM};$MYGROUP;$MYNAME;ApcUpsValueTooHigh_$KEY;${STATUS};${VALUE};$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
 1081     fi
 1082 }
 1083 
 1084 #---------------------------------------------------------
 1085 # ApcUpsStatus:  KEY compare
 1086 #---------------------------------------------------------
 1087 
 1088 ApcUpsStatus () {
 1089     MossheLog "ApcUpsValueTooHigh $1 $2 $3"
 1090     KEY=$1
 1091     MATCH=$2
 1092 
 1093     if [ -z `which apcaccess` ]; then
 1094         echo "${DATIM};$MYGROUP;$MYNAME;ApcUpsStatus_$KEY;UNDEF;0;APCACCESS not installed - cannot perform APC UPS health check" >> $TEMPDIR/tmp.$$.collected
 1095     else
 1096         VALUE=`apcaccess -h 127.0.0.1 | fgrep $KEY| cut -d ':' -f 2 | cut -d ' ' -f 2`
 1097         if [ "$VALUE" = $MATCH ]; then
 1098             STATUS="OK"
 1099             MESSAGE="APC parameter $KEY ok : $VALUE"
 1100         else
 1101             STATUS="ALERT"
 1102             MESSAGE="APC parameter $KEY in critical state: $VALUE"
 1103         fi
 1104     echo "${DATIM};$MYGROUP;$MYNAME;ApcUpsStatus_$KEY;${STATUS};${VALUE};$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
 1105     fi
 1106 }
 1107 
 1108 
 1109 
 1110                                                       
 1111 ################################################################
 1112 ###  Network
 1113 ################################################################
 1114 
 1115 
 1116 #---------------------------------------------------------
 1117 # NetworkErrors:  interface  WARN:percentage  ALERT:percentage
 1118 #---------------------------------------------------------
 1119 NetworkErrorsCheck () {
 1120   MossheLog "NetworkErrorsCheck $1"
 1121   if [ -z `which netstat` ]; then
 1122     echo "${DATIM};$MYGROUP;$MYNAME;networktraffic (general);UNDEF;0;NETSTAT not installed - cannot perform NETWORKTRAFFIC check" >> $TEMPDIR/tmp.$$.collected.tmp
 1123   else
 1124     IFACE="$1"
 1125     typeset -i WARNTRAF=$2
 1126     typeset -i ALERTRAF=$3
 1127     
 1128 #eth0      Link encap:Ethernet  HWaddr FE:FD:D5:CB:F4:BC  
 1129 #          inet addr:213.203.244.188  Bcast:213.203.244.188  Mask:255.255.255.255
 1130 #          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 1131 #          RX packets:27259082 errors:0 dropped:0 overruns:0 frame:0
 1132 #          TX packets:30825801 errors:0 dropped:0 overruns:0 carrier:0
 1133 #          collisions:0 txqueuelen:1000 
 1134 #          RX bytes:3895048735 (3.6 GiB)  TX bytes:2141303265 (1.9 GiB)
 1135 #          Interrupt:5 
 1136 
 1137     STAT=`/sbin/ifconfig $IFACE | fgrep "RX packets"`
 1138     typeset -i RXOK=`echo $STAT | cut -d ":" -f 2 | cut -d " " -f 1`
 1139     typeset -i RXE1=`echo $STAT | cut -d ":" -f 3 | cut -d " " -f 1`
 1140     typeset -i RXE2=`echo $STAT | cut -d ":" -f 4 | cut -d " " -f 1`
 1141     typeset -i RXE3=`echo $STAT | cut -d ":" -f 5 | cut -d " " -f 1`
 1142     typeset -i RXERR=$(( RXE1 + RXE2 + RXE3 ))
 1143     typeset -i RXPERC=$(( RXERR * 100 / ( RXOK + 1 ) ))
 1144 
 1145     STAT=`/sbin/ifconfig $IFACE | fgrep "TX packets"`
 1146     typeset -i TXOK=`echo $STAT | cut -d ":" -f 2 | cut -d " " -f 1`
 1147     typeset -i TXE1=`echo $STAT | cut -d ":" -f 3 | cut -d " " -f 1`
 1148     typeset -i TXE2=`echo $STAT | cut -d ":" -f 4 | cut -d " " -f 1`
 1149     typeset -i TXE3=`echo $STAT | cut -d ":" -f 5 | cut -d " " -f 1`
 1150     typeset -i TXERR=$(( TXE1 + TXE2 + TXE3 ))
 1151     typeset -i TXPERC=$(( TXERR * 100 / (TXOK + 1)))
 1152     
 1153     typeset -i PERC=$(( TXPERC + RXPERC ))
 1154     
 1155     MESSAGE="No notable network errors on interface $IFACE"
 1156     STATUS="OK"      
 1157 
 1158     if [ $PERC -gt $WARNTRAF  ]; then
 1159     STATUS="WARN";
 1160     MESSAGE="Traffic errors on $IFACE: $RXPERC % in / $TXPERC % out"
 1161     fi
 1162     if [ $PERC -gt $ALERTRAF  ]; then
 1163     STATUS="ALERT";
 1164     MESSAGE="Traffic errors on $IFACE: $RXPERC % in / $TXPERC % out"
 1165     fi
 1166     echo "${DATIM};$MYGROUP;$MYNAME;net_errors_${IFACE};$STATUS;$PERC;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
 1167   fi
 1168 }
 1169 
 1170 #---------------------------------------------------------
 1171 # NetworkTraffic:  interface  WARN:byte/s  ALERT:byte/s
 1172 #---------------------------------------------------------
 1173 NetworkTrafficCheck () {
 1174     MossheLog "NetworkTrafficCheck $1"
 1175   if [ -z `which netstat` ]; then
 1176     echo "${DATIM};$MYGROUP;$MYNAME;networktraffic (general);UNDEF;0;NETSTAT not installed - cannot perform NETWORKTRAFFIC check" >> $TEMPDIR/tmp.$$.collected.tmp
 1177   else
 1178     IFACE="$1"
 1179     typeset -i WARNTRAF=$2
 1180     typeset -i ALERTRAF=$3
 1181     
 1182     NOW=`date +%s`
 1183     STAT=`/sbin/ifconfig $IFACE | fgrep "RX bytes"`
 1184 #          RX bytes:153523789 (146.4 MiB)  TX bytes:153523789 (146.4 MiB)
 1185     typeset -i RX=`echo $STAT | cut -d ":" -f 2 | cut -d " " -f 1`
 1186     typeset -i TX=`echo $STAT | cut -d ":" -f 3 | cut -d " " -f 1`
 1187     typeset -i TOTAL=$(( RX + TX ))
 1188     if [ $TOTAL -lt 0 ]; then TOTAL=0; fi       # very crude rollover fix
 1189 
 1190     if ! [ -f $DATADIR/stat.networktraffic.$IFACE ]; then
 1191     MESSAGE="Initializing network traffic analysis on interface $IFACE"
 1192     STATUS="UNDEF"
 1193     else     
 1194     OLDSEC=`cat $DATADIR/stat.networktraffic.$IFACE | cut -d " " -f 1`
 1195     OLDTRAFFIC=`cat $DATADIR/stat.networktraffic.$IFACE | cut -d " " -f 2`
 1196     
 1197     typeset -i TRAFPERSEC=$(( (TOTAL - OLDTRAFFIC) / ( NOW - OLDSEC + 1) / 128 ))
 1198     # short math: / 128  =  / 1024 for kilo  * 8 bits in a byte ))
 1199         if [ $TRAFPERSEC -lt 0 ]; then TRAFPERSEC=0; fi       # very crude rollover fix
 1200      
 1201     MESSAGE="Network traffic on interface $IFACE ok: $TRAFPERSEC kbit/sec"
 1202     STATUS="OK"      
 1203 
 1204         if [ $TRAFPERSEC -gt $WARNTRAF ]; then 
 1205         STATUS="WARN";
 1206         MESSAGE="High traffic on $IFACE: $TRAFPERSEC kbit/sec"
 1207     fi
 1208         if [ $TRAFPERSEC -gt $ALERTRAF ]; then
 1209         STATUS="ALERT";
 1210         MESSAGE="Excessive traffic on $IFACE: $TRAFPERSEC kbit/sec"
 1211     fi
 1212     fi
 1213     echo "${DATIM};$MYGROUP;$MYNAME;net_traffic_${IFACE};$STATUS;$TRAFPERSEC;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp 
 1214     echo "$NOW $TOTAL" > $DATADIR/stat.networktraffic.$IFACE
 1215   fi
 1216 }
 1217 
 1218 #---------------------------------------------------------
 1219 # NetworkBandwidth:  interface  WARN:GByte/month  ALERT:GB/mth
 1220 #---------------------------------------------------------
 1221 NetworkBandwidth () {
 1222     MossheLog "NetworkBandwidth $1"
 1223   if [ -z `which netstat` ]; then
 1224     echo "${DATIM};$MYGROUP;$MYNAME;networkbandwidth (general);UNDEF;0;NETSTAT not installed - cannot perform NETWORKTRAFFIC check" >> $TEMPDIR/tmp.$$.collected.tmp
 1225   else
 1226     IFACE="$1"
 1227     typeset -i WARNTRAF=$2
 1228     typeset -i ALERTRAF=$3
 1229     
 1230     NOW=`date +%s`
 1231     STAT=`/sbin/ifconfig $IFACE | fgrep "RX bytes"`
 1232 #          RX bytes:153523789 (146.4 MiB)  TX bytes:153523789 (146.4 MiB)
 1233     typeset -i RX=`echo $STAT | cut -d ":" -f 2 | cut -d " " -f 1`
 1234     typeset -i TX=`echo $STAT | cut -d ":" -f 3 | cut -d " " -f 1`
 1235     typeset -i TOTAL=$(( RX + TX ))
 1236     if [ $TOTAL -lt 0 ]; then TOTAL=0; fi       # very crude rollover fix
 1237     
 1238     if ! [ -f $DATADIR/stat.networkbandwidth.$IFACE ]; then
 1239     MESSAGE="Initializing network traffic analysis on interface $IFACE"
 1240     STATUS="UNDEF"
 1241     else     
 1242     OLDSEC=`cat $DATADIR/stat.networkbandwidth.$IFACE | cut -d " " -f 1`
 1243     OLDTRAFFIC=`cat $DATADIR/stat.networkbandwidth.$IFACE | cut -d " " -f 2`
 1244     
 1245     typeset -i BWPERMONTH=$(( (TOTAL - OLDTRAFFIC) / ( NOW - OLDSEC + 1) / 414 ))
 1246     # / k1024 / M1024 / G1024 * h3600 * d24 * m30
 1247         if [ $BWPERMONTH -lt 0 ]; then BWPERMONTH=0; fi       # very crude rollover fix
 1248      
 1249     MESSAGE="Bandwidth usage on interface $IFACE ok: $BWPERMONTH  GB/month"
 1250     STATUS="OK"      
 1251 
 1252         if [ $BWPERMONTH -gt $WARNTRAF ]; then 
 1253         STATUS="WARN";
 1254         MESSAGE="High bandwidth usage on interface $IFACE ok: $BWPERMONTH GB/month"
 1255     fi
 1256         if [ $BWPERMONTH -gt $ALERTRAF ]; then
 1257         STATUS="ALERT";
 1258         MESSAGE="Excessive bandwidth usage on interface $IFACE ok: $BWPERMONTH GB/month"
 1259     fi
 1260     fi
 1261     echo "${DATIM};$MYGROUP;$MYNAME;net_bandwidth_${IFACE};$STATUS;$BWPERMONTH;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp 
 1262     echo "$NOW $TOTAL" > $DATADIR/stat.networkbandwidth.$IFACE
 1263   fi
 1264 }
 1265 
 1266 #---------------------------------------------------------
 1267 # NetworkLinuxTraffic:  interface  WARN:byte/s  ALERT:byte/s
 1268 #---------------------------------------------------------
 1269 NetworkLinuxTrafficCheck () {
 1270     MossheLog "NetworkLinuxTrafficCheck $1"
 1271   if [ -e /proc/net/dev ]; then
 1272     IFACE="$1"
 1273     typeset -i WARNTRAF=$2
 1274     typeset -i ALERTRAF=$3
 1275     
 1276     NOW=`date +%s`
 1277     # eth0: 66342695 458262355 0 0 0 0 0 0 249959870 1184448 0 0 0 0 0 0
 1278     STAT=`/bin/cat /proc/net/dev | fgrep $IFACE | sed -e 's/  */ /g' | sed -e 's/^ *//'`
 1279     typeset -i RX=`echo $STAT | cut -d " " -f 2`
 1280     typeset -i TX=`echo $STAT | cut -d " " -f 10`
 1281     typeset -i TOTAL=$(( RX + TX ))
 1282     if [ $TOTAL -lt 0 ]; then TOTAL=0; fi       # very crude rollover fix
 1283     
 1284     if ! [ -f $DATADIR/stat.networktraffic.$IFACE ]; then
 1285     MESSAGE="Initializing network traffic analysis on interface $IFACE"
 1286     STATUS="UNDEF"
 1287     else     
 1288     OLDSEC=`cat $DATADIR/stat.networktraffic.$IFACE | cut -d " " -f 1`
 1289     OLDTRAFFIC=`cat $DATADIR/stat.networktraffic.$IFACE | cut -d " " -f 2`
 1290     
 1291     typeset -i TRAFPERSEC=$(( (TOTAL - OLDTRAFFIC) / ( NOW - OLDSEC + 1) / 128 ))
 1292     # short math: / 128  =  / 1024 for kilo  * 8 bits in a byte ))
 1293         if [ $TRAFPERSEC -lt 0 ]; then TRAFPERSEC=0; fi       # very crude rollover fix
 1294      
 1295     MESSAGE="Network traffic on interface $IFACE ok: $TRAFPERSEC kbit/sec"
 1296     STATUS="OK"      
 1297 
 1298         if [ $TRAFPERSEC -gt $WARNTRAF ]; then 
 1299         STATUS="WARN";
 1300         MESSAGE="High traffic on $IFACE: $TRAFPERSEC kbit/sec"
 1301     fi
 1302         if [ $TRAFPERSEC -gt $ALERTRAF ]; then
 1303         STATUS="ALERT";
 1304         MESSAGE="Excessive traffic on $IFACE: $TRAFPERSEC kbit/sec"
 1305     fi
 1306     fi
 1307     echo "${DATIM};$MYGROUP;$MYNAME;net_ltraffic_${IFACE};$STATUS;$TRAFPERSEC;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp 
 1308     echo "$NOW $TOTAL" > $DATADIR/stat.networktraffic.$IFACE
 1309   else
 1310     echo "${DATIM};$MYGROUP;$MYNAME;networktraffic (general);UNDEF;0;Cannot find /proc/net/dev - cannot perform NETWORKLINUXTRAFFIC check" >> $TEMPDIR/tmp.$$.collected.tmp
 1311   fi
 1312 }
 1313 
 1314 #---------------------------------------------------------
 1315 # NetworkLinuxBandwidth:  interface  WARN:GByte/month  ALERT:GB/mth
 1316 #---------------------------------------------------------
 1317 NetworkLinuxBandwidth () {
 1318     MossheLog "NetworkLinuxBandwidth $1"
 1319   if [ -e /proc/net/dev ]; then
 1320     IFACE="$1"
 1321     typeset -i WARNTRAF=$2
 1322     typeset -i ALERTRAF=$3
 1323     
 1324     NOW=`date +%s`
 1325     # eth0: 66342695 458262355 0 0 0 0 0 0 249959870 1184448 0 0 0 0 0 0
 1326     STAT=`/bin/cat /proc/net/dev | fgrep $IFACE | sed -e 's/  */ /g'`
 1327     typeset -i RX=`echo $STAT | cut -d " " -f 2`
 1328     typeset -i TX=`echo $STAT | cut -d ":" -f 10`
 1329     typeset -i TOTAL=$(( RX + TX ))
 1330     if [ $TOTAL -lt 0 ]; then TOTAL=0; fi       # very crude rollover fix
 1331     
 1332     if ! [ -f $DATADIR/stat.networkbandwidth.$IFACE ]; then
 1333     MESSAGE="Initializing network traffic analysis on interface $IFACE"
 1334     STATUS="UNDEF"
 1335     else     
 1336     OLDSEC=`cat $DATADIR/stat.networkbandwidth.$IFACE | cut -d " " -f 1`
 1337     OLDTRAFFIC=`cat $DATADIR/stat.networkbandwidth.$IFACE | cut -d " " -f 2`
 1338     
 1339     typeset -i BWPERMONTH=$(( (TOTAL - OLDTRAFFIC) / ( NOW - OLDSEC + 1) / 414 ))
 1340     # / k1024 / M1024 / G1024 * h3600 * d24 * m30
 1341         if [ $BWPERMONTH -lt 0 ]; then BWPERMONTH=0; fi       # very crude rollover fix
 1342      
 1343     MESSAGE="Bandwidth usage on interface $IFACE ok: $BWPERMONTH  GB/month"
 1344     STATUS="OK"      
 1345 
 1346         if [ $BWPERMONTH -gt $WARNTRAF ]; then 
 1347         STATUS="WARN";
 1348         MESSAGE="High bandwidth usage on interface $IFACE ok: $BWPERMONTH GB/month"
 1349     fi
 1350         if [ $BWPERMONTH -gt $ALERTRAF ]; then
 1351         STATUS="ALERT";
 1352         MESSAGE="Excessive bandwidth usage on interface $IFACE ok: $BWPERMONTH GB/month"
 1353     fi
 1354     fi
 1355     echo "${DATIM};$MYGROUP;$MYNAME;net_lbandwidth_${IFACE};$STATUS;$BWPERMONTH;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp 
 1356     echo "$NOW $TOTAL" > $DATADIR/stat.networkbandwidth.$IFACE
 1357   else
 1358     echo "${DATIM};$MYGROUP;$MYNAME;networktraffic (general);UNDEF;0;Cannot find /proc/net/dev - cannot perform NETWORKLINUXTRAFFIC check" >> $TEMPDIR/tmp.$$.collected.tmp
 1359   fi
 1360 }
 1361 
 1362 #---------------------------------------------------------
 1363 # NetworkConnectionsNetstat WARN ALERT
 1364 #---------------------------------------------------------
 1365 NetworkConnectionsNetstat () {
 1366     MossheLog "NetworkConnections $1 $2"
 1367     typeset -i WARN ALERT; WARN=$1; ALERT=$2
 1368     typeset -i VALUE 
 1369     
 1370   if ! [ -x /bin/netstat ]; then
 1371     STATUS="UNDEF"
 1372     COUNT=0
 1373     MESSAGE="NETSTAT not installed - cannot perform NetworkConnectionsNetstat check."
 1374   else
 1375 
 1376     VALUE=`netstat -s | fgrep "connections established" | cut -d "c" -f 1 | sed -e "s/ *//g"`
 1377     if [ $VALUE -gt $ALERT ]; then 
 1378         STATUS="ALERT"
 1379     MESSAGE="Critically many connections : $VALUE"
 1380     elif [ $VALUE -gt $WARN ]; then 
 1381         STATUS="WARN"
 1382     MESSAGE="Many connections : $VALUE"
 1383     else
 1384     STATUS="OK"; MESSAGE="Connection count ok: $VALUE"
 1385     fi
 1386     
 1387     echo "${DATIM};$MYGROUP;$MYNAME;NetworkConnections;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp    
 1388   fi
 1389 }
 1390 
 1391 #---------------------------------------------------------
 1392 # NetworkConnections WARN ALERT
 1393 #---------------------------------------------------------
 1394 NetworkConnections () {
 1395     MossheLog "NetworkConnections $1 $2"
 1396     typeset -i WARN ALERT; WARN=$1; ALERT=$2
 1397     typeset -i VALUE 
 1398     
 1399     VALUE=`ss -tu | fgrep "ESTAB" | wc -l`
 1400     if [ $VALUE -gt $ALERT ]; then 
 1401         STATUS="ALERT"
 1402     MESSAGE="Critically many connections : $VALUE"
 1403     elif [ $VALUE -gt $WARN ]; then 
 1404         STATUS="WARN"
 1405     MESSAGE="Many connections : $VALUE"
 1406     else
 1407     STATUS="OK"; MESSAGE="Connection count ok: $VALUE"
 1408     fi
 1409     
 1410     echo "${DATIM};$MYGROUP;$MYNAME;NetworkConnections;$STATUS;$VALUE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp    
 1411 }
 1412 
 1413 
 1414 
 1415  
 1416  
 1417                                                       
 1418 ################################################################
 1419 ###  IDS functions
 1420 ################################################################
 1421 
 1422 
 1423 #---------------------------------------------------------
 1424 # Check Log Files: name string logfile max occurrence (warn alert)
 1425 #   if using wildcards escape the filename-pattern with quotes when calling
 1426 #---------------------------------------------------------
 1427 LogEntryCheck () {
 1428     MossheLog "LogEntryCheck $1 "
 1429      NAME="$1"
 1430      MATCH="$2"
 1431      FILE="$3"
 1432      typeset -i WARN="$4"
 1433      typeset -i ALERT="$5"
 1434      typeset -i OCCUR=`cat $FILE | fgrep "${MATCH}" | wc -l`
 1435      
 1436      MESSAGE="Check $FILE for '$MATCH' - $OCCUR occurrencies"
 1437      STATUS="OK"
 1438      
 1439      if [ $OCCUR -gt $WARN ]; then 
 1440         STATUS="WARN";
 1441     MESSAGE="Notable occurrence of '$MATCH' in $FILE: $OCCUR"
 1442 
 1443     if [ $OCCUR -gt $ALERT ]; then  
 1444             STATUS="ALERT";
 1445         MESSAGE="Excessive occurrence of '$MATCH' in $FILE: $OCCUR"
 1446     fi
 1447      fi
 1448      
 1449      echo "${DATIM};$MYGROUP;$MYNAME;$NAME;$STATUS;$OCCUR;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
 1450 }
 1451 
 1452 
 1453 #---------------------------------------------------------
 1454 # CheckFileChanges  KNOWNFILE  CHECKEDFILE:  are these the same?
 1455 #---------------------------------------------------------
 1456 CheckFileChanges () {
 1457     MossheLog "CheckFileChanges $1"
 1458     KNOWNSHORT="$1"
 1459     KNOWNF="$DATADIR/CompareFiles/$KNOWNSHORT"
 1460     ORIGF="$2"
 1461     CTEMP=`mktemp`
 1462  
 1463     if [ ! -f $ORIGFF ]; then
 1464         MESSAGE="Original file $ORIGF does not exist"
 1465     STATUS="ALERT"
 1466     CODE=4
 1467     elif [ ! -f $KNOWNF ]; then
 1468     MESSAGE="Comparison file $KNOWNF does not exist - please generate"
 1469     STATUS="UNDEF"
 1470     CODE=3
 1471     else
 1472     diff $KNOWNF $ORIGF > $CTEMP
 1473     if [ -s $CTEMP ]; then
 1474             CODE=1
 1475         MESSAGE="File $ORIGF has changed: "
 1476         while read A; do
 1477                 MESSAGE="$MESSAGE  $A"
 1478         done < $CTEMP  
 1479         STATUS="WARN"       
 1480     else
 1481         MESSAGE="File $ORIGF stays unchanged"
 1482         CODE=0
 1483         STATUS="OK"         
 1484         fi
 1485     rm $CTEMP
 1486      fi
 1487      echo "${DATIM};$MYGROUP;$MYNAME;filechange_${KNOWNSHORT};$STATUS;$CODE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
 1488 }
 1489 
 1490 
 1491 #---------------------------------------------------------
 1492 # CheckConfigChanges  KNOWNFILE  "COMMAND+PARAM":  are these the same?
 1493 #---------------------------------------------------------
 1494 CheckConfigChanges () {
 1495     MossheLog "CheckConfigChanges $1"
 1496     KNOWNSHORT="$1"    
 1497     KNOWNF="$DATADIR/CompareFiles/$KNOWNSHORT"
 1498     CMD="$2"
 1499     CMDOUT="$TEMPDIR/tmp.$$.chkconfchanges"
 1500     CTEMP=`mktemp`
 1501  
 1502     if [ ! -f $KNOWNF ]; then
 1503     MESSAGE="Comparison file $KNOWNF does not exist - please generate"
 1504     STATUS="UNDEF"
 1505     CODE=3
 1506     else
 1507         $CMD | sort > $CMDOUT
 1508     diff $KNOWNF $CMDOUT > $CTEMP
 1509      fi
 1510      if [ -s $CTEMP ]; then
 1511     MESSAGE="Configuration $CMD has changed: "
 1512         while read A; do
 1513             MESSAGE="$MESSAGE  <br>$A"
 1514     done < $CTEMP  
 1515     STATUS="WARN"       
 1516      else
 1517     MESSAGE="Configuration of  '$CMD'  stays unchanged"
 1518     STATUS="OK"         
 1519      fi
 1520      rm $CTEMP
 1521      echo "${DATIM};$MYGROUP;$MYNAME;confchange_${KNOWNSHORT};$STATUS;$CODE;$MESSAGE" >> $TEMPDIR/tmp.$$.collected.tmp
 1522      rm -f $CMDOUT
 1523 }
 1524 
 1525 #############################################################################
 1526 #############################################################################