2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdnc.config.generator.tool;
23 import java.text.ParseException;
24 import java.text.SimpleDateFormat;
25 import java.util.ArrayList;
26 import java.util.Date;
27 import java.util.List;
29 import com.att.eelf.configuration.EELFLogger;
30 import com.att.eelf.configuration.EELFManager;
32 public class LogParserTool {
33 private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class);
35 private String[] singleLines;
36 private List<String> recentErrors = new ArrayList<String> ();;
37 private Date todaysDate = new Date();
38 private SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
39 private final int minMilli = 60000;
40 private final int IN_TIME = 0;
41 private final int NOT_IN_TIME = 1;
42 private final int NO_DATE = 2;
44 public String parseErrorLog(String data){
45 singleLines = data.split("\\r?\\n");
49 } catch (Exception e) {
52 if(recentErrors.size() == 0){
54 return "Did not find the string 'Starting orchestration of file backed up to /var/opt/MetaSwitch/orch/orch_conf.json' in the log file with timestamp within the last 5 minutes";
55 }else if(recentErrors.size() == 1){
57 return "Did not find the string ‘Error parsing orchestration file’ in the log file with timestamp within the last 5 minutes";
59 String error = recentErrors.get(0);
61 return "Error: "+ error.substring(error.indexOf("Error parsing orchestration file:")+34);
65 public void getNearestDates() throws ParseException{
67 for( int i = singleLines.length-1; i >= 0 ; i--){
68 if(singleLines[i].contains("Starting orchestration of file backed up to") || singleLines[i].contains("Error parsing orchestration file:")){
69 result = checkDateTime(singleLines[i]);
70 if( result == IN_TIME)
71 recentErrors.add(singleLines[i]);
72 else if(result == NOT_IN_TIME){
79 private int checkDateTime(String line){
82 newDate = dFormat.parse(line.substring(0, 19));
83 if((todaysDate.getTime() - newDate.getTime()) <= 5*minMilli){
87 } catch (ParseException e) {