Python监控es集群状态

import os
from urllib import request
import requests
import datetime
import json


index_time = (datetime.datetime.now() + datetime.timedelta(days=-0)).strftime("%H%M")
if index_time == '0800':
    exit()

###运维钉钉监控
headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "http://oapi.dingtalk.com/robot/send?access_token=4ff92016951904d668485d760efef44a4012f1ea605ece99fe83168ccf4477a6"
ip = ['172.16.196.66', '172.16.196.67', '172.16.196.68']

username = 'elastic'
password = 'XORPossw0rd123!'

for x in ip:
    try:
        url = 'http://%s:9200/_cat/health?'%(x)
        zt = str(requests.get(url, auth=(username, password)).content).rstrip('\n')
        zj = zt.rstrip('\n').split()[3]
        if zj == "green":
            pass
        elif zj == "yellow":
            json_text = {"msgtype": "text", "at": {"isAtAll": "true"},"text": {"content": "一体化ES集群,状态为yellow" %(ip)}}
            requests.post(api_url, json.dumps(json_text), headers=headers).content
        else:
            json_text = {"msgtype": "text", "at": {"isAtAll": "true"},"text": {"content": "一体化ES集群,状态为red" %(ip)}}
            requests.post(api_url, json.dumps(json_text), headers=headers).content
        break
    except:
        json_text = {"msgtype": "text", "at": {"isAtAll": "true"},"text": {"content": "一体化ES集群%s节点状态异常,请检查!" % (x)}}
        requests.post(api_url, json.dumps(json_text), headers=headers).content

如上代码:分别监控了es集群状态

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值