コード例 #1
0
  def _ResponseToClientsFullInfo(self, response):
    """Creates a ClientFullInfo object from a database response."""
    c_full_info = None
    prev_cid = None
    for row in response:
      (cid, fs, crt, ping, clk, ip, foreman, first, last_client_ts,
       last_crash_ts, last_startup_ts, client_obj, client_startup_obj,
       last_startup_obj, label_owner, label_name) = row

      if cid != prev_cid:
        if c_full_info:
          yield db_utils.IntToClientID(prev_cid), c_full_info

        metadata = rdf_objects.ClientMetadata(
            certificate=crt,
            fleetspeak_enabled=fs,
            first_seen=mysql_utils.TimestampToRDFDatetime(first),
            ping=mysql_utils.TimestampToRDFDatetime(ping),
            clock=mysql_utils.TimestampToRDFDatetime(clk),
            ip=mysql_utils.StringToRDFProto(rdf_client_network.NetworkAddress,
                                            ip),
            last_foreman_time=mysql_utils.TimestampToRDFDatetime(foreman),
            startup_info_timestamp=mysql_utils.TimestampToRDFDatetime(
                last_startup_ts),
            last_crash_timestamp=mysql_utils.TimestampToRDFDatetime(
                last_crash_ts))

        if client_obj is not None:
          l_snapshot = rdf_objects.ClientSnapshot.FromSerializedString(
              client_obj)
          l_snapshot.timestamp = mysql_utils.TimestampToRDFDatetime(
              last_client_ts)
          l_snapshot.startup_info = rdf_client.StartupInfo.FromSerializedString(
              client_startup_obj)
          l_snapshot.startup_info.timestamp = l_snapshot.timestamp
        else:
          l_snapshot = rdf_objects.ClientSnapshot(
              client_id=db_utils.IntToClientID(cid))

        if last_startup_obj is not None:
          startup_info = rdf_client.StartupInfo.FromSerializedString(
              last_startup_obj)
          startup_info.timestamp = mysql_utils.TimestampToRDFDatetime(
              last_startup_ts)
        else:
          startup_info = None

        prev_cid = cid
        c_full_info = rdf_objects.ClientFullInfo(
            metadata=metadata,
            labels=[],
            last_snapshot=l_snapshot,
            last_startup_info=startup_info)

      if label_owner and label_name:
        c_full_info.labels.append(
            rdf_objects.ClientLabel(name=label_name, owner=label_owner))

    if c_full_info:
      yield db_utils.IntToClientID(prev_cid), c_full_info
コード例 #2
0
 def MultiReadClientFullInfo(self, client_ids, min_last_ping=None):
     """Reads full client information for a list of clients."""
     res = {}
     for client_id in client_ids:
         md = self.ReadClientMetadata(client_id)
         if md and min_last_ping and md.ping < min_last_ping:
             continue
         res[client_id] = rdf_objects.ClientFullInfo(
             metadata=md,
             labels=self.ReadClientLabels(client_id),
             last_snapshot=self.ReadClientSnapshot(client_id),
             last_startup_info=self.ReadClientStartupInfo(client_id))
     return res
コード例 #3
0
ファイル: mem_clients.py プロジェクト: wxh0000mm/grr
    def MultiReadClientFullInfo(self, client_ids, min_last_ping=None):
        """Reads full client information for a list of clients."""
        res = {}
        for client_id in client_ids:
            try:
                md = self.ReadClientMetadata(client_id)
            except db.UnknownClientError:
                continue

            if md and min_last_ping and md.ping < min_last_ping:
                continue
            last_snapshot = self.ReadClientSnapshot(client_id)
            full_info = rdf_objects.ClientFullInfo(
                metadata=md,
                labels=self.ReadClientLabels(client_id),
                last_startup_info=self.ReadClientStartupInfo(client_id))
            if last_snapshot is None:
                full_info.last_snapshot = rdf_objects.ClientSnapshot(
                    client_id=client_id)
            else:
                full_info.last_snapshot = last_snapshot
            res[client_id] = full_info
        return res
コード例 #4
0
 def testDeserializeClientSnapshot(self):
   snapshot = rdf_objects.ClientSnapshot(client_id="C.1234567890123456")
   client_info = rdf_objects.ClientFullInfo(last_snapshot=snapshot)
   deserialized = rdf_objects.ClientFullInfo.FromSerializedBytes(
       client_info.SerializeToBytes())
   self.assertEqual(deserialized.last_snapshot, snapshot)