我正在将Shell脚本移植到snmp4j。我没有运气使用snmp send或TableUtils.createRow将行插入表中。脚本中的snmp命令类似于
snmpset -t 60 192.168.60.112 cwNetStgSvrRAIDDevs.1 x '01 02 03 04 05 06' cwNetStgSvrRAIDChunkSize.1 i 4096 cwNetStgSvrRAIDDataOffset.1 i 2097152 cwNetStgSvrRAIDRowStatus.1 i createAndGo
我尝试使用以下代码通过具有多个变量绑定的PDU设置值。我收到错误代码17不可写。我不清楚这是指表(行)还是行中的列。
public void setupRaidTable2() {
try {
PDU pdu = new ScopedPDU();
pdu.add(new VariableBinding(new OID(RAID_DEVS + ".1"),
OctetString.fromString("01 02 03 04 05 06", ' ', 16)));
pdu.add(new VariableBinding(new OID(RAID_CHUNK_SIZE + ".1"), new Integer32(4096)));
pdu.add(new VariableBinding(new OID(RAID_DATA_OFFSET + ".1"), new Integer32(2097152)));
pdu.add(new VariableBinding(new OID(RAID_ROW_STATUS + ".1"), new Integer32(4)));
pdu.setType(PDU.SET);
ResponseEvent event = snmp.send(pdu, userTarget);
if (event != null) {
pdu = event.getResponse();
if (pdu.getErrorStatus() == PDU.noError && pdu.getType() != PDU.REPORT) {
LOG.debug("SNMPv3 SET Successful for RaidPartTable ");
} else {
LOG.debug("SNMPv3 SET Unsuccessfulfor RaidTable: Error Code " + pdu.getErrorStatus() + " "
+ pdu.getErrorStatusText());
}
} else {
LOG.debug("SNMP send unsuccessful RAID Table");
}
} catch (Exception e) {
throw new RuntimeException("Error setting up raid table ", e);
}
}
我也尝试过使用TableUtils.createRow并得到错误11无法创建对象。我已经尝试过,无论是否有行状态的变量绑定。
public void setupRaidTable() {
try {
DefaultPDUFactory pduFactory = new DefaultPDUFactory(PDU.SET);
pduFactory.setContextEngineID(engineIdStr);
TableUtils tUtils = new TableUtils(snmp, pduFactory);
VariableBinding[] vbs = {
new VariableBinding(new OID(RAID_DEVS + ".1"),
OctetString.fromString("01 02 03 04 05 06", ' ', 16)),
new VariableBinding(new OID(RAID_CHUNK_SIZE + ".1"), new Integer32(4096)),
new VariableBinding(new OID(RAID_DATA_OFFSET + ".1"), new Integer32(2097152)),
new VariableBinding(new OID(RAID_ROW_STATUS + ".1"), new Integer32(4))
};
ResponseEvent event = tUtils.createRow(userTarget, new OID(RAID_ROW_STATUS + ".1"),
new OID(".1.3.6.1.4.1.27675.20.5.5.1.1.1"), vbs);
if (event != null) {
PDU pdu = event.getResponse();
if (pdu.getErrorStatus() == PDU.noError && pdu.getType() != PDU.REPORT) {
LOG.debug("SNMPv3 SET Successful for RaidPartTable ");
} else {
LOG.debug("SNMPv3 SET Unsuccessfulfor RaidPartTable: Error Code " + pdu.getErrorStatus() + " "
+ pdu.getErrorStatusText());
}
} else {
LOG.debug("SNMP send unsuccessful RAID Part Table");
}
} catch (Exception e) {
throw new RuntimeException("Error setting up raid table ", e);
}
我已经使用MibBrowser仔细检查了用于OIDS的所有常量。我不知所措,下一步该做什么。第一个问题是哪种方法是插入表的正确方法,第二个问题是我在实现过程中做错了什么。