William Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 1 | /* |
William Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 2 | * 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 Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 16 | package ves;
|
| 17 |
|
| 18 | import evel_javalibrary.att.com.*;
|
| 19 | import evel_javalibrary.att.com.AgentMain.EVEL_ERR_CODES;
|
| 20 | import evel_javalibrary.att.com.EvelFault.EVEL_SEVERITIES;
|
| 21 | import evel_javalibrary.att.com.EvelFault.EVEL_SOURCE_TYPES;
|
| 22 | import evel_javalibrary.att.com.EvelFault.EVEL_VF_STATUSES;
|
| 23 | import evel_javalibrary.att.com.EvelHeader.PRIORITIES;
|
| 24 | import evel_javalibrary.att.com.EvelMobileFlow.MOBILE_GTP_PER_FLOW_METRICS;
|
| 25 | import evel_javalibrary.att.com.EvelScalingMeasurement.MEASUREMENT_CPU_USE;
|
| 26 | import evel_javalibrary.att.com.EvelScalingMeasurement.MEASUREMENT_VNIC_PERFORMANCE;
|
| 27 | import evel_javalibrary.att.com.EvelStateChange.EVEL_ENTITY_STATE;
|
| 28 | import evel_javalibrary.att.com.EvelThresholdCross.EVEL_ALERT_TYPE;
|
| 29 | import evel_javalibrary.att.com.EvelThresholdCross.EVEL_EVENT_ACTION;
|
| 30 | import java.net.HttpURLConnection;
|
| 31 |
|
| 32 | import org.apache.log4j.Level;
|
| 33 | import config.Config;
|
| 34 |
|
William Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 35 | import mapper.VesVolthaMapper;
|
| 36 | import mapper.VesVolthaMessage;
|
| 37 |
|
William Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 38 | import org.slf4j.Logger;
|
| 39 | import org.slf4j.LoggerFactory;
|
William Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 40 | import com.google.gson.JsonSyntaxException;
|
William Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 41 |
|
| 42 | public class VesAgent {
|
| 43 |
|
William Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 44 | private static final Logger logger = LoggerFactory.getLogger("VesAgent");
|
William Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 45 |
|
William Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 46 | 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 Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 53 | 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 Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 62 | } catch( Exception e ) {
|
| 63 | e.printStackTrace();
|
| 64 | }
|
William Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 65 | }
|
William Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 66 |
|
William Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 67 | 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 Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 88 | EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH,
|
William Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 89 | vesSeverity,
|
| 90 | vesType,
|
William Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 91 | EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE);
|
William Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 92 | 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 Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 96 |
|
William Kurkian | 1bedb41 | 2018-07-19 12:55:41 -0400 | [diff] [blame^] | 97 | 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 Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame] | 120 | }
|