[a]基于nodejs的最小snmp agent

假设我们创建一个agent,当客户端使用oid=1来查询时,会返回一个终极人生宇宙和任何事的答案42,那么代码就这样写:

var key = "Answer to the Ultimate Question of Life, the Universe, and Everything"

var snmp = require ("node-net-snmp");

var agent = snmp.createAgent({});

var authorizer = agent.getAuthorizer ();

authorizer.addCommunity ("public");

var scalarProvider = {

name: key,

type: snmp.MibProviderType.Scalar,

oid: "1",

scalarType: snmp.ObjectType.OctetString

};

agent.registerProvider (scalarProvider);

var mib = agent.getMib ();

mib.setScalarValue (key, "43");

客户端使用net-snmp工具集来查询:

# snmpget -v2c -cpublic 127.0.0.1 .1.0

返回结果:

iso.3.6.1 = STRING: "42"

或者修改它:

$snmpset -v2c -cpublic 127.0.0.1 .1.0 s "43" 

以上是 [a]基于nodejs的最小snmp agent 的全部内容, 来源链接: www.h5w3.com/29355.html

回到顶部