Snmp object initialization with error check from a device ID (JScript)
- Last Updated: February 20, 2023
- 1 minute read
The SnmpRqst.Initialize method returns a ComResult object that tells if the initialization succeeded or failed.
This script uses the Failed method to detect an error and logs an error message using GetErrorMsg if the initialization failed:
var oSnmpRqst = new ActiveXObject("CoreAsp.SnmpRqst");var nDeviceID = 150;var oComResult = oSnmpRqst.Initialize(nDeviceID);if (oComResult.Failed){ Context.LogMessage(oComResult.GetErrorMsg);}
Alternatively, initialization using a device address and an SNMP credential ID:
var oSnmpRqst = new ActiveXObject("CoreAsp.SnmpRqst");var sAddress = "192.168.3.1";var nCredentialID = 1;var oComResult = oSnmpRqst.Initialize2(sAddress, nCredentialID);if (oComResult.Failed){ Context.LogMessage(oComResult.GetErrorMsg);}