当前位置:首页 > nagios运用飞信实现短信报警监控服务器
alias maintainhost contacters members ZY }
(3) commands.cfg的编辑
为了支持飞信发短信的功能需要在此文件中添加飞信命令,以促使信息的发送,代码如下: # 'notify-host-by-fei' command definition
define command {
command_name host-notify-by-fei ;
command_line /usr/local/fetion/fetion --mobile=137*** --pwd=*** --to=$CONTACTPAGER$ --msg-utf8=\$HOSTSTATE$ alert for $HOSTNAME$! on '$LONGDATETIME$'\$CONTACTPAGER$ }
# 'notify-service-by-fei' command definition
define command {
command_name service-notify-by-fei
command_line /usr/local/fetion/fetion --mobile=137*** --pwd=*** --to=$CONTACTPAGER$ --msg-utf8=\$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ on $LONGDATETIME$\$CONTACTPAGER$
} (4) 编辑nagios.cfg
为了不监控本机,现把localhost注释掉,找到此行,并且加以注释: # cfg_file=/usr/local/nagios/etc/objects/localhost.cfg 为了使刚才编辑的文件生效,需加入一行:
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg (5) 编辑cgi.cfg
为了保证权限能正常访问nagios的web页面,需把这些行的值改掉: authorized_for_system_information=* authorized_for_configuration_information=* authorized_for_system_commands=nagios authorized_for_all_services=* authorized_for_all_hosts=*
authorized_for_all_service_commands=* authorized_for_all_host_commands=*
*号在此表示所有用户,也可以改成相关用户,不过必须逐一添加。 服务器端的配置基本上大致如此了。
4、启动nagios与apache服务
(1) nagios自启动
[root@localhost objects]# service nagios restart Running configuration check...done.
Stopping nagios: done. Starting nagios: done.
[root@localhost objects]# chkconfig nagios on [root@localhost objects]# chkconfig --list|grep nagios
nagios 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭 (2) apache的启动
[root@localhost ~]# export PATH=$PATH:/usr/local/apache/bin [root@localhost ~]# apachectl -k start
httpd (pid 3108) already running 注:为了让apache可以自启动,可以加入到/etc/rc.local之中。
5、测试与浏览
在启动nagios服务之前,我们可以先测试一下是否配置有没有错误,或者你启动的时候出现错误也可以用下述命令进行测试
[root@localhost ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Nagios 3.1.2
Copyright (c) 2009 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad Last Modified: 06-23-2009 License: GPL
Website: http://www.nagios.org Reading configuration data... Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'... Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'... Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'... Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'... Processing object config file '/usr/local/nagios/etc/objects/hosts.cfg'... Read object config files okay...
Running pre-flight check on configuration data... Checking services...
Checked 9 services. Checking hosts...
Checked 5 hosts. Checking host groups...
Checked 3 host groups. Checking service groups...
Checked 0 service groups. Checking contacts...
Checked 3 contacts. Checking contact groups...
Checked 3 contact groups.
Checking service escalations...
Checked 0 service escalations. Checking service dependencies...
Checked 0 service dependencies. Checking host escalations...
Checked 0 host escalations. Checking host dependencies...
Checked 0 host dependencies. Checking commands...
Checked 26 commands. Checking time periods...
Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies... Checking global event handlers...
Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0
Total Errors: 0 呵呵,没有错误,可能您在配置之前或多或少会出现问题的,根据相关错误提示,逐一排查,相信您定会成功的。
现在我们打开nagios的web页面,输入:http://***.com/nagios样例 先看map页面,大致页面如下
再看hosts相关链接页面:
共分享92篇相关文档