免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12下一页
最近访问板块 发新帖
查看: 7832 | 回复: 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

论坛徽章:
0
2 [报告]
发表于 2011-09-17 08:12 |只看该作者
到底是哪儿错了,才会造成这样的问题,
已经查了很多变了,而且现在只剩下一个用户,一台机器,一个服务的监控,故障依旧!

希望各位大虾指点一下!

论坛徽章:
0
3 [报告]
发表于 2011-09-17 08:15 |只看该作者
在监控系统的 Notifications 中确实也没有找到记录

有一个奇怪的事情
  通过 Send custom service notification 却可以正确的获取到相应的警告信息

论坛徽章:
0
4 [报告]
发表于 2011-09-17 10:59 |只看该作者
通过 Send custom service notification 却可以正确的获取到相应的警告信息,不知道你说的这句话是什么意思,如果说你Send custom service notification 能够收到邮件的话,那你的邮件配置是没有问题的。
如果定制消息可以收到,系统不能自动发送消息的原因就是commands.cfg和ssh.cfg里的max_check_attempts              999,最大尝试次数太大了,只有检查999次,如果故障仍然没有恢复才会给你发短信,天啊,3*999分钟,你要连续等50个小时啊,你改成max_check_attempts              1再试一下。

论坛徽章:
0
5 [报告]
发表于 2011-09-17 18:13 |只看该作者
本帖最后由 badeager 于 2011-09-17 18:16 编辑

现在的问题是,我想测试一下发送邮件,但是获取到的发送信息中,竟然没有邮件地址,
主要是这个意思,


我可以正确的收到警告信息,通过自己编写的/bin/mail脚本,正常应该可以获取到相应的$CONTACTEMAIL$相应的电子邮件地址 ,可是现在却没有得到,只得到了一个$

至于我手动去执行  Send custom service notification  却可以得到准确的信息,获取到了准确的$CONTACTEMAIL$地址信息,  

我想知道这是为什么? 怎么会造成这样的原因是什么?

多谢了!

论坛徽章:
0
6 [报告]
发表于 2011-09-18 09:59 |只看该作者
不知道你自己写的mail脚本是通过什么方式执行的,如果是在commmands.cfg里调用我觉得是应该没有问题的,你说的“正常应该可以获取到相应的$CONTACTEMAIL$相应的电子邮件地址 ,可是现在却没有得到,只得到了一个$”,显然是你的shell脚本将$CONTACTEMAIL$分成两部分读取了,第一段$CONTACTEMAIL,因为CONTACTEMAIL这个变量你是没有赋值的,所以$CONTACTEMAIL为空,然后再取第二段$,所以你最后取到的只有$。原因是$CONTACTEMAIL$这个特殊格式的变量只有nagios的检测服务里调用才会取到你contact.cfg 里定义的email或pager。所以不要自己写脚本了,用commands.cfg里的send-by-email直接去测试。

论坛徽章:
0
7 [报告]
发表于 2011-09-18 15:07 |只看该作者
mail的脚本,主要是为了收集信息调试用的
脚本很简单,采用php写的

  1. #!/usr/bin/php -q
  2. <?php
  3. // 获取格式 邮件地址 , 邮件主题,邮件正文
  4. $mailto  = $argv[1];
  5. $subject = $argv[2];
  6. $content = $argv[3];

  7. $context = sprintf("%s : %s | %s | %s \n",date("Y-m-d H:i:s"),$mailto,$subject,$content);
  8. $fd = fopen("/tmp/mail.log","a+");
  9. fputs($fd,$context);
  10. fclose($fd);
  11. ?>
复制代码
看上去好像是$CONTACTEMAIL$没有体现出来,

论坛徽章:
0
8 [报告]
发表于 2011-09-18 15:09 |只看该作者
而这 些  $变量$  应该是nagios 自己会赋值进去的, 可是我却发现 有些值是空置, 而这些内容我都已经赋值了
比如这个contact 中的email, 都是明确写清楚地,pager等等,后来测试了定制变量 好像也没有啥用,都一样。

论坛徽章:
0
9 [报告]
发表于 2011-09-18 15:50 |只看该作者
这些信息不需要你去收集吧,nagios服务运行的时候都获取到了,一句话,就是没有必要去写发送邮件的脚本。玩nagios更多关注的是监控脚本的编写。

论坛徽章:
0
10 [报告]
发表于 2011-09-18 15:53 |只看该作者
呵呵,对,终于知道专用名词了,Macros, 可是这里面出问题了,就是无法获取到CONTACTEMAIL,CONTACTPAGER的量,正常应该是系统直接读取配置好的就可以了,现在看来就是没有,同是一个奇怪的问题也出来了,
$NOTIFICATIONTYPE$这个变量竟然也没有,是不是很奇怪?
而这个量是系统自己生成的,

这种情况不知道哪里出了问题?
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP