diff options
Diffstat (limited to 'veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance')
22 files changed, 2609 insertions, 803 deletions
diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/DeviceData.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/DeviceData.java new file mode 100644 index 0000000..94f9c4e --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/DeviceData.java @@ -0,0 +1,118 @@ +package evel_javalibrary.att.com.loadbalance; +/**************************************************************************//** + * @file + * Measurement class + * + * This file implements the Measurement Event class which is intended to provide a + * simple wrapper around the complexity of AT&T's Vendor Event Listener API so + * that VNFs can use it to send CPU, Memory, Disk Measurements to Collector. + * + * License + * ------- + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +import java.io.Serializable; + +public class DeviceData implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = 1L; + private String t0bytesIn; + private String t0bytesOut; + private String t0packetIn; + private String t0packetOut; + + private String t1Bytesin; + private String t1Bytesout; + private String t1Packetsin; + private String t1Packetsout; + + private String Instanceres02Command; + + public String getT0bytesIn() { + return t0bytesIn; + } + + public void setT0bytesIn(String t0bytesIn) { + this.t0bytesIn = t0bytesIn; + } + + public String getT0bytesOut() { + return t0bytesOut; + } + + public void setT0bytesOut(String t0bytesOut) { + this.t0bytesOut = t0bytesOut; + } + + public String getT0packetIn() { + return t0packetIn; + } + + public void setT0packetIn(String t0packetIn) { + this.t0packetIn = t0packetIn; + } + + public String getT0packetOut() { + return t0packetOut; + } + + public void setT0packetOut(String t0packetOut) { + this.t0packetOut = t0packetOut; + } + + public String getT1Bytesin() { + return t1Bytesin; + } + + public void setT1Bytesin(String t1Bytesin) { + this.t1Bytesin = t1Bytesin; + } + + public String getT1Bytesout() { + return t1Bytesout; + } + + public void setT1Bytesout(String t1Bytesout) { + this.t1Bytesout = t1Bytesout; + } + + public String getT1Packetsin() { + return t1Packetsin; + } + + public void setT1Packetsin(String t1Packetsin) { + this.t1Packetsin = t1Packetsin; + } + + public String getT1Packetsout() { + return t1Packetsout; + } + + public void setT1Packetsout(String t1Packetsout) { + this.t1Packetsout = t1Packetsout; + } + + public String getInstanceres02Command() { + return Instanceres02Command; + } + + public void setInstanceres02Command(String instanceres02Command) { + Instanceres02Command = instanceres02Command; + } + + +}
\ No newline at end of file diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/FaultData.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/FaultData.java new file mode 100644 index 0000000..6329ee7 --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/FaultData.java @@ -0,0 +1,1228 @@ +package evel_javalibrary.att.com.loadbalance; +/**************************************************************************//** + * @file + * Evel Fault Event class extends EvelHeader class + * + * This file implements the Evel Fault Event class which is intended to provide a + * simple wrapper around the complexity of AT&T's Vendor Event Listener API so + * that VNFs can use it to send Fault events. + * + * License + * ------- + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + + +import org.apache.log4j.Level; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import evel_javalibrary.att.com.AgentMain; +import evel_javalibrary.att.com.EvelBatch; +import evel_javalibrary.att.com.EvelFault; +import evel_javalibrary.att.com.EvelFault.EVEL_SEVERITIES; +import evel_javalibrary.att.com.EvelFault.EVEL_SOURCE_TYPES; +import evel_javalibrary.att.com.EvelFault.EVEL_VF_STATUSES; +import evel_javalibrary.att.com.EvelHeader; + + + +public class FaultData{ + + + static HashMap<String, String> fault_config = new HashMap<>(); + static HashMap<String, String> interface_config = new HashMap<>(); + + static HashMap<String, String> faultConfig = new HashMap<>(); + + static HashMap<String, String> faultInstanceres01 = new HashMap<>(); + static HashMap<String, String> faultInstanceres02 = new HashMap<>(); + static HashMap<String, String> tempAlaramClearParameter = new HashMap<>(); + + + static HashMap<String, String> Instanceres02ClearParameter = new HashMap<>(); + + + static String[] resDevice =null; + static String[] tempInitres; + static String[] tempcommandres; + static String[] tempcommand02res; + static HashMap<String, String> faultConfigTempInit = new HashMap<>(); + static HashMap<String, String> faultConfigCommand = new HashMap<>(); + static String alarmCondition =""; + static String specificProblem = ""; + static String eventSeverity=""; + static String alarmInterfaceA =""; + + static String alarmConditionClear =""; + static String specificProblemClear = ""; + static String eventSeverityClear=""; + + static String Instance02alarmInterfaceA; + static String Instance02eventCategory; + static String Instance02eventSourceType; + static String Instance02eventName; + + static String ins02alarmConditionClear; + static String ins02specificProblemClear; + static String ins02eventSeverityClear; + + static String setAlarmCondition; + static String setSpecificProblem; + static String setEventSeverity; + + static String eventCategory =""; + static String eventSourceType =""; + static HashMap<String, String> hm = new HashMap<>(); + + static String linkStart = ""; + static int linkCount; + static String event_id1 = "fault"; + static String event_id = "00000000"; + static float bytes_in; + static float bytes_out; + static float packets_in; + static float packets_out; + + static float ins02Cmd; + + + static int falut_raised =0; + + + public final Runnable faultInstance01; + public final Runnable faultInstance02; + + public FaultData(){ + + faultInstance01 = new Runnable() { + + @Override + public void run() { + int gm_event_id = 1; + String event_id2=null; + + Long start_epoch_microsec = 0L; + Long last_epoch_microsec = 0L; + String hostName = hostName(); + try { + readFalutConfig(); + readVppMetrics(resDevice); + } catch (IOException | ParseException e1) { + + } + + + String[] intFaceMapFault = resDevice; + int numOfInterfacesFalut = 0; + if( intFaceMapFault != null) + numOfInterfacesFalut = intFaceMapFault.length; + if( numOfInterfacesFalut <= 0) { + + return; + } + + HashMap<String, DeviceData> falut_last_metrics = readVppMetrics(resDevice); + + while(true) { + try { + EvelBatch ebt = new EvelBatch(); + + for( String falut : intFaceMapFault ) { + + HashMap<String, DeviceData> falut_current_metrics = readVppMetrics(resDevice); + + + for( String tmp_device :falut_current_metrics.keySet() ) { + + + + int receivedOctetsDelta = Integer.parseInt((falut_current_metrics.get(tmp_device).getT1Bytesin()) ) + - Integer.parseInt((falut_last_metrics.get(tmp_device).getT0bytesIn())); + + int receivedTotalPacketsDelta = Integer.parseInt((falut_current_metrics.get(tmp_device).getT1Packetsin()) ) + - Integer.parseInt((falut_last_metrics.get(tmp_device).getT0packetIn())); + + int transmittedOctetsDelta = Integer.parseInt((falut_current_metrics.get(tmp_device).getT1Bytesout()) ) + - Integer.parseInt((falut_last_metrics.get(tmp_device).getT0bytesOut())); + + + + int transmittedTotalPacketsDelta = Integer.parseInt((falut_current_metrics.get(tmp_device).getT1Packetsout()) ) + - Integer.parseInt((falut_last_metrics.get(tmp_device).getT0packetOut())); + + + String alarmInterface = tmp_device; //resDevice[0]; + if((receivedOctetsDelta < Integer.parseInt((String)faultInstanceres01.get("tmp_lowWaterMark")) || transmittedOctetsDelta < Integer.parseInt((String)faultInstanceres01.get("tmp_lowWaterMark")) || + receivedTotalPacketsDelta < Integer.parseInt((String)faultInstanceres01.get("tmp_lowWaterMark")) || transmittedTotalPacketsDelta < Integer.parseInt((String)faultInstanceres01.get("tmp_lowWaterMark"))) && falut_raised == 0){ + event_id2 = event_id1+ event_id+(gm_event_id++); + EvelFault eveFalt = new EvelFault(faultInstanceres01.get("eventName"),event_id2, alarmCondition, specificProblem, + EvelHeader.PRIORITIES.EVEL_PRIORITY_LOW, + EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR, + EVEL_SOURCE_TYPES.EVEL_SOURCE_ROUTER, + EVEL_VF_STATUSES.EVEL_VF_STATUS_IDLE); + if(eveFalt != null) { + + falut_raised =1; + + if( faultConfig.get("eventType")!=null) { + eveFalt.evel_fault_type_set(faultConfig.get("eventType")); + + start_epoch_microsec = last_epoch_microsec; + last_epoch_microsec = System.nanoTime()/1000; + + eveFalt.evel_last_epoch_set(start_epoch_microsec); + eveFalt.evel_start_epoch_set(last_epoch_microsec); + + eveFalt.evel_fault_category_set(eventCategory); + eveFalt.evel_fault_interface_set(alarmInterface.replaceAll("^[\"']+|[\"']+$", "")); + eveFalt.evel_nfcnamingcode_set(faultConfig.get("nfcNamingCode").toString()); + eveFalt.evel_nfnamingcode_set(faultConfig.get("nfNamingCode").toString()); + if(faultConfig.get("reportingEntityName") == null) { + eveFalt.evel_reporting_entity_name_set(hostName); + }else { + eveFalt.evel_reporting_entity_name_set(faultConfig.get("reportingEntityName").toString()); + } + eveFalt.evel_reporting_entity_id_set(faultConfig.get("reportingEntityId").toString()); + eveFalt.evel_nfVendorName_set(faultConfig.get("nfVendorName").toString()); + eveFalt.evel_header_set_sourceid(true,faultConfig.get("sourceId").toString()); + + if(faultConfig.get("sourceName") == null) { + eveFalt.evel_header_set_source_name(hostName); + }else { + eveFalt.evel_header_set_source_name(faultConfig.get("sourceName").toString()); + } + + eveFalt.evel_timeZoneOffset_set(faultConfig.get("timeZoneOffset").toString()); + AgentMain.evel_post_event(eveFalt); + } + + } + + }else if((receivedOctetsDelta > Integer.parseInt((String)faultInstanceres01.get("tmp_lowWaterMark")) && transmittedOctetsDelta > Integer.parseInt((String)faultInstanceres01.get("tmp_lowWaterMark")) && + receivedTotalPacketsDelta > Integer.parseInt((String)faultInstanceres01.get("tmp_lowWaterMark")) && transmittedTotalPacketsDelta > Integer.parseInt((String)faultInstanceres01.get("tmp_lowWaterMark"))) && falut_raised == 1) { + + event_id2 = event_id1+event_id+ (gm_event_id++); + EvelFault eveFalt = new EvelFault(faultInstanceres01.get("eventName"),event_id2, alarmConditionClear, specificProblemClear, + EvelHeader.PRIORITIES.EVEL_PRIORITY_LOW, + EVEL_SEVERITIES.EVEL_SEVERITY_NORMAL, + EVEL_SOURCE_TYPES.EVEL_SOURCE_ROUTER, + EVEL_VF_STATUSES.EVEL_VF_STATUS_IDLE); + + + + if(eveFalt != null) { + falut_raised =1; + + if( faultConfig.get("eventType")!=null) { + eveFalt.evel_fault_type_set(faultConfig.get("eventType")); + eveFalt.evel_fault_category_set(eventCategory); + eveFalt.evel_fault_interface_set(alarmInterface.replaceAll("^[\"']+|[\"']+$", "")); + + eveFalt.evel_nfcnamingcode_set(faultConfig.get("nfcNamingCode").toString()); + eveFalt.evel_nfnamingcode_set(faultConfig.get("nfNamingCode").toString()); + + if(faultConfig.get("reportingEntityName") == null) { + eveFalt.evel_reporting_entity_name_set(hostName); + }else { + eveFalt.evel_reporting_entity_name_set(faultConfig.get("reportingEntityName").toString()); + } + + + eveFalt.evel_reporting_entity_id_set(faultConfig.get("reportingEntityId").toString()); + eveFalt.evel_nfVendorName_set(faultConfig.get("nfVendorName").toString()); + eveFalt.evel_header_set_sourceid(true,faultConfig.get("sourceId").toString()); + + if(faultConfig.get("sourceName") == null) { + eveFalt.evel_header_set_source_name(hostName); + }else { + eveFalt.evel_header_set_source_name(faultConfig.get("sourceName").toString()); + } + + + eveFalt.evel_timeZoneOffset_set(faultConfig.get("timeZoneOffset").toString()); + AgentMain.evel_post_event(eveFalt); + + } + + } + + + + } + + + try { + String Ins01Interval=""; + long milliseconds = 60000; + if(faultInstanceres01.get("tmp_faultCheckInterval") == null) { + Ins01Interval = Long.toString(milliseconds); + }else { + Ins01Interval = faultInstanceres01.get("tmp_faultCheckInterval"); + } + Thread.sleep(Integer.parseInt(Ins01Interval)); + }catch(Exception e) {} + + } //for map keyset + + } //for intFaceMapFault + + + }catch (Exception e) { + + } + + + } + } + }; + + faultInstance02 = new Runnable() { + + @Override + public void run() { + int gm_event_id = 1; + String event_id2=null; + Long start_epoch_microsec = 0L; + Long last_epoch_microsec = 0L; + String hostName = hostName(); + try { + readFalutConfig(); + readVppMetrics(resDevice); + } catch (IOException | ParseException e1) { + + } + + + String[] intFaceMapFault = resDevice; + int numOfInterfacesFalut = 0; + if( intFaceMapFault != null) + numOfInterfacesFalut = intFaceMapFault.length; + if( numOfInterfacesFalut <= 0) { + + return; + } + + HashMap<String, DeviceData> falut_last_metrics = readVppMetrics(resDevice); + + while(true) { + try { + EvelBatch ebt = new EvelBatch(); + + HashMap<String, DeviceData> falutMetric = readVppMetrics(resDevice); + DeviceData mdGetdata = new DeviceData(); + String ins02cmd = mdGetdata.getInstanceres02Command(); + + + if(ins02Cmd < Integer.parseInt((String)falutMetric.get("Instanceres02Cmd").getInstanceres02Command())){ + + event_id2 = event_id1+ event_id+(gm_event_id++); + EvelFault eveFalt = new EvelFault(Instance02eventName,event_id2, setAlarmCondition, setSpecificProblem, + EvelHeader.PRIORITIES.EVEL_PRIORITY_LOW, + EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR, + EVEL_SOURCE_TYPES.EVEL_SOURCE_VIRTUAL_MACHINE, + EVEL_VF_STATUSES.EVEL_VF_STATUS_IDLE); + + + if(eveFalt != null) { + + falut_raised =1; + + + + if( faultConfig.get("eventType")!=null) { + eveFalt.evel_fault_type_set(faultConfig.get("eventType")); + + start_epoch_microsec = last_epoch_microsec; + last_epoch_microsec = System.nanoTime()/1000; + + eveFalt.evel_last_epoch_set(start_epoch_microsec); + eveFalt.evel_start_epoch_set(last_epoch_microsec); + + eveFalt.evel_fault_category_set(Instance02eventCategory); + eveFalt.evel_fault_interface_set(Instance02alarmInterfaceA.replaceAll("^[\"']+|[\"']+$", "")); + + eveFalt.evel_nfcnamingcode_set(faultConfig.get("nfcNamingCode").toString()); + eveFalt.evel_nfnamingcode_set(faultConfig.get("nfNamingCode").toString()); + + if(faultConfig.get("reportingEntityName") == null) { + eveFalt.evel_reporting_entity_name_set(hostName); + }else { + eveFalt.evel_reporting_entity_name_set(faultConfig.get("reportingEntityName").toString()); + } + + + eveFalt.evel_reporting_entity_id_set(faultConfig.get("reportingEntityId").toString()); + eveFalt.evel_nfVendorName_set(faultConfig.get("nfVendorName").toString()); + eveFalt.evel_header_set_sourceid(true,faultConfig.get("sourceId").toString()); + + if(faultConfig.get("sourceName") == null) { + eveFalt.evel_header_set_source_name(hostName); + }else { + eveFalt.evel_header_set_source_name(faultConfig.get("sourceName").toString()); + } + + eveFalt.evel_timeZoneOffset_set(faultConfig.get("timeZoneOffset").toString()); + AgentMain.evel_post_event(eveFalt); + } + + } + + }else if(ins02Cmd > Integer.parseInt((String)falutMetric.get("Instanceres02Cmd").getInstanceres02Command())) { + + + event_id2 = event_id1+ event_id+(gm_event_id++); + EvelFault eveFalt = new EvelFault(Instance02eventName,event_id2, ins02alarmConditionClear, ins02specificProblemClear, + EvelHeader.PRIORITIES.EVEL_PRIORITY_LOW, + EVEL_SEVERITIES.EVEL_SEVERITY_NORMAL, + EVEL_SOURCE_TYPES.EVEL_SOURCE_VIRTUAL_MACHINE, + EVEL_VF_STATUSES.EVEL_VF_STATUS_IDLE); + + + + if(eveFalt != null) { + falut_raised =1; + + if( faultConfig.get("eventType")!=null) { + eveFalt.evel_fault_type_set(faultConfig.get("eventType")); + eveFalt.evel_fault_category_set(Instance02eventCategory); + eveFalt.evel_fault_interface_set(Instance02alarmInterfaceA.replaceAll("^[\"']+|[\"']+$", "")); + + eveFalt.evel_nfcnamingcode_set(faultConfig.get("nfcNamingCode").toString()); + eveFalt.evel_nfnamingcode_set(faultConfig.get("nfNamingCode").toString()); + + if(faultConfig.get("reportingEntityName") == null) { + eveFalt.evel_reporting_entity_name_set(hostName); + }else { + eveFalt.evel_reporting_entity_name_set(faultConfig.get("reportingEntityName").toString()); + } + + + eveFalt.evel_reporting_entity_id_set(faultConfig.get("reportingEntityId").toString()); + eveFalt.evel_nfVendorName_set(faultConfig.get("nfVendorName").toString()); + eveFalt.evel_header_set_sourceid(true,faultConfig.get("sourceId").toString()); + + if(faultConfig.get("sourceName") == null) { + eveFalt.evel_header_set_source_name(hostName); + }else { + eveFalt.evel_header_set_source_name(faultConfig.get("sourceName").toString()); + } + + + eveFalt.evel_timeZoneOffset_set(faultConfig.get("timeZoneOffset").toString()); + AgentMain.evel_post_event(eveFalt); + + } + + } + + + + } + + + try { + String Ins02Interval=""; + long milliseconds = 60000; + if(faultInstanceres02.get("tmp_faultCheckInterval") == null) { + Ins02Interval = Long.toString(milliseconds); + }else { + Ins02Interval = faultInstanceres02.get("tmp_faultCheckInterval"); + } + Thread.sleep(Integer.parseInt(Ins02Interval)); + }catch(Exception e) { + + } + + }catch (Exception e) { + + } + + + } + } + }; + + } + private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); + private static String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for ( int j = 0; j < bytes.length; j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + public static String hostName() { + String hostname = "Unknown"; + String uuid = "Unknown"; + try + { + InetAddress addr; + addr = InetAddress.getLocalHost(); + hostname = addr.getHostName(); + } + catch (UnknownHostException ex) + { + + } + try{ + Enumeration<NetworkInterface> networks = + NetworkInterface.getNetworkInterfaces(); + while(networks.hasMoreElements()) { + NetworkInterface network = networks.nextElement(); + byte[] mac = network.getHardwareAddress(); + + if(hostname.equalsIgnoreCase("unknown")) + { + Enumeration inetAddrs = network.getInetAddresses(); + while(inetAddrs.hasMoreElements()){ + InetAddress inetAddr = (InetAddress) inetAddrs.nextElement(); + if (!inetAddr.isLoopbackAddress()) { + hostname = inetAddr.getHostAddress(); + break; + } + } + } + if (mac != null) { + uuid = bytesToHex(mac); + } + } + } catch (SocketException e) { + // TODO Auto-generated catch block + + } + + return hostname; + } + + + + public static HashMap<String, String> readFalutConfig() throws IOException, ParseException { + + System.out.println("readFalutConfig calling out lo:"); + + List<String> list = new ArrayList<String>(); + JSONParser jsonParser = new JSONParser(); + try { + + FileReader reader = new FileReader("./src/main/java/evel_javalibrary/att/com/loadbalance/flt_config.json"); + JSONObject obj = (JSONObject) jsonParser.parse(reader); + Map.Entry directPair = null; + String directObject =""; + String[] directres; + Map directParameters = ((Map)obj.get("tmp_directParameters")); + Iterator<Map.Entry> itr1 = directParameters.entrySet().iterator(); + while (itr1.hasNext()) { + directPair = itr1.next(); + directObject=String.valueOf(directPair); + directres = directObject.split("="); + faultConfig.put(directres[0], directres[1]); + } + JSONArray arrJson = (JSONArray) directParameters.get("tmp_device"); + resDevice = new String[arrJson.size()]; + for(int i = 0; i < arrJson.size(); i++) + resDevice[i] = (String) arrJson.get(i); + + + //tmp_indirectParameters + Map.Entry indirectPair = null; + String indirectObject =""; + String[] indirectres; + Map indirectParameters = ((Map)obj.get("tmp_indirectParameters")); + Iterator<Map.Entry> itr2 = indirectParameters.entrySet().iterator(); + while (itr2.hasNext()) { + indirectPair = itr2.next(); + indirectObject=String.valueOf(indirectPair); + indirectres = indirectObject.split("="); + faultConfig.put(indirectres[0], indirectres[1]); + } + + + //tmp_faultInstance01 + Map.Entry faultInstancePair = null; + String faultInstanceObject =""; + String[] faultInstanceres; + Map faultInstanceParameters = ((Map)indirectParameters.get("tmp_faultInstance01")); + Iterator<Map.Entry> itr3 = faultInstanceParameters.entrySet().iterator(); + while (itr3.hasNext()) { + faultInstancePair = itr3.next(); + faultInstanceObject=String.valueOf(faultInstancePair); + faultInstanceres = faultInstanceObject.split("="); + faultInstanceres01.put(faultInstanceres[0], faultInstanceres[1]); + } + + + eventCategory = faultInstanceres01.get("eventCategory").toString(); + eventSourceType = faultInstanceres01.get("eventSourceType").toString(); + //tmp_init + Map.Entry tempInitPair = null; + String tempInitObject =""; + Map tempInitParameters = ((Map)faultInstanceParameters.get("tmp_init")); + Iterator<Map.Entry> itr4 = tempInitParameters.entrySet().iterator(); + while (itr4.hasNext()) { + tempInitPair = itr4.next(); + tempInitObject=String.valueOf(tempInitPair); + tempInitres = tempInitObject.split("="); + faultConfigTempInit.put(tempInitres[0], tempInitres[1]); + } + + String tmp_t0BytesOut = faultConfigTempInit.get("tmp_init"); + + + + //tmp_command + Map.Entry tempcommandPair = null; + String tempcommandObject =""; + Map tempcommandParameters = ((Map)faultInstanceParameters.get("tmp_command")); + Iterator<Map.Entry> itr5 = tempcommandParameters.entrySet().iterator(); + while (itr5.hasNext()) { + tempcommandPair = itr5.next(); + tempcommandObject=String.valueOf(tempcommandPair); + tempcommandres = tempcommandObject.split("="); + faultConfigCommand.put(tempcommandres[0], tempcommandres[1]); + } + + //tmp_alarmSetParameters + Map.Entry alarmSetPair = null; + String alarmSetObject =""; + String[] alarmSetres; + Map alarmSetParameters = ((Map)faultInstanceParameters.get("tmp_alarmSetParameters")); + Iterator<Map.Entry> itr6 = alarmSetParameters.entrySet().iterator(); + while (itr6.hasNext()) { + alarmSetPair = itr6.next(); + alarmSetObject=String.valueOf(alarmSetPair); + alarmSetres = alarmSetObject.split("="); + faultConfig.put(alarmSetres[0], alarmSetres[1]); + } + + + alarmCondition = faultConfig.get("alarmCondition").toString(); + specificProblem = faultConfig.get("specificProblem").toString(); + eventSeverity = faultConfig.get("eventSeverity").toString(); + + //tmp_alarmClearParameters + Map.Entry alarmClearPair = null; + String alarmClearObject =""; + String[] alarmClearres; + Map alarmClearParameters = ((Map)faultInstanceParameters.get("tmp_alarmClearParameters")); + Iterator<Map.Entry> itr7 = alarmClearParameters.entrySet().iterator(); + while (itr7.hasNext()) { + alarmClearPair = itr7.next(); + alarmClearObject=String.valueOf(alarmClearPair); + alarmClearres = alarmClearObject.split("="); + tempAlaramClearParameter.put(alarmClearres[0], alarmClearres[1]); + } + + alarmConditionClear = tempAlaramClearParameter.get("alarmCondition").toString(); + specificProblemClear = tempAlaramClearParameter.get("specificProblem").toString(); + eventSeverityClear = tempAlaramClearParameter.get("eventSeverity").toString(); + System.out.println("specificProblemClear data:"+ specificProblemClear); + + //tmp_faultInstance02 + Map.Entry faultInstance02Pair = null; + String faultInstance02Object =""; + String[] faultInstance02res; + Map faultInstance02Parameters = ((Map)indirectParameters.get("tmp_faultInstance02")); + Iterator<Map.Entry> itr8 = faultInstance02Parameters.entrySet().iterator(); + while (itr8.hasNext()) { + faultInstance02Pair = itr8.next(); + faultInstance02Object=String.valueOf(faultInstance02Pair); + faultInstance02res = faultInstance02Object.split("="); + faultInstanceres02.put(faultInstance02res[0], faultInstance02res[1]); + } + Instance02alarmInterfaceA = faultInstanceres02.get("alarmInterfaceA"); + Instance02eventCategory = faultInstanceres02.get("eventCategory"); + Instance02eventSourceType = faultInstanceres02.get("eventSourceType"); + Instance02eventName = faultInstanceres02.get("eventName"); + + //tmp_command + Map.Entry tempcommand02Pair = null; + String tempcommand02Object =""; + Map tempcommand02Parameters = ((Map)faultInstance02Parameters.get("tmp_command")); + Iterator<Map.Entry> itr9 = tempcommand02Parameters.entrySet().iterator(); + while (itr9.hasNext()) { + tempcommand02Pair = itr9.next(); + tempcommand02Object=String.valueOf(tempcommand02Pair); + tempcommand02res = tempcommand02Object.split("="); + faultInstanceres02.put(tempcommand02res[0], tempcommand02res[1]); + } + + + + //tmp_alarmSetParameters + Map.Entry Instance02alarmSetPair = null; + String Instance02alarmSetObject =""; + String[] Instance02alarmSetres; + Map Instance02alarmSetParameters = ((Map)faultInstance02Parameters.get("tmp_alarmSetParameters")); + Iterator<Map.Entry> itr10 = Instance02alarmSetParameters.entrySet().iterator(); + while (itr10.hasNext()) { + Instance02alarmSetPair = itr10.next(); + Instance02alarmSetObject=String.valueOf(Instance02alarmSetPair); + Instance02alarmSetres = Instance02alarmSetObject.split("="); + faultInstanceres02.put(Instance02alarmSetres[0], Instance02alarmSetres[1]); + } + + + setAlarmCondition = faultInstanceres02.get("alarmCondition").toString(); + setSpecificProblem = faultInstanceres02.get("specificProblem").toString(); + setEventSeverity = faultInstanceres02.get("eventSeverity").toString(); + + //tmp_alarmClearParameters + Map.Entry Instanceres02alarmClearPair = null; + String Instanceres02alarmClearObject =""; + String[] Instanceres02alarmClearres; + Map Instanceres02alarmClearParameters = ((Map)faultInstance02Parameters.get("tmp_alarmClearParameters")); + Iterator<Map.Entry> itr11 = Instanceres02alarmClearParameters.entrySet().iterator(); + while (itr11.hasNext()) { + Instanceres02alarmClearPair = itr11.next(); + Instanceres02alarmClearObject=String.valueOf(Instanceres02alarmClearPair); + Instanceres02alarmClearres = Instanceres02alarmClearObject.split("="); + Instanceres02ClearParameter.put(Instanceres02alarmClearres[0], Instanceres02alarmClearres[1]); + } + + ins02alarmConditionClear = Instanceres02ClearParameter.get("alarmCondition").toString(); + ins02specificProblemClear = Instanceres02ClearParameter.get("specificProblem").toString(); + ins02eventSeverityClear = Instanceres02ClearParameter.get("eventSeverity").toString(); + + + + + } catch (ClassCastException ex) { + ex.printStackTrace(); + } + return faultConfig; + } + + + + + public static HashMap<String, String> readFalutConfig1() throws IOException, ParseException { + List<String> list = new ArrayList<String>(); + JSONParser jsonParser = new JSONParser(); + try { + + FileReader reader = new FileReader("./src/main/java/evel_javalibrary/att/com/loadbalance/flt_config.json"); + JSONObject obj = (JSONObject) jsonParser.parse(reader); + Map.Entry directPair = null; + String directObject =""; + String[] directres; + Map directParameters = ((Map)obj.get("tmp_directParameters")); + Iterator<Map.Entry> itr1 = directParameters.entrySet().iterator(); + while (itr1.hasNext()) { + directPair = itr1.next(); + directObject=String.valueOf(directPair); + directres = directObject.split("="); + faultConfig.put(directres[0], directres[1]); + } + JSONArray arrJson = (JSONArray) directParameters.get("tmp_device"); + resDevice = new String[arrJson.size()]; + for(int i = 0; i < arrJson.size(); i++) + resDevice[i] = (String) arrJson.get(i); + + + //tmp_indirectParameters + Map.Entry indirectPair = null; + String indirectObject =""; + String[] indirectres; + Map indirectParameters = ((Map)obj.get("tmp_indirectParameters")); + Iterator<Map.Entry> itr2 = indirectParameters.entrySet().iterator(); + while (itr2.hasNext()) { + indirectPair = itr2.next(); + indirectObject=String.valueOf(indirectPair); + indirectres = indirectObject.split("="); + faultConfig.put(indirectres[0], indirectres[1]); + } + + + //tmp_faultInstance01 + Map.Entry faultInstancePair = null; + String faultInstanceObject =""; + String[] faultInstanceres; + Map faultInstanceParameters = ((Map)indirectParameters.get("tmp_faultInstance01")); + Iterator<Map.Entry> itr3 = faultInstanceParameters.entrySet().iterator(); + while (itr3.hasNext()) { + faultInstancePair = itr3.next(); + faultInstanceObject=String.valueOf(faultInstancePair); + faultInstanceres = faultInstanceObject.split("="); + faultInstanceres01.put(faultInstanceres[0], faultInstanceres[1]); + } + + + eventCategory = faultInstanceres01.get("eventCategory").toString(); + eventSourceType = faultInstanceres01.get("eventSourceType").toString(); + //tmp_init + Map.Entry tempInitPair = null; + String tempInitObject =""; + Map tempInitParameters = ((Map)faultInstanceParameters.get("tmp_init")); + Iterator<Map.Entry> itr4 = tempInitParameters.entrySet().iterator(); + while (itr4.hasNext()) { + tempInitPair = itr4.next(); + tempInitObject=String.valueOf(tempInitPair); + tempInitres = tempInitObject.split("="); + faultConfigTempInit.put(tempInitres[0], tempInitres[1]); + } + + String tmp_t0BytesOut = faultConfigTempInit.get("tmp_init"); + + + + //tmp_command + Map.Entry tempcommandPair = null; + String tempcommandObject =""; + Map tempcommandParameters = ((Map)faultInstanceParameters.get("tmp_command")); + Iterator<Map.Entry> itr5 = tempcommandParameters.entrySet().iterator(); + while (itr5.hasNext()) { + tempcommandPair = itr5.next(); + tempcommandObject=String.valueOf(tempcommandPair); + tempcommandres = tempcommandObject.split("="); + faultConfig.put(tempcommandres[0], tempcommandres[1]); + } + + //tmp_alarmSetParameters + Map.Entry alarmSetPair = null; + String alarmSetObject =""; + String[] alarmSetres; + Map alarmSetParameters = ((Map)faultInstanceParameters.get("tmp_alarmSetParameters")); + Iterator<Map.Entry> itr6 = alarmSetParameters.entrySet().iterator(); + while (itr6.hasNext()) { + alarmSetPair = itr6.next(); + alarmSetObject=String.valueOf(alarmSetPair); + alarmSetres = alarmSetObject.split("="); + faultConfig.put(alarmSetres[0], alarmSetres[1]); + } + + + alarmCondition = faultConfig.get("alarmCondition").toString(); + specificProblem = faultConfig.get("specificProblem").toString(); + eventSeverity = faultConfig.get("eventSeverity").toString(); + + //tmp_alarmClearParameters + Map.Entry alarmClearPair = null; + String alarmClearObject =""; + String[] alarmClearres; + Map alarmClearParameters = ((Map)faultInstanceParameters.get("tmp_alarmClearParameters")); + Iterator<Map.Entry> itr7 = alarmClearParameters.entrySet().iterator(); + while (itr7.hasNext()) { + alarmClearPair = itr7.next(); + alarmClearObject=String.valueOf(alarmClearPair); + alarmClearres = alarmClearObject.split("="); + tempAlaramClearParameter.put(alarmClearres[0], alarmClearres[1]); + } + + alarmConditionClear = tempAlaramClearParameter.get("alarmCondition").toString(); + specificProblemClear = tempAlaramClearParameter.get("specificProblem").toString(); + eventSeverityClear = tempAlaramClearParameter.get("eventSeverity").toString(); + + + //tmp_faultInstance02 + Map.Entry faultInstance02Pair = null; + String faultInstance02Object =""; + String[] faultInstance02res; + Map faultInstance02Parameters = ((Map)indirectParameters.get("tmp_faultInstance02")); + Iterator<Map.Entry> itr8 = faultInstance02Parameters.entrySet().iterator(); + while (itr8.hasNext()) { + faultInstance02Pair = itr8.next(); + faultInstance02Object=String.valueOf(faultInstance02Pair); + faultInstance02res = faultInstance02Object.split("="); + faultInstanceres02.put(faultInstance02res[0], faultInstance02res[1]); + } + Instance02alarmInterfaceA = faultInstanceres02.get("alarmInterfaceA"); + Instance02eventCategory = faultInstanceres02.get("eventCategory"); + Instance02eventSourceType = faultInstanceres02.get("eventSourceType"); + Instance02eventName = faultInstanceres02.get("eventName"); + + //tmp_command + Map.Entry tempcommand02Pair = null; + String tempcommand02Object =""; + Map tempcommand02Parameters = ((Map)faultInstance02Parameters.get("tmp_command")); + Iterator<Map.Entry> itr9 = tempcommand02Parameters.entrySet().iterator(); + while (itr9.hasNext()) { + tempcommand02Pair = itr9.next(); + tempcommand02Object=String.valueOf(tempcommand02Pair); + tempcommand02res = tempcommand02Object.split("="); + faultInstanceres02.put(tempcommand02res[0], tempcommand02res[1]); + } + + + + //tmp_alarmSetParameters + Map.Entry Instance02alarmSetPair = null; + String Instance02alarmSetObject =""; + String[] Instance02alarmSetres; + Map Instance02alarmSetParameters = ((Map)faultInstance02Parameters.get("tmp_alarmSetParameters")); + Iterator<Map.Entry> itr10 = Instance02alarmSetParameters.entrySet().iterator(); + while (itr10.hasNext()) { + Instance02alarmSetPair = itr10.next(); + Instance02alarmSetObject=String.valueOf(Instance02alarmSetPair); + Instance02alarmSetres = Instance02alarmSetObject.split("="); + faultInstanceres02.put(Instance02alarmSetres[0], Instance02alarmSetres[1]); + } + + + setAlarmCondition = faultInstanceres02.get("alarmCondition").toString(); + setSpecificProblem = faultInstanceres02.get("specificProblem").toString(); + setEventSeverity = faultInstanceres02.get("eventSeverity").toString(); + + //tmp_alarmClearParameters + Map.Entry Instanceres02alarmClearPair = null; + String Instanceres02alarmClearObject =""; + String[] Instanceres02alarmClearres; + Map Instanceres02alarmClearParameters = ((Map)faultInstance02Parameters.get("tmp_alarmClearParameters")); + Iterator<Map.Entry> itr11 = Instanceres02alarmClearParameters.entrySet().iterator(); + while (itr11.hasNext()) { + Instanceres02alarmClearPair = itr11.next(); + Instanceres02alarmClearObject=String.valueOf(Instanceres02alarmClearPair); + Instanceres02alarmClearres = Instanceres02alarmClearObject.split("="); + Instanceres02ClearParameter.put(Instanceres02alarmClearres[0], Instanceres02alarmClearres[1]); + } + + ins02alarmConditionClear = Instanceres02ClearParameter.get("alarmCondition").toString(); + ins02specificProblemClear = Instanceres02ClearParameter.get("specificProblem").toString(); + ins02eventSeverityClear = Instanceres02ClearParameter.get("eventSeverity").toString(); + + + + + } catch (ClassCastException ex) { + ex.printStackTrace(); + } + return faultConfig; + } + + + public static HashMap<String, DeviceData> readVppMetrics(String[] linkStart) { + + //t0 + String Bytesin = faultConfigTempInit.get("tmp_t0BytesIn"); + String BytesOut = faultConfigTempInit.get("tmp_t0BytesOut").toString(); + String PacketsIn = faultConfigTempInit.get("tmp_t0PacketsIn"); + String PacketsOut = faultConfigTempInit.get("tmp_t0PacketsOut"); + + + //t1 + String t1BytesIn = faultConfigCommand.get("tmp_t1BytesIn"); + String t1BytesOut = faultConfigCommand.get("tmp_t1BytesOut").toString(); + String t1PacketsIn = faultConfigCommand.get("tmp_t1PacketsIn"); + String t1PacketsOut = faultConfigCommand.get("tmp_t1PacketsOut"); + + + + + String echoFalut = faultInstanceres02.get("tmp_cmd1"); + HashMap<String, DeviceData> vppMetrics = new HashMap<>(); + + for(int i=0;i<linkStart.length;i++) { + String device = linkStart[i]; + + + //t0 + String replaceBytesin =""; + if(Bytesin.contains("$tmp_device")) { + String repString = Bytesin.replace("$tmp_device", device.trim()); + replaceBytesin = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] bytesinArray= replaceBytesin.split(","); + + + String replaceBytesOut =""; + if(BytesOut.contains("$tmp_device")) { + String repString = BytesOut.replace("$tmp_device", device.trim()); + replaceBytesOut = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] bytesoutArray = replaceBytesOut.split(","); + + + String replacePacketsIn =""; + if(PacketsIn.contains("$tmp_device")) { + String repString = PacketsIn.replace("$tmp_device", device.trim()); + replacePacketsIn = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] packetsInArray= replacePacketsIn.split(","); + + String replacePacketsOut =""; + if(PacketsOut.contains("$tmp_device")) { + String repString = PacketsOut.replace("$tmp_device", device.trim()); + replacePacketsOut = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] packetsOutArray= replacePacketsOut.split(","); + + + + //t1 + String replacet1Bytesin =""; + if(t1BytesIn.contains("$tmp_device")) { + String repString = t1BytesIn.replace("$tmp_device", device.trim()); + replacet1Bytesin = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t1BytesinArray= replacet1Bytesin.split(","); + + String replacet1BytesOut =""; + if(t1BytesOut.contains("$tmp_device")) { + String repString = t1BytesOut.replace("$tmp_device", device.trim()); + replacet1BytesOut = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t1BytesoutArray = replacet1BytesOut.split(","); + + String replacet1PacketsIn =""; + if(t1PacketsIn.contains("$tmp_device")) { + String repString = t1PacketsIn.replace("$tmp_device", device.trim()); + replacet1PacketsIn = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t1PacketsInArray= replacet1PacketsIn.split(","); + + String replacet1PacketsOut =""; + if(t1PacketsOut.contains("$tmp_device")) { + String repString = t1PacketsOut.replace("$tmp_device", device.trim()); + replacet1PacketsOut = repString.replace("sudo", "/bin/sh,-c,"); + + } + String[] t1PacketsOutArray= replacet1PacketsOut.split(","); + + try { + //t0 + Runtime rt1 = Runtime.getRuntime(); + Process bytesinchild = rt1.exec(bytesinArray); + BufferedReader readerBytesin = new BufferedReader(new InputStreamReader( + bytesinchild.getInputStream())); + String readMetrics= readerBytesin.readLine(); + + + Runtime rt2 = Runtime.getRuntime(); + Process bytesoutchild = rt2.exec(bytesoutArray); + BufferedReader readerBytesout = new BufferedReader(new InputStreamReader( + bytesoutchild.getInputStream())); + String readMetrics1= readerBytesout.readLine(); + + Runtime rt3 = Runtime.getRuntime(); + Process packetsInchild = rt3.exec(packetsInArray); + BufferedReader readerPacketsIn = new BufferedReader(new InputStreamReader( + packetsInchild.getInputStream())); + String readMetrics2= readerPacketsIn.readLine(); + + Runtime rt4 = Runtime.getRuntime(); + Process packetsOutchild = rt4.exec(packetsOutArray); + BufferedReader readerpacketsOut = new BufferedReader(new InputStreamReader( + packetsOutchild.getInputStream())); + String readMetrics3= readerpacketsOut.readLine(); + + Runtime rt5 = Runtime.getRuntime(); + Process echoFaultchild = rt5.exec(echoFalut); + BufferedReader readerechoFault = new BufferedReader(new InputStreamReader( + echoFaultchild.getInputStream())); + String echoFaultMetric= readerechoFault.readLine(); + DeviceData mddata = new DeviceData(); + + + //t1_Commands run + + Runtime rt6 = Runtime.getRuntime(); + Process t1bytesinchild = rt6.exec(t1BytesinArray); + BufferedReader readert1Bytesin = new BufferedReader(new InputStreamReader( + t1bytesinchild.getInputStream())); + String readMetrics5= readert1Bytesin.readLine(); + + + + Runtime rt7 = Runtime.getRuntime(); + Process t1bytesoutchild = rt7.exec(t1BytesoutArray); + BufferedReader readert1Bytesout = new BufferedReader(new InputStreamReader( + t1bytesoutchild.getInputStream())); + String readMetrics6= readert1Bytesout.readLine(); + + Runtime rt8 = Runtime.getRuntime(); + Process t1packetsInchild = rt8.exec(t1PacketsInArray); + BufferedReader readert1PacketsIn = new BufferedReader(new InputStreamReader( + t1packetsInchild.getInputStream())); + String readMetrics7= readert1PacketsIn.readLine(); + + + Runtime rt9 = Runtime.getRuntime(); + Process t1packetsOutchild = rt9.exec(t1PacketsOutArray); + BufferedReader readert1packetsOut = new BufferedReader(new InputStreamReader( + t1packetsOutchild.getInputStream())); + String readMetrics8= readert1packetsOut.readLine(); + + + mddata.setT0bytesIn(readMetrics); + mddata.setT0bytesOut(readMetrics1); + mddata.setT0packetIn(readMetrics2); + mddata.setT0packetOut(readMetrics3); + + mddata.setT1Bytesin(readMetrics5); + mddata.setT1Bytesout(readMetrics6); + mddata.setT1Packetsin(readMetrics7); + mddata.setT1Packetsout(readMetrics8); + + + mddata.setInstanceres02Command(echoFaultMetric); + + vppMetrics.put("Instanceres02Cmd", mddata); + + if(device.equals("enp0s3")) { + vppMetrics.put("enp0s3", mddata); + }else if(device.equals("lo")) { + vppMetrics.put("lo", mddata); + }else if(device.equals("docker0")) { + vppMetrics.put("docker0", mddata); + } + + }catch (Exception e) { + + } + } + return vppMetrics; + } + + + + public static HashMap<String, DeviceData> readVppMetrics1(String[] linkStart) { + String Bytesin = faultConfigTempInit.get("tmp_t0BytesIn"); + String BytesOut = faultConfigTempInit.get("tmp_t0BytesOut").toString(); + String PacketsIn = faultConfigTempInit.get("tmp_t0PacketsIn"); + String PacketsOut = faultConfigTempInit.get("tmp_t0PacketsOut"); + + String echoFalut = faultInstanceres02.get("tmp_cmd1"); + HashMap<String, DeviceData> vppMetrics = new HashMap<>(); + + for(int i=0;i<linkStart.length;i++) { + String device = linkStart[i]; + String replaceBytesin =""; + if(Bytesin.contains("$tmp_device")) { + String repString = Bytesin.replace("$tmp_device", device.trim()); + replaceBytesin = repString.replace("sudo", "/bin/sh,-c,"); + + } + + String[] bytesinArray= replaceBytesin.split(","); + + + String replaceBytesOut =""; + if(BytesOut.contains("$tmp_device")) { + String repString = BytesOut.replace("$tmp_device", device.trim()); + replaceBytesOut = repString.replace("sudo", "/bin/sh,-c,"); + } + + String[] bytesoutArray = replaceBytesOut.split(","); + + + + + String replacePacketsIn =""; + if(PacketsIn.contains("$tmp_device")) { + String repString = PacketsIn.replace("$tmp_device", device.trim()); + replacePacketsIn = repString.replace("sudo", "/bin/sh,-c,"); + + } + String[] packetsInArray= replacePacketsIn.split(","); + + + String replacePacketsOut =""; + if(PacketsOut.contains("$tmp_device")) { + String repString = PacketsOut.replace("$tmp_device", device.trim()); + replacePacketsOut = repString.replace("sudo", "/bin/sh,-c,"); + + } + String[] packetsOutArray= replacePacketsOut.split(","); + try { + + Runtime rt1 = Runtime.getRuntime(); + Process bytesinchild = rt1.exec(bytesinArray); + BufferedReader readerBytesin = new BufferedReader(new InputStreamReader( + bytesinchild.getInputStream())); + String readMetrics= readerBytesin.readLine(); + Runtime rt2 = Runtime.getRuntime(); + Process bytesoutchild = rt2.exec(bytesoutArray); + BufferedReader readerBytesout = new BufferedReader(new InputStreamReader( + bytesoutchild.getInputStream())); + String readMetrics1= readerBytesout.readLine(); + Runtime rt3 = Runtime.getRuntime(); + Process packetsInchild = rt3.exec(packetsInArray); + BufferedReader readerPacketsIn = new BufferedReader(new InputStreamReader( + packetsInchild.getInputStream())); + String readMetrics2= readerPacketsIn.readLine(); + Runtime rt4 = Runtime.getRuntime(); + Process packetsOutchild = rt4.exec(packetsOutArray); + BufferedReader readerpacketsOut = new BufferedReader(new InputStreamReader( + packetsOutchild.getInputStream())); + String readMetrics3= readerpacketsOut.readLine(); + Runtime rt5 = Runtime.getRuntime(); + Process echoFaultchild = rt5.exec(echoFalut); + BufferedReader readerechoFault = new BufferedReader(new InputStreamReader( + echoFaultchild.getInputStream())); + String echoFaultMetric= readerechoFault.readLine(); + DeviceData mddata = new DeviceData(); + +// mddata.setBytesIn(readMetrics); +// mddata.setBytesOut(readMetrics1); +// mddata.setPacketIn(readMetrics2); +// mddata.setPacketOut(readMetrics3); + + mddata.setInstanceres02Command(echoFaultMetric); + + vppMetrics.put("Instanceres02Cmd", mddata); + + if(device.equals("enp0s3")) { + vppMetrics.put("enp0s3", mddata); + }else if(device.equals("lo")) { + vppMetrics.put("lo", mddata); + }else if(device.equals("docker0")) { + vppMetrics.put("docker0", mddata); + } + }catch (Exception e) { + + } + } + return vppMetrics; + } + +public static void main(String[] args) { + // TODO Auto-generated method stub + + try { + AgentMain.evel_initialize("http://127.0.0.1",30000, + null,null, + "will", + "pill", + null, null, null, + "http://127.0.0.1",30001, "will", + "pill", + Level.TRACE); + }catch(Exception e) { + e.printStackTrace(); + return; + } + FaultData flDataThread = new FaultData(); + new Thread(flDataThread.faultInstance01).start(); + new Thread(flDataThread.faultInstance02).start(); + } + +} diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/HeartBeatData.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/HeartBeatData.java new file mode 100644 index 0000000..59667ab --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/HeartBeatData.java @@ -0,0 +1,213 @@ +package evel_javalibrary.att.com.loadbalance; +/**************************************************************************//** + * @file + * Heartbeat field class + * + * This file implements the Heartbeat Event class which is intended to provide a + * simple wrapper around the complexity of AT&T's Vendor Event Listener API so + * that VNFs can use it to send Agent status. + * + * License + * ------- + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +import java.io.FileReader; +import java.io.IOException; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + + +import evel_javalibrary.att.com.AgentMain; +import evel_javalibrary.att.com.EvelHeartbeatField; + +import org.apache.log4j.Level; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + + +public class HeartBeatData extends Thread{ + static HashMap<String, String> hbConfig = new HashMap(); + static int gm_event_id = 1; + static String event_id1 = "heartbeatvfs"; + static String event_id = "00000000"; + static String event_id2=null; + + + public void run() { + + Long start_epoch_microsec = 0L; + Long last_epoch_microsec = 0L; + String hostName = hostName(); + try { + readHeartbeatConfig(); + }catch(Exception e) { + } + while(true) { + String heatBeatInterval=""; + long milliseconds = 60000; + + event_id2 = event_id1+ event_id+(gm_event_id++); + if(hbConfig.get("heartbeatInterval") == null) { + heatBeatInterval = Long.toString(milliseconds); + }else { + heatBeatInterval = hbConfig.get("heartbeatInterval"); + } + EvelHeartbeatField evelHb = new EvelHeartbeatField(Integer.parseInt(heatBeatInterval) , + hbConfig.get("eventName"), + event_id2); + + if( hbConfig.get("eventType")!=null) { + start_epoch_microsec = last_epoch_microsec; + last_epoch_microsec = System.nanoTime()/1000; + + evelHb.evel_last_epoch_set(start_epoch_microsec); + evelHb.evel_start_epoch_set(last_epoch_microsec); + + evelHb.evel_header_type_set(hbConfig.get("eventType").toString()); + evelHb.evel_nfcnamingcode_set(hbConfig.get("nfcNamingCode").toString()); + evelHb.evel_nfnamingcode_set(hbConfig.get("nfNamingCode").toString()); + if(hbConfig.get("reportingEntityName") == null) { + evelHb.evel_reporting_entity_name_set(hostName); + }else { + evelHb.evel_reporting_entity_name_set(hbConfig.get("reportingEntityName").toString()); + } + evelHb.evel_reporting_entity_id_set(hbConfig.get("reportingEntityId").toString()); + evelHb.evel_nfVendorName_set(hbConfig.get("nfVendorName").toString()); + evelHb.evel_header_set_sourceid(true,hbConfig.get("sourceId").toString()); + if(hbConfig.get("sourceName") == null) { + evelHb.evel_header_set_source_name(hostName); + }else { + evelHb.evel_header_set_source_name(hbConfig.get("sourceName").toString()); + } + evelHb.evel_timeZoneOffset_set(hbConfig.get("timeZoneOffset").toString()); + + } + + try { + Thread.sleep(Integer.parseInt(heatBeatInterval)); + }catch(Exception e) { + + } + AgentMain.evel_post_event(evelHb); + } + } + + + public static HashMap<String, String> readHeartbeatConfig() throws IOException, ParseException { + JSONParser jsonParser = new JSONParser(); + try { + + FileReader reader = new FileReader("./src/main/java/evel_javalibrary/att/com/loadbalance/hb_config.json"); + JSONObject obj = (JSONObject) jsonParser.parse(reader); + Map.Entry pair = null; + String convertObject =""; + String[] res; + Map directParameters = ((Map)obj.get("tmp_directParameters")); + Iterator<Map.Entry> itr1 = directParameters.entrySet().iterator(); + while (itr1.hasNext()) { + pair = itr1.next(); + convertObject=String.valueOf(pair); + res = convertObject.split("="); + hbConfig.put(res[0], res[1]); + } + + } catch (ClassCastException ex) { + ex.printStackTrace(); + } + return hbConfig; + } + +private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); +private static String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for ( int j = 0; j < bytes.length; j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); +} + +public static String hostName() { + String hostname = "Unknown"; + String uuid = "Unknown"; + try + { + InetAddress addr; + addr = InetAddress.getLocalHost(); + hostname = addr.getHostName(); + } + catch (UnknownHostException ex) + { + } + try{ + Enumeration<NetworkInterface> networks = + NetworkInterface.getNetworkInterfaces(); + while(networks.hasMoreElements()) { + NetworkInterface network = networks.nextElement(); + byte[] mac = network.getHardwareAddress(); + + if(hostname.equalsIgnoreCase("unknown")) + { + Enumeration inetAddrs = network.getInetAddresses(); + while(inetAddrs.hasMoreElements()){ + InetAddress inetAddr = (InetAddress) inetAddrs.nextElement(); + if (!inetAddr.isLoopbackAddress()) { + hostname = inetAddr.getHostAddress(); + break; + } + } + } + if (mac != null) { + uuid = bytesToHex(mac); + } + } + } catch (SocketException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return hostname; +} + +public static void main(String[] args) { + // TODO Auto-generated method stub + + try { + AgentMain.evel_initialize("http://127.0.0.1",30000, + null,null, + "will", + "pill", + null, null, null, + "http://127.0.0.1",30001, "will", + "pill", + Level.TRACE); + }catch(Exception e) { + e.printStackTrace(); + return; + } + HeartBeatData hbDataThread = new HeartBeatData(); + hbDataThread.start(); + } + + + +} diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/Main.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/Main.java deleted file mode 100644 index 83f97e1..0000000 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/Main.java +++ /dev/null @@ -1,64 +0,0 @@ -package evel_javalibrary.att.com.loadbalance; -/**************************************************************************//** - * @file - * Sample Test Agent for EVEL library - * - * This file implements the Sample Agent which is intended to provide a - * simple wrapper around the complexity of AT&T's Vendor Event Listener API so - * that VNFs can use it without worrying about details of the API transport. - * It also shows how events can be formatted with data for POST - * - * License - * ------- - * Unless otherwise specified, all software contained herein is - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *****************************************************************************/ - -import org.apache.log4j.Level; - -import evel_javalibrary.att.com.AgentMain; -//import evel_javalibrary.att.com.MeasureData; -//import evel_javalibrary.att.com.heartBeatData; - - - - - -public class Main { - - public static void main(String[] args) { - // TODO Auto-generated method stub - - try { - AgentMain.evel_initialize("http://127.0.0.1", 30000, - null,null, - "will", - "pill", - null, null, null, - Level.TRACE); - }catch(Exception e) { - e.printStackTrace(); - return; - } - MeasureData mdataThread = new MeasureData(); - mdataThread.start(); - - heartBeatData hbDataThread = new heartBeatData(); - hbDataThread.start(); - - faultData flDataThread = new faultData(); - flDataThread.start(); - - } - -} - diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java index 38c517a..9fa537e 100644 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/MeasureData.java @@ -24,352 +24,574 @@ package evel_javalibrary.att.com.loadbalance; import java.io.BufferedReader; -import java.io.File; + +import java.io.FileReader; +import java.io.IOException; import java.io.InputStreamReader; -import java.nio.charset.Charset; -import java.nio.file.Files; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; import java.util.ArrayList; +import java.util.Enumeration; import java.util.HashMap; +import java.util.Iterator; import java.util.List; +import java.util.Map; import org.apache.log4j.Level; +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import evel_javalibrary.att.com.AgentMain; import evel_javalibrary.att.com.EvelBatch; import evel_javalibrary.att.com.EvelScalingMeasurement; public class MeasureData extends Thread{ - static HashMap<String, String> hm = new HashMap<>(); - static HashMap<String, String> vpp_metrics = new HashMap<>(); - static HashMap<String, String> common_meas = new HashMap<>(); - - static int bytes_in_this_round; - static int bytes_out_this_round; - static int packets_in_this_round; - static int packets_out_this_round; + static HashMap<String, String> measConfig = new HashMap<>(); + static String[] resDevice =null; + static String[] tempInitres; + static String[] tempcommandres; + static String[] tempcommandres1; + static HashMap<String, String> vNicPerformanceCommand1 = new HashMap<>(); + static HashMap<String, String> vNicPerformanceArray = new HashMap<>(); + static HashMap<String, String> initTempCommand = new HashMap<>(); + static float bytesInLo; + static float bytesOutLo; + static float packetsInLo; + static float packetsOutLo; - static int gm_event_id = 1; - static String event_id1 = "mvfs"; - static String event_id = "00000000"; - static String event_id2=null; + static float bytesInEnps03; + static float bytesOutEnps03; + static float packetsInEnps03; + static float packetsOutEnps03; - static int request_rate = 0; + static float bytesInDocker0; + static float bytesOutDocker0; + static float packetsInDocker0; + static float packetsOutDocker0; - static long epoch_start = 0; + static int gmEventId = 1; + static String eventId1 = "mvfs"; + static String eventId = "00000000"; + static String eventId2=null; + + static int requestRate = 0; static String linkStart = ""; static int linkCount; Long start_epoch_microsec = 0L; Long last_epoch_microsec = 0L; - - //public static void main(String[] args) { public void run() { - // TODO Auto-generated method stub - //read_config_file(); - read_meas_traffic(); - read_common_config_file(); - read_meas_config_file(); + + try { + + readMeasurementConfig(); + readVppMetrics(resDevice); + } catch (IOException | ParseException e1) { + e1.printStackTrace(); + } + + String[] intFaceMap = resDevice; - HashMap<String, String> intFaceMap = read_interface_config_file(); int numOfInterfaces = 0; - if( !intFaceMap.isEmpty() ) - numOfInterfaces = intFaceMap.size(); + if( intFaceMap != null) + numOfInterfaces = intFaceMap.length; if( numOfInterfaces <= 0) { - System.out.println("ERROR : Didn't find interfacess in config file, exiting thread"); + return; - } + } - System.out.println("MAP values: " + hm.values()); - HashMap last_metrics = read_vpp_metrics(linkStart); + + try { - Thread.sleep(Integer.parseInt(common_meas.get("measurementInterval"))); + Thread.sleep(1000); }catch(Exception e) {} while(true) { - //request_rate = rand()%10000; - request_rate =2; - EvelBatch ebt = new EvelBatch(); - event_id2 = event_id1+ event_id+(gm_event_id++); - EvelScalingMeasurement eveMeas = new EvelScalingMeasurement( Double.parseDouble(common_meas.get("measurementInterval")) , - common_meas.get("eventName"), - event_id2); - - for( String vNic : intFaceMap.keySet() ) { - //System.out.println("INFO:: getting vpp metrics for vNic "+vNic); + HashMap<String, DeviceData> lastMetrics = readVppMetrics(resDevice); + //HashMap<String, DeviceData> currentMetrics = readVppMetrics(resDevice);; + HashMap<String, DeviceData> currentMetrics = lastMetrics; + requestRate =2; + eventId2 = eventId1+ eventId+(gmEventId++); + String measurmentInterval=""; + long milliseconds = 60000; + if(measConfig.get("measurementInterval") == null) { + measurmentInterval = Long.toString(milliseconds); + }else { + measurmentInterval = measConfig.get("measurementInterval"); + } + EvelScalingMeasurement eveMeas = new EvelScalingMeasurement(Integer.parseInt(measurmentInterval) , + measConfig.get("eventName"), + eventId2); - HashMap current_metrics = read_vpp_metrics(vNic); - if( current_metrics.size() !=4 ) { - System.out.println("ERROR:: Did't get vpp metrics for vNic "+vNic); - continue; - } - - if (Integer.parseInt((String) current_metrics.get("bytes_in")) - - Integer.parseInt((String) last_metrics.get("bytes_in")) > 0) { - bytes_in_this_round = Integer.parseInt((String) current_metrics.get("bytes_in")) - - Integer.parseInt((String) last_metrics.get("bytes_in")); - } else { - bytes_in_this_round = 0; - } - - if (Integer.parseInt((String) current_metrics.get("bytes_out")) - - Integer.parseInt((String) last_metrics.get("bytes_out")) > 0) { - bytes_out_this_round = Integer.parseInt((String) current_metrics.get("bytes_out")) - - Integer.parseInt((String) last_metrics.get("bytes_out")); - } else { - bytes_out_this_round = 0; - } + for( String vNic : intFaceMap) { + + int receivedOctetsDeltaLo = 0; + int receivedTotalPacketsDeltaLo = 0; + int transmittedOctetsDeltaLo = 0; + int transmittedTotalPacketsDeltaLo = 0; + + System.out.println("Data Array T0 "+vNic+" , "+ currentMetrics.get(vNic).getT0bytesIn()+" " + + currentMetrics.get(vNic).getT0bytesOut()+" " + + currentMetrics.get(vNic).getT0packetIn()+" " + + currentMetrics.get(vNic).getT0packetOut()); + System.out.println("Data Array T1 "+vNic+" , "+ currentMetrics.get(vNic).getT1Bytesin()+" " + + currentMetrics.get(vNic).getT1Bytesout()+" " + + currentMetrics.get(vNic).getT1Packetsin()+" " + + currentMetrics.get(vNic).getT1Packetsout()); - if (Integer.parseInt((String) current_metrics.get("packets_in")) - - Integer.parseInt((String) last_metrics.get("packets_in")) > 0) { - packets_in_this_round = Integer.parseInt((String) current_metrics.get("packets_in")) - - Integer.parseInt((String) last_metrics.get("packets_in")); - } else { - packets_in_this_round = 0; - } - - if (Integer.parseInt((String) current_metrics.get("packets_out")) - - Integer.parseInt((String) last_metrics.get("packets_out")) > 0) { - packets_out_this_round = Integer.parseInt((String) current_metrics.get("packets_out")) - - Integer.parseInt((String) last_metrics.get("packets_out")); - } else { - packets_out_this_round = 0; - } - event_id2 = event_id1+ (gm_event_id++); - /* EvelScalingMeasurement eveMeas = new EvelScalingMeasurement( Double.parseDouble(hm.get("measurementInterval")) , - hm.get("eventName"), - event_id2); */ - - - EvelScalingMeasurement.MEASUREMENT_NIC_PERFORMANCE vNicPerf = eveMeas.evel_measurement_new_vnic_performance(vNic, "true"); - eveMeas.evel_meas_vnic_performance_add(vNicPerf ); - if( hm.get("eventType")!=null) { - - start_epoch_microsec = last_epoch_microsec; - last_epoch_microsec = System.nanoTime()/1000; - - eveMeas.evel_last_epoch_set(start_epoch_microsec); - eveMeas.evel_start_epoch_set(last_epoch_microsec); + if (Integer.parseInt((currentMetrics.get(vNic).getT1Bytesin())) + - Integer.parseInt((lastMetrics.get(vNic).getT0bytesIn()) ) > 0) { + receivedOctetsDeltaLo = (int) (Integer.parseInt((currentMetrics.get(vNic).getT1Bytesin()) ) + - Integer.parseInt((lastMetrics.get(vNic).getT0bytesIn()) )); + } else { + receivedOctetsDeltaLo = 0; + } + + if (Integer.parseInt((currentMetrics.get(vNic).getT1Packetsin())) + - Integer.parseInt((lastMetrics.get(vNic).getT0packetIn()) ) > 0) { + receivedTotalPacketsDeltaLo = (int) (Integer.parseInt((currentMetrics.get(vNic).getT1Packetsin()) ) + - Integer.parseInt((lastMetrics.get(vNic).getT0packetIn()) )); + } else { + receivedTotalPacketsDeltaLo = 0; + } - eveMeas.evel_measurement_type_set( hm.get("eventType").toString()); - eveMeas.evel_measurement_request_rate_set(request_rate ); - eveMeas.evel_vnic_performance_rx_total_pkt_delta_set(vNicPerf, packets_in_this_round); - eveMeas.evel_vnic_performance_tx_total_pkt_delta_set(vNicPerf, packets_out_this_round); - eveMeas.evel_vnic_performance_rx_octets_delta_set( vNicPerf, bytes_in_this_round); - eveMeas.evel_vnic_performance_tx_octets_delta_set( vNicPerf, bytes_out_this_round); - eveMeas.evel_nfcnamingcode_set(hm.get("nfcNamingCode").toString()); - eveMeas.evel_nfnamingcode_set(hm.get("nfNamingCode").toString()); - eveMeas.evel_reporting_entity_name_set(hm.get("reportingEntityName").toString()); - eveMeas.evel_reporting_entity_id_set(hm.get("reportingEntityId").toString()); - eveMeas.evel_nfVendorName_set(hm.get("nfVendorName").toString()); - eveMeas.evel_header_set_sourceid(true,hm.get("sourceId").toString()); + if (Integer.parseInt((currentMetrics.get(vNic).getT1Bytesout())) + - Integer.parseInt((lastMetrics.get(vNic).getT0bytesOut()) ) > 0) { + transmittedOctetsDeltaLo = (int) (Integer.parseInt((currentMetrics.get(vNic).getT1Bytesout()) ) + - Integer.parseInt((lastMetrics.get(vNic).getT0bytesOut()))); + } else { + transmittedOctetsDeltaLo = 0; + } + - eveMeas.evel_header_set_source_name(hm.get("sourceName").toString()); - eveMeas.evel_timeZoneOffset_set(hm.get("timeZoneOffset").toString()); + if (Integer.parseInt((currentMetrics.get(vNic).getT1Packetsout())) + - Integer.parseInt((lastMetrics.get(vNic).getT0packetOut()) ) > 0) { + transmittedTotalPacketsDeltaLo = (int) (Integer.parseInt((currentMetrics.get(vNic).getT1Packetsout()) ) + - Integer.parseInt((lastMetrics.get(vNic).getT0packetOut()))); + } else { + transmittedTotalPacketsDeltaLo = 0; + } + + EvelScalingMeasurement.MEASUREMENT_NIC_PERFORMANCE vNicPerf = eveMeas.evel_measurement_new_vnic_performance(vNic.replaceAll("^[\"']+|[\"']+$", ""), "true"); + //eveMeas.evel_meas_vnic_performance_add(vNicPerf); + + if( measConfig.get("eventType")!=null) { + String hostName = hostName(); + start_epoch_microsec = last_epoch_microsec; + last_epoch_microsec = System.nanoTime()/1000; + eveMeas.evel_last_epoch_set(start_epoch_microsec); + eveMeas.evel_start_epoch_set(last_epoch_microsec); + eveMeas.evel_measurement_type_set( measConfig.get("eventType").toString()); - + eveMeas.evel_vnic_performance_rx_octets_delta_set( vNicPerf, receivedOctetsDeltaLo); + eveMeas.evel_vnic_performance_rx_total_pkt_delta_set(vNicPerf, receivedTotalPacketsDeltaLo); + eveMeas.evel_vnic_performance_tx_octets_delta_set( vNicPerf, transmittedOctetsDeltaLo); + eveMeas.evel_vnic_performance_tx_total_pkt_delta_set(vNicPerf, transmittedTotalPacketsDeltaLo); + + eveMeas.evel_nfcnamingcode_set(measConfig.get("nfcNamingCode").toString()); + eveMeas.evel_nfnamingcode_set(measConfig.get("nfNamingCode").toString()); + if(measConfig.get("reportingEntityName") == null) { + eveMeas.evel_reporting_entity_name_set(hostName); + }else { + eveMeas.evel_reporting_entity_name_set(measConfig.get("reportingEntityName").toString()); + } + eveMeas.evel_reporting_entity_id_set(measConfig.get("reportingEntityId").toString()); + eveMeas.evel_nfVendorName_set(measConfig.get("nfVendorName").toString()); + eveMeas.evel_header_set_sourceid(true,measConfig.get("sourceId").toString()); + if(measConfig.get("sourceName") == null) { + eveMeas.evel_header_set_source_name(hostName); + }else { + eveMeas.evel_header_set_source_name(measConfig.get("sourceName").toString()); + } + eveMeas.evel_timeZoneOffset_set(measConfig.get("timeZoneOffset").toString()); } - - - try { - Thread.sleep(Integer.parseInt(common_meas.get("measurementInterval"))); - }catch(Exception e) {} - last_metrics = current_metrics; - } - //ebt.addEvent(eveMeas); + } AgentMain.evel_post_event(eveMeas); - System.out.println(" Event sent"); - + boolean continues = true; + long curr = System.currentTimeMillis(); + while(continues) { + try { + Thread.sleep(100); + }catch (Exception e) { + // TODO: handle exception + } + if(System.currentTimeMillis() >= (curr+Integer.parseInt(measurmentInterval))) { + continues = false; + } + + + } } } - - - - public static HashMap<String, String> read_vpp_metrics(String linkStart) { - Process p; - - String s=""; - HashMap<String, String> vpp_metrics_map = new HashMap<>(); - String params[] = {"-f3", "-f11", "-f4", "-f12"}; - try { - Runtime rt = Runtime.getRuntime(); - for(int i=0;i<4;i++) { - String[] command = {"/bin/sh", "-c", "cat /proc/net/dev | grep \""+linkStart+"\" | tr -s \' \' | cut -d\' \' "+params[i]+""}; - Process child = rt.exec(command); - - BufferedReader reader = new BufferedReader(new InputStreamReader( - child.getInputStream())); - - while ((s= reader.readLine()) != null) { - String[] res = s.split(" "); - if( i==0) - vpp_metrics_map.put("bytes_in", res[0]); - if( i==1) - vpp_metrics_map.put("packets_in", res[0]); - if( i==2) - vpp_metrics_map.put("bytes_out", res[0]); - if( i==3) - vpp_metrics_map.put("packets_out", res[0]); - - } - } - - } catch (Exception e) { + private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); + private static String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for ( int j = 0; j < bytes.length; j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + public static String hostName() { + String hostname = "Unknown"; + String uuid = "Unknown"; + try + { + InetAddress addr; + addr = InetAddress.getLocalHost(); + hostname = addr.getHostName(); + } + catch (UnknownHostException ex) + { + } + try{ + Enumeration<NetworkInterface> networks = + NetworkInterface.getNetworkInterfaces(); + while(networks.hasMoreElements()) { + NetworkInterface network = networks.nextElement(); + byte[] mac = network.getHardwareAddress(); + + if(hostname.equalsIgnoreCase("unknown")) + { + Enumeration inetAddrs = network.getInetAddresses(); + while(inetAddrs.hasMoreElements()){ + InetAddress inetAddr = (InetAddress) inetAddrs.nextElement(); + if (!inetAddr.isLoopbackAddress()) { + hostname = inetAddr.getHostAddress(); + break; + } + } + } + if (mac != null) { + uuid = bytesToHex(mac); + } + } + } catch (SocketException e) { + // TODO Auto-generated catch block e.printStackTrace(); } - return vpp_metrics_map; + + return hostname; } - public static HashMap<String, String> read_common_config_file() { - - List<String> list = new ArrayList<String>(); - - - hm.put("eventType", ""); - hm.put("nfcNamingCode", ""); - hm.put("nfNamingCode", ""); - hm.put("nfVendorName", ""); - hm.put("reportingEntityId", ""); - hm.put("reportingEntityName", ""); - hm.put("sourceId", ""); - hm.put("sourceName", ""); - hm.put("timeZoneOffset", ""); + public static HashMap<String, String> readMeasurementConfig() throws IOException, ParseException { + JSONParser jsonParser = new JSONParser(); - - - System.out.println("KEYS: " + hm.keySet().size()); - System.out.println("VALUES: " + hm.values()); - try { - // File file = new File("/home/ves/users/admin/temp/fw_common_config.txt"); - File file = new File("./src/main/java/evel_javalibrary/att/com/loadbalance/fw_common_config.txt"); - list = Files.readAllLines(file.toPath(), Charset.defaultCharset()); - for (String lineSplit : list) { - String[] res = lineSplit.split(" "); - hm.put(res[0], res[1]); - System.out.println("File reading after split ---" + res[0]); - System.out.println("File reading after split second---" + res[1]); - } - } catch (Exception ex) { - ex.printStackTrace(); + + FileReader reader = new FileReader("./src/main/java/evel_javalibrary/att/com/loadbalance/meas_config.json"); + JSONObject obj = (JSONObject) jsonParser.parse(reader); + Map.Entry directPair = null; + String directObject =""; + String[] directres; + Map directParameters = ((Map)obj.get("tmp_directParameters")); + Iterator<Map.Entry> itr1 = directParameters.entrySet().iterator(); + while (itr1.hasNext()) { + directPair = itr1.next(); + directObject=String.valueOf(directPair); + directres = directObject.split("="); + measConfig.put(directres[0], directres[1]); + } + + String eventName = measConfig.get("eventName").toString(); + JSONArray arrJson = (JSONArray) directParameters.get("tmp_device"); + resDevice = new String[arrJson.size()]; + for(int i = 0; i < arrJson.size(); i++) + resDevice[i] = (String) arrJson.get(i); + + + //tmp_indirectParameters + Map.Entry indirectPair = null; + String indirectObject =""; + String[] indirectres; + Map indirectParameters = ((Map)obj.get("tmp_indirectParameters")); + Iterator<Map.Entry> itr2 = indirectParameters.entrySet().iterator(); + while (itr2.hasNext()) { + indirectPair = itr2.next(); + indirectObject=String.valueOf(indirectPair); + indirectres = indirectObject.split("="); + measConfig.put(indirectres[0], indirectres[1]); + } + + + + //tmp_init + // Map tempInitParameters = ((Map)indirectParameters.get("tmp_init")); + + //tmp_init + Map.Entry tempcommandPair = null; + String tempcommandObject =""; + Map tempcommandParameters = ((Map)indirectParameters.get("tmp_init")); + Iterator<Map.Entry> itr3 = tempcommandParameters.entrySet().iterator(); + while (itr3.hasNext()) { + tempcommandPair = itr3.next(); + tempcommandObject=String.valueOf(tempcommandPair); + tempcommandres = tempcommandObject.split("="); + initTempCommand.put(tempcommandres[0], tempcommandres[1]); + } + + //tmp_command1 + Map.Entry tempcommand1Pair = null; + String tempcommand1Object =""; + JSONArray nicPerfomenceArray = (JSONArray) indirectParameters.get("vNicPerformance"); + Map vNic = (Map)nicPerfomenceArray.get(0); + Map perf = ((Map)vNic.get("tmp_vnic_command")); + Iterator<Map.Entry> itr5 = perf.entrySet().iterator(); + while (itr5.hasNext()) { + tempcommand1Pair = itr5.next(); + tempcommand1Object=String.valueOf(tempcommand1Pair); + tempcommandres1 = tempcommand1Object.split("="); + vNicPerformanceCommand1.put(tempcommandres1[0], tempcommandres1[1]); + } + Map.Entry vnicPair = null; + String vnicObject =""; + String[] nicPerfomenceArrayRes; + vNic = (Map)nicPerfomenceArray.get(0); + Iterator<Map.Entry> itr6 = vNic.entrySet().iterator(); + while (itr6.hasNext()) { + vnicPair = itr6.next(); + vnicObject=String.valueOf(vnicPair); + nicPerfomenceArrayRes = vnicObject.split("="); + vNicPerformanceArray.put(nicPerfomenceArrayRes[0], nicPerfomenceArrayRes[1]); + } + + String receivedOctetsDelta = vNicPerformanceArray.get("receivedOctetsDelta"); + + } catch (ClassCastException ex) { + } - System.out.println("KEYS: " + hm.keySet().size()); - System.out.println("VALUES: " + hm.values()); - return hm; + return measConfig; } + + public static HashMap<String, DeviceData> readVppMetrics(String[] linkStart) { + DeviceData mddata = null; new DeviceData(); - public static HashMap<String, String> read_interface_config_file() { - - List<String> list = new ArrayList<String>(); - HashMap<String, String> interface_config = new HashMap<>(); - //interface_config.put("lo", ""); + //tmp_t0 + String t0BytesIn = initTempCommand.get("tmp_t0BytesIn"); + String t0BytesOut = initTempCommand.get("tmp_t0BytesOut"); + String t0PacketsIn = initTempCommand.get("tmp_t0PacketsIn"); + String t0PacketsOut = initTempCommand.get("tmp_t0PacketsOut"); - System.out.println("KEYS: " + interface_config.keySet().size()); - System.out.println("VALUES: " + interface_config.values()); - - try { - //File file = new File("/home/ves/users/admin/temp/fw_interface_config.txt"); - File file = new File("./src/main/java/evel_javalibrary/att/com/loadbalance/fw_interface_config.txt"); - list = Files.readAllLines(file.toPath(), Charset.defaultCharset()); - for (String lineSplit : list) { - String[] res = lineSplit.split(" "); - interface_config.put(res[0], res[1]); - } + //tmp_t1 + String t1BytesIn = vNicPerformanceCommand1.get("tmp_t1BytesIn"); + String t1BytesOut = vNicPerformanceCommand1.get("tmp_t1BytesOut").toString(); + String t1PacketsIn = vNicPerformanceCommand1.get("tmp_t1PacketsIn"); + String t1PacketsOut = vNicPerformanceCommand1.get("tmp_t1PacketsOut"); + + + HashMap<String, DeviceData> vppMetrics = new HashMap<>(); + for(int i = 0; i < linkStart.length; i++) { + mddata =new DeviceData(); + String device = linkStart[i]; - linkStart = (String)interface_config.keySet().toArray()[1]; - linkCount = interface_config.keySet().size(); + //t0_ + String replaceInitBytesint0 =""; + if(t0BytesIn.contains("$tmp_device")) { + String repString = t0BytesIn.replace("$tmp_device", device.trim()); + replaceInitBytesint0 = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t0BytesinArray= replaceInitBytesint0.split(","); - } catch (Exception ex) { - ex.printStackTrace(); - } - - return interface_config; - } + String replaceInitBytesout=""; + if(t0BytesOut.contains("$tmp_device")) { + String repString = t0BytesOut.replace("$tmp_device", device.trim()); + replaceInitBytesout = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t0BytesoutArray= replaceInitBytesout.split(","); + + String replaceInitPacketsin =""; + if(t0PacketsIn.contains("$tmp_device")) { + String repString = t0PacketsIn.replace("$tmp_device", device.trim()); + replaceInitPacketsin = repString.replace("sudo", "/bin/sh,-c,"); - - - + } + String[] t0PacketsinArray= replaceInitPacketsin.split(","); + + + String replaceInitPacketsout =""; + if(t0PacketsOut.contains("$tmp_device")) { + String repString = t0PacketsOut.replace("$tmp_device", device.trim()); + replaceInitPacketsout = repString.replace("sudo", "/bin/sh,-c,"); - - public static HashMap<String, String> read_meas_config_file() { + } + String[] t0PacketsoutArray= replaceInitPacketsout.split(","); + + //t1 + String replaceBytesin =""; + if(t1BytesIn.contains("$tmp_device")) { + String repString = t1BytesIn.replace("$tmp_device", device.trim()); + replaceBytesin = repString.replace("sudo", "/bin/sh,-c,"); - List<String> list = new ArrayList<String>(); + } + String[] t1BytesinArray= replaceBytesin.split(","); + + String replaceBytesOut =""; + if(t1BytesOut.contains("$tmp_device")) { + String repString = t1BytesOut.replace("$tmp_device", device.trim()); + replaceBytesOut = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t1BytesoutArray = replaceBytesOut.split(","); + + String replacePacketsIn =""; + if(t1PacketsIn.contains("$tmp_device")) { + String repString = t1PacketsIn.replace("$tmp_device", device.trim()); + replacePacketsIn = repString.replace("sudo", "/bin/sh,-c,"); + } + String[] t1PacketsInArray= replacePacketsIn.split(","); + + String replacePacketsOut =""; + if(t1PacketsOut.contains("$tmp_device")) { + String repString = t1PacketsOut.replace("$tmp_device", device.trim()); + replacePacketsOut = repString.replace("sudo", "/bin/sh,-c,"); - common_meas.put("eventName", "Measurement_vFirewall-AT&T_nicPerformance"); - common_meas.put("measurementInterval", ""); + } + String[] t1PacketsOutArray= replacePacketsOut.split(","); - System.out.println("KEYS: " + common_meas.keySet().size()); - System.out.println("VALUES: " + common_meas.values()); + try { + //t0_Commands run + Runtime rt5 = Runtime.getRuntime(); + Process initBytesint0child = rt5.exec(t0BytesinArray); + BufferedReader readerinitBytesint0 = new BufferedReader(new InputStreamReader( + initBytesint0child.getInputStream())); + String readinitMetrics= readerinitBytesint0.readLine(); + + Runtime rt6 = Runtime.getRuntime(); + Process initBytesoutchild = rt6.exec(t0BytesoutArray); + BufferedReader readerinitBytesout = new BufferedReader(new InputStreamReader( + initBytesoutchild.getInputStream())); + String readinitMetrics2= readerinitBytesout.readLine(); + + + Runtime rt7 = Runtime.getRuntime(); + Process initPacketsinchild = rt7.exec(t0PacketsinArray); + BufferedReader readerinitPacketsin = new BufferedReader(new InputStreamReader( + initPacketsinchild.getInputStream())); + String readinitMetrics3= readerinitPacketsin.readLine(); + + + + Runtime rt8 = Runtime.getRuntime(); + Process initPacketsoutchild = rt8.exec(t0PacketsoutArray); + BufferedReader readerinitPacketsout = new BufferedReader(new InputStreamReader( + initPacketsoutchild.getInputStream())); + String readinitMetrics4= readerinitPacketsout.readLine(); + + - try { - //File file = new File("/home/ves/users/admin/temp/fw_meas_config.txt"); - File file = new File("./src/main/java/evel_javalibrary/att/com/loadbalance/fw_meas_config.txt"); - list = Files.readAllLines(file.toPath(), Charset.defaultCharset()); - for (String lineSplit : list) { - String[] res = lineSplit.split(" "); - common_meas.put(res[0], res[1]); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - System.out.println("KEYS: " + common_meas.keySet().size()); - System.out.println("VALUES: " + common_meas.values()); - return common_meas; - } + //t1_Commands run + Thread.sleep(Integer.parseInt(measConfig.get("measurementInterval"))); + Runtime rt1 = Runtime.getRuntime(); + Process bytesinchild = rt1.exec(t1BytesinArray); + // bytesinchild.waitFor(); + BufferedReader readerBytesin = new BufferedReader(new InputStreamReader( + bytesinchild.getInputStream())); + String readMetrics= readerBytesin.readLine(); + + + + Runtime rt2 = Runtime.getRuntime(); + Process bytesoutchild = rt2.exec(t1BytesoutArray); + BufferedReader readerBytesout = new BufferedReader(new InputStreamReader( + bytesoutchild.getInputStream())); + String readMetrics1= readerBytesout.readLine(); + + Runtime rt3 = Runtime.getRuntime(); + Process packetsInchild = rt3.exec(t1PacketsInArray); + BufferedReader readerPacketsIn = new BufferedReader(new InputStreamReader( + packetsInchild.getInputStream())); + String readMetrics2= readerPacketsIn.readLine(); + + Runtime rt4 = Runtime.getRuntime(); + Process packetsOutchild = rt4.exec(t1PacketsOutArray); + BufferedReader readerpacketsOut = new BufferedReader(new InputStreamReader( + packetsOutchild.getInputStream())); + String readMetrics3= readerpacketsOut.readLine(); + + // System.out.println(device+" , T1 command data: "+ readMetrics+"," + readMetrics1+"," + readMetrics2+"," + readMetrics3); + // System.out.println(device+" , T0 command data: "+ readinitMetrics+"," + readinitMetrics2+"," + readinitMetrics3+"," + readinitMetrics4); + + //t1 + mddata.setT1Bytesin(readMetrics); + mddata.setT1Bytesout(readMetrics1); + mddata.setT1Packetsin(readMetrics2); + mddata.setT1Packetsout(readMetrics3); + + //t0 + mddata.setT0bytesIn(readinitMetrics); + mddata.setT0bytesOut(readinitMetrics2); + mddata.setT0packetIn(readinitMetrics3); + mddata.setT0packetOut(readinitMetrics4); + + if(device.equals("enp0s3")) { + vppMetrics.put("enp0s3", mddata); + + }else if(device.equals("lo")) { + vppMetrics.put("lo", mddata); + }else if(device.equals("docker0")) { + vppMetrics.put("docker0", mddata); + } + + }catch (Exception e) { + e.printStackTrace(); + } + } + return vppMetrics; + } - public static HashMap<String, String> read_meas_traffic() { - Process p; - List<String> vpp_params = new ArrayList(); - String s=""; - // HashMap<String, String> vpp_metrics_map = new HashMap<>(); - String params[] = {"-f3", "-f11", "-f4", "-f12"}; + + public static void main(String[] args) { + // TODO Auto-generated method stub + try { -// System.out.println("***********inside read_vpp_metrics"); -// String command = "cat /proc/net/dev | grep \"Receive\" | tr -s \' \' | cut -d\' \' -f3"; - //{"-f3", "-f11", "-f4", "-f12"}; -// String command = "cat /proc/net/dev | grep \""+vnic+"\" "; - for(int i=0;i<4;i++) { - String[] command = {"/bin/sh", "-c", "docker logs vHello | grep -c"}; -// System.out.println("**COMMAND***: "+command); - Process child = Runtime.getRuntime().exec(command); - - BufferedReader reader = new BufferedReader(new InputStreamReader( - child.getInputStream())); - - while ((s= reader.readLine()) != null) { - vpp_params.add(s); - System.out.println("VPP meas_traffic:----" + s); - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return vpp_metrics; + AgentMain.evel_initialize("http://127.0.0.1",30000, + null,null, + "will", + "pill", + null, null, null, + "http://127.0.0.1",30001, "will", + "pill", + Level.TRACE); + }catch(Exception e) { + e.printStackTrace(); + return; + } + MeasureData mdataThread = new MeasureData(); + mdataThread.start(); + } + + + } diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_Fault.md b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_Fault.md new file mode 100644 index 0000000..0151629 --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_Fault.md @@ -0,0 +1,33 @@ + +PROJECT DESCRIPTION + +--- +This project contains the source code and scripts for the generation of fault events. + + - README.md: this file. + + + - FaultData.java and DeviceData.java files: source code that uses the ECOMP Vendor Event Listener Library (VES) to generate the fault events. Fault is generated based on the link status. If number of bytes transmitted/received is less than the low water mark, the fault is generated. The application reads flt_config.json file for parameter values and populate the fault event. If eventName, eventSourceType, vfStatus, specificProblem or alarmCondition parameter value is not given, the application terminates. If reportingEntityName and sourceName parameter values are not given, then it gets the hostname and populates it. If tmp_faultCheckInterval is not given, it defaults to 60 seconds. + + + + - FaultData.java: It reads input parameters like DCAE IP address and port from configuration files contained in /opt/config. Based on the collector configuration, use FaultData.java for use single and 2 collectors configuration. + + +USAGE +----- + +Update the configuration files with proper parameters values so that events generated would contain those values + +To run the FaultData.java in single collector configuration, please execute the following steps: + + -Compile Load Balance VES agent + javac -cp <.:dependent jars> ./evel_javalibrary/att/com/loadbalance + In Eclipse right click on veslibrary/ves_javalibrary/evel_javalib2 application-> click Run As ->and select -> mvn build option then + ->select the configuration mvn clean install. + + + -Run Load Balance VES agent + java -cp <.:dependent jars> evel_javalibrary.att.com.loadbalance.FaultData.java + In Eclipse right click on evel_javalibrary.att.com.loadbalance.FaultData.java class right click -> click Run As -> click Java application. + diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_HeartBeat.md b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_HeartBeat.md new file mode 100644 index 0000000..7e541f8 --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_HeartBeat.md @@ -0,0 +1,38 @@ + +PROJECT DESCRIPTION + +--- +This project contains the source code and scripts for the periodic generation of heartbeat events. + + - README.md: this file. + + + - HeartBeatData.java file: source code that uses the ECOMP Vendor Event Listener Library (VES) to generate the periodic heartbeat events. It reads hb_config.json file for parameter values and populate the heartbeat event. If eventName parameter value is not given, the application terminates. If reportingEntityName and sourceName parameter values are not given, then it gets the hostname and populates it. If heartbeatInterval is not given, it defaults to 60 seconds. + + + + - HeartBeatData.java file: It reads input parameters like DCAE IP address and port from configuration files contained in /opt/config. Based on the collector configuration, use HeartBeatData.java file for single and 2 collectors configuration. + + +USAGE +----- + +Update the configuration files with proper parameters values so that events generated would contain those values com.googlecode.json-simple + + +To run the HeartBeatData.java in single collector configuration, please execute the following steps: + + -Compile Load Balance VES agent + javac -cp <.:dependent jars> ./evel_javalibrary/att/com/loadbalance + In Eclipse right click on veslibrary/ves_javalibrary/evel_javalib2 application-> click Run As ->and select -> mvn build option then + ->select the configuration mvn clean install. + + -Run Load Balance VES agent + java -cp <.:dependent jars> evel_javalibrary.att.com.loadbalance.HeartBeatData.java + In Eclipse right click on evel_javalibrary.att.com.loadbalance.HeartBeatData.java class right click -> click Run As -> click Java application. + + <dependency> + <groupId>com.googlecode.json-simple</groupId> + <artifactId>json-simple</artifactId> + <version>1.1.1</version> + </dependency> diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_Measurement.md b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_Measurement.md new file mode 100644 index 0000000..f17c9d4 --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_Measurement.md @@ -0,0 +1,32 @@ + +PROJECT DESCRIPTION + +--- +This project contains the source code and scripts for the periodic generation of network measurement reports events. It also generates fault event if the packets/bytes transferred are below the low water mark for the network interface. + + - README.md: this file. + + + - MeasureData.java and DeviceData.java files: source code that uses the ECOMP Vendor Event Listener Library (VES) to read metrics from the network interface and send periodic measurement reports to the VES collector in DCAE. It reads meas_config.json file for parameter values and populate the heartbeat event. If eventName parameter value is not given, the application terminates. If reportingEntityName and sourceName parameter values are not given, then it gets the hostname and populates it. + + + - - MeasureData.java: It reads input parameters like DCAE IP address and port from configuration files contained in /opt/config. Based on the collector configuration, use MeasureData.java for single and 2 collectors configuration. + + +USAGE +----- + +Update the configuration files with proper parameters values so that events generated would contain those values + +To run the MeasureData.java, please execute the following steps: + + -Compile Load Balance VES agent + javac -cp <.:dependent jars> ./evel_javalibrary/att/com/loadbalance + In Eclipse right click on veslibrary/ves_javalibrary/evel_javalib2 application-> click Run As ->and select -> mvn build option then + ->select the configuration mvn clean install. + + -Run Load Balance VES agent + java -cp <.:dependent jars> evel_javalibrary.att.com.loadbalance.MeasureData.java + In Eclipse right click on evel_javalibrary.att.com.loadbalance.MeasureData.java class right click -> click Run As -> click Java application. + + diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_Syslog.md b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_Syslog.md new file mode 100644 index 0000000..8b8ee6d --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/README_Syslog.md @@ -0,0 +1,30 @@ + +PROJECT DESCRIPTION + +--- +This project contains the source code and scripts for the periodic generation of network measurement reports and heartbeat events. It also generates fault event if the packets/bytes transferred are below the low water mark for the network interface. + + + - syslogData.java file: source code that uses the ECOMP Vendor Event Listener Library (VES) to read syslog message from /var/log/syslog and send syslog events to the VES collector in DCAE. It reads syslog_config.json file for parameter values and populate the syslog event. If eventName parameter value is not given, the application terminates. If reportingEntityName and sourceName parameter values are not given. + + + - - syslogData.java: It reads input parameters like DCAE IP address and port from configuration files contained in /opt/config. Based on the collector configuration, use MeasureData.java for single and 2 collectors configuration. + + +USAGE +----- + +Update the configuration files with proper parameters values so that events generated would contain those values + +To run the MeasureData.java, please execute the following steps: + + -Compile Load Balance VES agent + javac -cp <.:dependent jars> ./evel_javalibrary/att/com/loadbalance + In Eclipse right click on veslibrary/ves_javalibrary/evel_javalib2 application-> click Run As ->and select -> mvn build option then + ->select the configuration mvn clean install. + + -Run Load Balance VES agent + java -cp <.:dependent jars> evel_javalibrary.att.com.loadbalance.syslogData.java + In Eclipse right click on evel_javalibrary.att.com.loadbalance.syslogData.java class right click -> click Run As -> click Java application. + + diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/faultData.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/faultData.java deleted file mode 100644 index 5400ba3..0000000 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/faultData.java +++ /dev/null @@ -1,286 +0,0 @@ -package evel_javalibrary.att.com.loadbalance; -/**************************************************************************//** - * @file - * Evel Fault Event class extends EvelHeader class - * - * This file implements the Evel Fault Event class which is intended to provide a - * simple wrapper around the complexity of AT&T's Vendor Event Listener API so - * that VNFs can use it to send Fault events. - * - * License - * ------- - * Unless otherwise specified, all software contained herein is - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *****************************************************************************/ - -import java.io.File; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import evel_javalibrary.att.com.AgentMain; -import evel_javalibrary.att.com.EvelBatch; -import evel_javalibrary.att.com.EvelFault; -import evel_javalibrary.att.com.EvelFault.EVEL_SEVERITIES; -import evel_javalibrary.att.com.EvelFault.EVEL_SOURCE_TYPES; -import evel_javalibrary.att.com.EvelFault.EVEL_VF_STATUSES; -import evel_javalibrary.att.com.EvelHeader; -import evel_javalibrary.att.com.EvelHeader.PRIORITIES; - - - -public class faultData extends Thread{ - - static HashMap<String, String> fault_config = new HashMap<>(); - static HashMap<String, String> interface_config = new HashMap<>(); - - static HashMap<String, String> hm = new HashMap<>(); - - static String linkStart = ""; - static int linkCount; - - - static int gm_event_id = 1; - static String event_id1 = "fault"; - static String event_id = "00000000"; - static String event_id2=null; - - - static int bytes_in; - static int bytes_out; - static int packets_in; - static int packets_out; - - - static int falut_raised =0; - - - public void run() { - - String alarmCondition = "linkDown"; - String specificProblem = "Transmit-Receive issue"; - - Long start_epoch_microsec = 0L; - Long last_epoch_microsec = 0L; - - - MeasureData mdataThread = new MeasureData(); - hm = mdataThread.read_common_config_file(); - - read_fault_config_file(); - HashMap<String, String> intFaceMapFault = mdataThread.read_interface_config_file(); - int numOfInterfacesFalut = 0; - if( !intFaceMapFault.isEmpty() ) - numOfInterfacesFalut = intFaceMapFault.size(); - if( numOfInterfacesFalut <= 0) { - System.out.println("ERROR : Didn't find interfacess in config file, exiting thread"); - return; - } - - - HashMap falut_last_metrics = mdataThread.read_vpp_metrics(linkStart); - - while(true) { - //request_rate = rand()%10000; - //request_rate =2; - EvelBatch ebt = new EvelBatch(); - event_id2 = event_id1+ event_id+(gm_event_id++); -// EvelScalingMeasurement eveMeas = new EvelScalingMeasurement( Double.parseDouble(common_meas.get("measurementInterval")) , -// common_meas.get("eventName"), -// event_id2); - - EvelHeader header = new EvelHeader("", ""); - - - //EvelFault eveFalt = new EvelFault(fault_config.get("eventName"), event_id2, alarmCondition, specificProblem,EVEL_PRIORITY_MEDIUM, EVEL_SEVERITY_MAJOR,EVEL_SOURCE_HOST,EVEL_VF_STATUS_IDLE); - - EvelFault eveFalt = new EvelFault(fault_config.get("eventName"),event_id2, alarmCondition, specificProblem, - EvelHeader.PRIORITIES.EVEL_PRIORITY_HIGH, - EVEL_SEVERITIES.EVEL_SEVERITY_MAJOR, - EVEL_SOURCE_TYPES.EVEL_SOURCE_CARD, - EVEL_VF_STATUSES.EVEL_VF_STATUS_ACTIVE); - - - - //EvelFault eveFalt = new EvelFault(fault_config.get("eventName"), event_id2, alarmCondition,specificProblem,1,1,3,1); - // EvelFault eveFalt = new EvelFault("eventName", "event_id2", "alarmCondition","specificProblem",1,1,3,1); - // EvelFault eveFalt = new EvelFault(fault_config.get("eventName"), event_id2, alarmCondition,specificProblem,1,1,3,1); - - for( String falut : intFaceMapFault.keySet() ) { - - HashMap falut_current_metrics = mdataThread.read_vpp_metrics(falut); - if( falut_current_metrics.size() !=4 ) { - System.out.println("ERROR:: Did't get vpp metrics for vNic "+falut); - continue; - } - - if (Integer.parseInt((String) falut_current_metrics.get("bytes_in")) - - Integer.parseInt((String) falut_last_metrics.get("bytes_in")) > 0) { - bytes_in = Integer.parseInt((String) falut_current_metrics.get("bytes_in")) - - Integer.parseInt((String) falut_last_metrics.get("bytes_in")); - } else { - bytes_in = 0; - } - - if (Integer.parseInt((String) falut_current_metrics.get("bytes_out")) - - Integer.parseInt((String) falut_last_metrics.get("bytes_out")) > 0) { - bytes_out = Integer.parseInt((String) falut_current_metrics.get("bytes_out")) - - Integer.parseInt((String) falut_last_metrics.get("bytes_out")); - } else { - bytes_out = 0; - } - - if (Integer.parseInt((String) falut_current_metrics.get("packets_in")) - - Integer.parseInt((String) falut_last_metrics.get("packets_in")) > 0) { - packets_in = Integer.parseInt((String) falut_current_metrics.get("packets_in")) - - Integer.parseInt((String) falut_last_metrics.get("packets_in")); - } else { - packets_in = 0; - } - - if (Integer.parseInt((String) falut_current_metrics.get("packets_out")) - - Integer.parseInt((String) falut_last_metrics.get("packets_out")) > 0) { - packets_out = Integer.parseInt((String) falut_current_metrics.get("packets_out")) - - Integer.parseInt((String) falut_last_metrics.get("packets_out")); - } else { - packets_out = 0; - } - - - - if((bytes_in < Integer.parseInt((String)fault_config.get("lowWaterMark")) || bytes_out < Integer.parseInt((String)fault_config.get("lowWaterMark")) || - packets_in < Integer.parseInt((String)fault_config.get("lowWaterMark")) || packets_out < Integer.parseInt((String)fault_config.get("lowWaterMark"))) && falut_raised == 0){ - - event_id2 = event_id1+ (gm_event_id++); - - if(eveFalt != null) { - - falut_raised =1; - eveFalt.evel_fault_interface_set(linkStart); - - if( hm.get("eventType")!=null) { - eveFalt.evel_fault_type_set(hm.get("eventType")); - - start_epoch_microsec = last_epoch_microsec; - last_epoch_microsec = System.nanoTime()/1000; - - eveFalt.evel_last_epoch_set(start_epoch_microsec); - eveFalt.evel_start_epoch_set(last_epoch_microsec); - - eveFalt.evel_fault_category_set("link"); - eveFalt.evel_fault_interface_set("My Interface"); - eveFalt.evel_nfcnamingcode_set(hm.get("nfcNamingCode").toString()); - eveFalt.evel_nfnamingcode_set(hm.get("nfNamingCode").toString()); - eveFalt.evel_reporting_entity_name_set(hm.get("reportingEntityName").toString()); - eveFalt.evel_reporting_entity_id_set(hm.get("reportingEntityId").toString()); - eveFalt.evel_nfVendorName_set(hm.get("nfVendorName").toString()); - eveFalt.evel_header_set_sourceid(true,hm.get("sourceId").toString()); - - eveFalt.evel_header_set_source_name(hm.get("sourceName").toString()); - eveFalt.evel_timeZoneOffset_set(hm.get("timeZoneOffset").toString()); - - } - - } - - }else if((bytes_in > Integer.parseInt((String)fault_config.get("lowWaterMark")) && bytes_out > Integer.parseInt((String)fault_config.get("lowWaterMark")) && - packets_in > Integer.parseInt((String)fault_config.get("lowWaterMark")) && packets_out > Integer.parseInt((String)fault_config.get("lowWaterMark"))) && falut_raised == 1) { - - - - event_id2 = event_id1+ (gm_event_id++); -// EvelHeader header = new EvelHeader("", ""); -// EvelFault eveFalt = new EvelFault(fault_config.get("eventName"), event_id2, "linkDown", "Transmit-Receive issue", header.priority, eveFalt.event_severity,eveFalt.event_source_type,eveFalt.vf_status); - - if(eveFalt != null) { - falut_raised =1; - - eveFalt.evel_fault_interface_set(linkStart); - System.out.println("Event type is "+hm.get("eventType") ); - if( hm.get("eventType")!=null) { - eveFalt.evel_fault_type_set(hm.get("eventType")); - - eveFalt.evel_fault_category_set("link"); - eveFalt.evel_nfcnamingcode_set(hm.get("nfcNamingCode").toString()); - eveFalt.evel_nfnamingcode_set(hm.get("nfNamingCode").toString()); - eveFalt.evel_reporting_entity_name_set(hm.get("reportingEntityName").toString()); - eveFalt.evel_reporting_entity_id_set(hm.get("reportingEntityId").toString()); - eveFalt.evel_nfVendorName_set(hm.get("nfVendorName").toString()); - eveFalt.evel_header_set_sourceid(true,hm.get("sourceId").toString()); - - eveFalt.evel_header_set_source_name(hm.get("sourceName").toString()); - eveFalt.evel_timeZoneOffset_set(hm.get("timeZoneOffset").toString()); - - } - - } - - - - } - - - try { - Thread.sleep(1000); - }catch(Exception e) {} - } - // ebt.addEvent(eveFalt); - AgentMain.evel_post_event(eveFalt); - System.out.println(" Event sent"); - - } - - - } - - - - - - - public static HashMap<String, String> read_fault_config_file() { - - List<String> list = new ArrayList<String>(); - - List<String> list_interface = new ArrayList<String>(); - - fault_config.put("eventName", ""); - fault_config.put("faultCheckInterval", ""); - fault_config.put("lowWaterMark", ""); - - //interface_config.put("lo", ""); - - try { - // File file = new File("/home/ves/users/admin/temp/fw_flt_config.txt"); - File file = new File("./src/main/java/evel_javalibrary/att/com/loadbalance/fw_flt_config.txt"); - System.out.println("File path is..."+ file); - list = Files.readAllLines(file.toPath(), Charset.defaultCharset()); - for (String lineSplit : list) { - String[] res = lineSplit.split(" "); - fault_config.put(res[0], res[1]); - } - - - } catch (Exception ex) { - ex.printStackTrace(); - } - System.out.println("KEYS:fault_config " + fault_config.keySet().size()); - System.out.println("VALUES:fault_config " + fault_config.values()); - return fault_config; - } - - - -} diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/flt_config.json b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/flt_config.json new file mode 100644 index 0000000..edae8a6 --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/flt_config.json @@ -0,0 +1,74 @@ +{ + "tmp_directParameters": { + "eventType": "applicationVnf", + "nfcNamingCode": "AFX", + "nfNamingCode": "AFX", + "nfVendorName": "AT&T", + "priority": "Low", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "timeZoneOffset": "UTC-05:30", + "vfStatus": "Idle", + "tmp_device": ["lo", "enp0s3", "docker0"] + + }, + "tmp_indirectParameters": { + "tmp_faultInstance01": { + "eventName": "Fault_vLoadbalance-AT&T_linkDownError", + "eventCategory": "link", + "eventSourceType": "router", + "tmp_init":{ + "tmp_t0BytesIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f2", + "tmp_t0BytesOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f10", + "tmp_t0PacketsIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f3", + "tmp_t0PacketsOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f11" + }, + "alarmInterfaceA": "$tmp_device", + "tmp_faultCheckInterval": 20, + "tmp_lowWaterMark": 1, + "tmp_command": { + "tmp_t1BytesIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f2", + "tmp_t1BytesOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f10", + "tmp_t1PacketsIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f3", + "tmp_t1PacketsOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f11" + }, + "tmp_BytesIn": "$(tmp_t1BytesIn - tmp_t0BytesIn)", + "tmp_PacketsIn": "$(tmp_t1PacketsIn - tmp_t0PacketsIn)", + "tmp_BytesOut": "$(tmp_t1BytesOut - tmp_t0BytesOut)", + "tmp_PacketsOut": "$(tmp_t1PacketsOut - tmp_t0PacketsOut)", + "tmp_alarmSetParameters": { + "specificProblem": "physical or logical connection to a remote router is down", + "eventSeverity": "MAJOR", + "alarmCondition": "link down trap_alarm" + }, + "tmp_alarmClearParameters": { + "specificProblem": "physical or logical connection to a remote router is up", + "eventSeverity": "NORMAL", + "alarmCondition": "link up trap_alarm" + } + }, + "tmp_faultInstance02": { + "eventName": "Fault_vLoadbalance-AT&T_serviceDownError", + "alarmInterfaceA": "afx@input.service", + "eventCategory": "other", + "eventSourceType": "virtualMachine", + "tmp_faultCheckInterval": 10, + "tmp_command": { + + "tmp_cmd1": "echo 1" + }, + "tmp_alarmSetParameters": { + "specificProblem": "service is down", + "eventSeverity": "MAJOR", + "alarmCondition": "service down trap_alarm" + }, + "tmp_alarmClearParameters": { + "specificProblem": "service is up", + "eventSeverity": "NORMAL", + "alarmCondition": "service up trap_alarm" + } + } + } +} diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_common_config.txt b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_common_config.txt deleted file mode 100644 index e40b5b3..0000000 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_common_config.txt +++ /dev/null @@ -1,9 +0,0 @@ -eventType platform -nfcNamingCode ssc -nfNamingCode scfx -nfVendorName AT&T -reportingEntityId cc305d54-75b4-431b-adb2-eb6b9e541234 -reportingEntityName ibcx0001vm002oam001 -sourceId de305d54-75b4-431b-adb2-eb6b9e546014 -sourceName scfx0001vm002cap001 -timeZoneOffset UTC-05:30 diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_config.txt b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_config.txt deleted file mode 100644 index f730d6f..0000000 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_config.txt +++ /dev/null @@ -1,10 +0,0 @@ -eventName Measurement_vFirewall-AT&T_nicPerformance -eventType platform -nfcNamingCode ssc -nfNamingCode scfx -nfVendorName AT&T -reportingEntityId cc305d54-75b4-431b-adb2-eb6b9e541234 -reportingEntityName ibcx0001vm002oam001 -sourceId de305d54-75b4-431b-adb2-eb6b9e546014 -timeZoneOffset UTC-05:30 -measurementInterval 30 diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_flt_config.txt b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_flt_config.txt deleted file mode 100644 index 4b660ea..0000000 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_flt_config.txt +++ /dev/null @@ -1,3 +0,0 @@ -eventName Fault_vFirewall-AT&T_linkDownError -faultCheckInterval 30 -lowWaterMark 100 diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_hb_config.txt b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_hb_config.txt deleted file mode 100644 index c288120..0000000 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_hb_config.txt +++ /dev/null @@ -1,2 +0,0 @@ -eventName Heartbeat_vFirewall-AT&T_heartbeat -heartbeatInterval 20 diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_interface_config.txt b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_interface_config.txt deleted file mode 100644 index 46c3777..0000000 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_interface_config.txt +++ /dev/null @@ -1,13 +0,0 @@ -lo DNS1_RSLOTPORT_VLAN_CLASSTYPE -bond0 DNS2_RSLOTPORT_VLAN_CLASSTYPE -bond0.4020 DNS3_RSLOTPORT_VLAN_CLASSTYPE -bond0.4020.4020 DNS4_RSLOTPORT_VLAN_CLASSTYPE -bond0.4021 DNS5_RSLOTPORT_VLAN_CLASSTYPE -bond0.4021.4021 DNS6_RSLOTPORT_VLAN_CLASSTYPE -ens3 DNS7_RSLOTPORT_VLAN_CLASSTYPE -ens4 DNS8_RSLOTPORT_VLAN_CLASSTYPE -ens5 DNS9_RSLOTPORT_VLAN_CLASSTYPE -ens6 DNSa_RSLOTPORT_VLAN_CLASSTYPE -ens7 DNSb_RSLOTPORT_VLAN_CLASSTYPE -docker0 DNSb_RSLOTPORT_VLAN_CLASSTYPE -enp0s3 DNSb_RSLOTPORT_VLAN_CLASSTYPE diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_meas_config.txt b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_meas_config.txt deleted file mode 100644 index 7fac2f7..0000000 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/fw_meas_config.txt +++ /dev/null @@ -1,2 +0,0 @@ -eventName Measurement_vFirewall-AT&T_nicPerformance -measurementInterval 30 diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/hb_config.json b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/hb_config.json new file mode 100644 index 0000000..c1b3a19 --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/hb_config.json @@ -0,0 +1,15 @@ +{ + "tmp_directParameters": { + "eventName": "Heartbeat_vLoadbalance-AT&T_heartbeat", + "eventType": "platform", + "nfcNamingCode": "ssc", + "nfNamingCode": "scfx", + "nfVendorName": "AT&T", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "timeZoneOffset": "UTC-05:30", + "heartbeatInterval": 300 + } +} diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/heartBeatData.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/heartBeatData.java deleted file mode 100644 index 9da7521..0000000 --- a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/heartBeatData.java +++ /dev/null @@ -1,153 +0,0 @@ -package evel_javalibrary.att.com.loadbalance; -/**************************************************************************//** - * @file - * Heartbeat field class - * - * This file implements the Heartbeat Event class which is intended to provide a - * simple wrapper around the complexity of AT&T's Vendor Event Listener API so - * that VNFs can use it to send Agent status. - * - * License - * ------- - * Unless otherwise specified, all software contained herein is - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - *****************************************************************************/ - -import java.io.File; -import java.nio.charset.Charset; -import java.nio.file.Files; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import javax.json.Json; -import javax.json.JsonArray; -import javax.json.JsonArrayBuilder; -import javax.json.JsonObject; -import javax.json.JsonObjectBuilder; - -import evel_javalibrary.att.com.AgentMain; -import evel_javalibrary.att.com.EvelBatch; -import evel_javalibrary.att.com.EvelHeartbeatField; - -public class heartBeatData extends Thread{ - - static HashMap<String, String> hm = new HashMap<>(); - static HashMap<String, String> hb_config = new HashMap<>(); - static int gm_event_id = 1; - static String event_id1 = "mvfs"; - static String event_id2=null; - - - public void run() { - - Long start_epoch_microsec = 0L; - Long last_epoch_microsec = 0L; - - MeasureData mdataThread = new MeasureData(); - hm = mdataThread.read_common_config_file(); - read_hb_config_file(); - - while(true) { - event_id2 = event_id1+ (gm_event_id++); - - - EvelHeartbeatField evelHb = new EvelHeartbeatField(Integer.parseInt(hb_config.get("heartbeatInterval")) , - hb_config.get("eventName"), - event_id2); - - if( hm.get("eventType")!=null) { - - start_epoch_microsec = last_epoch_microsec; - last_epoch_microsec = System.nanoTime()/1000; - - evelHb.evel_last_epoch_set(start_epoch_microsec); - evelHb.evel_start_epoch_set(last_epoch_microsec); - - evelHb.evel_header_type_set(hm.get("eventType").toString()); - evelHb.evel_nfcnamingcode_set(hm.get("nfcNamingCode").toString()); - evelHb.evel_nfnamingcode_set(hm.get("nfNamingCode").toString()); - evelHb.evel_reporting_entity_name_set(hm.get("reportingEntityName").toString()); - evelHb.evel_reporting_entity_id_set(hm.get("reportingEntityId").toString()); - evelHb.evel_nfVendorName_set(hm.get("nfVendorName").toString()); - evelHb.evel_header_set_sourceid(true,hm.get("sourceId").toString()); - evelHb.evel_header_set_source_name(hm.get("sourceName").toString()); - - evelHb.evel_timeZoneOffset_set(hm.get("timeZoneOffset").toString()); - - - JsonObject obj = Json.createObjectBuilder() - .add( "heartbeatFields",evelHeartbeatFieldObject() - ).build(); - - EvelBatch ebt = new EvelBatch(); - //ebt.addEvent(evelHb); - - - System.out.println(" Event sent..."+ obj.asJsonObject()); - System.out.println("Event sent...###########"); - AgentMain.evel_post_event(evelHb); - System.out.println(" Event sent..."); - } - - try { - Thread.sleep(1000); - }catch(Exception e) { - - } - } - } - - - JsonObjectBuilder evelHeartbeatFieldObject() - { - String version = "3.0"; - JsonObjectBuilder evelHeatbeat = Json.createObjectBuilder() - .add("heartbeatInterval", hb_config.get("heartbeatInterval")); - evelHeatbeat.add( "heartbeatFieldsVersion", version); - return evelHeatbeat; - } - - - public static HashMap<String, String> read_hb_config_file() { - - List<String> list = new ArrayList<String>(); - - hb_config.put("eventName", ""); - hb_config.put("heartbeatInterval", ""); - - - System.out.println("KEYS: " + hb_config.keySet().size()); - System.out.println("VALUES: " + hb_config.values()); - - try { - //File file = new File("/home/ves/users/admin/temp/fw_hb_config.txt"); - File file = new File("./src/main/java/evel_javalibrary/att/com/loadbalance/fw_hb_config.txt"); - list = Files.readAllLines(file.toPath(), Charset.defaultCharset()); - for (String lineSplit : list) { - String[] res = lineSplit.split(" "); - hb_config.put(res[0], res[1]); -// System.out.println("File reading after split ---" + res[0]); -// System.out.println("File reading after split second---" + res[1]); - } - } catch (Exception ex) { - ex.printStackTrace(); - } - System.out.println("KEYS:hb_config " + hb_config.keySet().size()); - System.out.println("VALUES:hb_config " + hb_config.values()); - return hb_config; - } - - - - -} diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/meas_config.json b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/meas_config.json new file mode 100644 index 0000000..5d1a41e --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/meas_config.json @@ -0,0 +1,51 @@ +{ + "tmp_directParameters": { + "eventName": "Measurement_vFirewall-AT&T_nicPerformance", + "eventType": "applicationVnf", + "nfcNamingCode": "AFX", + "nfNamingCode": "AFX", + "nfVendorName": "AT&T", + "priority": "Low", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "timeZoneOffset": "UTC-05:30", + "measurementInterval": 25000, + "tmp_device": ["lo", "enp0s3","docker0"] + }, + "tmp_indirectParameters": { + "tmp_init":{ + "tmp_t0BytesIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f2", + "tmp_t0BytesOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f10", + "tmp_t0PacketsIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f3", + "tmp_t0PacketsOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f11" + }, + "vNicPerformance": [{ + "tmp_vnic_command": { + "tmp_t1BytesIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f2", + "tmp_t1BytesOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f10", + "tmp_t1PacketsIn": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f3", + "tmp_t1PacketsOut": "sudo cat /proc/net/dev | grep $tmp_device | tr -s ' ' | cut -d ':' -f2 | cut -d ' ' -f11" + }, + "receivedOctetsDelta": "$(tmp_t1BytesIn - tmp_t0BytesIn)", + "receivedTotalPacketsDelta": "$(tmp_t1PacketsIn - tmp_t0PacketsIn)", + "transmittedOctetsDelta": "$(tmp_t1BytesOut - tmp_t0BytesOut)", + "transmittedTotalPacketsDelta": "$(tmp_t1PacketsOut - tmp_t0PacketsOut)", + "valuesAreSuspect": "true", + "vNicIdentifier": "$tmp_device" + }], + "cpuUsage": [{ + "tmp_cpuuse_command": { + "tmp_cpuUseCmd": "/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 | cut -d ':' -f2", + "tmp_cpuIdle": "/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 |cut -d ':' -f2 | cut -d ',' -f4 | cut -b 1-5", + "tmp_cpuUsageSystem": "/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 |cut -d ':' -f2 | cut -d ',' -f2 | cut -b 1-5", + "tmp_cpuUsageUser": "/usr/bin/top -bn 2 -d 0.01 | grep '^%Cpu' | tail -n 1 |cut -d ':' -f2 | cut -d ',' -f1 | cut -b 1-5" + }, + "cpuIdentifier": "Cpu1", + "cpuIdle": "$tmp_cpuIdle", + "cpuUsageSystem": "$tmp_cpuUsageSystem", + "cpuUsageUser": "$tmp_cpuUsageUser" + }] + } +}
\ No newline at end of file diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/syslogData.java b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/syslogData.java new file mode 100644 index 0000000..89fc89d --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/syslogData.java @@ -0,0 +1,274 @@ +package evel_javalibrary.att.com.loadbalance; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import org.apache.log4j.Level; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; +import evel_javalibrary.att.com.AgentMain; +import evel_javalibrary.att.com.EvelSyslog; +import evel_javalibrary.att.com.EvelFault; +import evel_javalibrary.att.com.EvelSyslog.EVEL_SYSLOG_FACILITIES; + +/**************************************************************************//** + * @file + * Syslog class + * + * This file implements the Measurement Event class which is intended to provide a + * simple wrapper around the complexity of AT&T's Vendor Event Listener API so + * that VNFs can use it to send CPU, Memory, Disk Measurements to Collector. + * + * License + * ------- + * Unless otherwise specified, all software contained herein is + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *****************************************************************************/ + +public class syslogData extends Thread{ + + + static HashMap<String, String> syslogConfig = new HashMap<>(); + static String[] interfaceDevice =null; + + static String syslogInterval=""; + static String syslogFile =""; + static String tempCommand = ""; + static int gmEventId = 1; + static String eventId1 = "syslog"; + static String eventId = "00000000"; + static String eventId2=null; + + private static int linesReadFromFile =0; + + public void run() { + try { + readSyslogConfig(); + + } catch (IOException | ParseException e) {} + + while(true) { + String tagToCompare = syslogConfig.get("syslogTag").toString(); + + syslogFileRead(tagToCompare ); + + try { Thread.sleep(500);}catch(Exception e) {} + + } + } + + + public void sendSysLogEvent(String sysTag,String syslogMsg) { + Long start_epoch_microsec = 0L; + Long last_epoch_microsec = 0L; + String hostName = hostName(); + + eventId2 = eventId1+ eventId+(gmEventId++); + EvelSyslog eveSyslog = new EvelSyslog(syslogConfig.get("eventName"), + eventId2, EvelFault.EVEL_SOURCE_TYPES.EVEL_SOURCE_VIRTUAL_MACHINE, + syslogMsg, sysTag); + + if( syslogConfig.get("eventType")!=null) { + start_epoch_microsec = last_epoch_microsec; + last_epoch_microsec = System.nanoTime()/1000; + + eveSyslog.evel_last_epoch_set(start_epoch_microsec); + eveSyslog.evel_start_epoch_set(last_epoch_microsec); + + eveSyslog.evel_header_type_set(syslogConfig.get("eventType").toString()); + eveSyslog.evel_nfcnamingcode_set(syslogConfig.get("nfcNamingCode").toString()); + eveSyslog.evel_nfnamingcode_set(syslogConfig.get("nfNamingCode").toString()); + if(syslogConfig.get("reportingEntityName") == null) { + eveSyslog.evel_reporting_entity_name_set(hostName); + }else { + eveSyslog.evel_reporting_entity_name_set(syslogConfig.get("reportingEntityName").toString()); + } + eveSyslog.evel_reporting_entity_id_set(syslogConfig.get("reportingEntityId").toString()); + eveSyslog.evel_nfVendorName_set(syslogConfig.get("nfVendorName").toString()); + eveSyslog.evel_header_set_sourceid(true,syslogConfig.get("sourceId").toString()); + if(syslogConfig.get("sourceName") == null) { + eveSyslog.evel_header_set_source_name(hostName); + }else { + eveSyslog.evel_header_set_source_name(syslogConfig.get("sourceName").toString()); + } + eveSyslog.evel_timeZoneOffset_set(syslogConfig.get("timeZoneOffset").toString()); + } + + eveSyslog.evel_syslog_facility_set(EVEL_SYSLOG_FACILITIES.EVEL_SYSLOG_FACILITY_LOCAL0); + eveSyslog.evel_syslog_proc_set(syslogConfig.get("syslogProc").toString()); + + + + AgentMain.evel_post_event(eveSyslog); + + } + + public String syslogFileRead(String tagToCompare){ + String syslines =""; + int currentIndex = 0; + boolean compare = false; + + try { + + BufferedReader reader = new BufferedReader(new FileReader("/var/log/syslog")); + String line = reader.readLine(); + while (line != null) { + if( currentIndex == linesReadFromFile ) { + compare=true; + } + if( compare ) { + if( line.contains(tagToCompare) ) + sendSysLogEvent( tagToCompare, line); + } + currentIndex ++; + + line = reader.readLine(); + } + + if( compare ) + linesReadFromFile=currentIndex; + + + } catch (Exception ex) { + ex.printStackTrace(); + } + + return null; + } + + private final static char[] hexArray = "0123456789ABCDEF".toCharArray(); + private static String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for ( int j = 0; j < bytes.length; j++ ) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = hexArray[v >>> 4]; + hexChars[j * 2 + 1] = hexArray[v & 0x0F]; + } + return new String(hexChars); + } + + public static String hostName() { + String hostname = "Unknown"; + String uuid = "Unknown"; + try + { + InetAddress addr; + addr = InetAddress.getLocalHost(); + hostname = addr.getHostName(); + } + catch (UnknownHostException ex) + { + + } + try{ + Enumeration<NetworkInterface> networks = + NetworkInterface.getNetworkInterfaces(); + while(networks.hasMoreElements()) { + NetworkInterface network = networks.nextElement(); + byte[] mac = network.getHardwareAddress(); + + if(hostname.equalsIgnoreCase("unknown")) + { + Enumeration inetAddrs = network.getInetAddresses(); + while(inetAddrs.hasMoreElements()){ + InetAddress inetAddr = (InetAddress) inetAddrs.nextElement(); + if (!inetAddr.isLoopbackAddress()) { + hostname = inetAddr.getHostAddress(); + break; + } + } + } + if (mac != null) { + uuid = bytesToHex(mac); + } + } + } catch (SocketException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return hostname; + } + + + public static HashMap<String, String> readSyslogConfig() throws IOException, ParseException { + + JSONParser jsonParser = new JSONParser(); + try { + + FileReader reader = new FileReader("./src/main/java/evel_javalibrary/att/com/loadbalance/syslog_config.json"); + JSONObject obj = (JSONObject) jsonParser.parse(reader); + Map.Entry directPair = null; + String directObject =""; + String[] directres; + Map directParameters = ((Map)obj.get("tmp_directParameters")); + Iterator<Map.Entry> itr1 = directParameters.entrySet().iterator(); + while (itr1.hasNext()) { + directPair = itr1.next(); + directObject=String.valueOf(directPair); + directres = directObject.split("="); + syslogConfig.put(directres[0], directres[1]); + + } + //tmp_indirectParameters + Map.Entry indirectPair = null; + String indirectObject =""; + String[] indirectres; + Map indirectParameters = ((Map)obj.get("tmp_indirectParameters")); + Iterator<Map.Entry> itr2 = indirectParameters.entrySet().iterator(); + while (itr2.hasNext()) { + indirectPair = itr2.next(); + indirectObject=String.valueOf(indirectPair); + indirectres = indirectObject.split("="); + syslogConfig.put(indirectres[0], indirectres[1]); + } + syslogFile = syslogConfig.get("tmp_syslogFile").toString(); + } catch (ClassCastException ex) { + ex.printStackTrace(); + } + return syslogConfig; + } + + + public static void main(String[] args) { + // TODO Auto-generated method stub + + try { + AgentMain.evel_initialize("http://127.0.0.1",30000, + null,null, + "will", + "pill", + null, null, null, + "http://127.0.0.1",30001, "will", + "pill", + Level.TRACE); + }catch(Exception e) { + e.printStackTrace(); + return; + } + syslogData syslogDataThread = new syslogData(); + syslogDataThread.start(); + } + + + + +} diff --git a/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/syslog_config.json b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/syslog_config.json new file mode 100644 index 0000000..6b598b1 --- /dev/null +++ b/veslibrary/ves_javalibrary/evel_javalib2/src/main/java/evel_javalibrary/att/com/loadbalance/syslog_config.json @@ -0,0 +1,20 @@ +{ + "tmp_directParameters": { + "eventName": "syslog_vLoadbalance-AT&T_connectionReset", + "eventType": "applicationVnf", + "nfcNamingCode": "AFX", + "nfNamingCode": "AFX", + "nfVendorName": "AT&T", + "reportingEntityId": "cc305d54-75b4-431b-adb2-eb6b9e541234", + "reportingEntityName": "ibcx0001vm002oam001", + "sourceId": "de305d54-75b4-431b-adb2-eb6b9e546014", + "sourceName": "scfx0001vm002cap001", + "timeZoneOffset": "UTC-05:30", + "eventSourceType": "virtualMachine", + "syslogProc": "vSyslog", + "syslogTag": "INSECURE MODE" + }, + "tmp_indirectParameters": { + "tmp_syslogFile": "/var/log/syslog" + } +}
\ No newline at end of file |