コード例 #1
0
  def WriteClientMessages(self, messages, cursor=None):
    """Writes messages that should go to the client to the db."""

    query = ("INSERT IGNORE INTO client_messages "
             "(client_id, message_id, timestamp, message) "
             "VALUES %s ON DUPLICATE KEY UPDATE "
             "timestamp=VALUES(timestamp), message=VALUES(message)")
    now = mysql_utils.RDFDatetimeToMysqlString(rdfvalue.RDFDatetime.Now())

    client_ids = set()

    value_templates = []
    args = []
    for m in messages:
      cid = db_utils.ClientIdFromGrrMessage(m)
      client_ids.add(cid)
      client_id_int = mysql_utils.ClientIDToInt(cid)
      args.extend([client_id_int, m.task_id, now, m.SerializeToString()])
      value_templates.append("(%s, %s, %s, %s)")

    query %= ",".join(value_templates)
    try:
      cursor.execute(query, args)
    except MySQLdb.IntegrityError as e:
      raise db.AtLeastOneUnknownClientError(client_ids=client_ids, cause=e)
コード例 #2
0
ファイル: mysql_paths.py プロジェクト: x35029/grr
 def MultiWritePathInfos(self, path_infos):
   """Writes a collection of path info records for specified clients."""
   try:
     self._MultiWritePathInfos(path_infos)
   except MySQLdb.IntegrityError as error:
     client_ids = list(iterkeys(path_infos))
     raise db.AtLeastOneUnknownClientError(client_ids=client_ids, cause=error)
コード例 #3
0
  def WriteClientMessages(self, messages):
    """Writes messages that should go to the client to the db."""
    client_ids = [db_utils.ClientIdFromGrrMessage(msg) for msg in messages]
    for client_id in client_ids:
      if client_id not in self.metadatas:
        raise db.AtLeastOneUnknownClientError(client_ids=client_ids)

    for m in messages:
      client_id = db_utils.ClientIdFromGrrMessage(m)
      self.client_messages.setdefault(client_id, {})[m.task_id] = m