grr/server/grr_response_server/databases/mysql_clients.py
def WriteClientSnapshotHistory(self, clients, cursor=None):
    """Writes the full history for a particular client."""
    cid = mysql_utils.ClientIDToInt(clients[0].client_id)
    latest_timestamp = None

    for client in clients:

      startup_info = client.startup_info
      client.startup_info = None
      timestamp = mysql_utils.RDFDatetimeToMysqlString(client.timestamp)
      latest_timestamp = max(latest_timestamp, client.timestamp)

      try:
        cursor.execute(
            "INSERT INTO client_snapshot_history "
            "(client_id, timestamp, client_snapshot) "
            "VALUES (%s, %s, %s)",
            [cid, timestamp, client.SerializeToString()])
        cursor.execute(
            "INSERT INTO client_startup_history "
            "(client_id, timestamp, startup_info) "
            "VALUES (%s, %s, %s)",
            [cid, timestamp, startup_info.SerializeToString()])
      except MySQLdb.IntegrityError as e:
        raise db.UnknownClientError(clients[0].client_id, cause=e)
      finally:
        client.startup_info = startup_info

    latest_timestamp_str = mysql_utils.RDFDatetimeToMysqlString(
        latest_timestamp)
    cursor.execute(
        "UPDATE clients SET last_client_timestamp=%s "
        "WHERE client_id = %s AND "
        "(last_client_timestamp IS NULL OR last_client_timestamp < %s)",
        [latest_timestamp_str, cid, latest_timestamp_str])
    cursor.execute(
        "UPDATE clients SET last_startup_timestamp=%s "
        "WHERE client_id = %s AND "
        "(last_startup_timestamp IS NULL OR last_startup_timestamp < %s)",
        [latest_timestamp_str, cid, latest_timestamp_str])
Writes the full history for a particular client.
Writes the full history for a particular client.
Writes the full history for a particular client .
def WriteClientSnapshotHistory(self, clients, cursor=None):
    cid = mysql_utils.ClientIDToInt(clients[0].client_id)
    latest_timestamp = None
    for client in clients:
      startup_info = client.startup_info
      client.startup_info = None
      timestamp = mysql_utils.RDFDatetimeToMysqlString(client.timestamp)
      latest_timestamp = max(latest_timestamp, client.timestamp)
      try:
        cursor.execute(
            "INSERT INTO client_snapshot_history "
            "(client_id, timestamp, client_snapshot) "
            "VALUES (%s, %s, %s)",
            [cid, timestamp, client.SerializeToString()])
        cursor.execute(
            "INSERT INTO client_startup_history "
            "(client_id, timestamp, startup_info) "
            "VALUES (%s, %s, %s)",
            [cid, timestamp, startup_info.SerializeToString()])
      except MySQLdb.IntegrityError as e:
        raise db.UnknownClientError(clients[0].client_id, cause=e)
      finally:
        client.startup_info = startup_info
    latest_timestamp_str = mysql_utils.RDFDatetimeToMysqlString(
        latest_timestamp)
    cursor.execute(
        "UPDATE clients SET last_client_timestamp=%s "
        "WHERE client_id = %s AND "
        "(last_client_timestamp IS NULL OR last_client_timestamp < %s)",
        [latest_timestamp_str, cid, latest_timestamp_str])
    cursor.execute(
        "UPDATE clients SET last_startup_timestamp=%s "
        "WHERE client_id = %s AND "
        "(last_startup_timestamp IS NULL OR last_startup_timestamp < %s)",
        [latest_timestamp_str, cid, latest_timestamp_str])
def WriteClientSnapshotHistory ( self , clients , cursor = None ) : cid = mysql_utils . ClientIDToInt ( clients [ 0 ] . client_id ) latest_timestamp = None for client in clients : startup_info = client . startup_info client . startup_info = None timestamp = mysql_utils . RDFDatetimeToMysqlString ( client . timestamp ) latest_timestamp = max ( latest_timestamp , client . timestamp ) try : cursor . execute ( "INSERT INTO client_snapshot_history " "(client_id, timestamp, client_snapshot) " "VALUES (%s, %s, %s)" , [ cid , timestamp , client . SerializeToString ( ) ] ) cursor . execute ( "INSERT INTO client_startup_history " "(client_id, timestamp, startup_info) " "VALUES (%s, %s, %s)" , [ cid , timestamp , startup_info . SerializeToString ( ) ] ) except MySQLdb . IntegrityError as e : raise db . UnknownClientError ( clients [ 0 ] . client_id , cause = e ) finally : client . startup_info = startup_info latest_timestamp_str = mysql_utils . RDFDatetimeToMysqlString ( latest_timestamp ) cursor . execute ( "UPDATE clients SET last_client_timestamp=%s " "WHERE client_id = %s AND " "(last_client_timestamp IS NULL OR last_client_timestamp < %s)" , [ latest_timestamp_str , cid , latest_timestamp_str ] ) cursor . execute ( "UPDATE clients SET last_startup_timestamp=%s " "WHERE client_id = %s AND " "(last_startup_timestamp IS NULL OR last_startup_timestamp < %s)" , [ latest_timestamp_str , cid , latest_timestamp_str ] )
Writes the full history for a particular client.
Writes the full history for a particular client .
"""Writes the full history for a particular client."""
self
clients
cursor