Skip to content

Commit 2fcb483

Browse files
authored
Websocket client (#15)
* adding websocket client * add ping_interval and ping_timeout params * add ws.ready() and explicit parameters * websocket tools added * refactor: consolidate error handling and improve security * feat(__api_request): consolidate retry logic into _request_with_retry - Extract HTTP operations into inner functions (_do_get, _do_post, etc.) - Centralize error handling for all HTTP methods - Reduces code duplication by ~55 lines * security(__api_session): remove SSL verification bypass in Vault client - Remove verify=False from hvac.Client initialization - Make vault attributes private (_vault_url, _vault_path, etc.) - Improve vault credentials cleanup in finally block * feat(__api_session): improve session management - Add _new_session() helper for consistent session initialization - Add validate parameter to set_api_token() for optional token validation - Fix delete_api_token() to return APIResponse instead of Response - Use mist_delete() method instead of raw session.delete() * perf(__init__): implement lazy loading for heavy subpackages - Defer api and cli imports until accessed - Improves initial import performance * fix(__logger): correct logging sanitization - Use getMessage() instead of direct msg access - Clear record.args after sanitization to prevent re-formatting This refactoring improves maintainability, security, and performance without changing the public API surface. * refactor: improve logging format in APIRequest class * Refactor API parameter handling and improve documentation - Updated `searchOrgNacClients` and `searchSiteNacClients` to correct status options from 'session_ended' to 'session_stopped'. - Rearranged parameters in `searchOrgWanClients`, `searchSiteWanClients`, and `searchSiteWirelessClients` for consistency and clarity. - Added new parameters `cert_expiry_duration` and `psk_name` to `searchSiteNacClients` and `searchSiteWirelessClients` respectively. - Removed unused parameters and cleaned up query parameter handling in various search functions. - Enhanced logging and sanitization in `test_logger.py` to ensure sensitive data is properly redacted. - Deleted obsolete test file `test.py` to streamline the test suite. - Improved test readability and structure across multiple test files. * code scanning fix
1 parent 1a17b6a commit 2fcb483

69 files changed

Lines changed: 10928 additions & 783 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "mist_openapi"]
22
path = mist_openapi
33
url = https://github.com/mistsys/mist_openapi.git
4-
branch = 2602.1.5
4+
branch = master

