前段时间接到公司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. 取值:form表单取值、input框绑定取值

    1. form表单取值1.1 方式一,通过<form bindsubmit="formSubmit">与<button formType="submit ...

  2. Cocos2DX开发:记录遇到的一些问题和解决方法

    今天看了一下以前学习cocos2dx时记录的一些笔记,主要是在实际中遇到的一些问题,整理了一下,就成为了这篇文章,便于自己以后查找,也为一些新手提供点经验. 这篇文章会一直更新,将自己之后开发中遇到的 ...

  3. Print Spooler 服务自动停止

    1)先在服务里停止并禁用Print Spooler : 2)删除此文件夹下的所有文件,C:\Windows\System32\spool\PRINTERS\ : 3)删除注册表 HKEY_LOCAL_ ...

  4. 稳重商务风格教师求职简历免费word模板

    30款稳重商务风格教师求职简历免费word模板,也可用于其他专业和职业,个人免费简历模板,个人简历表免费,个人简历表格. 声明:该简历模板仅用于个人欣赏使用,请勿用于商业用途,谢谢. 下载地址:百度网 ...

  5. Qt-网易云音乐界面实现-5 收藏列表,播放列表实现 QListWidget QTableWidget

    先上目前完成的内容吧,发现后面越写越多.在看看点击量,心凉凉. 完成了左侧的导航列表,还有就是右下角的播放列表. //创建的歌单 my_Create_Music_List = new QListWid ...

  6. Kafka发送到分区的message是否是负载均衡的?

    首先说结论,是负载均衡的.也就是说,现在有一个producer,向一个主题下面的三个分区发送message,没有指定具体要发送给哪个partition, 这种情况,如果是负载均衡的,发送的消息应该均匀 ...

  7. python3实现合并两个有序数组

    很早就听同学和师兄经常说刷题很重要,然而编程能力一直都很渣的我最近才开始从leetcode的初级算法开始.今天遇到的这道题虽然很简单,因为是头一次用自己的方法速度还不错,特此记录一下,还大神们请不要嘲 ...

  8. 【NLP】使用bert

    # 参考 https://blog.csdn.net/luoyexuge/article/details/84939755 小做改动 需要: github上下载bert的代码:https://gith ...

  9. 02-matplotlib-散点图

    import numpy as np import matplotlib.pyplot as plt ''' 散点图显示两组数据的值,每个点的坐标位置的值决定 用户观察两种变量的相关性: 正相关 负相 ...

  10. Sqlmap常用命令大全

    1 Options(选项) -h,--help 显示帮助消息-hh 显示详细帮助-version -v VERBOSE 详细级别 0-6 默认12 Target 目标-u URL--url=URL-g ...