Nagios :扩展提示信息发送方式(smtp, msn, fetion)

运维 系统运维
Nagios使用监控系统和网络时,可以通过许多方法进行信息发送!

Nagios :扩展提示信息发送方式有这些:smtp, msn, fetion。

  1. 使用 SMTP 发送邮件

  objects/commands.cfg 中有邮件提醒命令的设置

  如要通过 SMTP 发送邮件,可以使用 sendEmail:

  http://caspian.dotconf.net/menu/Software/SendEmail/

  安装

  wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.55.tar.gz

  tar zxvf sendEmail-v1.55.tar.gz

  mv sendEmail-v1.55/sendEmail /usr/local/bin/

  发送邮件的示例:

  sendEmail -f nagios@test.com -t admin@test.com -s smtp.test.com -u "test" -xu nagios@test.com -xp password -m "test."

  vi objects/commands.cfg

  把 notify-host-by-email 和 notify-service-by-email 的邮件发送部分改为:

  /usr/local/bin/sendEmail -f nagios@test.com -t $CONTACTEMAIL$ -s smtp.test.com -u "$HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$" -xu nagios@test.com -xp password

#p#

  2. 发送 MSN 提醒

  这里有个 perl 写的程序:

  http://blog.chinaunix.net/u/24312/showart_1076329.html

  yum install perl-XML-Simple

  yum install perl-Hash-Merge

  perl -MCPAN -e 'install Net::MSN'

  cd msn

  修改一下 hello.pl 的 $handle 和 $password

  chmod +x hello.pl

  把发送者和接收者互相加为好友,然后发个测试信息试试:

  ./hello.pl admin@test.com hello

  ***次运行时发现这样的错误提示:

  could not find ParserDetails.ini in /usr/lib/perl5/vendor_perl/5.8.5/XML/SAX

  在这里有相关说明:

  http://perl-xml.sourceforge.net/faq/#parserdetails.ini

  执行

  perl -MXML::SAX -e "XML::SAX->add_parser(q(XML::SAX::PurePerl))->save_parsers()"

  mkdir /usr/local/nagios/lib

  mv lib /usr/local/nagios/lib/msn

  chown -R nagios:nagios /usr/local/nagios/lib

  vi msn_send.pl

  #!/usr/bin/perl

  use lib "/usr/local/nagios/lib/msn";

  my $handle = 'nagios@live.cn';

  my $password = 'password';

  chown nagios:nagios msn_send.pl

  chmod +x msn_send.pl

  mv msn_send.pl /usr/local/nagios/libexec/

  添加 MSN 提醒执行的命令:

  vi /usr/local/nagios/etc/objects/commands.cfg

  define command{

  command_name notify-host-by-msn

  command_line /usr/local/nagios/libexec/msn_send.pl $CONTACTEMAIL$ "`/usr/bin/printf "%b" "***** Monitor *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n"`"

  }

  define command{

  command_name notify-service-by-msn

  command_line /usr/local/nagios/libexec/msn_send.pl $CONTACTEMAIL$ "`/usr/bin/printf "%b" "***** Monitor *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$"`"

  }

  使用中发现,需要回复了才能终止进程,不然 check 就无法继续,而且是所有其它 host 和 service 的 check 都无法继续了。

  作者说需要把接收报警的人加为好友,可是的确是加为好友了的。但据说是可以设置超时时间的。

  如果有可以运行 PHP 的 Web 服务,用 PHP 发送 MSN 信息是个简单的办法:

  http://www.fanatic.net.nz/2005/02/15/send-a-message-using-php/

  安装

  wget http://downloads.fanatic.net.nz/dev/php/sendMsg.zip

  unzip sendMsg.zip

  mv sendMsg /path/to/web/dir/msn

  配置

  默认的验证提交方式需要 ssl 支持,用 curl 的(需要在编译 PHP 时加上 --with-curl ):

  vi sendMsg.php

  require_once('msnpauth-1.1.3.php');

  发送中文需要先用 iconv 将字符集转为 UTF-8:

  vi index.php

  $sendMsg->sendMessage(iconv("GBK", "UTF-8", $_POST['message']), 'Times New Roman', '008000');

  同样需要把发送者和接收者互相加为好友。

  可以先打开 http://server/msn/index.php 测试一下能否发送。如果没有问题,可以写一个脚本来执行 MSN 信息发送命令:

  vi /usr/local/nagios/libexec/msn_send.sh

  #!/bin/sh

  wget -O - -q --post-data="sender=nagios@live.cn&password=password&recipient=$1&message=$2" http://server/msn/index.php > /dev/null

  chmod +x /usr/local/nagios/libexec/msn_send.sh

  再把前面设置的 MSN 提醒命令中的 msn_send.pl 改为 msn_send.sh 就可以使用了。

#p#

  3. 发送 短信 提醒

  简单的,在 www.139.com 注册移动的邮箱,设置邮件短信提醒。这样就可以发送邮件的标题到注册的手机号码上。

  还有利用飞信实现的:

  http://www.it-adv.net/

  依赖 glibc-2.4 。 CentOS4/RHEL4, Debian Etch 不能使用。

  安装所依赖的库:

  tar zxvf lib.tar.gz

  mv lib /usr/local/lib/fetion

  echo "/usr/local/lib/fetion" > /etc/ld.so.conf.d/fetion-i386.conf

  ldconfig

  再安装飞信的命令行客户端:

  tar zxvf fetion_linux_20080402.tar.gz -C /usr/local/bin/

  vi /usr/local/bin/sms.sh

  #!/bin/sh

  /usr/local/bin/sms -f 159xxxxxxxx -p password -t $1 -m "$2"

  chmod +x /usr/local/bin/sms.sh

  和添加 MSN 提醒命令一样添加短信提醒的命令就可以了。

  Debian Etch 可以升级到 testing , glibc 也就更新到 2.4 了。

  sed -e 's|etch|testing|g' /etc/apt/sources.list > /etc/apt/sources.list~

  mv /etc/apt/sources.list~ /etc/apt/sources.list

  apt-get update

  apt-get dist-upgrade

通过文章的介绍,我们不难发现上面三种方法都可以做到信息及时的发送!希望本文对你们有用!

【编辑推荐】

 

责任编辑:赵鹏 来源: 网络转载
相关推荐

2011-03-23 12:55:51

NagiosMSN飞信

2022-07-08 09:01:36

logback日志异常

2011-03-22 13:00:50

Nagios

2011-03-22 13:00:49

Nagios

2011-03-22 13:00:50

Nagios

2010-01-05 11:14:25

Linux-FetioLinux

2011-03-23 14:43:07

Nagios监控

2011-03-25 17:30:02

Nagios

2011-07-08 10:21:23

Firefox 5.0

2011-03-24 13:00:31

Nagios飞信

2010-05-31 09:06:12

Nagios飞信

2013-01-10 09:36:19

NagiosNagios插件

2011-03-29 14:44:26

Zabbixemail

2011-04-01 16:52:29

zabbixemail

2011-11-25 16:27:46

2011-01-21 16:40:58

NagiosSendmail

2011-01-21 11:30:53

Sendmail

2011-03-25 11:05:39

Nagioswindows

2020-07-14 09:58:01

Python开发工具

2011-03-24 09:15:54

Nagios飞信
点赞
收藏

51CTO技术栈公众号