forked from dome9/cloud-bots
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_logs.py
More file actions
29 lines (24 loc) · 1.21 KB
/
send_logs.py
File metadata and controls
29 lines (24 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import json
from botocore.vendored import requests
import os
import time
from time import gmtime, strftime
SUMO_HTTP_ENDPOINT = 'https://endpoint4.collection.us2.sumologic.com/receiver/v1/http/ZaVnC4dhaV3N-lPxodY4J3xadi2by444XVaSboLlcbfMeGhqAnZn4PIVuJw_h3EzhhCv4jEFLfhHO3nbvfVgVSiRrB2X1hedSvXwyKB31hF3zdmR7j7mrQ=='
def send_logs(message, start_time, vendor):
account_mode = os.getenv('ACCOUNT_MODE', '')
cross_account_role_name = os.getenv('CROSS_ACCOUNT_ROLE_NAME', '')
output_type = os.getenv('OUTPUT_TYPE', '')
execution_time = time.time() - start_time
session = requests.Session()
for bot in message.get('Rules violations found'):
del bot['ID']
del bot['Name']
headers = {"Content-Type": "application/json", "Accept": "application/json", "X-Sumo-Name": message.get('Account id'), "X-Sumo-Category": vendor}
data = {'msg': message,
'account_mode': account_mode,
'cross_account_role_name': cross_account_role_name,
'output_type': output_type,
'execution_time': execution_time}
r = session.post(SUMO_HTTP_ENDPOINT, headers=headers, data=json.dumps(data))
print(f'{__file__} - status code from dome9 logs: {r.status_code}')
return