-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnotifications_update.py
More file actions
80 lines (62 loc) · 4.08 KB
/
Copy pathnotifications_update.py
File metadata and controls
80 lines (62 loc) · 4.08 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
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
import requests
import json
import argparse
file = open("config.json", "r")
data = json.load(file)
file.close()
USER_ID = data['USER_ID']
API_TOKEN = data['API_TOKEN']
API_ROOT = data['API_ROOT']
AUTH = (USER_ID, API_TOKEN)
def notifications_update():
endpoint_url = API_ROOT % "notifications/update"
parser = argparse.ArgumentParser(description='Updates an existing scan notification definition.')
parser.add_argument('-id', '-nid', type=str, help='Gets or sets the scan notification identifier')
parser.add_argument('-e', '-emails', type=str, nargs='+', help='Gets or sets the emails of users who will be notified via Email')
parser.add_argument('-eu', '-excludedUsers', type=str, nargs='+', help='Gets or sets users emails who wont be notified')
parser.add_argument('-i', '-integrations', type=str, nargs='+', help='Gets or sets the names of integraton endpoints which will be notified')
parser.add_argument('-pn', '-phoneNumbers', type=str, nargs='+', help='Gets or sets the phone numbers of users who will be notified via SMS')
parser.add_argument('-se', '-semailr', type=str, nargs='+', help='Gets or sets the specific recipients who will be notified via Email')
parser.add_argument('-ss', '-ssmsr', type=str, nargs='+', help='Gets or sets the phone numbers of users who will be notified via SMS')
parser.add_argument('-wg', '-wgroupname', type=str, help='Gets or sets the website group identifier associated with this scan notification')
parser.add_argument('-ru', '-wrooturl', type=str, help='Gets or sets the website identifier associated with this scan notification')
parser.add_argument('-c', '-certainty', type=int, help='Gets or sets a value indicating whether this Scan Notification is certainty')
parser.add_argument('-d', '-disabled', type=str, choices=['true', 'false'], default='true', help='Gets or sets a value indicating whether this Scan Notification is disabled', required=True)
parser.add_argument('-ev', '-event', type=str, choices=['NewScan', 'ScanCompleted', 'ScanCancelled', 'ScanFailed', 'ScheduledScanLaunchFailed', 'OutOfDateTechnology'], help='Gets or sets the event name. This property determines when this rule will be executed', required=True)
parser.add_argument('-ic', '-isconfirmed', type=str, choices=['true', 'false'], default='true', help='Gets or sets a value indicating whether this Scan Notification is confirmed')
parser.add_argument('-ls', '-lowests', type=str, choices=['BestPractice', 'Information', 'Low', 'Medium', 'High', 'Critical'], help='Gets or sets the lowest severity. This property determines when this rule will be executed and is only used for Scan Completion Notification')
parser.add_argument('-n', '-name', type=str, help='Gets or sets the name', required=True)
parser.add_argument('-sc', '-scope', type=str, choices=['AnyWebsite', 'WebsiteGroup', 'Website'], help='Gets or sets the Website Scope. This property indicates whether this rule will be executed for a specific Website, WebsiteGroup or All Websites', required=True)
args = parser.parse_args()
if not (args.e or args.eu or args.i or args.pn or args.se or args.ss):
parser.error('At least 1 recipient is required.')
recipient_object = {
'Emails': args.e,
'ExcludedUsers': args.eu,
'Integrations': args.i,
'PhoneNumbers': args.pn,
'SpecificEmailRecipients': args.se,
'SpecificSmsRecipients': args.ss
}
json_object = {
"Recipients": recipient_object,
"WebsiteGroupName": args.wg,
"WebsiteRootUrl": args.ru,
"Certainty": args.c,
"Disabled": args.d,
"Event": args.ev,
"IsConfirmed": args.ic,
"LowestSeverity": args.ls,
"Name": args.n,
"Scope": args.sc
}
response = requests.post(endpoint_url, json=json_object, auth=AUTH)
print("Response: %s - %s" % (response.status_code, response.reason))
if response.status_code != 201:
print(response.text)
else:
print("Notification updated.")
def main():
notifications_update()
if __name__ == '__main__':
main()