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); }
private void sendRequest(BlockPdu pdu) { setButton.setEnabled(false); getButton.setEnabled(false); getNextButton.setEnabled(false); lmessage.setText("Sending request .."); lmessage.setBackground(Color.white); try { varbind var = pdu.getResponseVariableBinding(); AsnObjectId oid = var.getOid(); AsnObject res = var.getValue(); if (res != null) { toid.setText(oid.toString()); tvalue.setText(res.toString()); lmessage.setText("Received aswer "); lmessage.setBackground(Color.white); } else { lmessage.setText("Received no aswer "); lmessage.setBackground(Color.red); } } catch (PduException exc) { lmessage.setText("PduException: " + exc.getMessage()); lmessage.setBackground(Color.red); exc.printStackTrace(); } catch (java.io.IOException exc) { lmessage.setText("IOException: " + exc.getMessage()); lmessage.setBackground(Color.red); exc.printStackTrace(); } setButton.setEnabled(true); getButton.setEnabled(true); getNextButton.setEnabled(true); }
public void start() { if (context != null) { try { UpSincePdu up = new UpSincePdu(context, this); } catch (java.io.IOException exc) { System.out.println("start(): IOException " + exc.getMessage()); } catch (PduException exc) { System.out.println("start(): PduException " + exc.getMessage()); } } }
private void createContext(String host, int port, String comm, String socketType) { myFrame.setTitle("Set One - " + host); if (context != null) { context.destroy(); } try { context = new SnmpContextPool(host, port, socketType); context.setCommunity(comm); } catch (java.io.IOException exc) { lmessage.setText("IOException: " + exc.getMessage()); lmessage.setBackground(Color.red); } }
public void init() { String host = util.getHost(); h = new JLabel(host + " up since: "); v = new JLabel(" unknown "); setLayout(new GridLayout(2, 1)); add(h); add(v); try { context = new SnmpContext(host, port); } catch (java.io.IOException exc) { System.out.println("IOException " + exc.getMessage()); System.exit(0); } }
public void run() { // We might not get an error, since it is not sure if an // interface exists with this intfIndex as index! InterfacePdu up2; while (context != null) { try { up2 = new InterfacePdu(context, this, intfIndex); Thread.sleep(interval); } catch (InterruptedException exc) {; } catch (java.io.IOException exc) { System.out.println("run(): IOException " + exc.getMessage()); } catch (PduException exc) { System.out.println("run(): PduException " + exc.getMessage()); } } }
public void init() { // get the host name String host = util.getHost(); h = new JLabel("Host " + host + ", Interface " + intfIndex + " speed"); try { context = new SnmpContext(host, port); context.setCommunity(community); setLayout(new GridLayout(2, 1)); add(h); v = new JLabel(" unknown "); add(v); } catch (java.io.IOException exc) { System.out.println("IOException " + exc.getMessage()); System.exit(0); } }
private void createContext(String host, String portStr, String comm, String socketType) { int port = SnmpContextBasisFace.DEFAULT_PORT; try { port = Integer.valueOf(portStr).intValue(); } catch (NumberFormatException exc) { } if (context != null) { context.destroy(); // context.dumpContexts("destroy"); } try { context = new SnmpContextPool(host, port, socketType); context.setCommunity(comm); // context.dumpContexts("create:"); System.out.println(context); } catch (java.io.IOException exc) { exc.printStackTrace(); } }