Révision 17f78427
Whitespace cleanup
- remove trailing whitespace
- remove empty lines at the end of files
| plugins/poseidon/snmp__poseidon-sensors | ||
|---|---|---|
| 29 | 29 |
E_OK="0" # everything went allright |
| 30 | 30 |
E_UNKNOWN="1" # "catch all" for otherwise unhandled errors |
| 31 | 31 |
|
| 32 |
E_ARG="81" # invalid argument
|
|
| 32 |
E_ARG="81" # invalid argument |
|
| 33 | 33 |
E_USAGE="82" # wrong program name or arguments |
| 34 | 34 |
E_SNMPGET="83" # error while executing the 'snmpget' utility |
| 35 | 35 |
|
| ... | ... | |
| 57 | 57 |
SENS_ID_OID=".1.3.6.1.4.1.21796.3.3.99.1.2.1.4." # unique sensor ID (integer) |
| 58 | 58 |
#+ representation of the |
| 59 | 59 |
#+ temperature (integer) |
| 60 |
SENS_UNIT_OID=".1.3.6.1.4.1.21796.3.3.3.1.9." # 0=°C,1=°F,2=°K,3=%,4=V,5=mA,
|
|
| 60 |
SENS_UNIT_OID=".1.3.6.1.4.1.21796.3.3.3.1.9." # 0=°C,1=°F,2=°K,3=%,4=V,5=mA, |
|
| 61 | 61 |
RTS_OUTPUT_OID=".1.3.6.1.4.1.21796.3.3.2.1.2." # binary input state (integer) |
| 62 | 62 |
#+ 6=unknown, 7=pulse, 8=switch |
| 63 | 63 |
|
| 64 | 64 |
# define some Poseidon specific stuff: |
| 65 |
STATE_OK="1"
|
|
| 65 |
STATE_OK="1" |
|
| 66 | 66 |
STATE_WARN="2" |
| 67 | 67 |
STATE_CRIT="3" |
| 68 | 68 |
UNITS=("C" "F" "K" "%" "V" "mA" "unknown" "pulse" "switch")
|
| ... | ... | |
| 100 | 100 |
cat <<- EOT |
| 101 | 101 |
multigraph $sensorType |
| 102 | 102 |
graph_title $sensorLocation - $sensorType [$sensorUnit] |
| 103 |
graph_args --base 1000 -l 0
|
|
| 103 |
graph_args --base 1000 -l 0 |
|
| 104 | 104 |
graph_vlabel $sensorUnit |
| 105 | 105 |
graph_category sensors |
| 106 | 106 |
graph_info This graph shows $sensorType history. |
| 107 | 107 |
EOT |
| 108 | 108 |
fi |
| 109 |
_firstSensor="0"
|
|
| 109 |
_firstSensor="0" |
|
| 110 | 110 |
cat <<- EOT |
| 111 | 111 |
$sensorType$_sensorNr.label $sensorName |
| 112 | 112 |
$sensorType$_sensorNr.info This graph shows $sensorType$_sensorNr history. |
| ... | ... | |
| 158 | 158 |
|
| 159 | 159 |
# getSensorData(sensorNr) |
| 160 | 160 |
# fetch state, value, name unit and sensor type for the sensor |
| 161 |
#+ with the number "sensorNr"
|
|
| 161 |
#+ with the number "sensorNr" |
|
| 162 | 162 |
getSensorData() {
|
| 163 | 163 |
_sensorNr=$1 |
| 164 | 164 |
sensorState=`snmpGet $hostAddr $SENS_STATE_OID$_sensorNr || err \ |
| ... | ... | |
| 172 | 172 |
} |
| 173 | 173 |
|
| 174 | 174 |
# getSystemInfo() |
| 175 |
# fetch general information about the system
|
|
| 175 |
# fetch general information about the system |
|
| 176 | 176 |
getSystemInfo() {
|
| 177 | 177 |
sensorLocation="`snmpGet $hostAddr $SYS_LOC_OID`" |
| 178 | 178 |
} |
| ... | ... | |
| 185 | 185 |
_host="$1" |
| 186 | 186 |
_exit="0" |
| 187 | 187 |
|
| 188 |
# fetch the requested OID
|
|
| 188 |
# fetch the requested OID |
|
| 189 | 189 |
_longValue="`snmpget -O v\ |
| 190 | 190 |
-m $MIBS\ |
| 191 | 191 |
-v $SNMPVERSION\ |
| 192 | 192 |
-c $SNMPCOMMUNITY\ |
| 193 | 193 |
$_host $_oid 2>/dev/null`" |
| 194 |
|
|
| 194 |
|
|
| 195 | 195 |
_exitStatus="$?" |
| 196 | 196 |
|
| 197 | 197 |
echo ${_longValue#*:} # remove the type from the answer
|
| 198 | 198 |
return $_exitStatus |
| 199 |
}
|
|
| 199 |
} |
|
| 200 | 200 |
|
| 201 | 201 |
# get unit (string) |
| 202 |
#+ find out the unit of the output of a given sensor. possible units are:
|
|
| 203 |
#+ "C" "F" "K" "%" "V" "mA" "unknown" "pulse" "switch"
|
|
| 202 |
#+ find out the unit of the output of a given sensor. possible units are: |
|
| 203 |
#+ "C" "F" "K" "%" "V" "mA" "unknown" "pulse" "switch" |
|
| 204 | 204 |
getSensorUnitString () {
|
| 205 | 205 |
_sensorNr=$1 |
| 206 | 206 |
_sensorUnit=`snmpGet $hostAddr $SENS_UNIT_OID$_sensorNr || err \ |
| ... | ... | |
| 209 | 209 |
} |
| 210 | 210 |
|
| 211 | 211 |
# get type (string) |
| 212 |
#+ find out what type of sensor we are dealing with. possible types are:
|
|
| 212 |
#+ find out what type of sensor we are dealing with. possible types are: |
|
| 213 | 213 |
#+ "Temp" "Hum" "Volt" "Curr" "Unkn" "Pulse" "Switch" |
| 214 | 214 |
getSensorType () {
|
| 215 | 215 |
_sensorNr=$1 |
| ... | ... | |
| 223 | 223 |
#+ in the array for the respective unit |
| 224 | 224 |
getAvailableSensorsByType () {
|
| 225 | 225 |
_thisSensorNr="1" |
| 226 |
|
|
| 226 |
|
|
| 227 | 227 |
# initial fetch |
| 228 | 228 |
_snmpget=`snmpGet $hostAddr $SENS_UNIT_OID$_thisSensorNr` |
| 229 | 229 |
_nextSensorExits=$? |
| 230 | 230 |
_unit=`echo "$_snmpget" | tr -d " "` |
| 231 | 231 |
|
| 232 |
# add next sensor if it exists
|
|
| 233 |
while [ true ]; do
|
|
| 232 |
# add next sensor if it exists |
|
| 233 |
while [ true ]; do |
|
| 234 | 234 |
# add sensors of the same type to a list |
| 235 |
sensorsOfType[$_unit]="${sensorsOfType[$_unit]} $_thisSensorNr"
|
|
| 236 |
|
|
| 235 |
sensorsOfType[$_unit]="${sensorsOfType[$_unit]} $_thisSensorNr"
|
|
| 236 |
|
|
| 237 | 237 |
# fetch next sensor |
| 238 |
_thisSensorNr=$(($_thisSensorNr+1))
|
|
| 238 |
_thisSensorNr=$(($_thisSensorNr+1)) |
|
| 239 | 239 |
_snmpget=`snmpGet $hostAddr $SENS_UNIT_OID$_thisSensorNr` |
| 240 | 240 |
_nextSensorExits=$? |
| 241 | 241 |
|
| ... | ... | |
| 243 | 243 |
if [ $_nextSensorExits -ne 0 ]; then |
| 244 | 244 |
break |
| 245 | 245 |
fi |
| 246 |
|
|
| 246 |
|
|
| 247 | 247 |
_unit=`echo "$_snmpget" |cut -d" " -f 4` |
| 248 | 248 |
done |
| 249 | 249 |
} |
| ... | ... | |
| 264 | 264 |
} |
| 265 | 265 |
|
| 266 | 266 |
# usage () |
| 267 |
# print usage
|
|
| 267 |
# print usage |
|
| 268 | 268 |
usage () {
|
| 269 | 269 |
echo "usage: snmp_<host>_poseidon-sensors [config|snmpconf]" 1>&2 |
| 270 | 270 |
exit $E_USAGE |
| ... | ... | |
| 279 | 279 |
else |
| 280 | 280 |
_errorMsg="Fatal: An unknown error occurred! Exiting..." |
| 281 | 281 |
_exitCode="$E_UNKNOWN" |
| 282 |
|
|
| 282 |
|
|
| 283 | 283 |
fi |
| 284 | 284 |
|
| 285 | 285 |
# print error message to STDERR ... |
| ... | ... | |
| 291 | 291 |
#==============================================================================# |
| 292 | 292 |
|
| 293 | 293 |
# SNMP Config |
| 294 |
MIBS=":" # we don't use any configured MIBs so we don't
|
|
| 294 |
MIBS=":" # we don't use any configured MIBs so we don't |
|
| 295 | 295 |
#+ have to deal with errors in the MIBs |
| 296 |
if [ -z $SNMPVERSION ]; then
|
|
| 296 |
if [ -z $SNMPVERSION ]; then |
|
| 297 | 297 |
SNMPVERSION="1" # as of firmware 3.1.5 only SNMPv1 is supported |
| 298 | 298 |
fi |
| 299 | 299 |
|
| 300 |
if [ -z $SNMPCOMMUNITY ]; then
|
|
| 300 |
if [ -z $SNMPCOMMUNITY ]; then |
|
| 301 | 301 |
SNMPCOMMUNITY="public" # SNMP community string to read from the device |
| 302 | 302 |
fi |
| 303 | 303 |
|
| ... | ... | |
| 326 | 326 |
if [ "$myName" = "snmp_poseidon-sensors" ]; then |
| 327 | 327 |
hostAddr=`sanitize $hostAddr || err \ |
| 328 | 328 |
"Fatal: Invalid argument \"$hostAddr\"! Exiting..." $E_ARG` |
| 329 |
if [ -z "$hostAddr" ]; then
|
|
| 329 |
if [ -z "$hostAddr" ]; then |
|
| 330 | 330 |
usage munin |
| 331 | 331 |
fi |
| 332 | 332 |
getAvailableSensorsByType |
| 333 |
if [ "$1" = "config" ]; then
|
|
| 333 |
if [ "$1" = "config" ]; then |
|
| 334 | 334 |
printMuninConfig |
| 335 | 335 |
exit $E_OK |
| 336 | 336 |
elif [ "$1" = "snmpconfig" ]; then |
Formats disponibles : Unified diff