设为首页 收藏本站
查看: 1139|回复: 0

nagios使用

[复制链接]

尚未签到

发表于 2017-4-20 08:05:22 | 显示全部楼层 |阅读模式
nagios中文:http://nagios-cn.sourceforge.net/
nagiso官方网站:http://www.nagios.org/

Ununtu下Nagios信息发送方式:
1.mail
如果要接收Nagios的EMail警报,需要安装(Postfix)包

sudo apt-get install mailx

需要编辑Nagios里的EMail通知送出命令,它位于/usr/local/nagios/etc/commands.cfg文件中,将里面的'/bin/mail'全部替换为'/usr/bin/mail'。一旦设置好需要重启动Nagios以使配置生效。

sudo /etc/init.d/nagios restart

2.MSN
  用php来发送MSN信息。
  wget http://downloads.fanatic.net.nz/dev/php/sendMsg.zip
  unzip sendMsg.zip
  mv sendMsg /path/to/web/dir/msn
  可以先打开 http://server/msn/index.php 测试一下能否发送。如果没有问题,可以写一个脚本来执行 MSN 信息发送命令:
  /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

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

define command{
        command_name    notify-host-by-msn
        command_line    /usr/local/nagios/libexec/msn_send.sh $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.sh $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$"`"
        }

/usr/local/nagios/etcobjects/contacts.cfg :

define contact{
        contact_name                    nagios
        alias                           Nagios Msn
        use                             generic-contact
        service_notification_period     24x7
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,u,r
        service_notification_commands   notify-service-by-msn
        host_notification_commands      notify-host-by-msn
}

参考于:http://blog.bluedata.org/nagios-notification-type/
3.飞信通知

飞信官方网站:http://www.it-adv.net/
  下载:fetion20080910048-linux.tar.gz 和 library32.rar(版本不断更新)
  tar xvfz fetion_linux_20080402.tar.gz
  cd install
  sudo cp fetion /usr/bin
  fetion -h
如果出现如下错误:
  error while loading shared libraries: libACE.so.5.4.7: cannot open shared object file: No such file or directory
  说明缺少运行的库文件。
解决方法:
   a.sudo apt-get install libACE.so.5.4.7 libACE_SSL.so.5.4.7
     (可能你的ubuntu已经不提供安装这两个库文件,采用下面的方案)
   b.unrar e library32.rar
     cd library32
     sudo cp *.* /lib/
     sudo cp *.* /usr/lib/
  重新执行 fetion -h.应该能看到所要的结果。
  如果你有飞信号,可以执行一下。
  fetion  -u 飞信号 -p pwd 来登录。
/usr/local/nagios/etc/objects/commands.cfg:
# 'notify-service-by-fetion' command definition                                                                             
define command{
        command_name notify-service-by-fetion
        command_line /usr/bin/feiton -u 13888888888  -p 123456   -t $CONTACTPAGER$ -m "$HOSTNAME$ $SERVICEDESC$ is $SERVICESTATE$ on $TIME$ result is $SERVICEOUTPUT$" $CONTACTPAGER$
        }
/usr/local/nagios/etcobjects/contacts.cfg :
define contact{
contact_name                    fetion
alias                           nagios admin
host_notification_period        24x7
service_notification_period     24x7
host_notification_options       d,r,
service_notification_options    c,w,r
service_notification_commands   notify-service-by-email,notify-service-by-fetion
#       service_notification_commands   notify-service-by-email                                                            
host_notification_commands      notify-host-by-email
pager                           158010775111
}


最后将定义的contact添加到contactgroup中:
define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin,nagios,fetion
}
当你定义一个主机的时候:
/usr/local/nagios/etc/objects/templates:
# Linux host definition template - This is NOT a real host, just a template!                                                

define host{
        name                            linux-server    ; The name of this host template
        use                             generic-host    ; This template inherits other values from the generic-host template
check_period                    24x7            ; By default, Linux hosts are checked round the clock
check_interval                  5               ; Actively check the host every 5 minutes
retry_interval                  1               ; Schedule host check retries at 1 minute intervals
        max_check_attempts              10              ; Check each Linux host 10 times (max)
        check_command                   check-host-alive ; Default command to check Linux hosts
        notification_period             workhours       ; Linux admins hate to be woken up, so we only notify during the day
                                                        ; Note that the notification_period variable is being overridden from
                                                        ; the value that is inherited from the generic-host template!
notification_interval           120             ; Resend notifications every 2 hours
        notification_options            d,u,r           ; Only send notifications for specific host states
contact_groups                  admins          ;使用的联系组为admins
        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

  此处参考:http://yang2001.blog.iyunv.com/25307/73164

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-366569-1-1.html 上篇帖子: Nagios && Cacti 下篇帖子: Nagios + Nconf
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表