In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to configure Zabbix with picture alarm function, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The idea of realization is:
First of all, there must be itemid in the alarm message, which is the premise. According to the parameters passed in the message, use regular matching to itemid to build a session session, or use cookie to log in, request the picture according to itemid, and save the obtained picture locally. Because the picture link of markdown needs to be accessed, my zabbix is in the intranet, so you need to send the picture to the picture bed or to a web server with public network IP. I sent it to my personal server to convert the alarm information into markdown syntax format to construct a request to set up a nailing robot using the webhook message of the nail.
The nailing robot needs to make security settings. Here I define the keyword "notification", that is, the word must be included in the message sent.
Script implementation due to the need to copy images from local to remote, encryption needs to be configured in advance. The script is executed by zabbix users. It is best to set the security policy of the Web server directory.
#! / usr/bin/python#-*-coding: utf-8-*-import requests,timeimport json,sys,re,oszabbixserver_url = 'http://192.168.99.200/index.php'# defines the remote web server address Copy the image to the remote web directory under the pname_path=' http://47.103.15.51/dingding_pic/'# definition to get the image address testUrl = "http://192.168.99.200/chart.php"host='192.168.99.200'def get_itemid (): itemid=re.search (r'ITEM ID: (\ d +)', sys.argv [2]) .group (1) return itemiddef get_picture (itemid,pname): # build session Or you can use cookie to log in to myRequests = requests.Session () try: loginHeaders = {"Host": host, "Accept": "text/html,application/xhtml+xml,application/xml" after a build Qcoach 0.9 imageCharpy webpCharge imageUniverse apngMagneTime * PlayLoad = {"name": "Admin", "password": 'zabbix', "autologin": "1", "enter": "Sign in",} myRequests.post (url=zabbixserver_url, headers=loginHeaders, data=playLoad) testUrlplayLoad = {"from": "now-10m", "to": "now", "itemids": itemid "width": "700",} testGraph = myRequests.get (url=testUrl,params=testUrlplayLoad) IMAGEPATH = os.path.join ('/ usr/lib/zabbix/alertscripts/dingding_pic/', pname) # write the acquired image data to the file to with open (IMAGEPATH) 'wb') as f: f.write (testGraph.content) os.system ("sudo scp% s root@47.103.15.51:/usr/share/nginx/html/dingding_pic"% IMAGEPATH) pname_url = pname_path+pname return pname_url except Exception as e: print (e) return False# construct a request to send a message def send_msg (pname_url,info3): headers = {' Content-Type': 'application/json Charset=utf-8'} print (info3) data = {"msgtype": "markdown", "markdown": {"title": info1, "text": "# # Notification:\ n" + info3+ "! [screenshot] (% s)\ n"% (pname_url)}, "at": {"atMobiles": reminders, "isAtAll": False,},} r = requests.post (url=webhook_url,json=data) Headers=headers) print (r.text) # format alarm messages def info_text (): new_text = "" x = info2.split ('\ n') for i in x: if re.search ('ITEM ID' Str (I): pass else: new_text+= "-" + str (I) + ('\ n') print (type (new_text)) return new_textif _ _ name__ = ='_ _ main__': # write alarm information to the log os.system ("echo hello > > / tmp/syslog.md") pname = str (int (time.time () + '.png' info1 = str (sys.argv [ 1]) info2 = str (sys.argv [2]) info3 = info_text () with open ('/ tmp/syslog.md' 'a') as f: f.write (info1) f.write (info2) f.close () reminders = [] webhook_url = 'https://oapi.dingtalk.com/robot/send?access_token=771ded387e6be652c51a2b6c83cade4e048e3da4fdfe128f1db6b124b87df18a' itemid = get_itemid () pname_url=get_picture (itemid,pname) print (pname_url) send_msg (pname_url,info3)
Define the alarm media type to open the zabbix monitoring web, select the alarm media type in the management menu, create the media type, select the script, fill in the name of the email script you just wrote, zabbix_email_pic.py, script parameters, and finally add
Open the user in the management, click the user who needs to set the email alarm, then add the alarm medium to the alarm medium, select the type just defined in the pop-up box, customize the recipient, and finally add
Define alarm action
Click the actions in the configuration menu, create the actions, and then fill in them according to the picture.
Operation default title Zabbix alarm Beijing: server: {HOSTNAME} occurs: {TRIGGER.NAME} failure! ITEMID: {ITEM.ID} alarm host: {HOST.NAME} alarm host: {HOST.IP} alarm time: {EVENT.DATE} {EVENT.TIME} alarm level: {TRIGGER.SEVERITY} alarm message: {TRIGGER.NAME} alarm item: {TRIGGER.KEY} question details: {ITEM.NAME}: {ITEM.VALUE} when Previous status: {TRIGGER.STATUS}: {ITEM.VALUE} event ID: {EVENT.ID} recovery operation Zabbix alarm Beijing: server: {HOST.NAME} occurred: {TRIGGER.NAME} restored! ITEMID: {ITEM.ID} alarm host: {HOST.NAME} alarm host: {HOST.IP} alarm time: {EVENT.DATE} {EVENT.TIME} alarm level: {TRIGGER.SEVERITY} alarm information: {TRIGGER.NAME} alarm Project: {TRIGGER.KEY} question details: {ITEM.NAME}: {ITEM.VALUE} current status: {TRIGGER.STATUS}: {ITEM.VALUE} event ID: {EVENT.ID}
Final effect
An alarm test effect can be triggered manually.
At this point, the Wechat, mailbox and nail alarm with pictures of zabbix have all been configured.
The above is all the contents of the article "how to configure Zabbix with picture alarm function". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.