当前位置:网站首页>基础架构之日志管理平台及钉钉&邮件告警通知
基础架构之日志管理平台及钉钉&邮件告警通知
2022-07-28 13:46:00 【微服务布道者】
在现代化的软件开发流程中,日志显得非常的重要,不可能再零散的游离在各个项目中,等查看日志的时候再登录服务器去到特定的目录去查看,这显然很繁琐且效率低下,所有整合一套日志管理平台,也显得非常重要,这篇文章是日志管理平台搭建的第一篇,第二篇为告警及邮件通知
接上一篇,我们继续解释如何把ELK跟钉钉及发送邮件功能结合起来,让我们及时的了解重要日志并快速反馈。
- Sentinel 安装,项目介绍在https://github.com/sirensolutions/sentinl,点击可以详细介绍。
运行命令转到kibana的bin目录
cd /usr/share/kibana/bin,这里是默认安装路径,然后执行如下命令
./kibana-plugin install https://github.com/sirensolutions/sentinl/releases/download/tag-6.3.2-beta-1/sentinl-v6.3.1.zip,这里根据服务器性能及网络环境,可能要等一会才能看到成功的信息,成功后会自动刷新kibana服务,再次打开kibana,如图所示说明安装成功
- 邮件通知
a) 要发送邮件,得先有一台SMTP发送服务,我这里用的是163,现在几乎提供邮件功能的服务商都可以启动SMTP功能,开通即可。
b) 邮件配置,打开/etc/kibana/kibana.yml 文件,添加如下设置
sentinl:
settings:
email:
active: true
user: [email protected]
password: 123456
host: smtp.163.com
ssl: false #根据实际情况添加
report:
active: true千万注意设置级别,不然会出现莫名的错误。
c) 点击sentinl,添加一个Watcher,我这里配置信息如下。
{
"actions": {
"Alerm": {
"throttle_period": "1h0m0s",
"email": {
"to": "[email protected]",
"from": "[email protected]",
"subject": "业务系统告警",
"priority": "high",
"html": "系统程序错误告警: 一共发生{{payload.hits.total}} 次,请登录核查<a herf=\"http://192.168.1.215:5601\" target=\"_blank\">点击登录</a>"
}
}
},
"input": {
"search": {
"request": {
"index": [
"nlog*"
],
"body": {
"query": {
"bool": {
"must": [
{
"query_string": {
"analyze_wildcard": true,
"query": "\"error\""
}
},
{
"range": {
"@timestamp": {
"gte": "now-1h",
"lte": "now",
"format": "epoch_millis"
}
}
}
],
"must_not": []
}
}
}
}
}
},
"condition": {
"script": {
"script": "payload.hits.total >= 5"
}
},
"trigger": {
"schedule": {
"later": "every 2 minutes"
}
},
"disable": true,
"report": false,
"title": "nlog",
"wizard": {},
"save_payload": false,
"spy": false,
"impersonate": false
}主要是配置接收者邮箱,判断依据,判断条件,触发间隔
d) 开启Watcher并执行,如下图所示。
等一会,就会在alarms下看到告警信息。
打开配置文件中接收者的邮件,可以看到收到的信息,我的信息如下
,说明邮件告警功能运行正常。
2. 钉钉消息
a) 钉钉接收消息,主要是利用钉钉的机器人功能,首先开通机器人,我的机器人设置如下
主要是利用webhook,接下来在设置发送消息中用到。
b) 钉钉Watcher设置,设置如下
{
"actions": {
"Webhook_683bd385-86b3-46ba-8e1b-f89cccccbbec": {
"name": "WatcherName",
"throttle_period": "1m",
"webhook": {
"priority": "high",
"stateless": false,
"method": "POST",
"host": "oapi.dingtalk.com",
"port": "443",
"path": "/robot/send?access_token=ec5fe24b4a218f71bca667975850cbf3f2830b9bd2bd91f60ca07fab28a3d439",
"body": " {\"msgtype\": \"text\",\r\n \"text\": {\r\n \"content\":\"业务系统告警\"\r\n }\r\n}",
"params": {
"watcher": "{{watcher.title}}",
"payload_count": "{{payload.hits.total}}"
},
"headers": {
"Content-Type": "application/json"
},
"auth": "钉钉账号名:密码",
"message": "业务功能告警",
"use_https": true
}
}
},
"input": {
"search": {
"request": {
"index": [
"nlog*"
],
"body": {
"query": {
"bool": {
"filter": {
"range": {
"@timestamp": {
"gte": "now-15m/m",
"lte": "now/m",
"format": "epoch_millis"
}
}
}
}
},
"size": 0,
"aggs": {
"dateAgg": {
"date_histogram": {
"field": "@timestamp",
"time_zone": "Europe/Amsterdam",
"interval": "1m",
"min_doc_count": 1
}
}
}
}
}
}
},
"condition": {
"script": {
"script": "payload.aggregations.dateAgg.buckets.some(b => b.doc_count>=5)"
}
},
"trigger": {
"schedule": {
"later": "every 1 minutes"
}
},
"disable": true,
"report": false,
"title": "nlog_dingding",
"wizard": {},
"save_payload": false,
"spy": false,
"impersonate": false
}c) 开启并执行Watcher,注意观察钉钉,如果收到如下信息,则说明该功能运行成功。
这样,ELK跟业务系统对接,及邮件、钉钉告警已经介绍完了,其实发挥想象并根据业务需求,可以延伸出更有用的功能。如果更好的建议欢迎交流并共同进步。
喜欢的朋友记得给个关注~
边栏推荐
- Another way of understanding the essence of Hamming code
- [ecmascript6] proxy and reflection
- Leetcode 0142. circular linked list II
- Forage QR code -- online QR code generator
- Hcip day 11
- Node file operation
- 文件批量重命名工具Bulk Rename Utility
- Iterator iterator interface
- 58子站安居,经纪人营销管理平台登录接口加密逆向
- Some problems encountered in the development of Excel VBA, solutions, and continuous updates
猜你喜欢

开源项目丨Taier1.2版本发布,新增工作流、租户绑定简化等多项功能

35道MySQL面试必问题图解,这样也太好理解了吧

Hcip day 10

Career planning of Software Test Engineer

MeterSphere--开源持续测试平台

Install mysql5.7.36 in CentOS

IP black and white list

8、 Picker usage drop-down box selection effect

How to effectively conduct the review meeting (Part 1)?

ScottPlot入门教程:获取和显示鼠标处的数值
随机推荐
How to effectively conduct the review meeting (Part 1)?
ZABBIX distributed
JS instantiation method
Detailed explanation of common commands of vim (VIM use tutorial)
Some problems encountered in the development of Excel VBA, solutions, and continuous updates
Afnetworking crash course
SwiftUI 4.0 的全新导航系统
Cv:: mat conversion to qimage error
企鹅一面:为什么不建议使用SELECT * ?
pix2pix
如何在 Core Data 中进行批量操作
35道MySQL面试必问题图解,这样也太好理解了吧
SwiftUI 布局 —— 对齐
Install mysql5.7.36 in CentOS
工厂模式和构造函数模式
SwiftUI 布局 —— 尺寸( 上 )
Tdengine helps Siemens' lightweight digital solutions
Forage QR code -- online QR code generator
2022高处安装、维护、拆除考试题库及在线模拟考试
[ecmascript6] proxy and reflection