python监控ELK kibana 页面是否正常的脚本

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

import urllib2
import os,time,urllib2,urllib

test = "test"

password = "1234@DJ"

webserver = "xx.xx.xx.xx"

def work():
    #构建一个密码管理对象,可以用来保存和http请求相关的授权账户信息
    passwordMgr = urllib2.HTTPPasswordMgrWithDefaultRealm()

    #添加授权账户信息,第一个参数realm如果没有指定就写None,后三个分别是站点IP,账户和密码
    passwordMgr.add_password(None,webserver, test, password)

    httpauth_handler = urllib2.HTTPBasicAuthHandler(passwordMgr)

    opener = urllib2.build_opener(httpauth_handler)

    request = urllib2.Request("http://xx.xx.xx.xx/app/kibana/")
    #response = opener.open(request)

    try:
        opener.open(request)
    except urllib2.URLError,e:
        msg1="ELK is down"
        return msg1

def Send_Sms(mobile,msg):
#  f = file('d:/testlist.txt','w+')
  for phone in mobile:
    sms_url = 'http://xx.xx.xx.xx:xx/api/sms?mobiles=%s&content=' %(phone) + urllib.quote(msg)
    print sms_url
    urllib2.urlopen(sms_url)


if __name__ == '__main__':
    msg = work()
    #print msg 
    Pho_Num = ['XXXXXXXXXXX']
    if not msg is None:
        #print msg
        Send_Sms(Pho_Num,msg)
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值