William Kurkian | bde6fc9 | 2018-07-13 17:19:58 -0400 | [diff] [blame^] | 1 | /* |
| 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 | */ |
| 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 |
|
| 35 | import org.slf4j.Logger;
|
| 36 | import org.slf4j.LoggerFactory;
|
| 37 |
|
| 38 | public class VesAgent {
|
| 39 |
|
| 40 | private static final Logger logger = LoggerFactory.getLogger("VesAgent");
|
| 41 |
|
| 42 | public static void initVes() {
|
| 43 | logger.info("Initializing VES Agent");
|
| 44 | try {
|
| 45 | AgentMain.evel_initialize("http://"+Config.getVesAddress(),
|
| 46 | Integer.parseInt(Config.getVesPort()),
|
| 47 | // "http://1.2.3.4", 8080,
|
| 48 | //"/vendor_event_listener","/example_vnf",
|
| 49 | null,null,
|
| 50 | "will",
|
| 51 | "pill",
|
| 52 | null, null, null,
|
| 53 | //"/home/gokul/newwk/demo/vnfs/VES5.0/evel/sslcerts2/my-keystore.jks", "changeit", "changeit",
|
| 54 | Level.TRACE);
|
| 55 | } catch( Exception e ) {
|
| 56 | e.printStackTrace();
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | public static boolean sendToVES(String json) {
|
| 61 |
|
| 62 | EvelFault flt = new EvelFault("Fault_VOLTHA_failed", "tbd_event_key_unique_to_source",
|
| 63 | "NIC error", "Hardware failed",
|
| 64 | EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH,
|
| 65 | EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR,
|
| 66 | EVEL_SOURCE_TYPES.EVEL_SOURCE_CARD,
|
| 67 | EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE);
|
| 68 | flt.evel_fault_addl_info_add("voltha", json);
|
| 69 | //flt.evel_fault_addl_info_add("nicsw", "fail");
|
| 70 | flt.evel_fault_category_set("Communication");
|
| 71 | logger.info("Sending fault event");
|
| 72 | int code = AgentMain.evel_post_event_immediate(flt);
|
| 73 | logger.info("Fault event http code received: " + code);
|
| 74 | if(code == 0 || code >= HttpURLConnection.HTTP_BAD_REQUEST )
|
| 75 | {
|
| 76 | return false;
|
| 77 | } else {
|
| 78 | return true;
|
| 79 | }
|
| 80 | }
|
| 81 |
|
| 82 | }
|