forked from mph13/pc-toolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcs_alerts_read.py
84 lines (71 loc) · 2.09 KB
/
pcs_alerts_read.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
""" Get a list of Alerts """
from __future__ import print_function
import json
from pc_lib import pc_api, pc_utility
# --Configuration-- #
parser = pc_utility.get_arg_parser()
parser.add_argument(
'--detailed',
action='store_true',
help='(Optional) - Get Alert details.')
parser.add_argument(
'-fas',
'--alertstatus',
type=str,
help='(Optional) - Filter - Alert Status.')
parser.add_argument(
'-fpt',
'--policytype',
type=str,
help='(Optional) - Filter - Policy Type.')
parser.add_argument(
'-tr',
'--timerange',
type=int,
default=30,
help='(Optional) - Time Range in days (default 30).')
parser.add_argument(
'-l',
'--limit',
type=int,
default=500,
help='(Optional) - Limit the number of Alerts to get (default 500).')
args = parser.parse_args()
# --Initialize-- #
settings = pc_utility.get_settings(args)
pc_api.configure(settings)
# --Main-- #
# ALERT GET
# Sort out and build the filters.
alerts_filter = {}
if args.detailed:
alerts_filter['detailed'] = True
else:
alerts_filter['detailed'] = False
alerts_filter['filters'] = []
alerts_filter['limit'] = args.limit
alerts_filter['offset'] = 0
alerts_filter['sortBy'] = ['id:asc']
alerts_filter['timeRange'] = {}
alerts_filter['timeRange']['type'] = 'relative'
alerts_filter['timeRange']['value'] = {}
alerts_filter['timeRange']['value']['unit'] = 'day'
alerts_filter['timeRange']['value']['amount'] = args.timerange
if args.alertstatus is not None:
temp_filter = {}
temp_filter['name'] = 'alert.status'
temp_filter['operator'] = '='
temp_filter['value'] = args.alertstatus
alerts_filter['filters'].append(temp_filter)
if args.policytype is not None:
temp_filter = {}
temp_filter['name'] = 'policy.type'
temp_filter['operator'] = '='
temp_filter['value'] = args.policytype
alerts_filter['filters'].append(temp_filter)
print('API - Getting the Alerts list ...', end='')
alerts_list = pc_api.alert_v2_list_read(body_params=alerts_filter)
print(' done.')
print()
print('Alerts:')
print(json.dumps(alerts_list))