[Nagios] 邮件告警
1、server端安装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
# mv sendEmail /usr/local/bin/
# chmod 755 /usr/local/bin/sendEmail
# chown nagios.nagios /usr/local/bin/sendEmail
For Example: |
/usr/local/bin/sendEmail -f [email protected] -t [email protected] \ |
/usr/local/bin/sendEmail
命令主程序 - t [email protected] 收件人邮箱,多个以逗号相连 -s smtp.163.com
发件人邮箱的smtp服务器
|
2、配置email
# cd /usr/local/nagios/etc/objects
# vi commands.cfg
define command { command_name notify-host-by-email command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type:$NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOST STATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/local/bin/sendEmail -f [email protected] -t $CONTACTEMAIL$ -s smtp.qq.com -u " ** $HOSTNAME$ is $HOSTSTATE$ **" -xu [email protected] -xp 'password' }
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" | /usr/local/bin/sendEmail -f 60259 [email protected] -t $CONTACTEMAIL$ -s smtp.qq.com -u "** $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -xu [email protected] -xp 'password' }
|
# vi contacts.cfg
define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user
email [email protected] ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** host_notification_commands notify-host-by-email service_notification_commands notify-service-by-email }
define contactgroup{ contactgroup_name admins alias Nagios Administrators members nagiosadmin }
|
3、配置哪些主机发送邮件
# vi linux.cfg
define host{ use linux-server ; Name of host template to use host_name zabbix_server alias zabbix_server address 192.168.1.201 contact_groups +admins ;发送至admins组 } |
4、重启
# service nagios restart
5、测试