@@ -307,28 +307,47 @@ def get_conf(self, variable, is_number=None, default=None, required=None):
307307
308308
309309class OpenBASCollectorHelper :
310- def __init__ (self , config : OpenBASConfigHelper , icon ) -> None :
310+ def __init__ (
311+ self , config : OpenBASConfigHelper , icon , security_platform_type = None
312+ ) -> None :
311313 self .config_helper = config
312314 self .api = OpenBAS (
313315 url = config .get_conf ("openbas_url" ),
314316 token = config .get_conf ("openbas_token" ),
315317 )
316318
317- self .config = {
318- "collector_id" : config .get_conf ("collector_id" ),
319- "collector_name" : config .get_conf ("collector_name" ),
320- "collector_type" : config .get_conf ("collector_type" ),
321- "collector_period" : config .get_conf ("collector_period" ),
322- }
323-
324319 self .logger_class = utils .logger (
325320 config .get_conf ("collector_log_level" , default = "info" ).upper (),
326321 config .get_conf ("collector_json_logging" , default = True ),
327322 )
328323 self .collector_logger = self .logger_class (config .get_conf ("collector_name" ))
329324
330325 icon_name = config .get_conf ("collector_id" ) + ".png"
331- collector_icon = (icon_name , icon , "image/png" )
326+
327+ security_platform_id = None
328+ if security_platform_type is not None :
329+ collector_icon = (icon_name , open (icon , "rb" ), "image/png" )
330+ document = self .api .document .upsert (document = {}, file = collector_icon )
331+ security_platform = self .api .security_platform .upsert (
332+ {
333+ "asset_name" : config .get_conf ("collector_name" ),
334+ "asset_external_reference" : config .get_conf ("collector_id" ),
335+ "security_platform_type" : security_platform_type ,
336+ "security_platform_logo_light" : document .get ("document_id" ),
337+ "security_platform_logo_dark" : document .get ("document_id" ),
338+ }
339+ )
340+ security_platform_id = security_platform .get ("asset_id" )
341+
342+ self .config = {
343+ "collector_id" : config .get_conf ("collector_id" ),
344+ "collector_name" : config .get_conf ("collector_name" ),
345+ "collector_type" : config .get_conf ("collector_type" ),
346+ "collector_period" : config .get_conf ("collector_period" ),
347+ "collector_security_platform" : security_platform_id ,
348+ }
349+
350+ collector_icon = (icon_name , open (icon , "rb" ), "image/png" )
332351 self .api .collector .create (self .config , collector_icon )
333352 self .connect_run_and_terminate = False
334353 # self.api.injector.create(self.config)
0 commit comments