@Override public void execute(ExecuteCheck executeCheck) { long start = System.nanoTime(); ActiveResultMO result = new ActiveResultMO().fromCheck(executeCheck); String output = executeCheck.getParameter("output", ""); // parse time ranges TimeRange warning = TimeRangeParser.parseTimeRange( executeCheck.getParameter( "warning", "01:00-02:00, 05:00-06:00, 08:00-09:00, 11:00-12:00, 14:00-15:00, 17:00-18:00, 20:00-21:00, 23:00-24:00")); TimeRange critical = TimeRangeParser.parseTimeRange( executeCheck.getParameter( "critical", "02:00-03:00, 06:00-07:00, 09:00-10:00, 12:00-13:00, 15:00-16:00, 18:00-19:00, 21:00-22:00")); Calendar now = Calendar.getInstance(); // compute the check state if (critical.isInTimeRange(now)) { result.critical(output); } else if (warning.isInTimeRange(now)) { result.warning(output); } else { result.ok(output); } this.publishActiveResult( executeCheck, result.runtime(((double) (System.nanoTime() - start)) / 1_000_000D)); }
@Override public void execute(ExecuteCheck executeCheck) { if (logger.isTraceEnabled()) logger.trace("Checking Bergamot Agent presence"); try { // get the agent id UUID agentId = executeCheck.getAgentId(); if (agentId == null) throw new RuntimeException("No agent id was given"); // lookup the agent BergamotAgentServerHandler agent = this.getEngine().getAgentServer().getRegisteredAgent(agentId); if (agent != null) { agent.sendOnePingAndOnePingOnly( (rtt) -> { this.publishActiveResult( executeCheck, new ActiveResultMO() .fromCheck(executeCheck) .ok( "Bergamot Agent " + agent.getAgentName() + " connected. Latency: " + rtt + "ms") .runtime(rtt)); this.publishReading(executeCheck, new LongGaugeReading("latency", "ms", rtt)); }); } else { this.publishActiveResult( executeCheck, new ActiveResultMO() .fromCheck(executeCheck) .disconnected("Bergamot Agent disconnected")); } } catch (Exception e) { this.publishActiveResult(executeCheck, new ActiveResultMO().fromCheck(executeCheck).error(e)); } }
/** Only execute Checks where the engine == "agent" */ @Override public boolean accept(ExecuteCheck task) { return AgentEngine.NAME.equals(task.getEngine()) && NAME.equals(task.getExecutor()); }