码迷,mamicode.com
首页 > 微信 > 详细

沃云vertica集群微信监控

时间:2018-07-12 20:18:50      阅读:20      评论:0      收藏:0      [点我收藏+]

标签:fail   gen   ipad   access   ash   宕机   imp   data   bre   

 

#!/bin/bash
/usr/bin/python <<EOF
#!/usr/bin/env python
# coding:utf-8

import re
import os
import urllib2
import json

def qywxSendTextMsg(text_msg):
    agentid = 1000003
    corpid = "wwcc772268cf665691"
    secret = "_gWmEzT4NXwJX30IZ2TiUnnfdulBbC9_2q8GcbQukAQ"
    # --- 创建连接 --- #
    login_url = r"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={0}&corpsecret={1}".format(corpid, secret)
    access_token = json.loads(urllib2.urlopen(urllib2.Request(login_url)).read())[access_token]

    print("access_token:"+access_token)

    send_url = rhttps://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={0}.format(access_token)
    msg = {
            "touser": "@all",
            "toparty": "",
            "totag": "",
            "msgtype": "text",
            "agentid": agentid,
            "text": {
                "content": text_msg
            },
            "safe": 0
        }
    msg_json = json.dumps(msg).encode(utf-8)
    respone = urllib2.urlopen(url=send_url, data=msg_json).read()
    print("responce:"+str(respone))
    x = json.loads(respone.decode())[errcode]
    if x == 0:
        print(Succesfully)
    else:
        print(Failed)


# with open(‘con.txt‘, ‘r+‘) as f1:
#     textL = f1.readlines()

ipL = [172.16.10.2, 172.16.10.22, 172.16.10.23]
for ipaddr in ipL:
    print("ipaddr:"+ipaddr)
    recode = os.system("ping -c 1 {0} > /dev/null".format(ipaddr))
    print("recode:"+str(recode))
    if not recode:
        textL = os.popen(‘‘‘ssh [email protected]{0} "su - dbadmin -c ‘admintools -t list_allnodes‘"‘‘‘.format(ipaddr)).readlines()
        print(‘‘.join(textL))
        for i, j in enumerate(textL):
            if re.findall(rnode, j):
                resL = re.findall(rUP, j)
                if not resL:
                    qywxSendTextMsg(‘‘.join(textL))
                    break
        exit(0)

text = "vertica三节点服务器全部宕机!"
qywxSendTextMsg(text)
EOF

 

沃云vertica集群微信监控

标签:fail   gen   ipad   access   ash   宕机   imp   data   bre   

原文地址:https://www.cnblogs.com/sorliran/p/9300981.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 mamicode.com 版权所有 京ICP备13008772号-2
迷上了代码!