예제 #1
0
    def packet_drop_api(self):
        end = int(time.time() * 1000)
        begin = end - 10 * 60 * 1000   # latest 10 min
        url = 'http://{0}/api/web/packet_drop/?begin={1}&end={2}'.format(self.host, begin, end)
        my_headers = {
                    'Accept': 'application/json, text/javascript, */*; q=0.01',
                    'Accept-Encoding': 'gzip, deflate, br',
                    'Cache-Control': 'no-cache',
                    'Connection': 'keep-alive',
                    'Host': self.host,
                    'Referer': self.url_prefix + '/index.html',
                    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
                    'X-Requested-With': 'XMLHttpRequest',
                    }
        '''
        {"error":"OK","results":[[1579441355398,1.8],[1579441415398,3.6],[1579441475398,0.0]],"status":0}
        '''

        results = None
        try:
            res = self.ss.get(url, headers = my_headers)
            if res.status_code == 200:
                results = res.json().get('results')
        except Exception as e:
            slog.warning("catch exception:{0}".format(e))

        slog.debug("get result:{0}".format(json.dumps(results)))
        return results
예제 #2
0
    def node_info_api(self):
        url = 'http://{0}/api/web/node_info/?status=offline'.format(self.host)
        my_headers = {
                    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
                    'Accept-Encoding': 'gzip, deflate, br',
                    'Cache-Control': 'no-cache',
                    'Connection': 'keep-alive',
                    'Host': self.host,
                    'Referer': self.url_prefix + '/index.html',
                    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36',
                    }
        '''
        {"error":"OK","results":{"node_info":[],"node_size":0},"status":0}
        '''

        results = None
        try:
            res = self.ss.get(url, headers = my_headers)
            if res.status_code == 200:
                results = res.json().get('results')
        except Exception as e:
            slog.warning("catch exception:{0}".format(e))

        slog.debug("get result:{0}".format(json.dumps(results)))
        return results
예제 #3
0
def run_page(topargus, mbot):
    slog.debug("run_page alive")
    subject = 'TOPARGUS 常规定时监控'
    contents = [
        'TOPARGUS_host: {0}'.format(topargus.default_index()),
        'TOPARGUS_name: {0}'.format(topargus.get_topargus_name()),
        'TOPARGUS_info: {0}'.format(topargus.get_topargus_net_info()),
    ]

    ret = topargus.home()
    ret = list(ret)
    if len(ret) == 2 and ret[1] != None:
        if ret[1].endswith('png'):  # picture
            pic = mbot.make_pic_inline(ret[1])
            contents.append("[首页]")
            contents.append(pic)
            contents.append("\n\n\n")

    ret = topargus.alarm()
    ret = list(ret)
    if len(ret) == 2 and ret[1] != None:
        if ret[1].endswith('png'):  # picture
            pic = mbot.make_pic_inline(ret[1])
            contents.append("[告警页面]")
            contents.append(pic)
            contents.append("\n\n\n")

    ret = topargus.packet()
    ret = list(ret)
    if len(ret) == 2 and ret[1] != None:
        if ret[1].endswith('png'):  # picture
            pic = mbot.make_pic_inline(ret[1])
            contents.append("[收包情况]")
            contents.append(pic)
            contents.append("\n\n\n")

    ret = topargus.network()
    ret = list(ret)
    if len(ret) == 2 and ret[1] != None:
        if ret[1].endswith('png'):  # picture
            pic = mbot.make_pic_inline(ret[1])
            contents.append("[P2P网络]")
            contents.append(pic)
            contents.append("\n\n\n")

    contents.append("MAIL END")
    ret = mbot.send_mail(CONFIG.get('target_email_adr'), subject, contents)
    if ret:
        slog.info('send alarm_api mail to {0} ok'.format(
            json.dumps(CONFIG.get('target_email_adr'))))
        return True
    else:
        slog.warning('send alarm_api mail to {0} error'.format(
            json.dumps(CONFIG.get('target_email_adr'))))
        return False
