前段时间接到公司IT同事需求,帮助其配置smokeping的告警功能,之前配置的姿势有些问题,告警有些问题,现在调试OK,在此将关键配置点简单记录下。

关键的配置项主要有:

  1. 定义告警规则并配置将告警信息通过管道交给自定义的alert脚本
  2. 在主机定义里调用定义的告警规则
  3. 自定义的alert脚本对告警内容进行解析和处理

定义告警规则并配置将告警信息通过管道交给自定义的alert脚本

需要在config文件的Alert配置section中进行配置

# /usr/local/smokeping/etc/config

*** Alerts ***
# 将告警信息交给自己定的alert脚本进行处理
to = |/usr/local/smokeping/bin/send_alert.sh
from = a@b.com # 定义各种告警规则
+hostdown
type = loss
# in percent
pattern = ==0%,==0%,==0%, ==U
comment = 对端无响应 +bigloss
type = loss
# in percent
pattern = ==0%,==0%,==0%,==0%,>20%,>20%,>20%
comment = 连续3次采样-丢包率超过20% +lossdetect
type = loss
# in percent
pattern = ==0%,==0%,==0%,==0%,>0%,>0%,>0%
comment = 连续3次采样-存在丢包 +someloss
type = loss
# in percent
pattern = >0%,*12*,>0%,*12*,>0%
comment = 间断性丢包 +rttdetect
type = rtt
# in milli seconds
pattern = <100,<100,<100,<100,<100,<150,>150,>150,>150
comment = 连续3次采样延迟增大-超过150ms

The Alert section lets you setup loss and RTT pattern detectors. After each round of polling, SmokePing will examine its data and determine which detectors match. Detectors are enabled per target and get inherited by the targets children.

Detectors are not just simple thresholds which go off at first sight of a problem. They are configurable to detect special loss or RTT patterns. They let you look at a number of past readings to make a more educated decision on what kind of alert should be sent, or if an alert should be sent at all.

The patterns are numbers prefixed with an operator indicating the type of comparison required for a match.

告警规则参考:官方文档配置详解的Alert段

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

在主机定义里调用告警规则

配置语法

alerts = 告警规则1,告警规则2,告警规则3

如你所了解的,smokeping的配置文件里面通过"+"号的个数来定义层级关系,因此你可以在不同的层级里面调用告警规则,上级的定义可以被下级继承和覆盖(内层的优先级更高)

+ xxoo
menu = xxoo-top
title = xxoo-所有网络监控列表
host = /xxoo/net-A /xxoo/net-B /xxoo/net-C
alerts = hostdown,bigloss,lossdetect,someloss,rttdetect # 这里的作用范围就是/xxoo ++net-A
menu = Menu-Name-A
title = Titile-Name-A
host = 10.10.10.101
alerts = hostdown,bigloss,lossdetect # 这里的规则作用范围就是/xxoo/net-A ++net-B
menu = Google-DNS
title = To-Google-DNS
host = 8.8.8.8

  

自定义的alert脚本对告警内容进行解析和处理

smokeping在告警的时候会发送5~6个参数到告警接收媒介(这里也就是我们自定义的alert脚本),参数按照顺序分别为:name-of-alert, target, loss-pattern, rtt-pattern, hostname,[raise]。

因此我们的alert脚本需要做的就是对上述参数进行解析和处理。

告警脚本样例:

