use of org.snmp4j.smi.VariableBinding in project opennms by OpenNMS.
the class MockProxy method processGetNext.
/**
* @param request
* @return
*/
private PDU processGetNext(PDU request) {
PDU response = request;
response.setErrorIndex(0);
response.setErrorStatus(0);
response.setType(PDU.RESPONSE);
Vector<? extends VariableBinding> varBinds = response.getVariableBindings();
for (int i = 0; i < varBinds.size(); i++) {
VariableBinding varBind = varBinds.get(i);
VariableBinding nextVarBind = m_agent.getNext(varBind.getOid());
if (nextVarBind == null) {
if (response instanceof PDUv1) {
if (response.getErrorIndex() == 0) {
response.setErrorIndex(i + 1);
response.setErrorStatus(PDU.noSuchName);
}
} else {
varBind.setVariable(Null.endOfMibView);
}
} else {
response.set(i, nextVarBind);
}
}
return response;
}
use of org.snmp4j.smi.VariableBinding in project LogHub by fbacchella.
the class SnmpTrap method processPdu.
@Override
public void processPdu(CommandResponderEvent trap) {
try {
PDU pdu = trap.getPDU();
Address localaddr = trap.getTransportMapping().getListenAddress();
Address remoteaddr = trap.getPeerAddress();
ConnectionContext ctx = ConnectionContext.EMPTY;
if (localaddr instanceof TransportIpAddress && remoteaddr instanceof TransportIpAddress) {
InetSocketAddress localinetaddr = getSA((TransportIpAddress) localaddr);
InetSocketAddress remoteinetaddr = getSA((TransportIpAddress) remoteaddr);
ctx = new IpConnectionContext(localinetaddr, remoteinetaddr, null);
}
Event event = emptyEvent(ctx);
if (pdu instanceof PDUv1) {
PDUv1 pduv1 = (PDUv1) pdu;
String enterprise = (String) convertVar(pduv1.getEnterprise());
event.put("enterprise", enterprise);
event.put("agent_addr", pduv1.getAgentAddress().getInetAddress());
if (pduv1.getGenericTrap() != PDUv1.ENTERPRISE_SPECIFIC) {
event.put("generic_trap", GENERICTRAP.values()[pduv1.getGenericTrap()].toString());
} else {
String resolved = formatter.format(pduv1.getEnterprise(), new Integer32(pduv1.getSpecificTrap()), true);
event.put("specific_trap", resolved);
}
event.put("time_stamp", 1.0 * pduv1.getTimestamp() / 100.0);
}
@SuppressWarnings("unchecked") Enumeration<VariableBinding> vbenum = (Enumeration<VariableBinding>) pdu.getVariableBindings().elements();
for (VariableBinding i : Collections.list(vbenum)) {
OID vbOID = i.getOid();
Object value = convertVar(i.getVariable());
smartPut(event, vbOID, value);
}
send(event);
} catch (Exception e) {
logger.error(e.getMessage());
logger.catching(e);
} finally {
trap.setProcessed(true);
}
}
use of org.snmp4j.smi.VariableBinding in project LogHub by fbacchella.
the class SNMPTrapGeneratorClient2 method createPdu.
private static PDU createPdu(int snmpVersion) {
PDU pdu = DefaultPDUFactory.createPDU(snmpVersion);
if (snmpVersion == SnmpConstants.version1) {
pdu.setType(PDU.V1TRAP);
} else {
pdu.setType(PDU.TRAP);
}
pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(1000)));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(trapOid)));
pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress(ipAddress)));
pdu.add(new VariableBinding(new OID(trapOid), new OctetString("Major")));
return pdu;
}
use of org.snmp4j.smi.VariableBinding in project LogHub by fbacchella.
the class TestTrap method testtrapv1Generic.
@Ignore
@Test
public void testtrapv1Generic() throws InterruptedException, IOException {
BlockingQueue<Event> receiver = new ArrayBlockingQueue<>(2);
SnmpTrap r = new SnmpTrap(receiver, new Pipeline(Collections.emptyList(), "testbig", null));
r.setPort(0);
Map<String, Object> props = new HashMap<>();
props.put("mibdirs", new String[] { "/usr/share/snmp/mibs", "/tmp/mibs" });
Assert.assertTrue(r.configure(new Properties(props)));
r.start();
CommandResponderEvent trapEvent = new CommandResponderEvent(new MessageDispatcherImpl(), new DefaultUdpTransportMapping(), TransportIpAddress.parse("127.0.0.1/162"), 0, 0, null, 0, null, null, 0, null);
PDUv1 pdu = new PDUv1();
pdu.setEnterprise(new OID("1.3.6.1.4.1.232"));
pdu.setAgentAddress(new IpAddress());
pdu.setGenericTrap(1);
pdu.setTimestamp(10);
pdu.add(new VariableBinding(new OID("1.3.6.1.6.3.1.1.4.1"), new OctetString("lldpRemTablesChange")));
trapEvent.setPDU(pdu);
r.processPdu(trapEvent);
Event e = receiver.poll();
Assert.assertEquals(0.1, (Double) e.get("time_stamp"), 1e-10);
Assert.assertEquals("warmStart", e.get("generic_trap"));
Assert.assertEquals("compaq", e.get("enterprise"));
Assert.assertEquals(null, e.get("specific_trap"));
Assert.assertEquals("lldpRemTablesChange", e.get("snmpTrapOID"));
Assert.assertEquals(InetAddress.getByName("0.0.0.0"), e.get("agent_addr"));
r.interrupt();
}
use of org.snmp4j.smi.VariableBinding in project ovirt-engine by oVirt.
the class Snmp method addPayload.
private void addPayload(PDU pdu, AuditLogEvent event, Profile profile) {
pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks((System.nanoTime() - nanoStart) / 10000000)));
// { [baseoid] notifications(0) audit(1) }
pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, SnmpConstants.getTrapOID(new OID(profile.oid), ENTERPRISE_SPECIFIC, AUDIT)));
int auditLogId = AuditLogType.UNASSIGNED.getValue();
try {
auditLogId = AuditLogType.valueOf(event.getName()).getValue();
} catch (IllegalArgumentException e) {
log.warn("Could not find event: {} in auditLogTypes", event.getName());
}
// { [baseoid] objects(2) audit(1) }
OID auditObjects = new OID(profile.oid).append(OBJECTS_AUDIT);
addString(pdu, auditObjects, INSTANCE_ID, Long.toString(event.getId()), true);
addString(pdu, auditObjects, NAME, event.getName(), true);
addInt(pdu, auditObjects, ID, auditLogId, true);
addInt(pdu, auditObjects, SEVERITY, event.getSeverity().getValue(), true);
addString(pdu, auditObjects, MESSAGE, event.getMessage(), true);
addInt(pdu, auditObjects, STATUS, event.getType().getValue(), true);
addString(pdu, auditObjects, DATETIME, new SimpleDateFormat(ISO8601).format(event.getLogTime()), true);
// Optional pdu:
addString(pdu, auditObjects, USERNAME, event.getUserName(), false);
addUuid(pdu, auditObjects, USER_ID, event.getUserId());
addString(pdu, auditObjects, VM_NAME, event.getVmName(), false);
addUuid(pdu, auditObjects, VM_ID, event.getVmId());
addString(pdu, auditObjects, VDS_NAME, event.getVdsName(), false);
addUuid(pdu, auditObjects, VDS_ID, event.getVdsId());
addString(pdu, auditObjects, VM_TEMPLATE_NAME, event.getVmTemplateName(), false);
addUuid(pdu, auditObjects, VM_TEMPLATE_ID, event.getVmTemplateId());
addString(pdu, auditObjects, STORAGE_POOL_NAME, event.getStoragePoolName(), false);
addUuid(pdu, auditObjects, STORAGE_POOL_ID, event.getStoragePoolId());
addString(pdu, auditObjects, STORAGE_DOMAIN_NAME, event.getStorageDomainName(), false);
addUuid(pdu, auditObjects, STORAGE_DOMAIN_ID, event.getStorageDomainId());
}
Aggregations