| | |
| | | ResponseEntity<String> res = null; |
| | | String prefix = "http://"; |
| | | if ("127.0.0.1".equals(monitor.getIp())) { |
| | | monitor.setOnline(Boolean.FALSE); |
| | | monitor.setPingOnline(Boolean.FALSE); |
| | | return monitor; |
| | | } |
| | | try { |
| | | res = selfHttpUtil.get(prefix + monitor.getIp(), null, null); |
| | | monitor.setOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode()); |
| | | monitor.setPingOnline(Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode()); |
| | | } catch (Exception e) { |
| | | monitor.setOnline(Boolean.FALSE); |
| | | monitor.setPingOnline(Boolean.FALSE); |
| | | } |
| | | // 如果http得到的不在线,那么再ping一下 |
| | | boolean reachable = false; |
| | |
| | | } else { |
| | | map = new HashMap<>(); |
| | | } |
| | | if (!monitor.getOnline()) { |
| | | if (!monitor.getPingOnline()) { |
| | | try { |
| | | reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | monitor.setOnline(reachable); |
| | | monitor.setPingOnline(reachable); |
| | | } |
| | | if (!monitor.getOnline()) { |
| | | if (!monitor.getPingOnline()) { |
| | | offLineTimes++; |
| | | } |
| | | map.put("checkTimes", checkTimes); |
| | |
| | | String status = ""; |
| | | if (! webReachable) { |
| | | status += "设备web访问失败;"; |
| | | }else if(webReachable){ |
| | | status += "设备web访问正常;"; |
| | | } |
| | | |
| | | if (! pingReachable) { |
| | | status += "设备ip未ping通;"; |
| | | }else if(pingReachable){ |
| | | status += "设备ipPing正常;"; |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(imgUrl)) { |
| | | status += "未获取到图片"; |
| | | } |
| | | if (StringUtils.isEmpty(status)) { |
| | | status += "设备正常"; |
| | | }else { |
| | | status += "获取图片正常"; |
| | | } |
| | | result.setStatus(status); |
| | | return result; |