Authored by 王凤

合并分支 'master_zmm' 到 'master'

针对贵州现场返回的问题进行修改



查看合并请求 !5
... ... @@ -14,10 +14,17 @@
VALUES (#DEVICE_ID#,#DEVICE_IP#,#DEVICE_STATE#,#CREATE_DATE#);
</insert>
<delete id="deleteBeforeData">
$value$
</delete>
<select id="getStatByParam" parameterClass="java.util.HashMap">
<select id="getPingResultByIp" resultClass="connectionStateBean" >
$value$
</select>
<select id="getStatByParam" resultClass="connectionStateBean" parameterClass="java.util.HashMap">
SELECT DEVICE_STATE FROM TB_CONNECTION_STATE
WHERE DEVICE_STATE='DOWN' AND DEVICE_IP= #DEVICE_IP# ORDER BY CREATE_DATE DESC
WHERE DEVICE_IP= #DEVICE_IP# ORDER BY CREATE_DATE DESC
</select>
... ...
... ... @@ -6,6 +6,7 @@ import org.apache.log4j.Logger;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
... ... @@ -34,18 +35,32 @@ public class CheckConnectionDao {
/**
* 插入ping结果。
* 插入ping结果。在插入数据之前,删除掉当前时间前30分钟的数据,即只保留30分钟的数据。
* @param bean
*/
public void addPingConnectionState(ConnectionStateBean bean){
try {
deleteBeforeData();
sqlmapClient.insert("addPingConnectionState", bean);
log.info("******* CheckConnectionDao **** execute method addPingConnectionState ******");
} catch (SQLException e) {
log.error("Exception while addPingConnectionState.",e);
}
}
/**
* 清除TB_CONNECTION_STATE表里30分钟前的数据。
*/
public void deleteBeforeData(){
long temp=new Date().getTime()-1000*60*30;
String sql="DELETE from TB_CONNECTION_STATE where CREATE_DATE < "+temp;
try {
sqlmapClient.delete("deleteBeforeData", sql);
} catch (Exception e) {
log.error("Exception while deleteBeforeData()", e);
}
}
/**
* 根据IP获取该IP对应ping不通的次数。
* @param map
... ... @@ -62,4 +77,26 @@ public class CheckConnectionDao {
}
/**
* 根据ip查询该ip是否能ping通,时间按照倒序排序。
* @param sql
* @return
*/
public String getPingResultByIp(String sql){
List<ConnectionStateBean> beanList=new ArrayList<ConnectionStateBean>();
try {
beanList=sqlmapClient.queryForList("getPingResultByIp", sql);
} catch (SQLException e) {
e.printStackTrace();
}
String result="";
log.info("&&&&&&&& beanList.size()="+beanList.size()+" &&&&&&&&&&&&&&&&&&&&&&");
if(null !=beanList && beanList.size()>0){
ConnectionStateBean bean=beanList.get(0);
log.info("&&&&&&&& ConnectionStateBean ="+bean.toString()+" &&&&&&&&&&&&&&&&&&&&&&");
result=bean.getDEVICE_STATE();
}
return result;
}
}
... ...
... ... @@ -416,19 +416,18 @@ public class CheckConnectionService {
return dao.getStatByParam(map);
}
public static void main(String [] args){
long beforeTime = 15*60*1000+500;//15.5分钟前
long afterTime = 30*1000;//半分钟后
Date now = new Date();
long nn=now.getTime();
long before = nn - beforeTime;
long after = nn + afterTime;
System.out.println(nn);
System.out.println(after);
System.out.println(before);
}
/**
* 根据ip查询该ip是否能ping通,时间按照倒序排序。
* @param ip
* @return
*/
public String getPingResultByIp(String ip){
String sql="SELECT DEVICE_STATE FROM TB_CONNECTION_STATE WHERE DEVICE_IP='"+ip+"' ORDER BY CREATE_DATE DESC";
CheckConnectionDao dao=new CheckConnectionDao();
String result=dao.getPingResultByIp(sql);
return result;
}
}
... ...
... ... @@ -52,12 +52,21 @@ public class CheckConnectionState {
}
/**
* 根据ip查询该ip是否能ping通,时间按照倒序排序。
* @param ip
* @return
*/
public String getPingResultByIp(String ip){
return service.getPingResultByIp(ip);
}
/**
* 根据IP获取ping不通的次数。只取集合中的前3条数据。当都为down的时候表明已经宕机,少于3次不算宕机。
* @param ip
* @return
*/
public String getPingErrorState(String ip){
List<ConnectionStateBean> list=service.getStatByParam(ip);
log.info("**********&&&&& list .size ="+list.size()+"&&&&&&&&&********(((((((");
int temp=0;
String state=null;
ConnectionStateBean bean=null;
... ... @@ -71,7 +80,7 @@ public class CheckConnectionState {
}
}
String stat="UP";
if(temp==3){
if(temp!=0){
stat="DOWN";
}
return stat;
... ...
... ... @@ -153,10 +153,10 @@ public class CollLinuxHost implements CollLinuxHostMBean {
public Vector getSSH(HashMap params) {
Vector<TblATO_KPIDETAIL> v=new Vector<TblATO_KPIDETAIL>();
String ip=params.get("IP_ADDR")+"";
if(!StringUtils.isEmpty(ip)){
String result=server.getPingResultByIp(ip);
if(!StringUtils.isEmpty(result) && "UP".equals(result)){
String loginStatCode="FM-00-10-001-998"; // linux 主机登录状态
ParamterBean bean =new ParamterBean();
String tempPort=params.get("PROTOCOL_PORT")+"";
int port=0;
if(!StringUtils.isEmpty(tempPort)){
... ...
... ... @@ -65,7 +65,7 @@ public class CollWindows implements CollWindowsMBean {
/**
* 获取连接状态
* 获取连接状态,在进行连接之前,检查该设备是否能ping通,如果为down就不执行操作了。
* @param params
* @return
*/
... ... @@ -73,8 +73,10 @@ public class CollWindows implements CollWindowsMBean {
public Vector<TblATO_KPIDETAIL> getSnmpState(HashMap<String, String> params){
Vector<TblATO_KPIDETAIL> v=new Vector<TblATO_KPIDETAIL>();
String ip=params.get("IP");
if(!StringUtils.isEmpty(ip)){
String result=server.getPingResultByIp(ip);
log.info("@@@@@###### getSnmpState ping result="+ result +"###$$$$$$$$$$%%%%%%%%%%");
if(!StringUtils.isEmpty(result) && "UP".equals(result)){
String kpiId="FM-00-10-001-998"; // Windows 设备登录状态
ParamterBean bean =new ParamterBean();
String tempPort=params.get("PORT");
... ... @@ -98,6 +100,7 @@ public class CollWindows implements CollWindowsMBean {
}
v.add(kpidetail);
}
}
return v;
}
... ...