-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathssm_test.py
54 lines (45 loc) · 1.91 KB
/
ssm_test.py
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import re
import boto3
import xlsxwriter
from test_decorator import timed_func
@timed_func
def test():
command_id = 'cadf87b7-8369-4521-8d01-956cb2d466e2'
patterns = ['Important','Important Updates', 'Critical','Moderate','Low', 'Unspecified', 'Optional Updates', 'Total Updates']
client = boto3.client('ssm')
workbook = xlsxwriter.Workbook('commandDetails.xlsx')
worksheet = workbook.add_worksheet()
bold = workbook.add_format({'bold': 1})
worksheet.write('A1', 'CommandId', bold)
worksheet.write('B1', 'InstanceId', bold)
worksheet.write('C1', 'Status', bold)
worksheet.write('D1', 'DocumentName', bold)
worksheet.write('E1', 'Important', bold)
worksheet.write('F1', 'ImportantUpdates', bold)
worksheet.write('G1', 'Critical', bold)
worksheet.write('H1', 'Moderate', bold)
worksheet.write('I1', 'Low', bold)
worksheet.write('J1', 'Unspecified', bold)
worksheet.write('K1', 'OptionalUpdates', bold)
worksheet.write('L1', 'TotalUpdates', bold)
row = 1
col = 0
response = client.list_command_invocations(CommandId=command_id, Details=True)
for item in response['CommandInvocations']:
worksheet.write_string(row, col, item['CommandId'])
worksheet.write_string(row, col + 1, item['InstanceId'])
worksheet.write_string(row, col + 2, item['Status'])
worksheet.write_string(row, col + 3, item['DocumentName'])
for data in item['CommandPlugins']:
output = data['Output']
if item['DocumentName'] == 'AWS-FindWindowsUpdates':
col = 4
for pattern in patterns:
key = pattern.replace(" ", "")
data_dict = re.search(r""+pattern+": (?P<"+key+">\d+)", output).groupdict()
worksheet.write_string(row, col, data_dict[key])
col += 1
row += 1
col = 0
workbook.close()
test()