@Test public void testUnavailable() throws Exception { NetScalerGroupHealthMonitor monitor = new NetScalerGroupHealthMonitor(); Map<String, Object> parameters = createBasicParams(); parameters.put("group-health", 70); PollStatus status = monitor.poll(createMonitor(), parameters); Assert.assertFalse(status.isAvailable()); }
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { NetworkInterface<InetAddress> iface = svc.getNetInterface(); InetAddress ipaddr = (InetAddress) iface.getAddress(); SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr); if (agentConfig == null) throw new RuntimeException("SnmpAgentConfig object not available for interface " + ipaddr); final String hostAddress = InetAddressUtils.str(ipaddr); PollStatus status = PollStatus.unavailable("NetScalerGroupHealthMonitor: cannot determinate group health, addr=" + hostAddress); int groupHealth = ParameterMap.getKeyedInteger(parameters, "group-health", 60); String groupName = ParameterMap.getKeyedString(parameters, "group-name", null); if (groupName == null) { status.setReason("NetScalerGroupHealthMonitor no group-name defined, addr=" + hostAddress); log().warn("NetScalerGroupHealthMonitor.poll: No Service Name Defined! "); return status; } int snLength = groupName.length(); StringBuffer serviceOidBuf = new StringBuffer(SVC_GRP_MEMBER_STATE); serviceOidBuf.append(".").append(Integer.toString(snLength)); for (byte thisByte : groupName.getBytes()) { serviceOidBuf.append(".").append(Byte.toString(thisByte)); } log().debug("For group name '" + groupName +"', OID to check is " + serviceOidBuf.toString()); try { final SnmpObjId groupStateOid = SnmpObjId.get(serviceOidBuf.toString()); final Map<SnmpInstId, SnmpValue> hostResults = new HashMap<SnmpInstId, SnmpValue>(); RowCallback callback = new RowCallback() { @Override public void rowCompleted(SnmpRowResult result) { hostResults.put(result.getInstance(), result.getValue(groupStateOid)); } }; TableTracker tracker = new TableTracker(callback, groupStateOid); SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "NetScalerGroupHealthMonitor", tracker); walker.start(); walker.waitFor(); int totalServers = hostResults.size(); if (totalServers == 0) { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are 0 servers on group " + groupName + " for " + hostAddress); } int activeServers = 0; for (SnmpValue v : hostResults.values()) { if (v.toInt() == 7) { activeServers++; } } double health = (new Double(activeServers)/new Double(totalServers)) * new Double(100); log().debug("There are " + activeServers + " of " + totalServers + " active servers (" + health + "%) on group " + groupName + " for NetScaler " + hostAddress); if (health >= groupHealth) { status = PollStatus.available(); } else { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are " + activeServers + " of " + totalServers + " servers active (" + health + "%) on group " + groupName + ", which is less than " + groupHealth + "% for " + hostAddress); } } catch (Throwable t) { status = logDown(Level.WARN, "Unexpected exception during SNMP poll of interface " + hostAddress, t); } return status; }
NetScalerGroupHealthMonitor extends SnmpMonitorStrategy { public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { NetworkInterface<InetAddress> iface = svc.getNetInterface(); InetAddress ipaddr = (InetAddress) iface.getAddress(); SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr); if (agentConfig == null) throw new RuntimeException("SnmpAgentConfig object not available for interface " + ipaddr); final String hostAddress = InetAddressUtils.str(ipaddr); PollStatus status = PollStatus.unavailable("NetScalerGroupHealthMonitor: cannot determinate group health, addr=" + hostAddress); int groupHealth = ParameterMap.getKeyedInteger(parameters, "group-health", 60); String groupName = ParameterMap.getKeyedString(parameters, "group-name", null); if (groupName == null) { status.setReason("NetScalerGroupHealthMonitor no group-name defined, addr=" + hostAddress); log().warn("NetScalerGroupHealthMonitor.poll: No Service Name Defined! "); return status; } int snLength = groupName.length(); StringBuffer serviceOidBuf = new StringBuffer(SVC_GRP_MEMBER_STATE); serviceOidBuf.append(".").append(Integer.toString(snLength)); for (byte thisByte : groupName.getBytes()) { serviceOidBuf.append(".").append(Byte.toString(thisByte)); } log().debug("For group name '" + groupName +"', OID to check is " + serviceOidBuf.toString()); try { final SnmpObjId groupStateOid = SnmpObjId.get(serviceOidBuf.toString()); final Map<SnmpInstId, SnmpValue> hostResults = new HashMap<SnmpInstId, SnmpValue>(); RowCallback callback = new RowCallback() { @Override public void rowCompleted(SnmpRowResult result) { hostResults.put(result.getInstance(), result.getValue(groupStateOid)); } }; TableTracker tracker = new TableTracker(callback, groupStateOid); SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "NetScalerGroupHealthMonitor", tracker); walker.start(); walker.waitFor(); int totalServers = hostResults.size(); if (totalServers == 0) { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are 0 servers on group " + groupName + " for " + hostAddress); } int activeServers = 0; for (SnmpValue v : hostResults.values()) { if (v.toInt() == 7) { activeServers++; } } double health = (new Double(activeServers)/new Double(totalServers)) * new Double(100); log().debug("There are " + activeServers + " of " + totalServers + " active servers (" + health + "%) on group " + groupName + " for NetScaler " + hostAddress); if (health >= groupHealth) { status = PollStatus.available(); } else { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are " + activeServers + " of " + totalServers + " servers active (" + health + "%) on group " + groupName + ", which is less than " + groupHealth + "% for " + hostAddress); } } catch (Throwable t) { status = logDown(Level.WARN, "Unexpected exception during SNMP poll of interface " + hostAddress, t); } return status; } }
NetScalerGroupHealthMonitor extends SnmpMonitorStrategy { public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { NetworkInterface<InetAddress> iface = svc.getNetInterface(); InetAddress ipaddr = (InetAddress) iface.getAddress(); SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr); if (agentConfig == null) throw new RuntimeException("SnmpAgentConfig object not available for interface " + ipaddr); final String hostAddress = InetAddressUtils.str(ipaddr); PollStatus status = PollStatus.unavailable("NetScalerGroupHealthMonitor: cannot determinate group health, addr=" + hostAddress); int groupHealth = ParameterMap.getKeyedInteger(parameters, "group-health", 60); String groupName = ParameterMap.getKeyedString(parameters, "group-name", null); if (groupName == null) { status.setReason("NetScalerGroupHealthMonitor no group-name defined, addr=" + hostAddress); log().warn("NetScalerGroupHealthMonitor.poll: No Service Name Defined! "); return status; } int snLength = groupName.length(); StringBuffer serviceOidBuf = new StringBuffer(SVC_GRP_MEMBER_STATE); serviceOidBuf.append(".").append(Integer.toString(snLength)); for (byte thisByte : groupName.getBytes()) { serviceOidBuf.append(".").append(Byte.toString(thisByte)); } log().debug("For group name '" + groupName +"', OID to check is " + serviceOidBuf.toString()); try { final SnmpObjId groupStateOid = SnmpObjId.get(serviceOidBuf.toString()); final Map<SnmpInstId, SnmpValue> hostResults = new HashMap<SnmpInstId, SnmpValue>(); RowCallback callback = new RowCallback() { @Override public void rowCompleted(SnmpRowResult result) { hostResults.put(result.getInstance(), result.getValue(groupStateOid)); } }; TableTracker tracker = new TableTracker(callback, groupStateOid); SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "NetScalerGroupHealthMonitor", tracker); walker.start(); walker.waitFor(); int totalServers = hostResults.size(); if (totalServers == 0) { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are 0 servers on group " + groupName + " for " + hostAddress); } int activeServers = 0; for (SnmpValue v : hostResults.values()) { if (v.toInt() == 7) { activeServers++; } } double health = (new Double(activeServers)/new Double(totalServers)) * new Double(100); log().debug("There are " + activeServers + " of " + totalServers + " active servers (" + health + "%) on group " + groupName + " for NetScaler " + hostAddress); if (health >= groupHealth) { status = PollStatus.available(); } else { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are " + activeServers + " of " + totalServers + " servers active (" + health + "%) on group " + groupName + ", which is less than " + groupHealth + "% for " + hostAddress); } } catch (Throwable t) { status = logDown(Level.WARN, "Unexpected exception during SNMP poll of interface " + hostAddress, t); } return status; }  }
NetScalerGroupHealthMonitor extends SnmpMonitorStrategy { public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { NetworkInterface<InetAddress> iface = svc.getNetInterface(); InetAddress ipaddr = (InetAddress) iface.getAddress(); SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr); if (agentConfig == null) throw new RuntimeException("SnmpAgentConfig object not available for interface " + ipaddr); final String hostAddress = InetAddressUtils.str(ipaddr); PollStatus status = PollStatus.unavailable("NetScalerGroupHealthMonitor: cannot determinate group health, addr=" + hostAddress); int groupHealth = ParameterMap.getKeyedInteger(parameters, "group-health", 60); String groupName = ParameterMap.getKeyedString(parameters, "group-name", null); if (groupName == null) { status.setReason("NetScalerGroupHealthMonitor no group-name defined, addr=" + hostAddress); log().warn("NetScalerGroupHealthMonitor.poll: No Service Name Defined! "); return status; } int snLength = groupName.length(); StringBuffer serviceOidBuf = new StringBuffer(SVC_GRP_MEMBER_STATE); serviceOidBuf.append(".").append(Integer.toString(snLength)); for (byte thisByte : groupName.getBytes()) { serviceOidBuf.append(".").append(Byte.toString(thisByte)); } log().debug("For group name '" + groupName +"', OID to check is " + serviceOidBuf.toString()); try { final SnmpObjId groupStateOid = SnmpObjId.get(serviceOidBuf.toString()); final Map<SnmpInstId, SnmpValue> hostResults = new HashMap<SnmpInstId, SnmpValue>(); RowCallback callback = new RowCallback() { @Override public void rowCompleted(SnmpRowResult result) { hostResults.put(result.getInstance(), result.getValue(groupStateOid)); } }; TableTracker tracker = new TableTracker(callback, groupStateOid); SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "NetScalerGroupHealthMonitor", tracker); walker.start(); walker.waitFor(); int totalServers = hostResults.size(); if (totalServers == 0) { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are 0 servers on group " + groupName + " for " + hostAddress); } int activeServers = 0; for (SnmpValue v : hostResults.values()) { if (v.toInt() == 7) { activeServers++; } } double health = (new Double(activeServers)/new Double(totalServers)) * new Double(100); log().debug("There are " + activeServers + " of " + totalServers + " active servers (" + health + "%) on group " + groupName + " for NetScaler " + hostAddress); if (health >= groupHealth) { status = PollStatus.available(); } else { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are " + activeServers + " of " + totalServers + " servers active (" + health + "%) on group " + groupName + ", which is less than " + groupHealth + "% for " + hostAddress); } } catch (Throwable t) { status = logDown(Level.WARN, "Unexpected exception during SNMP poll of interface " + hostAddress, t); } return status; }  PollStatus poll(MonitoredService svc, Map<String, Object> parameters); }
NetScalerGroupHealthMonitor extends SnmpMonitorStrategy { public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) { NetworkInterface<InetAddress> iface = svc.getNetInterface(); InetAddress ipaddr = (InetAddress) iface.getAddress(); SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(ipaddr); if (agentConfig == null) throw new RuntimeException("SnmpAgentConfig object not available for interface " + ipaddr); final String hostAddress = InetAddressUtils.str(ipaddr); PollStatus status = PollStatus.unavailable("NetScalerGroupHealthMonitor: cannot determinate group health, addr=" + hostAddress); int groupHealth = ParameterMap.getKeyedInteger(parameters, "group-health", 60); String groupName = ParameterMap.getKeyedString(parameters, "group-name", null); if (groupName == null) { status.setReason("NetScalerGroupHealthMonitor no group-name defined, addr=" + hostAddress); log().warn("NetScalerGroupHealthMonitor.poll: No Service Name Defined! "); return status; } int snLength = groupName.length(); StringBuffer serviceOidBuf = new StringBuffer(SVC_GRP_MEMBER_STATE); serviceOidBuf.append(".").append(Integer.toString(snLength)); for (byte thisByte : groupName.getBytes()) { serviceOidBuf.append(".").append(Byte.toString(thisByte)); } log().debug("For group name '" + groupName +"', OID to check is " + serviceOidBuf.toString()); try { final SnmpObjId groupStateOid = SnmpObjId.get(serviceOidBuf.toString()); final Map<SnmpInstId, SnmpValue> hostResults = new HashMap<SnmpInstId, SnmpValue>(); RowCallback callback = new RowCallback() { @Override public void rowCompleted(SnmpRowResult result) { hostResults.put(result.getInstance(), result.getValue(groupStateOid)); } }; TableTracker tracker = new TableTracker(callback, groupStateOid); SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "NetScalerGroupHealthMonitor", tracker); walker.start(); walker.waitFor(); int totalServers = hostResults.size(); if (totalServers == 0) { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are 0 servers on group " + groupName + " for " + hostAddress); } int activeServers = 0; for (SnmpValue v : hostResults.values()) { if (v.toInt() == 7) { activeServers++; } } double health = (new Double(activeServers)/new Double(totalServers)) * new Double(100); log().debug("There are " + activeServers + " of " + totalServers + " active servers (" + health + "%) on group " + groupName + " for NetScaler " + hostAddress); if (health >= groupHealth) { status = PollStatus.available(); } else { status = logDown(Level.DEBUG, "NetScalerGroupHealthMonitor poll failed: there are " + activeServers + " of " + totalServers + " servers active (" + health + "%) on group " + groupName + ", which is less than " + groupHealth + "% for " + hostAddress); } } catch (Throwable t) { status = logDown(Level.WARN, "Unexpected exception during SNMP poll of interface " + hostAddress, t); } return status; }  PollStatus poll(MonitoredService svc, Map<String, Object> parameters);  }