예제 #4
0
def run_api(topargus, mbot):
    '''
    def alarm_api(self):
    def node_info_api(self):
    def packet_drop_api(self):
    '''
    slog.debug("run_api alive")
    subject = 'TOPARGUS 高优先级告警事件!'
    contents = [
        'TOPARGUS_host: {0}'.format(topargus.default_index()),
        'TOPARGUS_name: {0}'.format(topargus.get_topargus_name()),
        'TOPARGUS_info: {0}'.format(topargus.get_topargus_net_info()),
    ]

    results = topargus.alarm_api()
    if results:
        #if results.get('system_alarm_info') and len(results.get('system_alarm_info')) > 0:
        if True:
            slog.warning('get alarm high level info')
            ret = topargus.alarm(high=True)  # (True, filename)
            ret = list(ret)
            if len(ret) == 2 and ret[1] != None:
                if ret[1].endswith('png'):  # picture
                    pic = mbot.make_pic_inline(ret[1])
                    contents.append("[节点离线]")
                    contents.append(pic)
                    contents.append("\n\n\n")

    results = topargus.node_info_api()
    if results:
        #if results.get('node_info') and len(results.get('node_info')) > 0:
        if True:
            slog.warning('get offline node_info')
            contents.append("[离线节点列表]")
            contents.append(json.dumps(results.get('node_info')))
            contents.append("\n\n\n")

    # results = topargus.packet_drop_api()

    contents.append("MAIL END")
    ret = mbot.send_mail(CONFIG.get('target_email_adr'), subject, contents)
    if ret:
        slog.info('send alarm_api mail to {0} ok'.format(
            json.dumps(CONFIG.get('target_email_adr'))))
        return True
    else:
        slog.warning('send alarm_api mail to {0} error'.format(
            json.dumps(CONFIG.get('target_email_adr'))))
        return False
예제 #5
0
def run_page(topargus, mbot):
    slog.debug("run_page alive")
    subject = 'TOPARGUS 常规定时监控'
    contents = [
            'TOPARGUS_host: {0}'.format(topargus.default_index()),
            'TOPARGUS_name: {0}'.format(topargus.get_topargus_name()),
            'TOPARGUS_info: {0}'.format(topargus.get_topargus_net_info()),
            ]

    ret = topargus.home()
    ret = list(ret)
    if len(ret) == 2 and ret[1] != None:
        if ret[1].endswith('png'):  # picture
            pic = mbot.make_pic_inline(ret[1])
            contents.append("[首页]")
            contents.append(pic)
            contents.append("\n\n\n")

            # add for dingtalk robot
            mainnet_html_dir = '/usr/local/smaug/nginx/webapp/mainnet/home.png'
            from shutil import copyfile
            copyfile(ret[1], mainnet_html_dir)
            mainnet_url = 'http://142.93.126.168/mainnet/home.png'
            markdown_text = '''## 全网丢包率情况\n
![](http://142.93.126.168/mainnet/home.png)\n
详情查看: [http://smaug:[email protected]/index.html](http://smaug:[email protected]/index.html)'''
            send_info_dingding(markdown_text, None):


    ret = topargus.alarm()
    ret = list(ret)
    if len(ret) == 2 and ret[1] != None:
        if ret[1].endswith('png'):  # picture
            pic = mbot.make_pic_inline(ret[1])
            contents.append("[告警页面]")
            contents.append(pic)
            contents.append("\n\n\n")

    ret = topargus.packet()
    ret = list(ret)
    if len(ret) == 2 and ret[1] != None:
        if ret[1].endswith('png'):  # picture
            pic = mbot.make_pic_inline(ret[1])
            contents.append("[收包情况]")
            contents.append(pic)
            contents.append("\n\n\n")

    ret = topargus.network()
    ret = list(ret)
    if len(ret) == 2 and ret[1] != None:
        if ret[1].endswith('png'):  # picture
            pic = mbot.make_pic_inline(ret[1])
            contents.append("[P2P网络]")
            contents.append(pic)
            contents.append("\n\n\n")

    contents.append("MAIL END")
    ret = mbot.send_mail(CONFIG.get('target_email_adr'), subject, contents)
    if ret:
        slog.info('send alarm_api mail to {0} ok'.format(json.dumps(CONFIG.get('target_email_adr'))))
        return True
    else:
        slog.warning('send alarm_api mail to {0} error'.format(json.dumps(CONFIG.get('target_email_adr'))))
        return False