| | |
| | | } |
| | | } |
| | | |
| | | public void getPyRouterStatus() { |
| | | List<OspfInfo> ospfInfos = OspfInfoMapper.selectAllByParams(null); |
| | | for (OspfInfo ospfInfo : ospfInfos) { |
| | | String command = "display ospf peer "+ospfInfo.getHostname(); |
| | | Map<String,Object> map = new HashMap<>(); |
| | | map.put("command",command); |
| | | map.put("username",ospfInfo.getMonitorUsername()); |
| | | map.put("password",ospfInfo.getMonitorPassword()); |
| | | map.put("host",ospfInfo.getMonitorIp()); |
| | | if(ospfInfo.getMonitorRemoteType().equals("TELNET")){ |
| | | map.put("protocol","telnet"); |
| | | map.put("port",23); |
| | | }else if(ospfInfo.getMonitorRemoteType().equals("SSH")){ |
| | | map.put("protocol","ssh"); |
| | | map.put("port",22); |
| | | } |
| | | map.put("ospfIp",ospfInfo.getHostname()); |
| | | String str = JSON.toJSONString(map); |
| | | //System.out.println(str); |
| | | try { |
| | | String url = "http://"+remoteHost+":"+remotePort+"/exec-h3c"; |
| | | String responseBody = HttpRequest.post(url) |
| | | .timeout(50000) |
| | | .body(str) |
| | | .execute() |
| | | .body(); |
| | | System.out.println(responseBody); |
| | | String result = responseBody.replaceAll("^\"|\"$", ""); |
| | | if(result.equals("1")){ |
| | | HashMap<String, Object> hashMap = new HashMap<>(); |
| | | hashMap.put("state","1"); |
| | | hashMap.put("hostname",ospfInfo.getHostname()); |
| | | List<OspfErrorLog> ospfErrorLogs = errorLogMapper.selectAllByParams(hashMap); |
| | | if(ospfErrorLogs==null||ospfErrorLogs.size()==0){ |
| | | OspfErrorLog ospfErrorLog = new OspfErrorLog(); |
| | | ospfErrorLog.setInfoContent(ospfInfo.getInfoContent()); |
| | | ospfErrorLog.setHostname(ospfInfo.getHostname()); |
| | | ospfErrorLog.setState("1"); |
| | | ospfErrorLog.setId(UUIDUtil.getUUID()); |
| | | ospfErrorLog.setCreateTime(DateUtil.getNowTime()); |
| | | try { |
| | | errorLogMapper.save(ospfErrorLog); |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | ospfInfo.setState(result); |
| | | OspfInfoMapper.updateById(ospfInfo); |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | ospfInfo.setState("1"); |
| | | OspfInfoMapper.updateById(ospfInfo); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取OSPF接口状态 |
| | | */ |