监控巡检redis sentinel

# coding: utf-8
import json
import requests
import logging
import os,subprocess

#################public_sentinel_idc_a#############
# '10.0.0.1'','10.0.0.2,'10.0.0.3'
################public_sentinel_idc_b###############
#  '10.1.0.1'','10.1.0.2,'10.1.0.3'
################public_sentinel_idc_c###############
#  '10.2.0.1'','10.2.0.2,'10.2.0.3'

public_sentinels = (''10.0.0.1'','10.0.0.2,'10.0.0.3', '10.1.0.1'','10.1.0.2,'10.1.0.3', '10.2.0.1'','10.2.0.2,'10.2.0.3')

webhook_test = 'https://sd.a.cn/api/v1/webhook/send?key=xxxxxx'
webhook_redis = 'https://sd.a.cn/api/v1/webhook/send?key=ccccccc'

def run_shell(cmd, debug=False):
    if debug:
        logging.info('Print command but not actually run: %s' % cmd)
        return None, None

    result = os.popen(cmd).read()
    return result.strip()

def render_webhook_msg(msg):
    res_msg2 = {
    "msgtype":"markdown",
    "markdown": {
        "text": " ### sre主从redis公共sentinel巡检异常 ### \n\n  列表如下:"+str(msg)+"<at user_id=\"fhsjfhksfs\">张三</at>"
    }
}
    return res_msg2

def send_webhook(msg):  
    #req=requests.post(webhook_test,data=json.dumps(msg))
    req=requests.post(webhook_redis,data=json.dumps(msg))
    if req.status_code == 200:
        return req.json()
    else:
        "go back to response"

if __name__ == "__main__":
    err_list = []
    for node in public_sentinels:
        cmd = "/usr/bin/redis-cli --no-auth-warning -h {0} -p 26379 ping".format(node)
        res = run_shell(cmd)
        if res != "PONG":
            print(res)
            err_list.append(node)

    if len(err_list) >0 :
        msg = render_webhook_msg(err_list)
        send_webhook(msg)
    else:
        print("ksre主从redis公共sentinel 巡检正常")
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇
Secured By miniOrange