[root@smokeping ~]# cat /usr/local/smokeping/bin/send_alert.sh
#!/bin/bash
#########################################################
# Script to email a ping report on alert from Smokeping #
#########################################################
# 解析变量
alertname=$1
target=$2
losspattern=$3
rtt=$4
hostname=$5
# 自定义变量
email="xxx@yyy.com"
phone="12345678901"
smokename="AlertName"
smokeping_mail_content=/tmp/smokeping_mail_content
#smokeping_sms_content=/tmp/smokeping_sms_content # 把所有传过来的变量输出到脚本调用日志里,方便统计和问题排查
echo "$(date +%F-%T)" >> invoke.log
echo $@ >> invoke.log # 网络恢复逻辑判断
if [ "$losspattern" = "loss: 0%" ];
then
subject="Clear-${smokename}-Alert: $target host: ${hostname}"
else
subject="${smokename}Alert: ${target} – ${hostname}"
fi # generate mail content
# 清空并重新生成邮件内容
>${smokeping_mail_content}
echo "Name of Alert: " $alertname | tee -a ${smokeping_mail_content}
echo "Target: " $target | tee -a ${smokeping_mail_content}
echo "Loss Pattern: " $losspattern | tee -a ${smokeping_mail_content}
echo "RTT Pattern: " $rtt | tee -a ${smokeping_mail_content}
echo "Hostname: " $hostname | tee -a ${smokeping_mail_content}
echo "" | tee -a ${smokeping_mail_content}
echo "Ping Report:" | tee -a ${smokeping_mail_content}
ping ${hostname} -c 4 -i 0.5 | tee -a ${smokeping_mail_content} # send mail
# 发送email,下面的if逻辑其实没有什么卵用,因为脚本只要被调用了,这个${smokeping_mail_content}就一定是有内容的
if [ -s ${smokeping_mail_content} ];then
content=`cat ${smokeping_mail_content}`
curl http://notice.api.ourcompany.com/send_mail -d "receiver=${email}&subject=${subject}&content=${content}"
fi # send sms
# 判断alertname是否是hostdown,bigloss,rttdetect这几种比较严重的级别,如果是的话就调用短信接口进行短信发送。
# 注意,这里需要控制下短信发送内容的字数,要花钱的~哈哈
judge_alert_type=`echo ${alertname} | egrep "hostdown|bigloss|rttdetect"|wc -l`
if [ "${judge_alert_type}" -eq 1 ];then
curl http://notice.api.ourcompany.com/send_sms -d "receiver=${phone}&subject=${subject}&content=${alertname} on ${hostname}"
fi
[root@smokeping ~]#

上述脚本中调用了公司的通知接口进行告警的发送,此配置结合自己的需求进行调整即可

http://notice.api.ourcompany.com/send_mail
http://notice.api.ourcompany.com/send_sms  

告警效果

邮件

短信

自定义smokeping告警(邮件+短信)的更多相关文章

  1. java springboot activemq 邮件短信微服务,解决国际化服务的国内外兼容性问题,含各服务商调研情况

    java springboot activemq 邮件短信微服务,解决国际化服务的国内外兼容性问题,含各服务商调研情况 邮件短信微服务 spring boot 微服务 接收json格式参数 验证参数合 ...

  2. 自定义shareSDK的验证码短信内容

    应用中使用了shareSDK来做第三方登录和短信验证码的接收,但是想将短信内容修改为自己想要的内容 官方文档中并未详细提及:无GUI接口调用 默认的短信内容为: 如果只是要修改括号中的抬头,只需按照此 ...

  3. SpringCloud微服务实战——搭建企业级开发框架(二十六):自定义扩展OAuth2实现短信验证码登录

    现在手机验证码登录似乎是每个网站必备的功能,OAuth2支持扩展自定义授权模式,前面介绍了如何在系统集成短信通知服务,这里我们进行OAuth2的授权模式自定义扩展,使系统支持短信验证码登录. 1.在g ...

  4. iOS个人中心渐变动画、微信对话框、标签选择器、自定义导航栏、短信验证输入框等源码

    iOS精选源码 简单的个人中心页面-自定义导航栏并予以渐变动画 程序员取悦女票的正确姿势---Tip1(iOS美容篇) iOS 前台重启应用和清除角标的问题 微信原生提醒对话框3.0 JHLikeBu ...

  5. Zabbix告警脚本-短信

    [root@iot-svndata02 bin]# cat zbsms.sh #!/bin/sh #curl http://221.179.180.137:8080/smsaServer/lkSend ...

  6. sqlalchemy中使用event设置条件触发短信与邮件通知

    一.原因 近期在做短信与邮件通知系统.使用到了这一块.例如,当订单完成以后进行邮件短信的通知.虽然可以采用直接调用接口的方式实现,但有几个原因让我希望使用条件触发的方式 1.由于系统中支持线上线下以及 ...

  7. server宕机监控、检測、报警程序(139绑定手机短信报警)monitor_down.sh

    宕机监控报警程序 一.   需求来源 宕机对运维人员来说,最痛苦了.怎样检測一台server是否还在正常执行,假设该server宕机,怎样在第一时间监測到并通知一线运维人员进行维护,最大化降低损失. ...

  8. zabbix告警邮件、短信发送错误快速排查方法

    zabbix告警邮件.短信发送错误快速排查方法 背景 zabbix告警邮件.短信经常有同事反馈发送错误的情况,这个问题排查的角度很多,那么最快捷的角度是什么呢? 在我看来,最快的角度就是判断这个告警邮 ...

  9. zabbix增加手机短信、邮件监控的注意要点,SSL邮件发送python脚本

    1.短信接口文档: URL http://xxx.com/interfaces/sendMsg.htm Method POST Description 文字短信调用接口 Request Param L ...

