@@ -1429,28 +1429,33 @@ def _get_root_folder_id(self):
14291429 response = self .sumologic_cli .get_root_folder ()
14301430 return response ["id" ]
14311431
1432- def import_monitor (self , folder_name , monitors3url , variables , suffix_date_time ):
1432+ def import_monitor (self , folder_name , orgID , monitors3url , variables , suffix_date_time ):
14331433 date_format = "%d-%b-%Y %H:%M:%S"
14341434 root_folder_id = self ._get_root_folder_id ()
14351435 content = self ._get_content_from_s3 (monitors3url , variables )
14361436 content ["name" ] = folder_name + " " + datetime .utcnow ().strftime (date_format ) if suffix_date_time \
14371437 else folder_name
14381438 response = self .sumologic_cli .import_monitors (root_folder_id , content )
14391439 import_id = response ["id" ]
1440+ monitor_permission_payload = {"permissionStatementDefinitions" : [{"permissions" : ["Create" ,"Read" ,"Update" ,"Delete" ,"Manage" ],"subjectType" : "org" ,"subjectId" : orgID ,"targetId" : import_id }]}
1441+ self .sumologic_cli .set_monitors_permissions (monitor_permission_payload )
14401442 print ("ALERTS MONITORS - creation successful with ID %s and Name %s." % (import_id , folder_name ))
14411443 return {"ALERTS MONITORS" : response ["name" ]}, import_id
14421444
1443- def create (self , folder_name , monitors3url , variables , suffix_date_time = False , * args , ** kwargs ):
1444- return self .import_monitor (folder_name , monitors3url , variables , suffix_date_time )
1445+ def create (self , folder_name , orgID , monitors3url , variables , suffix_date_time = False , * args , ** kwargs ):
1446+ return self .import_monitor (folder_name , orgID , monitors3url , variables , suffix_date_time )
14451447
1446- def update (self , folder_id , folder_name , monitors3url , variables , suffix_date_time = False , retain_old_alerts = False , * args , ** kwargs ):
1447- data , new_folder_id = self .create (folder_name , monitors3url , variables , suffix_date_time )
1448+ def update (self , folder_id , folder_name , orgID , monitors3url , variables , suffix_date_time = False , retain_old_alerts = False , * args , ** kwargs ):
1449+ data , new_folder_id = self .create (folder_name , orgID , monitors3url , variables , suffix_date_time )
14481450 if retain_old_alerts :
14491451 # Retaining old folder in the new folder as backup.
14501452 try :
14511453 old_folder = self .sumologic_cli .export_monitors (folder_id )
14521454 old_folder ["name" ] = "Back Up " + old_folder ["name" ]
1453- self .sumologic_cli .import_monitors (new_folder_id , old_folder )
1455+ response = self .sumologic_cli .import_monitors (new_folder_id , old_folder )
1456+ import_id = response ["id" ]
1457+ monitor_permission_payload = {"permissionStatementDefinitions" : [{"permissions" : ["Create" ,"Read" ,"Update" ,"Delete" ,"Manage" ],"subjectType" : "org" ,"subjectId" : orgID ,"targetId" : import_id }]}
1458+ self .sumologic_cli .set_monitors_permissions (monitor_permission_payload )
14541459 except Exception as e :
14551460 print ("Error while taking backup of Monitors folder" )
14561461 print (e )
@@ -1482,6 +1487,7 @@ def extract_params(self, event):
14821487 "suffix_date_time" : props .get ("SuffixDateTime" ) == 'true' ,
14831488 "retain_old_alerts" : props .get ("RetainOldAlerts" ) == 'true' ,
14841489 "folder_id" : folder_id ,
1490+ "orgID" : props .get ("orgid" )
14851491 }
14861492
14871493
@@ -1515,7 +1521,7 @@ def extract_params(self, event):
15151521 }
15161522 # col = Collector(**params)
15171523 # src = HTTPSource(**params)
1518- app = App (props )
1524+ # app = App(props)
15191525
15201526 # create
15211527 # _, collector_id = col.create(collector_type, collector_name, source_category)
@@ -1524,8 +1530,10 @@ def extract_params(self, event):
15241530 #_, app_folder_id = app.update(app_folder_id='0000000001A70848', appname=appname, source_params=source_params,folder_name="abcd" ,s3url=s3url,orgID="0000000000BC5DF9",share=True,location='admin',retain_old_app=True) #import
15251531 #app.delete(app_folder_id, True, location='admin')
15261532
1527- # monitor=AlertsMonitor(props)
1528- # _, app_folder_id = monitor.update('1234','abc',monitors3,"",retain_old_alerts=True)
1533+ monitor = AlertsMonitor (props )
1534+ monitors3 = "https://sumologic-appdev-aws-sam-apps.s3.amazonaws.com/aws-observability-versions/v2.5.2/appjson/Alerts-App.json"
1535+ # _, app_folder_id = monitor.create('abc','0000000000285A74',monitors3,"",retain_old_alerts=False)
1536+ # _, app_folder_id = monitor.update('000000000002796B','abc1','0000000000285A74',monitors3,"",retain_old_alerts=True)
15291537
15301538 # update
15311539 # _, new_collector_id = col.update(collector_id, collector_type, "%sCollectorNew" % app_prefix, "Labs/AWS/%sNew" % app_prefix, description="%s Collector" % app_prefix)
0 commit comments