1 package evel_javalibrary.att.com;
\r
2 /**************************************************************************//**
\r
4 * Evel Threshold Crossing event class
\r
6 * This file implements the Evel Threshold Crossing event class which is intended to provide a
\r
7 * simple wrapper around the complexity of AT&T's Vendor Event Listener API so
\r
8 * that VNFs can use it to send Threshold Crossing Alert events.
\r
13 * Licensed under the Apache License, Version 2.0 (the "License");
\r
14 * you may not use this file except in compliance with the License.
\r
15 * You may obtain a copy of the License at
\r
16 * http://www.apache.org/licenses/LICENSE-2.0
\r
18 * Unless required by applicable law or agreed to in writing, software
\r
19 * distributed under the License is distributed on an "AS IS" BASIS,
\r
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
21 * See the License for the specific language governing permissions and
\r
22 * limitations under the License.
\r
23 *****************************************************************************/
\r
25 import java.text.MessageFormat;
\r
26 import java.util.ArrayList;
\r
27 import java.util.Date;
\r
29 import javax.json.Json;
\r
30 import javax.json.JsonArrayBuilder;
\r
31 import javax.json.JsonObject;
\r
32 import javax.json.JsonObjectBuilder;
\r
34 import org.apache.log4j.Logger;
\r
36 import evel_javalibrary.att.com.EvelMobileFlow.MOBILE_GTP_PER_FLOW_METRICS;
\r
39 public class EvelThresholdCross extends EvelHeader {
\r
42 int major_version = 1;
\r
43 int minor_version = 1;
\r
45 /**************************************************************************//**
\r
47 * JSON equivalent fields: newState, oldState
\r
48 *****************************************************************************/
\r
49 public enum EVEL_EVENT_ACTION {
\r
50 EVEL_EVENT_ACTION_CLEAR,
\r
51 EVEL_EVENT_ACTION_CONTINUE,
\r
52 EVEL_EVENT_ACTION_SET,
\r
53 EVEL_MAX_EVENT_ACTION
\r
56 public enum EVEL_ALERT_TYPE {
\r
58 EVEL_ELEMENT_ANOMALY,
\r
59 EVEL_INTERFACE_ANOMALY,
\r
60 EVEL_SERVICE_ANOMALY,
\r
64 public enum EVEL_SEVERITIES{
\r
65 EVEL_SEVERITY_CRITICAL,
\r
66 EVEL_SEVERITY_MAJOR,
\r
67 EVEL_SEVERITY_MINOR,
\r
68 EVEL_SEVERITY_WARNING,
\r
69 EVEL_SEVERITY_NORMAL,
\r
74 /***************************************************************************/
\r
75 /* Mandatory fields */
\r
76 /***************************************************************************/
\r
78 public class PERF_COUNTER {
\r
81 String thresholdCrossed;
\r
85 PERF_COUNTER additionalParameters;
\r
86 EVEL_EVENT_ACTION alertAction;
\r
87 String alertDescription;
\r
88 EVEL_ALERT_TYPE alertType;
\r
89 Date collectionTimestamp;
\r
90 EVEL_SEVERITIES eventSeverity;
\r
91 Date eventStartTimestamp;
\r
94 /***************************************************************************/
\r
95 /* Optional fields */
\r
96 /***************************************************************************/
\r
97 ArrayList<String[]> additional_info;
\r
98 EvelOptionString alertValue;
\r
99 ArrayList<String> alertidList;
\r
100 EvelOptionString dataCollector;
\r
101 EvelOptionString elementType;
\r
102 EvelOptionString interfaceName;
\r
103 EvelOptionString networkService;
\r
104 EvelOptionString possibleRootCause;
\r
107 private static final Logger LOGGER = Logger.getLogger( EvelThresholdCross.class.getName() );
\r
109 /**************************************************************************//**
\r
110 * Create a new Threshold Crossing event.
\r
113 * @param String tcriticality Counter Criticality MAJ MIN,
\r
114 * @param String tname Counter Threshold name
\r
115 * @param String tthresholdCrossed Counter Threshold crossed value
\r
116 * @param String tvalue Counter actual value
\r
117 * @param EVEL_EVENT_ACTION talertAction Alert set continue or clear
\r
118 * @param String talertDescription
\r
119 * @param EVEL_ALERT_TYPE talertType Kind of anamoly
\r
120 * @param Date tcollectionTimestamp time at which alert was collected
\r
121 * @param EVEL_SEVERITIES teventSeverity Severity of Alert
\r
122 * @param Date teventStartTimestamp Time when this alert started
\r
123 *****************************************************************************/
\r
124 public EvelThresholdCross( String evname,String evid,
\r
125 String tcriticality,
\r
127 String tthresholdCrossed,
\r
129 EVEL_EVENT_ACTION talertAction,
\r
130 String talertDescription,
\r
131 EVEL_ALERT_TYPE talertType,
\r
132 Date tcollectionTimestamp,
\r
133 EVEL_SEVERITIES teventSeverity,
\r
134 Date teventStartTimestamp)
\r
136 super(evname,evid);
\r
137 event_domain = EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING;
\r
138 assert( tcriticality!= null );
\r
139 assert( tname!= null );
\r
140 assert( tthresholdCrossed!= null );
\r
141 assert( tvalue!= null );
\r
142 assert( talertAction!= null );
\r
144 additionalParameters = new PERF_COUNTER();
\r
145 assert( additionalParameters != null);
\r
147 additionalParameters.criticality = tcriticality;
\r
148 additionalParameters.name = tname;
\r
149 additionalParameters.thresholdCrossed = tthresholdCrossed;
\r
150 additionalParameters.value = tvalue;
\r
151 alertAction = talertAction;
\r
152 alertDescription = talertDescription;
\r
153 alertType = talertType;
\r
154 collectionTimestamp = tcollectionTimestamp;
\r
155 eventSeverity = teventSeverity;
\r
156 eventStartTimestamp = teventStartTimestamp;
\r
158 additional_info = null;
\r
159 alertValue = new EvelOptionString();
\r
160 alertidList = null;
\r
161 dataCollector = new EvelOptionString();
\r
162 elementType = new EvelOptionString();
\r
163 interfaceName = new EvelOptionString();
\r
164 networkService = new EvelOptionString();
\r
165 possibleRootCause = new EvelOptionString();
\r
169 /**************************************************************************//**
\r
170 * Set the Event Type property of the TC Alert.
\r
172 * @note The property is treated as immutable: it is only valid to call
\r
173 * the setter once. However, we don't assert if the caller tries to
\r
174 * overwrite, just ignoring the update instead.
\r
176 * @param type The Event Type to be set. ASCIIZ string. The caller
\r
177 * does not need to preserve the value once the function
\r
179 *****************************************************************************/
\r
180 public void evel_thresholdcross_type_set(String type)
\r
184 /***************************************************************************/
\r
185 /* Check preconditions and call evel_header_type_set. */
\r
186 /***************************************************************************/
\r
187 assert(type!=null);
\r
188 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
189 evel_header_type_set(type);
\r
194 /**************************************************************************//**
\r
195 * Add an optional additional alertid value to Alert.
\r
197 *****************************************************************************/
\r
198 public void evel_thresholdcross_alertid_add(String alertid)
\r
202 /***************************************************************************/
\r
203 /* Check preconditions. */
\r
204 /***************************************************************************/
\r
205 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
206 assert(alertid != null);
\r
208 if( alertidList == null )
\r
210 alertidList = new ArrayList<String>();
\r
213 LOGGER.debug(MessageFormat.format("Adding alertid={0}", alertid));
\r
215 alertidList.add(new String(alertid));
\r
220 /**************************************************************************//**
\r
221 * Add an optional additional value name/value pair to the Alert.
\r
223 * The name and value are null delimited ASCII strings. The library takes
\r
224 * a copy so the caller does not have to preserve values after the function
\r
226 * @param name ASCIIZ string with the attribute's name. The caller
\r
227 * does not need to preserve the value once the function
\r
229 * @param value ASCIIZ string with the attribute's value. The caller
\r
230 * does not need to preserve the value once the function
\r
232 *****************************************************************************/
\r
233 public void evel_thresholdcross_addl_info_add(String name, String value)
\r
235 String[] addl_info = null;
\r
238 /***************************************************************************/
\r
239 /* Check preconditions. */
\r
240 /***************************************************************************/
\r
241 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
242 assert(name != null);
\r
243 assert(value != null);
\r
245 if( additional_info == null )
\r
247 additional_info = new ArrayList<String[]>();
\r
250 LOGGER.debug(MessageFormat.format("Adding name={0} value={1}", name, value));
\r
251 addl_info = new String[2];
\r
252 assert(addl_info != null);
\r
253 addl_info[0] = name;
\r
254 addl_info[1] = value;
\r
256 additional_info.add(addl_info);
\r
262 /**************************************************************************//**
\r
263 * Set the TCA probable Root cause.
\r
265 * @param sheader Possible root cause to Threshold
\r
266 *****************************************************************************/
\r
267 public void evel_threshold_cross_possible_rootcause_set(String sheader)
\r
271 /***************************************************************************/
\r
272 /* Check preconditions. */
\r
273 /***************************************************************************/
\r
274 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
276 assert(sheader != null);
\r
278 possibleRootCause.SetValuePr(
\r
280 "Rootcause value");
\r
284 /**************************************************************************//**
\r
285 * Set the TCA networking cause.
\r
287 * @param sheader Possible networking service value to Threshold
\r
288 *****************************************************************************/
\r
289 public void evel_threshold_cross_networkservice_set(String sheader)
\r
293 /***************************************************************************/
\r
294 /* Check preconditions. */
\r
295 /***************************************************************************/
\r
296 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
298 assert(sheader != null);
\r
300 networkService.SetValuePr(
\r
302 "Networking service value");
\r
306 /**************************************************************************//**
\r
307 * Set the TCA Interface name.
\r
309 * @param sheader Interface name to threshold
\r
310 *****************************************************************************/
\r
311 public void evel_threshold_cross_interfacename_set(String sheader)
\r
315 /***************************************************************************/
\r
316 /* Check preconditions. */
\r
317 /***************************************************************************/
\r
318 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
320 assert(sheader != null);
\r
322 interfaceName.SetValuePr(
\r
324 "TCA Interface name");
\r
328 /**************************************************************************//**
\r
329 * Set the TCA Data element type.
\r
331 * @param sheader element type of Threshold
\r
332 *****************************************************************************/
\r
333 public void evel_threshold_cross_data_elementtype_set(String sheader)
\r
337 /***************************************************************************/
\r
338 /* Check preconditions. */
\r
339 /***************************************************************************/
\r
340 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
342 assert(sheader != null);
\r
344 elementType.SetValuePr(
\r
346 "TCA Element type value");
\r
350 /**************************************************************************//**
\r
351 * Set the TCA Data collector value.
\r
353 * @param sheader Data collector value
\r
354 *****************************************************************************/
\r
355 public void evel_threshold_cross_data_collector_set(String sheader)
\r
359 /***************************************************************************/
\r
360 /* Check preconditions. */
\r
361 /***************************************************************************/
\r
362 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
364 assert(sheader != null);
\r
366 dataCollector.SetValuePr(
\r
368 "Datacollector value");
\r
374 /**************************************************************************//**
\r
375 * Set the TCA alert value.
\r
377 * @param sheader Possible alert value
\r
378 *****************************************************************************/
\r
379 public void evel_threshold_cross_alertvalue_set(String sheader)
\r
383 /***************************************************************************/
\r
384 /* Check preconditions. */
\r
385 /***************************************************************************/
\r
386 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
388 assert(sheader != null);
\r
390 alertValue.SetValuePr(
\r
397 /**************************************************************************//**
\r
398 * Encode the fault in JSON according to AT&T's schema for the TC ALert type.
\r
400 * @retvalue JSON object of TC Alert encoding
\r
401 *****************************************************************************/
\r
402 JsonObjectBuilder evelThresholdCrossingObject()
\r
404 double version = major_version+(double)minor_version/10;
\r
409 /***************************************************************************/
\r
410 /* Check preconditions. */
\r
411 /***************************************************************************/
\r
412 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
414 /***************************************************************************/
\r
415 /* Mandatory fields. */
\r
416 /***************************************************************************/
\r
418 JsonObjectBuilder counterobj = Json.createObjectBuilder()
\r
419 .add( "criticality",additionalParameters.criticality)
\r
420 .add( "name", additionalParameters.name)
\r
421 .add( "thresholdCrossed",additionalParameters.thresholdCrossed)
\r
422 .add( "value", additionalParameters.value);
\r
425 JsonObjectBuilder evelrep = Json.createObjectBuilder()
\r
426 .add("additionalParameters", counterobj)
\r
427 .add("alertAction", alertAction.toString())
\r
428 .add("alertDescription", alertDescription)
\r
429 .add("alertType", alertType.toString())
\r
430 .add("collectionTimestamp", collectionTimestamp.toString())
\r
431 .add("eventSeverity",eventSeverity.toString())
\r
432 .add("eventStartTimestamp",eventStartTimestamp.toString());
\r
434 /***************************************************************************/
\r
435 /* Optional fields. */
\r
436 /***************************************************************************/
\r
437 alertValue.encJsonValue(evelrep, "alertValue");
\r
438 if( alertidList != null && alertidList.size() > 0)
\r
440 JsonArrayBuilder builder = Json.createArrayBuilder();
\r
441 for(int i=0;i<alertidList.size();i++) {
\r
442 String addl_info = alertidList.get(i);
\r
443 JsonObject obj = Json.createObjectBuilder()
\r
444 .add("item",addl_info).build();
\r
447 evelrep.add("associatedAlertIdList", builder);
\r
450 dataCollector.encJsonValue(evelrep, "dataCollector");
\r
451 elementType.encJsonValue(evelrep, "elementType");
\r
452 interfaceName.encJsonValue(evelrep, "interfaceName");
\r
453 networkService.encJsonValue(evelrep, "networkService");
\r
454 possibleRootCause.encJsonValue(evelrep, "possibleRootCause");
\r
457 evelrep.add( "thresholdCrossingFieldsVersion", version);
\r
459 if( additional_info != null )
\r
461 JsonArrayBuilder builder = Json.createArrayBuilder();
\r
462 for(int i=0;i<additional_info.size();i++) {
\r
463 String[] addl_info = additional_info.get(i);
\r
464 JsonObject obj = Json.createObjectBuilder()
\r
465 .add("name", addl_info[0])
\r
466 .add("value", addl_info[1]).build();
\r
469 evelrep.add("additionalFields", builder);
\r
479 /**************************************************************************//**
\r
480 * Encode the event as a JSON event object according to AT&T's schema.
\r
481 * retval : String of JSON TCA event message
\r
482 *****************************************************************************/
\r
483 String evel_json_encode_event()
\r
487 assert(event_domain == EvelHeader.DOMAINS.EVEL_DOMAIN_THRESHOLD_CROSSING);
\r
489 JsonObject obj = Json.createObjectBuilder()
\r
490 .add("event", Json.createObjectBuilder()
\r
491 .add( "commonEventHeader",eventHeaderObject() )
\r
492 .add( "thresholdCrossingAlert",evelThresholdCrossingObject() )
\r
497 return obj.toString();
\r