Zabbix 4.0 - 钉钉告警
/

Zabbix 4.0 - 钉钉告警

SOSO
2022-04-19 / 0 评论 / 104 阅读 / 正在检测是否收录...

1. 钉钉告警 python脚本一

#!/usr/bin/python3
# coding: utf-8
import requests
import json
import sys
import os
import time
import hmac
import hashlib
import base64
import urllib.parse

timestamp = str(round(time.time() * 1000))
secret = 'SECRET' #密钥
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))

headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "Webhook地址&timestamp={0}&sign={1}".format(timestamp,sign)

def msg(text):
   json_text= {
    "msgtype": "text",
    "text": {
        "content": text
    }
   }
   print(requests.post(api_url,json.dumps(json_text),headers=headers).content)
if __name__ == '__main__':
   text = sys.argv[1]
   msg(text)

2. 钉钉告警 python脚本二

#!/usr/bin/python3
# -*- coding: utf-8 -*-

import json
import sys
import os
import requests
import time
import hmac
import hashlib
import base64
import urllib.parse

timestamp = str(round(time.time() * 1000))
secret = 'Secert'  #密钥
secret_enc = secret.encode('utf-8')
string_to_sign = '{}\n{}'.format(timestamp, secret)
string_to_sign_enc = string_to_sign.encode('utf-8')
hmac_code = hmac.new(secret_enc, string_to_sign_enc, digestmod=hashlib.sha256).digest()
sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))

headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "Webhook地址&timestamp={0}&sign={1}".format(timestamp,sign)


def msg(text):
    json_text= {
     "msgtype": "text",
        "text": {
            "content": text
        },
        "at": {
            "atMobiles": [
                "131xxxx6362"   #在群里@该手机用户
            ],
            "isAtAll": False
        }
    }
    print (requests.post(api_url,json.dumps(json_text),headers=headers).content)

if __name__ == '__main__':
    text = sys.argv[1]
    msg(text)
0

评论

博主关闭了当前页面的评论