Sending SNMP TRAP
Sends snmp trap.
- snmp.createTrapV1(oid: string, sourceAddress: string)
Helper to create an object that represent a snmp trap V1.
- Arguments:
oid
sourceAddress
- Returns:
- snmp.createTrapV2(oid: string, sourceAddress: string)
Helper to create an object that represent a snmp trap V2.
- Arguments:
oid
sourceAddress
- Returns:
- snmp.createTrapV3(oid: string, sourceAddress: string)
Helper to create an object that represent a snmp trap V3.
- Arguments:
oid
sourceAddress
- Returns:
- snmp.getTarget(host: string, port: number, community: string)
Helper to create an object to send traps.
- Arguments:
host – Hostname/Ip of the target.
port – Port opened on the server that listen for traps
community – Authentication community id.
- Returns:
- snmp.replayTrap(data: number[])
It is possible to replay a trap that was produced by the osp-snmp-trap module if its raw data are available. This is typically done by enabling the trap raw data storage in the alarm on osp-snmp-trap (
alarm.storeRawData = true
) and then accessing it using a menu interaction (alarm.additionalData._rawData
) that will trigger a detached script.snmp.replayTrap(data: byte[])
: asks a running osp-snmp-trap module to replay the trap from its given raw data.
Here is an example of a replay trap script :
main(); function main() { log.info("Replay trap requested"); snmp.replayTrap(trigger.parameters[0].raw); }
and its triggering menu configuration interaction :
{ "label": "Replay trap", "icon": "replay", "context": [ { "type": [ "AlarmTable", "AlarmHistoryTable" ], "action": "root.actions.run_script", "condition": "${alarms.selected}.length === 0 && !!${alarms.clicked.additionalData} && !!${alarms.clicked.additionalData._rawData}", "input": { "scriptId": { "expression": "'root.replay-trap'" }, "arguments": { "expression": "[{'raw': ${alarms.clicked.additionalData._rawData}}]" } } } ] }
- Arguments:
data – List of byte that represent a payload to replay.
- snmp.sendTrap(trap: SnmpTrap, target: SnmpTarget)
Send a trap to a target server.
- Arguments:
trap – Object of type :js:class`SnmpTrap`
target – Target of type :js:class`SnmpTarget` to send trap to.
- class snmp.SnmpTarget()
This class represent target that listen for traps.
- SnmpTarget.setRetry(retry: number)
Set number of retry to send trap to this target.
- Arguments:
retry
- SnmpTarget.setTimeoutMs(timeoutMs: number)
Sets a new timeout in [ms] before trap send is dropped. Default: 1500ms
- Arguments:
timeoutMs
- SnmpTarget.setTimeoutS(timeoutS: number)
Sets a new timeout in [s] before trap send is dropped. Default: 1.5s
- Arguments:
timeoutS
- class snmp.SnmpTrap()
Object that represent an SNMP trap that is sendable to a
SnmpTarget()
.- SnmpTrap.addCounter32Variable(oid: string, content: number)
Adds a COUNTER_32 variable to the trap.
- Arguments:
oid
content
- SnmpTrap.addCounter64Variable(oid: string, content: number)
Adds a COUNTER_64 variable to the trap.
- Arguments:
oid
content
- SnmpTrap.addGauges32Variable(oid: string, content: number)
Adds a GAUGES_32 variable to the trap.
- Arguments:
oid
content
- SnmpTrap.addIntegerVariable(oid: string, content: number)
Adds an INTEGER variable to the trap.
- Arguments:
oid
content
- SnmpTrap.addOctetStringVariable(oid: string, content: string)
Adds an OCTET_STRING variable to the trap.
- Arguments:
oid
content
- SnmpTrap.addTimeTicksVariable(oid: string, content: number)
Adds a TIME_TICKS variable to the trap.
- Arguments:
oid
content
- SnmpTrap.addUnsignedIntegerVariable(oid: string, content: number)
Add an UNSIGNED_INTEGER variable to the trap.
- Arguments:
oid
content