inventory-monitor-scripts 1.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.
- inventory_monitor_scripts-1.0.0/.env.sample +33 -0
- inventory_monitor_scripts-1.0.0/LICENSE +21 -0
- inventory_monitor_scripts-1.0.0/MANIFEST.in +3 -0
- inventory_monitor_scripts-1.0.0/PKG-INFO +461 -0
- inventory_monitor_scripts-1.0.0/README.md +433 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/__init__.py +4 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/helper.py +27 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/invmon.py +174 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/logger.py +59 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/main.py +353 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/models.py +172 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/netbox.py +238 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/snmp/__init__.py +67 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/snmp/base.py +208 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/snmp/cisco.py +187 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/snmp/constants.py +74 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/snmp/errors.py +15 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/snmp/junos.py +100 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor/snmp/sros.py +124 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor_scripts.egg-info/PKG-INFO +461 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor_scripts.egg-info/SOURCES.txt +33 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor_scripts.egg-info/dependency_links.txt +1 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor_scripts.egg-info/not-zip-safe +1 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor_scripts.egg-info/requires.txt +9 -0
- inventory_monitor_scripts-1.0.0/inventory_monitor_scripts.egg-info/top_level.txt +2 -0
- inventory_monitor_scripts-1.0.0/setup.cfg +4 -0
- inventory_monitor_scripts-1.0.0/setup.py +65 -0
- inventory_monitor_scripts-1.0.0/tests/__init__.py +0 -0
- inventory_monitor_scripts-1.0.0/tests/conftest.py +28 -0
- inventory_monitor_scripts-1.0.0/tests/test_helper.py +16 -0
- inventory_monitor_scripts-1.0.0/tests/test_invmon.py +78 -0
- inventory_monitor_scripts-1.0.0/tests/test_main.py +580 -0
- inventory_monitor_scripts-1.0.0/tests/test_models.py +162 -0
- inventory_monitor_scripts-1.0.0/tests/test_netbox.py +122 -0
- inventory_monitor_scripts-1.0.0/tests/test_snmp.py +225 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
NETBOX_API_TOKEN=
|
|
2
|
+
NETBOX_INSTANCE_URL=
|
|
3
|
+
|
|
4
|
+
# Define as a string of versions separated by ','
|
|
5
|
+
SNMP_VERSION = '3,2'
|
|
6
|
+
SNMP_USER =
|
|
7
|
+
SNMP_AUTH =
|
|
8
|
+
SNMP_AUTH_METHOD = "SHA"
|
|
9
|
+
SNMP_PRIVACY =
|
|
10
|
+
SNMP_PRIVACY_METHOD = "AES"
|
|
11
|
+
SNMP_SECURITY = "authPriv"
|
|
12
|
+
SNMP_COMMUNITY =
|
|
13
|
+
|
|
14
|
+
# SNMP connection tuning
|
|
15
|
+
SNMP_TIMEOUT=1 # timeout in seconds (default: 1) - passed to easysnmp Session
|
|
16
|
+
SNMP_RETRIES=1 # total attempts per SNMP version (1 = single attempt, no retry)
|
|
17
|
+
|
|
18
|
+
# when multiple model names, separate by ","
|
|
19
|
+
# Note: both "excludes" (corrected) and "exludes" (legacy) spellings are accepted
|
|
20
|
+
entPhysicalModelName_excludes="ASR-9900-AC-PEM,ASR-9900-DC-PEM,A9K-AC-PEM,A9K-DC-PEM"
|
|
21
|
+
|
|
22
|
+
# when multiple tags, separate by ","
|
|
23
|
+
NETBOX_TAGS="net-cesnet3"
|
|
24
|
+
NETBOX_TAGS__N=""
|
|
25
|
+
|
|
26
|
+
# SSL verification for NetBox API (true/false)
|
|
27
|
+
NETBOX_VERIFY_SSL=true
|
|
28
|
+
|
|
29
|
+
# Logging configuration (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
|
30
|
+
LOG_LEVEL="INFO"
|
|
31
|
+
|
|
32
|
+
# Number of parallel jobs for device processing (default: 50, tuned here for dev/test)
|
|
33
|
+
PARALLEL_JOBS=10
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jan Krupa
|
|
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,461 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: inventory_monitor_scripts
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Scan devices via SNMP and store its inventory to NetBox
|
|
5
|
+
Home-page: https://github.com/Kani999/inventory_monitor_scripts.git
|
|
6
|
+
Author: Jan Krupa
|
|
7
|
+
Project-URL: Bug Tracker, https://github.com/Kani999/inventory_monitor_scripts.git/issues
|
|
8
|
+
Project-URL: Source Code, https://github.com/Kani999/inventory_monitor_scripts.git
|
|
9
|
+
Keywords: netbox snmp inventory network monitoring cisco juniper nokia
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Intended Audience :: System Administrators
|
|
12
|
+
Classifier: Intended Audience :: Telecommunications Industry
|
|
13
|
+
Classifier: Topic :: System :: Monitoring
|
|
14
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Operating System :: OS Independent
|
|
24
|
+
Requires-Python: >=3.7
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
Provides-Extra: test
|
|
27
|
+
License-File: LICENSE
|
|
28
|
+
|
|
29
|
+
# Inventory Monitor Scripts
|
|
30
|
+
|
|
31
|
+
A comprehensive Python package for gathering network device inventory via SNMP and storing it in NetBox using the inventory-monitor-plugin.
|
|
32
|
+
|
|
33
|
+
## Overview
|
|
34
|
+
|
|
35
|
+
This package performs the following key functions:
|
|
36
|
+
|
|
37
|
+
1. Loads inventory data from network devices via SNMP (v2c and v3 supported)
|
|
38
|
+
2. Processes and normalizes inventory data from multiple vendor platforms
|
|
39
|
+
- Cisco (IOS, IOS-XE, IOS-XR)
|
|
40
|
+
- Juniper (JunOS)
|
|
41
|
+
- Nokia (SROS)
|
|
42
|
+
3. Merges inventory items with the same serial numbers based on priority class
|
|
43
|
+
4. Uploads inventory data to NetBox as Probes via the inventory-monitor-plugin
|
|
44
|
+
|
|
45
|
+
## Installation
|
|
46
|
+
|
|
47
|
+
### Prerequisites
|
|
48
|
+
|
|
49
|
+
- Python 3.7+
|
|
50
|
+
- NetBox instance with the inventory-monitor-plugin installed
|
|
51
|
+
- Network access to your devices via SNMP
|
|
52
|
+
- System SNMP libraries (required for easysnmp)
|
|
53
|
+
|
|
54
|
+
### System Dependencies
|
|
55
|
+
|
|
56
|
+
Install the net-snmp development libraries based on your OS:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
# macOS (Homebrew)
|
|
60
|
+
brew install net-snmp
|
|
61
|
+
|
|
62
|
+
# Debian/Ubuntu
|
|
63
|
+
sudo apt-get install libsnmp-dev
|
|
64
|
+
|
|
65
|
+
# RHEL/CentOS
|
|
66
|
+
sudo yum install net-snmp-devel
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
#### ⚠️ Known Issue: macOS ARM64 (Apple Silicon M1/M2/M3)
|
|
70
|
+
|
|
71
|
+
The `easysnmp` dependency has known compilation issues on macOS with Apple Silicon processors. This is a limitation of the `easysnmp` package itself, not this project.
|
|
72
|
+
|
|
73
|
+
**Recommended Workarounds:**
|
|
74
|
+
|
|
75
|
+
1. **Use Docker (Recommended for Production)**
|
|
76
|
+
```bash
|
|
77
|
+
# Use Linux-based container where easysnmp works reliably
|
|
78
|
+
docker run -it --rm -v $(pwd):/app python:3.11-slim bash
|
|
79
|
+
apt-get update && apt-get install -y libsnmp-dev gcc
|
|
80
|
+
cd /app && pip install -e .
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
2. **Use Linux VM or Server** - Deploy on Linux where easysnmp has better support
|
|
84
|
+
|
|
85
|
+
3. **Development on macOS** - If you must develop locally on ARM64 Mac:
|
|
86
|
+
- Install OpenSSL via Homebrew: `brew install openssl@3`
|
|
87
|
+
- Try manual installation with build flags:
|
|
88
|
+
```bash
|
|
89
|
+
export CFLAGS="-I/opt/homebrew/opt/openssl@3/include"
|
|
90
|
+
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
|
|
91
|
+
pip install easysnmp
|
|
92
|
+
```
|
|
93
|
+
- **Note**: This may still fail due to upstream bugs in easysnmp
|
|
94
|
+
|
|
95
|
+
For production deployments, **we strongly recommend using Linux** (Docker, VM, or bare metal) where all dependencies install reliably.
|
|
96
|
+
|
|
97
|
+
See [Troubleshooting](#troubleshooting) section for more details on easysnmp installation issues.
|
|
98
|
+
|
|
99
|
+
### Python Package Installation
|
|
100
|
+
|
|
101
|
+
Clone the repository and install:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
git clone https://github.com/yourusername/inventory_monitor_scripts.git
|
|
105
|
+
cd inventory_monitor_scripts
|
|
106
|
+
pip install -e .
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Verify installation:
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
python -m inventory_monitor.main --help
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Configuration
|
|
116
|
+
|
|
117
|
+
Create a `.env` file in the repository root with required settings. Copy `.env.sample` as a starting point:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
cp .env.sample .env
|
|
121
|
+
# Edit .env with your credentials
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Multiple Environment Configurations
|
|
125
|
+
|
|
126
|
+
You can maintain separate configuration files for different environments (production, staging, development) and specify which one to use with the `--env-file` flag:
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# Create environment-specific files
|
|
130
|
+
cp .env.sample .env.production
|
|
131
|
+
cp .env.sample .env.staging
|
|
132
|
+
|
|
133
|
+
# Use production config
|
|
134
|
+
python -m inventory_monitor.main --env-file .env.production
|
|
135
|
+
|
|
136
|
+
# Use staging config with different device filter
|
|
137
|
+
python -m inventory_monitor.main --env-file .env.staging --netbox-tags staging
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
If `--env-file` is not specified, the default `.env` file is used. This allows you to keep separate SNMP credentials, NetBox instances, and other settings per environment without modifying the default configuration.
|
|
141
|
+
|
|
142
|
+
### Security Best Practices
|
|
143
|
+
|
|
144
|
+
**⚠️ IMPORTANT**: This tool handles sensitive credentials (SNMP community strings, SNMPv3 passwords, NetBox API tokens).
|
|
145
|
+
|
|
146
|
+
**Recommended approach**:
|
|
147
|
+
- ✅ **Use environment variables** (`.env` file or exported variables)
|
|
148
|
+
- ✅ **Use `--env-file` for different environments** (keeps credentials in files, not CLI)
|
|
149
|
+
- ❌ **Avoid CLI arguments** for secrets (visible in `ps aux`, shell history, logs)
|
|
150
|
+
|
|
151
|
+
While CLI arguments like `--snmp-community` and `--netbox-api-token` are supported for convenience, they expose credentials in process listings. Use them only for testing in secure environments.
|
|
152
|
+
|
|
153
|
+
### Required Settings
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
# NetBox API Configuration
|
|
157
|
+
NETBOX_API_TOKEN="your_netbox_api_token"
|
|
158
|
+
NETBOX_INSTANCE_URL="https://your-netbox-instance/"
|
|
159
|
+
|
|
160
|
+
# SNMP Protocol Version (comma-separated, tried in order)
|
|
161
|
+
SNMP_VERSION="3,2" # Try SNMPv3 first, fall back to SNMPv2
|
|
162
|
+
|
|
163
|
+
# SNMPv2 Configuration
|
|
164
|
+
SNMP_COMMUNITY="public" # SNMPv2 community string
|
|
165
|
+
|
|
166
|
+
# SNMPv3 Configuration (only needed if using SNMPv3)
|
|
167
|
+
SNMP_USER="snmp_user"
|
|
168
|
+
SNMP_AUTH="auth_password"
|
|
169
|
+
SNMP_AUTH_METHOD="SHA" # MD5 or SHA
|
|
170
|
+
SNMP_PRIVACY="privacy_password"
|
|
171
|
+
SNMP_PRIVACY_METHOD="AES" # DES or AES
|
|
172
|
+
SNMP_SECURITY="authPriv" # noAuthNoPriv, authNoPriv, or authPriv
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Optional Settings
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
# Device Filtering
|
|
179
|
+
NETBOX_TAGS="tag1,tag2" # Only process devices with these tags
|
|
180
|
+
NETBOX_TAGS__N="tag3,tag4" # Exclude devices with these tags
|
|
181
|
+
entPhysicalModelName_excludes="ASR-9900-AC-PEM,ASR-9900-DC-PEM" # Exclude specific models
|
|
182
|
+
# Note: the legacy spelling "entPhysicalModelName_exludes" is also accepted
|
|
183
|
+
|
|
184
|
+
# SNMP Connection Tuning
|
|
185
|
+
SNMP_TIMEOUT=1 # SNMP timeout in seconds (default: 1)
|
|
186
|
+
SNMP_RETRIES=1 # Number of retries per SNMP version (default: 1)
|
|
187
|
+
|
|
188
|
+
# NetBox SSL
|
|
189
|
+
NETBOX_VERIFY_SSL=true # Set to "false" to skip SSL certificate verification
|
|
190
|
+
|
|
191
|
+
# Performance Tuning
|
|
192
|
+
PARALLEL_JOBS=50 # Number of parallel device processing jobs (default: 50)
|
|
193
|
+
|
|
194
|
+
# Logging
|
|
195
|
+
LOG_LEVEL="INFO" # DEBUG, INFO, WARNING, ERROR, CRITICAL (default: INFO)
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Security Note**: The `.env` file contains sensitive credentials and is automatically ignored by git. The application loads config in priority order: `.env` file → environment variables (CLI and exported vars override `.env` values).
|
|
199
|
+
|
|
200
|
+
## Usage
|
|
201
|
+
|
|
202
|
+
### Process all devices
|
|
203
|
+
|
|
204
|
+
Run the script to process all active devices with primary IPs in NetBox:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
python -m inventory_monitor.main
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
The script will:
|
|
211
|
+
1. Query NetBox for matching devices
|
|
212
|
+
2. Establish SNMP connections to each device in parallel
|
|
213
|
+
3. Retrieve inventory data
|
|
214
|
+
4. Merge inventory items by serial number
|
|
215
|
+
5. Create or update Probes in NetBox
|
|
216
|
+
|
|
217
|
+
### Process a single device
|
|
218
|
+
|
|
219
|
+
To process a specific device by name (useful for testing):
|
|
220
|
+
|
|
221
|
+
```bash
|
|
222
|
+
python -m inventory_monitor.main --device router-1
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Single device processing runs sequentially without parallelization.
|
|
226
|
+
|
|
227
|
+
### CLI options for SNMP and NetBox
|
|
228
|
+
|
|
229
|
+
All SNMP and NetBox parameters can be overridden directly from the command line. CLI values take precedence over `.env` settings:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
# Override SNMPv2 community string
|
|
233
|
+
python -m inventory_monitor.main --snmp-version 2 --snmp-community my_community
|
|
234
|
+
|
|
235
|
+
# Override SNMPv3 credentials
|
|
236
|
+
python -m inventory_monitor.main --snmp-user admin --snmp-auth MyPass --snmp-auth-method SHA
|
|
237
|
+
|
|
238
|
+
# Override SNMPv3 with full privacy
|
|
239
|
+
python -m inventory_monitor.main \
|
|
240
|
+
--snmp-user admin \
|
|
241
|
+
--snmp-auth AuthPass \
|
|
242
|
+
--snmp-auth-method SHA \
|
|
243
|
+
--snmp-privacy PrivPass \
|
|
244
|
+
--snmp-privacy-method AES \
|
|
245
|
+
--snmp-security authPriv
|
|
246
|
+
|
|
247
|
+
# Adjust timeout and retries
|
|
248
|
+
python -m inventory_monitor.main --snmp-timeout 30 --snmp-retries 3
|
|
249
|
+
|
|
250
|
+
# Combine with device selection
|
|
251
|
+
python -m inventory_monitor.main --device router-1 --snmp-version 2 --snmp-community secret
|
|
252
|
+
|
|
253
|
+
# Override NetBox settings
|
|
254
|
+
python -m inventory_monitor.main --netbox-url https://netbox.example.com/ --netbox-api-token mytoken
|
|
255
|
+
|
|
256
|
+
# Filter by tags via CLI
|
|
257
|
+
python -m inventory_monitor.main --netbox-tags production,core
|
|
258
|
+
|
|
259
|
+
# Exclude tags via CLI
|
|
260
|
+
python -m inventory_monitor.main --netbox-tags-exclude decommissioned
|
|
261
|
+
|
|
262
|
+
# Adjust parallel jobs
|
|
263
|
+
python -m inventory_monitor.main --parallel-jobs 10
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
Full list of CLI options:
|
|
267
|
+
|
|
268
|
+
| Option | Description |
|
|
269
|
+
|--------|-------------|
|
|
270
|
+
| `--env-file` | Path to environment file (default: `.env`) |
|
|
271
|
+
| `-d`, `--device` | Process a specific device by name |
|
|
272
|
+
| `--snmp-version` | Comma-separated SNMP versions to try (e.g. `"3,2"`) |
|
|
273
|
+
| `--snmp-community` | SNMPv2 community string ⚠️ |
|
|
274
|
+
| `--snmp-user` | SNMPv3 username |
|
|
275
|
+
| `--snmp-auth` | SNMPv3 auth password ⚠️ |
|
|
276
|
+
| `--snmp-auth-method` | SNMPv3 auth protocol (`MD5` or `SHA`) |
|
|
277
|
+
| `--snmp-privacy` | SNMPv3 privacy password ⚠️ |
|
|
278
|
+
| `--snmp-privacy-method` | SNMPv3 privacy protocol (`DES` or `AES`) |
|
|
279
|
+
| `--snmp-security` | SNMPv3 security level (`noAuthNoPriv`, `authNoPriv`, `authPriv`) |
|
|
280
|
+
| `--snmp-timeout` | SNMP timeout per request (integer) |
|
|
281
|
+
| `--snmp-retries` | Number of retries per SNMP version (integer) |
|
|
282
|
+
| `--netbox-api-token` | NetBox API token ⚠️ |
|
|
283
|
+
| `--netbox-url` | NetBox instance URL |
|
|
284
|
+
| `--netbox-tags` | Comma-separated tags to filter devices |
|
|
285
|
+
| `--netbox-tags-exclude` | Comma-separated tags to exclude devices |
|
|
286
|
+
| `--parallel-jobs` | Number of parallel processing jobs (integer) |
|
|
287
|
+
| `--log-level` | Logging level (`DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`) |
|
|
288
|
+
| `--model-excludes` | Comma-separated model names to exclude from inventory |
|
|
289
|
+
| `--debug-dump` | Dump raw SNMP data to JSON file for debugging |
|
|
290
|
+
|
|
291
|
+
⚠️ Options marked with warning expose credentials in process listings. Use `--env-file` with separate environment files instead.
|
|
292
|
+
|
|
293
|
+
### Override environment variables at runtime
|
|
294
|
+
|
|
295
|
+
You can also still use environment variable overrides:
|
|
296
|
+
|
|
297
|
+
```bash
|
|
298
|
+
# Force SNMPv2 only
|
|
299
|
+
SNMP_VERSION='2' python -m inventory_monitor.main
|
|
300
|
+
|
|
301
|
+
# Process only devices tagged 'production'
|
|
302
|
+
NETBOX_TAGS='production' python -m inventory_monitor.main
|
|
303
|
+
|
|
304
|
+
# Combine multiple overrides
|
|
305
|
+
LOG_LEVEL=DEBUG PARALLEL_JOBS=10 python -m inventory_monitor.main --device test-device
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Performance tuning
|
|
309
|
+
|
|
310
|
+
For large device sets, adjust parallelism:
|
|
311
|
+
|
|
312
|
+
```bash
|
|
313
|
+
# Reduce load on SNMP devices (10 parallel jobs)
|
|
314
|
+
PARALLEL_JOBS=10 python -m inventory_monitor.main
|
|
315
|
+
|
|
316
|
+
# Maximize throughput (200 parallel jobs, requires more system resources)
|
|
317
|
+
PARALLEL_JOBS=200 python -m inventory_monitor.main
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## How to tell which SNMP version is being used
|
|
321
|
+
|
|
322
|
+
The application logs which SNMP version successfully connects to each device. Run with `LOG_LEVEL=DEBUG` (or at default `INFO`) and look for these log messages:
|
|
323
|
+
|
|
324
|
+
```
|
|
325
|
+
# Successful SNMPv3:
|
|
326
|
+
device-name (10.0.0.1): SNMPv3 connection successful
|
|
327
|
+
|
|
328
|
+
# SNMPv3 failed, fell back to SNMPv2:
|
|
329
|
+
device-name (10.0.0.1): Unable to use SNMPv3 - <reason>
|
|
330
|
+
device-name (10.0.0.1): SNMPv2 connection successful
|
|
331
|
+
|
|
332
|
+
# Both failed:
|
|
333
|
+
device-name (10.0.0.1): All SNMP connection attempts failed
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
The version try order is controlled by `SNMP_VERSION` (env) or `--snmp-version` (CLI). With the default `"3,2"`, SNMPv3 is tried first. If it fails, SNMPv2 is tried. To force a specific version:
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
# Force SNMPv2 only (skip v3 entirely)
|
|
340
|
+
python -m inventory_monitor.main --snmp-version 2
|
|
341
|
+
|
|
342
|
+
# Force SNMPv3 only (no v2 fallback)
|
|
343
|
+
python -m inventory_monitor.main --snmp-version 3
|
|
344
|
+
|
|
345
|
+
# Try v2 first, then v3
|
|
346
|
+
python -m inventory_monitor.main --snmp-version "2,3"
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
At `DEBUG` log level, you will also see retry attempts. The default `SNMP_RETRIES=1` means one attempt per version (no retries). With `--snmp-retries 3`:
|
|
350
|
+
|
|
351
|
+
```
|
|
352
|
+
device-name (10.0.0.1): SNMPv3 attempt 1/3 failed, retrying
|
|
353
|
+
device-name (10.0.0.1): SNMPv3 attempt 2/3 failed, retrying
|
|
354
|
+
device-name (10.0.0.1): SNMPv3 authentication failed - check username and password/keys
|
|
355
|
+
device-name (10.0.0.1): SNMPv2 connection successful
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
## Logging
|
|
359
|
+
|
|
360
|
+
Logs are created in the `logs/` directory with automatic rotation:
|
|
361
|
+
|
|
362
|
+
- **`logs/all.log`** - All messages at the configured log level (default: INFO)
|
|
363
|
+
- **`logs/errors.log`** - Error and critical messages with detailed traces
|
|
364
|
+
|
|
365
|
+
Both logs rotate at 10 MB and are retained for 1 week.
|
|
366
|
+
|
|
367
|
+
Set `LOG_LEVEL=DEBUG` for detailed troubleshooting:
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
LOG_LEVEL=DEBUG python -m inventory_monitor.main --device router-1
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Troubleshooting
|
|
374
|
+
|
|
375
|
+
### Installation Issues
|
|
376
|
+
|
|
377
|
+
**easysnmp on macOS ARM64**: The `easysnmp` dependency has known issues on Apple Silicon Macs. For production use, deploy on Linux (recommended) or use Docker.
|
|
378
|
+
|
|
379
|
+
### SNMP Connection Issues
|
|
380
|
+
|
|
381
|
+
**"All SNMP connection attempts failed"**
|
|
382
|
+
- Verify device IP is reachable: `ping <device-ip>`
|
|
383
|
+
- Confirm SNMP is enabled on the device
|
|
384
|
+
- Check SNMP credentials in `.env`
|
|
385
|
+
- Try forcing a specific version: `python -m inventory_monitor.main --device <name> --snmp-version 2`
|
|
386
|
+
|
|
387
|
+
**"SNMPv3 authentication failed"**
|
|
388
|
+
- Verify `SNMP_USER` matches device configuration
|
|
389
|
+
- Check `SNMP_AUTH` password and `SNMP_AUTH_METHOD` (SHA vs MD5)
|
|
390
|
+
- If using privacy, ensure `SNMP_PRIVACY` password and `SNMP_PRIVACY_METHOD` are correct
|
|
391
|
+
- Override from CLI to test: `--snmp-user myuser --snmp-auth mypass --snmp-auth-method SHA`
|
|
392
|
+
|
|
393
|
+
**"SNMPv2 timeout"**
|
|
394
|
+
- Device may not support SNMPv2
|
|
395
|
+
- Increase timeout: `--snmp-timeout 200`
|
|
396
|
+
- Increase retries: `--snmp-retries 3`
|
|
397
|
+
- Try SNMPv3: `--snmp-version 3`
|
|
398
|
+
|
|
399
|
+
### No Inventory Returned
|
|
400
|
+
|
|
401
|
+
- Device may not support Entity MIB (standard OIDs)
|
|
402
|
+
- Cisco devices fall back to legacy OIDs automatically
|
|
403
|
+
- Check device is actively reporting SNMP inventory
|
|
404
|
+
|
|
405
|
+
### NetBox API Errors
|
|
406
|
+
|
|
407
|
+
**"API token invalid"**
|
|
408
|
+
- Regenerate token in NetBox under Settings > API Tokens
|
|
409
|
+
- Verify token has write permissions to inventory-monitor plugin
|
|
410
|
+
|
|
411
|
+
**"Probe creation failed"**
|
|
412
|
+
- Ensure inventory-monitor-plugin is installed in NetBox
|
|
413
|
+
- Check device exists in NetBox with correct name
|
|
414
|
+
- Verify device has primary IPv4 address assigned
|
|
415
|
+
|
|
416
|
+
**"NetBox API error ... 500"**
|
|
417
|
+
- NetBox server encountered an internal error
|
|
418
|
+
- Check NetBox server logs for details
|
|
419
|
+
- Retry after the server recovers
|
|
420
|
+
|
|
421
|
+
**"NetBox API error ... 400 ... not one of the available choices"**
|
|
422
|
+
- A tag specified in `NETBOX_TAGS` or `--netbox-tags` does not exist in NetBox
|
|
423
|
+
- Verify tag names match exactly (case-sensitive)
|
|
424
|
+
- Create missing tags in NetBox under Organization > Tags
|
|
425
|
+
|
|
426
|
+
### Debug Data
|
|
427
|
+
|
|
428
|
+
Use `--debug-dump` to save raw SNMP data as a JSON file for inspection:
|
|
429
|
+
|
|
430
|
+
```bash
|
|
431
|
+
python -m inventory_monitor.main --device router-1 --debug-dump debug_output.json
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
Then inspect it in Python:
|
|
435
|
+
|
|
436
|
+
```python
|
|
437
|
+
import json
|
|
438
|
+
with open('debug_output.json') as f:
|
|
439
|
+
data = json.load(f)
|
|
440
|
+
# Inspect raw SNMP results
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
## Development
|
|
444
|
+
|
|
445
|
+
See `CLAUDE.md` for detailed architecture and development guidance.
|
|
446
|
+
|
|
447
|
+
### Contributing
|
|
448
|
+
|
|
449
|
+
1. Fork the repository
|
|
450
|
+
2. Create a feature branch (`git checkout -b feature/your-feature`)
|
|
451
|
+
3. Commit your changes (`git commit -am 'Add feature'`)
|
|
452
|
+
4. Push to the branch (`git push origin feature/your-feature`)
|
|
453
|
+
5. Create a Pull Request
|
|
454
|
+
|
|
455
|
+
## License
|
|
456
|
+
|
|
457
|
+
[Insert your license information here]
|
|
458
|
+
|
|
459
|
+
## Credits
|
|
460
|
+
|
|
461
|
+
Developed by [Your Organization/Team Name]
|