当前位置:网站首页>Zabbix_监控ssh/crond服务-微信告警

Zabbix_监控ssh/crond服务-微信告警

2022-06-10 19:01:00 这个手刹不太灵儿

监控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/

创建媒体类型

在这里插入图片描述

创建用户组群和用户

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
操作过程繁琐,详情请见 ‘微信告警’文档,或后续有空更新。

原网站

版权声明
本文为[这个手刹不太灵儿]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_40887651/article/details/125139634