免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7841 | 回复: 19
打印 上一主题 下一主题

nagios contact信息无法在command_line中体现出来 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2011-09-17 07:54 |只看该作者 |正序浏览
本帖最后由 badeager 于 2011-09-17 08:01 编辑

各位大侠,请指教!
  
   折腾了好几天了, 邮件无法发送,

   后来创建了一个/bin/mail程序调试之后,才发现,竟然是contact的$CONTACTEMAIL$这个变量并没有吧用户的信息替换上去,只显示了$
   后来测试了短信的,同样的问题

认为制造了一些故障后
报警信息中 $CONTACTEMAIL$  $CONTACTPAGER$ 都是$ , 但是在contacts.cfg中,都是确实填写好的

EMAIL

  1. 2011-09-17 07:14:09 : $ | **  Service Alert: LN CLUSTER 92 node/check ssh service is CRITICAL ** | ***** Nagios ***** -- Notification Type:  -- Service: check ssh service -- Host: LN CLUSTER 92 node -- Address: 172.21.92.23 -- State: CRITICAL - Date/Time: Sat Sept 17 07:14:09 CST 2011 -- Additional Info: -- Connection refused
  2. 2011-09-17 07:17:29 : $ | **  Service Alert: LN CLUSTER 92 node/check ssh service is CRITICAL ** | ***** Nagios ***** -- Notification Type:  -- Service: check ssh service -- Host: LN CLUSTER 92 node -- Address: 172.21.92.233 -- State: CRITICAL - Date/Time: Sat Sept 17 07:17:29 CST 2011 -- Additional Info: -- CRITICAL - Socket timeout after 10 seconds
  3. 2011-09-17 07:18:09 : $ | **  Host Alert: ln1 is DOWN ** | ***** Nagios ***** -- Notification Type:  - Host: ln1 - State: DOWN - Address: 172.21.92.233 - Info: (Host Check Timed Out) -- Date/Time: Sat Sept 17 07:18:09 CST 2011
  4. 2011-09-17 07:18:23 : $ | **  Host Alert: ln1 is UP ** | ***** Nagios ***** -- Notification Type:  - Host: ln1 - State: UP - Address: 172.21.92.23 - Info: PING OK - Packet loss = 0%, RTA = 0.16 ms -- Date/Time: Sat Sept 17 07:18:23 CST 2011
  5. 2011-09-17 07:18:33 : $ | **  Service Alert: LN CLUSTER 92 node/check ssh service is OK ** | ***** Nagios ***** -- Notification Type:  -- Service: check ssh service -- Host: LN CLUSTER 92 node -- Address: 172.21.92.23 -- State: OK - Date/Time: Sat Sept 17 07:18:33 CST 2011 -- Additional Info: -- SSH OK - OpenSSH_3.9p1 (protocol 1.99)
  6. 2011-09-17 07:20:29 :$ | **  Service Alert: LN CLUSTER 92 node/check ssh service is CRITICAL ** | ***** Nagios ***** -- Notification Type:  -- Service: check ssh service -- Host: LN CLUSTER 92 node -- Address: 172.21.92.23 -- State: CRITICAL - Date/Time: Sat Sept 17 07:20:29 CST 2011 -- Additional Info: -- Connection refused
  7. 2011-09-17 07:23:29 :$ | **  Service Alert: LN CLUSTER 92 node/check ssh service is CRITICAL ** | ***** Nagios ***** -- Notification Type:  -- Service: check ssh service -- Host: LN CLUSTER 92 node -- Address: 172.21.92.23 -- State: CRITICAL - Date/Time: Sat Sept 17 07:23:29 CST 2011 -- Additional Info: -- Connection refused
  8. 2011-09-17 07:26:29 : $ | **  Service Alert: LN CLUSTER 92 node/check ssh service is CRITICAL ** | ***** Nagios ***** -- Notification Type:  -- Service: check ssh service -- Host: LN CLUSTER 92 node -- Address: 172.21.92.23 -- State: CRITICAL - Date/Time: Sat Sept 17 07:26:29 CST 2011 -- Additional Info: -- Connection refused
  9. 2011-09-17 07:29:29 : $ | **  Service Alert: LN CLUSTER 92 node/check ssh service is CRITICAL ** | ***** Nagios ***** -- Notification Type:  -- Service: check ssh service -- Host: LN CLUSTER 92 node -- Address: 172.21.92.23 -- State: CRITICAL - Date/Time: Sat Sept 17 07:29:29 CST 2011 -- Additional Info: -- Connection refused
复制代码
短信信息

  1. Sat Sep 17 07:40:58 CST 2011:$ Service  LN CLUSTER 92 node/check ssh service is OK ! on '$'
