前段时间接到公司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. 多栏布局与JS实现瀑布流

    css3属性之多栏布局与JS实现瀑布流 背景:之前打算自己总结一下flex布局的知识点,发现自己无从下手,原因在何处:我反思了一下,其实原因很简单,使用的次数少,更多的时间使用了百分比,浮动和定位解决 ...

  2. WebSocket抓包分析

    转载自:https://www.cnblogs.com/songwenjie/p/8575579.html Chrome控制台 (1)F12进入控制台,点击Network,选中ws栏,注意选中Filt ...

  3. ActiveMQ笔记:管理和监控

    ActiveMQ提供了比较丰富的监控和管理工具.在ActiveMQ的网页里(http://activemq.apache.org/how-can-i-monitor-activemq.html)提到了 ...

  4. 服务端模版注入漏洞检测payload整理

    服务端模版注入漏洞产生的根源是将用户输入的数据被模版引擎解析渲染可能导致代码执行漏洞 下表涵盖了java,php,python,javascript语言中可能使用到的模版引擎,如果网站存在服务端模版注 ...

  5. html , body , margin , overflow 之大乱战

    <!DOCTYPE html> <html> <head> <style> html,body{ margin:0 ;padding:0 } div{m ...

  6. swapon和swapoff命令详解

    基础命令学习目录首页 原文链接:https://blog.csdn.net/yexiangCSDN/article/details/83182259 swapon命令用于激活Linux系统中交换空间, ...

  7. 随手记录-linux-常用命令

    转自:https://www.cnblogs.com/yjd_hycf_space/p/7730690.html linux目录结构:http://www.cnblogs.com/fat39/p/72 ...

  8. 作业MathExam

    MathExam233 一.预估与实际 PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 600 650 • ...

  9. 树莓派 Raspberry-Pi 折腾系列:系统安装及一些必要的配置

    入手树莓派将近一个月了,很折腾,许多资源不好找,也很乱.简单整理一下自己用到的东西,方便以后自己或别人继续折腾. 0. 操作系统下载 树莓派官方 Raspbian 系统下载:http://www.ra ...

  10. Sprint会议3

    昨天:熟悉了一下软件操作,设计了图标. 今天:今天满课,没有做什么实质性的进展. 遇到问题:由于没干什么,也没遇到什么问题.