邮件报警
1 install
rpm -ivh /tmp/msmtp-1.4.6-1.el5.scopserv.i386.rpm
2 config
cd /etc/
vim msmtprc
account default
host smtp.163.com
port 25
from jakback@163.com
tls off
auth login
user jakback@163.com
password 123456
logfile /tmp/msmtp.log
3 mutt 添加
vim /etc/Muttrc
set sendmail="/usr/bin/msmtp"
set from="jakback@163.com" 发信人的邮件地址
set realname="baism" 这个定义的就是你收到邮件后 发信人是谁 发信人的名字
4 mutt+msmtp 测试填写的公网邮箱是否能收到信
echo "hello" | mutt -s "test" jakback@163.com
5 nagios 设置
vim commands.cfg 定义如何报警——报警命令 服务宕机了如何报警 机器宕机了如何报警
#notifu-host-by-host command definition 机器宕机了如何报警
define command{
command_name notify-host-by-sms
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/bin/mutt -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition 服务宕机了如何报警
define command{
command_name notify-service-by-sms
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/bin/mutt -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
vim contacts.cfg 报警给谁
define contact {
contact_name abc
alias abc
host_notification_period 24x7
host_notification_options d,u,r
service_notification_period 24x7
service_notification_options w,u,c,r
service_notification_commands notify-service-by-sms
host_notification_commands notify-host-by-sms
email jakback@163.com
}
设置组 如果多个成员用逗号隔开就行
define contactgroup{
contactgroup_name vfast
alias Nagios Administrators
members abc
}
vim localhost.cfg 定义报警联系人
define host {
host_name instructor.example.com
alias dell_R510
address 192.168.18.248
check_command check-host-alive
notification_options d,u,r
check_interval 1
max_check_attempts 2
contact_groups vfast 定义监控主机的时候 加上这句 报警联系人
notification_interval 10
notification_period 24x7
}
注意:nagios报警中如果出现了监控数据抖动 则默认不报警 做实验的时候关了 在localhost.cfg 定义监控服务的时候将其关了就行 如下例子
define service {
host_name instructor.example.com
service_description DISK_io
check_period 24x7
normal_check_interval 2
retry_check_interval 1
max_check_attempts 2
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_disk_io
flap_detection_enabled 0 #0代表关闭抖动抑制发邮件的设置
}
可以查看nagios.log日志发现是否报警
1 install
rpm -ivh /tmp/msmtp-1.4.6-1.el5.scopserv.i386.rpm
2 config
cd /etc/
vim msmtprc
account default
host smtp.163.com
port 25
from jakback@163.com
tls off
auth login
user jakback@163.com
password 123456
logfile /tmp/msmtp.log
3 mutt 添加
vim /etc/Muttrc
set sendmail="/usr/bin/msmtp"
set from="jakback@163.com" 发信人的邮件地址
set realname="baism" 这个定义的就是你收到邮件后 发信人是谁 发信人的名字
4 mutt+msmtp 测试填写的公网邮箱是否能收到信
echo "hello" | mutt -s "test" jakback@163.com
5 nagios 设置
vim commands.cfg 定义如何报警——报警命令 服务宕机了如何报警 机器宕机了如何报警
#notifu-host-by-host command definition 机器宕机了如何报警
define command{
command_name notify-host-by-sms
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/bin/mutt -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}
# 'notify-service-by-email' command definition 服务宕机了如何报警
define command{
command_name notify-service-by-sms
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/bin/mutt -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}
vim contacts.cfg 报警给谁
define contact {
contact_name abc
alias abc
host_notification_period 24x7
host_notification_options d,u,r
service_notification_period 24x7
service_notification_options w,u,c,r
service_notification_commands notify-service-by-sms
host_notification_commands notify-host-by-sms
email jakback@163.com
}
设置组 如果多个成员用逗号隔开就行
define contactgroup{
contactgroup_name vfast
alias Nagios Administrators
members abc
}
vim localhost.cfg 定义报警联系人
define host {
host_name instructor.example.com
alias dell_R510
address 192.168.18.248
check_command check-host-alive
notification_options d,u,r
check_interval 1
max_check_attempts 2
contact_groups vfast 定义监控主机的时候 加上这句 报警联系人
notification_interval 10
notification_period 24x7
}
注意:nagios报警中如果出现了监控数据抖动 则默认不报警 做实验的时候关了 在localhost.cfg 定义监控服务的时候将其关了就行 如下例子
define service {
host_name instructor.example.com
service_description DISK_io
check_period 24x7
normal_check_interval 2
retry_check_interval 1
max_check_attempts 2
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_disk_io
flap_detection_enabled 0 #0代表关闭抖动抑制发邮件的设置
}
可以查看nagios.log日志发现是否报警
tail -f /usr/local/nagios/var/nagios.log