1. 准备alert脚本,用来调用微信脚本

#!/bin/bash

alertname=$
target=$
losspattern=$
rtt=$
hostname=$ smokename="hq_to_idc "
if [ "$losspattern" = "loss: 0%" ];
then
subject="Clear-${smokename}-Alert: $target host: ${hostname}"
else
subject="${smokename}Alert: ${target} – ${hostname}"
fi
echo "MTR Report for hostname: ${hostname}" > /tmp/mtr.txt
echo "" >> /tmp/mtr.txt
echo "sudo mtr -n –report ${hostname} "
sudo /usr/sbin/mtr -n –report ${hostname} >> /tmp/mtr.txt
echo "" >> /tmp/mtr.txt
echo "Name of Alert: " $alertname >> /tmp/mtr.txt
echo "Target: " $target >> /tmp/mtr.txt
echo "Loss Pattern: " $losspattern >> /tmp/mtr.txt
echo "RTT Pattern: " $rtt >> /tmp/mtr.txt
echo "Hostname: " $hostname >> /tmp/mtr.txt
echo "" >> /tmp/mtr.txt
echo "Full mtr command is: sudo /usr/sbin/mtr -n –report ${hostname}" >> /tmp/mtr.txt
echo "subject: " $subject
if [ -s /tmp/mtr.txt ]; then
/usrt/smokeping/weixin.sh "s" "s" "${subject}:${hostname}:$losspattern:$rtt:$target"
fi

准备微信报警代码

#!/bin/bash
### script name weixin.sh
### send messages from weixin for zabbix monitor
###
###
### usage: curl -s -G url 获取acessToken
### curl --data url 传送凭证调用企业号接口
### zabbix 会传送三个参数给脚本,$ 是消息接收账号,$ 报警标题, $ 报警内容 CropID=''
Secret=''
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F '"' '{print $4}')
now_time=$(date -d now)
now_timestamp=$(date -d "${now_time}" +%s)
options=$[**]
token_file='/tmp/token_file.txt'
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Gtoken"
LOG_FILE='/tmp/weixin_log.txt' function logMessageToFile(){
echo "[ $1 ] - ["$(date "+%Y-%m-%d %H:%M:%S")"] - $2" >> $LOG_FILE
} function create_tokenfile(){
echo "${now_time} > ${Gtoken}" > ${token_file}
} function get_Gtoken(){
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret"
Gtoken=$(/usr/bin/curl -s -G $GURL | awk -F '"' '{print $4}')
} function check_token(){
if [ -f "${token_file}" ]; then
file_token=$(awk -F '>' '{print $2}' ${token_file})
file_time=$(awk -F '>' '{print $1}' ${token_file})
file_timestamp=$(date -d "${file_time}" +%s)
time_difference=$[${now_timestamp}-${file_timestamp}]
if [ "${time_difference}" -gt "${options}" ]; then
get_Gtoken
create_tokenfile
logMessageToFile "INFO" "上次token是: ${file_token},到现在过了${time_difference} 秒, 新的token是:${Gtoken}"
else
logMessageToFile "INFO" "not need update the token, use old token ${file_token} 到现在过了${time_difference} 秒"
Gtoken=$(echo ${file_token})
fi
else
get_Gtoken
logMessageToFile "INFO" "the token_file : ${token_file} not exsits ,will create it . 到现在过了${time_difference} 秒"
create_tokenfile
fi } function body(){
local int AppID= # 企业号中的应用ID
local UserID="@all" # 部门成员id,zabbix中定义的微信接受者
local PartyID="" # 部门id,定义了范围,组内成员都可接收到消息
local Msg=$(echo "$@" | cut -d " " -f3-) # 过滤出zabbix中传递的第三个参数
printf '{\n'
printf '\t"touser":"'"$UserID"\"",\n"
printf '\t"toparty":"'"$PartyID"\"",\n"
printf '\t"msgtype": "text",'"\n"
printf '\t"agentid":'$AppID\,"\n"
printf '\t"text":{\n'
printf '\t\t"content":"'"$Msg"\"
printf '\n\t},\n'
printf '\t"safe":"0"\n'
printf '}\n'
} check_token
#smokeping_alert=${}-${}-${}-${}-${]
/usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL
# smokeping 配置文件 config中需要修改的参数
# to 后面默认是 填写 邮件
# 如果 = 后面 跟上 | 代表执行用户自己的脚本
# 脚本会读入5或者6个参数:name-of-alert, target, loss-pattern, rtt-pattern, # hostname,[raise]。
*** Alerts ***
#to = |/opt/smokeping/alert.sh
to =test@test.com
from = smokealert@company.xy # 报警条件
+someloss
type = loss
# in percent
pattern = >%,**,>%,**,>%
comment = loss times in a row
# 意思是 12次检查中 出现了 3次丢包的情况 监控主机参数增加
alerts = someloss

后续规则可以自己调整

关于smokeping告警规则 官方文档

http://oss.oetiker.ch/smokeping/doc/smokeping_config.en.html

http://blog.csdn.net/achejq/article/details/51556494

2、特定主机发送到特定用户

