-
Notifications
You must be signed in to change notification settings - Fork 0
/
ca_insightvm.py
711 lines (575 loc) · 25.8 KB
/
ca_insightvm.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
#!/usr/bin/python3
# Standard Python libraries
from calendar import weekheader
import ssl
import datetime
import logging
import json
# Third party Python libraries
import requests
import mysql.connector
# Custom libraries
from modules.secrets import SECRETS
from modules.dbConn import *
########################
# FUNCTIONS
########################
# Generate the API headers
def api_headers():
header = {
'Accept': 'application/json',
'Accept-Encoding': 'deflate, gzip',
'Accept-Language': 'en-us',
}
logging.debug('API headers: %s', str(header))
return header
# Close function api_headers
# Get the details of the scan engines and write to database
def ivm_get_scan_engines ():
# The full URL including the API endpoint
url = '{0}/scan_engines'.format(baseUrl)
response = requests.get(url, auth=auth, headers=api_headers(), verify=False)
response_json = response.json()
# Scan engines we dont care about and don't want to insert into the database
blacklist_scan_engines = ['Rapid7 Hosted Scan Engine','Rapid7 Hosted','Default Engine Pool','Local scan engine']
# Process each object in the JSON, saving the data to variables, and
# ultimatly writing it to our MySQL database
logging.debug('response: %s', response)
for i in response_json['resources']:
if i['name'] not in blacklist_scan_engines:
# Name of the scan engine - example: Insightscan
name = i['name']
logging.debug('name: %s', name)
# Address of the scan engine, could be FQDN or IP Address
address = i['address']
logging.debug('address: %s', address)
#Scan engine status - we want to see "Active"!
status = i['status']
logging.debug('status: %s', address)
# Rapid7's scan engine id
scan_engine_id = i['id']
logging.debug('scan_engine_id: %s', scan_engine_id)
# Date the scan engine last checked into the core server
# We want this to be within 3 hours
last_refreshed_date = datetime.datetime.strftime(datetime.datetime.strptime(i['lastRefreshedDate'], iso), mysqliso)
logging.debug('last_refreshed_date: %s', last_refreshed_date)
# Last time the scan engine received updates
last_updated_date = datetime.datetime.strftime(datetime.datetime.strptime(i['lastUpdatedDate'], iso), mysqliso)
logging.debug('last_updated_date: %s', last_updated_date)
# Content version - contains the vulnerabilty check updates
content_version = i['contentVersion']
logging.debug('content_version: %s', content_version)
# Date of the last content update
content_version_date = content_version[content_version.find(char1)+1 : content_version.find(char2)]
logging.debug('content_version_date: %s', content_version_date)
# Product version - contains new feature updates.
# Updates less frequesntly than content.
product_version = i['productVersion']
logging.debug('product_version: %s', address)
#Date of the last product update
product_version_date = product_version[product_version.find(char1)+1 : product_version.find(char2)]
logging.debug('product_version_date: %s', address)
sql = "INSERT INTO " + str(table_scan_engines) + " (\
id, \
date, \
name, \
address, \
scan_engine_id, \
status, \
last_refreshed_date, \
last_updated_date, \
content_version, \
content_version_date, \
product_version, \
product_version_date \
) VALUES (\
NULL, \
'" + str(today) + "', \
'" + str(name) + "', \
'" + str(address) + "', \
'" + str(scan_engine_id) + "', \
'" + str(status) + "', \
'" + str(last_refreshed_date) + "', \
'" + str(last_updated_date) + "', \
'" + str(content_version) + "', \
'" + str(content_version_date) + "', \
'" + str(product_version) + "', \
'" + str(product_version_date) + "'\
)"
try:
ret = db.doExec(sql)
logging.info('Successfully INSERTed into table "%s": %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s.', table_scan_engines, today, name, address, scan_engine_id, status, last_refreshed_date, last_updated_date, content_version, content_version_date, product_version, product_version_date)
except mysql.connector.Error as err:
logging.error(err)
# Close function api_scan_engines_update_status
# Check that sites have been recently scanned
def ivm_get_sites():
# The full URL including the API endpoint
url = '{0}/sites?size=100'.format(baseUrl)
logging.debug('get sites url: %s', url)
# Hit the API and save the result to a JSON object
response = requests.get(url, auth=auth, headers=api_headers(), verify=False)
response_json = response.json()
# Sites we dont care about start with...
blacklist = ['_TEST','Compliance', 'Rapid7 Insight Agents']
# Process each site that we care about (skip those that start
# with an item in the blacklist)
for site in response_json['resources']:
name = str(site['name'])
logging.debug('name: %s', name)
for i in blacklist:
skip = "no"
if name.startswith(i):
skip = "yes"
break
if skip is "no":
# Last time the site was scanned
last_scan_time = datetime.datetime.strftime(datetime.datetime.strptime(site['lastScanTime'], iso), mysqliso)
logging.debug('last_scan_time: %s', last_scan_time)
sql = "INSERT INTO " + str(table_site_scan) + " (\
id, \
date, \
name, \
last_scan_time\
) VALUES (\
NULL, \
'" + str(today) + "', \
'" + str(name) + "', \
'" + str(last_scan_time) + "' \
)"
try:
ret = db.doExec(sql)
logging.info('Successfully INSERTed into table "%s": %s, %s, %s.', table_site_scan, today, name, last_scan_time)
except mysql.connector.Error as err:
logging.error(err)
# Close function api_sites_scan_status
# Get all assets being scanned
def ivm_get_assets():
# Create an empty list to store IDs later
asset_ids = []
# Iterate through upto 10 pages and build the list of asset IDs
i = 0
while i < 10:
# The full URL including the API endpoint
url = '{0}/assets?page={1}&size=500'.format(baseUrl, i)
# Hit the API and save the result to a JSON object
response = requests.get(url, auth=auth, headers=api_headers(), verify=False)
response_json = response.json()
for asset in response_json['resources']:
if "id" in asset:
id = int(asset['id'])
asset_ids.append(id)
else:
break
i += 1
# Get asset information and write it to the database
for i in asset_ids:
# The URL for the asset
url = '{0}/assets/{1}'.format(baseUrl, i)
# Hit the API and save the result to a JSON object
response = requests.get(url, auth=auth, headers=api_headers(), verify=False)
response_json = response.json()
# I could compare two dictionaries, but I'm lazy and just wanna get this done...
if "hostName" in response_json:
hostname = str(response_json['hostName'])
else:
hostname = ''
logging.debug('hostname: %s', hostname)
if "ip" in response_json:
ip = str(response_json['ip'])
else:
ip = ''
logging.debug('ip: %s', ip)
if "mac" in response_json:
mac = str(response_json['mac'])
else:
mac = ''
logging.debug('mac: %s', mac)
if "riskScore" in response_json:
risk_score = str(round((response_json['riskScore']), 2))
else:
risk_score = ''
logging.debug('risk_score: %s', risk_score)
try:
for software in response_json['software']:
if software['product'] == "Rapid7 Insight Agent":
agent_version = software['version']
break
else:
agent_version = ''
except KeyError:
agent_version = ''
logging.debug('Agent version: %s', agent_version)
if "assessedForVulnerabilities" in response_json:
assessed_for_vulnerabilities = str(response_json['assessedForVulnerabilities'])
else:
assessed_for_vulnerabilities = ''
logging.debug('assessed_for_vulnerabilities: %s', assessed_for_vulnerabilities)
if "assessedForPolicies" in response_json:
assessed_for_policies = str(response_json['assessedForPolicies'])
else:
assessed_for_policies = ''
logging.debug('assessed_for_policies: %s', assessed_for_policies)
if "critical" in response_json['vulnerabilities']:
critical_vulnerabilities = str(response_json['vulnerabilities']['critical'])
else:
critical_vulnerabilities = ''
logging.debug('critical_vulnerabilities: %s', critical_vulnerabilities)
if "severe" in response_json['vulnerabilities']:
severe_vulnerabilities = str(response_json['vulnerabilities']['severe'])
else:
severe_vulnerabilities = ''
logging.debug('severe_vulnerabilities: %s', severe_vulnerabilities)
if "moderate" in response_json['vulnerabilities']:
moderate_vulnerabilities = str(response_json['vulnerabilities']['moderate'])
else:
moderate_vulnerabilities = ''
logging.debug('moderate_vulnerabilities: %s', moderate_vulnerabilities)
if "exploits" in response_json['vulnerabilities']:
exploits = str(response_json['vulnerabilities']['exploits'])
else:
exploits = ''
logging.debug('exploits: %s', exploits)
if "malwareKits" in response_json['vulnerabilities']:
malware_kits = str(response_json['vulnerabilities']['malwareKits'])
else:
malware_kits = ''
logging.debug('malware_kits: %s', malware_kits)
if "total" in response_json['vulnerabilities']:
total_vulnerabilities = str(response_json['vulnerabilities']['total'])
else:
total_vulnerabilities = ''
logging.debug('total_vulnerabilities: %s', total_vulnerabilities)
sql = "INSERT INTO " + str(table_asset) + " (\
asset_id, \
hostname, \
ip, \
mac, \
risk_score, \
agent_version, \
assessed_for_vulnerabilities, \
assessed_for_policies, \
critical_vulnerabilities, \
severe_vulnerabilities, \
moderate_vulnerabilities, \
exploits, \
malware_kits, \
total_vulnerabilities\
) VALUES (\
'" + str(i) + "', \
'" + str(hostname) + "', \
'" + str(ip) + "', \
'" + str(mac) + "', \
'" + str(risk_score) + "', \
'" + str(agent_version) + "', \
'" + str(assessed_for_vulnerabilities) + "', \
'" + str(assessed_for_policies) + "', \
'" + str(critical_vulnerabilities) + "', \
'" + str(severe_vulnerabilities) + "', \
'" + str(moderate_vulnerabilities) + "',\
'" + str(exploits) + "', \
'" + str(malware_kits) + "', \
'" + str(total_vulnerabilities) + "'\
)"
try:
ret = db.doExec(sql)
logging.info('Successfully INSERTed into table "%s": %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s.', table_asset, i, hostname, ip, mac, risk_score, agent_version, assessed_for_vulnerabilities, assessed_for_policies, critical_vulnerabilities, severe_vulnerabilities, moderate_vulnerabilities, exploits, malware_kits, total_vulnerabilities)
except mysql.connector.Error as err:
logging.error(err)
# Get the asset tag IDs from the tags endpoint
url = '{0}/assets/{1}/tags'.format(baseUrl, i)
response = requests.get(url, auth=auth, headers=api_headers(), verify=False)
response_json = response.json()
# Save the tag name as a variable
for tag in response_json['resources']:
tag_id = int(tag['id'])
sql = "INSERT INTO " + str(table_asset_tag) + " (\
asset_id, \
tag_id \
) VALUES (\
'" + str(i) + "', \
'" + str(tag_id) + "' \
)"
try:
ret = db.doExec(sql)
logging.info('Successfully INSERTed into table "%s": %s, %s.', table_asset_tag, i, tag_id)
except mysql.connector.Error as err:
logging.error(err)
# Close function api_assets
# Get asset tag data
def ivm_get_tags ():
# Clear the current entries in the r7_asset_tag, r7_asset, and r7_tag table
# Alternativly, find a way to keep them in sync so we don't have to keep DELETEing
sql = "DELETE FROM " + str(table_asset_tag)
try:
ret = db.doExec(sql)
logging.info('Cleared table "%s".', table_asset_tag)
except mysql.connector.Error as err:
logging.error(err)
#cursor.execute(sql)
sql = "DELETE FROM " + str(table_asset)
try:
ret = db.doExec(sql)
logging.info('Cleared table "%s".', table_asset)
except mysql.connector.Error as err:
logging.error(err)
#cursor.execute(sql)
sql = "DELETE FROM " + str(table_tag)
try:
ret = db.doExec(sql)
logging.info('Cleared table "%s".', table_tag)
except mysql.connector.Error as err:
logging.error(err)
#cursor.execute(sql)
# The full URL including the API endpoint
url = '{0}/tags?size=500'.format(baseUrl)
# Hit the API and save the result to a JSON object
response = requests.get(url, auth=auth, headers=api_headers(), verify=False)
response_json = response.json()
for i in response_json['resources']:
tag_id = int(i['id'])
name = str(i['name'])
source = str(i['source'])
type = str(i['type'])
if "riskModifier" in i:
risk_modifier = float(i['riskModifier'])
else:
risk_modifier = 0
sql = "INSERT INTO " + str(table_tag) + " (\
tag_id, \
tag_name, \
source, \
type, \
risk_modifier \
) VALUES (\
'" + str(tag_id) + "', \
'" + str(name) + "', \
'" + str(source) + "', \
'" + str(type) + "', \
'" + str(risk_modifier) + "' \
)"
try:
ret = db.doExec(sql)
logging.info('Successfully INSERTed into table "%s": %s, %s, %s, %s, %s.', table_tag, tag_id, name, source, type, risk_modifier)
except mysql.connector.Error as err:
logging.error(err)
# Close function ivm_get_assets
# Perform counts and other math to get rollup (data over time) information for metrics
def ivm_metrics_rollup():
# Agent version - this returns the most updated version number of all currently installed agents
sql = "select agent_version \
from " + str(table_asset) + " \
where agent_version not like '' and agent_version not like 'config' \
order by agent_version desc \
limit 1"
try:
ret = db.doSel(sql)
version = ret[0][0]
logging.info('version: %s', version)
except mysql.connector.Error as err:
logging.error(err)
# site_scan - returns a number 1-100 indicating the health of sites being scanned
sql = "select round(a.num / a.den * 100, 0)\
from (\
select\
(select count(*) from " + str(table_site_scan) + " where date = curdate() and last_scan_time > date_sub(curdate(), interval 7 day)) as num,\
(select count(*) from " + str(table_site_scan) + " where date = curdate()) as den\
) a"
try:
ret = db.doSel(sql)
site_scan = ret[0][0]
logging.info('site_scan: %s', site_scan)
except mysql.connector.Error as err:
logging.error(err)
# scan_engine - returns a number 1-100 indicating the health of scan engines
sql = "select round(a.num / a.den * 100, 0)\
from (\
select\
(select count(*) from " + str(table_scan_engines) + " where date = curdate() and status = 'active') as num,\
(select count(*) from " + str(table_scan_engines) + " where date = curdate()) as den\
) a"
try:
ret = db.doSel(sql)
scan_engine = ret[0][0]
logging.info('scan_engine: %s', scan_engine)
except mysql.connector.Error as err:
logging.error(err)
# product_updates - returns a date indicating the last date we received product updates
sql = "select product_version_date from " + str(table_scan_engines) + " where date = curdate()"
try:
ret = db.doSel(sql)
product_updates = abs((today - ret[0][0]).days)
logging.info('product_updates: %s', product_updates)
except mysql.connector.Error as err:
logging.error(err)
# content_updates - returns a date indicating the last date we received product updates
sql = "select content_version_date from " + str(table_scan_engines) + " where date = curdate()"
try:
ret = db.doSel(sql)
content_updates = abs((today - ret[0][0]).days)
logging.info('content_updates: %s', content_updates)
except mysql.connector.Error as err:
logging.error(err)
# assets_scanned - returns a number 1-100 indicating the health status of all assets being scanned
sql = "select 0 -- Need to change this when we get CMDB: select round(a.num / a.den * 100, 0)\
from (\
select\
(select count(*) from " + str(table_asset) + ") as num,\
(select count(*) from " + str(table_asset) + ") as den -- change this table to the CMDB total scanned assets\
) a"
try:
ret = db.doSel(sql)
assets_scanned = ret[0][0]
logging.info('assets_scanned: %s', assets_scanned)
except mysql.connector.Error as err:
logging.error(err)
# agent_installs - returns a number 1-100 indicating the coverage of agents on workstations (servers dont get agents)
sql = "select round(a.num / a.den * 100, 0)\
from (\
select\
(select count(*) from " + str(table_asset) + " \
join " + str(table_asset_tag) + " on " + str(table_asset) + ".asset_id=" + str(table_asset_tag) + ".asset_id\
join " + str(table_tag) + " on " + str(table_asset_tag) + ".tag_id=" + str(table_tag) + ".tag_id\
where tag_name = 'Desktop Support Team'\
and agent_version not like '') as num,\
(select count(*) from " + str(table_asset) + " \
join " + str(table_asset_tag) + " on " + str(table_asset) + ".asset_id=" + str(table_asset_tag) + ".asset_id\
join " + str(table_tag) + " on " + str(table_asset_tag) + ".tag_id=" + str(table_tag) + ".tag_id\
where tag_name = 'Desktop Support Team'\
order by hostname) as den\
) a"
try:
ret = db.doSel(sql)
agent_installs = ret[0][0]
logging.info('agent_installs: %s', agent_installs)
except mysql.connector.Error as err:
logging.error(err)
# agent_version - returns a number 1-100 indicating the health status of all assets being scanned
sql = "select round(a.num / a.den * 100, 0)\
from (\
select\
(select count(*) from " + str(table_asset) + " where agent_version = '" + str(version) + "') as num,\
(select count(*) from " + str(table_asset) + " where agent_version not like '' and agent_version not like 'config' order by agent_version desc limit 1) as den\
) a"
try:
ret = db.doSel(sql)
agent_version = ret[0][0]
logging.info('agent_version: %s', agent_version)
except mysql.connector.Error as err:
logging.error(err)
# Insert all of the above data into the table
sql = "INSERT INTO " + table_metrics_rollup + " (\
id, \
date, \
site_scan, \
scan_engine, \
product_updates, \
content_updates, \
assets_scanned, \
agent_installs, \
agent_version\
) VALUES (\
NULL,\
curdate(),\
'" + str(site_scan) + "', \
'" + str(scan_engine) + "', \
'" + str(product_updates) + "', \
'" + str(content_updates) + "', \
'" + str(assets_scanned) + "', \
'" + str(agent_installs) + "', \
'" + str(agent_version) + "'\
)"
try:
ret = db.doExec(sql)
logging.info('Successfully INSERTed into table "%s": %s, %s, %s, %s, %s, %s, %s', table_metrics_rollup, site_scan, scan_engine, product_updates,content_updates, assets_scanned, agent_installs, agent_version)
except mysql.connector.Error as err:
logging.error(err)
# daily_total = a daily rollup weighted average of the day's metrics
# WARNING!!!
# If you attempt to format this query on multi-lines, it will break!!
sql = "select round((site_scan*1 + scan_engine*1 + agent_installs*1 + agent_version*1 + (CASE WHEN product_updates <= 7 THEN 100 ELSE 100+7 - product_updates*1.5 END)*1 + (CASE WHEN content_updates <= 7 THEN 100 ELSE 100+7 - content_updates*1.5 END)*1)/6, 0) from " + table_metrics_rollup + " where date = curdate()"
try:
ret = db.doSel(sql)
daily_total = ret[0][0]
logging.info('daily_total: %s', daily_total)
except mysql.connector.Error as err:
logging.error(err)
# Insert the daily rollup into the table
sql = "UPDATE " + table_metrics_rollup + " SET daily_total = '" + str(daily_total) + "' WHERE date = curdate()"
try:
ret = db.doExec(sql)
logging.info('Successfully INSERTed into table "%s": %s', table_metrics_rollup, daily_total)
except mysql.connector.Error as err:
logging.error(err)
# Close function ivm_metrics_rollup
# Data retention - Delete data from tables older than X months
def data_retention():
# Delete data older than X months
limit = 6
# Loop through the array of table names and cleanup data in each
for i in cleanUp:
sql = "DELETE FROM " + str(i) + " WHERE date <= CURDATE() - INTERVAL '" + str(limit) + "' MONTH"
try:
ret = db.doExec(sql)
logging.info('Purged data older than %s months from table "%s".', limit, i)
except mysql.connector.Error as err:
logging.error(err)
# Close function data_retention
########################
# Global Variables
########################
# Valid log levels include:
# INFO
# WARNING
# ERROR
# CRITICAL
# DEBUG
# Logging options
log_File = '/usr/local/scripts/log/ca_insightvm.log'
logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', datefmt='%Y-%m-%d %H:%M:%S', filename=log_File, level=logging.INFO, filemode='w')
# Define the URL that we will use throughout this script
# And pull in the credentials from the secrets.json file
if 'insightvm' in SECRETS:
# Build the base URL that will be passed into the API calls
baseUrl = 'https://{0}:{1}/api/3'.format(SECRETS['insightvm']['host'], SECRETS['insightvm']['port'])
# Create requests AUTH object
auth = requests.auth.HTTPBasicAuth(SECRETS['insightvm']['username'], SECRETS['insightvm']['password'])
db = dbConn(
'{0}'.format(SECRETS['mysql_ca']['host']),
'{0}'.format(SECRETS['mysql_ca']['user']),
'{0}'.format(SECRETS['mysql_ca']['password']),
'{0}'.format(SECRETS['mysql_ca']['database'])
)
# Define the MySQL tables
table_scan_engines = "r7_scan_engines"
table_site_scan = "r7_site_scan"
table_asset = "r7_asset"
table_asset_tag = "r7_asset_tag"
table_tag = "r7_tag"
table_metrics_rollup = "r7_metrics_rollup"
# Some objects in our JSON will include data between the () characters.
# We need to define the charactors to "read between".
char1 = '('
char2 = ')'
# Used to set the date in the date column of the MySQL tables
ymd = '%Y-%m-%d'
# Define the format of the date that Rapid7 presents via the API
iso = '%Y-%m-%dT%H:%M:%S.%fZ'
# We will take the date format from Rapid7's API and convert it to a
# format that we can then insert into MySQL
mysqliso = '%Y-%m-%d %H:%M:%S'
# Today's date e.g.: 2022-01-25
today = datetime.datetime.strptime(datetime.datetime.strftime(datetime.date.today(), ymd), ymd).date()
# These tables will be purged of data older than X months from the
# data_retention function
cleanUp = [table_scan_engines, table_site_scan, table_metrics_rollup]
########################
# ACTION!
########################
ivm_get_scan_engines()
ivm_get_sites()
ivm_get_tags()
ivm_get_assets()
ivm_metrics_rollup()
# Run this last
data_retention()