| | |
| | | String prefix = "http://"; |
| | | if ("127.0.0.1".equals(monitor.getIp())) { |
| | | monitor.setPingOnline(Boolean.FALSE); |
| | | log.error("ip有误"+monitor.getIp()); |
| | | return monitor; |
| | | } |
| | | try { |
| | | res = selfHttpUtil.get(prefix + monitor.getIp(), null, null); |
| | | monitor.setPingOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode()); |
| | | } catch (Exception e) { |
| | | log.error("web检测离线"+monitor.getIp()); |
| | | monitor.setPingOnline(Boolean.FALSE); |
| | | } |
| | | // 如果http得到的不在线,那么再ping一下 |
| | |
| | | try { |
| | | reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | log.error("Ping异常{}",e.getMessage()); |
| | | } |
| | | if(!reachable) log.error("ping检测离线"+monitor.getIp()); |
| | | monitor.setPingOnline(reachable); |
| | | } |
| | | if (!monitor.getPingOnline()) { |
| | |
| | | Date now = new Date(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | offTimeList.add(dateFormat.format(now)); |
| | | monitor.setOffLineTimeStr(offTimeList); |
| | | //到达产生工单的阈值次数 |
| | | if (continueOffTimes>=times) { |
| | | //产生了工单才会存储离线时间,存储最近一次产生工单的这几个离线时间点 |
| | | monitor.setOffLineTimeStr(offTimeList); |
| | | monitor.setCreateWorkOrder(Boolean.TRUE); |
| | | //产生了一次工单则清除 |
| | | continueOffTimes = 0; |
| | | offTimeList = new ArrayList<>(); |
| | | } |
| | | }else { |
| | | //如果在线了,清空连续离线次数,清空离线时间 |
| | | continueOffTimes = 0; |
| | | offTimeList = new ArrayList<>(); |
| | | } |
| | | map.put("checkTimes", checkTimes); |
| | | map.put("offLineTimes", offLineTimes); |