tty-egpf-monitor 0.5.26__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.
- tty_egpf_monitor-0.5.26/MANIFEST.in +11 -0
- tty_egpf_monitor-0.5.26/PKG-INFO +237 -0
- tty_egpf_monitor-0.5.26/README.md +191 -0
- tty_egpf_monitor-0.5.26/examples/README.md +137 -0
- tty_egpf_monitor-0.5.26/examples/automation_script.py +167 -0
- tty_egpf_monitor-0.5.26/examples/basic_usage.py +94 -0
- tty_egpf_monitor-0.5.26/examples/monitor_serial_data.py +137 -0
- tty_egpf_monitor-0.5.26/pyproject.toml +86 -0
- tty_egpf_monitor-0.5.26/setup.cfg +4 -0
- tty_egpf_monitor-0.5.26/setup.py +84 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor/__init__.py +20 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor/cli.py +172 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor/client.py +324 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor/models.py +141 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor/py.typed +2 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor.egg-info/PKG-INFO +237 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor.egg-info/SOURCES.txt +20 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor.egg-info/dependency_links.txt +1 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor.egg-info/entry_points.txt +2 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor.egg-info/not-zip-safe +1 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor.egg-info/requires.txt +9 -0
- tty_egpf_monitor-0.5.26/tty_egpf_monitor.egg-info/top_level.txt +1 -0
@@ -0,0 +1,237 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: tty-egpf-monitor
|
3
|
+
Version: 0.5.26
|
4
|
+
Summary: Python client library for TTY eBPF Monitor daemon
|
5
|
+
Home-page: https://github.com/seelso-net/tty-egpf-monitor
|
6
|
+
Author: TTY eBPF Monitor Team
|
7
|
+
Author-email: TTY eBPF Monitor Team <contact@seelso.net>
|
8
|
+
Maintainer-email: TTY eBPF Monitor Team <contact@seelso.net>
|
9
|
+
License: GPL-3.0
|
10
|
+
Project-URL: Homepage, https://github.com/seelso-net/tty-egpf-monitor
|
11
|
+
Project-URL: Documentation, https://github.com/seelso-net/tty-egpf-monitor/blob/main/README.md
|
12
|
+
Project-URL: Repository, https://github.com/seelso-net/tty-egpf-monitor
|
13
|
+
Project-URL: Bug Tracker, https://github.com/seelso-net/tty-egpf-monitor/issues
|
14
|
+
Project-URL: APT Repository, https://seelso-net.github.io/tty-egpf-monitor
|
15
|
+
Keywords: serial,tty,monitoring,ebpf,uart,debugging,reverse-engineering,protocol-analysis,hardware
|
16
|
+
Classifier: Development Status :: 4 - Beta
|
17
|
+
Classifier: Environment :: Console
|
18
|
+
Classifier: Intended Audience :: Developers
|
19
|
+
Classifier: Intended Audience :: System Administrators
|
20
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
21
|
+
Classifier: Operating System :: POSIX :: Linux
|
22
|
+
Classifier: Programming Language :: Python :: 3
|
23
|
+
Classifier: Programming Language :: Python :: 3.8
|
24
|
+
Classifier: Programming Language :: Python :: 3.9
|
25
|
+
Classifier: Programming Language :: Python :: 3.10
|
26
|
+
Classifier: Programming Language :: Python :: 3.11
|
27
|
+
Classifier: Programming Language :: Python :: 3.12
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
29
|
+
Classifier: Topic :: System :: Hardware :: Hardware Drivers
|
30
|
+
Classifier: Topic :: System :: Monitoring
|
31
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
32
|
+
Classifier: Topic :: Terminals :: Serial
|
33
|
+
Requires-Python: >=3.8
|
34
|
+
Description-Content-Type: text/markdown
|
35
|
+
Provides-Extra: dev
|
36
|
+
Requires-Dist: pytest>=6.0; extra == "dev"
|
37
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
38
|
+
Requires-Dist: black; extra == "dev"
|
39
|
+
Requires-Dist: flake8; extra == "dev"
|
40
|
+
Requires-Dist: mypy; extra == "dev"
|
41
|
+
Requires-Dist: build; extra == "dev"
|
42
|
+
Requires-Dist: twine; extra == "dev"
|
43
|
+
Dynamic: author
|
44
|
+
Dynamic: home-page
|
45
|
+
Dynamic: requires-python
|
46
|
+
|
47
|
+
# TTY eBPF Monitor Python Client
|
48
|
+
|
49
|
+
[](https://badge.fury.io/py/tty-egpf-monitor)
|
50
|
+
[](https://pypi.org/project/tty-egpf-monitor/)
|
51
|
+
[](https://www.gnu.org/licenses/gpl-3.0)
|
52
|
+
|
53
|
+
A Python client library for [TTY eBPF Monitor](https://github.com/seelso-net/tty-egpf-monitor), providing a clean, Pythonic interface to monitor serial port activity using eBPF technology.
|
54
|
+
|
55
|
+
## Features
|
56
|
+
|
57
|
+
- 🐍 **Pure Python** - No C dependencies, works with any Python 3.8+
|
58
|
+
- 🔌 **Unix Socket API** - Communicates with daemon via Unix domain socket
|
59
|
+
- 📊 **Parsed Log Entries** - Automatic parsing of log format with timestamps
|
60
|
+
- 🔄 **Live Streaming** - Real-time event streaming with iterator interface
|
61
|
+
- 🛠️ **CLI Wrapper** - Drop-in replacement for the C CLI tool
|
62
|
+
- 📚 **Rich Examples** - Comprehensive examples for common use cases
|
63
|
+
- 🔍 **Data Analysis** - Built-in support for protocol analysis and debugging
|
64
|
+
|
65
|
+
## Installation
|
66
|
+
|
67
|
+
### Install from PyPI
|
68
|
+
|
69
|
+
```bash
|
70
|
+
pip install tty-egpf-monitor
|
71
|
+
```
|
72
|
+
|
73
|
+
### Install the Daemon
|
74
|
+
|
75
|
+
The Python client requires the `tty-egpf-monitord` daemon to be running:
|
76
|
+
|
77
|
+
```bash
|
78
|
+
# Install daemon via APT repository
|
79
|
+
curl -fsSL https://raw.githubusercontent.com/seelso-net/tty-egpf-monitor/main/install.sh | bash
|
80
|
+
|
81
|
+
# Or install manually
|
82
|
+
CODENAME=$(lsb_release -cs)
|
83
|
+
REPO_URL=https://seelso-net.github.io/tty-egpf-monitor
|
84
|
+
curl -fsSL ${REPO_URL}/public-apt-key.asc | sudo gpg --dearmor -o /usr/share/keyrings/tty-egpf-monitor.gpg
|
85
|
+
echo "deb [signed-by=/usr/share/keyrings/tty-egpf-monitor.gpg] ${REPO_URL} ${CODENAME} main" | sudo tee /etc/apt/sources.list.d/tty-egpf-monitor.list
|
86
|
+
sudo apt-get update && sudo apt-get install -y tty-egpf-monitord
|
87
|
+
sudo systemctl enable --now tty-egpf-monitord
|
88
|
+
```
|
89
|
+
|
90
|
+
## Quick Start
|
91
|
+
|
92
|
+
### Library Usage
|
93
|
+
|
94
|
+
```python
|
95
|
+
from tty_egpf_monitor import TTYMonitorClient
|
96
|
+
|
97
|
+
# Create client
|
98
|
+
client = TTYMonitorClient()
|
99
|
+
|
100
|
+
# Add a port to monitor
|
101
|
+
idx = client.add_port("/dev/ttyUSB0", baudrate=115200)
|
102
|
+
print(f"Monitoring port {idx}")
|
103
|
+
|
104
|
+
# List all ports
|
105
|
+
ports = client.list_ports()
|
106
|
+
for port in ports:
|
107
|
+
print(f"Port {port.idx}: {port.device}")
|
108
|
+
|
109
|
+
# Stream live events
|
110
|
+
for entry in client.stream_parsed_logs("/dev/ttyUSB0"):
|
111
|
+
print(f"[{entry.timestamp}] {entry.event_type}: {entry.process}")
|
112
|
+
if entry.data:
|
113
|
+
print(f" Data: {entry.data}")
|
114
|
+
|
115
|
+
# Remove port when done
|
116
|
+
client.remove_port("/dev/ttyUSB0")
|
117
|
+
```
|
118
|
+
|
119
|
+
### CLI Usage
|
120
|
+
|
121
|
+
The package includes a CLI tool compatible with the C version:
|
122
|
+
|
123
|
+
```bash
|
124
|
+
# Add a port
|
125
|
+
tty-egpf-monitor-py add /dev/ttyUSB0 115200
|
126
|
+
|
127
|
+
# List ports
|
128
|
+
tty-egpf-monitor-py list
|
129
|
+
|
130
|
+
# Stream logs (by index or device path)
|
131
|
+
tty-egpf-monitor-py stream 0
|
132
|
+
tty-egpf-monitor-py stream /dev/ttyUSB0
|
133
|
+
|
134
|
+
# Download logs
|
135
|
+
tty-egpf-monitor-py logs /dev/ttyUSB0 > captured.jsonl
|
136
|
+
|
137
|
+
# Remove port
|
138
|
+
tty-egpf-monitor-py remove /dev/ttyUSB0
|
139
|
+
```
|
140
|
+
|
141
|
+
## API Reference
|
142
|
+
|
143
|
+
### TTYMonitorClient
|
144
|
+
|
145
|
+
#### Methods
|
146
|
+
|
147
|
+
- **`list_ports()`** → `List[Port]`
|
148
|
+
|
149
|
+
List all configured ports.
|
150
|
+
|
151
|
+
- **`add_port(device, baudrate=115200, log_path=None)`** → `int`
|
152
|
+
|
153
|
+
Add a port to monitor. Returns the port index.
|
154
|
+
|
155
|
+
- **`remove_port(port_identifier)`** → `bool`
|
156
|
+
|
157
|
+
Remove a port by index (int) or device path (str).
|
158
|
+
|
159
|
+
- **`get_logs(port_identifier)`** → `str`
|
160
|
+
|
161
|
+
Download full log content for a port.
|
162
|
+
|
163
|
+
- **`stream_logs(port_identifier)`** → `Iterator[str]`
|
164
|
+
|
165
|
+
Stream raw log lines as they arrive.
|
166
|
+
|
167
|
+
- **`stream_parsed_logs(port_identifier)`** → `Iterator[LogEntry]`
|
168
|
+
|
169
|
+
Stream parsed log entries as they arrive.
|
170
|
+
|
171
|
+
- **`wait_for_event(port_identifier, event_type, timeout=30.0)`** → `Optional[LogEntry]`
|
172
|
+
|
173
|
+
Wait for a specific event type with timeout.
|
174
|
+
|
175
|
+
### LogEntry
|
176
|
+
|
177
|
+
Represents a parsed log entry:
|
178
|
+
|
179
|
+
```python
|
180
|
+
@dataclass
|
181
|
+
class LogEntry:
|
182
|
+
timestamp: datetime # When the event occurred
|
183
|
+
event_type: str # OPEN, CLOSE, READ, WRITE, IOCTL, MODE_CHANGE
|
184
|
+
process: str # Process name that triggered the event
|
185
|
+
direction: Optional[str] # APP->DEV or DEV->APP (for READ/write)
|
186
|
+
data: Optional[bytes] # Raw data (for read/write events)
|
187
|
+
raw_line: str # Original log line
|
188
|
+
```
|
189
|
+
|
190
|
+
### Port
|
191
|
+
|
192
|
+
Represents a monitored port:
|
193
|
+
|
194
|
+
```python
|
195
|
+
@dataclass
|
196
|
+
class Port:
|
197
|
+
idx: int # Port index
|
198
|
+
device: str # Device path
|
199
|
+
baudrate: Optional[int] # Configured baud rate
|
200
|
+
log_path: Optional[str] # Log file path
|
201
|
+
```
|
202
|
+
|
203
|
+
## Examples
|
204
|
+
|
205
|
+
See the [`examples/`](examples/) directory for comprehensive usage examples:
|
206
|
+
|
207
|
+
- **`basic_usage.py`** - Core functionality demonstration
|
208
|
+
- **`monitor_serial_data.py`** - Real-time monitoring with processing
|
209
|
+
- **`automation_script.py`** - Automated testing and analysis
|
210
|
+
|
211
|
+
## Error Handling
|
212
|
+
|
213
|
+
```python
|
214
|
+
from tty_egpf_monitor import TTYMonitorError
|
215
|
+
|
216
|
+
try:
|
217
|
+
client = TTYMonitorClient()
|
218
|
+
client.add_port("/dev/ttyUSB0")
|
219
|
+
except TTYMonitorError as e:
|
220
|
+
print(f"Error: {e}")
|
221
|
+
```
|
222
|
+
|
223
|
+
## Requirements
|
224
|
+
|
225
|
+
- **Python**: 3.8 or later
|
226
|
+
- **Operating System**: Linux (Ubuntu 22.04+ recommended)
|
227
|
+
- **Daemon**: `tty-egpf-monitord` must be installed and running
|
228
|
+
- **Permissions**: Access to the daemon's Unix socket (usually `/run/tty-egpf-monitord.sock`)
|
229
|
+
|
230
|
+
## Related Projects
|
231
|
+
|
232
|
+
- **[TTY eBPF Monitor](https://github.com/seelso-net/tty-egpf-monitor)** - Main project with C daemon and CLI
|
233
|
+
- **[APT Repository](https://seelso-net.github.io/tty-egpf-monitor)** - Binary packages for Ubuntu
|
234
|
+
|
235
|
+
## License
|
236
|
+
|
237
|
+
This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](https://github.com/seelso-net/tty-egpf-monitor/blob/main/LICENSE) file for details.
|
@@ -0,0 +1,191 @@
|
|
1
|
+
# TTY eBPF Monitor Python Client
|
2
|
+
|
3
|
+
[](https://badge.fury.io/py/tty-egpf-monitor)
|
4
|
+
[](https://pypi.org/project/tty-egpf-monitor/)
|
5
|
+
[](https://www.gnu.org/licenses/gpl-3.0)
|
6
|
+
|
7
|
+
A Python client library for [TTY eBPF Monitor](https://github.com/seelso-net/tty-egpf-monitor), providing a clean, Pythonic interface to monitor serial port activity using eBPF technology.
|
8
|
+
|
9
|
+
## Features
|
10
|
+
|
11
|
+
- 🐍 **Pure Python** - No C dependencies, works with any Python 3.8+
|
12
|
+
- 🔌 **Unix Socket API** - Communicates with daemon via Unix domain socket
|
13
|
+
- 📊 **Parsed Log Entries** - Automatic parsing of log format with timestamps
|
14
|
+
- 🔄 **Live Streaming** - Real-time event streaming with iterator interface
|
15
|
+
- 🛠️ **CLI Wrapper** - Drop-in replacement for the C CLI tool
|
16
|
+
- 📚 **Rich Examples** - Comprehensive examples for common use cases
|
17
|
+
- 🔍 **Data Analysis** - Built-in support for protocol analysis and debugging
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
### Install from PyPI
|
22
|
+
|
23
|
+
```bash
|
24
|
+
pip install tty-egpf-monitor
|
25
|
+
```
|
26
|
+
|
27
|
+
### Install the Daemon
|
28
|
+
|
29
|
+
The Python client requires the `tty-egpf-monitord` daemon to be running:
|
30
|
+
|
31
|
+
```bash
|
32
|
+
# Install daemon via APT repository
|
33
|
+
curl -fsSL https://raw.githubusercontent.com/seelso-net/tty-egpf-monitor/main/install.sh | bash
|
34
|
+
|
35
|
+
# Or install manually
|
36
|
+
CODENAME=$(lsb_release -cs)
|
37
|
+
REPO_URL=https://seelso-net.github.io/tty-egpf-monitor
|
38
|
+
curl -fsSL ${REPO_URL}/public-apt-key.asc | sudo gpg --dearmor -o /usr/share/keyrings/tty-egpf-monitor.gpg
|
39
|
+
echo "deb [signed-by=/usr/share/keyrings/tty-egpf-monitor.gpg] ${REPO_URL} ${CODENAME} main" | sudo tee /etc/apt/sources.list.d/tty-egpf-monitor.list
|
40
|
+
sudo apt-get update && sudo apt-get install -y tty-egpf-monitord
|
41
|
+
sudo systemctl enable --now tty-egpf-monitord
|
42
|
+
```
|
43
|
+
|
44
|
+
## Quick Start
|
45
|
+
|
46
|
+
### Library Usage
|
47
|
+
|
48
|
+
```python
|
49
|
+
from tty_egpf_monitor import TTYMonitorClient
|
50
|
+
|
51
|
+
# Create client
|
52
|
+
client = TTYMonitorClient()
|
53
|
+
|
54
|
+
# Add a port to monitor
|
55
|
+
idx = client.add_port("/dev/ttyUSB0", baudrate=115200)
|
56
|
+
print(f"Monitoring port {idx}")
|
57
|
+
|
58
|
+
# List all ports
|
59
|
+
ports = client.list_ports()
|
60
|
+
for port in ports:
|
61
|
+
print(f"Port {port.idx}: {port.device}")
|
62
|
+
|
63
|
+
# Stream live events
|
64
|
+
for entry in client.stream_parsed_logs("/dev/ttyUSB0"):
|
65
|
+
print(f"[{entry.timestamp}] {entry.event_type}: {entry.process}")
|
66
|
+
if entry.data:
|
67
|
+
print(f" Data: {entry.data}")
|
68
|
+
|
69
|
+
# Remove port when done
|
70
|
+
client.remove_port("/dev/ttyUSB0")
|
71
|
+
```
|
72
|
+
|
73
|
+
### CLI Usage
|
74
|
+
|
75
|
+
The package includes a CLI tool compatible with the C version:
|
76
|
+
|
77
|
+
```bash
|
78
|
+
# Add a port
|
79
|
+
tty-egpf-monitor-py add /dev/ttyUSB0 115200
|
80
|
+
|
81
|
+
# List ports
|
82
|
+
tty-egpf-monitor-py list
|
83
|
+
|
84
|
+
# Stream logs (by index or device path)
|
85
|
+
tty-egpf-monitor-py stream 0
|
86
|
+
tty-egpf-monitor-py stream /dev/ttyUSB0
|
87
|
+
|
88
|
+
# Download logs
|
89
|
+
tty-egpf-monitor-py logs /dev/ttyUSB0 > captured.jsonl
|
90
|
+
|
91
|
+
# Remove port
|
92
|
+
tty-egpf-monitor-py remove /dev/ttyUSB0
|
93
|
+
```
|
94
|
+
|
95
|
+
## API Reference
|
96
|
+
|
97
|
+
### TTYMonitorClient
|
98
|
+
|
99
|
+
#### Methods
|
100
|
+
|
101
|
+
- **`list_ports()`** → `List[Port]`
|
102
|
+
|
103
|
+
List all configured ports.
|
104
|
+
|
105
|
+
- **`add_port(device, baudrate=115200, log_path=None)`** → `int`
|
106
|
+
|
107
|
+
Add a port to monitor. Returns the port index.
|
108
|
+
|
109
|
+
- **`remove_port(port_identifier)`** → `bool`
|
110
|
+
|
111
|
+
Remove a port by index (int) or device path (str).
|
112
|
+
|
113
|
+
- **`get_logs(port_identifier)`** → `str`
|
114
|
+
|
115
|
+
Download full log content for a port.
|
116
|
+
|
117
|
+
- **`stream_logs(port_identifier)`** → `Iterator[str]`
|
118
|
+
|
119
|
+
Stream raw log lines as they arrive.
|
120
|
+
|
121
|
+
- **`stream_parsed_logs(port_identifier)`** → `Iterator[LogEntry]`
|
122
|
+
|
123
|
+
Stream parsed log entries as they arrive.
|
124
|
+
|
125
|
+
- **`wait_for_event(port_identifier, event_type, timeout=30.0)`** → `Optional[LogEntry]`
|
126
|
+
|
127
|
+
Wait for a specific event type with timeout.
|
128
|
+
|
129
|
+
### LogEntry
|
130
|
+
|
131
|
+
Represents a parsed log entry:
|
132
|
+
|
133
|
+
```python
|
134
|
+
@dataclass
|
135
|
+
class LogEntry:
|
136
|
+
timestamp: datetime # When the event occurred
|
137
|
+
event_type: str # OPEN, CLOSE, READ, WRITE, IOCTL, MODE_CHANGE
|
138
|
+
process: str # Process name that triggered the event
|
139
|
+
direction: Optional[str] # APP->DEV or DEV->APP (for READ/write)
|
140
|
+
data: Optional[bytes] # Raw data (for read/write events)
|
141
|
+
raw_line: str # Original log line
|
142
|
+
```
|
143
|
+
|
144
|
+
### Port
|
145
|
+
|
146
|
+
Represents a monitored port:
|
147
|
+
|
148
|
+
```python
|
149
|
+
@dataclass
|
150
|
+
class Port:
|
151
|
+
idx: int # Port index
|
152
|
+
device: str # Device path
|
153
|
+
baudrate: Optional[int] # Configured baud rate
|
154
|
+
log_path: Optional[str] # Log file path
|
155
|
+
```
|
156
|
+
|
157
|
+
## Examples
|
158
|
+
|
159
|
+
See the [`examples/`](examples/) directory for comprehensive usage examples:
|
160
|
+
|
161
|
+
- **`basic_usage.py`** - Core functionality demonstration
|
162
|
+
- **`monitor_serial_data.py`** - Real-time monitoring with processing
|
163
|
+
- **`automation_script.py`** - Automated testing and analysis
|
164
|
+
|
165
|
+
## Error Handling
|
166
|
+
|
167
|
+
```python
|
168
|
+
from tty_egpf_monitor import TTYMonitorError
|
169
|
+
|
170
|
+
try:
|
171
|
+
client = TTYMonitorClient()
|
172
|
+
client.add_port("/dev/ttyUSB0")
|
173
|
+
except TTYMonitorError as e:
|
174
|
+
print(f"Error: {e}")
|
175
|
+
```
|
176
|
+
|
177
|
+
## Requirements
|
178
|
+
|
179
|
+
- **Python**: 3.8 or later
|
180
|
+
- **Operating System**: Linux (Ubuntu 22.04+ recommended)
|
181
|
+
- **Daemon**: `tty-egpf-monitord` must be installed and running
|
182
|
+
- **Permissions**: Access to the daemon's Unix socket (usually `/run/tty-egpf-monitord.sock`)
|
183
|
+
|
184
|
+
## Related Projects
|
185
|
+
|
186
|
+
- **[TTY eBPF Monitor](https://github.com/seelso-net/tty-egpf-monitor)** - Main project with C daemon and CLI
|
187
|
+
- **[APT Repository](https://seelso-net.github.io/tty-egpf-monitor)** - Binary packages for Ubuntu
|
188
|
+
|
189
|
+
## License
|
190
|
+
|
191
|
+
This project is licensed under the GNU General Public License v3.0 - see the [LICENSE](https://github.com/seelso-net/tty-egpf-monitor/blob/main/LICENSE) file for details.
|
@@ -0,0 +1,137 @@
|
|
1
|
+
# TTY eBPF Monitor Python Examples
|
2
|
+
|
3
|
+
This directory contains example scripts demonstrating how to use the TTY eBPF Monitor Python client library.
|
4
|
+
|
5
|
+
## Prerequisites
|
6
|
+
|
7
|
+
1. **Install the daemon** (if not already installed):
|
8
|
+
```bash
|
9
|
+
curl -fsSL https://raw.githubusercontent.com/seelso-net/tty-egpf-monitor/main/install.sh | bash
|
10
|
+
```
|
11
|
+
|
12
|
+
2. **Install the Python client**:
|
13
|
+
```bash
|
14
|
+
pip install tty-egpf-monitor
|
15
|
+
```
|
16
|
+
|
17
|
+
3. **Ensure the daemon is running**:
|
18
|
+
```bash
|
19
|
+
sudo systemctl status tty-egpf-monitord
|
20
|
+
```
|
21
|
+
|
22
|
+
## Examples
|
23
|
+
|
24
|
+
### 1. Basic Usage (`basic_usage.py`)
|
25
|
+
|
26
|
+
Demonstrates core functionality of the Python client library:
|
27
|
+
- Adding and removing ports
|
28
|
+
- Listing configured ports
|
29
|
+
- Getting historical logs
|
30
|
+
- Streaming live events
|
31
|
+
|
32
|
+
```bash
|
33
|
+
python basic_usage.py
|
34
|
+
```
|
35
|
+
|
36
|
+
### 2. Serial Data Monitoring (`monitor_serial_data.py`)
|
37
|
+
|
38
|
+
Advanced example showing real-time monitoring with event processing:
|
39
|
+
- Event filtering and categorization
|
40
|
+
- Data pattern detection
|
41
|
+
- Formatted output with emojis
|
42
|
+
- Graceful shutdown handling
|
43
|
+
|
44
|
+
```bash
|
45
|
+
python monitor_serial_data.py /dev/ttyUSB0
|
46
|
+
python monitor_serial_data.py /dev/ttyUSB0 --baudrate 9600
|
47
|
+
```
|
48
|
+
|
49
|
+
### 3. Automation Script (`automation_script.py`)
|
50
|
+
|
51
|
+
Example for automated testing and monitoring:
|
52
|
+
- Waiting for device activity
|
53
|
+
- Capturing session data
|
54
|
+
- Protocol analysis
|
55
|
+
- Summary reporting
|
56
|
+
|
57
|
+
```bash
|
58
|
+
python automation_script.py /dev/ttyUSB0 30
|
59
|
+
```
|
60
|
+
|
61
|
+
## Library Usage
|
62
|
+
|
63
|
+
### Quick Start
|
64
|
+
|
65
|
+
```python
|
66
|
+
from tty_egpf_monitor import TTYMonitorClient
|
67
|
+
|
68
|
+
# Create client
|
69
|
+
client = TTYMonitorClient()
|
70
|
+
|
71
|
+
# Add a port
|
72
|
+
idx = client.add_port("/dev/ttyUSB0", baudrate=115200)
|
73
|
+
|
74
|
+
# List ports
|
75
|
+
ports = client.list_ports()
|
76
|
+
for port in ports:
|
77
|
+
print(f"Port {port.idx}: {port.device}")
|
78
|
+
|
79
|
+
# Stream live events
|
80
|
+
for entry in client.stream_parsed_logs("/dev/ttyUSB0"):
|
81
|
+
print(f"{entry.timestamp}: {entry.event_type} by {entry.process}")
|
82
|
+
if entry.data:
|
83
|
+
print(f" Data: {entry.data}")
|
84
|
+
|
85
|
+
# Remove port
|
86
|
+
client.remove_port("/dev/ttyUSB0")
|
87
|
+
```
|
88
|
+
|
89
|
+
### API Reference
|
90
|
+
|
91
|
+
#### TTYMonitorClient
|
92
|
+
|
93
|
+
- `list_ports()` → `List[Port]`
|
94
|
+
- `add_port(device, baudrate=115200, log_path=None)` → `int`
|
95
|
+
- `remove_port(port_identifier)` → `bool`
|
96
|
+
- `get_logs(port_identifier)` → `str`
|
97
|
+
- `stream_logs(port_identifier)` → `Iterator[str]`
|
98
|
+
- `stream_parsed_logs(port_identifier)` → `Iterator[LogEntry]`
|
99
|
+
- `wait_for_event(port_identifier, event_type, timeout=30.0)` → `Optional[LogEntry]`
|
100
|
+
|
101
|
+
#### LogEntry
|
102
|
+
|
103
|
+
- `timestamp: datetime`
|
104
|
+
- `event_type: str` (OPEN, CLOSE, READ, WRITE, IOCTL, MODE_CHANGE)
|
105
|
+
- `process: str`
|
106
|
+
- `direction: Optional[str]` (APP->DEV, DEV->APP)
|
107
|
+
- `data: Optional[bytes]`
|
108
|
+
- `raw_line: str`
|
109
|
+
|
110
|
+
## Error Handling
|
111
|
+
|
112
|
+
All API methods may raise `TTYMonitorError` for:
|
113
|
+
- Connection failures
|
114
|
+
- HTTP errors
|
115
|
+
- Invalid responses
|
116
|
+
- Device not found
|
117
|
+
|
118
|
+
```python
|
119
|
+
from tty_egpf_monitor import TTYMonitorError
|
120
|
+
|
121
|
+
try:
|
122
|
+
client.add_port("/dev/ttyUSB0")
|
123
|
+
except TTYMonitorError as e:
|
124
|
+
print(f"Failed to add port: {e}")
|
125
|
+
```
|
126
|
+
|
127
|
+
## Tips
|
128
|
+
|
129
|
+
1. **Run with appropriate permissions**: The daemon runs as root, but the Python client can run as any user with access to the socket.
|
130
|
+
|
131
|
+
2. **Handle interrupts gracefully**: Use signal handlers for clean shutdown in long-running scripts.
|
132
|
+
|
133
|
+
3. **Device path vs index**: Most methods accept either a device path (`"/dev/ttyUSB0"`) or port index (`0`).
|
134
|
+
|
135
|
+
4. **Stream processing**: Use `stream_parsed_logs()` for real-time processing, `get_logs()` for historical data.
|
136
|
+
|
137
|
+
5. **Data handling**: Serial data is returned as `bytes` objects, allowing proper handling of binary protocols.
|