当前位置:网站首页>利用GrayLog告警功能实现钉钉群机器人定时工作提醒
利用GrayLog告警功能实现钉钉群机器人定时工作提醒
2022-07-05 15:34:00 【yuanfan2012】
利用GrayLog告警功能实现钉钉群机器人定时工作提醒
1、GrayLog单独新建一个Syslog Input
用于接收Linux服务器系统日志
(图片可点击放大查看)
建议单独建一个Indice
(图片可点击放大查看)
并配置单独的Stream
(图片可点击放大查看)
(图片可点击放大查看)
(图片可点击放大查看)
防火墙中将Input端口放通
[[email protected] opt]# firewall-cmd --permanent --zone=public --add-port=2514/udp
success
[[email protected] opt]# firewall-cmd --reload
success2、Linux服务器系统日志接入到GrayLog
这里为了方便,直接用Graylog自身作为Linux服务器日志源
[[email protected] opt]# echo "*.* @192.168.31.127:2514;RSYSLOG_SyslogProtocol23Format" >> /etc/rsyslog.conf
[[email protected] opt]#
[[email protected] opt]# tail -n 4 /etc/rsyslog.conf
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###
*.* @192.168.31.127:2514;RSYSLOG_SyslogProtocol23Format
[[email protected] opt]#
[[email protected] opt]# systemctl restart rsyslog
(图片可点击放大查看)
3、检查日志是否正常查询
可以看到日志正常接入
(图片可点击放大查看)
4、编写定时写入系统日志的脚本及Crontab定时任务
vi replace_username.sh
#!/bin/bash
temp_day=`date +%a`
case $temp_day in
Mon)
echo "今日值班工作提醒 @张三A" > /etc/work_alert.txt;
;;
Tue)
echo "今日值班工作提醒 @李四B" > /etc/work_alert.txt;
;;
Wed)
echo "今日值班工作提醒 @王五C" > /etc/work_alert.txt;
;;
Thu)
echo "今日值班工作提醒 @袁繁(行云) " > /etc/work_alert.txt;
;;
Fri)
echo "今日值班工作提醒 @袁繁" > /etc/work_alert.txt;
;;
Sat)
echo "今日值班工作提醒 @张三F" > /etc/work_alert.txt;
;;
Sun)
echo "今日值班工作提醒 @张三G" > /etc/work_alert.txt;
;;
*)
exit;
esac
配置本月工作定时任务
crontab -e
1 0 1,2,6,7,8,9,10,13,14,15,16,17,20,21,22,23,24,27,28,29,30 * * /opt/replace_username.sh
00 17 1,2,6,7,8,9,10,13,14,15,16,17,20,21,22,23,24,27,28,29,30 * * /usr/bin/logger -f /etc/work_alert.txt
也就是6月份的工作日
1、每天0点1分自动替换/etc/work_alert.txt文件中@的人员姓名,相关每周每日轮班为不同人员
2、每天17点时执行logger -f 命令写入到系统日志中
(图片可点击放大查看)
5、配置Alert告警模板
(图片可点击放大查看)
(图片可点击放大查看)
(图片可点击放大查看)
Search Query "今日值班工作提醒" Search within the last你可以写5分钟或者更短3分钟
Execute search every建议跟Search within the last设置的时间一致
(图片可点击放大查看)
(图片可点击放大查看)
PrometheusAlert上的告警模板请自行配置
如下截图
(图片可点击放大查看)
6、手动触发日志并测试告警
[[email protected] opt]# /usr/bin/logger -f /etc/work_alert.txt
[[email protected] opt]# date
Thu Jun 9 23:21:51 CST 2022
[[email protected] opt]# cat /etc/work_alert.txt
(图片可点击放大查看)
(图片可点击放大查看)
(图片可点击放大查看)
等待5分钟观察是否可以收到告警
(图片可点击放大查看)
7、Tips
1)理论上crontab定时任务脚本如果没有问题的话,就会正常发送告警
2)PrometheusAlert关闭@所有人 以及告警通知标题修改
(图片可点击放大查看)
(图片可点击放大查看)
3)说明:目前发现@某人的功能未能成功
还待研究,需要改写replace_username.sh 脚本
边栏推荐
- Noi / 1.4 07: collect bottle caps to win awards
- Data communication foundation - route republication
- Detailed explanation of C language branch statements
- Which keywords will conflict with the abstract keyword
- 21. [STM32] I don't understand the I2C protocol. Dig deep into the sequence diagram to help you write the underlying driver
- Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
- go语言编程规范梳理总结
- 通过的英特尔Evo 3.0整机认证到底有多难?忆联科技告诉你
- DataArts Studio数据架构——数据标准介绍
- The OBD deployment mode of oceanbase Community Edition is installed locally
猜你喜欢

The difference between abstract classes and interfaces

力扣今日题-729. 我的日程安排表 I

Data communication foundation - route republication

Data communication foundation ACL access control list

Transfer the idea of "Zhongtai" to the code

Anti shake and throttling

Summary of the third class

Mistakes made when writing unit tests

vant tabbar遮挡内容的解决方式
![18.[stm32] read the ROM of DS18B20 temperature sensor and realize multi-point temperature measurement](/img/e7/4f682814ae899917c8ee981c05edb8.jpg)
18.[stm32] read the ROM of DS18B20 temperature sensor and realize multi-point temperature measurement
随机推荐
MySQL表字段调整
ES6深入—ES6 Class 类
Replknet: it's not that large convolution is bad, but that convolution is not large enough. 31x31 convolution. Let's have a look at | CVPR 2022
Data communication foundation - route republication
OceanBase社区版之OBD方式部署方式本地安装
abstract关键字和哪些关键字会发生冲突呢
[brief notes] solve the problem of IDE golang code red and error reporting
Intelligent metal detector based on openharmony
List uses stream flow to add according to the number of certain attributes of the element
Definition of episodic and batch
Data communication foundation - Ethernet port mirroring and link aggregation
机械臂速成小指南(九):正运动学分析
Li Kou today's question -729 My schedule I
Analytic hierarchy process of mathematical modeling (including Matlab code)
Subclasses and superclasses of abstract classes
【网易云信】超分辨率技术在实时音视频领域的研究与实践
Modify PyUnit_ Time makes it support the time text of 'xx~xx months'
17. [stm32] use only three wires to drive LCD1602 LCD
16. [stm32] starting from the principle, I will show you the DS18B20 temperature sensor - four digit digital tube displays the temperature
Convert obj set to entity set