Skip to content

Commit 2060810

Browse files
ghankinshellt
andauthored
SNMP Framework copy edits. (#179)
* SNMP Framework copy edits. * cleanup frontmatter --------- Co-authored-by: Roman Dodin <dodin.roman@gmail.com>
1 parent 2d99dbd commit 2060810

File tree

2 files changed

+75
-70
lines changed

2 files changed

+75
-70
lines changed

docs/programmability/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ title: Programmability
7979

8080
[:octicons-arrow-right-24: Documentation](../ansible/index.md)
8181

82-
- :octicons-terminal-24:{ .lg .middle } **Screen scraping**
82+
- :octicons-terminal-24:{ .lg .middle } **Screen Scraping**
8383

8484
---
8585

@@ -94,13 +94,13 @@ title: Programmability
9494

9595
<small>:material-progress-wrench: Tutorials coming soon...</small>
9696

97-
- :material-emoticon-devil:{ .lg .middle } **Program SNMP MIBs and Traps**
97+
- :material-emoticon-devil:{ .lg .middle } **Custom SNMP MIBs for Gets and Traps**
9898

9999
---
100100

101-
We have gNMI, we have JSON-RPC, we have NETCONF, we have CLI with JSON and YAML outputs, but you kept asking for SNMP...
101+
We have gNMI, we have JSON-RPC, we have NETCONF, we have a CLI with JSON and YAML outputs, but if you are still using SNMP...
102102

103-
Alright, here is your SNMP, but fully programmable!
103+
We have SNMP, and it's fully programmable to define custom MIBs!
104104

105105
[:octicons-arrow-right-24: SNMP Framework](../snmp/snmp_framework.md)
106106

docs/snmp/snmp_framework.md

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22
comments: true
33
---
44

5-
# Customizing SNMP MIBs and Traps in SR Linux
5+
# Customizing SNMP MIBs for Gets and Traps in SR Linux
66

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.
98

10-
The framework utilizes:
9+
The framework defines:
1110

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.
1413

15-
## SR Linux Built-In MIBs
14+
## SR Linux Built-In MIBs for Gets
1615

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:
1817

1918
```bash
2019
cat /opt/srlinux/snmp/snmp_files_config.yaml
@@ -34,13 +33,15 @@ trap-definitions:
3433
```
3534
</div>
3635
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
3839

3940
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`.
4041

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:
4243

43-
/// details | `if_mib.yaml` definition file
44+
/// details | `if_mib.yaml` Definition File
4445
type: subtle-note
4546

4647
```yaml
@@ -224,15 +225,15 @@ scalars:
224225
The table definition file has the following important top level fields:
225226

226227
* `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.
228229
* `tables`: Lists MIB tables, their structure, and their OIDs.
229230
* `scalars`: Defines scalar OIDs.
230231

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:
232233

233234
* `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.
236237
* `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.
237238
* `name`: The name of the index column.
238239
* `oid`: The OID for the index.
@@ -263,24 +264,24 @@ The `syntax` field in SNMP table and scalar definitions specifies the data type
263264

264265
## Creating Custom MIBs
265266

266-
Users can create custom MIB definitions following these steps:
267+
You can create custom MIB definitions following these steps:
267268

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 table definitions under `/etc/opt/srlinux/snmp/snmp_files_config.yaml`.
271272

272-
/// admonition | Builtin vs Custom SNMP files and their location
273+
/// admonition | Location of Built-in and Custom SNMP Framework Files
273274
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.
275276
///
276277

277278
### Input JSON Format
278279

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.
280281

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/...`.
282283

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.
284285

285286
```{.json .code-scroll-lg}
286287
{
@@ -393,7 +394,7 @@ The uPython script receives data in JSON format, including global SNMP informati
393394

394395
### Output JSON Format
395396

396-
The script should output JSON containing tables and scalars.
397+
The script outputs JSON containing tables and scalars.
397398

398399
```{.json .code-scroll-lg}
399400
{
@@ -438,24 +439,25 @@ The script should output JSON containing tables and scalars.
438439
}
439440
```
440441

441-
### uPython script
442+
### Python Script
442443

443444
The script entry point is a function called `snmp_main` that takes a JSON string as input and returns a JSON string.
444445

445446
```python
446447
def snmp_main(in_json_str: str) -> str:
447448
```
448449

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.
451451

452452
## SR Linux Built-In Traps
453453

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.
455457

456-
### Trap definitions
458+
### Trap Definitions
457459

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:
459461

460462
/// details | `rfc3418_traps.yaml` definition file
461463
type: subtle-note
@@ -551,9 +553,9 @@ Besides the common `name`, `enabled` and `oid` fields, the `traps` object has th
551553

552554
To define custom traps:
553555

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`.
557559

558560
### Input JSON Format
559561

@@ -627,7 +629,7 @@ The Python script receives a JSON object containing trap triggers and context da
627629

628630
### Output JSON Format
629631

630-
The script should return a list of traps.
632+
The script returns a list of traps.
631633

632634
```{.json .code-scroll-lg}
633635
{
@@ -649,79 +651,78 @@ The script should return a list of traps.
649651
}
650652
```
651653

652-
### uPython script
654+
### Python Script
653655

654656
The script entry point is a function called `snmp_main` that takes a JSON string as input and returns a JSON string.
655657

656658
```python
657659
def snmp_main(in_json_str: str) -> str:
658660
```
659661

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.
662663

663664
## Directory Structure for Custom Files
664665

665-
Place user-defined files under `/etc/opt/srlinux/snmp`.
666+
Place user-defined files in `/etc/opt/srlinux/snmp`.
666667

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.
669669

670670
```srl
671+
--{ + running }--[ ]--
671672
A:srl1# /tools system app-management application snmp_server-mgmt restart
672673
```
673674

674675
## Debugging and Troubleshooting
675676

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.
677678

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.
681681

682682
## Example: gRPCServer MIB
683683

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 🤪.
686685

687-
### Table definition
686+
### Table Definition
688687

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`.
690689

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.
692691

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/...`
694693

695694
```{.yaml .code-scroll-lg}
696695
--8<-- "https://raw.githubusercontent.com/srl-labs/srl-snmp-framework-lab/refs/heads/main/grpc_mib.yaml"
697696
```
698697

699-
### Python script
698+
### Python Script
700699

701-
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.
702701

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.
706703

707704
```{.python .code-scroll-lg}
708705
--8<-- "https://raw.githubusercontent.com/srl-labs/srl-snmp-framework-lab/refs/heads/main/grpc_mib.py"
709706
```
710707

711-
### Custom MIBs file
708+
### Custom MIBs File
712709

713-
Reference the YAML mapping file in the user's `snmp_files_config.yaml` so that the SNMP server picks it up
710+
Reference to the YAML mapping file in the your `snmp_files_config.yaml` so that the SNMP server loads it.
714711

715-
```shell
712+
```bash
716713
cat /etc/opt/srlinux/snmp/snmp_files_config.yaml
714+
```
717715

716+
<div class="embed-result">
717+
```yaml
718718
table-definitions:
719719
- scripts/grpc_mib.yaml
720720
```
721+
</div>
721722

722-
### SNMP server restart
723+
### SNMP Server Restart
723724

724-
Restart the SNMP server process for it to pick up the new custom MIB definitions.
725+
Restart the SNMP server process for it to load the new custom MIB definitions.
725726

726727
```srl
727728
--{ + running }--[ ]--
@@ -733,9 +734,9 @@ A:srl1# /tools system app-management application snmp_server-mgmt restart
733734
Application 'snmp_server-mgmt' was restarted
734735
```
735736

736-
And test your new MIB
737+
And test your new MIB.
737738

738-
```shell
739+
```bash
739740
$ snmpwalk -v2c -c public clab-snmp-srl1 1.3.6.1.4.1.6527.115
740741
741742
iso.3.6.1.4.1.6527.115.114.108.105.110.117.120.1.2.4.109.103.109.116 = STRING: "mgmt" # <-- grpcServerNetworkInstance
@@ -748,8 +749,12 @@ iso.3.6.1.4.1.6527.115.114.108.105.110.117.120.1.7.4.109.103.109.116 = Timeticks
748749

749750
Have a look at `/tmp/snmp_debug` to see the input and output JSON blobs.
750751

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.
752757

753-
### Lab
758+
## Conclusion
754759

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

Comments
 (0)