SNMP JavaScript API

Connector functions SNMP JS API guide

In this javascript code, it is possible to use some defined functions to execute SNMP petitions in the connector function. We will explain them below.

JS SNMP API

For REQUEST Connector Functions we will use the functions get and set described below. You have an object, named snmp, with those functions described. You must use snmp.get or snmp.set.

If you want to collect data after executing any of these function you can call collectCF and you can set various oids in the URL provided as you can see in the next example:

collectCF(result.data, "snmps://<oidValue>");

get() ⇒ String

Executes a multi SNMP get attribute request with specified payload. You must have previously given value to the properties snmp.ip, snmp.port (161 by default), snmp.comunity (in case of snmp version 1), snmp.version (3 by default), snmp.retries (3 by default), snmp.timeout (5000 by default) and security info in case of snmpv3 version (snmp.securityName, snmp.authentication, snmp.privacy, snmp.authPassphrase and snmp.privPassphrase). In addition, you have to add the oids you want to get using the snmp.addOid function with the oid string as many times as you want.

Kind: global function
Returns: String - A JSON with response. This JSON will have two fields: ‘result’ of the get operation and ‘data’ with response of the device.

SNMP Field Type Description
ip string IP address of the device you want to connect to.
port number Port of the device you want to connect to. By default is 161.
oids Array Array of strings with the list of wanted oids. To add items to the list, you must call the function ‘snmp.addOid’ with the oid as parameter as many times as you want oids.
comunity string The community octet sting. This is a convenience method to set the security name for community based SNMP (v1 and v2c).
securityName string The security name of the user (typically the user name).
authentication string The authentication protocol ID to be associated with this user. If set to null, this user only supports unauthenticated messages.
authPassphrase string The authentication passphrase. If not null, authentication must also be not null.
privacy string The privacy protocol ID to be associated with this user. If set to null, this user only supports unencrypted messages.
privPassphrase string The privacy passphrase. If not null, privacy must also be not null.
version number Version number of the SNMP. By default is 3.
retries number Number of retries for the request. By default is 3.
timeout number Timeout of the request in millis. By default is 5000.

Here is an example of use for the snmp.addOid function for snmp.get:

snmp.addOid('1.3.6.1.4.1.2007.4.1.2.2.2.18.3.2.1.11.3');

set() ⇒ String

Executes a multi SNMP set attribute request with specified payload. You must have previously given value to the properties snmp.ip, snmp.port (161 by default), snmp.comunity (in case of snmp version 1), snmp.version (3 by default), snmp.retries (3 by default), snmp.timeout (5000 by default) and security info in case of snmpv3 version (snmp.securityName, snmp.authentication, snmp.privacy, snmp.authPassphrase and snmp.privPassphrase). In addition, you have to add the oids you want to set using the snmp.addOid function with the oid string, the type of the value and the value you want to set to as many times as you want.

Kind: global function
Returns: String - A JSON with response. This JSON will have two fields: ‘result’ of the get operation and ‘data’ with response of the device. This ‘data’ contains pairs of (oid, value).

SNMP Field Type Description
ip string IP address of the device you want to connect to.
port number Port of the device you want to connect to. By default is 161.
oids Array Array of items with the list of oids you want to set. To add items to the list, you must call the function ‘snmp.addOid’ with the oid you want to set, the type of the value for that oid and the value you want to set as parameters as many times as you want oids.
comunity string The community octet sting. This is a convenience method to set the security name for community based SNMP (v1 and v2c).
securityName string The security name of the user (typically the user name).
authentication string The authentication protocol ID to be associated with this user. If set to null, this user only supports unauthenticated messages.
authPassphrase string The authentication passphrase. If not null, authentication must also be not null.
privacy string The privacy protocol ID to be associated with this user. If set to null, this user only supports unencrypted messages.
privPassphrase string The privacy passphrase. If not null, privacy must also be not null.
version number Version number of the SNMP. By default is 3.
retries number Number of retries for the request. By default is 3.
timeout number Timeout of the request in millis. By default is 5000.

Here is an example of use for the snmp.addOid function for snmp.set:

snmp.addOid('1.0.1.4.5.123456.1.6', 'INTEGER', '3');

The allowed values for type are: OBJECT_IDENTIFIER, INTEGER, BIT_STRING, OCTET_STRING, GAUGE32, COUNTER32, COUNTER64, TIMETICKS, OPAQUE and IPADDRESS.

Here is a successful response example:

{
  "result": {
    "code": "SUCCESSFUL",
    "description": "Operation executed successfully"
  },
  "data": {
    "oid":"value",
    "oid1":"value1",
    ....
    "oidN":"valueN"
  }
}

And here an error response example:

{
  "result": {
    "code": "ERROR_PROCESSING",
    "description": "Error getting data"
  },
  "data": {}
}