private String enrichArguments(String args, MonitoredService svc, TimeoutTracker tracker, Map <String, Object> parameters) { String richArgs = args; richArgs = richArgs.replace("${timeout}", ((Long)tracker.getTimeoutInMillis()).toString()); richArgs = richArgs.replace("${timeoutsec}", ((Long)tracker.getTimeoutInSeconds()).toString()); richArgs = richArgs.replace("${retry}", ParameterMap.getKeyedString(parameters, "retry", ((Integer)DEFAULT_RETRY).toString())); richArgs = richArgs.replace("${ipaddr}", svc.getIpAddr()); richArgs = richArgs.replace("${nodeid}", ((Integer) svc.getNodeId()).toString()); richArgs = richArgs.replace("${nodelabel}", svc.getNodeLabel()); richArgs = richArgs.replace("${svcname}", svc.getSvcName()); return richArgs; }
@Override public Map<String, Object> getRuntimeAttributes(MonitoredService svc, Map<String, Object> parameters) { final Map<String, Object> attributes = new HashMap<>(); final PollStatus pollStatus = doPoll(svc.getNodeId(), svc.getIpAddr(), m_svcName); attributes.put("status", Integer.toString(pollStatus.getStatusCode())); attributes.put("reason", pollStatus.getReason()); return attributes; }
public static Properties getServiceProperties(final MonitoredService svc) { final InetAddress addr = InetAddressUtils.addr(svc.getIpAddr()); final boolean requireBrackets = addr != null && addr instanceof Inet6Address && !svc.getIpAddr().startsWith("["); final Properties properties = new Properties(); properties.put("ipaddr", requireBrackets ? "[" + svc.getIpAddr() + "]" : svc.getIpAddr()); properties.put("nodeid", svc.getNodeId()); properties.put("nodelabel", svc.getNodeLabel()); properties.put("svcname", svc.getSvcName()); return properties; } }
break; case "nodeId": sb.append(svc.getNodeId()); break; case "nodeLabel": break; case "foreignId": sb.append(nodeDao.get().get(svc.getNodeId()).getForeignId()); break; case "foreignSource": sb.append(nodeDao.get().get(svc.getNodeId()).getForeignSource()); break; default: LOG.debug("attempting to add node asset property {}", m.group(1)); OnmsNode node = nodeDao.get().get(svc.getNodeId()); if (node != null) { BeanWrapper wrapper = new BeanWrapperImpl(node.getAssetRecord());
@Override public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) { // Minions send heartbeat every 30 seconds - we check that we can skip not more than one beat final int period = 2 * ParameterMap.getKeyedInteger(parameters, "period", 30 * 1000); // Get the minion to test whereas the minion ID is the nodes foreign ID by convention final OnmsNode node = nodeDao.get().get(svc.getNodeId()); final OnmsMinion minion = minionDao.get().findById(node.getForeignId()); // Calculate the time since the last heartbeat was received final long lastSeen = System.currentTimeMillis() - minion.getLastUpdated().getTime(); final PollStatus status; if (lastSeen <= period) { status = PollStatus.available(); } else if (ManagementFactory.getRuntimeMXBean().getUptime() < period) { status = PollStatus.unknown("JVM has not been started long enough to process a heartbeat."); } else { status = PollStatus.unavailable(String.format("Last heartbeat was %.2f seconds ago", lastSeen / 1000.0)); } return status; }
@Override public PollStatus poll(MonitoredService monSvc, Map<String, Object> parameters) { if (parameters.containsKey("status")) { final int statusCode = getKeyedInteger(parameters, "status", PollStatus.SERVICE_UNKNOWN); final String reason = getKeyedString(parameters, "reason", null); return PollStatus.get(statusCode, reason); } synchronized (m_network) { return doPoll(monSvc.getNodeId(), monSvc.getIpAddr(), m_svcName); } }
private void applyThresholds(String rrdPath, MonitoredService service, String dsName, Map<String, Number> entries) { try { if (m_thresholdingSet == null) { RrdRepository repository = new RrdRepository(); repository.setRrdBaseDir(new File(rrdPath)); m_thresholdingSet = new LatencyThresholdingSet(service.getNodeId(), service.getIpAddr(), service.getSvcName(), service.getNodeLocation(), repository, m_resourceStorageDao); } LinkedHashMap<String, Double> attributes = new LinkedHashMap<String, Double>(); for (String ds : entries.keySet()) { Number sampleValue = entries.get(ds); if (sampleValue == null) { attributes.put(ds, Double.NaN); } else { attributes.put(ds, sampleValue.doubleValue()); } } if (m_thresholdingSet.isNodeInOutage()) { LOG.info("applyThresholds: the threshold processing will be skipped because the service {} is on a scheduled outage.", service); } else if (m_thresholdingSet.hasThresholds(attributes)) { List<Event> events = m_thresholdingSet.applyThresholds(dsName, attributes); if (events.size() > 0) { ThresholdingEventProxy proxy = new ThresholdingEventProxy(); proxy.add(events); proxy.sendAllEvents(); } } } catch(Throwable e) { LOG.error("Failed to threshold on {} for {} because of an exception", service, dsName, e); } }
m_bsfManager.declareBean("node_id",svc.getNodeId(),int.class ); m_bsfManager.declareBean("node_label", svc.getNodeLabel(), String.class); m_bsfManager.declareBean("svc_name", svc.getSvcName(), String.class);
@Override public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) { Long ttlInMs = ParameterMap.getKeyedLong(parameters, "ttl", DEFAULT_TTL_IN_MS); if (ttlInMs < 1) { // Use the global default ttlInMs = null; } int messageSize = ParameterMap.getKeyedInteger(parameters, "message-size", DEFAULT_MESSAGE_SIZE); if (messageSize < 0) { messageSize = 0; } // Create the client final RpcClient<EchoRequest, EchoResponse> client = rpcClientFactory.get().getClient(EchoRpcModule.INSTANCE); // Build the request final OnmsNode node = nodeDao.get().get(svc.getNodeId()); final EchoRequest request = new EchoRequest(); request.setId(System.currentTimeMillis()); request.setMessage(Strings.repeat("*", messageSize)); request.setLocation(node.getLocation().getLocationName()); request.setSystemId(node.getForeignId()); request.setTimeToLiveMs(ttlInMs); try { final EchoResponse response = client.execute(request).get(); final Long responseTime = System.currentTimeMillis() - response.getId(); return PollStatus.available(responseTime.doubleValue()); } catch (InterruptedException|ExecutionException t) { return RpcExceptionUtils.handleException(t, this); } }
expect(svc.getNodeId()).andReturn(1); expect(svc.getIpAddr()).andReturn("127.0.0.1").atLeastOnce(); expect(svc.getSvcName()).andReturn("ICMP").atLeastOnce();
.withNodeId(service.getNodeId()) .withLocation(service.getNodeLocation()) .withSystemId(systemId) request.setServiceName(service.getSvcName()); request.setAddress(service.getAddress()); request.setNodeId(service.getNodeId()); request.setNodeLabel(service.getNodeLabel()); request.setNodeLocation(service.getNodeLocation());