Beispiel #1
0
 def update_offline_record(self, item):
     if self.db.exec_sql(
             """UPDATE `monitoring`.`cabinet_offline_record` SET `offline_endtime` = '{}' \
         WHERE `cabinet_id` = '{}' and `offline_endtime` is NULL;""".format(
                 self.now, item.get('柜机ID'))):
         print('更新结束时间成功: {}'.format(item))
     else:
         raise Error('更新数据错误: {}'.format(item))
Beispiel #2
0
 def insert_offline_record(self, item):
     if self.db.exec_sql(
             """INSERT INTO `monitoring`.`cabinet_offline_record`(`id`, `cabinet_id`, `cabinet_name`, \
         `offline_starttime`) VALUES ('{}', '{}', '{}', '{}');""".format(
                 uuid.uuid4(), item.get('柜机ID'), item.get('柜机名称'),
                 self.now)):
         print('插入新的离线记录: {}'.format(item))
     else:
         raise Error('插入数据错误: {}'.format(item))
Beispiel #3
0
 async def ping(self, reconnect=True):
     """Check if the server is alive"""
     if self._writer is None and self._reader is None:
         if reconnect:
             await self._connect()
             reconnect = False
         else:
             raise Error("Already closed")
     try:
         await self._execute_command(COMMAND.COM_PING, "")
         await self._read_ok_packet()
     except Exception:
         if reconnect:
             await self._connect()
             await self.ping(False)
         else:
             raise
 def _check_connection(self):
     if not self.connection:
         raise Error("No DBConnection established. use .connect first")