当前位置:网站首页>Zabbix_监控ssh/crond服务-微信告警
Zabbix_监控ssh/crond服务-微信告警
2022-06-10 19:01:00 【这个手刹不太灵儿】
zabbix
监控ssh服务
1、创建一个专门ssh进程的zabbix_agent的配置文件
[[email protected] zabbix_agentd.d]# cat userparameter_ssh.conf
UserParameter=ssh.status[*],/etc/zabbix/zabbix_agentd.d/ssh.sh $1
2、编写脚本监控ssh进程
[[email protected] zabbix_agentd.d]# cat sshd.sh
#!/bin/bash
case $1 in
ping)
/usr/bin/netstat -anlupt|grep sshd|grep "LISTEN"|wc -l
;;
esac
[[email protected] zabbix_agentd.d]# chmod +x sshd.sh
3、刷新服务,在server端验证
[[email protected] zabbix_agentd.d]# service zabbix-agent restart
Redirecting to /bin/systemctl restart zabbix-agent.service
[[email protected] zabbix]# zabbix_get -s 192.168.169.154 -k sshd.status[ping]
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
0
4、排错
# 登录root用户,执行如下命令,让其他用户获得文件所有者的权限,授予suid权限
[[email protected] zabbix_agentd.d]# chmod +s /usr/bin/netstat
# 此时在server端验证正常
[[email protected] zabbix]# zabbix_get -s 192.168.169.154 -k sshd.status[ping]
2
监控crond进程
# 编写监控crond进程的配置文件
[[email protected] zabbix_agentd.d]# cat userparameter_crond.conf
UserParameter=crond.status[*],/usr/sbin/pidof crond|wc -w
# server端验证
[[email protected] zabbix]# zabbix_get -s 192.168.169.154 -k crond.status[ping]
1
添加ssh/crond的监控
创建应用集

创建监控项



创建图形

验证图形
触发器
配置触发器


验证
在后台停止sshd服务
微信告警
申请企业微信
企业微信注册地址:https://work.weixin.qq.com

创建成功后,进入管理后台


企业ID
wwb510050c4fd9ef9c
Secret
JzgsTmWB32UOwH79kuc9WqGLHSy_ILPUCU9A7jrwK9o
编写脚本
[[email protected] zabbix]# cat wechat.sh
#!/bin/bash
CorpID="1000002" # 你的企业id
Secret="JzgsTmWB32UOwH79kuc9WqGLHSy_ILPUCU9A7jrwK9o" #你的SecretID
GURL="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CorpID&corpsecret=$Secret"
Token=$(/usr/bin/curl -s -G $GURL |awk -F\": '{print $4}'|awk -F\" '{print $2}')
# echo $Token
PURL="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$Token"
function body(){
local int agentid=1000002 # 你的agentdid
local UserID="@all" # 发送的用户ID
local PartyID=1 # 部门ID
local Msg=$(echo "[email protected]" | cut -d" " -f3-) # 发送给所有人
printf '{\n'
printf '\t"touser": "'"$UserID"\"",\n" printf '\t"toparty": "'"$PartyID"\"",\n" printf '\t"msgtype": "text",\n' printf '\t"agentid": "'"$agentid"\"",\n" printf '\t"text": {
\n' printf '\t\t"content": "'"$Msg"\""\n" printf '\t},\n' printf '\t"safe":"0"\n' printf '}\n'
}
/usr/bin/curl --data-ascii "$(body $1 $2 $3)" $PURL
[[email protected] zabbix]# chmod +x wechat.sh
[[email protected] zabbix]# cp wechat.sh /usr/lib/zabbix/alertscripts/
创建媒体类型

创建用户组群和用户




操作过程繁琐,详情请见 ‘微信告警’文档,或后续有空更新。
边栏推荐
- Ding Dong grabs vegetables - monitoring and pushing tools for delivery period
- 2022.05.25 (lc_718_longest repeating subarray)
- 写作技术文章是留给自己未来的财富
- 2022.05.28 (lc_5_longest palindrome substring)
- An error row size too large (& gt; 8126) occurs when MySQL's MyISAM engine switches to InnoDB
- 轻松学Pytorch-全卷积神经网络实现表情识别
- Routine solution - the problem of horse walking on the chessboard
- MicroNet实战:使用MicroNet实现图像分类
- 2022.05.24 (lc_674_longest continuous increasing sequence)
- 618大促将至,用AI挖掘差评,零代码实现亿级评论观点情感分析
猜你喜欢

Bit operation topic

Go language learning notes - cross domain configuration, global exception capture | web framework gin (IV)

一文详解EventMesh落地华为云的探索及实践

Summary of "performance test" of special test

Detailed interpretation of tph-yolov5 | making small targets in target detection tasks invisible

Go语学习笔记 - 跨域配置、全局异常捕获 | Web框架Gin(四)

One question to explain the past and present life of dynamic planning

高考后选择哪所学校?VR全景校园全方位展示

During the college entrance examination this year, all examination sites were in good order, and no sensitive cases affecting safety occurred

2022 年 DevOps 路线图|Medium
随机推荐
Complete knapsack problem and optimization tips
用 Plotly 绘制了几张精湛的图表,美翻了!!
Tencent libco collaboration open source library source code analysis full series summary blog
In the all digital era, how can enterprise it complete transformation?
站在今天这样一个时间节点上,或许对产业互联网有一个更加明晰的认识
LLDP协议编写要点
刷脸认证如何实现人脸又快又准完成校验?
用一个性能提升了666倍的小案例说明在TiDB中正确使用索引的重要性
2022 年 DevOps 路线图|Medium
seata 还是不支持sqlserver吗?
4.35V锂电充电IC
一文带你了解J.U.C的FutureTask、Fork/Join框架和BlockingQueue
仅需三步学会使用低代码ThingJS与森数据DIX数据对接
FS2117升压IC输出5V2.4A同步整流
HM3416H降压IC芯片PWM/PFM 控制 DC-DC 降压转换器
Open the door of the hybrid cloud market, Lenovo xcloud's way to break the situation
Easily learn pytoch full convolution neural network to realize expression recognition
户外太阳能野营灯移动电源方案
frp reverse proxy
[advanced C language] data storage [Part 2] [ten thousand words summary]