| | |
| | | */ |
| | | public TMonitorResult check(TMonitorResult monitor) { |
| | | // 先检测能否访问该ip的网页 |
| | | ResponseEntity<Object> res = null; |
| | | log.info("监测IP:" + monitor.getIp()); |
| | | ResponseEntity<String> res = null; |
| | | String prefix = "http://"; |
| | | if ("127.0.0.1".equals(monitor.getIp())) { |
| | | monitor.setOnline(Boolean.FALSE); |
| | |
| | | } |
| | | if (!monitor.getOnline()) { |
| | | try { |
| | | reachable = InetAddress.getByName(monitor.getIp()).isReachable(3000); |
| | | reachable = InetAddress.getByName(monitor.getIp()).isReachable(5000); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | } |
| | | boolean webReachable = false; |
| | | try { |
| | | ResponseEntity<Object> res = selfHttpUtil.get(prefix + checkUtil.getIp(), null, null); |
| | | ResponseEntity<String> res = selfHttpUtil.get(prefix + checkUtil.getIp(), null, null); |
| | | webReachable = Objects.nonNull(res) && HttpStatus.OK == res.getStatusCode(); |
| | | } catch (Exception e) { |
| | | log.info("检测web异常"+e.getMessage()); |
| | | webReachable = Boolean.FALSE; |
| | | } |
| | | // ping |
| | |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | String imgUrl = ""; |
| | | // 查出国标设备,就一条数据 |
| | | List<DeviceInfo> gbDevices = new LambdaQueryChainWrapper<>(deviceInfoMapper) |
| | | .orderByDesc(DeviceInfo::getUpdateTime) |
| | | .last("limit 1") |
| | | .list(); |
| | | if (! CollectionUtils.isEmpty(gbDevices)) { |
| | | try { |
| | | imgUrl = workOrderService.getFrameImgByDevice(gbDevices.get(0).getDeviceId(), checkUtil.getSerialNumber(), IdUtils.workOrderNO(new Date(), "99999")); |
| | | result.setImg(imgUrl); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | if(pingReachable || webReachable) { |
| | | // 查出国标设备,就一条数据 |
| | | List<DeviceInfo> gbDevices = new LambdaQueryChainWrapper<>(deviceInfoMapper) |
| | | .orderByDesc(DeviceInfo::getUpdateTime) |
| | | .last("limit 1") |
| | | .list(); |
| | | if (!CollectionUtils.isEmpty(gbDevices)) { |
| | | try { |
| | | imgUrl = workOrderService.getFrameImgByDevice(gbDevices.get(0).getDeviceId(), checkUtil.getSerialNumber(), IdUtils.workOrderNO(new Date(), "99999")); |
| | | result.setImg(imgUrl); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | String status = ""; |
| | | if (! webReachable) { |
| | | status += "设备web访问失败;"; |
| | |
| | | } |
| | | if (StringUtils.isEmpty(imgUrl)) { |
| | | status += "未获取到图片"; |
| | | } |
| | | if (StringUtils.isEmpty(status)) { |
| | | status += "设备正常"; |
| | | } |
| | | result.setStatus(status); |
| | | return result; |
| | |
| | | String status = ""; |
| | | if (! pingReachable) { |
| | | status += "ip未ping通;"; |
| | | }else { |
| | | status += "成功"; |
| | | } |
| | | result.setStatus(status); |
| | | return result; |