修改现场返回的问题,当ping通的情况下才检查连接状态。
Showing
3 changed files
with
46 additions
and
18 deletions
@@ -35,14 +35,13 @@ public class CheckConnectionDao { | @@ -35,14 +35,13 @@ public class CheckConnectionDao { | ||
35 | 35 | ||
36 | 36 | ||
37 | /** | 37 | /** |
38 | - * 插入ping结果。在插入数据之前,删除掉当前时间前1小时的数据,即只保留1小时的数据。 | 38 | + * 插入ping结果。在插入数据之前,删除掉当前时间前30分钟的数据,即只保留30分钟的数据。 |
39 | * @param bean | 39 | * @param bean |
40 | */ | 40 | */ |
41 | public void addPingConnectionState(ConnectionStateBean bean){ | 41 | public void addPingConnectionState(ConnectionStateBean bean){ |
42 | try { | 42 | try { |
43 | deleteBeforeData(); | 43 | deleteBeforeData(); |
44 | sqlmapClient.insert("addPingConnectionState", bean); | 44 | sqlmapClient.insert("addPingConnectionState", bean); |
45 | - log.info("******* CheckConnectionDao **** execute method addPingConnectionState ******"); | ||
46 | } catch (SQLException e) { | 45 | } catch (SQLException e) { |
47 | log.error("Exception while addPingConnectionState.",e); | 46 | log.error("Exception while addPingConnectionState.",e); |
48 | } | 47 | } |
@@ -51,12 +50,11 @@ public class CheckConnectionDao { | @@ -51,12 +50,11 @@ public class CheckConnectionDao { | ||
51 | 50 | ||
52 | 51 | ||
53 | /** | 52 | /** |
54 | - * 清除TB_CONNECTION_STATE表里1小时前的数据。 | 53 | + * 清除TB_CONNECTION_STATE表里30分钟前的数据。 |
55 | */ | 54 | */ |
56 | public void deleteBeforeData(){ | 55 | public void deleteBeforeData(){ |
57 | - long temp=new Date().getTime()-1000*60*60; | 56 | + long temp=new Date().getTime()-1000*60*30; |
58 | String sql="DELETE from TB_CONNECTION_STATE where CREATE_DATE < "+temp; | 57 | String sql="DELETE from TB_CONNECTION_STATE where CREATE_DATE < "+temp; |
59 | - log.info("******* deleteBeforeData **** sql["+sql+"]******"); | ||
60 | try { | 58 | try { |
61 | sqlmapClient.delete("deleteBeforeData", sql); | 59 | sqlmapClient.delete("deleteBeforeData", sql); |
62 | } catch (Exception e) { | 60 | } catch (Exception e) { |
@@ -79,4 +77,26 @@ public class CheckConnectionDao { | @@ -79,4 +77,26 @@ public class CheckConnectionDao { | ||
79 | } | 77 | } |
80 | 78 | ||
81 | 79 | ||
80 | + /** | ||
81 | + * 根据ip查询该ip是否能ping通,时间按照倒序排序。 | ||
82 | + * @param sql | ||
83 | + * @return | ||
84 | + */ | ||
85 | + public String getPingResultByIp(String sql){ | ||
86 | + List<ConnectionStateBean> beanList=new ArrayList<ConnectionStateBean>(); | ||
87 | + try { | ||
88 | + beanList=sqlmapClient.queryForList("getPingResultByIp", sql); | ||
89 | + } catch (SQLException e) { | ||
90 | + e.printStackTrace(); | ||
91 | + } | ||
92 | + String result=""; | ||
93 | + log.info("&&&&&&&& beanList.size()="+beanList.size()+" &&&&&&&&&&&&&&&&&&&&&&"); | ||
94 | + if(null !=beanList && beanList.size()>0){ | ||
95 | + ConnectionStateBean bean=beanList.get(0); | ||
96 | + log.info("&&&&&&&& ConnectionStateBean ="+bean.toString()+" &&&&&&&&&&&&&&&&&&&&&&"); | ||
97 | + result=bean.getDEVICE_STATE(); | ||
98 | + } | ||
99 | + return result; | ||
100 | + } | ||
101 | + | ||
82 | } | 102 | } |
@@ -416,19 +416,18 @@ public class CheckConnectionService { | @@ -416,19 +416,18 @@ public class CheckConnectionService { | ||
416 | return dao.getStatByParam(map); | 416 | return dao.getStatByParam(map); |
417 | } | 417 | } |
418 | 418 | ||
419 | - public static void main(String [] args){ | ||
420 | - long beforeTime = 15*60*1000+500;//15.5分钟前 | ||
421 | - long afterTime = 30*1000;//半分钟后 | ||
422 | - Date now = new Date(); | ||
423 | - long nn=now.getTime(); | ||
424 | - long before = nn - beforeTime; | ||
425 | - long after = nn + afterTime; | ||
426 | - System.out.println(nn); | ||
427 | - System.out.println(after); | ||
428 | - System.out.println(before); | ||
429 | - } | ||
430 | - | ||
431 | 419 | ||
420 | + /** | ||
421 | + * 根据ip查询该ip是否能ping通,时间按照倒序排序。 | ||
422 | + * @param ip | ||
423 | + * @return | ||
424 | + */ | ||
425 | + public String getPingResultByIp(String ip){ | ||
426 | + String sql="SELECT DEVICE_STATE FROM TB_CONNECTION_STATE WHERE DEVICE_IP='"+ip+"' ORDER BY CREATE_DATE DESC"; | ||
427 | + CheckConnectionDao dao=new CheckConnectionDao(); | ||
428 | + String result=dao.getPingResultByIp(sql); | ||
429 | + return result; | ||
430 | + } | ||
432 | 431 | ||
433 | 432 | ||
434 | } | 433 | } |
@@ -52,12 +52,21 @@ public class CheckConnectionState { | @@ -52,12 +52,21 @@ public class CheckConnectionState { | ||
52 | } | 52 | } |
53 | 53 | ||
54 | /** | 54 | /** |
55 | + * 根据ip查询该ip是否能ping通,时间按照倒序排序。 | ||
56 | + * @param ip | ||
57 | + * @return | ||
58 | + */ | ||
59 | + public String getPingResultByIp(String ip){ | ||
60 | + return service.getPingResultByIp(ip); | ||
61 | + } | ||
62 | + /** | ||
55 | * 根据IP获取ping不通的次数。只取集合中的前3条数据。当都为down的时候表明已经宕机,少于3次不算宕机。 | 63 | * 根据IP获取ping不通的次数。只取集合中的前3条数据。当都为down的时候表明已经宕机,少于3次不算宕机。 |
56 | * @param ip | 64 | * @param ip |
57 | * @return | 65 | * @return |
58 | */ | 66 | */ |
59 | public String getPingErrorState(String ip){ | 67 | public String getPingErrorState(String ip){ |
60 | List<ConnectionStateBean> list=service.getStatByParam(ip); | 68 | List<ConnectionStateBean> list=service.getStatByParam(ip); |
69 | + log.info("**********&&&&& list .size ="+list.size()+"&&&&&&&&&********((((((("); | ||
61 | int temp=0; | 70 | int temp=0; |
62 | String state=null; | 71 | String state=null; |
63 | ConnectionStateBean bean=null; | 72 | ConnectionStateBean bean=null; |
@@ -71,7 +80,7 @@ public class CheckConnectionState { | @@ -71,7 +80,7 @@ public class CheckConnectionState { | ||
71 | } | 80 | } |
72 | } | 81 | } |
73 | String stat="UP"; | 82 | String stat="UP"; |
74 | - if(temp==3){ | 83 | + if(temp!=0){ |
75 | stat="DOWN"; | 84 | stat="DOWN"; |
76 | } | 85 | } |
77 | return stat; | 86 | return stat; |
-
Please register or login to post a comment