合并分支 'master_zmm' 到 'master'
针对贵州现场返回的问题进行修改 查看合并请求 !5
Showing
6 changed files
with
97 additions
and
42 deletions
@@ -14,10 +14,17 @@ | @@ -14,10 +14,17 @@ | ||
14 | VALUES (#DEVICE_ID#,#DEVICE_IP#,#DEVICE_STATE#,#CREATE_DATE#); | 14 | VALUES (#DEVICE_ID#,#DEVICE_IP#,#DEVICE_STATE#,#CREATE_DATE#); |
15 | </insert> | 15 | </insert> |
16 | 16 | ||
17 | + <delete id="deleteBeforeData"> | ||
18 | + $value$ | ||
19 | + </delete> | ||
17 | 20 | ||
18 | - <select id="getStatByParam" parameterClass="java.util.HashMap"> | 21 | + <select id="getPingResultByIp" resultClass="connectionStateBean" > |
22 | + $value$ | ||
23 | + </select> | ||
24 | + | ||
25 | + <select id="getStatByParam" resultClass="connectionStateBean" parameterClass="java.util.HashMap"> | ||
19 | SELECT DEVICE_STATE FROM TB_CONNECTION_STATE | 26 | SELECT DEVICE_STATE FROM TB_CONNECTION_STATE |
20 | - WHERE DEVICE_STATE='DOWN' AND DEVICE_IP= #DEVICE_IP# ORDER BY CREATE_DATE DESC | 27 | + WHERE DEVICE_IP= #DEVICE_IP# ORDER BY CREATE_DATE DESC |
21 | </select> | 28 | </select> |
22 | 29 | ||
23 | 30 |
@@ -6,6 +6,7 @@ import org.apache.log4j.Logger; | @@ -6,6 +6,7 @@ import org.apache.log4j.Logger; | ||
6 | 6 | ||
7 | import java.sql.SQLException; | 7 | import java.sql.SQLException; |
8 | import java.util.ArrayList; | 8 | import java.util.ArrayList; |
9 | +import java.util.Date; | ||
9 | import java.util.HashMap; | 10 | import java.util.HashMap; |
10 | import java.util.List; | 11 | import java.util.List; |
11 | 12 | ||
@@ -34,18 +35,32 @@ public class CheckConnectionDao { | @@ -34,18 +35,32 @@ public class CheckConnectionDao { | ||
34 | 35 | ||
35 | 36 | ||
36 | /** | 37 | /** |
37 | - * 插入ping结果。 | 38 | + * 插入ping结果。在插入数据之前,删除掉当前时间前30分钟的数据,即只保留30分钟的数据。 |
38 | * @param bean | 39 | * @param bean |
39 | */ | 40 | */ |
40 | public void addPingConnectionState(ConnectionStateBean bean){ | 41 | public void addPingConnectionState(ConnectionStateBean bean){ |
41 | try { | 42 | try { |
43 | + deleteBeforeData(); | ||
42 | sqlmapClient.insert("addPingConnectionState", bean); | 44 | sqlmapClient.insert("addPingConnectionState", bean); |
43 | - log.info("******* CheckConnectionDao **** execute method addPingConnectionState ******"); | ||
44 | } catch (SQLException e) { | 45 | } catch (SQLException e) { |
45 | log.error("Exception while addPingConnectionState.",e); | 46 | log.error("Exception while addPingConnectionState.",e); |
46 | } | 47 | } |
48 | + | ||
47 | } | 49 | } |
48 | 50 | ||
51 | + | ||
52 | + /** | ||
53 | + * 清除TB_CONNECTION_STATE表里30分钟前的数据。 | ||
54 | + */ | ||
55 | + public void deleteBeforeData(){ | ||
56 | + long temp=new Date().getTime()-1000*60*30; | ||
57 | + String sql="DELETE from TB_CONNECTION_STATE where CREATE_DATE < "+temp; | ||
58 | + try { | ||
59 | + sqlmapClient.delete("deleteBeforeData", sql); | ||
60 | + } catch (Exception e) { | ||
61 | + log.error("Exception while deleteBeforeData()", e); | ||
62 | + } | ||
63 | + } | ||
49 | /** | 64 | /** |
50 | * 根据IP获取该IP对应ping不通的次数。 | 65 | * 根据IP获取该IP对应ping不通的次数。 |
51 | * @param map | 66 | * @param map |
@@ -62,4 +77,26 @@ public class CheckConnectionDao { | @@ -62,4 +77,26 @@ public class CheckConnectionDao { | ||
62 | } | 77 | } |
63 | 78 | ||
64 | 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 | + | ||
65 | } | 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; |
@@ -153,10 +153,10 @@ public class CollLinuxHost implements CollLinuxHostMBean { | @@ -153,10 +153,10 @@ public class CollLinuxHost implements CollLinuxHostMBean { | ||
153 | public Vector getSSH(HashMap params) { | 153 | public Vector getSSH(HashMap params) { |
154 | Vector<TblATO_KPIDETAIL> v=new Vector<TblATO_KPIDETAIL>(); | 154 | Vector<TblATO_KPIDETAIL> v=new Vector<TblATO_KPIDETAIL>(); |
155 | String ip=params.get("IP_ADDR")+""; | 155 | String ip=params.get("IP_ADDR")+""; |
156 | - if(!StringUtils.isEmpty(ip)){ | 156 | + String result=server.getPingResultByIp(ip); |
157 | + if(!StringUtils.isEmpty(result) && "UP".equals(result)){ | ||
157 | String loginStatCode="FM-00-10-001-998"; // linux 主机登录状态 | 158 | String loginStatCode="FM-00-10-001-998"; // linux 主机登录状态 |
158 | ParamterBean bean =new ParamterBean(); | 159 | ParamterBean bean =new ParamterBean(); |
159 | - | ||
160 | String tempPort=params.get("PROTOCOL_PORT")+""; | 160 | String tempPort=params.get("PROTOCOL_PORT")+""; |
161 | int port=0; | 161 | int port=0; |
162 | if(!StringUtils.isEmpty(tempPort)){ | 162 | if(!StringUtils.isEmpty(tempPort)){ |
@@ -65,7 +65,7 @@ public class CollWindows implements CollWindowsMBean { | @@ -65,7 +65,7 @@ public class CollWindows implements CollWindowsMBean { | ||
65 | 65 | ||
66 | 66 | ||
67 | /** | 67 | /** |
68 | - * 获取连接状态 | 68 | + * 获取连接状态,在进行连接之前,检查该设备是否能ping通,如果为down就不执行操作了。 |
69 | * @param params | 69 | * @param params |
70 | * @return | 70 | * @return |
71 | */ | 71 | */ |
@@ -73,30 +73,33 @@ public class CollWindows implements CollWindowsMBean { | @@ -73,30 +73,33 @@ public class CollWindows implements CollWindowsMBean { | ||
73 | public Vector<TblATO_KPIDETAIL> getSnmpState(HashMap<String, String> params){ | 73 | public Vector<TblATO_KPIDETAIL> getSnmpState(HashMap<String, String> params){ |
74 | Vector<TblATO_KPIDETAIL> v=new Vector<TblATO_KPIDETAIL>(); | 74 | Vector<TblATO_KPIDETAIL> v=new Vector<TblATO_KPIDETAIL>(); |
75 | String ip=params.get("IP"); | 75 | String ip=params.get("IP"); |
76 | - | ||
77 | if(!StringUtils.isEmpty(ip)){ | 76 | if(!StringUtils.isEmpty(ip)){ |
78 | - String kpiId="FM-00-10-001-998"; // Windows 设备登录状态 | ||
79 | - ParamterBean bean =new ParamterBean(); | ||
80 | - String tempPort=params.get("PORT"); | ||
81 | - String community=params.get("COMMUNITY"); | ||
82 | - int port=Integer.parseInt(tempPort); | ||
83 | - String hostName=params.get("HOST_NAME"); | ||
84 | - log.info("******ip "+ip+"**port "+tempPort+"****hostName "+hostName+"*****"); | ||
85 | - bean.setDEVICE_IP(ip); | ||
86 | - bean.setPROTOCOL_PORT(port); | ||
87 | - bean.setCOMMUNITY(community); | ||
88 | - String state=server.getConnectionState4Snmp(bean); | ||
89 | - String unitId = kbpClass+":" + hostName + "-total"; | ||
90 | - TblATO_KPIDETAIL kpidetail=new TblATO_KPIDETAIL(); | ||
91 | - try { | ||
92 | - kpidetail.setKPI_ID(kpiId); | ||
93 | - kpidetail.setUNIT_ID(unitId); | ||
94 | - kpidetail.setKPI_VALUE(state); | ||
95 | - kpidetail.setCLL_TIME(new Date()); | ||
96 | - } catch (ParseException e) { | ||
97 | - e.printStackTrace(); | 77 | + String result=server.getPingResultByIp(ip); |
78 | + log.info("@@@@@###### getSnmpState ping result="+ result +"###$$$$$$$$$$%%%%%%%%%%"); | ||
79 | + if(!StringUtils.isEmpty(result) && "UP".equals(result)){ | ||
80 | + String kpiId="FM-00-10-001-998"; // Windows 设备登录状态 | ||
81 | + ParamterBean bean =new ParamterBean(); | ||
82 | + String tempPort=params.get("PORT"); | ||
83 | + String community=params.get("COMMUNITY"); | ||
84 | + int port=Integer.parseInt(tempPort); | ||
85 | + String hostName=params.get("HOST_NAME"); | ||
86 | + log.info("******ip "+ip+"**port "+tempPort+"****hostName "+hostName+"*****"); | ||
87 | + bean.setDEVICE_IP(ip); | ||
88 | + bean.setPROTOCOL_PORT(port); | ||
89 | + bean.setCOMMUNITY(community); | ||
90 | + String state=server.getConnectionState4Snmp(bean); | ||
91 | + String unitId = kbpClass+":" + hostName + "-total"; | ||
92 | + TblATO_KPIDETAIL kpidetail=new TblATO_KPIDETAIL(); | ||
93 | + try { | ||
94 | + kpidetail.setKPI_ID(kpiId); | ||
95 | + kpidetail.setUNIT_ID(unitId); | ||
96 | + kpidetail.setKPI_VALUE(state); | ||
97 | + kpidetail.setCLL_TIME(new Date()); | ||
98 | + } catch (ParseException e) { | ||
99 | + e.printStackTrace(); | ||
100 | + } | ||
101 | + v.add(kpidetail); | ||
98 | } | 102 | } |
99 | - v.add(kpidetail); | ||
100 | } | 103 | } |
101 | return v; | 104 | return v; |
102 | } | 105 | } |
-
Please register or login to post a comment