温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

sendmail,mail,fetion,页面声音实现nagios报警

发布时间:2020-07-04 03:57:30 来源:网络 阅读:766 作者:skykws 栏目:移动开发

一,用sendmail发送邮件

1、下载安装sendEmail

wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.56.tar.gz

tar zxvf sendEmail-v1.56.tar.gz

cd sendEmail-v1.56

cp sendEmail /usr/local/bin/

chmod 775 /usr/local/bin/sendEmail

chown nagios:nagios /usr/local/bin/sendEmail        #因为我要让nagios发邮件所以用的是nagios用户

2、测试一下


/usr/local/bin/sendEmail -f skykws@163.com -t 872260085@qq.com -s smtp.163.com -u "邮件标题" -xu skykws -xp 000000 -m "邮件内容"


3、邮件参数:


-f 发送者地址  -t 接收者地址   -s SMTP服务器地址(可以是域名或IP)


-u 邮件主题   -xu SMTP验证用户名


-xp SMTP验证密码(注意,这个密码有限制,有一些特殊符号或者超长度密码不能被正确识别)


-m邮件具体内容  如不带-m参数的话,就会提示你自行输入,输入完成后CTRL-D来结束



Nagios通过sendEmail报警需要修改commands.cfg


#'notify-host-by-email' command definition

define command{

        command_name    notify-host-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -f skykws@163.com -t $CONTACEMAIL$ -s SMTP.163.COM "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -xu skykws -xp 0000000 $CONTACTEMAIL$

}


# 'notify-service-by-email' command definition

define command{

        command_name    notify-service-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress:0$HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/local/bin/sendEmail -f skykws@163.com -t $CONTACEMAIL$ -s SMTP.163.COM"** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu skykws -xp 000000 $CONTACTEMAIL$

}


[root@localhost objects]# vi contacts.cfg

 email                           skykws@163.com  修改添加邮件地址

 pager                                   15800000000  添加这行



(例子:command_line

 /usr/local/bin/sendEmail -f 发送账户 -t $CONTACTEMAIL$ -s smtp服务器地址 -u "** $NOTIFICATIONTYPE$ 主机警报: $HOSTNAME$ is $HOSTSTATE$ **" -m "主机

警报*\n\n通知类型: $NOTIFICATIONTYPE$\n主机: $HOSTNAME$\n状态: $HOSTSTATE$\nip地址: $HOSTADDRESS$\n信息: $HOSTOUTPUT$\n\n北京时间: $LONGDATETIME$\n-by 信息技术部\n" -xu 用户 -xp 密码  -o message-charset=utf-8

 然后是服务报警的command_line

 /usr/local/bin/sendEmail -f 发送账户 -t $CONTACTEMAIL$ -s smtp服务器地址 -u "** $NOTIFICATIONTYPE$ 服务警报: $HOSTNAME$ is $HOSTSTATE$ **" -m "*服>务报警*\n\n警报类型: $NOTIFICATIONTYPE$\n\n服务: $SERVICEDESC$\n主机: $HOSTALIAS$\nip地址: $HOSTADDRESS$\n状态: $SERVICESTATE$\n\n北京时间: $LONGDATETIME$\n\n信息:\n\n$SERVICEOUTPUT$\n-by 信息技术部\n" -xu 用户 -xp 密码  -o message-charset=utf-8)


二,用本地mail发送邮件

[root@localhost]#vi /etc/mail.rc


set from=skykws@163.com smtp=smtp.163.com set smtp-auth-user=skykws smtp-auth-password=000000 smtp-auth=login


[root@localhost]#cd /bin/


[root@localhost]#mail -s "skykws" skykws@163.com <123.txt


Nagios通过mail报警需要修改commands.cfg

# 'notify-host-by-email' command definition

define command{

        command_name    notify-host-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

        }


# 'notify-service-by-email' command definition

define command{

        command_name    notify-service-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

        }

三,fetion

1.安装飞信

[root@localhost ~]#unzip fetion.zip

[root@localhost ~]#mv fx  fetion

[root@localhost ~]#cp -R fetion /usr/local/

[root@localhost ~]#cp libACE-5.7.2.so libcrypto.so.4  libssl.so.4 libACE_ssl-5.7.2.so libeay32.dll /usr/lib/

[root@localhost ~]#chown -R nagios:nagios /usr/local/fetion/fetion

[root@localhost ~]#chmod -R 775 /usr/local/fetion/fetion

[root@localhost ~]#vi /etc/ld.so.conf

添加“/usr/local/fetion/fetion/”

[root@localhost ~]#ldconfig

[root@localhost ~]#cd /usr/local/fetion/fetion

[root@localhost  fx]# ./fetion --mobile=15889971794 --pwd=000000 --to=15889971794 --msg-type=1 --msg-utf8="测试"

2、修改commands.cfg

#"notify-host-by-fetion"

define command{

        command_name    notify-host-by-fetion

        command_line    LD_LIBRARY_PATH=/usr/local/fetion /usr/local/fetion/fetion --mobile=15889971794 --pwd=000000 --to=15889971794 --msg-utf8="HOST$HOSTSTATE$ alert for $HOSTNAME$!on'$LONGDATETIME$'"$CONTACTPAGER$

}

#"notify-service-by-fetion"

define command{

       command_name    notify-service-by-fetion

       command_line   LD_LIBRARY_PATH=/usr/local/fetion /usr/local/fetion/fetion --mobile=15889971794 --pwd=000000 --to=15889971794 --msg-utf8="$HOSTADDRESS$ $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$" $CONTACTRAGER$

}

3、使用飞信报警命令

[root@localhost objects]# vi templates.cfg  //对应添加:notify-service-by-fetion notify-host-by-fetion;

service_notification_commands   notify-service-by-email,notify-service-by-fetion;

  host_notification_commands      notify-host-by-email,notify-host-by-fetion; 

四,nagios的页面声音报警

1. 准备音频文件,后缀要求.wav 

2. 修改配置文件:/usr/local/nagios/etc/cgi.cfg

将原先的注释去掉,修改成如下:

host_unreachable_sound=hostdown.wav
host_down_sound=hostdown.wav
service_critical_sound=critical.wav
service_warning_sound=warning.wav
service_unknown_sound=warning.wav
#normal_sound=noproblem.wav(这是设置正常情况下声音,一般注释)
3. 将音频文件上传的文件夹/usr/local/nagios/share/media/

 

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI