Skip to content

Commit bc529bb

Browse files
authored
Merge pull request #160 from SumoLogic/monitors_fgp
Adding monitor FGP api call
2 parents c83d8ba + 8a156b2 commit bc529bb

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

sumologic-app-utils/src/sumologic.py

+4
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,10 @@ def import_monitors(self, folder_id, content):
312312
response = self.post('/monitors/%s/import' % folder_id, params=content)
313313
return json.loads(response.text)
314314

315+
def set_monitors_permissions(self, content):
316+
response = self.put('/monitors/permissions/set', params=content)
317+
return json.loads(response.text)
318+
315319
def export_monitors(self, folder_id):
316320
response = self.get('/monitors/%s/export' % folder_id)
317321
return json.loads(response.text)

sumologic-app-utils/src/sumoresource.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -1429,22 +1429,24 @@ 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:
@@ -1482,6 +1484,7 @@ def extract_params(self, event):
14821484
"suffix_date_time": props.get("SuffixDateTime") == 'true',
14831485
"retain_old_alerts": props.get("RetainOldAlerts") == 'true',
14841486
"folder_id": folder_id,
1487+
"orgID": props.get("orgid")
14851488
}
14861489

14871490

@@ -1515,7 +1518,7 @@ def extract_params(self, event):
15151518
}
15161519
# col = Collector(**params)
15171520
# src = HTTPSource(**params)
1518-
app = App(props)
1521+
# app = App(props)
15191522

15201523
# create
15211524
# _, collector_id = col.create(collector_type, collector_name, source_category)
@@ -1524,8 +1527,10 @@ def extract_params(self, event):
15241527
#_, 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
15251528
#app.delete(app_folder_id, True, location='admin')
15261529

1527-
# monitor=AlertsMonitor(props)
1528-
# _, app_folder_id = monitor.update('1234','abc',monitors3,"",retain_old_alerts=True)
1530+
monitor=AlertsMonitor(props)
1531+
monitors3 = "https://sumologic-appdev-aws-sam-apps.s3.amazonaws.com/aws-observability-versions/v2.5.2/appjson/Alerts-App.json"
1532+
# _, app_folder_id = monitor.create('abc','0000000000285A74',monitors3,"",retain_old_alerts=False)
1533+
# _, app_folder_id = monitor.update('000000000002796B','abc1','0000000000285A74',monitors3,"",retain_old_alerts=True)
15291534

15301535
# update
15311536
# _, new_collector_id = col.update(collector_id, collector_type, "%sCollectorNew" % app_prefix, "Labs/AWS/%sNew" % app_prefix, description="%s Collector" % app_prefix)
83 KB
Binary file not shown.

0 commit comments

Comments
 (0)