forked from jasonbellack/Python_Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws_get_inventory.py
42 lines (32 loc) · 1.36 KB
/
aws_get_inventory.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
import boto3
from csv import DictWriter
ssm = boto3.client('ssm')
ec2 = boto3.resource('ec2')
# Get instance-Ids from Prod VPC info list
response = ec2.instances.filter(Filters=[{'Name': 'vpc-id', 'Values': ['vpc-099b436e86f46bef3']}])
instances = []
for i in response:
instances.append(i.id)
# Get software on instances using ssm agent
software_info = []
instanceIds = []
for i in instances:
response = ssm.list_inventory_entries(InstanceId = i, TypeName = "AWS:Application")
for entry in response['Entries']:
software_inventory = {}
software_inventory['InstanceId'] = i
software_inventory['SoftwareName'] = entry['Name']
software_inventory['SoftwareVersion'] = entry['Version']
publisher = entry['Publisher']
software_inventory['Publisher'] = publisher.replace(',','')
# if entry['InstalledTime'] in response['Entries']:
try:
software_inventory['InstallDate'] = entry['InstalledTime']
except Exception:
pass
# software_inventory['InstallDate'] = 'No install date given'
software_info.append(software_inventory)
with open('InstanceSoftwareInfo.csv','w', newline='') as outfile:
writer = DictWriter(outfile, ('InstanceId','SoftwareName', 'SoftwareVersion', 'Publisher', 'InstallDate'))
writer.writeheader()
writer.writerows(software_info)