[a]基於nodejs的最小snmp agent

假設咱們建立一個agent,當客戶端使用oid=1來查詢時,會返回一個終極人生宇宙和任何事的答案42,那麼代碼就這樣寫:node

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工具集來查詢:ide

# snmpget -v2c -cpublic 127.0.0.1 .1.0
複製代碼

返回結果:工具

iso.3.6.1 = STRING: "42"
複製代碼

或者修改它:ui

$snmpset -v2c -cpublic 127.0.0.1 .1.0 s "43"複製代碼
相關文章
相關標籤/搜索