Downtime.java
2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.sitech.ismp.check.downtime;
import com.sitech.ismp.coll.basic.TblATO_KPIDETAIL;
import org.apache.log4j.Logger;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author frank zmm@honggroup.com.cn
* @Description: 宕机检测MBean实现类
* @Package com.sitech.ismp.check.downtime
* @ClassName: com.sitech.ismp.check.downtime.Downtime
* @date 2017年04月15日 13:43
*/
public class Downtime implements DowntimeMBean {
private static Logger log= Logger.getLogger(Downtime.class);
DowntimeDao dao=new DowntimeDao();
DowntimeHistoryDao historyDao=new DowntimeHistoryDao();
SimpleDateFormat formaF=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 检查主机的连接状态。如果连接异常,需要每隔30秒连续连接3次,如果3次连接都异常,则视为主机宕机,发送严重告警。
* 1 将需要监控的设备添加到内存数据库中。
* 2 对表中的主机进行ping操作。
* 3 对表中的主机进行SSH登录认证
* 4 发送告警信息
* @param params
* @return
*/
@Override
public Vector<TblATO_KPIDETAIL> checkConnectState(HashMap<String,String> params){
dao.addDowntimeHost(params);
String ipAddr=params.get("DEVICE_IP");
boolean flag=isNeedExecuteCheckMethod(ipAddr);
if(flag){
log.info("*************"+ formaF.format(new Date()) +" execute method checkConnectState .................");
// 将需要监控的设备添加到内存数据库中。
DowntimeBean bean=dao.map2DowntimeBean(params);
DowntimeServer server=new DowntimeServer(bean);
// 包括 2-4 需要执行的内容。 如果监控的设备很多的时候,使用单线程可能一个监控周期都不能ping完所有的主机。
server.run();
log.info("@@@@@@@@@@@@@@@@@@@@@@***** finish run method *****@@@@@@@@@@@@@@@@@@@@@@@@@@@");
log.info(bean.toString());
}
Vector<TblATO_KPIDETAIL> bean = new Vector<TblATO_KPIDETAIL>();
return bean;
}
/**
* 是否执行checkConnectState 方法。
* 判断当前IP是否发送过告警信息。每天一个主机只发送1条告警信息。
* @return
*/
private boolean isNeedExecuteCheckMethod(String ipAddr){
boolean flag=true; // 是否该ipAddr已经发送过消息。
SimpleDateFormat formaF=new SimpleDateFormat("yyyy-MM-dd");
String currentDay=formaF.format(new Date());
List<DowntimeHistoryBean> list=historyDao.getDowntimeHistoryByIp(ipAddr,currentDay);
if(null !=list && list.size()>0){
flag=false;
}
return flag;
}
}