cisco-audit-tool 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cisco_audit_tool-0.1.1/LICENSE +21 -0
- cisco_audit_tool-0.1.1/PKG-INFO +204 -0
- cisco_audit_tool-0.1.1/README.md +174 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/__init__.py +0 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/check_env.py +79 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/cli.py +71 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/collect.py +114 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/config.py +54 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/dashboard.py +74 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/dashboard_launcher.py +19 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/demo.py +51 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/dnac.py +61 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/http.py +84 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/ise.py +54 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/report.py +120 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool/rules.py +158 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool.egg-info/PKG-INFO +204 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool.egg-info/SOURCES.txt +24 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool.egg-info/dependency_links.txt +1 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool.egg-info/entry_points.txt +4 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool.egg-info/requires.txt +10 -0
- cisco_audit_tool-0.1.1/cisco_audit_tool.egg-info/top_level.txt +1 -0
- cisco_audit_tool-0.1.1/pyproject.toml +46 -0
- cisco_audit_tool-0.1.1/setup.cfg +4 -0
- cisco_audit_tool-0.1.1/tests/test_audit.py +156 -0
- cisco_audit_tool-0.1.1/tests/test_step2.py +95 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mohammed Agmih
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cisco-audit-tool
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Read-only audit toolkit for Cisco Catalyst Center (DNA Center) and Cisco ISE: inventory, audit rules, Excel/PDF reports, dashboard.
|
|
5
|
+
Author: Mohammed Agmih
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/agmihmohammed98-lang/cisco-audit-tool
|
|
8
|
+
Project-URL: Issues, https://github.com/agmihmohammed98-lang/cisco-audit-tool/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/agmihmohammed98-lang/cisco-audit-tool/releases
|
|
10
|
+
Keywords: cisco,ise,catalyst-center,dnac,dna-center,network-automation,audit,netdevops
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: System Administrators
|
|
13
|
+
Classifier: Intended Audience :: Telecommunications Industry
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
17
|
+
Requires-Python: >=3.10
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: requests>=2.32
|
|
21
|
+
Requires-Dist: truststore>=0.10
|
|
22
|
+
Requires-Dist: python-dotenv>=1.0
|
|
23
|
+
Requires-Dist: pandas>=2.3
|
|
24
|
+
Requires-Dist: openpyxl>=3.1
|
|
25
|
+
Requires-Dist: reportlab>=4.2
|
|
26
|
+
Provides-Extra: dashboard
|
|
27
|
+
Requires-Dist: streamlit>=1.50; extra == "dashboard"
|
|
28
|
+
Requires-Dist: plotly>=6.0; extra == "dashboard"
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
# cisco-audit-tool
|
|
32
|
+
|
|
33
|
+
**Read-only audit toolkit for Cisco Catalyst Center (DNA Center) and Cisco ISE.**
|
|
34
|
+
|
|
35
|
+
It connects to the Catalyst Center Intent API and the ISE ERS, OpenAPI and MnT APIs, collects inventory and configuration data, and is designed to produce audit reports (Excel, PDF and a Streamlit dashboard) **without ever changing anything on the network**.
|
|
36
|
+
|
|
37
|
+
> **Status: early stage (v0.1).** Works end to end: collection, 7 audit rules, Excel and PDF reports, and a Streamlit dashboard, all covered by offline tests. It has been tested against fictional demo data, not yet against many real deployments. Feedback is welcome.
|
|
38
|
+
|
|
39
|
+
[](https://github.com/agmihmohammed98-lang/cisco-audit-tool/actions/workflows/tests.yml)
|
|
40
|
+
|
|
41
|
+
**Try it in 30 seconds, no Cisco gear needed:**
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install "cisco-audit-tool[dashboard]"
|
|
45
|
+
cisco-audit --demo # Excel and PDF reports in ./reports
|
|
46
|
+
cisco-audit-dashboard # dashboard, "Demo data" is preselected
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Audit rules
|
|
50
|
+
|
|
51
|
+
| Rule | Severity | What it detects |
|
|
52
|
+
|---|---|---|
|
|
53
|
+
| `dnac_unreachable` | HIGH | Catalyst Center device not reachable (with the failure reason) |
|
|
54
|
+
| `dnac_not_managed` | MEDIUM | Reachable device whose inventory collection is failing |
|
|
55
|
+
| `dnac_software_drift` | MEDIUM | Device running a different version from most devices of the same platform (stacks are handled) |
|
|
56
|
+
| `ise_node_status` | HIGH | ISE node not `Connected` |
|
|
57
|
+
| `ise_admin_redundancy` | LOW | No Secondary Admin node in the deployment |
|
|
58
|
+
| `dnac_missing_in_ise` | MEDIUM | **Cross-check:** device managed by Catalyst Center but not defined in ISE (no RADIUS/TACACS+). ISE subnets are taken into account. |
|
|
59
|
+
| `ise_stale_nad` | LOW | **Cross-check:** ISE network device (single host) unknown to Catalyst Center, possibly decommissioned |
|
|
60
|
+
|
|
61
|
+
Rules are plain Python functions in [`cisco_audit_tool/rules.py`](cisco_audit_tool/rules.py) that take a snapshot and return findings, so adding one only takes a few lines.
|
|
62
|
+
|
|
63
|
+
## Why read-only matters
|
|
64
|
+
|
|
65
|
+
Audit tools often run with admin credentials on production controllers. This toolkit makes write access impossible by design:
|
|
66
|
+
|
|
67
|
+
| Guarantee | How |
|
|
68
|
+
|---|---|
|
|
69
|
+
| **No write calls** | `ReadOnlySession` rejects every `PUT`, `PATCH`, `DELETE` and `POST`, except the explicitly allow-listed authentication endpoint. |
|
|
70
|
+
| **TLS always verified** | `verify=False` is silently dropped. Certificates are checked against the OS trust store (via `truststore`), with an optional custom CA bundle. |
|
|
71
|
+
| **HTTPS only** | Plain `http://` URLs are refused. |
|
|
72
|
+
| **No secret leakage** | Passwords never appear in `repr()`, `str()`, logs or error messages. Logs record method, URL and status only, never headers or bodies. |
|
|
73
|
+
| **Resilient** | Timeouts, retries with backoff on 429/502/503/504 (GET only), `Retry-After` honoured, automatic token renewal on Catalyst Center. |
|
|
74
|
+
|
|
75
|
+
## Requirements
|
|
76
|
+
|
|
77
|
+
- Python 3.10+
|
|
78
|
+
- Network access to Catalyst Center and/or ISE
|
|
79
|
+
- An API account. A **read-only** role is strongly recommended.
|
|
80
|
+
|
|
81
|
+
## Installation
|
|
82
|
+
|
|
83
|
+
From PyPI (first upload pending: until then, use the "From source" steps below):
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
python -m venv .venv
|
|
87
|
+
# Windows: .venv\Scripts\activate | Linux/macOS: source .venv/bin/activate
|
|
88
|
+
pip install cisco-audit-tool # CLI and reports
|
|
89
|
+
pip install "cisco-audit-tool[dashboard]" # + Streamlit dashboard
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Then create a working folder with a `.env` file, using [`.env.example`](.env.example) as a template. The tool reads `.env` and writes `data/` and `reports/` in the **current directory**. Set `CISCO_AUDIT_HOME` to use another folder.
|
|
93
|
+
|
|
94
|
+
From source:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
git clone https://github.com/agmihmohammed98-lang/cisco-audit-tool.git
|
|
98
|
+
cd cisco-audit-tool
|
|
99
|
+
pip install -e ".[dashboard]"
|
|
100
|
+
cp .env.example .env # then fill in URLs and credentials
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
| Command | From a git clone |
|
|
104
|
+
|---|---|
|
|
105
|
+
| `cisco-audit` | `python audit.py` |
|
|
106
|
+
| `cisco-audit-check` | `python check_env.py` |
|
|
107
|
+
| `cisco-audit-dashboard` | `streamlit run dashboard.py` |
|
|
108
|
+
|
|
109
|
+
## Usage
|
|
110
|
+
|
|
111
|
+
### Run an audit
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
python audit.py # live read-only collection using .env, then rules and reports
|
|
115
|
+
python audit.py --snapshot data/snapshot_live_XXXX.json # re-audit a saved snapshot offline
|
|
116
|
+
python audit.py --formats pdf # only the PDF report
|
|
117
|
+
python audit.py --ise-device-limit 200 # cap ISE device detail calls (1 GET per device)
|
|
118
|
+
python audit.py --fail-on high # exit code 1 if a HIGH finding exists (cron/CI)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
Each run saves a JSON snapshot in `data/` and writes the reports in `reports/`. Both folders are git-ignored, because they contain your inventory.
|
|
122
|
+
|
|
123
|
+
### Dashboard
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
streamlit run dashboard.py
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
The dashboard only reads the snapshots and never calls the Cisco APIs. It shows KPIs, findings with a severity filter, reachability, software versions per platform and the ISE inventory, and offers Excel and PDF downloads.
|
|
130
|
+
|
|
131
|
+
### Check the environment
|
|
132
|
+
|
|
133
|
+
Check the environment, which makes no API calls and uses no credentials:
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
python check_env.py
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
This checks the Python version, the installed packages and the `.env` file. It also runs a TCP and TLS handshake against each controller, with full certificate verification.
|
|
140
|
+
|
|
141
|
+
Use the clients from Python:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from cisco_audit_tool.config import load_settings
|
|
145
|
+
from cisco_audit_tool.dnac import DnacClient
|
|
146
|
+
from cisco_audit_tool.ise import IseClient
|
|
147
|
+
|
|
148
|
+
s = load_settings()
|
|
149
|
+
dnac = DnacClient(s.dnac, s.ca_bundle, s.timeout)
|
|
150
|
+
print(dnac.ping()) # {'devices': 42, ...}
|
|
151
|
+
for dev in dnac.get_paged("/dna/intent/api/v1/network-device"):
|
|
152
|
+
print(dev["hostname"], dev["softwareVersion"])
|
|
153
|
+
|
|
154
|
+
ise = IseClient(s.ise, s.ca_bundle, s.timeout)
|
|
155
|
+
print(ise.ping()) # OpenAPI, falls back to ERS
|
|
156
|
+
for ep in ise.ers_paged("/ers/config/endpoint"):
|
|
157
|
+
print(ep["name"])
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Tests
|
|
161
|
+
|
|
162
|
+
The tests run fully offline (`requests` is mocked):
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
python -m unittest discover -s tests -v
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Configuration
|
|
169
|
+
|
|
170
|
+
All settings come from `.env` (see `.env.example`):
|
|
171
|
+
|
|
172
|
+
| Variable | Description |
|
|
173
|
+
|---|---|
|
|
174
|
+
| `DNAC_URL`, `DNAC_USERNAME`, `DNAC_PASSWORD` | Catalyst Center |
|
|
175
|
+
| `ISE_URL`, `ISE_USERNAME`, `ISE_PASSWORD` | ISE (ERS/OpenAPI/MnT must be enabled) |
|
|
176
|
+
| `CA_BUNDLE` | Optional PEM file for your internal CA |
|
|
177
|
+
| `HTTP_TIMEOUT` | Seconds, default 30 |
|
|
178
|
+
|
|
179
|
+
**Never commit `.env`.** It is already in `.gitignore`, together with `certs/`, `data/`, `logs/` and `reports/`.
|
|
180
|
+
|
|
181
|
+
## Roadmap
|
|
182
|
+
|
|
183
|
+
- [x] Environment and TLS check
|
|
184
|
+
- [x] Read-only API clients (Catalyst Center, ISE) with offline tests
|
|
185
|
+
- [x] Inventory collection: Catalyst Center devices, ISE nodes, ISE network devices
|
|
186
|
+
- [x] 7 audit rules, including Catalyst Center and ISE cross-checks
|
|
187
|
+
- [x] Excel and PDF reports
|
|
188
|
+
- [x] Streamlit dashboard and demo mode
|
|
189
|
+
- [ ] More data: sites, interfaces, ISE endpoints, policy sets, certificate expiry
|
|
190
|
+
- [ ] More rules: end-of-life software, ISE certificate expiry, unused policy sets
|
|
191
|
+
- [ ] Trend comparison between two snapshots
|
|
192
|
+
- [x] PyPI package (`pip install cisco-audit-tool`) and CI on Linux/Windows, Python 3.10–3.13
|
|
193
|
+
|
|
194
|
+
## Contributing
|
|
195
|
+
|
|
196
|
+
Issues and pull requests are welcome. Please keep the read-only guarantee intact and add an offline test for every new API call.
|
|
197
|
+
|
|
198
|
+
## Disclaimer
|
|
199
|
+
|
|
200
|
+
Not affiliated with or endorsed by Cisco Systems. "Cisco", "Catalyst Center" and "ISE" are trademarks of Cisco Systems, Inc.
|
|
201
|
+
|
|
202
|
+
## License
|
|
203
|
+
|
|
204
|
+
[MIT](LICENSE)
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
# cisco-audit-tool
|
|
2
|
+
|
|
3
|
+
**Read-only audit toolkit for Cisco Catalyst Center (DNA Center) and Cisco ISE.**
|
|
4
|
+
|
|
5
|
+
It connects to the Catalyst Center Intent API and the ISE ERS, OpenAPI and MnT APIs, collects inventory and configuration data, and is designed to produce audit reports (Excel, PDF and a Streamlit dashboard) **without ever changing anything on the network**.
|
|
6
|
+
|
|
7
|
+
> **Status: early stage (v0.1).** Works end to end: collection, 7 audit rules, Excel and PDF reports, and a Streamlit dashboard, all covered by offline tests. It has been tested against fictional demo data, not yet against many real deployments. Feedback is welcome.
|
|
8
|
+
|
|
9
|
+
[](https://github.com/agmihmohammed98-lang/cisco-audit-tool/actions/workflows/tests.yml)
|
|
10
|
+
|
|
11
|
+
**Try it in 30 seconds, no Cisco gear needed:**
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install "cisco-audit-tool[dashboard]"
|
|
15
|
+
cisco-audit --demo # Excel and PDF reports in ./reports
|
|
16
|
+
cisco-audit-dashboard # dashboard, "Demo data" is preselected
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Audit rules
|
|
20
|
+
|
|
21
|
+
| Rule | Severity | What it detects |
|
|
22
|
+
|---|---|---|
|
|
23
|
+
| `dnac_unreachable` | HIGH | Catalyst Center device not reachable (with the failure reason) |
|
|
24
|
+
| `dnac_not_managed` | MEDIUM | Reachable device whose inventory collection is failing |
|
|
25
|
+
| `dnac_software_drift` | MEDIUM | Device running a different version from most devices of the same platform (stacks are handled) |
|
|
26
|
+
| `ise_node_status` | HIGH | ISE node not `Connected` |
|
|
27
|
+
| `ise_admin_redundancy` | LOW | No Secondary Admin node in the deployment |
|
|
28
|
+
| `dnac_missing_in_ise` | MEDIUM | **Cross-check:** device managed by Catalyst Center but not defined in ISE (no RADIUS/TACACS+). ISE subnets are taken into account. |
|
|
29
|
+
| `ise_stale_nad` | LOW | **Cross-check:** ISE network device (single host) unknown to Catalyst Center, possibly decommissioned |
|
|
30
|
+
|
|
31
|
+
Rules are plain Python functions in [`cisco_audit_tool/rules.py`](cisco_audit_tool/rules.py) that take a snapshot and return findings, so adding one only takes a few lines.
|
|
32
|
+
|
|
33
|
+
## Why read-only matters
|
|
34
|
+
|
|
35
|
+
Audit tools often run with admin credentials on production controllers. This toolkit makes write access impossible by design:
|
|
36
|
+
|
|
37
|
+
| Guarantee | How |
|
|
38
|
+
|---|---|
|
|
39
|
+
| **No write calls** | `ReadOnlySession` rejects every `PUT`, `PATCH`, `DELETE` and `POST`, except the explicitly allow-listed authentication endpoint. |
|
|
40
|
+
| **TLS always verified** | `verify=False` is silently dropped. Certificates are checked against the OS trust store (via `truststore`), with an optional custom CA bundle. |
|
|
41
|
+
| **HTTPS only** | Plain `http://` URLs are refused. |
|
|
42
|
+
| **No secret leakage** | Passwords never appear in `repr()`, `str()`, logs or error messages. Logs record method, URL and status only, never headers or bodies. |
|
|
43
|
+
| **Resilient** | Timeouts, retries with backoff on 429/502/503/504 (GET only), `Retry-After` honoured, automatic token renewal on Catalyst Center. |
|
|
44
|
+
|
|
45
|
+
## Requirements
|
|
46
|
+
|
|
47
|
+
- Python 3.10+
|
|
48
|
+
- Network access to Catalyst Center and/or ISE
|
|
49
|
+
- An API account. A **read-only** role is strongly recommended.
|
|
50
|
+
|
|
51
|
+
## Installation
|
|
52
|
+
|
|
53
|
+
From PyPI (first upload pending: until then, use the "From source" steps below):
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
python -m venv .venv
|
|
57
|
+
# Windows: .venv\Scripts\activate | Linux/macOS: source .venv/bin/activate
|
|
58
|
+
pip install cisco-audit-tool # CLI and reports
|
|
59
|
+
pip install "cisco-audit-tool[dashboard]" # + Streamlit dashboard
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Then create a working folder with a `.env` file, using [`.env.example`](.env.example) as a template. The tool reads `.env` and writes `data/` and `reports/` in the **current directory**. Set `CISCO_AUDIT_HOME` to use another folder.
|
|
63
|
+
|
|
64
|
+
From source:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
git clone https://github.com/agmihmohammed98-lang/cisco-audit-tool.git
|
|
68
|
+
cd cisco-audit-tool
|
|
69
|
+
pip install -e ".[dashboard]"
|
|
70
|
+
cp .env.example .env # then fill in URLs and credentials
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
| Command | From a git clone |
|
|
74
|
+
|---|---|
|
|
75
|
+
| `cisco-audit` | `python audit.py` |
|
|
76
|
+
| `cisco-audit-check` | `python check_env.py` |
|
|
77
|
+
| `cisco-audit-dashboard` | `streamlit run dashboard.py` |
|
|
78
|
+
|
|
79
|
+
## Usage
|
|
80
|
+
|
|
81
|
+
### Run an audit
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
python audit.py # live read-only collection using .env, then rules and reports
|
|
85
|
+
python audit.py --snapshot data/snapshot_live_XXXX.json # re-audit a saved snapshot offline
|
|
86
|
+
python audit.py --formats pdf # only the PDF report
|
|
87
|
+
python audit.py --ise-device-limit 200 # cap ISE device detail calls (1 GET per device)
|
|
88
|
+
python audit.py --fail-on high # exit code 1 if a HIGH finding exists (cron/CI)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Each run saves a JSON snapshot in `data/` and writes the reports in `reports/`. Both folders are git-ignored, because they contain your inventory.
|
|
92
|
+
|
|
93
|
+
### Dashboard
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
streamlit run dashboard.py
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The dashboard only reads the snapshots and never calls the Cisco APIs. It shows KPIs, findings with a severity filter, reachability, software versions per platform and the ISE inventory, and offers Excel and PDF downloads.
|
|
100
|
+
|
|
101
|
+
### Check the environment
|
|
102
|
+
|
|
103
|
+
Check the environment, which makes no API calls and uses no credentials:
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
python check_env.py
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
This checks the Python version, the installed packages and the `.env` file. It also runs a TCP and TLS handshake against each controller, with full certificate verification.
|
|
110
|
+
|
|
111
|
+
Use the clients from Python:
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from cisco_audit_tool.config import load_settings
|
|
115
|
+
from cisco_audit_tool.dnac import DnacClient
|
|
116
|
+
from cisco_audit_tool.ise import IseClient
|
|
117
|
+
|
|
118
|
+
s = load_settings()
|
|
119
|
+
dnac = DnacClient(s.dnac, s.ca_bundle, s.timeout)
|
|
120
|
+
print(dnac.ping()) # {'devices': 42, ...}
|
|
121
|
+
for dev in dnac.get_paged("/dna/intent/api/v1/network-device"):
|
|
122
|
+
print(dev["hostname"], dev["softwareVersion"])
|
|
123
|
+
|
|
124
|
+
ise = IseClient(s.ise, s.ca_bundle, s.timeout)
|
|
125
|
+
print(ise.ping()) # OpenAPI, falls back to ERS
|
|
126
|
+
for ep in ise.ers_paged("/ers/config/endpoint"):
|
|
127
|
+
print(ep["name"])
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Tests
|
|
131
|
+
|
|
132
|
+
The tests run fully offline (`requests` is mocked):
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
python -m unittest discover -s tests -v
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Configuration
|
|
139
|
+
|
|
140
|
+
All settings come from `.env` (see `.env.example`):
|
|
141
|
+
|
|
142
|
+
| Variable | Description |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `DNAC_URL`, `DNAC_USERNAME`, `DNAC_PASSWORD` | Catalyst Center |
|
|
145
|
+
| `ISE_URL`, `ISE_USERNAME`, `ISE_PASSWORD` | ISE (ERS/OpenAPI/MnT must be enabled) |
|
|
146
|
+
| `CA_BUNDLE` | Optional PEM file for your internal CA |
|
|
147
|
+
| `HTTP_TIMEOUT` | Seconds, default 30 |
|
|
148
|
+
|
|
149
|
+
**Never commit `.env`.** It is already in `.gitignore`, together with `certs/`, `data/`, `logs/` and `reports/`.
|
|
150
|
+
|
|
151
|
+
## Roadmap
|
|
152
|
+
|
|
153
|
+
- [x] Environment and TLS check
|
|
154
|
+
- [x] Read-only API clients (Catalyst Center, ISE) with offline tests
|
|
155
|
+
- [x] Inventory collection: Catalyst Center devices, ISE nodes, ISE network devices
|
|
156
|
+
- [x] 7 audit rules, including Catalyst Center and ISE cross-checks
|
|
157
|
+
- [x] Excel and PDF reports
|
|
158
|
+
- [x] Streamlit dashboard and demo mode
|
|
159
|
+
- [ ] More data: sites, interfaces, ISE endpoints, policy sets, certificate expiry
|
|
160
|
+
- [ ] More rules: end-of-life software, ISE certificate expiry, unused policy sets
|
|
161
|
+
- [ ] Trend comparison between two snapshots
|
|
162
|
+
- [x] PyPI package (`pip install cisco-audit-tool`) and CI on Linux/Windows, Python 3.10–3.13
|
|
163
|
+
|
|
164
|
+
## Contributing
|
|
165
|
+
|
|
166
|
+
Issues and pull requests are welcome. Please keep the read-only guarantee intact and add an offline test for every new API call.
|
|
167
|
+
|
|
168
|
+
## Disclaimer
|
|
169
|
+
|
|
170
|
+
Not affiliated with or endorsed by Cisco Systems. "Cisco", "Catalyst Center" and "ISE" are trademarks of Cisco Systems, Inc.
|
|
171
|
+
|
|
172
|
+
## License
|
|
173
|
+
|
|
174
|
+
[MIT](LICENSE)
|
|
File without changes
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"""Étape 1 : vérification de l'environnement. Aucune authentification, aucun appel API."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import importlib.metadata as md
|
|
5
|
+
import socket
|
|
6
|
+
import ssl
|
|
7
|
+
import sys
|
|
8
|
+
from urllib.parse import urlparse
|
|
9
|
+
|
|
10
|
+
REQUIRED = ["requests", "truststore", "python-dotenv", "pandas", "openpyxl", "reportlab"]
|
|
11
|
+
OPTIONAL = ["plotly", "streamlit"] # dashboard only: pip install "cisco-audit-tool[dashboard]"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def check_python() -> bool:
|
|
15
|
+
ok = sys.version_info >= (3, 10)
|
|
16
|
+
print(f"[{'OK' if ok else 'KO'}] Python {sys.version.split()[0]} ({sys.executable})")
|
|
17
|
+
return ok
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def check_packages() -> bool:
|
|
21
|
+
ok = True
|
|
22
|
+
for p in REQUIRED:
|
|
23
|
+
try:
|
|
24
|
+
print(f"[OK] {p} {md.version(p)}")
|
|
25
|
+
except md.PackageNotFoundError:
|
|
26
|
+
print(f"[KO] {p} absent")
|
|
27
|
+
ok = False
|
|
28
|
+
for p in OPTIONAL:
|
|
29
|
+
try:
|
|
30
|
+
print(f"[OK] {p} {md.version(p)} (dashboard)")
|
|
31
|
+
except md.PackageNotFoundError:
|
|
32
|
+
print(f"[--] {p} absent (dashboard only)")
|
|
33
|
+
return ok
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def check_tls(name: str, url: str, ca_bundle: str | None, timeout: int) -> bool:
|
|
37
|
+
"""Connexion TCP + poignée de main TLS avec vérification du certificat (sans identifiants)."""
|
|
38
|
+
if not url or url == "https://":
|
|
39
|
+
print(f"[--] {name} : URL non renseignée dans .env")
|
|
40
|
+
return False
|
|
41
|
+
u = urlparse(url)
|
|
42
|
+
host, port = u.hostname, u.port or 443
|
|
43
|
+
import truststore # magasin de certificats Windows
|
|
44
|
+
|
|
45
|
+
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
46
|
+
if ca_bundle:
|
|
47
|
+
ctx.load_verify_locations(ca_bundle)
|
|
48
|
+
try:
|
|
49
|
+
with socket.create_connection((host, port), timeout=timeout) as s:
|
|
50
|
+
with ctx.wrap_socket(s, server_hostname=host) as t:
|
|
51
|
+
print(f"[OK] {name} {host}:{port} joignable, certificat TLS vérifié ({t.version()})")
|
|
52
|
+
return True
|
|
53
|
+
except ssl.SSLError as e:
|
|
54
|
+
print(f"[KO] {name} {host}:{port} certificat refusé : {e}")
|
|
55
|
+
except OSError as e:
|
|
56
|
+
print(f"[KO] {name} {host}:{port} injoignable : {e}")
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def main() -> int:
|
|
61
|
+
print("== Python ==")
|
|
62
|
+
ok = check_python()
|
|
63
|
+
print("\n== Paquets ==")
|
|
64
|
+
ok &= check_packages()
|
|
65
|
+
print("\n== Configuration (.env) ==")
|
|
66
|
+
from cisco_audit_tool.config import ENV_FILE, load_settings
|
|
67
|
+
|
|
68
|
+
print(f"[{'OK' if ENV_FILE.exists() else '--'}] {ENV_FILE} {'présent' if ENV_FILE.exists() else 'absent (copier .env.example)'}")
|
|
69
|
+
st = load_settings()
|
|
70
|
+
for p in (st.dnac, st.ise):
|
|
71
|
+
print(f"[{'OK' if p.configured else '--'}] {p}")
|
|
72
|
+
print("\n== Réseau / TLS ==")
|
|
73
|
+
check_tls("Catalyst Center", st.dnac.url, st.ca_bundle, min(st.timeout, 10))
|
|
74
|
+
check_tls("ISE", st.ise.url, st.ca_bundle, min(st.timeout, 10))
|
|
75
|
+
return 0 if ok else 1
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""Command line: collect (read-only), run audit rules, write Excel/PDF reports.
|
|
2
|
+
|
|
3
|
+
Examples:
|
|
4
|
+
python audit.py --demo # fictional data, no Cisco gear needed
|
|
5
|
+
python audit.py # live collection using .env
|
|
6
|
+
python audit.py --snapshot data/snapshot_live_20261202T101500.json
|
|
7
|
+
python audit.py --fail-on high # exit code 1 if any HIGH finding (CI / scheduled runs)
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import logging
|
|
13
|
+
import sys
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
from .collect import collect, load_snapshot, save_snapshot
|
|
17
|
+
from .config import BASE_DIR, load_settings
|
|
18
|
+
from .demo import demo_snapshot
|
|
19
|
+
from .report import write_excel, write_pdf
|
|
20
|
+
from .rules import SEVERITY_ORDER, run_rules, summarize
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main(argv: list[str] | None = None) -> int:
|
|
24
|
+
ap = argparse.ArgumentParser(description="Read-only audit of Cisco Catalyst Center and ISE")
|
|
25
|
+
src = ap.add_mutually_exclusive_group()
|
|
26
|
+
src.add_argument("--demo", action="store_true", help="use fictional demo data")
|
|
27
|
+
src.add_argument("--snapshot", type=Path, help="re-audit an existing snapshot JSON instead of collecting")
|
|
28
|
+
ap.add_argument("--out", type=Path, default=BASE_DIR / "reports", help="report directory (default: reports/)")
|
|
29
|
+
ap.add_argument("--data", type=Path, default=BASE_DIR / "data", help="snapshot directory (default: data/)")
|
|
30
|
+
ap.add_argument("--formats", default="xlsx,pdf", help="comma list: xlsx,pdf (default: both)")
|
|
31
|
+
ap.add_argument("--ise-device-limit", type=int, default=None, help="max ISE network devices to read")
|
|
32
|
+
ap.add_argument("--fail-on", choices=["high", "medium", "low"], help="exit 1 if a finding of this severity or worse exists")
|
|
33
|
+
ap.add_argument("-v", "--verbose", action="store_true")
|
|
34
|
+
a = ap.parse_args(argv)
|
|
35
|
+
logging.basicConfig(level=logging.DEBUG if a.verbose else logging.WARNING, format="%(levelname)s %(message)s")
|
|
36
|
+
|
|
37
|
+
if a.snapshot:
|
|
38
|
+
snap = load_snapshot(a.snapshot)
|
|
39
|
+
else:
|
|
40
|
+
snap = demo_snapshot() if a.demo else collect(load_settings(), a.ise_device_limit)
|
|
41
|
+
print(f"Snapshot saved: {save_snapshot(snap, a.data)}")
|
|
42
|
+
|
|
43
|
+
findings = run_rules(snap)
|
|
44
|
+
s = summarize(snap, findings)
|
|
45
|
+
a.out.mkdir(parents=True, exist_ok=True)
|
|
46
|
+
base = a.out / f"audit_{snap['source']}_{snap['collected_at'].replace(':', '').replace('-', '')[:15]}"
|
|
47
|
+
formats = {f.strip().lower() for f in a.formats.split(",") if f.strip()}
|
|
48
|
+
if "xlsx" in formats:
|
|
49
|
+
write_excel(snap, findings, base.with_suffix(".xlsx"))
|
|
50
|
+
print(f"Excel report: {base.with_suffix('.xlsx')}")
|
|
51
|
+
if "pdf" in formats:
|
|
52
|
+
write_pdf(snap, findings, str(base.with_suffix(".pdf")))
|
|
53
|
+
print(f"PDF report: {base.with_suffix('.pdf')}")
|
|
54
|
+
|
|
55
|
+
print(f"\nCatalyst Center devices: {s['dnac_devices']} ({s['dnac_reachable']} reachable) | "
|
|
56
|
+
f"ISE nodes: {s['ise_nodes']} | ISE network devices: {s['ise_network_devices']}")
|
|
57
|
+
print(f"Findings: {s['findings']} (HIGH {s['high']}, MEDIUM {s['medium']}, LOW {s['low']})")
|
|
58
|
+
for f in findings:
|
|
59
|
+
print(f" [{f.severity:<6}] {f.source:<15} {str(f.item):<15} {f.message}")
|
|
60
|
+
for e in s["errors"]:
|
|
61
|
+
print(f" [ERROR ] {e}", file=sys.stderr)
|
|
62
|
+
|
|
63
|
+
if a.fail_on:
|
|
64
|
+
limit = SEVERITY_ORDER[a.fail_on.upper()]
|
|
65
|
+
if any(SEVERITY_ORDER[f.severity] <= limit for f in findings):
|
|
66
|
+
return 1
|
|
67
|
+
return 2 if s["errors"] and not (s["dnac_devices"] or s["ise_nodes"]) else 0
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
if __name__ == "__main__":
|
|
71
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"""Read-only inventory collection from Catalyst Center and ISE, saved as a JSON snapshot."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import json
|
|
5
|
+
import logging
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any
|
|
9
|
+
|
|
10
|
+
from .config import Settings
|
|
11
|
+
from .dnac import DnacClient
|
|
12
|
+
from .http import ApiError
|
|
13
|
+
from .ise import IseClient
|
|
14
|
+
|
|
15
|
+
log = logging.getLogger("cisco_audit")
|
|
16
|
+
|
|
17
|
+
DNAC_FIELDS = (
|
|
18
|
+
"id", "hostname", "managementIpAddress", "platformId", "family", "role", "series",
|
|
19
|
+
"softwareType", "softwareVersion", "serialNumber", "reachabilityStatus",
|
|
20
|
+
"reachabilityFailureReason", "collectionStatus", "upTime", "lastUpdated",
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def empty_snapshot(source: str) -> dict[str, Any]:
|
|
25
|
+
return {
|
|
26
|
+
"collected_at": datetime.now(timezone.utc).isoformat(timespec="seconds"),
|
|
27
|
+
"source": source,
|
|
28
|
+
"dnac_devices": [],
|
|
29
|
+
"ise_nodes": [],
|
|
30
|
+
"ise_network_devices": [],
|
|
31
|
+
"errors": [],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# --- Catalyst Center ---------------------------------------------------------
|
|
36
|
+
def collect_dnac_devices(client: DnacClient) -> list[dict]:
|
|
37
|
+
return [{k: d.get(k) for k in DNAC_FIELDS} for d in client.get_paged("/dna/intent/api/v1/network-device")]
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# --- ISE -----------------------------------------------------------------------
|
|
41
|
+
def _join(v: Any) -> str:
|
|
42
|
+
return ", ".join(str(x) for x in v) if isinstance(v, (list, tuple)) else (v or "")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def collect_ise_nodes(client: IseClient) -> list[dict]:
|
|
46
|
+
nodes = client.get("/api/v1/deployment/node").get("response", [])
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
"hostname": n.get("hostname"),
|
|
50
|
+
"fqdn": n.get("fqdn"),
|
|
51
|
+
"ipAddress": n.get("ipAddress"),
|
|
52
|
+
"roles": _join(n.get("roles")),
|
|
53
|
+
"services": _join(n.get("services")),
|
|
54
|
+
"nodeStatus": n.get("nodeStatus"),
|
|
55
|
+
}
|
|
56
|
+
for n in nodes
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def collect_ise_network_devices(client: IseClient, limit: int | None = None) -> list[dict]:
|
|
61
|
+
"""ERS list only returns id/name, so each device detail is read (one GET per device)."""
|
|
62
|
+
out = []
|
|
63
|
+
for i, r in enumerate(client.ers_paged("/ers/config/networkdevice")):
|
|
64
|
+
if limit is not None and i >= limit:
|
|
65
|
+
log.warning("ISE network devices: stopped at limit=%s", limit)
|
|
66
|
+
break
|
|
67
|
+
d = client.get(f"/ers/config/networkdevice/{r['id']}").get("NetworkDevice", {})
|
|
68
|
+
out.append(
|
|
69
|
+
{
|
|
70
|
+
"name": d.get("name") or r.get("name"),
|
|
71
|
+
"ips": [f"{x.get('ipaddress')}/{x.get('mask', 32)}" for x in d.get("NetworkDeviceIPList") or []],
|
|
72
|
+
"profileName": d.get("profileName"),
|
|
73
|
+
"groups": "; ".join(d.get("NetworkDeviceGroupList") or []),
|
|
74
|
+
}
|
|
75
|
+
)
|
|
76
|
+
return out
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# --- Orchestration -------------------------------------------------------------
|
|
80
|
+
def collect(settings: Settings, ise_device_limit: int | None = None) -> dict[str, Any]:
|
|
81
|
+
"""Collect everything that is configured. A failing platform is recorded in 'errors', not raised."""
|
|
82
|
+
snap = empty_snapshot("live")
|
|
83
|
+
if settings.dnac.configured:
|
|
84
|
+
try:
|
|
85
|
+
snap["dnac_devices"] = collect_dnac_devices(DnacClient(settings.dnac, settings.ca_bundle, settings.timeout))
|
|
86
|
+
except ApiError as e:
|
|
87
|
+
snap["errors"].append(f"Catalyst Center: {e}")
|
|
88
|
+
if settings.ise.configured:
|
|
89
|
+
ise = IseClient(settings.ise, settings.ca_bundle, settings.timeout)
|
|
90
|
+
for key, fn in (("ise_nodes", collect_ise_nodes),
|
|
91
|
+
("ise_network_devices", lambda c: collect_ise_network_devices(c, ise_device_limit))):
|
|
92
|
+
try:
|
|
93
|
+
snap[key] = fn(ise)
|
|
94
|
+
except ApiError as e:
|
|
95
|
+
snap["errors"].append(f"ISE ({key}): {e}")
|
|
96
|
+
if not (settings.dnac.configured or settings.ise.configured):
|
|
97
|
+
snap["errors"].append("No platform configured in .env")
|
|
98
|
+
return snap
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
def save_snapshot(snap: dict, directory: Path) -> Path:
|
|
102
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
103
|
+
stamp = snap["collected_at"].replace(":", "").replace("-", "")[:15]
|
|
104
|
+
path = directory / f"snapshot_{snap['source']}_{stamp}.json"
|
|
105
|
+
path.write_text(json.dumps(snap, indent=2, ensure_ascii=False), encoding="utf-8")
|
|
106
|
+
return path
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def load_snapshot(path: Path) -> dict[str, Any]:
|
|
110
|
+
return json.loads(Path(path).read_text(encoding="utf-8"))
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def list_snapshots(directory: Path) -> list[Path]:
|
|
114
|
+
return sorted(Path(directory).glob("snapshot_*.json"), key=lambda p: p.stat().st_mtime, reverse=True)
|