isptools-pro 3.0.0__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.
- isptools_pro-3.0.0/LICENSE +21 -0
- isptools_pro-3.0.0/MANIFEST.in +3 -0
- isptools_pro-3.0.0/PKG-INFO +261 -0
- isptools_pro-3.0.0/README.md +220 -0
- isptools_pro-3.0.0/autofix/__init__.py +5 -0
- isptools_pro-3.0.0/autofix/engine.py +91 -0
- isptools_pro-3.0.0/autofix/permissions.py +31 -0
- isptools_pro-3.0.0/autofix/rules.py +64 -0
- isptools_pro-3.0.0/core/__init__.py +4 -0
- isptools_pro-3.0.0/core/base.py +47 -0
- isptools_pro-3.0.0/core/exceptions.py +15 -0
- isptools_pro-3.0.0/drivers/__init__.py +6 -0
- isptools_pro-3.0.0/drivers/cisco.py +165 -0
- isptools_pro-3.0.0/drivers/mikrotik.py +179 -0
- isptools_pro-3.0.0/drivers/snmp.py +114 -0
- isptools_pro-3.0.0/drivers/ubiquiti.py +273 -0
- isptools_pro-3.0.0/isptools_pro.egg-info/PKG-INFO +261 -0
- isptools_pro-3.0.0/isptools_pro.egg-info/SOURCES.txt +37 -0
- isptools_pro-3.0.0/isptools_pro.egg-info/dependency_links.txt +1 -0
- isptools_pro-3.0.0/isptools_pro.egg-info/entry_points.txt +2 -0
- isptools_pro-3.0.0/isptools_pro.egg-info/requires.txt +15 -0
- isptools_pro-3.0.0/isptools_pro.egg-info/top_level.txt +7 -0
- isptools_pro-3.0.0/models/__init__.py +5 -0
- isptools_pro-3.0.0/models/device.py +13 -0
- isptools_pro-3.0.0/models/station.py +14 -0
- isptools_pro-3.0.0/models/stats.py +13 -0
- isptools_pro-3.0.0/monitor/__init__.py +4 -0
- isptools_pro-3.0.0/monitor/alerts.py +65 -0
- isptools_pro-3.0.0/monitor/poller.py +65 -0
- isptools_pro-3.0.0/pyproject.toml +54 -0
- isptools_pro-3.0.0/reports/__init__.py +4 -0
- isptools_pro-3.0.0/reports/collector.py +100 -0
- isptools_pro-3.0.0/reports/reporter.py +121 -0
- isptools_pro-3.0.0/setup.cfg +4 -0
- isptools_pro-3.0.0/setup.py +36 -0
- isptools_pro-3.0.0/tests/test_models.py +22 -0
- isptools_pro-3.0.0/topology/__init__.py +4 -0
- isptools_pro-3.0.0/topology/exporter.py +36 -0
- isptools_pro-3.0.0/topology/mapper.py +62 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 devyassin01
|
|
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,261 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: isptools-pro
|
|
3
|
+
Version: 3.0.0
|
|
4
|
+
Summary: Python library for ISP network management - MikroTik, Ubiquiti NanoStation, Cisco, SNMP
|
|
5
|
+
Home-page: https://github.com/alexiq01/IspTool
|
|
6
|
+
Author: devyassin01
|
|
7
|
+
Author-email: devyassin01 <developeryassin01@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/alexiq01/IspTool
|
|
10
|
+
Project-URL: Repository, https://github.com/alexiq01/IspTool
|
|
11
|
+
Project-URL: Bug Tracker, https://github.com/alexiq01/IspTool/issues
|
|
12
|
+
Project-URL: Instagram, https://instagram.com/y_as.01
|
|
13
|
+
Keywords: networking,isp,mikrotik,ubiquiti,nanostation,snmp,cisco,network-management
|
|
14
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Requires-Python: >=3.10
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: routeros-api>=0.17.0
|
|
25
|
+
Requires-Dist: requests>=2.28.0
|
|
26
|
+
Requires-Dist: urllib3>=1.26.0
|
|
27
|
+
Requires-Dist: netmiko>=4.0.0
|
|
28
|
+
Requires-Dist: pysnmp>=4.4.12
|
|
29
|
+
Requires-Dist: click>=8.1.0
|
|
30
|
+
Requires-Dist: tabulate>=0.9.0
|
|
31
|
+
Provides-Extra: telegram
|
|
32
|
+
Requires-Dist: requests>=2.28.0; extra == "telegram"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
37
|
+
Dynamic: author
|
|
38
|
+
Dynamic: home-page
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
Dynamic: requires-python
|
|
41
|
+
|
|
42
|
+
# isptools 🌐 (v3.0.0)
|
|
43
|
+
|
|
44
|
+
[](https://pypi.org/project/isptools/)
|
|
45
|
+
[](https://pypi.org/project/isptools/)
|
|
46
|
+
[](https://opensource.org/licenses/MIT)
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
### 🌍 (Arabic / العربية)
|
|
51
|
+
|
|
52
|
+
**isptools** هي مكتبة Python احترافية وأداة سطر أوامر (CLI) متكاملة مصممة خصيصاً لمهندسي الشبكات وفنيي مزودي خدمات الإنترنت (ISPs).
|
|
53
|
+
|
|
54
|
+
#### ❓ ما هي أداة isptools؟
|
|
55
|
+
هي أداة شاملة لإدارة أجهزة الشبكة من شركات مختلفة مثل **MikroTik**, **Ubiquiti**, **Cisco**, و أجهزة **SNMP** عبر واجهة موحدة.
|
|
56
|
+
|
|
57
|
+
#### ⚙️ كيف تعمل الأداة؟
|
|
58
|
+
1. **الاتصال الموحد:** تستخدم بروتوكولات (SSH, HTTP, API) للوصول للأجهزة.
|
|
59
|
+
2. **التحليل:** تحول البيانات المعقدة إلى تقارير بسيطة.
|
|
60
|
+
3. **الإصلاح التلقائي (AutoFix):** تكتشف المشاكل (مثل ضعف الإشارة) وتعالجها تلقائياً.
|
|
61
|
+
4. **رسم الخرائط:** ترسم خريطة الشبكة (Topology) آلياً.
|
|
62
|
+
|
|
63
|
+
#### 👨💻 المطور
|
|
64
|
+
تم التطوير بواسطة **ياسين طه (devyassin01)**.
|
|
65
|
+
- **GitHub:** [devyassin01](https://github.com/alexiq01)
|
|
66
|
+
- **Instagram:** [@y_as.01](https://instagram.com/y_as.01)
|
|
67
|
+
|
|
68
|
+
#### 💻 الأنظمة المدعومة
|
|
69
|
+
تعمل على: **Linux**, **Windows**, **macOS**, و **Android (Termux)**.
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### 🌎 (English / الإنجليزية)
|
|
74
|
+
|
|
75
|
+
**isptools** is a professional Python library and CLI tool designed specifically for network engineers and ISP technicians.
|
|
76
|
+
|
|
77
|
+
#### ❓ What is isptools?
|
|
78
|
+
It is a comprehensive tool for managing network equipment from multiple vendors like **MikroTik**, **Ubiquiti**, **Cisco**, and **SNMP** devices through a unified interface.
|
|
79
|
+
|
|
80
|
+
#### ⚙️ How does it work?
|
|
81
|
+
1. **Unified Connection:** Uses standard protocols (SSH, HTTP, API) to access devices.
|
|
82
|
+
2. **Analysis:** Converts complex data into simple, readable reports.
|
|
83
|
+
3. **Self-Healing (AutoFix):** Detects issues (like low signal) and fixes them automatically.
|
|
84
|
+
4. **Topology Mapping:** Automatically maps the network structure.
|
|
85
|
+
|
|
86
|
+
#### 👨💻 Developer
|
|
87
|
+
Developed by **Yassin Taha (devyassin01)**.
|
|
88
|
+
- **GitHub:** [devyassin01](https://github.com/alexiq01)
|
|
89
|
+
- **Instagram:** [@y_as.01](https://instagram.com/y_as.01)
|
|
90
|
+
|
|
91
|
+
#### 💻 Supported Systems
|
|
92
|
+
Runs on: **Linux**, **Windows**, **macOS**, and **Android (Termux)**.
|
|
93
|
+
|
|
94
|
+
---
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
## Features
|
|
98
|
+
- **Unified API:** One library to talk to multiple vendor platforms.
|
|
99
|
+
- **MikroTik:** Full support via RouterOS API.
|
|
100
|
+
- **Ubiquiti NanoStation:** Deep integration with airOS 6.x/8.x (Auto-detection, Link Quality, Spectrum Scan).
|
|
101
|
+
- **Cisco:** Command execution via SSH (Netmiko).
|
|
102
|
+
- **SNMP:** Generic monitoring support (v1, v2c, v3).
|
|
103
|
+
- **CLI Tool:** Powerful `isptools` command for terminal-based management.
|
|
104
|
+
- **Monitoring:** Built-in asynchronous poller for concurrent device monitoring.
|
|
105
|
+
- **Alerting:** Flexible alert manager with threshold-based rules.
|
|
106
|
+
|
|
107
|
+
## Installation
|
|
108
|
+
```bash
|
|
109
|
+
pip install isptools
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## CLI Usage
|
|
113
|
+
The library comes with a powerful CLI tool:
|
|
114
|
+
```bash
|
|
115
|
+
# Scan a device for full info
|
|
116
|
+
isptools scan --host 192.168.1.20 --user admin --password pass --type ubiquiti
|
|
117
|
+
|
|
118
|
+
# List connected clients
|
|
119
|
+
isptools clients --host 192.168.1.1 --user admin --password pass --type mikrotik
|
|
120
|
+
|
|
121
|
+
# Live monitor stats
|
|
122
|
+
isptools monitor --host 10.0.0.1 --user ubnt --password ubnt --type ubiquiti --interval 2
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Quick Start (Python API)
|
|
126
|
+
|
|
127
|
+
### Basic Usage
|
|
128
|
+
```python
|
|
129
|
+
from isptools import ISPTools, Device
|
|
130
|
+
|
|
131
|
+
# Initialize
|
|
132
|
+
isp = ISPTools()
|
|
133
|
+
|
|
134
|
+
# Add a MikroTik device
|
|
135
|
+
isp.add_device(Device(
|
|
136
|
+
host="192.168.88.1",
|
|
137
|
+
username="admin",
|
|
138
|
+
password="password",
|
|
139
|
+
device_type="mikrotik"
|
|
140
|
+
))
|
|
141
|
+
|
|
142
|
+
# Connect and get stats
|
|
143
|
+
isp.connect_all()
|
|
144
|
+
stats = isp.get_stats("192.168.88.1")
|
|
145
|
+
print(f"CPU Load: {stats.cpu_load}%")
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Advanced NanoStation Support
|
|
149
|
+
```python
|
|
150
|
+
from isptools import ISPTools, Device
|
|
151
|
+
|
|
152
|
+
isp = ISPTools()
|
|
153
|
+
isp.add_device(Device(host="192.168.1.20", username="ubnt", password="ubnt", device_type="ubiquiti"))
|
|
154
|
+
isp.connect_all()
|
|
155
|
+
|
|
156
|
+
driver = isp.devices["192.168.1.20"]
|
|
157
|
+
quality = driver.get_link_quality()
|
|
158
|
+
print(f"Link Quality Score: {quality['score']}/100 ({quality['level']})")
|
|
159
|
+
|
|
160
|
+
# Run spectrum scan
|
|
161
|
+
# results = driver.scan_spectrum()
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Advanced Features
|
|
165
|
+
|
|
166
|
+
### AutoFix (Self-Healing)
|
|
167
|
+
Automatically detect and repair common network issues with a permission-based system.
|
|
168
|
+
```python
|
|
169
|
+
from isptools import ISPTools, Device, PermissionManager, PermissionLevel, AutoFixEngine
|
|
170
|
+
|
|
171
|
+
pm = PermissionManager(level=PermissionLevel.SAFE_FIX, require_confirm=True)
|
|
172
|
+
engine = AutoFixEngine(pm)
|
|
173
|
+
|
|
174
|
+
isp = ISPTools()
|
|
175
|
+
# ... add devices ...
|
|
176
|
+
stats = isp.get_stats("192.168.1.20")
|
|
177
|
+
results = engine.apply_fixes(isp.devices["192.168.1.20"], stats.__dict__)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### Network Topology Mapping
|
|
181
|
+
Discover how your devices are connected and export the graph.
|
|
182
|
+
```python
|
|
183
|
+
from isptools import TopologyMapper, TopologyExporter
|
|
184
|
+
|
|
185
|
+
mapper = TopologyMapper(list(isp.devices.values()))
|
|
186
|
+
graph = mapper.discover()
|
|
187
|
+
print(TopologyExporter.to_mermaid(graph))
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Reports & History
|
|
191
|
+
Track bandwidth and performance over time using SQLite.
|
|
192
|
+
```python
|
|
193
|
+
from isptools import StatsCollector, Reporter
|
|
194
|
+
|
|
195
|
+
collector = StatsCollector()
|
|
196
|
+
reporter = Reporter(collector)
|
|
197
|
+
|
|
198
|
+
# After some polling...
|
|
199
|
+
reporter.export_html("192.168.1.1", hours=24, output_path="daily_report.html")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Telegram Alerts
|
|
203
|
+
Get notified of issues directly on your phone.
|
|
204
|
+
```python
|
|
205
|
+
from isptools import TelegramNotifier
|
|
206
|
+
|
|
207
|
+
tg = TelegramNotifier(bot_token="YOUR_TOKEN", chat_id="YOUR_ID")
|
|
208
|
+
tg.send_alert("192.168.1.20", "Signal dropped to -85 dBm", "Increased TX power ✅")
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
## API Reference
|
|
212
|
+
|
|
213
|
+
### `Device` Dataclass
|
|
214
|
+
| Field | Type | Description |
|
|
215
|
+
|-------|------|-------------|
|
|
216
|
+
| `host` | `str` | IP address or hostname |
|
|
217
|
+
| `username`| `str` | Login username |
|
|
218
|
+
| `password`| `str` | Login password |
|
|
219
|
+
| `device_type`| `str` | `mikrotik`, `ubiquiti`, `cisco`, `snmp` |
|
|
220
|
+
| `port` | `int` | Optional override port |
|
|
221
|
+
|
|
222
|
+
### `ISPTools` Class Methods
|
|
223
|
+
- `add_device(device: Device)`: Register a device.
|
|
224
|
+
- `connect_all()`: Establish connections to all devices.
|
|
225
|
+
- `get_stats(host: str) -> DeviceStats`: Fetch performance metrics.
|
|
226
|
+
- `get_clients(host: str) -> List[Station]`: List connected clients.
|
|
227
|
+
- `start_monitor(interval: int)`: Start async background polling.
|
|
228
|
+
- `stop_monitor()`: Stop polling.
|
|
229
|
+
|
|
230
|
+
## Publishing
|
|
231
|
+
To publish a new version to PyPI:
|
|
232
|
+
1. Update version in `isptools/version.py`.
|
|
233
|
+
2. Commit changes and push.
|
|
234
|
+
3. Create a git tag:
|
|
235
|
+
```bash
|
|
236
|
+
git tag -a v3.0.0 -m "Release version 3.0.0"
|
|
237
|
+
git push origin v3.0.0
|
|
238
|
+
```
|
|
239
|
+
GitHub Actions will automatically build and publish to PyPI.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## 👨💻 Developer
|
|
244
|
+
|
|
245
|
+
**isptools** was developed by **Yassin Taha**
|
|
246
|
+
|
|
247
|
+
[
|
|
248
|
+
|
|
249
|
+

|
|
250
|
+
|
|
251
|
+
](https://instagram.com/y_as.01)
|
|
252
|
+
[
|
|
253
|
+
|
|
254
|
+

|
|
255
|
+
|
|
256
|
+
](https://github.com/alexiq01)
|
|
257
|
+
|
|
258
|
+
> Built with ❤️ for ISP engineers and network technicians.
|
|
259
|
+
|
|
260
|
+
## License
|
|
261
|
+
MIT
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# isptools 🌐 (v3.0.0)
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/isptools/)
|
|
4
|
+
[](https://pypi.org/project/isptools/)
|
|
5
|
+
[](https://opensource.org/licenses/MIT)
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
### 🌍 (Arabic / العربية)
|
|
10
|
+
|
|
11
|
+
**isptools** هي مكتبة Python احترافية وأداة سطر أوامر (CLI) متكاملة مصممة خصيصاً لمهندسي الشبكات وفنيي مزودي خدمات الإنترنت (ISPs).
|
|
12
|
+
|
|
13
|
+
#### ❓ ما هي أداة isptools؟
|
|
14
|
+
هي أداة شاملة لإدارة أجهزة الشبكة من شركات مختلفة مثل **MikroTik**, **Ubiquiti**, **Cisco**, و أجهزة **SNMP** عبر واجهة موحدة.
|
|
15
|
+
|
|
16
|
+
#### ⚙️ كيف تعمل الأداة؟
|
|
17
|
+
1. **الاتصال الموحد:** تستخدم بروتوكولات (SSH, HTTP, API) للوصول للأجهزة.
|
|
18
|
+
2. **التحليل:** تحول البيانات المعقدة إلى تقارير بسيطة.
|
|
19
|
+
3. **الإصلاح التلقائي (AutoFix):** تكتشف المشاكل (مثل ضعف الإشارة) وتعالجها تلقائياً.
|
|
20
|
+
4. **رسم الخرائط:** ترسم خريطة الشبكة (Topology) آلياً.
|
|
21
|
+
|
|
22
|
+
#### 👨💻 المطور
|
|
23
|
+
تم التطوير بواسطة **ياسين طه (devyassin01)**.
|
|
24
|
+
- **GitHub:** [devyassin01](https://github.com/alexiq01)
|
|
25
|
+
- **Instagram:** [@y_as.01](https://instagram.com/y_as.01)
|
|
26
|
+
|
|
27
|
+
#### 💻 الأنظمة المدعومة
|
|
28
|
+
تعمل على: **Linux**, **Windows**, **macOS**, و **Android (Termux)**.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
### 🌎 (English / الإنجليزية)
|
|
33
|
+
|
|
34
|
+
**isptools** is a professional Python library and CLI tool designed specifically for network engineers and ISP technicians.
|
|
35
|
+
|
|
36
|
+
#### ❓ What is isptools?
|
|
37
|
+
It is a comprehensive tool for managing network equipment from multiple vendors like **MikroTik**, **Ubiquiti**, **Cisco**, and **SNMP** devices through a unified interface.
|
|
38
|
+
|
|
39
|
+
#### ⚙️ How does it work?
|
|
40
|
+
1. **Unified Connection:** Uses standard protocols (SSH, HTTP, API) to access devices.
|
|
41
|
+
2. **Analysis:** Converts complex data into simple, readable reports.
|
|
42
|
+
3. **Self-Healing (AutoFix):** Detects issues (like low signal) and fixes them automatically.
|
|
43
|
+
4. **Topology Mapping:** Automatically maps the network structure.
|
|
44
|
+
|
|
45
|
+
#### 👨💻 Developer
|
|
46
|
+
Developed by **Yassin Taha (devyassin01)**.
|
|
47
|
+
- **GitHub:** [devyassin01](https://github.com/alexiq01)
|
|
48
|
+
- **Instagram:** [@y_as.01](https://instagram.com/y_as.01)
|
|
49
|
+
|
|
50
|
+
#### 💻 Supported Systems
|
|
51
|
+
Runs on: **Linux**, **Windows**, **macOS**, and **Android (Termux)**.
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
## Features
|
|
57
|
+
- **Unified API:** One library to talk to multiple vendor platforms.
|
|
58
|
+
- **MikroTik:** Full support via RouterOS API.
|
|
59
|
+
- **Ubiquiti NanoStation:** Deep integration with airOS 6.x/8.x (Auto-detection, Link Quality, Spectrum Scan).
|
|
60
|
+
- **Cisco:** Command execution via SSH (Netmiko).
|
|
61
|
+
- **SNMP:** Generic monitoring support (v1, v2c, v3).
|
|
62
|
+
- **CLI Tool:** Powerful `isptools` command for terminal-based management.
|
|
63
|
+
- **Monitoring:** Built-in asynchronous poller for concurrent device monitoring.
|
|
64
|
+
- **Alerting:** Flexible alert manager with threshold-based rules.
|
|
65
|
+
|
|
66
|
+
## Installation
|
|
67
|
+
```bash
|
|
68
|
+
pip install isptools
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## CLI Usage
|
|
72
|
+
The library comes with a powerful CLI tool:
|
|
73
|
+
```bash
|
|
74
|
+
# Scan a device for full info
|
|
75
|
+
isptools scan --host 192.168.1.20 --user admin --password pass --type ubiquiti
|
|
76
|
+
|
|
77
|
+
# List connected clients
|
|
78
|
+
isptools clients --host 192.168.1.1 --user admin --password pass --type mikrotik
|
|
79
|
+
|
|
80
|
+
# Live monitor stats
|
|
81
|
+
isptools monitor --host 10.0.0.1 --user ubnt --password ubnt --type ubiquiti --interval 2
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Quick Start (Python API)
|
|
85
|
+
|
|
86
|
+
### Basic Usage
|
|
87
|
+
```python
|
|
88
|
+
from isptools import ISPTools, Device
|
|
89
|
+
|
|
90
|
+
# Initialize
|
|
91
|
+
isp = ISPTools()
|
|
92
|
+
|
|
93
|
+
# Add a MikroTik device
|
|
94
|
+
isp.add_device(Device(
|
|
95
|
+
host="192.168.88.1",
|
|
96
|
+
username="admin",
|
|
97
|
+
password="password",
|
|
98
|
+
device_type="mikrotik"
|
|
99
|
+
))
|
|
100
|
+
|
|
101
|
+
# Connect and get stats
|
|
102
|
+
isp.connect_all()
|
|
103
|
+
stats = isp.get_stats("192.168.88.1")
|
|
104
|
+
print(f"CPU Load: {stats.cpu_load}%")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Advanced NanoStation Support
|
|
108
|
+
```python
|
|
109
|
+
from isptools import ISPTools, Device
|
|
110
|
+
|
|
111
|
+
isp = ISPTools()
|
|
112
|
+
isp.add_device(Device(host="192.168.1.20", username="ubnt", password="ubnt", device_type="ubiquiti"))
|
|
113
|
+
isp.connect_all()
|
|
114
|
+
|
|
115
|
+
driver = isp.devices["192.168.1.20"]
|
|
116
|
+
quality = driver.get_link_quality()
|
|
117
|
+
print(f"Link Quality Score: {quality['score']}/100 ({quality['level']})")
|
|
118
|
+
|
|
119
|
+
# Run spectrum scan
|
|
120
|
+
# results = driver.scan_spectrum()
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Advanced Features
|
|
124
|
+
|
|
125
|
+
### AutoFix (Self-Healing)
|
|
126
|
+
Automatically detect and repair common network issues with a permission-based system.
|
|
127
|
+
```python
|
|
128
|
+
from isptools import ISPTools, Device, PermissionManager, PermissionLevel, AutoFixEngine
|
|
129
|
+
|
|
130
|
+
pm = PermissionManager(level=PermissionLevel.SAFE_FIX, require_confirm=True)
|
|
131
|
+
engine = AutoFixEngine(pm)
|
|
132
|
+
|
|
133
|
+
isp = ISPTools()
|
|
134
|
+
# ... add devices ...
|
|
135
|
+
stats = isp.get_stats("192.168.1.20")
|
|
136
|
+
results = engine.apply_fixes(isp.devices["192.168.1.20"], stats.__dict__)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Network Topology Mapping
|
|
140
|
+
Discover how your devices are connected and export the graph.
|
|
141
|
+
```python
|
|
142
|
+
from isptools import TopologyMapper, TopologyExporter
|
|
143
|
+
|
|
144
|
+
mapper = TopologyMapper(list(isp.devices.values()))
|
|
145
|
+
graph = mapper.discover()
|
|
146
|
+
print(TopologyExporter.to_mermaid(graph))
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Reports & History
|
|
150
|
+
Track bandwidth and performance over time using SQLite.
|
|
151
|
+
```python
|
|
152
|
+
from isptools import StatsCollector, Reporter
|
|
153
|
+
|
|
154
|
+
collector = StatsCollector()
|
|
155
|
+
reporter = Reporter(collector)
|
|
156
|
+
|
|
157
|
+
# After some polling...
|
|
158
|
+
reporter.export_html("192.168.1.1", hours=24, output_path="daily_report.html")
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Telegram Alerts
|
|
162
|
+
Get notified of issues directly on your phone.
|
|
163
|
+
```python
|
|
164
|
+
from isptools import TelegramNotifier
|
|
165
|
+
|
|
166
|
+
tg = TelegramNotifier(bot_token="YOUR_TOKEN", chat_id="YOUR_ID")
|
|
167
|
+
tg.send_alert("192.168.1.20", "Signal dropped to -85 dBm", "Increased TX power ✅")
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## API Reference
|
|
171
|
+
|
|
172
|
+
### `Device` Dataclass
|
|
173
|
+
| Field | Type | Description |
|
|
174
|
+
|-------|------|-------------|
|
|
175
|
+
| `host` | `str` | IP address or hostname |
|
|
176
|
+
| `username`| `str` | Login username |
|
|
177
|
+
| `password`| `str` | Login password |
|
|
178
|
+
| `device_type`| `str` | `mikrotik`, `ubiquiti`, `cisco`, `snmp` |
|
|
179
|
+
| `port` | `int` | Optional override port |
|
|
180
|
+
|
|
181
|
+
### `ISPTools` Class Methods
|
|
182
|
+
- `add_device(device: Device)`: Register a device.
|
|
183
|
+
- `connect_all()`: Establish connections to all devices.
|
|
184
|
+
- `get_stats(host: str) -> DeviceStats`: Fetch performance metrics.
|
|
185
|
+
- `get_clients(host: str) -> List[Station]`: List connected clients.
|
|
186
|
+
- `start_monitor(interval: int)`: Start async background polling.
|
|
187
|
+
- `stop_monitor()`: Stop polling.
|
|
188
|
+
|
|
189
|
+
## Publishing
|
|
190
|
+
To publish a new version to PyPI:
|
|
191
|
+
1. Update version in `isptools/version.py`.
|
|
192
|
+
2. Commit changes and push.
|
|
193
|
+
3. Create a git tag:
|
|
194
|
+
```bash
|
|
195
|
+
git tag -a v3.0.0 -m "Release version 3.0.0"
|
|
196
|
+
git push origin v3.0.0
|
|
197
|
+
```
|
|
198
|
+
GitHub Actions will automatically build and publish to PyPI.
|
|
199
|
+
|
|
200
|
+
---
|
|
201
|
+
|
|
202
|
+
## 👨💻 Developer
|
|
203
|
+
|
|
204
|
+
**isptools** was developed by **Yassin Taha**
|
|
205
|
+
|
|
206
|
+
[
|
|
207
|
+
|
|
208
|
+

|
|
209
|
+
|
|
210
|
+
](https://instagram.com/y_as.01)
|
|
211
|
+
[
|
|
212
|
+
|
|
213
|
+

|
|
214
|
+
|
|
215
|
+
](https://github.com/alexiq01)
|
|
216
|
+
|
|
217
|
+
> Built with ❤️ for ISP engineers and network technicians.
|
|
218
|
+
|
|
219
|
+
## License
|
|
220
|
+
MIT
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from .permissions import PermissionManager, PermissionLevel
|
|
3
|
+
from .rules import AUTOFIX_RULES
|
|
4
|
+
|
|
5
|
+
logger = logging.getLogger(__name__)
|
|
6
|
+
|
|
7
|
+
class AutoFixEngine:
|
|
8
|
+
"""Engine for automatically detecting and fixing network issues."""
|
|
9
|
+
|
|
10
|
+
def __init__(self, permission_manager: PermissionManager):
|
|
11
|
+
self.permission_manager = permission_manager
|
|
12
|
+
self.history = []
|
|
13
|
+
|
|
14
|
+
def analyze(self, device_host: str, stats: dict) -> list[dict]:
|
|
15
|
+
"""Analyze stats against rules and return potential fixes."""
|
|
16
|
+
detected_problems = []
|
|
17
|
+
for rule in AUTOFIX_RULES:
|
|
18
|
+
if rule["trigger"](stats):
|
|
19
|
+
detected_problems.append({
|
|
20
|
+
"name": rule["name"],
|
|
21
|
+
"description": rule["description"],
|
|
22
|
+
"fixes": rule["fixes"]
|
|
23
|
+
})
|
|
24
|
+
return detected_problems
|
|
25
|
+
|
|
26
|
+
def apply_fixes(self, driver, stats: dict) -> list[dict]:
|
|
27
|
+
"""Analyze and apply allowed fixes."""
|
|
28
|
+
device_host = driver.device.host
|
|
29
|
+
device_type = driver.device.device_type
|
|
30
|
+
problems = self.analyze(device_host, stats)
|
|
31
|
+
results = []
|
|
32
|
+
|
|
33
|
+
for problem in problems:
|
|
34
|
+
for fix in problem["fixes"]:
|
|
35
|
+
# Check if fix applies to this device type
|
|
36
|
+
if fix["devices"] != ["all"] and device_type not in fix["devices"]:
|
|
37
|
+
continue
|
|
38
|
+
|
|
39
|
+
action = fix["action"]
|
|
40
|
+
required_level = fix["permission"]
|
|
41
|
+
|
|
42
|
+
# Request permission
|
|
43
|
+
if self.permission_manager.request_permission(action, device_host, required_level, problem["description"]):
|
|
44
|
+
status = self._execute_fix(driver, action)
|
|
45
|
+
else:
|
|
46
|
+
status = 'denied' if self.permission_manager.level < required_level else 'skipped'
|
|
47
|
+
|
|
48
|
+
result = {
|
|
49
|
+
"problem": problem["name"],
|
|
50
|
+
"action": action,
|
|
51
|
+
"status": status
|
|
52
|
+
}
|
|
53
|
+
self.history.append(result)
|
|
54
|
+
results.append(result)
|
|
55
|
+
|
|
56
|
+
if status == 'applied':
|
|
57
|
+
logger.info(f"AutoFix: Applied {action} to {device_host} for {problem['name']}")
|
|
58
|
+
else:
|
|
59
|
+
logger.debug(f"AutoFix: {action} on {device_host} status: {status}")
|
|
60
|
+
|
|
61
|
+
return results
|
|
62
|
+
|
|
63
|
+
def _execute_fix(self, driver, action: str) -> str:
|
|
64
|
+
"""Execute the actual fix on the driver."""
|
|
65
|
+
try:
|
|
66
|
+
if action == "reboot_device":
|
|
67
|
+
driver.reboot()
|
|
68
|
+
return 'applied'
|
|
69
|
+
elif action == "send_alert":
|
|
70
|
+
# Alerting is handled externally usually, but we mark as applied
|
|
71
|
+
return 'applied'
|
|
72
|
+
|
|
73
|
+
# Call driver-specific methods
|
|
74
|
+
method = getattr(driver, action, None)
|
|
75
|
+
if method:
|
|
76
|
+
if method():
|
|
77
|
+
return 'applied'
|
|
78
|
+
else:
|
|
79
|
+
return 'failed'
|
|
80
|
+
else:
|
|
81
|
+
logger.warning(f"Driver {driver.__class__.__name__} does not implement {action}")
|
|
82
|
+
return 'failed'
|
|
83
|
+
except Exception as e:
|
|
84
|
+
logger.error(f"Error executing fix {action} on {driver.device.host}: {e}")
|
|
85
|
+
return 'failed'
|
|
86
|
+
|
|
87
|
+
def get_fix_log(self, device_host: str = None) -> list[dict]:
|
|
88
|
+
"""Return history of all applied fixes."""
|
|
89
|
+
if device_host:
|
|
90
|
+
return [h for h in self.history if h.get('host') == device_host]
|
|
91
|
+
return self.history
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
from enum import IntEnum
|
|
2
|
+
|
|
3
|
+
class PermissionLevel(IntEnum):
|
|
4
|
+
READ_ONLY = 0 # فقط قراءة، بدون أي تعديل
|
|
5
|
+
SAFE_FIX = 1 # إصلاح آمن (restart interface, clear arp)
|
|
6
|
+
MODERATE_FIX = 2 # إصلاح متوسط (change tx power, channel)
|
|
7
|
+
FULL_AUTO = 3 # صلاحية كاملة (reboot, change config)
|
|
8
|
+
|
|
9
|
+
class PermissionManager:
|
|
10
|
+
def __init__(self, level: PermissionLevel = PermissionLevel.READ_ONLY, require_confirm: bool = True):
|
|
11
|
+
self.level = level
|
|
12
|
+
self.require_confirm = require_confirm
|
|
13
|
+
self.confirm_callback = None
|
|
14
|
+
|
|
15
|
+
def set_confirm_callback(self, callback: callable):
|
|
16
|
+
"""Set a callback function for confirmation.
|
|
17
|
+
Callback receives: (action, device_host, details) -> returns bool
|
|
18
|
+
"""
|
|
19
|
+
self.confirm_callback = callback
|
|
20
|
+
|
|
21
|
+
def request_permission(self, action: str, device_host: str, required_level: PermissionLevel, details: str = "") -> bool:
|
|
22
|
+
"""Check if action is allowed based on current permission level and confirmation."""
|
|
23
|
+
if self.level < required_level:
|
|
24
|
+
return False
|
|
25
|
+
|
|
26
|
+
if self.require_confirm:
|
|
27
|
+
if self.confirm_callback:
|
|
28
|
+
return self.confirm_callback(action, device_host, details)
|
|
29
|
+
return False # No callback set but confirmation required
|
|
30
|
+
|
|
31
|
+
return True
|