复制代码

  1. define contact {
  2.         contact_name                            nagiosadmin
  3.         alias                                   Nagios Admin
  4.         host_notifications_enabled              1
  5.         service_notifications_enabled           1
  6.         host_notification_period                24x7
  7.         service_notification_period             24x7
  8.         host_notification_options               d,r,f,s,n
  9.         service_notification_options            w,c,f
  10.         email                                   nagios@localhost
  11.         pager                                   11111111111
  12.         use                                     generic-contact
  13.         }

复制代码
contacts.cfg

  1. define contactgroup {
  2.         contactgroup_name                       admins
  3.         alias                                        Nagios Administrators
  4.         members                                 nagiosadmin
  5.         }
复制代码
contactgroup.cfg

  1. ......
  2. define command {
  3.        command_name                             notify-host-by-email
  4.        command_line                            /bin/mail "$CONTACTEMAIL$" "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"   "***** Nagios *****   -- Notification Type: $NOTIFICATIONTYPE$ - Host: $HOSTNAME$ - State: $HOSTSTATE$ - Address: $HOSTADDRESS$ - Info: $HOSTOUTPUT$ -- Date/Time: $LONGDATETIME$"
  5. }

  6. define command {
  7.        command_name                             notify-host-by-sms
  8.        command_line                             /opt/sms/sms.sh $CONTACTPAGER$  "Host $HOSTSTATE$ alert for $HOSTNAME$! on '$DATETIME$'"
  9. }

  10. define command {
  11.        command_name                             notify-service-by-email
  12.        command_line                              /bin/mail "$CONTACTEMAIL$"  "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **"  "***** Nagios ***** -- Notification Type: $NOTIFICATIONTYPE$ -- Service: $SERVICEDESC$ -- Host: $HOSTALIAS$ -- Address: $HOSTADDRESS$ -- State: $SERVICESTATE$ - Date/Time: $LONGDATETIME$ -- Additional Info: -- $SERVICEOUTPUT$"
  13. }

  14. define command {
  15.        command_name                             notify-service-by-sms
  16.        command_line                               /opt/sms/sms.sh $CONTACTPAGER$  "Service  $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ ! on '$DATETIME$'"
  17. }

  18. define command {
  19.        command_name                             nrpe_check_users
  20.        command_line                             $USER1$/check_nrpe -H $HOSTADDRESS$ -c check_users
  21. }

  22. .....
复制代码
commands.cfg

  1. define service {
  2.         host_name                       ln1
  3.         service_description             check ssh service
  4.         use                             generic-service
  5.         check_command                   check_ssh
  6.         initial_state                   u
  7.         max_check_attempts              999
  8.         check_interval                  3
  9.         retry_interval                  3
  10.         check_period                    24x7
  11.         event_handler                   notify-service-by-sms
  12.         flap_detection_enabled          1
  13.         flap_detection_options          o
  14.         notification_interval           120
  15.         notification_period             24x7
  16.         notification_options            w,c
  17.         notifications_enabled           1
  18.         contact_groups                  admins
  19.         icon_image                      ssh_icon.png
  20.         register                        1
  21.         }

复制代码
services/ssh.cfg

  1. define host {
  2.         host_name                       ln1
  3.         alias                               LN CLUSTER 92 node
  4.         address                         172.21.92.23
  5.         check_command                   check-host-alive
  6.         initial_state                   u
  7.         max_check_attempts              999
  8.         check_period                    24x7
  9.         event_handler                   notify-host-by-email
  10.         contact_groups                  admins
  11.         notifications_enabled           1
  12.         notification_interval           120
  13.         notification_period             24x7
  14.         icon_image                      rack_linux.png
  15.         statusmap_image                 rack_linux.png
  16.         register                        1
  17.         }
复制代码
hosts/ln1.cfg

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
20 [报告]
发表于 2011-09-20 12:09 |只看该作者
回复 19# badeager


   

论坛徽章:
0
19 [报告]
发表于 2011-09-20 11:04 |只看该作者
回复  badeager


    顺序不对吧,正常的应该是echo mail_body |mail -s "subject"
你哪个直接mail  ...
expert1 发表于 2011-09-19 11:31



   呵呵,多谢版主提醒, 不过,现在的/bin/mail不是系统的/bin/mail,是我自己写的,主要适用于调试,所以格式是我定的,并非通用的格式,

