-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnac_issue_report_ecall.py
More file actions
executable file
·80 lines (64 loc) · 2.7 KB
/
Copy pathdnac_issue_report_ecall.py
File metadata and controls
executable file
·80 lines (64 loc) · 2.7 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Cisco DNA Center Issue Report eCall Script.
Copyright (c) 2023 Cisco and/or its affiliates.
This software is licensed to you under the terms of the Cisco Sample
Code License, Version 1.1 (the "License"). You may obtain a copy of the
License at
https://developer.cisco.com/docs/licenses
All use of the material herein must be in accordance with the terms of
the License. All rights not expressly granted by the License are
reserved. Unless required by applicable law or agreed to separately in
writing, software distributed under the License is distributed on an "AS
IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied.
"""
__author__ = "Patrick Mosimann"
__email__ = "pamosima@cisco.com"
__version__ = "0.1.0"
__copyright__ = "Copyright (c) 2023 Cisco and/or its affiliates."
__license__ = "Cisco Sample Code License, Version 1.1"
import json
import http.client
import base64
import os
from dnacentersdk import DNACenterAPI
from dotenv import load_dotenv
from datetime import datetime
load_dotenv()
dnac_username = os.getenv('dnacUsername')
dnac_password = os.getenv('dnacPassword')
dnac_base_url = os.getenv('dnacIP')
ecall_username = os.getenv('ecallUsername')
ecall_password = os.getenv('ecallPassword')
# Create a DNACenterAPI connection object; it uses DNA Center username and password, with DNA Center API version 1.2.10
# The base_url used by default is `from dnacentersdk.config import DEFAULT_BASE_URL`
api = DNACenterAPI(username=dnac_username,
password=dnac_password,
base_url=dnac_base_url,
version='2.3.3.0',
verify=False,
debug=True)
issueP1=api.issues.issues(priority="p1", issueStatus="ACTIVE")
issueP2=api.issues.issues(priority="p2", issueStatus="ACTIVE")
issueP3=api.issues.issues(priority="p3", issueStatus="ACTIVE")
issueP4=api.issues.issues(priority="p4", issueStatus="ACTIVE")
occurrence = datetime.now().strftime('%d.%m.%Y %H:%M:%S')
authorization = base64.b64encode(f"{ecall_username}:{ecall_password}".encode('ascii')).decode('ascii')
client = http.client.HTTPSConnection("rest.ecall.ch")
headers = {
'Authorization': 'Basic ' + authorization,
'Content-Type': 'application/json'
}
message = f"""{{
"channel": "sms",
"from": "0041763373989",
"to": "0041763373989",
"content": {{
"type": "Text",
"text": "Cisco DNA Center Issue Report from {occurrence} No of Issues: P1={issueP1.totalCount} P2={issueP2.totalCount} P3={issueP3.totalCount} P4={issueP4.totalCount}"
}}
}}"""
client.request("POST", "/api/message", message, headers)
res = client.getresponse()
print(res.read().decode("utf-8"))