systemRuleAdd.jsp
6.47 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
155
156
157
158
159
160
161
162
163
164
165
<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="a" uri="/WEB-INF/app.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="res" uri="http://www.unidal.org/webres"%>
<%@ taglib prefix="w" uri="http://www.unidal.org/web/core"%>
<jsp:useBean id="ctx" type="com.dianping.cat.system.page.config.Context" scope="request"/>
<jsp:useBean id="payload" type="com.dianping.cat.system.page.config.Payload" scope="request"/>
<jsp:useBean id="model" type="com.dianping.cat.system.page.config.Model" scope="request"/>
<a:config>
<res:useJs value="${res.js.local['jquery.validate.min.js']}" target="head-js" />
<res:useJs value="${res.js.local['alarm_js']}" target="head-js" />
<res:useJs value="${res.js.local['dependencyConfig_js']}" target="head-js" />
<res:useCss value="${res.css.local['select2.css']}" target="head-css" />
<res:useJs value="${res.js.local['select2.min.js']}" target="head-js" />
<form method="post">
<h3 class="text-center text-success">编辑系统监控规则</h3>
<div class="config">
<strong class="text-success">规则ID</strong> <input id="ruleId" type="text" value="${model.id}" /> <span class="text-danger">String,唯一性</span>
</div>
<div id="metrics" class="config">
<button class="btn btn-success btn-xs" id="add-metric-button"
type="button">
添加匹配对象<i class="icon-plus icon-white"></i>
</button>
<div id="metricItem" class="metric config">
设备:
<textarea name="productlineText" class="productlineText "
type=" text" placeholder="支持正则"></textarea>
指标:
<textarea name="metricText" class="metricText " type=" text"
placeholder="支持正则"></textarea>
监控类型: <label class="checkbox inline"> <input name="count"
class="count" type="checkbox">count
</label> <label class="checkbox inline"> <input name="sum"
class="sum" type="checkbox">sum
</label> <label class="checkbox inline"> <input name="avg"
class="avg" type="checkbox">avg
</label>
<button class="btn btn-danger btn-xs delete-metric-button"
type="button">
<i class="ace-icon fa fa-trash-o bigger-120"></i>
</button>
</div>
</div>
${model.content}
<div style='text-align: center'>
<input class="btn btn-primary" id="ruleSubmitButton" type="text"
name="submit" value="提交">
</div>
</form>
<script type="text/javascript">
function drawMetricItems(metricsStr, newMetric) {
if (metricsStr == undefined || metricsStr == "") {
return;
}
try {
metrics = JSON.parse(metricsStr);
} catch (e) {
alert("读取规则错误!请刷新重试或联系leon.li@dianping.com");
return;
}
if (metrics != undefined) {
for (count in metrics) {
var metric = metrics[count];
var productlineText = metric["productText"];
var metricText = metric["metricItemText"];
if (count > 0) {
addMetricHeader(newMetric);
}
var metricForm = $(".metric").last();
if (productlineText) {
metricForm.find(".productlineText").val(productlineText);
}
if (metricText) {
metricForm.find(".metricText").val(metricText);
}
if (metric["monitorCount"]) {
metricForm.find(".count").prop("checked", "true");
}
if (metric["monitorSum"]) {
metricForm.find(".sum").prop("checked", "true");
}
if (metric["monitorAvg"]) {
metricForm.find(".avg").prop("checked", "true");
}
}
}
}
function addMetricHeader(newMetric){
$("#metrics").append(newMetric.clone());
}
function generateMetricsJsonString() {
var metricLength = $(".metric").length;
if (metricLength > 0) {
var metricList = [];
$(".metric").each(function () {
var metric = {};
var hasPro = false;
var productLineText = $(this).find(".productlineText").val();
var metricText = $(this).find(".metricText").val()
if (productLineText != "") {
metric["productText"] = productLineText;
hasPro = true;
}
if (metricText != "") {
metric["metricItemText"] = metricText;
hasPro = true;
}
if ($(this).find($("input[name='count']")).prop("checked") == true) {
metric["monitorCount"] = true;
hasPro = true;
}
if ($(this).find($("input[name='sum']")).prop("checked") == true) {
metric["monitorSum"] = true;
hasPro = true;
}
if ($(this).find($("input[name='avg']")).prop("checked") == true) {
metric["monitorAvg"] = true;
hasPro = true;
}
if (hasPro) {
metricList.push(metric);
}
});
if (metricList.length > 0) {
return JSON.stringify(metricList);
} else {
return "";
}
}
}
$(document).ready(function() {
initRuleConfigs(["DescVal","DescPer","AscVal","AscPer"]);
$('#alert_config').addClass('active open');
$('#systemRuleConfigList').addClass('active');
var newMetric = $('#metricItem').clone();
var configHeader = '${model.configHeader}';
drawMetricItems(configHeader, newMetric);
$(document).delegate("#ruleSubmitButton","click",function(){
var key = $('#ruleId').val();
var metrics = generateMetricsJsonString();
var configStr = generateConfigsJsonString();
window.location.href = "?op=systemRuleSubmit&configs=" + configStr + "&ruleId=" + key +"&metrics="+metrics;
});
$("#add-metric-button").click(function(){
addMetricHeader(newMetric);
});
$("#metrics").delegate(".delete-metric-button", "click", function () {
$(this).parent().remove();
});
});
</script>
</a:config>