nagios企业微信代理报警配置+报警时间间隔

 

cat libexec/set_to_weixin.sh 

#!/bin/bash

http_proxy=IP:808
https_proxy=IP:808           内网代理需配置,外网环境忽略
export http_proxy
export https_proxy

get_access_token () {
curl -s https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=ww****e042\&corpsecret=Ss*****znLQ >/tmp/$$.txt
access_token=`awk -F "\"" '{print $10}' /tmp/$$.txt`
}

sed_to_weixin () {
curl https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$access_token -d  "{ \
\"toparty\": \"2\", \
\"msgtype\": \"text\", \
\"agentid\": 1000002, \
\"text\": { \
\"content\": \"$1\" \
}, \
\"safe\":\"0\" \
}"
}

main () {
get_access_token
sed_to_weixin "$*"
}

main "$*"

 cat commands.cfg 
# For weixin
define command{
command_name notify-host-by-weixin
command_line /usr/local/nagios/libexec/set_to_weixin.sh "$NOTIFICATIONTYPE$-$HOSTNAME$\n$HOSTALIAS$\nSTATE--$HOSTSTATE$\n$HOSTADDRESS$--$HOSTOUTPUT$\n$CONTACTALIAS$ $LONGDATETIME$"
}

 

 cat timeperiods.cfg

define timeperiod{
        name                    china
        timeperiod_name         china
        alias                   china
 
        january 1               00:00-00:00     ; 1.1
        may 1                   00:00-00:00     ; 5.1
        october 1               00:00-00:00     ; 10.1
        monday          08:00-18:00
        tuesday         08:00-18:00
        wednesday       08:00-18:00
        thursday        08:00-18:00
        friday          08:00-18:00
        saturday        08:00-18:00
       
        }

# vim nagios.cfg 

添加下边内容 

cfg_file=/usr/local/nagios/etc/objects/escalations.cfg 

新建 escalations.cfg 

define hostescalation{ 

host_name               IP  ; 被监控主机名称,与hosts.cfg中一致,多个主机以逗号隔开 

 first_notification      2                ; 第2条信息起,改变频率间隔 

last_notification       0                ; 第n条信息起,恢复频率间隔 

notification_interval   600              ; 通知间隔(10小时) 

 contact_groups          admins           ; 联系组  

 } 

cat templates.cfg | grep host_notification_commands
        host_notification_commands      notify-host-by-email,notify-host-by-weixin

 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg  检查问题

restart OK

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

王Sir_yt

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值