Skip to content

Commit

Permalink
#216 - nOutput_SNMPServer add sysUpTime defining how long ago in mill…
Browse files Browse the repository at this point in the history
…iseconds the trap occurred

After the change done in SNMP Lib there is the need to enable in the corresponding object nOutput_SNMPServer the ability to define sysUpTime. This parameter defines how long ago in milliseconds the trap occurred and it's used when integrating with OpenNMS.
  • Loading branch information
abrizida committed Jan 29, 2024
1 parent 522a169 commit 5f6133d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions config/objects/nOutput_SNMPServer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Author: Surya Kalyan Jaddu
* Author: Surya Kalyan Jaddu
* Changes: Andreia Brizida
*
* <odoc>
* <key>nAttrmon.nOutput_SNMPServer(aMap)</key>
Expand All @@ -9,6 +10,7 @@
* - baseOID((string) Base Oid is used to send traps.\
* - snmpVersion(string) it defines version of SNMP server.\
* - oidMapping(Map) it contains keys mapped with OID values to send traps.\
* - sysUpTime(double) it defines how long ago in milliseconds the trap occurred.\
*
* </odoc>
*/
Expand All @@ -23,6 +25,7 @@ var nOutput_SNMPServer = function (aMap) {
baseOID = _$(aMap.baseOID, "var aMap.baseOID").isString().regexp(/([0-9]{1,4}\.)/).$_("something")
snmpVersion = _$(aMap.snmpVersion, "snmpVersion").oneOf([1, 2, 3]).isNumber().default(2)
oidMapping = _$(aMap.oidMapping, "oidMapping").isObject().$_("Please Map the oid's")
sysUpTime = _$(aMap.sysUpTime, "var aMap.sysUpTime").isDouble().default(0)

snmpAuthPassPhrase = _$(aMap.snmpAuthPassPhrase, "snmpAuthPassPhrase").isString().$_("Please provide snmpAuthPhrase")
snmpPrivPassPhrase = _$(aMap.snmpPrivPassPhrase, "snmpPrivPassPhrase").isString().$_("Please Provoide snmpPrivPassPhrase")
Expand All @@ -33,6 +36,7 @@ var nOutput_SNMPServer = function (aMap) {
if (isUnDef(aMap.snmpSecurityName) || aMap.snmpSecurityName === null) aMap.snmpSecurityName = "NMS";
if (isUnDef(aMap.timeOut) || aMap.timeOut === null) aMap.timeOut = 5000;
if (isUnDef(aMap.numOfRetries) || aMap.timeOut === null) aMap.numOfRetries = 3;
if (isUnDef(aMap.snmpSecurityName) || aMap.snmpSecurityName === null) aMap.snmpSecurityName = "NMS";

this.IDMapping = aMap.oidMapping
this.params = {
Expand All @@ -42,7 +46,8 @@ var nOutput_SNMPServer = function (aMap) {
"numOfRetries": aMap.numOfRetries,
"snmpVersion": snmpVersion,
"snmpEngineID": snmpEngineID,
"snmpBaseOID": baseOID
"snmpBaseOID": baseOID,
"sysUpTime": sysUpTime
}

this.snmpProtocols = {
Expand Down Expand Up @@ -165,7 +170,8 @@ nOutput_SNMPServer.prototype.sendTrap = function (argsValue, params, snmpProtoco
if (params.snmpVersion <= 2) var snmp = new SNMP(params.snmpIPAddress, params.snmpCommunity); else var snmp = new SNMP(params.snmpIPAddress, params.snmpCommunity, params.snmpTimeout, params.numOfRetries, params.snmpVersion, snmpProtocols);
var response = this.entitiesExtraction(argsValue, IDMapping)
log(stringify(response.trapArr))
snmp.trap(params.snmpBaseOID, response.trapArr)
//snmp.trap(params.snmpBaseOID, response.trapArr)
snmp.trap(params.snmpBaseOID, params.sysUpTime, response.trapArr)
log("Trap Sent Successfully")
}
catch (e) {
Expand Down
1 change: 1 addition & 0 deletions config/outputs.disabled/yaml/10.SNMPServer_Output.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ output:
snmpAuthProtocol: "MD5"
snmpPrivProtocol: "AES128"
snmpSecurityName: "NMS"
sysUpTime: 0

0 comments on commit 5f6133d

Please sign in to comment.