Esempio n. 1
0
  public void init() {
    String host = util.getHost();
    String bindAddr = util.getBindAddress();
    int port = util.getPort(ListeningContextFace.DEFAULT_TRAP_PORT);
    String socketType = util.getSocketType();
    // String oid = util.getOid();
    String community = util.getCommunity();

    try {
      context = new SnmpContextv2c(host, port, bindAddr, socketType);
      context.setCommunity(community);

      pdu = new TrapPduv2(context);
      pdu.addOid(sysUpTime, new AsnUnsInteger(5));
      pdu.addOid(snmpTrapOID, new AsnObjectId(warmStart));

      System.out.println(pdu.toString());
      pdu.send();

      // when calling destroy, the pdu might not be sent
      // context.destroy();
    } catch (java.io.IOException exc) {
      System.out.println("IOException " + exc.getMessage());
    } catch (uk.co.westhawk.snmp.stack.PduException exc) {
      System.out.println("PduException " + exc.getMessage());
    }
    // System.exit(0);
  }