あまりにも暑い日が続くなか、夜は涼しくなるかとエアコンを控えめにすると、暑さで目が覚めることもある。部屋の温度は、温度・湿度センサーで測っているし、google-home-notifier を使って暑さの警告をしゃべらせてみる。単純に温度が設定温度を越えたら…なんてプログラムだと、頻繁に喋られてもうるさいし、icinga から呼び出させてみた。
警告時にプログラムを起動
## /etc/icinga/commands.cfg 追記 ##
# 'notify-host-by-program' command definition
define command{
command_name notify-host-by-program
command_line /etc/icinga/commands-host.sh \
"$HOSTNAME$" "$NOTIFICATIONTYPE$" \
"$HOSTSTATE$" "$HOSTOUTPUT$"
}
# 'notify-service-by-program' command definition
define command{
command_name notify-service-by-program
command_line /etc/icinga/commands-service.sh \
"$HOSTNAME$" "$SERVICESESC$" "$NOTIFICATIONTYPE$" \
"$SERVICESTATE$" "$SERVICEOUTPUT$"
}
## /etc/icinga/objects/contacts_icinga.cfg 追記 ##
define contact{
contact_name notifyProgram
alias NotifyProgram
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,r
service_notification_commands notify-service-by-program
host_notification_commands notify-host-by-program
email foobar@example.com
}
define contactgroup{
contactgroup_name adminsProgram
alias Administrators and Notify Program
members root,notifyProgram
}
温度センサーの設定
## /etc/icinga/objects/localhost_icinga.cfg ##
# USBRH
define service{
use generic-service
host_name localhost
service_description USBRH
check_command check_usbrh2!32!35!81!85
contact_groups adminsProgram
}
## /etc/icinga/commands-service.sh ##
#!/bin/bash
# icinga からプログラムにより警告
# ((commands.cfg を参照))
# /etc/icinga/commands-service.sh
# "$HOSTNAME$" "$SERVICESESC$" "$NOTIFICATIONTYPE$"
# "$SERVICESTATE$" "$SERVICEOUTPUT$"
case "$2-$3" in
USBRH-PROBLEM )
case "$4" in
WARNING | CRITICAL )
if [ "$4" == "CRITICAL" ]; then
MESS="部屋の温度が危険です。"
else
MESS="部屋の温度に注意してください。"
fi
/usr/bin/printf "%s %.1f 度 %.1f %%" "$MESS" \
`温度と湿度を取得するスクリプト` \
| 標準入力をgoogle-home-notifierに送るスクリプト
;;
esac
;;
esac