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. 线程间操作无效: 从不是创建控件“XXX”的线程访问它

    方法1 Invoke((MethodInvoker)(()=>{XXX.Text = message;})); 方法2 取消跨线程检查 Control.CheckForIllegalCrossT ...

  2. Redis 在 Java 中的使用

    转:http://blog.csdn.net/jiangtao_st/article/details/8256610 一.下载jar包 https://github.com/xetorthio/jed ...

  3. Java enum枚举的使用方法

    一. 出现背景: 在JDK1.5之前,我们定义常量是这种:public static final String RED = "RED"; 在JDK1.5中增加了枚举类型,我们能够把 ...

  4. 【SharePoint】SharePoint 2013 使用PreSaveAction自定义客户端验证

    使用PreSaveAction函数实现客户端自定义验证. 例:[项目编号]为空时,必须填写[责任者]项.(其中[项目编号]为单行文本框,[责任者]为用户/组选择框.) function PreSave ...

  5. 【工具类】Date、Long、String 类型互转

    开发常常遇到Date.Long.String 三种类型数据须要互转的问题.以此记录. public static void main(String[] args) throws ParseExcept ...

  6. Oracle 唯一 索引 约束 创建 删除

    http://www.blogjava.net/lukangping/articles/340683.html/*给创建bitmap index分配的内存空间参数,以加速建索引*/ show para ...

  7. Android NDK开发常见错误

    错误一: make: *** No rule to make target `/cygdrive/d/1-workspace/showmap-android-opengles/jni/showmap_ ...

  8. C#中判断某个值是否存在于枚举

    我有一个枚举类型: #region -酒的种类- public enum WineType { 白酒 = 3, 葡萄酒 = 4, 洋酒 = 5, 老年陈酒 = 16, 啤酒 = 17 } #endre ...

  9. hdu4612 无向图中随意加入一条边后使桥的数量最少 / 无向图缩点+求树的直径

    题意如上,含有重边(重边的话,俩个点就能够构成了边双连通). 先缩点成树,在求数的直径,最远的连起来,剩下边(桥)的自然最少.这里学习了树的直径求法:第一次选随意起点U,进行bfs,到达最远的一个点v ...

  10. ClassNotFoundException Log

    Studio 运行时异常: Error:Execution failed for task ':app:compileDebugJavaWithJavac'.> Compilation fail ...