Beispiel #1
0
    def _ResponseToClientsFullInfo(self, 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 _IntToClientID(prev_cid), c_full_info

                metadata = objects.ClientMetadata(
                    certificate=crt,
                    fleetspeak_enabled=fs,
                    first_seen=_MysqlToRDFDatetime(first),
                    ping=_MysqlToRDFDatetime(ping),
                    clock=_MysqlToRDFDatetime(clk),
                    ip=_StringToRDFProto(rdf_client.NetworkAddress, ip),
                    last_foreman_time=_MysqlToRDFDatetime(foreman),
                    startup_info_timestamp=_MysqlToRDFDatetime(
                        last_startup_ts),
                    last_crash_timestamp=_MysqlToRDFDatetime(last_crash_ts))

                if client_obj is not None:
                    l_snapshot = objects.ClientSnapshot.FromSerializedString(
                        client_obj)
                    l_snapshot.timestamp = _MysqlToRDFDatetime(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 = objects.ClientSnapshot(
                        client_id=_IntToClientID(cid))

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

                prev_cid = cid
                c_full_info = 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(
                    objects.ClientLabel(name=label_name, owner=label_owner))

        if c_full_info:
            yield _IntToClientID(prev_cid), c_full_info
Beispiel #2
0
 def MultiReadClientFullInfo(self, client_ids):
   res = {}
   for client_id in client_ids:
     self._ValidateClientId(client_id)
     res[client_id] = objects.ClientFullInfo(
         metadata=self.ReadClientMetadata(client_id),
         labels=self.ReadClientLabels(client_id),
         last_snapshot=self.ReadClientSnapshot(client_id),
         last_startup_info=self.ReadClientStartupInfo(client_id))
   return res
Beispiel #3
0
 def MultiReadClientFullInfo(self, client_ids, min_last_ping=None):
     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] = objects.ClientFullInfo(
             metadata=md,
             labels=self.ReadClientLabels(client_id),
             last_snapshot=self.ReadClientSnapshot(client_id),
             last_startup_info=self.ReadClientStartupInfo(client_id))
     return res