You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/snmp/snmp_framework.md
+71-66Lines changed: 71 additions & 66 deletions
Original file line number
Diff line number
Diff line change
@@ -2,19 +2,18 @@
2
2
comments: true
3
3
---
4
4
5
-
# Customizing SNMP MIBs and Traps in SR Linux
5
+
# Customizing SNMP MIBs for Gets and Traps in SR Linux
6
6
7
-
In version 24.10.1, SR Linux introduces a customizable SNMP framework allowing users to define their own SNMP MIBs and traps.
8
-
This same framework powers [SR Linux's built-in MIBs and traps](https://documentation.nokia.com/srlinux/24-10/books/system-mgmt/snmp.html), offering flexibility to tailor SNMP functionalities to specific requirements.
7
+
SR Linux version 24.10.1 introduces a customizable SNMP framework allowing you to define your own SNMP management information bases (MIBs) for gets and traps. This same framework powers [SR Linux's built-in MIBs and traps](https://documentation.nokia.com/srlinux/24-10/books/system-mgmt/snmp.html), offering flexibility that customizes SNMP MIBs to the specific requirements for your network.
9
8
10
-
The framework utilizes:
9
+
The framework defines:
11
10
12
-
* Mapping files (YAML): To define MIB tables and traps.
13
-
* Conversion scripts ([uPython](https://micropython.org/)): To process data from the management server and expose it via SNMP.
11
+
* Mapping files (YAML): To define MIB tables and object identifiers (OIDs).
12
+
* Conversion scripts ([uPython](https://micropython.org/)): To process data from the management server via gNMI and convert it for SNMP.
14
13
15
-
## SR Linux Built-In MIBs
14
+
## SR Linux Built-In MIBs for Gets
16
15
17
-
Built-in MIB mappings are defined in the configuration file available on the SR Linux's filesystem:
16
+
Built-in MIB mappings are defined in the configuration file available on the SR Linux's file system:
18
17
19
18
```bash
20
19
cat /opt/srlinux/snmp/snmp_files_config.yaml
@@ -34,13 +33,15 @@ trap-definitions:
34
33
```
35
34
</div>
36
35
37
-
### Table definitions
36
+
A simple list of supported OIDs for monitoring is in `/etc/opt/srlinux/snmp/numbers.txt`, and a detailed list with script information is in `/etc/opt/srlinux/snmp/exportOids` when an `access-group` is configured. These files are created at runtime when the SNMP server is started.
37
+
38
+
### Table Definitions
38
39
39
40
The table definition YAML file describes the framework components used to define a particular MIB table. Take the `if_mib.yaml` file for example, it maps interface-related data to standard MIB tables such as `ifTable`, `ifXTable`, and `ifStackTable`.
40
41
41
-
You can list the contents of this file with `cat /opt/srlinux/snmp/scripts/if_mib.yaml` command and we provide it here for reference:
42
+
You can list the contents of this file with `cat /opt/srlinux/snmp/scripts/if_mib.yaml` and it is below for reference:
42
43
43
-
/// details | `if_mib.yaml` definition file
44
+
/// details | `if_mib.yaml` Definition File
44
45
type: subtle-note
45
46
46
47
```yaml
@@ -224,15 +225,15 @@ scalars:
224
225
The table definition file has the following important top level fields:
225
226
226
227
* `paths`: Specifies the gNMI paths for retrieving data.
227
-
* `python-script`: References the uPython script used for data conversion.
228
+
* `python-script`: References the Python script used for data conversion.
228
229
* `tables`: Lists MIB tables, their structure, and their OIDs.
229
230
* `scalars`: Defines scalar OIDs.
230
231
231
-
Under the `tables` key you find the list of MIB table definitions, where each table has the following structure:
232
+
You can see the list of MIB table definitions in the `tables` list, where each table has the following structure:
232
233
233
234
* `name`: Specifies the name of the SNMP table. This is used for identification and reference in the SNMP configuration.
234
-
* `enabled`: Determines whether the table is active (true) or inactive (false).
235
-
* `oid`: The base Object Identifier (OID) for the table. All rows and columns in the table are extensions of this base OID.
235
+
* `enabled`: Defines whether the table is active (true) or inactive (false).
236
+
* `oid`: The base OID for the table. All rows and columns in the table are extensions of this base OID.
236
237
* `indexes`: Indexes uniquely identify rows in the table. Each index maps a specific OID to a value that differentiates rows. A list of column definitions that serve as unique identifiers for rows.
237
238
* `name`: The name of the index column.
238
239
* `oid`: The OID for the index.
@@ -263,24 +264,24 @@ The `syntax` field in SNMP table and scalar definitions specifies the data type
263
264
264
265
## Creating Custom MIBs
265
266
266
-
Users can create custom MIB definitions following these steps:
267
+
You can create custom MIB definitions following these steps:
267
268
268
-
1. Define the Mapping File: Use YAML to specify paths, tables, scalars, and their structure.
269
-
2. Write the Conversion Script: Implement a `snmp_main` function in uPython that processes the input JSON and generates SNMP objects.
270
-
3. Add the mapping file to the list of table-definitions under `/etc/opt/srlinux/snmp/snmp_files_config.yaml`
269
+
1. Define the mapping file: Specify paths, tables, scalars, and their structure in YAML.
270
+
2. Write the conversion script: Implement a `snmp_main` function in Python that processes the input JSON and generates SNMP objects.
271
+
3. Add the mapping file to the list of tabledefinitions under `/etc/opt/srlinux/snmp/snmp_files_config.yaml`.
271
272
272
-
/// admonition | Builtin vs Custom SNMP files and their location
273
+
/// admonition | Location of Built-in and Custom SNMP Framework Files
273
274
type: subtle-note
274
-
The user-defined MIB definitions and table/trap files with the associated scripts are stored in `/etc/opt/srlinux/snmp` directory, while the built-in MIB definitions are stored in `/opt/srlinux/snmp` directory.
275
+
The user-defined MIB definitions and files with the associated scripts are stored in `/etc/opt/srlinux/snmp` directory, while the built-in MIB definitions are stored in `/opt/srlinux/snmp` directory.
275
276
///
276
277
277
278
### Input JSON Format
278
279
279
-
Recall, that SNMP framework is powered by the underlying SR Linux's gNMI infrastructure. The `paths` you define in the table mapping file will retrieve the data that the conversion script will work on to create the SNMP MIB tables.
280
+
The SNMP framework is powered by the underlying SR Linux's gNMI infrastructure. The `paths` you define in the table mapping file will retrieve the data that the conversion script will use to create the SNMP MIB tables.
280
281
281
-
A thing to note is that the `paths` you define in the mapping file are non-recursive; this means that the returned data will be limited to the immediate children of the path you specify. To recursively retrieve data from a path, add `...` to the end of the path, e.g. `/interface/ethernet/...`.
282
+
Note that the `paths` you define in the mapping file are non-recursive; this means that the returned data will be limited to the immediate children of the path you specify. To recursively retrieve data from a path, add `...` to the end of the path, e.g. `/interface/ethernet/...`.
282
283
283
-
The uPython script receives data in JSON format, including global SNMP information and the gNMI query results. Here is an example of a payload the `if_mib.py` script receives.
284
+
The Python script receives data in JSON format, including global SNMP information and the gNMI query results. Here is an example of a payload the `if_mib.py` script receives.
284
285
285
286
```{.json .code-scroll-lg}
286
287
{
@@ -393,7 +394,7 @@ The uPython script receives data in JSON format, including global SNMP informati
393
394
394
395
### Output JSON Format
395
396
396
-
The script should output JSON containing tables and scalars.
397
+
The script outputs JSON containing tables and scalars.
397
398
398
399
```{.json .code-scroll-lg}
399
400
{
@@ -438,24 +439,25 @@ The script should output JSON containing tables and scalars.
438
439
}
439
440
```
440
441
441
-
### uPython script
442
+
### Python Script
442
443
443
444
The script entry point is a function called `snmp_main` that takes a JSON string as input and returns a JSON string.
444
445
445
446
```python
446
447
def snmp_main(in_json_str: str) -> str:
447
448
```
448
449
449
-
See the built-in scripts as examples.
450
-
The `/opt/srlinux/snmp/scripts/utilities.py` contains some useful helper functions to perform various checks and common type conversions.
450
+
Refer to the built-in scripts as examples. The `/opt/srlinux/snmp/scripts/utilities.py` script contains some useful helper functions to perform various checks and common type conversions.
451
451
452
452
## SR Linux Built-In Traps
453
453
454
-
Traps are defined with the mapping files that look similar to the MIB ones, but include additional parameters for triggers and variable bindings. As we've seen in the beginning of this document, the traps mapping files are listed in the global `/opt/srlinux/snmp/snmp_files_config.yaml`.
454
+
Traps are defined with mapping files that look similar to the MIB files, but include additional parameters for triggers and variable bindings. As you have seen in the beginning of this document, the traps mapping files are listed in the global `/opt/srlinux/snmp/snmp_files_config.yaml`.
455
+
456
+
A list of OIDs available for traps is in `/etc/opt/srlinux/snmp/installedTraps` when a `trap-group` is configured. This file is created at runtime when the SNMP server is started.
455
457
456
-
### Trap definitions
458
+
### Trap Definitions
457
459
458
-
The trap definition YAML file has exactly the same top level elements as the table definition file but instead of `tables` the file contains `traps` top-level key. Here is the contents of the `/opt/srlinux/snmp/scripts/rfc3418_traps.yaml` mapping file that defines the traps as per RFC 3418:
460
+
The trap definition YAML file has exactly the same top level elements as the table definition file but instead of `tables` the file contains `traps` top-level list. Here is the contents of the `/opt/srlinux/snmp/scripts/rfc3418_traps.yaml` mapping file that defines the traps as per RFC 3418:
@@ -551,9 +553,9 @@ Besides the common `name`, `enabled` and `oid` fields, the `traps` object has th
551
553
552
554
To define custom traps:
553
555
554
-
1. Write a YAML Mapping File: Define the trap triggers, contexts, and variable bindings.
555
-
2. Implement the Conversion Script: Process trigger events and generate trap data in the `snmp_main` function.
556
-
3. Add the mapping file to the list of trap-definitions under `/etc/opt/SR Linux/snmp/snmp_files_config.yaml`
556
+
1. Define the mapping file: Define the trap triggers, contexts, and variable bindings in YAML.
557
+
2. Write the conversion script: Implement trigger events and generate trap data in the `snmp_main` function.
558
+
3. Add the mapping file to the list of trap-definitions under `/etc/opt/SR Linux/snmp/snmp_files_config.yaml`.
557
559
558
560
### Input JSON Format
559
561
@@ -627,7 +629,7 @@ The Python script receives a JSON object containing trap triggers and context da
627
629
628
630
### Output JSON Format
629
631
630
-
The script should return a list of traps.
632
+
The script returns a list of traps.
631
633
632
634
```{.json .code-scroll-lg}
633
635
{
@@ -649,79 +651,78 @@ The script should return a list of traps.
649
651
}
650
652
```
651
653
652
-
### uPython script
654
+
### Python Script
653
655
654
656
The script entry point is a function called `snmp_main` that takes a JSON string as input and returns a JSON string.
655
657
656
658
```python
657
659
def snmp_main(in_json_str: str) -> str:
658
660
```
659
661
660
-
See the built-in scripts as examples.
661
-
The `/opt/srlinux/snmp/scripts/utilities.py` file contains some useful helper functions to perform various checks and common type conversions.
662
+
Refer to the built-in scripts as examples. The `/opt/srlinux/snmp/scripts/utilities.py` script contains some useful helper functions to perform various checks and common type conversions.
662
663
663
664
## Directory Structure for Custom Files
664
665
665
-
Place user-defined files under `/etc/opt/srlinux/snmp`.
666
+
Place user-defined files in `/etc/opt/srlinux/snmp`.
666
667
667
-
Changes to mapping files and scripts are not automatically picked up by the SNMP server,
668
-
a restart of the SNMP server is required.
668
+
Changes to mapping files and scripts are not automatically read by the SNMP server, a restart of the SNMP server is required.
669
669
670
670
```srl
671
+
--{ + running }--[ ]--
671
672
A:srl1# /tools system app-management application snmp_server-mgmt restart
672
673
```
673
674
674
675
## Debugging and Troubleshooting
675
676
676
-
Debug files are generated in `/tmp/snmp_debug/$NETWORK_INSTANCE`:
677
+
Debug files are generated in `/tmp/snmp_debug/$NETWORK_INSTANCE` when `debug: true` is set in the YAML configuration file.
677
678
678
-
* Input/Output Logs: Check `.json_input`, `.json_output`, `.console` and `.error` files for debugging script execution.
679
-
The `.console` files contain anything printed by the scripts and the `.error` files contain mapping and scripts errors.
680
-
* Path Data: Inspect debug outputs for issues in path retrieval.
679
+
* Input/output logs: Check `.json_input`, `.json_output`, `.console` and `.error` files for debugging script execution. The `.console` files contain output printed by the scripts and the `.error` files contain mapping and scripts errors.
680
+
* Path data: Inspect debug outputs for issues in path retrieval.
681
681
682
682
## Example: gRPCServer MIB
683
683
684
-
Let's add a custom SNMP MIB to SR Linux at **runtime**, no feature requests, no software upgrades,
685
-
let it be a gRPC server SNMP MIB 🤪.
684
+
Let's add a custom SNMP MIB to SR Linux at **runtime**, no feature requests, no software upgrades, by creating a gRPC server SNMP MIB 🤪.
686
685
687
-
### Table definition
686
+
### Table Definition
688
687
689
-
Add a new table definition under `/etc/opt/srlinux/snmp/scripts/grpc_mib.yaml`
688
+
Add a new table definition under `/etc/opt/srlinux/snmp/scripts/grpc_mib.yaml`.
690
689
691
-
This MIB has a single index `gRPCServerName` and 6 columns; the gRPC server network instance, its admin and operational states, the number of accepted and rejected RPCs as well as the last time an RPC was accepted.
690
+
This MIB has a single index `gRPCServerName` and 6 columns; the gRPC server network instance, its admin and operational states, the number of accepted and rejected RPCs and the last time an RPC was accepted.
692
691
693
-
All these fields can be mapped from leaves that can be found under the xpath `/system/grpc-server/...`
692
+
All of these fields can be mapped from leafs that are found under the XPath `/system/grpc-server/...`
The YAML file points to a python script called `grpc_mib.py`. It must be placed in the same directory as the `grpc_mib.yaml` file.
700
+
The YAML file references a Python script called `grpc_mib.py`. It must be placed in the same directory as the `grpc_mib.yaml` file.
702
701
703
-
The script is fairly simple; grabs the JSON input, set some global SNMP information such as the box boot time (useful for calculating time ticks values).
704
-
After that, it iterates over the list of gRPC servers in the input JSON and set each server's columns values (with the correct format) in the prepared output dict.
705
-
Finally it returns the output dict as a JSON blob.
702
+
The script is fairly simple; it grabs the JSON input and sets some global SNMP information such as the system boot time (useful for calculating time ticks values). After that, it iterates over the list of gRPC servers in the input JSON and set each server's columns values (with the correct format) in the prepared output dict. Finally it returns the output dict as a JSON blob.
Have a look at `/tmp/snmp_debug` to see the input and output JSON blobs.
750
751
751
-
There you have it: A user-defined SNMP MIB added to SR Linux at **runtime**, no feature request, no software upgrade needed.
752
+
There you have it: a user-defined SNMP MIB added to SR Linux at **runtime**, no feature request, no software upgrade needed.
753
+
754
+
### Lab Example
755
+
756
+
We created [a lab](https://github.com/srl-labs/srl-snmp-framework-lab) that implements this custom gRPC server MIB that you can deploy locally or in Codespaces to try it out.
752
757
753
-
### Lab
758
+
## Conclusion
754
759
755
-
We create [a lab](https://github.com/srl-labs/srl-snmp-framework-lab) that implements this custom gRPC server MIB that you can deploy locally or in Codespaces to try it out.
760
+
The SR Linux customizable SNMP framework allows you to define your own SNMP MIBs for gets and traps that customize SNMP functionalities to specific requirements.
0 commit comments