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. VC++动态链接库(DLL)编程深入浅出(四)

    这是<VC++动态链接库(DLL)编程深入浅出>的第四部分,阅读本文前,请先阅读前三部分:(一).(二).(三). MFC扩展DLL的内涵为MFC的扩展,用户使用MFC扩展DLL就像使用M ...

  2. Eclipse Memory Analyzer安装

    转载:http://www.jianshu.com/p/3b3c3a914724 1.下载地址:Eclipse Memory Analyzer Open Source Project   2.点击进入 ...

  3. TP5结合聚合数据API查询天气

    php根据城市查询天气情况看到有人分享java的查询全国天气情况的代码,于是我想分享一个php版本的查询天气接口.免费查询天气的接口有很多,比如百度的apistore的天气api接口,我本来想采用这个 ...

  4. 前端标签--js--css大致思路

    html标签语言在块级和内联标签的基础上进行页面的设计,设计的时候主要是注意标签块间的距离位置等信息,设计盒子的浮动,盒子的位置,盒子之间的联系. 在设计网页之前一定要判断好该设计多少个盒子,什么样的 ...

  5. nginx教程1:location 匹配规则

    worker_process # 表示工作进程的数量,一般设置为cpu的核数 worker_connections # 表示每个工作进程的最大连接数 server{} # 块定义了虚拟主机 liste ...

  6. Jenkins:使用Git Parameter插件实现tag或分支的选择性构建

    Jenkins如何选择任意一个tag来构建代码 Jenkins如何选择任意一个branch(分支)来构建代码 苦恼了一段时间后,发现Git Parameter插件实现可以帮助我们来实现. 下面来介绍如 ...

  7. linux 更新yum源 改成163源

    安装完CentOS6.3后,为避免从国外站点安装更新速度过慢,需要更改yum更新源,所以从网上找了下更改linux yum源的方法,和大家进行下分享.原理很简单,就是把yum配置文件中的更新源改一下, ...

  8. SERVICE_STATUS结构各成员解析

    在编写Windows服务的时候,需要调用API函数::SetServiceStatus()向服务控制管理器(SCM)提交更新当前服务的状态信息,其第2个参数为指向SERVICE_STATUS结构的指针 ...

  9. PHP中的session永不过期的解决思路及实现方法分享

    打开php.ini设置文件,修改三行如下: 1.session.use_cookies  把这个的值设置为1,利用cookie来传递sessionid  2.session.cookie_lifeti ...

  10. Drcom账户管理Server端解说

    https://www.github.com/xiyouMc 首先今天要讲的是针对Drcom查询账户URL的解析和抓取数据.    Drcom是大学生宿舍上网普遍使用的联网client,然而对于自己账 ...