[syslog-ng]Sensord (lm_sensors) and Syslog-ng using "program()"
Ann Hopkins
syslog-ng@lists.balabit.hu
Thu, 22 Jul 2004 16:33:17 -0700
I was wondering if anyone sees any problem with what I am doing with the
following script. I want an "Alarm" which causes an "Alert" message to
actually shutdown the machine under certain circumstances, since I run a
family server and I don't have a backup.
1) "sensord" (lm_sensors library) is running and I can do "sensors"
command to get a result.
via686a-isa-6000
Adapter: ISA adapter
Algorithm: ISA algorithm
CPU core: +1.73 V (min = +1.68 V, max = +2.49 V)
+2.5V: +2.59 V (min = +2.24 V, max = +2.74 V)
I/O: +3.40 V (min = +2.95 V, max = +3.62 V)
+5V: +4.87 V (min = +4.47 V, max = +5.49 V)
+12V: +11.74 V (min = +10.79 V, max = +13.18 V)
CPU Fan: 0 RPM (min = 3000 RPM, div = 2)
P/S Fan: 0 RPM (min = 3000 RPM, div = 2)
SYS Temp: +30.0°C (high = +45°C, hyst = +40°C)
CPU Temp: +38.5°C (high = +60°C, hyst = +55°C)
SBr Temp: +25.1°C (high = +65°C, hyst = +60°C)
2) "syslog-ng" is working and logging the data under 'local5". The
following is the pertinent "syslog-ng.conf" data. All the data is
logged and the "Alert" data triggers input to a shell program.
filter f_local5 { facility(local5); };
filter f_sensorA { level(alert) and facility(local5); };
destination sensord { file("/var/log/local5.log"); };
log { source(src); filter(f_local5); destination(sensord); };
# Sensor Alarm Messages - Programs are loaded once (email)
destination sensor_alarm { program("/usr/local/sbin/sensor_alarm.sh"); };
log { source(src); filter(f_sensorA); destination(sensor_alarm); };
3) Program "sensor_alarm.sh" will try to shutdown the machine if it
reaches a too hot condition. I don't have fan sensors so it will never
trigger. I am no programmer, please excuse my very primitive (and
naive) coding.
Is there anything wrong with calling this program?
SENSOR_ALARM.SH
#!/bin/sh
# Make sensord do something useful with syslog-ng
# -k does nothing will use a -h halt later
# +2 in 2 minutes
while read line; do
echo $line | /usr/bin/mail -s "SENSORD Alarm" root@localhost
AlarmName=""
AlarmName=`echo $line | /usr/bin/awk -F":" '{ print $1 }'`
case "$AlarmName" in
"CPU core")
/sbin/shutdown -k +2 "CPU core ALARM - bad voltage"
;;
"SYS Temp")
/sbin/shutdown -k +2 "SYS Temp ALARM - too hot"
;;
"CPU Temp")
/sbin/shutdown -k +2 "CPU Temp ALARM - too hot"
;;
"CPU Fan")
/sbin/shutdown -k +2 "CPU Fan ALARM - fan down"
;;
"P/S Fan")
/sbin/shutdown -k +2 "P/S Fan ALARM - fan down"
;;
*)
echo "WARNING SENSORD - Be Careful!" | /usr/bin/wall
;;
esac
done