def send_sms_mess(data): mess = {"body": data, "phone": conf_data("sms_conf","admin_phone")} work_log.info("send sms mess:") work_log.info(str(mess)) try: sms_api = conf_data('sms_conf', 'api') r = requests.get(sms_api, params=mess, timeout=5) code = r.status_code if code == 200: work_log.info("send sms sesscue") r.close() except Exception as e: work_log.error("request sms api error") work_log.error(str(e))
def run_network_tcp_port_task(self): tcp_service = conf_data("network_tcp") work_log.info("run_network_tcp_port_task -------- start") mess = {} for service_name in tcp_service: pool = ThreadPool(50) result = [] for addr in tcp_service.get(service_name): result.append(pool.apply_async(self.port_check, (addr, ))) pool.close() pool.join() Display = [] for res in result: vle = res.get() if vle != 0: Display.append(vle) mess[service_name] = Display new_data = { "mess_type": 102, "mess_code": 2011, "type": "tcp_service", "body": mess, "ctime": time.strftime("%Y-%m-%d %H:%M:%S"), } send_mess_udp(new_data) work_log.debug("send data success") work_log.debug(str(new_data)) work_log.info("run_network_tcp_port_task -------- end")
def __init__(self): super(RedisQueue, self).__init__() redis_conf = conf_data("redis") redis_host = redis_conf.get("host") redis_port = redis_conf.get("port") redis_db = redis_conf.get("queue") self.r = redis.StrictRedis(host=redis_host, port=redis_port, db=redis_db, decode_responses=True) self.queue = "queue:bunnyc"
def run(self): """docstring for NetUdpThread""" listen_port = conf_data("bproxy", "port") address = ("", listen_port) work_log.info("listen udp thread start") try: task = SelectorsUdpServer(address, self.queue) task.server_start() except Exception as e: work_log.error("udp thread error") work_log.error(str(e))
def run(self): """docstring for NetTcpThread""" listen_ip = "0.0.0.0" listen_port = conf_data("bproxy", "port") work_log.info("listen tcp thread start") try: task = SelectorsTcpServer((listen_ip, listen_port), self.queue) task.server_start() except Exception as e: work_log.error("tcp thread error") work_log.error(str(e))
def send_udp_mess(self, mess): # 通过 udp 发送数据 # udp 是无状态的协议,没有发送失败这种情况, # server_addr = ('10.2.1.5', 8716) server_addr = tuple(conf_data("gserver", "mess_server")) try: s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.sendto(mess, server_addr) s.close() except socket.error: work_log.error("send_udp_mess socket.error") except Exception as e: work_log.error("send_udp_mess other error") work_log.error(str(e))
def run_web_service_task(self): work_log.info("run_web_service_task -------- start") web_service = conf_data("web_service") data = self.task_run(web_service) work_log.debug(str(data)) new_data = { "mess_type": 102, "mess_code": 2001, "type": "web_service", "body": data, "ctime": time.strftime("%Y-%m-%d %H:%M:%S"), } work_log.debug(str(new_data)) send_mess_udp(new_data) work_log.info("run_web_service_task -------- end")
def run(self): work_log = My_log().get_log() work_log.debug("get memcached threading start") memcache_service_id = conf_data("memcache_id") for i in memcache_service_id.keys(): work_log.debug("get memcache data work start : " + i) ip = memcache_service_id.get(i)[0] port = memcache_service_id.get(i)[1] work_log.debug("mc_ip: %s, mc_port: %d" % (ip, port)) try: mem_data = my_memcached(ip, port) data = mem_data.get_run_date(i) self.queue.put(data) work_log.debug("memcache data put redis queue: " + i) except Exception as e: work_log.error("memcache data get error") work_log.error(str(e) + " : " + i) else: work_log.info("all memcache check end")
def redis_link(): host = conf_data('redis','host') port = conf_data('redis', 'port') r = redis.StrictRedis(host=host, port=port, decode_responses=True) return r
class work_daemon(daemon): """docstring for work_daemon""" def run(self): work_start() def main(): if len(sys.argv) == 2: daemon=work_daemon(pidfile) if 'start' == sys.argv[1]: work_log.info('------admin start daemon run ') daemon.start() elif 'stop' == sys.argv[1]: work_log.info('------admin stop') daemon.stop() elif 'restart' == sys.argv[1]: work_log.info('------admin restart') daemon.restart() else: print('unkonow command') sys.exit(2) sys.exit(0) elif len(sys.argv) == 1: work_start() if __name__ == "__main__": work_dir = Path(__file__).resolve().parent logfile = work_dir / conf_data('alarm','log') pidfile = work_dir / conf_data('alarm', 'pid') work_log = My_log(logfile, conf_data('alarm',"log_revel")).get_log() main()
def main(): if len(sys.argv) == 2: daemon = work_daemon(pidfile) if "start" == sys.argv[1]: work_log.info("------admin start daemon run ") daemon.start() elif "stop" == sys.argv[1]: work_log.info("------admin stop") daemon.stop() elif "restart" == sys.argv[1]: work_log.info("------admin restart") daemon.restart() else: print("unkonow command") sys.exit(2) sys.exit(0) elif len(sys.argv) == 1: work_log.info("------admin start") work_start() if __name__ == "__main__": work_dir = Path(__file__).resolve().parent logfile = work_dir / conf_data("gserver", "log") pidfile = work_dir / conf_data("gserver", "pid") log_revel = conf_data("gserver", "log_revel") work_log = My_log(logfile, log_revel).get_log() main()
def main(): if len(sys.argv) == 2: daemon = work_daemon(pidfile) if "start" == sys.argv[1]: work_log.info("------admin start daemon run ") daemon.start() elif "stop" == sys.argv[1]: work_log.info("------admin stop") daemon.stop() elif "restart" == sys.argv[1]: work_log.info("------admin restart") daemon.restart() else: print("unkonow command") sys.exit(2) sys.exit(0) elif len(sys.argv) == 1: work_start() if __name__ == "__main__": work_dir = Path(__file__).resolve().parent logfile = work_dir / conf_data("bproxy", "log") pidfile = work_dir / conf_data("bproxy", "pid") log_revel = conf_data("bproxy", "log_revel") work_log = My_log(logfile, log_revel).get_log() main()
def main(): if len(sys.argv) == 2: daemon = work_daemon(pidfile) if "start" == sys.argv[1]: work_log.info("------admin start daemon run ") daemon.start() elif "stop" == sys.argv[1]: work_log.info("------admin stop") daemon.stop() elif "restart" == sys.argv[1]: work_log.info("------admin restart") daemon.restart() else: print("unkonow command") sys.exit(2) sys.exit(0) elif len(sys.argv) == 1: work_start() if __name__ == "__main__": work_dir = Path(__file__).resolve().parent logfile = work_dir / conf_data("monitor", "log") pidfile = work_dir / conf_data("monitor", "pid") work_log = My_log(logfile, conf_data("monitor", "log_revel")).get_log() server_addr = tuple(conf_data("monitor", "mess_server")) main()