def show_user_info(self): self.cursor.execute( "select * from user where username='******' and password='******'" % (self.login_user, self.login_pwd)) row_data = self.cursor.fetchone() if row_data: self.cursor.execute( "SELECT A.uid,A.username,A.mail,B.title FROM user as A \ LEFT JOIN department as B on A.department_id=B.pid \ WHERE A.username='******'" % self.login_user) result = self.cursor.fetchone() if result: self.tb.align["用户ID"] = "2" self.tb.padding_width = 1 user_info_li = [ result['uid'], result['username'], result['mail'], result['title'] ] self.tb.add_row(user_info_li) print() print("\033[1;32m 当前用户信息\033[0m ".center(50, '*')) print(self.tb) logger.info("user: %s,success!" % self.login_user) return True else: print("\033[1;31m用户名或密码错误,请检查!\033[0m") return False
def ssh_command(host_dic, cmd): """ 执行ssh命令并输出结果 :param ssh_obj: ssh对象 :param host_dic: 主机信息字典 :return: """ ip = host_dic['public_ip'] ssh_port = int(host_dic['ssh_port']) ssh_user = host_dic['username'] passwd = host_dic['password'] cmd = cmd ssh_obj = paramiko.SSHClient() ssh_obj.set_missing_host_key_policy(paramiko.AutoAddPolicy()) # print("执行的命令信息: ", ip, ssh_port, ssh_user, passwd, cmd) # 对应的主机信息 logger.info("ip:%s ssh_port:%d, ssh_user:%s, cmd:%s" % (ip, ssh_port, ssh_user, cmd)) ssh_obj.connect(ip, ssh_port, ssh_user, passwd, timeout=300) stdin, stdout, stderr = ssh_obj.exec_command(cmd) stdout_data = stdout.read().decode() if stdout_data: print('\033[1;32m%s\t| success | rc=0 >>\033[0m' % ip) return stdout_data else: print('\033[1;31m%s\t| failed | rc !=0 >>\033[0m' % ip) stderr_data = stderr.read().decode() return stderr_data
def run(self): threads = [] self.c.server_start() if self.c.check_server(): drivers = self.c.driver_start() logger.info('开始执行CASE!当前启动[%s]个DRIVER!' % drivers.qsize()) # 根据driver的个数启动对应的case for driver in range((drivers.qsize())): # 根据driver启动多线程跑case,对每个线程通过手机名 命名 t = threading.Thread(target=self.case, name=devices_name_queue.get()) threads.append(t) t.start() for t in threads: t.join()
def put_message(self) -> bool: timestamp = self.__get_timestamp() message: dict = {"timestamp": timestamp, "to": self.group, "from": self.from_app, "content": self.content, "event_id": self.event_id, "event_type": self.event_type} message: str = json.dumps(message) try: logger.info(message) RedisConnPool.pool().lpush("alert", message) except Exception as e: logger.error(e) return False return True
def main(login_user, login_pwd): admin_obj = Auth_show_info(login_user, login_pwd) res = admin_obj.show_user_info() if res: while True: sql = input("\033[1;32mmysql> \033[0m").strip() if sql == "quit" or sql == "exit": quit() inp_li = sql.split(' ') operation = inp_li[0] obj = AdminView() # 实例化 if hasattr(obj, operation): action_obj = getattr(obj, operation) action_obj(sql) logger.info("user: %s sql: %s" % (login_user, sql)) else: print("\033[1;31m用户名或密码错误,请检查!\033[0m")
def main(): updater = Updater(token=BOT_TOKEN) dispatcher = updater.dispatcher job_queue = updater.job_queue dispatcher.add_handler(start_handler) job_queue.run_repeating(start_job, JOB_TIME) # Start the Bot updater.start_polling() logger.info('bot started') # Block until you press Ctrl-C or the process receives SIGINT, SIGTERM or # SIGABRT. This should be used most of the time, since start_polling() is # non-blocking and will stop the bot gracefully. updater.idle()
def post(self): recv_message: dict = json.loads(self.request.body) # group_name 接收报警信息的用户组, 该报警服务平台约定, 所有的报警信息都是以用户组的形式发出 # 如果发给一个人, 这一个人就必须是一个组; 发给多个人, 多个人必须在同一组中 # content 报警信息的具体内容, 由于微信消息中没有主题(project)的概念, 所以消息体中的分行需要自己通过\n来实现 try: group_name: str = recv_message["group_name"] content: str = recv_message["content"] except KeyError as ke: logger.error(ke) self.write("group_name & content 为必填项") return # from_app 用于标识是哪一个监控平台发出的报警 # 该参数可以为空 try: from_app: str = recv_message["from_app"] except Exception as ke: logger.info(ke) from_app = "" # event_id 用于标识同一条报警信息的关联性 # 一般情况下, 同一条event_id最多只可能出现两次, 一次是故障报警, 一次是故障恢复报警 try: event_id: int = int(recv_message["event_id"]) except Exception as ke: logger.info(ke) event_id = 0 # event_type 用于标识故障报警与恢复故障报警 # 如果某平台只有故障报警, 则调用此接口无需传递此参数, 默认为故障报警消息, 或传递空字符串 # 如果类似于zabbix的报警平台, 需要在恢复报警中显示的声明此变量, 并为该变量赋值, 赋值为非空字符串即可, 例如: "ok" try: event_type: str = recv_message["event_type"] event_type: bool = bool(event_type) except Exception as ke: logger.info(ke) event_type = False # 创建微信消息对象 wx = WeiXinModel(group_name, content, from_app, event_id, event_type) # 创建微信消息服务对象 wxs = WeiXinService(wx, self.executor) # 发送消息(向消息队列中推送消息) ret = yield wxs.put_message() if ret: ret: Result = Result(data={}) else: ret: Result = Result(status_code=1, message="Error") self.write(ret.to_json())