AnalysisRule.java
4.54 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.sitech.ismp.coll.busi.e2e.rule;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import org.apache.log4j.Logger;
import bsh.Interpreter;
import com.sitech.base.AgentProperties;
import com.sitech.base.Config;
import com.sitech.database.dao.TbCfgEventDao;
import com.sitech.database.domain.TbCfgEvent;
import com.sitech.ismp.app.event.ExpressionHelper;
import com.sitech.ismp.coll.busi.e2e.dao.TbE2eFile2dbFinishTagDao;
import com.sitech.ismp.coll.busi.e2e.dao.TbE2eProcessFinishTagDao;
import com.sitech.ismp.coll.busi.e2e.domain.TbE2eFile2dbFinishTag;
import com.sitech.ismp.messageObject.AlarmEvent;
import com.sitech.util.RandomGUID;
import com.sitech.util.mq.TunnelFactory;
/**
* ClassName:AnalysisRule 业务分析规则抽象类
*
* @author linxc
* @version
* @since Ver 1.1
* @Date 2012 May 11, 2012 2:59:55 PM
*/
public abstract class AnalysisRule implements Runnable {
protected static int CRM_ORDER = 1;
protected static int ZQYZS = 21;
protected Logger logger = Logger.getLogger("BUSI_COLL");
protected Logger error = Logger.getLogger("ERROR");
protected Map<String, String> params;
protected String kbpClass;
protected String productType;
protected TbE2eFile2dbFinishTagDao fileFinishTagdao = null;
protected TbE2eProcessFinishTagDao processTagDao = null;
protected List<TbCfgEvent> eventConfigList = null;
public AnalysisRule(Map<String, String> params) {
this.params = params;
this.kbpClass = params.get("KBP_CLASS");
this.productType = params.get("TAG_TYPE");
this.fileFinishTagdao = new TbE2eFile2dbFinishTagDao(params);
this.processTagDao = new TbE2eProcessFinishTagDao(params);
}
public void run() {
TbCfgEventDao eventConfigdao = new TbCfgEventDao();
eventConfigList = eventConfigdao.queryEventCfgByUnitId(kbpClass);
excute();
}
protected abstract void excute();
/**
* 根据文件类型和处理规则查询采集入库的文件
*/
protected List<TbE2eFile2dbFinishTag> getTbE2eFile2dbFinishTag(
int fileType, int ruleType) {
List<TbE2eFile2dbFinishTag> tagList = fileFinishTagdao
.selectTbE2eFile2dbFinishTag(fileType, ruleType);
return tagList;
}
protected boolean kpiToEvent(String unitId, String kpiId, String kpiValue) {
return kpiToEvent(unitId, kpiId, kpiValue, 1, "");
}
protected boolean kpiToEvent(String unitId, String kpiId, String kpiValue, int eventType, String extEventInfo) {
try {
TbCfgEvent config = ExpressionHelper.getMostMatchExpression(unitId,
kpiId, eventConfigList);
// 没有匹配的告警配置
if (config == null) {
return false;
}
Vector<String> expressionSet = new Vector<String>();
expressionSet.add(config.getEXPRESSION1());
expressionSet.add(config.getEXPRESSION2());
expressionSet.add(config.getEXPRESSION3());
expressionSet.add(config.getEXPRESSION4());
expressionSet.add(config.getEXPRESSION5());
for (int i = 0; i < expressionSet.size(); i++) {
String EXPRESSION = (String) expressionSet.get(i);
if (EXPRESSION == null || EXPRESSION.trim().equals("")) {
continue;
}
Interpreter interpreter = new Interpreter();
interpreter.set("UNIT_ID", unitId);
interpreter.set("KPI_VALUE", kpiValue);
interpreter.set("KPI_ID", kpiId);
interpreter.eval("result=" + EXPRESSION);
Boolean bool = (Boolean) interpreter.get("result");
if (bool.booleanValue()) { // 条件成立,生成新事件, 设置告警字段
AlarmEvent event = new AlarmEvent();
event.setAgentId(AgentProperties.AGENT_ID);
event.setEventId(RandomGUID.getRandomGUID());
event.setCfgExpression(EXPRESSION);
event.setCfgGuid(config.getGUID());
event.setCllTime(new Date());
event.setGenerantTime(new Date());
event.setEventClass((short) getEventLevel(i));
event.setEventTitle(unitId + "的" + kpiId + "值为: "
+ kpiValue);
event.setKpiId(kpiId);
event.setKpiValue(kpiValue);
event.setUnitId(unitId);
// 告警类型 1: 告警, 2:预警
// agent生成的全部为告警
event.setEventType(eventType);
event.setExtEventInfo(extEventInfo);
sendEvent2Workstation(event);
return true;
} // end if
} // end for
} catch (Exception e) {
logger.error("Exception while kpiToEvent", e);
}
return false;
}
private short getEventLevel(int i) { // 根据序号产生告警级别
return (short) (i + 1);
}
public boolean sendEvent2Workstation(AlarmEvent event) throws Exception {
TunnelFactory.getTunnel(Config.Q_WORSTATION).writeData(event);
return true;
}
}