钉钉告警发送

 1#!/usr/bin/env python
 2#coding:utf-8
 3
 4#zabbix钉钉报警
 5import requests
 6import json
 7import sys
 8import os
 9import datetime
10
11#这里是自己创建的机器人的webhook
12webhook="https://oapi.dingtalk.com/robot/send?access_token=xxxxxx"      
13
14user=sys.argv[1]
15text=sys.argv[3]
16data={
17    "msgtype": "text",
18    "text": {
19        "content": text
20    },
21    "at": {
22        "atMobiles": [
23            user
24        ],
25        "isAtAll": False
26    }
27}
28headers = {'Content-Type': 'application/json'}
29x=requests.post(url=webhook,data=json.dumps(data),headers=headers)

下面放shell脚本的

 1#!/bin/bash
 2 
 3function ddmsg() {
 4    Token="xxxxxxxxxxxx"
 5    Weburl="https://oapi.dingtalk.com/robot/send?access_token="
 6    curl -ks -m 2 "${Weburl}${Token}" \
 7        -H 'Content-Type: application/json;charset=utf-8' \
 8        -d "{'msgtype': 'text', 
 9             'text': { 'content': '$*'}
10        }" &>/tmp/ddmsg.log
11    if [ `grep "errmsg.*ok" /tmp/ddmsg.log |wc -l` -ne 1 ]; then
12        echo 'send error !';cat /tmp/ddmsg.log;exit 1;
13    fi
14}
15
16#测试内容
17echo "@警报
18主机:$(hostname)
19信息:Node test
20时间:$(date +"%F %T")
21">.msg
22
23cat .msg
24ddmsg "`cat .msg`"

Freelancer之aws
Kubernetes使用nfs做持久化卷存储
comments powered by Disqus