当前位置:网站首页>利用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 脚本
边栏推荐
- lv_ font_ Conv offline conversion
- Boost the development of digital economy and consolidate the base of digital talents - the digital talent competition was successfully held in Kunming
- abstract关键字和哪些关键字会发生冲突呢
- Cs231n notes (medium) -- applicable to 0 Foundation
- 19.[STM32]HC_ SR04 ultrasonic ranging_ Timer mode (OLED display)
- Appium automation test foundation - appium basic operation API (I)
- 视觉体验全面升级,豪威集团与英特尔Evo 3.0共同加速PC产业变革
- 20.[STM32]利用超声波模块和舵机实现智能垃圾桶功能
- 对象和类的关系
- Five common negotiation strategies of consulting companies and how to safeguard their own interests
猜你喜欢

定义严苛标准,英特尔Evo 3.0正在加速PC产业升级
![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

Arduino controls a tiny hexapod 3D printing robot
![[brief notes] solve the problem of IDE golang code red and error reporting](/img/b6/0b2ea06eb5fbe651ff9247b109fa15.png)
[brief notes] solve the problem of IDE golang code red and error reporting
![16.[STM32]从原理开始带你了解DS18B20温度传感器-四位数码管显示温度](/img/9f/c91904b6b1d3a1e85c0b50e43972e5.jpg)
16.[STM32]从原理开始带你了解DS18B20温度传感器-四位数码管显示温度

示例项目:简单的六足步行者

Mistakes made when writing unit tests

数学建模之层次分析法(含MATLAB代码)

Subclasses and superclasses of abstract classes

Transfer the idea of "Zhongtai" to the code
随机推荐
示例项目:简单的六足步行者
Convert obj set to entity set
Pits encountered in the use of boolean type in development
机械臂速成小指南(九):正运动学分析
Defining strict standards, Intel Evo 3.0 is accelerating the upgrading of the PC industry
Object. defineProperty() - VS - new Proxy()
写单元测试的时候犯的错
Li Kou today's question -729 My schedule I
ES6深入—ES6 Class 类
CSRF, XSS science popularization and defense
How to introduce devsecops into enterprises?
基于OpenHarmony的智能金属探测器
Temporary cramming before DFS examination
Parameter type setting error during batch update in project SQL
我们为什么要学习数学建模?
How difficult is it to pass the certification of Intel Evo 3.0? Yilian technology tells you
RLock锁的使用
Information collection of penetration test
Query the latest record in SQL
Fundamentals of data communication - Principles of IP routing