Skip to content

Commit df65a62

Browse files
committed
SNMP: add shared extension systemd units
1 parent bb61002 commit df65a62

3 files changed

Lines changed: 78 additions & 0 deletions

File tree

snmp/common/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# LibreNMS SNMP Extension Common Units
2+
3+
This directory contains shared systemd units for LibreNMS SNMP extensions that refresh cached output on a schedule.
4+
5+
## Files
6+
7+
- `librenms-snmp-extension@.service`: common oneshot service template.
8+
- `librenms-snmp-extension@.timer`: common timer template that runs an extension every five minutes.
9+
10+
## Defaults
11+
12+
The common service runs extension instances by name:
13+
14+
```ini
15+
ExecStart=/usr/local/lib/snmpd/%i --config /etc/snmp/extension/%i.yaml --output /run/snmp/extension/%i.json
16+
```
17+
18+
For an extension named `example`, this resolves to:
19+
20+
- Script: `/usr/local/lib/snmpd/example`
21+
- Config: `/etc/snmp/extension/example.yaml`
22+
- Output: `/run/snmp/extension/example.json`
23+
24+
Extensions that need different arguments should install a systemd drop-in override for their specific instance.
25+
26+
The units include `Documentation=` metadata for the shared common units and the extension-specific directory. The service also sets `SyslogIdentifier=librenms-snmp-extension-%i` so logs can be filtered per extension instance.
27+
28+
## Enable An Extension
29+
30+
Install the shared units to `/etc/systemd/system/`, then enable the timer for the extension instance:
31+
32+
```bash
33+
sudo systemctl daemon-reload
34+
sudo systemctl enable --now librenms-snmp-extension@example.timer
35+
```
36+
37+
Check timer status:
38+
39+
```bash
40+
systemctl status librenms-snmp-extension@example.timer
41+
```
42+
43+
Run a refresh manually:
44+
45+
```bash
46+
sudo systemctl start librenms-snmp-extension@example.service
47+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# SNMP common extension cache.
2+
[Unit]
3+
Description=LibreNMS SNMP extension cache: %i
4+
Documentation=https://github.com/librenms/librenms-agent/tree/master/snmp/common
5+
Documentation=https://github.com/librenms/librenms-agent/tree/master/snmp/%i
6+
7+
[Service]
8+
Type=oneshot
9+
SyslogIdentifier=librenms-snmp-extension-%i
10+
RuntimeDirectory=snmp/extension
11+
RuntimeDirectoryMode=0755
12+
ExecStart=/usr/local/lib/snmpd/%i --config /etc/snmp/extension/%i.yaml --output /run/snmp/extension/%i.json
13+
NoNewPrivileges=true
14+
PrivateTmp=true
15+
ProtectHome=true
16+
ProtectSystem=full
17+
ReadWritePaths=/run/snmp/extension
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SNMP common extension cache.
2+
[Unit]
3+
Description=Run LibreNMS SNMP extension cache refresh: %i
4+
Documentation=https://github.com/librenms/librenms-agent/tree/master/snmp/common
5+
Documentation=https://github.com/librenms/librenms-agent/tree/master/snmp/%i
6+
7+
[Timer]
8+
OnBootSec=2min
9+
OnUnitActiveSec=5min
10+
AccuracySec=30s
11+
Persistent=true
12+
13+
[Install]
14+
WantedBy=timers.target

0 commit comments

Comments
 (0)