Search in sources :

Example 6 with SnmpV1TrapBuilder

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

the class EventdStresser method createBuilder.

public static SnmpTrapBuilder createBuilder() throws IllegalArgumentException {
    SnmpV1TrapBuilder builder = SnmpUtils.getV1TrapBuilder();
    builder.setAgentAddress(m_agentAddress);
    SnmpObjId enterpriseOid = SnmpObjId.get(".1.3.6.1.4.1.5813.1");
    builder.setEnterprise(enterpriseOid);
    builder.setTimeStamp(0);
    builder.setGeneric(6);
    builder.setSpecific(1);
    builder.setTimeStamp(1);
    // dbid
    SnmpObjId dbIdOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.1");
    SnmpValue dbIdValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("-1".getBytes());
    builder.addVarBind(dbIdOid, dbIdValue);
    // distPoller
    SnmpObjId distPollerOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.2");
    SnmpValue distPollerValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(distPollerOid, distPollerValue);
    // create-time
    SnmpObjId createTimeOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.3");
    Date createTime = Calendar.getInstance().getTime();
    String formattedTime = DateFormat.getDateTimeInstance().format(createTime);
    SnmpValue createTimeValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(formattedTime.getBytes());
    builder.addVarBind(createTimeOid, createTimeValue);
    // master-station
    SnmpObjId masterStationOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.4");
    SnmpValue masterStationValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_trapSink.getHostAddress().getBytes());
    builder.addVarBind(masterStationOid, masterStationValue);
    // uei
    SnmpObjId ueiOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.5");
    SnmpValue ueiValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("uei.opennms.org/test/EventdStressTest".getBytes());
    builder.addVarBind(ueiOid, ueiValue);
    // source,
    SnmpObjId sourceOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.6");
    SnmpValue sourceValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("EventdStresser".getBytes());
    builder.addVarBind(sourceOid, sourceValue);
    // nodeid,
    SnmpObjId nodeIdOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.7");
    SnmpValue nodeIdValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("1".getBytes());
    builder.addVarBind(nodeIdOid, nodeIdValue);
    // time,
    SnmpObjId timeOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.8");
    SnmpValue timeValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(formattedTime.getBytes());
    builder.addVarBind(timeOid, timeValue);
    // host,
    SnmpObjId hostOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.9");
    SnmpValue hostValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(hostOid, hostValue);
    // interface,
    SnmpObjId interfaceOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.10");
    SnmpValue interfaceValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(interfaceOid, interfaceValue);
    // snmphost,
    SnmpObjId snmpHostOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.11");
    SnmpValue snmpValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(snmpHostOid, snmpValue);
    // service,
    SnmpObjId serviceOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.12");
    SnmpValue serviceValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("SNMP".getBytes());
    builder.addVarBind(serviceOid, serviceValue);
    // descr,
    SnmpObjId descrOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.13");
    SnmpValue descrValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("Eventd Stressor Trap".getBytes());
    builder.addVarBind(descrOid, descrValue);
    // logmsg,
    SnmpObjId logMsgOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.14");
    SnmpValue logMsgValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("Eventd Stressor Trap".getBytes());
    builder.addVarBind(logMsgOid, logMsgValue);
    // severity,
    SnmpObjId severityOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.15");
    SnmpValue severityValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("4".getBytes());
    builder.addVarBind(severityOid, severityValue);
    // pathoutage,
    SnmpObjId pathOutageOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.16");
    SnmpValue pathOutageValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("NA".getBytes());
    builder.addVarBind(pathOutageOid, pathOutageValue);
    // operinst,
    SnmpObjId operInstOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.17");
    SnmpValue operInstValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("Ignore".getBytes());
    builder.addVarBind(operInstOid, operInstValue);
    // ifresolve,
    SnmpObjId ifResolveOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.18");
    SnmpValue ifResolveValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("NA".getBytes());
    builder.addVarBind(ifResolveOid, ifResolveValue);
    // nodelabel
    SnmpObjId nodeLabelOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.19");
    String nodeLabel;
    nodeLabel = m_agentAddress.getCanonicalHostName();
    SnmpValue nodeLabelValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(nodeLabel.getBytes());
    builder.addVarBind(nodeLabelOid, nodeLabelValue);
    return builder;
}
Also used : SnmpV1TrapBuilder(org.opennms.netmgt.snmp.SnmpV1TrapBuilder) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Date(java.util.Date)

Example 7 with SnmpV1TrapBuilder

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

the class SnmpTrapHelper method forwardV1Trap.

/**
     * Create an SNMP V1 trap based on the content of the specified trap configuration, and send it to the appropriate destination.
     * 
     * @param trapConfig The trap configuration mapping object
     * @throws SnmpTrapException if any.
     */
private void forwardV1Trap(SnmpTrapConfig trapConfig) throws SnmpTrapException {
    SnmpV1TrapBuilder trap = SnmpUtils.getV1TrapBuilder();
    trap.setEnterprise(SnmpObjId.get(trapConfig.getEnterpriseId()));
    trap.setAgentAddress(trapConfig.getHostAddress());
    if (trapConfig.hasGeneric()) {
        trap.setGeneric(trapConfig.getGeneric());
    }
    if (trapConfig.hasSpecific()) {
        trap.setSpecific(trapConfig.getSpecific());
    }
    trap.setTimeStamp(System.currentTimeMillis() / 1000);
    addParameters(trap, trapConfig);
    try {
        SnmpAgentConfig config = getAgentConfig(trapConfig);
        trap.send(config.getAddress().getHostAddress(), config.getPort(), config.getReadCommunity());
    } catch (Throwable e) {
        throw new SnmpTrapException("Failed to send trap " + e.getMessage(), e);
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpV1TrapBuilder(org.opennms.netmgt.snmp.SnmpV1TrapBuilder)

Example 8 with SnmpV1TrapBuilder

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

the class SnmpTrapNotificationStrategy method sendV1Trap.

/**
     * <p>sendV1Trap</p>
     *
     * @throws java.lang.Exception if any.
     */
public void sendV1Trap() throws Exception {
    SnmpV1TrapBuilder pdu = SnmpUtils.getV1TrapBuilder();
    pdu.setEnterprise(SnmpObjId.get(getEnterpriseId()));
    pdu.setGeneric(getGenericId());
    pdu.setSpecific(getSpecificId());
    pdu.setTimeStamp(0);
    InetAddress agentAddress = getHostInetAddress();
    pdu.setAgentAddress(agentAddress);
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.4.1.5813.20.1"), SnmpUtils.getValueFactory().getOctetString(getVarbind().getBytes()));
    pdu.send(InetAddressUtils.str(agentAddress), getPort(), getCommunity());
}
Also used : SnmpV1TrapBuilder(org.opennms.netmgt.snmp.SnmpV1TrapBuilder) InetAddress(java.net.InetAddress)

Aggregations

SnmpV1TrapBuilder (org.opennms.netmgt.snmp.SnmpV1TrapBuilder)8 InetAddress (java.net.InetAddress)3 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)2 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Test (org.junit.Test)1 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)1 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)1 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)1 Parm (org.opennms.netmgt.xml.event.Parm)1 Snmp (org.opennms.netmgt.xml.event.Snmp)1 Value (org.opennms.netmgt.xml.event.Value)1