1 2 23 24 package net.fenyo.gnetwatch.targets; 25 26 import net.fenyo.gnetwatch.*; 27 import net.fenyo.gnetwatch.GUI.GUI; 28 import net.fenyo.gnetwatch.GUI.VisualElement; 29 import net.fenyo.gnetwatch.actions.*; 30 import net.fenyo.gnetwatch.data.EventReachable; 31 32 import org.apache.commons.logging.Log; 33 import org.apache.commons.logging.LogFactory; 34 import org.snmp4j.event.ResponseEvent; 35 36 import java.net.*; 37 38 43 44 public class TargetIPv6 extends Target { 45 private static Log log = LogFactory.getLog(TargetIPv4.class); 46 47 private Inet6Address address; private SNMPQuerier snmp_querier; 49 private IPQuerier ip_querier; 50 51 58 public TargetIPv6(final String name, final Inet6Address address, final SNMPManager snmp_manager) throws AlgorithmException { 60 super(name); 61 if (address == null) throw new AlgorithmException("name is null"); 62 this.address = address; 63 snmp_querier = snmp_manager != null ? snmp_manager.getQuerier(address) : null; 64 setItem(address.getHostAddress()); 65 ip_querier = new IPQuerier(address); 66 } 69 70 75 public void checkSNMPAwareness() { 76 snmp_querier.getSysDescr(new SNMPQuerier.QuerierListener() { 77 public void onResponse(ResponseEvent event) { 78 getGUI().setStatus(getGUI().getConfig().getPattern("discovered_snmp", getAddress().toString().substring(1))); 79 setImageHostSNMP(); 80 } 81 82 public void onTimeout(ResponseEvent event) { 83 getGUI().setStatus(getGUI().getConfig().getPattern("snmp_timeout", getAddress().toString().substring(1))); 84 } 85 }); 86 } 87 88 93 public SNMPQuerier getSNMPQuerier() { 94 return snmp_querier; 95 } 96 97 102 public IPQuerier getIPQuerier() { 103 return ip_querier; 104 } 105 106 111 public Inet6Address getAddress() { 113 return address; 114 } 115 116 121 public boolean canManageThisChild(final VisualElement visual_element) { 122 if (ActionPing.class.isInstance(visual_element)) return true; 123 if (ActionFlood.class.isInstance(visual_element)) return true; 124 if (ActionSNMP.class.isInstance(visual_element)) return true; 125 if (EventReachable.class.isInstance(visual_element)) return true; 126 if (TargetInterface.class.isInstance(visual_element)) return true; 127 if (ActionHTTP.class.isInstance(visual_element)) return true; 128 if (ActionNmap.class.isInstance(visual_element)) return true; 129 return false; 130 } 131 132 137 protected final void initialize(final GUI gui) { 139 super.initialize(gui); 140 if (gui != null) setImageHost6(); 141 } 142 143 149 public boolean addTarget(final GUI gui, final VisualElement parent) { 150 initialize(gui); 151 152 if (!canAddTarget(parent)) return false; 153 if (parent != null && !parent.canManageThisChild(this)) return false; 154 155 final boolean is_new = !getGUI().containsCanonicalInstance(this); 156 final TargetIPv6 target_ipv6 = (TargetIPv6) getGUI().getCanonicalInstance(this); 157 158 if (!getGUI().getVisualTransientAll().contains(target_ipv6)) target_ipv6.setParent(getGUI(), getGUI().getVisualTransientAll()); 159 160 if (parent != null) target_ipv6.setParent(getGUI(), parent); 161 162 return is_new; 163 } 164 165 171 public static void addTargetIPv6(final GUI gui, final String addr_str) { 172 try { 173 synchronized (gui.sync_tree) { 174 final TargetIPv6 foo = new TargetIPv6(addr_str, (Inet6Address) InetAddress.getByName(addr_str), gui.getSNMPManager()); 175 if (gui.containsCanonicalInstance(foo)) return; 176 gui.asyncExecIfNeeded(new Runnable () { 177 public void run() { 178 synchronized (gui.sync_tree) { 179 if (gui.containsCanonicalInstance(foo)) return; 180 if (foo.addTarget(gui, (VisualElement) null) == true) foo.checkSNMPAwareness(); 181 } 182 } 183 }); 184 } 185 } catch (final AlgorithmException ex) { 186 log.error("Exception", ex); 187 } catch (final UnknownHostException ex) { 188 log.error("Exception", ex); 189 } 190 } 191 192 197 public boolean equals(final Object o) { 199 if (this == o) return true; 200 if ((o == null) || (o.getClass() != getClass())) return false; 201 final TargetIPv6 target = (TargetIPv6) o; 202 return getAddress().equals(target.getAddress()); 203 } 204 205 210 public int hashCode() { 212 return getAddress().hashCode(); 213 } 214 } 215 | Popular Tags |