Search in sources :

Example 31 with SnmpInstId

use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.

the class SnmpTrapNotificationStrategy method sendV2Trap.

/**
 * <p>sendV2Trap</p>
 *
 * @throws java.lang.Exception if any.
 */
public void sendV2Trap() throws Exception {
    SnmpObjId enterpriseId = SnmpObjId.get(getEnterpriseId());
    boolean isGeneric = false;
    SnmpObjId trapOID;
    if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
        isGeneric = true;
        trapOID = enterpriseId;
    } else {
        trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(getSpecificId()));
    // XXX or should it be this
    // trap OID = enterprise + ".0." + specific;
    }
    SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
    if (isGeneric) {
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    }
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.4.1.5813.20.1"), SnmpUtils.getValueFactory().getOctetString(getVarbind().getBytes()));
    pdu.send(InetAddressUtils.str(getHostInetAddress()), getPort(), getCommunity());
}
Also used : SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 32 with SnmpInstId

use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.

the class InstanceStrategy method getInstanceFromPhysAddr.

public static SnmpInstId getInstanceFromPhysAddr(String physAddr) {
    String[] elm;
    elm = physAddr.split(":");
    if (elm.length != 6) {
        return null;
    }
    final StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 6; i++) {
        sb.append(".");
        sb.append(Integer.parseInt(elm[i], 16));
    }
    return new SnmpInstId(sb.toString());
}
Also used : SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) OnmsAccessPoint(org.opennms.netmgt.model.OnmsAccessPoint)

Example 33 with SnmpInstId

use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.

the class CollectionResourceWrapperIT method testGenericResource.

@Test
public void testGenericResource() throws Exception {
    SnmpCollectionAgent agent = createCollectionAgent();
    MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
    OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
    ResourceType rt = new ResourceType();
    rt.setName("hrStorageIndex");
    rt.setLabel("host-resources storage");
    StorageStrategy strategy = new StorageStrategy();
    strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
    strategy.addParameter(new Parameter("sibling-column-name", "hrStorageLabel"));
    strategy.addParameter(new Parameter("replace-all", "s/^-//"));
    rt.setStorageStrategy(strategy);
    PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
    pstrategy.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
    rt.setPersistenceSelectorStrategy(pstrategy);
    GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, collection, rt);
    SnmpCollectionResource resource = new GenericIndexResource(resourceType, resourceType.getName(), new SnmpInstId(100));
    SnmpAttribute used = addAttributeToCollectionResource(resource, "hrStorageUsed", AttributeType.GAUGE, "hrStorageIndex", "5000");
    SnmpAttribute label = addAttributeToCollectionResource(resource, "hrStorageLabel", AttributeType.STRING, "hrStorageIndex", "/opt");
    Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
    attributes.put(used.getName(), used);
    attributes.put(label.getName(), label);
    CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
    Assert.assertEquals("opt", wrapper.getInstanceLabel());
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) Parameter(org.opennms.netmgt.config.datacollection.Parameter) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 34 with SnmpInstId

use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.

the class TrapHandlerITCase method sendV2Trap.

public void sendV2Trap(String enterprise, int specific, LinkedHashMap<String, SnmpValue> varbinds) throws Exception {
    SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
    boolean isGeneric = false;
    SnmpObjId trapOID;
    if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
        isGeneric = true;
        trapOID = enterpriseId;
    } else {
        trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(specific));
    // XXX or should it be this
    // trap OID = enterprise + ".0." + specific;
    }
    SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
    if (isGeneric) {
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    }
    for (Map.Entry<String, SnmpValue> entry : varbinds.entrySet()) {
        pdu.addVarBind(SnmpObjId.get(entry.getKey()), entry.getValue());
    }
    pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 35 with SnmpInstId

use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.

the class TrapHandlerITCase method sendV2Trap.

public void sendV2Trap(String enterprise, int specific) throws Exception {
    SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
    boolean isGeneric = false;
    SnmpObjId trapOID;
    if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
        isGeneric = true;
        trapOID = enterpriseId;
    } else {
        trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(specific));
    // XXX or should it be this
    // trap OID = enterprise + ".0." + specific;
    }
    SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
    if (isGeneric) {
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    }
    pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
Also used : SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Aggregations

SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)42 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)23 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)20 InetAddress (java.net.InetAddress)16 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)16 Map (java.util.Map)12 Test (org.junit.Test)11 PollStatus (org.opennms.netmgt.poller.PollStatus)10 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)9 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)7 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)6 SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)6 GenericIndexResource (org.opennms.netmgt.collectd.GenericIndexResource)5 GenericIndexResourceType (org.opennms.netmgt.collectd.GenericIndexResourceType)5 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)5 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)5 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)5