/[pdpsoft]/trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_temperature
ViewVC logotype

Diff of /trunk/nl.nikhef.ndpf.tools/nagios-ndpf-sensors/scripts/check_temperature

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2192 by fbernabe, Wed Feb 9 10:46:44 2011 UTC revision 2193 by ronalds, Mon Feb 14 13:43:20 2011 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2    
3  if [ $# -lt 3 ]; then  if [ $# -lt 5 ]; then
4    echo "missing required argument" >&2      echo "usage: $0 <hostname> <warn_cpu> <error_cpu> <warn_system> <error_system> [debug]" >&2
5        echo "UNKNOWN - missing required argument(s)"
6        exit 3
7  fi  fi
8    
9  hostname=$1  hostname=$1
10  warn_treshold=$2  warn_cpu=$2
11  error_treshold=$3  error_cpu=$3
12  debug=${4:-""}  warn_sys=$4
13    error_sys=$5
14  temperature=""  temperature=""
15  user="monitor"  user="monitor"
16  password="/etc/nagios/pass_temperature"  password="/etc/nagios/pass_temperature"
17    
18  if [ "${debug[0]}" = "debug" ]  debug=0
19  then  if [ $# -gt 5 ]; then
20    echo $hostname      debug=1
21  fi  fi
22    
23    stat_text[0]="OK"
24    stat_text[1]="WARNING"
25    stat_text[2]="CRITICAL"
26    stat_text[3]="UNKNOWN"
27    
28    [ $debug -gt 0 ] && echo $hostname >&2
29    
30  ipminame="`echo $hostname | cut -d'.' -f1`.ipmi.nikhef.nl"  ipminame="`echo $hostname | cut -d'.' -f1`.ipmi.nikhef.nl"
31    
32  if [ "${debug[0]}" = "debug" ]  [ $debug -gt 0 ] && echo $ipminame >&2
 then  
    echo $ipminame  
 fi  
33    
34  if echo $hostname | grep "wn-" > /dev/null  if echo $hostname | grep "wn-" > /dev/null
35  then  then
# Line 35  else Line 42  else
42  fi  fi
43    
44    
45  if [ "${debug[0]}" = "debug" ]  [ $debug -gt 0 ] && echo $x
 then  
    echo $x  
 fi  
46    
47    
48  case $x in  case $x in
49       bull) echo "This is a bull";;       bull)
50            msg="This is a bull"
51       val) temperature=`ipmitool -H $ipminame -U $user -f $password -L USER sensor get 'CPU Temp 1' 'CPU Temp 2' 'Sys Temp' | grep "Sensor Reading" | cut -d' ' -f 12`          perf=""
52            temperature[1]=`echo ${temperature[0]} | awk '{print $1}'`          ret=3;;  # UNKNOWN, bull should not appear
53            temperature[2]=`echo ${temperature[0]} | awk '{print $2}'`  
54            temperature[3]=`echo ${temperature[0]} | awk '{print $3}'`       val)
55            temperature=`ipmitool -H $ipminame -U $user -f $password -L USER \
56            if [ "${debug[0]}" = "debug" ]                       sensor get 'CPU Temp 1' 'CPU Temp 2' 'Sys Temp' | \
57            then                       grep "Sensor Reading" | cut -d' ' -f 12`
58                  echo "Temperature of $hostname CPU1 is ${temperature[1]}"          temperature[1]=`echo ${temperature[0]} | awk '{print $1}'`
59                  echo "Temperature of $hostname CPU2 is ${temperature[2]}"          temperature[2]=`echo ${temperature[0]} | awk '{print $2}'`
60                  echo "Temperature of $hostname System is ${temperature[3]}"          temperature[3]=`echo ${temperature[0]} | awk '{print $3}'`
61            fi  
62            if [ ${temperature[1]} -gt $error_treshold ] || [ ${temperature[2]} -gt $error_treshold ] || [ ${temperature[3]} -gt $error_treshold ]          if [ $debug -gt 0 ]
63            then
64                echo "Temperature of $hostname CPU1 is ${temperature[1]}" >&2
65                echo "Temperature of $hostname CPU2 is ${temperature[2]}" >&2
66                echo "Temperature of $hostname System is ${temperature[3]}" >&2
67            fi
68            if [ ${temperature[1]} -gt $error_cpu ] ||
69               [ ${temperature[2]} -gt $error_cpu ] ||
70               [ ${temperature[3]} -gt $error_sys ]
71          then          then
72                  echo "CRITICAL - CPU Temp 1: ${temperature[1]}°C - CPU Temp 2: ${temperature[2]}°C - Sys Temp: ${temperature[3]}°C"              ret=2
73                  exit 2          elif [ ${temperature[1]} -gt $warn_cpu ] ||
74          elif [ ${temperature[1]} -gt $warn_treshold ] || [ ${temperature[2]} -gt $warn_treshold ] || [ ${temperature[3]} -gt $warn_treshold ]               [ ${temperature[2]} -gt $warn_cpu ] ||
75          then               [ ${temperature[3]} -gt $warn_sys ]
76                  echo "WARNING - CPU Temp 1: ${temperature[1]}°C - CPU Temp 2: ${temperature[2]}°C - Sys Temp: ${temperature[3]}°C"          then
77                  exit 1              ret=1
78          fi          else
79                          ret=0
80            echo "OK - CPU Temp 1: ${temperature[1]}°C - CPU Temp 2: ${temperature[2]}°C - Sys Temp: ${temperature[3]}°C"          fi
81            exit 0;;          msg="CPU Temp 1: ${temperature[1]}°C - CPU Temp 2: ${temperature[2]}°C - Sys Temp: ${temperature[3]}°C"
82            perf="'T(cpu1)'=${temperature[1]}°C;$warn_cpu;$error_cpu;; 'T(cpu2)'=${temperature[2]}°C;$warn_cpu;$error_cpu;; 'T(sys)'=${temperature[3]}°C;$warn_sys;$error_sys;;"
83       lui1) temperature=`ipmitool -H $ipminame -U $user -f $password -L USER sensor get 'Ambient Temp' | grep "Sensor Reading" | cut -d' ' -f 12`          ;;
84    
85            if [ "${debug[0]}" = "debug" ]       lui1|lui2)
86            then          temperature=`ipmitool -H $ipminame -U $user -f $password -L USER \
87                  echo "Temperature of $hostname is ${temperature[0]}"                       sensor get 'Ambient Temp' | \
88            fi                       grep "Sensor Reading" | cut -d' ' -f 12`
89            if [ ${temperature[0]} -gt $error_treshold ]  
90            then          [ $debug -gt 0 ] && echo "Temperature of $hostname is ${temperature[0]}" >&2
91                  echo "CRITICAL - Ambient Temp: ${temperature[0]}°C"          
92                  exit 2          if [ ${temperature[0]} -gt $error_sys ]
93            then
94            elif [ ${temperature[0]} -gt $warn_treshold ]              ret=2
95            then  
96                  echo "WARNING - Ambient Temp: ${temperature[0]}°C"          elif [ ${temperature[0]} -gt $warn_sys ]
97                  exit 1          then
98            fi              ret=1
99                      else
100            echo "OK - Ambient Temp: ${temperature[0]}°C"              ret=0
101            exit 0;;          fi
102            msg="Ambient Temp: ${temperature[0]}°C"
103            perf="'T(sys)'=${temperature[0]}°C;$warn_sys;$error_sys;; "
104       lui2) temperature=`ipmitool -H $ipminame -U $user -f $password -L USER sensor get 'Ambient Temp' | grep "Sensor Reading" | cut -d' ' -f 12`          ;;
105    
106            if [ "${debug[0]}" = "debug" ]       smrt)
107            then          temperature="`expect /usr/local/lib/nagios/plugins/smrt.exp $ipminame`"
108                  echo "Temperature of $hostname is ${temperature[0]}"  
109            fi          temperature[1]=`echo ${temperature[0]} | \
110            if [ ${temperature[0]} -gt $error_treshold ]                          sed -e 's/.*CurrentReading=//g' | sed -e 's/\r.*//g'`
111            then  
112                  echo "CRITICAL - Ambient Temp: ${temperature[0]}°C"          if [ $debug -gt 0 ]
113                  exit 2          then
114                echo "This is the output of expect\n ${temperature[0]}" >&2
115            elif [ ${temperature[0]} -gt $warn_treshold ]              echo "Temperature of $hostname is ${temperature[1]}" >&2
116            then          fi
117                  echo "WARNING - Ambient Temp: ${temperature[0]}°C"  
118                  exit 1          if [ ${temperature[1]} -gt $error_sys ]
119            fi          then
120                ret=2
121            echo "OK - Ambient Temp: ${temperature[0]}°C"  
122            exit 0;;          elif [ ${temperature[1]} -gt $warn_sys ]
123            then
124                ret=1
125       smrt) temperature="`expect /usr/local/lib/nagios/plugins/smrt.exp $ipminame`"  
126            else
127             temperature[1]=`echo ${temperature[0]} | sed -e 's/.*CurrentReading=//g' | sed -e 's/\r.*//g'`              ret=0
128            fi
129             if [ "${debug[0]}" = "debug" ]          msg="Ambient Temp: ${temperature[1]}°C"
130             then          perf="'T(sys)'=${temperature[1]}°C;$warn_sys;$error_sys;; "
131                   echo "This is the output of expect\n ${temperature[0]}"          ;;
132                   echo "Temperature of $hostname is ${temperature[1]}"  
133             fi      tbn)
134             if [ ${temperature[1]} -gt $error_treshold ]          msg="test node"
135             then          ret=0
136                   echo "CRITICAL - Ambient Temp: ${temperature[1]}°C"          ;;
137                   exit 2  
138        *)
139             elif [ ${temperature[1]} -gt $warn_treshold ]          msg="Unkown Server $x"
140             then          ret=3
141                   echo "WARNING - Ambient Temp: ${temperature[1]}°C"          ;;
142                   exit 1  esac
            fi  
143    
            echo "OK - Ambient Temp: ${temperature[1]}°C"  
            exit 0;;  
144    
145       tbn) echo "OK: Working on this"  # output and return
146            exit 0;;  echo "${stat_text[$ret]} - $msg|$perf"
147    exit $ret
148    
        *)  echo "UNKNOWN: Unkown Server"  
            exit 3;;  
 esac  

Legend:
Removed from v.2192  
changed lines
  Added in v.2193

grid.support@nikhef.nl
ViewVC Help
Powered by ViewVC 1.1.28