在agent上添加 UserParameter=auth.check,/etc/zabbix/auth_monitor/auth_check.py
auth.check就是之后添加的自定义的item值。脚本返回0/1,做trigger报警用
#!/usr/bin/env python #_*_coding:utf-8_*_ import os,sys,time import smtplib from email.mime.text import MIMEText from email.header import Header from email.utils import formatdate hostName="xxxxx" res_str = os.popen("java -jar /etc/zabbix/auth_monitor/loginMonitor.jar") res = res_str.read().strip().split("\n") success_status = [‘xxxxx‘,‘xxxxx‘] def sendMail(mTitle,mes): receiver = ["[email protected]","[email protected]"] encoding = "utf-8" message = MIMEText("巡检主机:\n" + hostName + "\n\n" + "auth check error:" + mes, ‘plain‘, ‘utf-8‘) message[‘Subject‘] = Header(mTitle, encoding) message[‘From‘] = "[email protected]" message[‘To‘] = ", ".join(receiver) message[‘Date‘] = formatdate() try: smtpObj = smtplib.SMTP_SSL(‘smtp.exmail.qq.com‘, 465) smtpObj.ehlo() smtpObj.login(‘[email protected]‘, ‘xxxxxxx‘) smtpObj.sendmail(‘[email protected]‘, receiver, message.as_string()) #print "send mail success" except Exception: print "send mail error" def auth_status(): if success_status == res: #sendMail("【auth0 巡检告警】auth不异常!",str(res)) statuscode = 1 return statuscode else: sendMail("【auth 巡检告警】auth异常!",res) statuscode = 0 return statuscode i = auth_status() print i
trigger
创建新的报警触发器 create trigger
点击Expression constructor 开始创建监控条件
添加新到条件
原文地址:https://www.cnblogs.com/dribs/p/11776262.html
时间: 2024-11-09 01:06:21