コード例 #1
0
ファイル: SendTrap.java プロジェクト: bartoszm/snmp123
  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);
  }
コード例 #2
0
  private void createPropertyDialog() {
    propDialog = new propertyDialog(null);

    String host = util.getHost();
    String port = "" + util.getPort(SnmpContextBasisFace.DEFAULT_PORT);
    String socketType = util.getSocketType();
    String comm = util.getCommunity();

    if (host != null) {
      propDialog.setHost(host);
    }
    if (port != null) {
      propDialog.setPort(port);
    }
    if (comm != null) {
      propDialog.setCommunityName(comm);
    }
    if (socketType != null) {
      propDialog.setSocketType(socketType);
    }
    propDialog.addActionListener(this);
    propDialog.pack();
  }