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/02 Report--
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 the local to the remote end, encryption needs to be configured in advance. The script is executed by zabbix users. The security policy of the Web server directory had better be set up #! / 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 the request def send_msg (pname_url) to send the message 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 the alarm message 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 type of alarm medium to open zabbix monitoring web In the administration menu, select the alarm media type, 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.
Welcome to the personal account "Master Chen without Story"
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.