论坛徽章:
0
18 [报告]
发表于 2011-09-20 11:02 |只看该作者
命令颠倒了吧,应该是
define command{
        command_name    notify-service-by-email
        comm ...
Linux@初学者 发表于 2011-09-19 16:58



    这个源于mail命令的获取方式,应该是没有关系的。

论坛徽章:
0
17 [报告]
发表于 2011-09-20 09:56 |只看该作者
今天,我查看了一下,又重新编写了所有服务的配置文件,还是按照老路子走,竟然发现奇迹出现了,mail的log文件中出现了邮件地址,经过查看后,发现有邮件的都是指定需要通知的,没有邮件的不需要通知的。

这样问题就在这儿,不需要通知的,你notify啥啊,为什么会这样的?

论坛徽章:
0
16 [报告]
发表于 2011-09-19 16:58 |只看该作者
命令颠倒了吧,应该是
define command{
        command_name    notify-service-by-email
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\
nHost: $HOSTNAME$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$
\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTNAME$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }

论坛徽章:
16
IT运维版块每日发帖之星
日期:2015-08-24 06:20:00综合交流区版块每日发帖之星
日期:2015-10-14 06:20:00IT运维版块每日发帖之星
日期:2015-10-25 06:20:00IT运维版块每日发帖之星
日期:2015-11-06 06:20:00IT运维版块每日发帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT运维版块每日发帖之星
日期:2016-04-15 06:20:00IT运维版块每日发帖之星
日期:2016-05-21 06:20:00综合交流区版块每日发帖之星
日期:2016-08-16 06:20:002015七夕节徽章
日期:2015-08-21 11:06:17IT运维版块每日发帖之星
日期:2015-08-14 06:20:00
15 [报告]
发表于 2011-09-19 11:31 |只看该作者
回复 14# badeager


    顺序不对吧,正常的应该是echo mail_body |mail -s "subject" xxx@xxx.com
你哪个直接mail somebody@domain.com 然后是正文什么的,发的出去吗?

这个可以自己改,遵守nagios的宏命令即可。

论坛徽章:
0
14 [报告]
发表于 2011-09-19 09:22 |只看该作者
本帖最后由 badeager 于 2011-09-19 09:24 编辑

我用哪个/bin/mail来获取报警信息,发现里面竟然就发现没有这个变量,但是这个又不像其它两个变量一样变成 $,而是啥都没有,为空,

  1. 2011-09-19 09:17:51 : $ | **  Service Alert: IBM GATEWAY 1/MET-9KM-20-48 stat is UNKNOWN ** | Notification Type:  -- Service: MET-9KM-20-48 stat -- Host: IBM GATEWAY 1 -- Address: 172.21.17.10 -- State: UNKNOWN -- Date/Time: Mon Sept 19 09:17:51 CST 2011 -- Additional Info: CHECK_NRPE: Socket timeout after 10 seconds.
  2. 2011-09-19 09:18:19 : $ | **  Service Alert: RADWARE LP200/netstatus is WARNING ** | Notification Type:  -- Service: netstatus -- Host: RADWARE LP200 -- Address: 10.0.0.2 -- State: WARNING -- Date/Time: Mon Sept 19 09:18:19 CST 2011 -- Additional Info: PING WARNING - DUPLICATES FOUND! Packet loss = 0%, RTA = 1.91 ms
  3. 2011-09-19 09:19:19 : $ | **  Service Alert: RADWARE LP200/netstatus is WARNING ** | Notification Type:  -- Service: netstatus -- Host: RADWARE LP200 -- Address: 10.0.0.2 -- State: WARNING -- Date/Time: Mon Sept 19 09:19:19 CST 2011 -- Additional Info: PING WARNING - DUPLICATES FOUND! Packet loss = 0%, RTA = 1.33 ms
复制代码
邮件发送命令

  1. define command {
  2.        command_name notify-service-by-email
  3.        command_line /bin/mail $CONTACTEMAIL$ "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" "Notification Type:
  4. $NOTIFICATIONTYPE$ -- Service: $SERVICEDESC$ -- Host: $HOSTALIAS$ -- Address: $HOSTADDRESS$ -- State: $SERVICESTATE$ -- Date/Time: $LONGDATETIME$ --
  5. Additional Info: $SERVICEOUTPUT$"
  6. }
复制代码
所以原本应该是
2011-09-19 09:19:19 : xxx@xxx.com | ** PROBLEM  Service Alert: RADWARE LP200/netstatus is WARNING ** | Notification Type:  -- Service: netstatus -- Host: RADWARE LP200 -- Address: 10.0.0.2 -- State: WARNING -- Date/Time: Mon Sept 19 09:19:19 CST 2011 -- Additional Info: PING WARNING - .....  
这里面标注红色的,就是现在的故障所在,前面应该出现Email地址的地方,现在变成了$ ,后面应该有PROBLEM的地方,现在空,没有东西了

论坛徽章:
0
13 [报告]
发表于 2011-09-18 16:00 |只看该作者
$NOTIFICATIONTYPE$这个变量竟然也没有,是不是很奇怪?
能说得更详细点吗

论坛徽章:
0
12 [报告]
发表于 2011-09-18 15:57 |只看该作者
$NOTIFICATIONTYPE$ 你说的是在哪里没有?
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP