nagios notification by audio

nagios發現錯誤時要如何發出聲音的警告管理人員

在nagios初裝完成時,預設是用發送mail通知信來提出警告訊息。但是我們並不非時時刻刻都一直盯著是不是有新郵件進來,這時如果能利用警報聲響來通知有狀況發生可能會比較理想一些。

nagios 當然也有提出方案如下

If you want to try out a non-traditional method of notification, you might want to mess around with audio alerts. If you want to have audio alerts played on the monitoring server (with synthesized speech), check out Festival. If you’d rather leave the monitoring box alone and have audio alerts played on another box, check out the Network Audio System (NAS) and rplay projects.

festival 可以將文字轉為演說聲音的工具

安裝

#apt-get install festival

如何使用
echo文字

#echo "I am here." | festival --tts

cat文字檔

#cat speech_file | festival --tts"

cat由標準輸入,輸入完成按ctrl+D結束

#cat - | festival --tts

nas or network audio system

我們可以用nas透過網路在network audio server上來播放我們想要的音樂檔或是聲音檔案

安裝

#apt-get install nas

如何使用
啟用audio server 並開放所有client的連線

#nasd -aa &

預設開啟的port是8000,如果我們沒有指定的話。要指定port的話,可加上「:listen port offset」 例如:

#nasd :0 -aa &
#nasd :1 -aa &
#nasd :2 -aa &

檢查連線

netstate -tl | grep nasd

clietn端操作

auplay -audioserver server-ip:0 local_audio_file

audio server 是可以開很多通道的只要加上listen port 的偏移量,client端也可以在不同的通道上要求播放聲音。如果有要求同時並連上同一通道上的話,聲音會一起出現。但是如果同時請求,但是不在相同的通道上的話,這就有點像是排隊一樣。

新增notification for audio

#vim /usr/local/etc/nagios/objects/command.cfg

add audio notify command define

# 'notify-host-by-festival' command definition
define command{
        command_name    notify-host-by-festival
        command_line    /usr/local/libexec/nagios/notify_by_festival.sh " $HOSTNAME$ is $HOSTSTATE$ "
        }

# 'notify-service-by-festival' command definition
define command{
        command_name    notify-service-by-festival
        command_line    /usr/local/libexec/nagios/notify_by_festival.sh " $SERVICEDESC$ was $SERVICESTATE$ on $HOSTALIAS$ "
        }

add shell script for command define

#vim /usr/local/libexec/nagios/notify_by_festival.sh

audio notify shell script

#!/usr/local/bin/bash
log=/usr/local/libexec/nagios/log.txt
echo "" > $log
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/root/bin
message=$@
echo $(date) >> $log
echo it is $(whoami) running the script >> $log
echo $message >> $log
for ((i=0;i<4;i++)); do sudo ssh root@192.168.0.189 "echo $message | festival --tts" done echo "ssh run state : $?" >> $log
#chmod a+x /usr/local/libexec/nagios/notify_by_festival.sh

modify nagios’s account to join wheel group

#pw usermod -G nagios,wheel nagios

edit sudoers to allow wheel group sudo nopassword

#visudo
# uncomment the line
%wheel  ALL=(ALL) NOPASSWD: ALL
#reboot

ssh login without password

Because we use remote festival by ssh , so we must to login remote server with out password.
we can find it from google.

add contact define

#vim /usr/local/etc/nagios/objects/contacts.cfg
#add this define
define contact{
        contact_name                    nagiosadmin1
        use                             generic-contact
        alias                           Nagios Admin1
        service_notification_commands   notify-service-by-festival
        host_notification_commands      notify-host-by-festival
        }
#modify contactgroup
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin,nagiosadmin1
        }
/usr/local/etc/rc.d/nagios reload

Howto test

we can test the notify by send a custom notification on web gui .
if everythings is ok, then we can listen a notification by festival .

發表迴響

在下方填入你的資料或按右方圖示以社群網站登入:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 變更 )

Twitter picture

You are commenting using your Twitter account. Log Out / 變更 )

Facebook照片

You are commenting using your Facebook account. Log Out / 變更 )

Google+ photo

You are commenting using your Google+ account. Log Out / 變更 )

連結到 %s