forked from Peter-Nhan/Flask_webhook_receiver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_webhook.py
90 lines (76 loc) · 3.26 KB
/
test_webhook.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
import requests
import json
import urllib3
from requests.auth import HTTPBasicAuth # for Basic Auth
from urllib3.exceptions import InsecureRequestWarning # for insecure https warnings
urllib3.disable_warnings(InsecureRequestWarning) # disable insecure https warnings
from config import WEBHOOK_URL, WEBHOOK_USERNAME, WEBHOOK_PASSWORD
# set the payload for a Cisco DNA Center new event notification
dnac_param = {
"version": "",
"instanceId": "ea6e28c5-b7f2-43a4-9937-def73771c5ef",
"eventId": "NETWORK-NON-FABRIC_WIRED-1-251",
"namespace": "ASSURANCE",
"name": "",
"description": "",
"type": "NETWORK",
"category": "ALERT",
"domain": "Connectivity",
"subDomain": "Non-Fabric Wired",
"severity": 1,
"source": "ndp",
"timestamp": 1574457834497,
"tags": "",
"details": {
"Type": "Network Device",
"Assurance Issue Priority": "P1",
"Assurance Issue Details": "Interface GigabitEthernet1/0/3 on the following network device is down: Local Node: PDX-M",
"Device": "10.93.141.17",
"Assurance Issue Name": "Interface GigabitEthernet1/0/3 is Down on Network Device 10.93.141.17",
"Assurance Issue Category": "Connectivity",
"Assurance Issue Status": "active"
},
"ciscoDnaEventLink": "https://10.93.141.35/dna/assurance/issueDetails?issueId=ea6e28c5-b7f2-43a4-9937-def73771c5ef",
"note": "To programmatically get more info see here - https://<ip-address>/dna/platform/app/consumer-portal/developer-toolkit/apis?apiId=8684-39bb-4e89-a6e4",
"tntId": "",
"context": "",
"tenantId": ""
}
# set the payload for a Cisco DNA Center resolved event notification
dnac_param_resolved = {
"version": "",
"instanceId": "4292b3bc-a8a7-4a2e-8349-ddfae1ea8b9e",
"eventId": "NETWORK-NON-FABRIC_WIRED-1-251",
"namespace": "",
"name": "",
"description": "",
"type": "NETWORK",
"category": "ALERT",
"domain": "Connectivity",
"subDomain": "Non-Fabric Wired",
"severity": 1,
"source": "Cisco DNA Assurance",
"timestamp": 1576122993751,
"tags": "",
"details": {
"Type": "Network Device",
"Assurance Issue Priority": "P1",
"Assurance Issue Details": "Interface GigabitEthernet0/0 on the following network device is down: Local Node: PDX-CORE2",
"Device": "10.93.141.3",
"Assurance Issue Name": "Interface GigabitEthernet0/0 is Down on Network Device 10.93.141.3",
"Assurance Issue Category": "Connectivity",
"Assurance Issue Status": "resolved"
},
"ciscoDnaEventLink": "https://10.93.141.35/dna/assurance/issueDetails?issueId=4292b3bc-a8a7-4a2e-8349-ddfae1ea8b9e",
"note": "To programmatically get more info see here - https://<ip-address>/dna/platform/app/consumer-portal/developer-toolkit/apis?apiId=8684-39bb-4e89-a6e4",
"tntId": "",
"context": "",
"tenantId": ""
}
# test the Webhook with a Cisco DNA Center sample notification
basic_auth = HTTPBasicAuth(WEBHOOK_USERNAME, WEBHOOK_PASSWORD)
url = WEBHOOK_URL
header = {'content-type': 'application/json'}
response = requests.post(url, auth=basic_auth, data=json.dumps(dnac_param), headers=header, verify=False)
print('\nWebhook notification status code: ', response.status_code)
print('\nWebhook notification response: ', response.text)