CHANGELOG.md

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,201 @@
11
# CHANGELOG
2+
## Version 0.61.0 (March 2026)
3+
4+
**Released**: March 13, 2026
5+
6+
**MAJOR RELEASE** with extensive new features, code quality improvements, security enhancements, and performance optimizations. This release adds real-time WebSocket streaming, comprehensive device diagnostic utilities, extensive test coverage, and significant API improvements.
7+
8+
---
9+
10+
### 1. NEW FEATURES
11+
12+
#### **1.1 WebSocket Streaming Module** (`mistapi.websockets`)
13+
Complete real-time event streaming support with flexible consumption patterns:
14+
15+
**Available Channels:**
16+
* Organization Channels
17+
18+
| Class | Description |
19+
|-------|-------------|
20+
| `mistapi.websockets.orgs.InsightsEvents` | Real-time insights events for an organization |
21+
| `mistapi.websockets.orgs.MxEdgesStatsEvents` | Real-time MX edges stats for an organization |
22+
| `mistapi.websockets.orgs.MxEdgesUpgradesEvents` | Real-time MX edges upgrades events for an organization |
23+
24+
* Site Channels
25+
26+
| Class | Description |
27+
|-------|-------------|
28+
| `mistapi.websockets.sites.ClientsStatsEvents` | Real-time clients stats for a site |
29+
| `mistapi.websockets.sites.DeviceCmdEvents` | Real-time device command events for a site |
30+
| `mistapi.websockets.sites.DeviceStatsEvents` | Real-time device stats for a site |
31+
| `mistapi.websockets.sites.DeviceUpgradesEvents` | Real-time device upgrades events for a site |
32+
| `mistapi.websockets.sites.MxEdgesStatsEvents` | Real-time MX edges stats for a site |
33+
| `mistapi.websockets.sites.PcapEvents` | Real-time PCAP events for a site |
34+
35+
* Location Channels
36+
37+
| Class | Description |
38+
|-------|-------------|
39+
| `mistapi.websockets.location.BleAssetsEvents` | Real-time BLE assets location events |
40+
| `mistapi.websockets.location.ConnectedClientsEvents` | Real-time connected clients location events |
41+
| `mistapi.websockets.location.SdkClientsEvents` | Real-time SDK clients location events |
42+
| `mistapi.websockets.location.UnconnectedClientsEvents` | Real-time unconnected clients location events |
43+
| `mistapi.websockets.location.DiscoveredBleAssetsEvents` | Real-time discovered BLE assets location events |
44+
45+
46+
**Features:**
47+
- Callback-based message handling
48+
- Generator-style iteration
49+
- Context manager support
50+
- Automatic reconnection with configurable ping intervals
51+
- Non-blocking background threads
52+
- Type-safe API with full parameter validation
53+
54+
**Example Usage:**
55+
```python
56+
ws = mistapi.websockets.sites.DeviceStatsEvents(apisession, site_ids=["<site_id>"])
57+
ws.connect(run_in_background=True)
58+
59+
for msg in ws.receive(): # blocks, yields each message as a dict
60+
print(msg)
61+
if some_condition:
62+
ws.disconnect() # stops the generator cleanly
63+
```
64+
65+
#### **1.2 Device Utilities Module** (`mistapi.device_utils`)
66+
`mistapi.device_utils` provides high-level utilities for running diagnostic commands on Mist-managed devices. Each function triggers a REST API call and streams the results back via WebSocket. The library handles the connection plumbing — you just call the function and get back a `UtilResponse` object.
67+
68+
**Device-Specific Modules** (Recommended):
69+
| Module | Device Type | Functions |
70+
|--------|-------------|-----------|
71+
| `device_utils.ap` | Mist Access Points | `ping`, `traceroute`, `retrieveArpTable` |
72+
| `device_utils.ex` | Juniper EX Switches | `ping`, `monitorTraffic`, `retrieveArpTable`, `retrieveBgpSummary`, `retrieveDhcpLeases`, `releaseDhcpLeases`, `retrieveMacTable`, `clearMacTable`, `clearLearnedMac`, `clearBpduError`, `clearDot1xSessions`, `clearHitCount`, `bouncePort`, `cableTest` |
73+
| `device_utils.srx` | Juniper SRX Firewalls | `ping`, `monitorTraffic`, `retrieveArpTable`, `retrieveBgpSummary`, `retrieveDhcpLeases`, `releaseDhcpLeases`, `showDatabase`, `showNeighbors`, `showInterfaces`, `bouncePort`, `retrieveRoutes` |
74+
| `device_utils.ssr` | Juniper SSR Routers | `ping`, `retrieveArpTable`, `retrieveBgpSummary`, `retrieveDhcpLeases`, `releaseDhcpLeases`, `showDatabase`, `showNeighbors`, `showInterfaces`, `bouncePort`, `retrieveRoutes`, `showServicePath` |
75+
76+
**Example Usage:**
77+
```python
78+
from mistapi.device_utils import ap, ex
79+
80+
# Ping from an AP
81+
result = ap.ping(apisession, site_id, device_id, host="8.8.8.8")
82+
print(result.ws_data)
83+
84+
# Retrieve ARP table from a switch
85+
result = ex.retrieveArpTable(apisession, site_id, device_id)
86+
print(result.ws_data)
87+
88+
# With real-time callback
89+
def handle(msg):
90+
print("got:", msg)
91+
92+
result = ex.cableTest(apisession, site_id, device_id, port="ge-0/0/0", on_message=handle)
93+
```
94+
95+
#### **1.3 New API Endpoints**
96+
97+
**MapStacks API** (`mistapi.api.v1.sites.mapstacks`):
98+
- `listSiteMapStacks()`: List map stacks with filtering
99+
- `createSiteMapStack()`: Create new map stack
100+
101+
**Enhanced Query Parameters**:
102+
- Additional filtering options across alarms, clients, and devices endpoints
103+
- Improved parameter handling in JSI, NAC clients, and WAN clients APIs
104+
105+
---
106+
107+
### 2. SECURITY IMPROVEMENTS
108+
109+
##### **HashiCorp Vault SSL Verification**
110+
- Now properly verifies SSL certificates when connecting to Vault
111+
- Made vault configuration attributes private (`_vault_url`, `_vault_path`, etc.)
112+
- Improved cleanup of vault credentials after loading
113+
114+
---
115+
116+
### 3. PERFORMANCE IMPROVEMENTS
117+
118+
##### **Lazy Module Loading**
119+
- Implemented lazy loading for `api` and `cli` subpackages
120+
- Reduces initial import time by deferring heavy module imports until accessed
121+
- Uses `__getattr__` for transparent lazy loading
122+
123+
---
124+
125+
### 4. CODE QUALITY IMPROVEMENTS
126+
127+
##### **HTTP Request Error Handling**
128+
- Consolidated duplicate error handling logic into `_request_with_retry()` method
129+
- Extracts HTTP operations into inner functions for cleaner code
130+
- Reduces code duplication by ~55 lines across GET/POST/PUT/DELETE/POST_FILE methods
131+
- Centralizes 429 rate limit handling and retry logic
132+
133+
##### **Session Management**
134+
- Added `_new_session()` helper method for consistent session initialization
135+
- Improves code reusability when creating new HTTP sessions
136+
137+
##### **API Token Management**
138+
- Added `validate` parameter to `set_api_token()` method
139+
- Allows skipping token validation when needed (default: `True`)
140+
- Useful for faster initialization when tokens are known to be valid
141+
142+
##### **Logging Improvements**
143+
- Fixed logging sanitization to use `getMessage()` instead of direct `msg` access
144+
- Clear `record.args` after sanitization to prevent re-formatting issues
145+
- Improved logging format consistency using %-style formatting
146+
147+
---
148+
149+
### 6. DEPENDENCIES
150+
151+
##### **New Dependencies**
152+
- Added `websocket-client>=1.8.0` for WebSocket streaming support
153+
154+
---
155+
156+
## Version 0.60.3 (February 2026)
157+
158+
**Released**: February 21, 2026
159+
160+
This release add a missing query parameter to the `searchOrgWanClients()` function.
161+
162+
---
163+
164+
### 1. CHANGES
165+
166+
##### **API Function Updates**
167+
- Updated `searchOrgWanClients()` and related functions in `orgs/wan_clients.py`.
168+
169+
---
170+
171+
## Version 0.60.1 (February 2026)
172+
173+
**Released**: February 21, 2026
174+
175+
This release includes function updates and bug fixes in the self/logs.py and sites/sle.py modules.
176+
177+
---
178+
179+
### 1. CHANGES
180+
181+
##### **API Function Updates**
182+
- Updated `listSelfAuditLogs()` and related functions in `self/logs.py`.
183+
- Updated deprecated and new SLE classifier functions in `sites/sle.py`.
184+
185+
---
186+
187+
### 2. BUG FIXES
188+
189+
- Minor bug fixes and improvements in API modules.
190+
191+
---
192+
193+
### Breaking Changes
194+
195+
No breaking changes in this release.
196+
197+
---
198+
2199
## Version 0.60.4 (March 2026)
3200

4201
**Released**: March 3, 2026

0 commit comments

Comments
 (0)