python 飛書告警監控

探測Nginx 服務監控

#coding: utf-8
import requests,json,os,time

def Alarm(img):
    data = {
            "msg_type": "interactive",
            "card": {
                "elements": [{
                    "tag": "div",
                    "text": {
                        "content": "<font color='grey'> **%s** </font>"  %img,
                        "tag": "lark_md",
                    }
                } ,{
                    "tag": "div",
                    "text": {
                        "content": "<font color='grey'> %s-- </font>" %content,
                        "tag": "lark_md"
                    }
                } , {
                    "tag": "div",
                    "text": {
                        "content": "告警平臺: 來機房\n告警級別: critical\n運維團隊: 影x運維\n故障實例: %s\n描述信息: %s"  %(content,content),
                        "tag": "lark_md"
                    }
                }, ],
                "header": {
                    "title": {
                        "content": "影x科技監控告警通知",
                        "tag": "plain_text"
                    },
                    "template": "red"
                }
            }
    }
    url='https://open.feishu.cn/open-apis/bot/v2/hook/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    header = {
        'Content - Type': 'application / json'
    }
    data = json.dumps(data)
    return requests.post(url,data,header)

def CheckNginx():
  process = os.popen('ps -ef |grep nginx |grep -v "grep"|wc -l')
  process_num = int(process.read())
  print(type(process_num),process_num)
  return process_num
  


if __name__ =="__main__":
  process_num = CheckNginx()
  if process_num == 0:
    content = "Nginx 服務異常"
    img = "Nginx 服務告警信息"
    Alarm(img)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章