如何在发送snmp陷阱之前检查会话是否已创建?

时间:2016-07-01 15:43:30

标签: javascript dns net-snmp

我发送陷阱消息到特定主机OID之前我可以确定会话是否成功创建,以便我可以发送陷阱消息。

main.js

var snmp = require("net-snmp");
var msg = require('./event.js');
var dns = require('dns');
var os = require('os');

function process (msg) {
   var host = msg.event.body.snmp.trapHost;
    //Create snmp Session
    var session = snmp.createSession(host,"public",sessionOptions);
    var options = {upTime: 1000};

    try {
        dns.lookup (os.hostname (), function (error, host) {
            if (error) {
                console.error(error);
            } else {
                session.trap(trapOid, varbinds, options, function (error) {
                    if (error)
                        console.log(error);
                    else
                        console.log('SNMP successfully delivered');
                });
            }
        });
    } catch (e) {
        console.log("SNMP processing error: " + e);
    }
};

process(msg);

0 个答案:

没有答案