def ListClients(self, request): clients = [] for client_id in request.client_ids: clients.append( fs_admin_pb2.Client( client_id=client_id, labels=[ fs_common_pb2.Label( service_name="client", label="alphabet"), fs_common_pb2.Label( service_name="client", label="alphabet-google-corp"), fs_common_pb2.Label(service_name="client", label="linux"), ])) return fs_admin_pb2.ListClientsResponse(clients=clients)
def GenerateFleetspeakServiceConfig(self): """Generate a service config, used to register the GRR client with FS.""" logging.info("Generating Fleetspeak service config.") fs_service_config = fs_system_pb2.ClientServiceConfig( name=config.CONFIG["Client.name"], factory="Daemon", required_labels=[ fs_common_pb2.Label( service_name="client", label="windows", ), ], ) daemonservice_config = fs_config_pb2.Config( argv=[ # Note this is an argv list, so we can't use # config.CONFIG["Nanny.child_command_line"] directly. config.CONFIG["Nanny.child_binary"], "--config=%s.yaml" % config.CONFIG["Nanny.child_binary"], ], monitor_heartbeats=True, heartbeat_unresponsive_grace_period_seconds=600, heartbeat_unresponsive_kill_period_seconds=300, ) fs_service_config.config.Pack(daemonservice_config) str_fs_service_config = text_format.MessageToString(fs_service_config, as_one_line=True) return str_fs_service_config
def _MockConnReturningClient(grr_id, labels): client = admin_pb2.Client( client_id=fleetspeak_utils.GRRIDToFleetspeakID(grr_id), labels=[common_pb2.Label(service_name=k, label=v) for k, v in labels]) conn = mock.MagicMock() conn.outgoing.ListClients.return_value = admin_pb2.ListClientsResponse( clients=[client]) return conn
def testGetLabelFromFleetspeakKnown(self): client_id = "C.0000000000000001" conn = MockConnReturningClient( admin_pb2.Client( client_id=fleetspeak_utils.GRRIDToFleetspeakID(client_id), labels=[common_pb2.Label(service_name="client", label="division1")])) with test_lib.ConfigOverrider({ "Server.fleetspeak_label_map": ["division1:fleetspeak-division1"], }): with fleetspeak_test_lib.ConnectionOverrider(conn): self.assertEqual("fleetspeak-division1", fleetspeak_utils.GetLabelFromFleetspeak(client_id))
def GenerateFleetspeakServiceConfig(self): """Generate a service config, used to register the GRR client with FS.""" fs_service_config = fs_system_pb2.ClientServiceConfig( name=config.CONFIG["Client.name"], factory="Daemon", required_labels=[ fs_common_pb2.Label( service_name="client", label="windows", ), ], ) daemonservice_config = fs_config_pb2.Config(argv=[ # Note this is an argv list, so we can't use # config.CONFIG["Nanny.child_command_line"] directly. config.CONFIG["Nanny.child_binary"], "--config=%s.yaml" % config.CONFIG["Nanny.child_binary"], ]) fs_service_config.config.Pack(daemonservice_config) str_fs_service_config = text_format.MessageToString(fs_service_config, as_one_line=True) return str_fs_service_config