blob: a9a723d41fb6ab0c3378044a2436fd15ab468551 [file] [log] [blame]
William Kurkianbde6fc92018-07-13 17:19:58 -04001/*
William Kurkian1bedb412018-07-19 12:55:41 -04002* Copyright 2018- Cisco
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*/
William Kurkianbde6fc92018-07-13 17:19:58 -040016package ves;
17
18import evel_javalibrary.att.com.*;
19import evel_javalibrary.att.com.AgentMain.EVEL_ERR_CODES;
20import evel_javalibrary.att.com.EvelFault.EVEL_SEVERITIES;
21import evel_javalibrary.att.com.EvelFault.EVEL_SOURCE_TYPES;
22import evel_javalibrary.att.com.EvelFault.EVEL_VF_STATUSES;
23import evel_javalibrary.att.com.EvelHeader.PRIORITIES;
24import evel_javalibrary.att.com.EvelMobileFlow.MOBILE_GTP_PER_FLOW_METRICS;
25import evel_javalibrary.att.com.EvelScalingMeasurement.MEASUREMENT_CPU_USE;
26import evel_javalibrary.att.com.EvelScalingMeasurement.MEASUREMENT_VNIC_PERFORMANCE;
27import evel_javalibrary.att.com.EvelStateChange.EVEL_ENTITY_STATE;
28import evel_javalibrary.att.com.EvelThresholdCross.EVEL_ALERT_TYPE;
29import evel_javalibrary.att.com.EvelThresholdCross.EVEL_EVENT_ACTION;
30import java.net.HttpURLConnection;
31
32import org.apache.log4j.Level;
33import config.Config;
34
William Kurkian1bedb412018-07-19 12:55:41 -040035import mapper.VesVolthaMapper;
36import mapper.VesVolthaMessage;
37
William Kurkianbde6fc92018-07-13 17:19:58 -040038import org.slf4j.Logger;
39import org.slf4j.LoggerFactory;
William Kurkian1bedb412018-07-19 12:55:41 -040040import com.google.gson.JsonSyntaxException;
William Kurkianbde6fc92018-07-13 17:19:58 -040041
42public class VesAgent {
43
William Kurkian1bedb412018-07-19 12:55:41 -040044 private static final Logger logger = LoggerFactory.getLogger("VesAgent");
William Kurkianbde6fc92018-07-13 17:19:58 -040045
William Kurkian1bedb412018-07-19 12:55:41 -040046 private static VesVolthaMapper mapper;
47
48 public static void initVes() {
49 logger.info("Initializing VES Agent");
50 try {
51 mapper = new VesVolthaMapper();
52 AgentMain.evel_initialize("http://"+Config.getVesAddress(),
William Kurkianbde6fc92018-07-13 17:19:58 -040053 Integer.parseInt(Config.getVesPort()),
54 // "http://1.2.3.4", 8080,
55 //"/vendor_event_listener","/example_vnf",
56 null,null,
57 "will",
58 "pill",
59 null, null, null,
60 //"/home/gokul/newwk/demo/vnfs/VES5.0/evel/sslcerts2/my-keystore.jks", "changeit", "changeit",
61 Level.TRACE);
William Kurkian1bedb412018-07-19 12:55:41 -040062 } catch( Exception e ) {
63 e.printStackTrace();
64 }
William Kurkianbde6fc92018-07-13 17:19:58 -040065 }
William Kurkianbde6fc92018-07-13 17:19:58 -040066
William Kurkian1bedb412018-07-19 12:55:41 -040067 public static boolean sendToVES(String json) throws JsonSyntaxException {
68 VesVolthaMessage message = mapper.parseJson(json);
69 String id = message.getId();
70 String ldeviceId = message.getLogicalDeviceId();
71 String ts = message.getRaisedTS();
72 String description = message.getDescription();
73 //Type in Voltha needs to be category in VES
74 String category = message.getType();
75 //Category in VOLTHA needs to be type in VES
76 String type = message.getCategory();
77 String severity = message.getSeverity();
78 String state = message.getState();
79 String resourceId = message.getResourceId();
80
81 EVEL_SEVERITIES vesSeverity = mapSeverity(severity);
82 EVEL_SOURCE_TYPES vesType = mapType(type);
83 EvelFault flt = new EvelFault(
84 "Fault_VOLTHA_" + id,
85 ldeviceId + ":" + ts,
86 id,
87 description,
William Kurkianbde6fc92018-07-13 17:19:58 -040088 EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH,
William Kurkian1bedb412018-07-19 12:55:41 -040089 vesSeverity,
90 vesType,
William Kurkianbde6fc92018-07-13 17:19:58 -040091 EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE);
William Kurkian1bedb412018-07-19 12:55:41 -040092 flt.evel_fault_addl_info_add("voltha", json);
93 flt.evel_fault_addl_info_add("state", state);
94 flt.evel_fault_addl_info_add("resourceId", resourceId);
95 flt.evel_fault_category_set(category);
William Kurkianbde6fc92018-07-13 17:19:58 -040096
William Kurkian1bedb412018-07-19 12:55:41 -040097 logger.info("Sending fault event");
98 int code = AgentMain.evel_post_event_immediate(flt);
99 logger.info("Fault event http code received: " + code);
100 if(code == 0 || code >= HttpURLConnection.HTTP_BAD_REQUEST ) {
101 return false;
102 } else {
103 return true;
104 }
105 }
106
107 private static EVEL_SEVERITIES mapSeverity(String severity) {
108 String severityUpper = severity.toUpperCase();
109 switch (severityUpper) {
110 case "INDETERMINATE":
111 return EVEL_SEVERITIES.EVEL_SEVERITY_NORMAL;
112 default:
113 return EVEL_SEVERITIES.valueOf("EVEL_SEVERITY_" + severityUpper);
114 }
115 }
116
117 private static EVEL_SOURCE_TYPES mapType(String type) {
118 return EVEL_SOURCE_TYPES.valueOf("EVEL_SOURCE_" + type.toUpperCase());
119 }
William Kurkianbde6fc92018-07-13 17:19:58 -0400120}