Пример #1
0
def main():
    global results_queue
    global event_loop
    global pinger
    args = parse_args()
    log_format = '%(asctime)s %(levelname)s:%(module)s:%(funcName)s# ' \
                 + '%(message)s'
    if args.foreground:
        logging.basicConfig(format=log_format, level=args.log_level)
    else:
        log_filename = env.get_env_string('PROBER_LOG_FILE')
        logging.basicConfig(filename=log_filename,
                            format=log_format,
                            level=args.log_level)
    setup_signal_handler()
    results_queue = TQueue()
    unconfirmed_list = []
    hosts = []
    logging.info("Starting ping thread")
    pinger = Pinger(hosts, output=results_queue)
    pinger.start()
    logging.info("Starting event loop")
    event_loop = asyncio.get_event_loop()
    main_task = maintain_collector_connection(results_queue, unconfirmed_list)
    try:
        event_loop.run_until_complete(main_task)
    except KeyboardInterrupt:
        logging.debug("Caught KeyboardInterrupt in main()")
        shutdown()
Пример #2
0
def monitor():
    ping = Pinger()
    ping.thread_count = 4
    while True:
        ping.hosts = pingips()
        nodes=ping.start()
        for ip in nodes['dead']:
            updatedead(ip)
        time.sleep(1)
        os.system("clear")
        select()
Пример #3
0
    def reportAlive(self):
        aliveinfo = AliveInfo()

        ping = Pinger()
        hosts = []
        hosts.append(self.api_conf['public_router'])
        hosts.append(self.api_conf['public_gateway'])
        ex_hosts = []
        ex_hosts.append(self.api_conf['aws'])
        ex_hosts.append(self.api_conf['kt'])
        ex_hosts.append(self.api_conf['legacy'])
        ping.hosts = hosts
        status = ping.start()
        status2 = ping.start()

        if self.api_conf['public_router'] in status['alive'] or self.api_conf[
                'public_router'] in status2['alive']:
            aliveinfo.normal_public_fx = True
            aliveinfo.normal_public_fx_latency = status['alive'][
                self.api_conf['public_router']]
        else:
            aliveinfo.normal_public_fx = False
            aliveinfo.normal_public_fx_latency = status['dead'][
                self.api_conf['public_router']]

        if self.api_conf['public_gateway'] in status['alive'] or self.api_conf[
                'public_gateway'] in status2['alive']:
            aliveinfo.normal_public_fl = True
            aliveinfo.normal_public_fl_latency = status['alive'][
                self.api_conf['public_gateway']]
        else:
            ping.hosts = ex_hosts
            ex_status = ping.start()
            if len(ex_status['alive']) > 0:
                aliveinfo.normal_public_fl = True
                if ex_status['alive'].has_key(self.api_conf['aws']):
                    aliveinfo.normal_public_fl_latency = ex_status['alive'][
                        self.api_conf['aws']]
                elif ex_status['alive'].has_key(self.api_conf['kt']):
                    aliveinfo.normal_public_fl_latency = ex_status['alive'][
                        self.api_conf['kt']]
                elif ex_status['alive'].has_key(self.api_conf['legacy']):
                    aliveinfo.normal_public_fl_latency = ex_status['alive'][
                        self.api_conf['legacy']]
                else:
                    aliveinfo.normal_public_fl_latency = -1
            else:
                aliveinfo.normal_public_fl = False
                aliveinfo.normal_public_fl_latency = ex_status['dead'][
                    self.api_conf['aws']]

        aliveinfo.wmi_private_fx = None
        aliveinfo.wmi_private_fl = None
        aliveinfo.wmi_public_fx = None
        aliveinfo.wmi_public_fl = None

        #influx_container = "tc_npath_monitor,host=%s normal_public_fx=%d,normal_public_fl=%d,normal_public_fx_latency=%.4f,normal_public_fl_latency=%.4f" %(self.data['name'], aliveinfo.normal_public_fx,
        #aliveinfo.normal_public_fl,
        #aliveinfo.normal_public_fx_latency,
        #aliveinfo.normal_public_fl_latency)

        metric = "normal_npath"
        json_body = [{
            "measurement": metric,
            "tags": {
                "host": self.data['name'],
            },
            "fields": {
                "normal_public_fx":
                aliveinfo.normal_public_fx,
                "normal_public_fl":
                aliveinfo.normal_public_fl,
                "normal_public_fx_latency":
                round(aliveinfo.normal_public_fx_latency, 3),
                "normal_public_fl_latency":
                round(aliveinfo.normal_public_fl_latency, 3)
            }
        }]
        self.influxdb_client.write_points(json_body)
        #print influx_container
        #headers = { "Content-Type" : "text/plain"}
        #headers = {}
        #postData(DB_URL,influx_container,headers)

        ret = self.tcrpc.reportAlive(self.data['uuid'], aliveinfo)

        return ret