to 表示接受所有报警的邮箱,如果需要在特定的节点报警发送到特定的邮箱
则在该节点上增加alertee = testmonitor@139.com即可。具体可以参看/opt/smokeping/lib/Smokeping.pm源码,如下部分:

    1. foreach my $addr (map {$_ ? (split /\s*,\s*/,$_) : ()} $cfg->{Alerts}{to},$tree->{alertee},$alert->{to}){

smokeping 微信报警配置的更多相关文章

  1. CentOS7.3下Zabbix3.5之微信报警配置

    一.报警脚本放到服务端的 /usr/lib/zabbix/alertscripts/下      属组属主为zabbix zabbix      有执行权限vim weixinbaojing.py # ...

  2. Zabbix 3.0 配置企业微信报警(配置zabbix-web)

    一.添加报警媒体类型 Name:自定义 Type:选择script Scripts name:填写脚本名称 Script parameters:脚本参数 --corpid=XXX --corpsecr ...

  3. zabbix配置微信报警

    首先我们先目睹下微信报警的效果 接下来我们正式开始操作. 一:注册企业微信. 打开企业微信注册:http://work.weixin.qq.com 根据以上提示填入相应的内容,然后注册即可. 二:登录 ...

  4. 总zabbix配置-搭建-邮件报警-微信报警-监控mysql

    Centos7安装Zabbix4.0步骤 官方搭建zabbix4.0的环境要求: 1. 环境搭建LAMP 前提Centos系统安装完成:  确认一下: 1 2 cat /etc/redhat-rele ...

  5. elasticsearch5之Elastalert 安装使用 配置邮件报警和微信报警

    简介 Elastalert是用python2写的一个报警框架(目前支持python2.6和2.7,不支持3.x),github地址为 https://github.com/Yelp/elastaler ...

  6. zabbix设置微信报警的配置过程

    zabbix设置微信报警的配置过程 转发:https://blog.csdn.net/qq_31613055/article/details/78831607 微信企业号的申请 注册的地址https: ...

  7. 配置zabbix通过微信报警企业微信报警

    如今势态: 报警的方式可谓是八仙过海各显神通,如电话报警,短信报警,邮件报警,QQ报警,微信报警等等. 电话报警:一般都是使用别的平台的工具,平台给你提供一个接口供你使用,大多数为限量收费款 短信报警 ...

  8. Zabbix配置微信报警通知

    Zabbix告警可以通过邮件,微信,电话,短信等方式发送告警消息. 电话和短信需要向运营商购买相应的网关,需要付费: 邮件和微信是免费的,可以根据业务需要选择相应的告警模式 Zabbix版本:3.2 ...

  9. zabbix的配置之新版微信报警(二)

    zabbix配置2018版本微信报警 centos6.5中微信报警需要Python2.7版本之上,由于服务器是centos6.5.所以需要升级版本2.6到2.7. 具体升级步骤:Python升级版本2 ...

随机推荐

  1. HDU 1017 A Mathematical Curiosity (枚举水题)

    Problem Description Given two integers n and m, count the number of pairs of integers (a,b) such tha ...

  2. 全国车辆违章查询API文档及demo

    简介 聚合数据全国车辆违章API,目前已经支持300个左右的城市违章查询,已连接上万个APP.方便有车一族随时了解自己是否有过交通违章,避免因遗忘或逾期处理违章罚单而造成的不必要损失. API参考文档 ...

  3. 【Python】写入文件

    1.1写入空文件 若将文本写入文件,在调用open()时候需要提供另外一个实参,告诉Python你要写入打开的文件 file_path = 'txt\MyFavoriteFruit.txt' with ...

  4. HttpWebRequest.Proxy属性

    HttpWebRequest.Proxy默认使用IE代理,可以设置“Internet选项-Internet属性-连接-局域网设置-代理服务器”.

  5. srm 541

    资瓷点这里阅读该文章O_o 250 Solution 水题,最暴力的方法枚举就可以 Code #include <bits/stdc++.h> using namespace std; # ...

  6. Oracle中没有 if exists(...)的解决方法

    http://blog.csdn.net/hollboy/article/details/7550171对于Oracle中没有 if exists(...) 的语法,目前有许多种解决方法,这里先分析常 ...

  7. Oracle 复制表创建的sql语句

    http://cache.baiducontent.com/c?m=9d78d513d99e01fc09b3c3690d67c0161343f0652ba1d4020ed08449e3732b4250 ...

  8. 【Python】Selenium元素定位错误之解决办法

    当使用class定位元素时发现报错: 错误信息:selenium.common.exceptions.InvalidSelectorException: Message: Compound class ...

  9. 关于ejabberd限制单点登录

    ejabberd 是对xmpp协议的完全实现,那么单纯的ejabberd是不提供该功能限制的,但是从我们的xmpp协议则可以完全的解决这个问题,我们通过jid对它进行限制,下面可以看一下jid的解释: ...

  10. HTTP状态码介绍详细

    HTTP协议中几个状态码的含义:1xx(临时响应) 表示临时响应并需要请求者继续执行操作的状态代码. 代码 说明 100 (继续) 请求者应当继续提出请求. 服务器返回此代码表示已收到请求的第一部分, ...