zabbix脚本告警和自定义监控

邮箱告警方式
1.在web界面配置
2.用系统账户发送邮件(要装mailx包)
3.用第三方邮件发送邮件(要装mailx包,要配置/etc/mail.rc)
自定义监控:
1.写脚本把想监控的资源取出卡
2.在agent配置文件中启用自定义监控功能
UnsafeUserParameters=1
UserParameter=key[*],/bin/bash /path/to/script_name $1
3.重启服务
4.配置web界面添加监控项
5.添加触发器

T=last()

zabbix脚本警告

1、下载mailx包

[root@localhost ~]# yum -y install mailx
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
此处省略。。。。
  验证中      : mailx-12.5-19.el7.x86_64                                                    1/1 

已安装:
  mailx.x86_64 0:12.5-19.el7                                                                    

完毕!
[root@localhost ~]# echo "linux" |mail -s 'this is a text' 1353668411@qq.com

2.创建媒介
在这里插入图片描述
3.编写脚本

[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d
[root@localhost etc]# vim zabbix_server.conf
[root@localhost etc]# mkdir -p /usr/local/etc/zabbix/alertscripts
[root@localhost etc]# ls
zabbix  zabbix_agentd.conf  zabbix_agentd.conf.d  zabbix_server.conf  zabbix_server.conf.d
[root@localhost etc]# ls zabbix
alertscripts
[root@localhost etc]# cd zabbix/alertscripts/
[root@localhost alertscripts]# pwd
/usr/local/etc/zabbix/alertscripts
[root@localhost alertscripts]# touch sendmail.sh
[root@localhost alertscripts]# ll
总用量 0
-rw-r--r-- 1 root root 0 7月  23 09:38 sendmail.sh
[root@localhost alertscripts]# chmod +x sendmail.sh
[root@localhost alertscripts]# ll
总用量 0
-rwxr-xr-x 1 root root 0 7月  23 09:38 sendmail.sh
[root@localhost alertscripts]# vim sendmail.sh
[root@localhost alertscripts]# ./sendmail.sh "hello world \r\nhehe" "123456" 1353668411@qq.com
[root@localhost alertscripts]# vim sendmail.sh
您在 /var/spool/mail/root 中有新邮件
[root@localhost alertscripts]# cat sendmail.sh
#!/bin/bash

SUBJECT=$(echo $2 |tr "\r\n" "\n")
MESSAGE=$(echo $1 |tr "\r\n" "\n")

echo "$MESSAGE" | /usr/bin/mail -s "$SUBJECT" $3
[root@localhost alertscripts]# cd
[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# ll
总用量 40
drwxr-xr-x  3 root root    26 7月  23 09:37 zabbix
-rw-r--r--. 1 root root 14988 7月  22 13:29 zabbix_agentd.conf
drwxr-xr-x. 2 root root     6 7月  22 13:29 zabbix_agentd.conf.d
-rw-r--r--  1 root root 21345 7月  23 09:37 zabbix_server.conf
drwxr-xr-x. 2 root root     6 7月  22 13:29 zabbix_server.conf.d
[root@localhost etc]# chown -R zabbix.zabbix zabbix
[root@localhost etc]# ll zabbix
总用量 0
drwxr-xr-x 2 zabbix zabbix 25 7月  23 09:50 alertscripts
[root@localhost etc]# pkill zabbix
[root@localhost etc]# zabbix_server
[root@localhost etc]# zabbix_agentd
[root@localhost etc]# ss -antl
State      Recv-Q Send-Q   Local Address:Port                  Peer Address:Port              
LISTEN     0      128                  *:22                               *:*                  
LISTEN     0      100          127.0.0.1:25                               *:*                  
LISTEN     0      128                  *:10050                            *:*                  
LISTEN     0      128                  *:10051                            *:*                  
LISTEN     0      128                  *:9000                             *:*                  
LISTEN     0      80                  :::3306                            :::*                  
LISTEN     0      128                 :::80                              :::*                  
LISTEN     0      128                 :::22                              :::*                  
LISTEN     0      100                ::1:25                              :::*                  
[root@localhost etc]# 

配置媒介
在这里插入图片描述
在这里插入图片描述
4.添加用户
在这里插入图片描述
5.添加动作
在这里插入图片描述
显示动作
在这里插入图片描述

zabbix自定义监控

编写脚本

[root@localhost ~]# ps -ef|grep postfix
root       1490      1  0 05:35 ?        00:00:00 /usr/libexec/postfix/master -w
postfix    1514   1490  0 05:35 ?        00:00:00 qmgr -l -t unix -u
postfix    6867   1490  0 08:59 ?        00:00:00 pickup -l -t unix -u
root      94692  93791  0 10:22 pts/2    00:00:00 grep --color=auto postfix
[root@localhost ~]# ps -ef|grep postfix|grep -v grep
root       1490      1  0 05:35 ?        00:00:00 /usr/libexec/postfix/master -w
postfix    1514   1490  0 05:35 ?        00:00:00 qmgr -l -t unix -u
postfix    6867   1490  0 08:59 ?        00:00:00 pickup -l -t unix -u
[root@localhost ~]# ps -ef|grep postfix|grep -v grep|wc -l
3
[root@localhost ~]# mkdir /scripts
[root@localhost ~]# cd /scripts/
[root@localhost scripts]# chmod +x check_process.sh
[root@localhost scripts]# vim check_process.sh
[root@localhost scripts]# cat check_process.sh
#!/bin/bash

process_status=$(ps -ef|grep $1|grep -Ev "grep|$0" |wc -l)
echo $process_status

[root@localhost scripts]# ./check_process.sh postfix
3
[root@localhost scripts]# vim check_process.sh   (下面的0和1表示状态,0表示正常)

[root@localhost scripts]# cat check_process.sh
#!/bin/bash

process_status=$(ps -ef|grep $1|grep -Ev "grep|$0" |wc -l)
if  [ $process_status -eq 0 ];then
    echo '1'
else 
    echo '0'
fi

[root@localhost scripts]# ./check_process.sh postfix
0
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf 编辑下面图片内容
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd

在这里插入图片描述
在这里插入图片描述
服务端验证

[root@localhost etc]# zabbix_get -s 192.168.175.150 -k check_process 
0      结果显示0即为正常

修改

[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_agentd

在这里插入图片描述
服务端验证

[root@localhost etc]# zabbix_get -s 192.168.175.150 -k check_process[postfix]
0

添加items
在这里插入图片描述
在这里插入图片描述
添加触发器
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值