rebuild GUI structure(only changed modules' name)
[vnfsdk/refrepo.git] / performance / src / main / webapp / performance / js / alarmConds.js
1 /*
2  * Copyright 2016-2017, CMCC Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 var AlarmConds = function () {
17
18     return {
19
20         parseActiveConds2JSon: function (conds) {
21             return this.parseConds2JSon(conds, 1);
22         },
23         parseHistoryConds2JSon: function (conds) {
24             return this.parseConds2JSon(conds, 2);
25         },
26
27         /**
28          *  传入的条件数组说明:
29          *  每个条件都是一个对象,包含2个属性:type和data。type表示条件的类型,data是一个数组,每项都表示一个条件。
30          *  下面是支持的所有条件的说明:
31          *  1)网元
32          *      {
33                          *          type : 'Position',
34                          *          data : [{   //支持多个
35                          *               locationId : 'lId1',
36                          *               oid : 'oid1',
37                          *               isSelf : true //是否分组,true表示只包含自己,false表示分组
38                          *           }
39                          *          ]
40                          *       }
41          *  2)级别
42          *      {
43                          *          type : 'Severity',
44                          *          data : [{  //支持多个
45                          *               severity : 1 //1表示严重,2表示主要,3表示次要,4表示警告
46                          *           }
47                          *          ]
48                          *       }
49          *  3)确认状态
50          *      {
51                          *          type : 'AckState',
52                          *          data : [{  //支持多个
53                          *               ackState : 1 //1表示已确认,2表示未确认
54                          *           }
55                          *          ]
56                          *      }
57          *  4)可见性
58          *      {
59                          *          type : 'FilterState',
60                          *          data : [{  //支持多个
61                          *               filterState : 1 //1表示可见,0表示不可见
62                          *           }
63                          *          ]
64                          *       }
65          *  5)告警类型
66          *      {
67                          *          type : 'AlarmType',
68                          *          data : [{  //支持多个
69                          *               alarmType : 1 //0表示通信告警,1表示处理错误告警,2表示服务质量告警,3表示设备告警,4表示环境告警,5表示网管系统告警,6表示完整性告警,7表示可用性告警,8表示物理攻击告警,9表示安全攻击告警,10表示时限告警
70                          *           }
71                          *          ]
72                          *       }
73          *  6)告警码
74          *      {
75                          *          type : 'ProbableCause',
76                          *          data : [{  //支持多个
77                          *               systemType : 6,
78                          *               code : 1001
79                          *           }
80                          *          ]
81                          *       }
82          *  7)发生时间
83          *      {
84                          *          type : 'RaisedTime',
85                          *          data : [{  //支持一个
86                          *               mode : 0, //0表示区间,1表示最近
87                          *               start : 1399429229000, //mode为0时,表示开始时间,mode为1时,表示时间的毫秒值
88                          *               end : 1399515601000  //mode为0时,表示结束时间,mode为1时,表示时间的毫秒值
89                          *           }
90                          *          ]
91                          *       }
92          *  8)确认时间
93          *      {
94                          *          type : 'AckTime',
95                          *          data : [{  //支持一个
96                          *               mode : 0, //0表示区间,1表示最近
97                          *               start : 1399429229000, //mode为0时,表示开始时间,mode为1时,表示时间的毫秒值
98                          *               end : 1399515601000  //mode为0时,表示结束时间,mode为1时,表示时间的毫秒值
99                          *           }
100                          *          ]
101                          *       }
102          *  9)清除时间
103          *      {
104                          *          type : 'ClearedTime',
105                          *          data : [{  //支持一个
106                          *               mode : 0, //0表示区间,1表示最近
107                          *               start : 1399429229000, //mode为0时,表示开始时间,mode为1时,表示时间的毫秒值
108                          *               end : 1399515601000  //mode为0时,表示结束时间,mode为1时,表示时间的毫秒值
109                          *           }
110                          *          ]
111                          *       }
112          *    10)告警ID
113          *      {
114                          *          type : 'AlarmId',
115                          *          data : [{  //支持一个
116                          *               id : 1412923648983
117                          *           }
118                          *          ]
119                          *       }
120          *    11)MOC
121          *      {
122                          *          type : 'Moc',
123                          *          data : [{ //支持一个
124                          *               moc : 'moc' //支持前缀匹配,如:'moc%'
125                          *           }
126                          *          ]
127                          *       }
128          *    12)ip地址
129          *      {
130                          *                      type : 'NeIp',
131                          *                      data : [{ //支持一个
132                          *                              neIp : '10.74.165.57'
133                          *                      }
134                          *         ]
135                          *              }
136          */
137         parseConds2JSon: function (conds, ruleType) {
138             var parser = {
139                 Position: function (cond) {
140                     var condStr = "";
141                     if (cond.type === "Position" && cond.data.length > 0) {
142                         condStr = "<NewPositionCond OwnerType='Position' value='" + cond.data[0].locationId + "#" + cond.data[0].oid + "#" + cond.data[0].isSelf;
143                         for (var i = 1; i < cond.data.length; i++) {
144                             condStr += "∷" + cond.data[i].locationId + "#" + cond.data[i].oid + "#" + cond.data[i].isSelf;
145                         }
146                         condStr += "' />";
147                     }
148                     return condStr;
149                 },
150                 Severity: function (cond) {
151                     var condStr = "";
152                     if (cond.type === "Severity" && cond.data.length > 0) {
153                         condStr = "<PerceivedSeverity value='" + cond.data[0].severity;
154                         for (var i = 1; i < cond.data.length; i++) {
155                             condStr += "," + cond.data[i].severity;
156                         }
157                         condStr += "' />";
158                     }
159                     return condStr;
160                 },
161                 AckState: function (cond) {
162                     var condStr = "";
163                     if (cond.type === "AckState" && cond.data.length > 0) {
164                         condStr = "<AckState value='" + cond.data[0].ackState;
165                         for (var i = 1; i < cond.data.length; i++) {
166                             condStr += "," + cond.data[i].ackState;
167                         }
168                         condStr += "' />";
169                     }
170                     return condStr;
171                 },
172                 FilterState: function (cond) {
173                     var condStr = "";
174                     if (cond.type === "FilterState" && cond.data.length > 0) {
175                         condStr = "<FilterState value='" + cond.data[0].filterState;
176                         for (var i = 1; i < cond.data.length; i++) {
177                             condStr += "," + cond.data[i].filterState;
178                         }
179                         condStr += "' />";
180                     }
181                     return condStr;
182                 },
183                 AlarmType: function (cond) {
184                     var condStr = "";
185                     if (cond.type === "AlarmType" && cond.data.length > 0) {
186                         condStr = "<AlarmType value='" + cond.data[0].alarmType;
187                         for (var i = 1; i < cond.data.length; i++) {
188                             condStr += "," + cond.data[i].alarmType;
189                         }
190                         condStr += "' />";
191                     }
192                     return condStr;
193                 },
194                 ProbableCause: function (cond) {
195                     var condStr = "";
196                     if (cond.type === "ProbableCause" && cond.data.length > 0) {
197                         condStr = "<ProbableCause value='" + cond.data[0].systemType + "#" + cond.data[0].code;
198                         for (var i = 1; i < cond.data.length; i++) {
199                             condStr += "," + cond.data[i].systemType + "#" + cond.data[i].code;
200                         }
201                         condStr += "' />";
202                     }
203                     return condStr;
204                 },
205                 RaisedTime: function (cond) {
206                     var condStr = "";
207                     if (cond.type === "RaisedTime" && cond.data.length === 1) {
208                         condStr = "<RaisedTime model='" + cond.data[0].mode + "' start='" + cond.data[0].start + "' end= '" + cond.data[0].end + "' queryTimeZone='' condTimeZone='' />";
209                     }
210                     return condStr;
211                 },
212                 AckTime: function (cond) {
213                     var condStr = "";
214                     if (cond.type === "AckTime" && cond.data.length === 1) {
215                         condStr = "<AckTime model='" + cond.data[0].mode + "' start='" + cond.data[0].start + "' end= '" + cond.data[0].end + "' queryTimeZone='' condTimeZone='' />";
216                     }
217                     return condStr;
218                 },
219                 ClearedTime: function (cond) {
220                     var condStr = "";
221                     if (cond.type === "ClearedTime" && cond.data.length === 1) {
222                         condStr = "<ClearedTime model='" + cond.data[0].mode + "' start='" + cond.data[0].start + "' end= '" + cond.data[0].end + "' queryTimeZone='' condTimeZone='' />";
223                     }
224                     return condStr;
225                 },
226                 AlarmId: function (cond) {
227                     var condStr = "";
228                     if (cond.type === "AlarmId" && cond.data.length === 1) {
229                         condStr = "<IDString value='" + cond.data[0].id + "'/>";
230                     }
231                     return condStr;
232                 },
233                 Moc: function (cond) {
234                     var condStr = "";
235                     if (cond.type === "Moc" && cond.data.length === 1) {
236                         condStr = "<Moc Moc='" + cond.data[0].moc + "' SELECT_MODEL='false' MocSelf='true' />";
237                     }
238                     return condStr;
239                 },
240                 NeIp: function (cond) {
241                     var condStr = "";
242                     if (cond.type === "NeIp" && cond.data.length === 1) {
243                         condStr = "<NeIp value='" + cond.data[0].neIp + "' />";
244                     }
245                     return condStr;
246                 }
247             };
248
249             var d = new Date();
250             var JSonObj = {
251                 rule: {
252                     ruleId: -1,
253                     name: "Alarm",
254                     creator: "admin",
255                     createTime: d.getTime(),
256                     modifier: "",
257                     modifyTime: 0,
258                     description: "",
259                     state: true,
260                     ruleType: ruleType,
261                     ruleSort: 1,
262                     owner: "",
263                     attrs: "<Attrs/>"
264                 }
265             };
266             var condStr = "<CompoundCond>";
267             for (var i = 0; i < conds.length; i++) {
268                 condStr += parser[conds[i].type](conds[i]);
269             }
270             JSonObj.rule.ruleData = condStr + "</CompoundCond>";
271             //return JSON.stringify(JSonObj);
272             return JSonObj;
273         }
274
275     };
276 }();