Package ch.rakudave.jnetmap.model.device

Examples of ch.rakudave.jnetmap.model.device.Device


  @Override
  public void statusChanged(DeviceEvent e, Map m) {
    boolean match = filter.matches(e);
    Logger.debug("Attempting to create log-entry, filtered: " + !match);
    if (!match) return;
    Device d = e.getItem();
    StringBuffer sb = new StringBuffer();
    sb.append(new Date().toString()).append(" [");
    sb.append(m.getFileName()).append("] - ");
    if (Type.INTERFACE_STATUS_CHANGED.equals(e.getType())) {
      NetworkIF nif = (NetworkIF) e.getSubject();
      sb.append(nif.getName()).append(" ");
      sb.append(nif.getAddress()).append(": ");
      sb.append(nif.getStatus().getMessage());
      sb.append(" (").append(d.getName()).append(")");
    } else {
      sb.append(d.getName()).append(": ");
      sb.append(d.getStatus().getMessage());
    }
    if (writer != null) writer.println(sb.toString());
  }
View Full Code Here


  @Override
  public void statusChanged(DeviceEvent e, Map m) {
    boolean match = filter.matches(e);
    Logger.debug("Attempting to send ubuntu notification, filtered: " + !match);
    if (!match) return;
    Device d = e.getItem();
    String icon = new File(IO.userDir, "cisco/"+d.getType().toString().toLowerCase()+".png").getAbsolutePath();
    StringBuffer sb = new StringBuffer();
    if (Type.INTERFACE_STATUS_CHANGED.equals(e.getType())) {
      NetworkIF nif = (NetworkIF) e.getSubject();
      sb.append(nif.getName()).append(" ");
      sb.append(nif.getAddress()).append(": ");
      sb.append(nif.getStatus().getMessage());
      libnotify(new String[] {"notify-send", "-i", icon, sb.toString(), Lang.get("device")+": "+d.getName()});
    } else {
      for (Iterator<NetworkIF> it = d.getInterfaces().iterator(); it.hasNext();) {
        formatIF(sb, (NetworkIF) it.next());
        if (it.hasNext()) sb.append("\n");
      }
      libnotify(new String[] {"notify-send", "-i", icon, d.getName()+": "+d.getStatus().getMessage(), sb.toString()});
    }
  }