随机推荐

  1. 对RedisTemplate接口二次封装成自定义工具接口

    开发过程中,经常使用redis数据库存储. 一般都是依赖注入redisTemplate,然后调用redisTemplate的api进行接口功能实现. 但是,如果对redisTemplate自带的API ...

  2. asp.net core 发布到docker 极简步骤

    1.使用dotnet命令发布项目 2.把发布成功的文件通过scp等工具发布到linux服务器上,在当前目录下新建一个dockerfile 3.使用asp.net core镜像为底包构建一个新的镜像 4 ...

  3. WHO ARE YOU?--writeup

    TIPS:广东强网杯线上题 总结知识点:BASE64,ROT13 0x00 Base64 什么是Base64? Base64编码原理 其用途 什么是Base64? Base64是一种基于64个可打印字 ...

  4. hadoop组件概念理解

    一.HADOOP 二.HIVE 三.SQOOP 1.来由和作用 sqoop由一些封装好的MR程序的jar包构成,后演变成框架,但sqoop只有map任务没有reduce任务. 用于 hdfs.hive ...

  5. ats编译中增加透明度 选项

    在大多数情况下,如果环境支持透明度,则configure将自动启用它.对于其他环境,可能需要 配置configure 选项. --enable-posix-cap 这实现了POSIX功能,这是透明度所 ...

  6. route命令详情

    基础命令学习目录首页 原文链接:https://www.cnblogs.com/lpfuture/p/5857738.html 考试题一:linux下如何添加路由(百度面试题) 以上是原题,老男孩老师 ...

  7. Vue实现双向绑定的原理以及响应式数据

    一.vue中的响应式属性 Vue中的数据实现响应式绑定 1.对象实现响应式: 是在初始化的时候利用definePrototype的定义set和get过滤器,在进行组件模板编译时实现water的监听搜集 ...

  8. java控制台编译通过,运行出现找不到或无法加载主类的情况

    参考链接:http://www.knowsky.com/1046493.html 当建了一个包之后(假设建的包的名字为com),找到该java文件的com目录,发现编译能够通过,但是运行的时候出现了一 ...

  9. Final阶段中间产物

    空天猎功能说明书:https://git.coding.net/liusx0303/Plane.git 空天猎代码控制:https://coding.net/u/MR__Chen/p/SkyHunte ...

  10. “Hello World!”团队第七周召开的第六次会议

    博客内容: 一.会议时间 二.会议地点 三.会议成员 四.会议内容 五.todo list 六.会议照片 七.燃尽图 八 .功能说明书 一.会议时间 2017年12月6日  11:20-12:00 二 ...