This recipe integrates a UPS (uninterruptible power supply) or a network switch into the building supervision with the SNMP driver: read the useful values, publish them to the BMS, keep their history, and send an e-mail when the UPS switches to battery or when the device sends a notification (trap). The order of the steps matters, especially the MIB files before the Walk.
Checked against: firmware r9347. Licence: the SNMP driver is a licensed feature (contact support@weble.ch). Level: BMS integrator.
You need:
public for read access), or a user name, security level and keys for v3. Allow the IP address of the gateway in the access list of the device, if it has one;.mib), available on the manufacturer's website. Most UPS also implement the standard UPS-MIB (RFC 1628), and every switch the standard IF-MIB;161.v2c for most devices, v1 for old ones, v3 when the site requires authentication and encryption.0, confirm and start the gateway.The gateway connects when the device answers. If it restarts in a loop, see section 8.
Load the MIB first. Open the address table of the gateway, then SNMP Methods › MIB Files, and upload the .mib file(s) of the device. The Walk uses them to give readable names to the addresses; a MIB uploaded after the Walk does not rename the addresses already created.
Then run the Walk with SNMP Methods › Walk. Enter a root OID, ideally a narrow one:
| Device | Root OID | Content |
|---|---|---|
| UPS (standard UPS-MIB) | 1.3.6.1.2.1.33 |
Battery, input, output, alarms |
| Switch (interfaces) | 1.3.6.1.2.1.2 |
Interface table: status and counters |
| Any device | 1.3.6.1.2.1.1 |
System group: name, description, uptime |
| Manufacturer data | 1.3.6.1.4.1 |
Private MIB of the manufacturer (can be large) |
The progress is shown in percent. Avoid the root 1 on a switch: a full walk can create several thousand addresses.
Or insert the addresses by hand. Insert an address with a name of your choice, for example %snmp:upsBatteryStatus, and type the numeric OID with its instance suffix in OID: .0 for a single value, the row index for a table.
The addresses created by the Walk hold the value read during the walk, but they are not polled. Delete the addresses you do not need, then tick those you keep, open Selection › Update addresses and set Polling in milliseconds (minimum 1000).
Useful values of the standard MIBs:
| Value | OID | Meaning | Polling |
|---|---|---|---|
| Battery status (UPS) | 1.3.6.1.2.1.33.1.2.1.0 |
1 unknown, 2 normal, 3 low, 4 depleted | 10000 |
| Estimated minutes remaining (UPS) | 1.3.6.1.2.1.33.1.2.3.0 |
Minutes of autonomy on battery | 60000 |
| Estimated charge remaining (UPS) | 1.3.6.1.2.1.33.1.2.4.0 |
Battery charge in % | 60000 |
| Output source (UPS) | 1.3.6.1.2.1.33.1.4.1.0 |
3 normal, 4 bypass, 5 battery (other values: see the MIB) | 5000 |
| Interface status (switch) | 1.3.6.1.2.1.2.2.1.8.<n> |
1 up, 2 down, for interface index <n> |
10000 |
| System uptime | 1.3.6.1.2.1.1.3.0 |
Time since the last restart of the device | 60000 |
Check that the Value column updates at the polling interval.
Publish to the BMS. Drag an SNMP address onto a BACnet, Modbus or KNX address to create a route (see Routes). For example, route %snmp:upsEstimatedChargeRemaining to an analog value of the BACnet gateway, and the output source to a multi-state value. The SNMP addresses are read-only: the routes go from SNMP to the other protocol.
Keep the history. Set Log on the addresses to keep: on update for states (battery status, output source, interface status), a duration such as 900000 (15 minutes) for the charge and the autonomy. See Logging & history.
Create a route:
| Parameter | Value |
|---|---|
| Name | UPS on battery |
| Trigger | tick value only (untick status, refresh and gateway), so that a restart does not send the e-mail again |
| Source gateway / address | the SNMP gateway, %snmp:upsOutputSource |
| Source value | the function below |
| Destination gateway / address | the SMTP gateway, facility@example.com:UPS alarm (recipient and subject) |
function upsAlert(v, src, dst, options){
// upsOutputSource (RFC 1628): 3 = normal, 4 = bypass, 5 = battery
var ctx = options.context
if(v == 5 && !ctx.onBattery){
ctx.onBattery = true
return "The UPS is running on battery (" + src.name + ")."
}
if(v != 5 && ctx.onBattery){
ctx.onBattery = false
return "The UPS is no longer on battery, output source = " + v + "."
}
// otherwise return nothing: no e-mail
}
The function returns the text of the e-mail only when the state changes; when it returns nothing, nothing is sent. The same pattern works with the battery status (3 low, 4 depleted) or with an interface status (2 down).
To be alerted when the UPS itself stops answering, add a status route on the same address, as in Email gateway status alerts.
A trap is a notification sent by the device without being polled, for example when the UPS switches to battery or a switch port goes down. To receive them:
162 and leave Receiver auth unticked.Each notification received is written to the address %snmp_trap:receiver (created at the first trap) as a JSON object: rinfo.address is the sender, and pdu.varbinds the list of {oid, type, value} it carries. In addition, when a varbind matches an existing address named %snmp:<numeric OID>, that address is updated at once, without waiting for the next poll.
To receive the traps by e-mail, route %snmp_trap:receiver to an SMTP address (trigger value only) with this function:
function trapToMail(v, src, dst, options){
if(!v || !v.pdu) return
var lines = ["SNMP notification from " + (v.rinfo && v.rinfo.address)]
;(v.pdu.varbinds || []).forEach(function(vb){
var val = (vb.value && vb.value.value_string !== undefined) ? vb.value.value_string : vb.value
lines.push(vb.oid + " = " + JSON.stringify(val))
})
return lines.join("\n")
}
Filter on the OIDs of the notifications that matter (see the MIB of the device) before returning the text, otherwise every notification produces an e-mail.
| Symptom | Cause and fix |
|---|---|
The gateway restarts in a loop, the log shows connection to <host> failed: ... (restarting in 5s) |
The device does not answer or refuses the credentials: check Host, Version, the community or the v3 user, and the access list of the device. |
Address error invalid oid |
The OID field must be numeric (1.3.6.1...), not a name. |
Address error no such object |
The OID has no instance: add .0 for a single value, or the row index for a table. |
| The values do not change after the Walk | The imported addresses are not polled: set Polling (step 3). |
| The addresses have numeric names although a MIB was loaded | The MIB was uploaded after the Walk. Delete the addresses and run the Walk again. |
The Walk window stops with timeout |
The tree is large or the device slow: the walk may continue in the background. Refresh the address table, and start again from a narrower root OID. |
| No trap arrives | Check the trap destination on the device (IP of the gateway, port 162, version), that Receiver is ticked, and the firewalls between the device and the gateway. |
The log shows missing license |
The gateway has no SNMP licence. |