View Full Code Here

  public void addToMap(final java.util.Map<InetAddress, PingMethod> hosts, final Map map) {
    if (hosts == null || hosts.isEmpty() || map == null) return;
    // TODO devices are added at [0,0], find way to layout properly!
    Connection gToS = new Connection();
    Device gateway = null;
    Device aSwitch = null;
    NetworkIF gatewayIF = null;
    try { // try to find the gateway
      gatewayIF = tryFindIP(map, InetAddress.getByName(subnet.getInfo().getLowAddress()));
    } catch (UnknownHostException ex) {
      Logger.debug("Unable to find gateway-interface", ex);
    }
    if (gatewayIF == null) { // create a gateway if none was found
      gateway = new Host(Type.Router);
      gatewayIF = new PhysicalIF(gateway, gToS, subnet.getInfo().getLowAddress());
      map.addVertex(gateway);
      gateway.addInterface(gatewayIF);
    } else {
      gateway = gatewayIF.getDevice();
    }
    try { // try to find the switch attached to the gateway
      aSwitch = map.getOpposite(gateway, gatewayIF.getConnection());
      // if the opposite is not a switch, reset
      if (aSwitch != null && !aSwitch.getType().toString().toLowerCase().contains("switch")) aSwitch = null;
    } catch (Exception e) {
      Logger.debug("Unable to find opposite", e);
    }
    if (aSwitch == null) { // create a switch if necessary
      aSwitch = new Host(Type.Switch);
      map.addVertex(aSwitch);
      aSwitch.addInterface(new TransparentIF(aSwitch, gToS, gatewayIF));
      map.addEdge(gToS, gateway, aSwitch);
    }
    final Device gw = gateway, sw = aSwitch;
    final NetworkIF gif = gatewayIF;
    for (final InetAddress address : hosts.keySet()) {
      Scheduler.execute(new Runnable() {
        @Override
        public void run() {
          try {
            if (!address.equals(gif.getAddress())) {
              if (tryFindIP(map, address) != null) return;
              Logger.debug("Adding Interface "+address);
              Connection c = new Connection();
              Device d = new Host();
                d.setName(address.getHostName());
                PhysicalIF pif = new PhysicalIF(d, c, address.getHostAddress());
                  pif.setPingMethod(hosts.get(address));
                  pif.setSubnet(subnet.getInfo().getNetmask());
                  pif.setGateway(subnet.getInfo().getLowAddress());
                d.addInterface(pif);
                SNMP.inferProperties(d);
              sw.addInterface(new TransparentIF(sw, c, pif));
              map.addVertex(d);
              map.addEdge(c, d, sw);
            } else {
View Full Code Here

        Graph<Device, Connection> graph = vv.getModel()
            .getGraphLayout().getGraph();
        // set default edge type
        edgeIsDirected = EdgeType.UNDIRECTED;

        final Device vertex = pickSupport.getVertex(vv.getModel()
            .getGraphLayout(), p.getX(), p.getY());
        if (vertex != null) { // get ready to make an edge
          startVertex = vertex;
          down = e.getPoint();
          transformEdgeShape(down, down);
          vv.addPostRenderPaintable(edgePaintable);
        } else { // make a new vertex
          Device newVertex = vertexFactory.create();
          Layout<Device, Connection> layout = vv.getModel()
              .getGraphLayout();
          graph.addVertex(newVertex);
          layout.setLocation(newVertex, vv.getRenderContext()
              .getMultiLayerTransformer().inverseTransform(
View Full Code Here

      final Point2D p = e.getPoint();
      Layout<Device, Connection> layout = vv.getModel().getGraphLayout();
      GraphElementAccessor<Device, Connection> pickSupport = vv
          .getPickSupport();
      if (pickSupport != null) {
        final Device vertex = pickSupport.getVertex(layout, p.getX(), p.getY());
        if (vertex != null && startVertex != null) {
          Graph<Device, Connection> graph = vv.getGraphLayout().getGraph();
          Connection newEdge = edgeFactory.create();
          graph.addEdge(newEdge, startVertex, vertex,  edgeIsDirected);
          if (startVertex.equals(vertex)) {
            new InterfaceProperties(owner, vertex.getInterfaceFor(newEdge));
          } else {
            new ConnectionProperties(owner, newEdge);
          }
          vv.repaint();
        }
View Full Code Here

          }
        });
      } else {
        popup.add(new AbstractAction(Lang.get("action.add"), Icons.get("add")) {
          public void actionPerformed(ActionEvent e) {
            Device newVertex = vertexFactory.create();
            new DeviceProperties(owner, newVertex, true);
            graph.addVertex(newVertex);
            layout.setLocation(newVertex, vv.getRenderContext()
              .getMultiLayerTransformer().inverseTransform(p));
            vv.repaint();
View Full Code Here

    this.onIFChange = onIFChange;
  }
 
  public boolean matches(DeviceEvent e) {
    if (!onDeviceChange && !onIFChange) return false;
    Device d = (Device) e.getSource();
    if (!deviceNameMatcher.isEmpty() && !d.getName().matches(deviceNameMatcher)) return false;
    if (statusMatcher == null) statusMatcher = "";
    if (onDeviceChange && Type.STATUS_CHANGED.equals(e.getType())) {
      for (NetworkIF nif : d.getInterfaces()) {
        if (!statusMatcher.isEmpty() && !d.getStatus().getMessage().matches(statusMatcher)) return false;
        if (!ipMatcher.isEmpty() && nif.getAddress() != null
            && !nif.getAddress().getHostAddress().matches(ipMatcher)) return false;
        if (!subnetMatcher.isEmpty() && nif.getSubnet() != null
            && !nif.getSubnet().getInfo().getBroadcastAddress().matches(ipMatcher))  return false;
      }
View Full Code Here

      public Object undo() {
        boolean b = graph.addVertex(arg0);
        for (Pair<Device> p : connectors.keySet()) {
          Connection c = connectors.get(p);
          graph.addEdge(c, p);
          Device other = (p.getFirst().equals(arg0))?p.getSecond():p.getFirst();
          other.addInterface(oppositeIFs.get(c));
        }
        notifyListeners(new MapEvent(_this, Type.VERTEX_ADDED, arg0));
        arg0.addDeviceListener(_this);
        return b;
      }
     
      @Override
      public Object redo() {
        for (Connection c : graph.getOutEdges(arg0)) {
          Pair<Device> pair = graph.getEndpoints(c);
          connectors.put(pair, c);
          Device other = (pair.getFirst().equals(arg0))?pair.getSecond():pair.getFirst();
          NetworkIF nif = other.getInterfaceFor(c);
          oppositeIFs.put(c, nif);
          other.removeInterface(nif);
        }
        boolean b = graph.removeVertex(arg0);
        notifyListeners(new MapEvent(_this, Type.VERTEX_REMOVED, arg0));
        arg0.removeDeviceListener(_this);
        return b;
View Full Code Here

 
  private String fillArgs(String arguments, DeviceEvent e, Map m) {
    String args = arguments.replaceAll("%e", e.getType().toString());
    args = args.replaceAll("%mn", m.getFileName());
    args = args.replaceAll("%mp", m.getFilePath());
    Device d;
    if (Type.STATUS_CHANGED.equals(e.getType())) {
      d = (Device) e.getSource();
    } else {
      PhysicalIF nif = (PhysicalIF) e.getSubject();
      d = nif.getDevice();
      args = args.replaceAll("%is", nif.getStatus().toString());
      args = args.replaceAll("%in", nif.getName());
      args = args.replaceAll("%ia", nif.getAddress().getHostAddress());
      args = args.replaceAll("%iu", nif.getSubnet().getInfo().getBroadcastAddress());
      args = args.replaceAll("%ig", nif.getGateway().getHostAddress());
      args = args.replaceAll("%im", nif.getMacAddress());
    }
    args = args.replaceAll("%ds", d.getStatus().toString());
    args = args.replaceAll("%dn", d.getName());
    args = args.replaceAll("%dl", d.getLocation());
    args = args.replaceAll("%di", new File(IO.userDir, "cisco/"+d.getType().toString().toLowerCase()+".png").getAbsolutePath());
    return args;
  }
View Full Code Here

      StringBuffer sb = new StringBuffer();
        if (Type.INTERFACE_STATUS_CHANGED.equals(e.getType())) {
          formatIF(sb, (NetworkIF) e.getSubject());
          sb.append("\n").append(Lang.getNoHTML("details")).append(":\n");
        }
        Device d = (Device) e.getSource();
        sb.append(Lang.getNoHTML("device"));
        sb.append(" \"").append(d.getName()).append("\"").append(": ");
        sb.append(d.getStatus().getMessage()).append("\n");
        for (NetworkIF nif : d.getInterfaces()) {
          sb.append("\t");
          formatIF(sb, nif);
        }
      message.setContent(sb.toString(), "text/plain");
      Transport.send(message);
View Full Code Here

TOP

Related Classes of ch.rakudave.jnetmap.model.device.Device

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.