2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.sdnc.config.generator.tool;
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import java.text.ParseException;
30 import java.text.SimpleDateFormat;
31 import java.util.ArrayList;
32 import java.util.Date;
33 import java.util.List;
35 public class LogParserTool {
37 private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class);
39 private String[] singleLines;
40 private List<String> recentErrors = new ArrayList<String>();
42 private Date todaysDate = new Date();
43 private SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
44 private final int minMilli = 60000;
45 private final int IN_TIME = 0;
46 private final int NOT_IN_TIME = 1;
47 private final int NO_DATE = 2;
49 public String parseErrorLog(String data) {
50 singleLines = data.split("\\r?\\n");
54 } catch (Exception e) {
57 if (recentErrors.size() == 0) {
59 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";
60 } else if (recentErrors.size() == 1) {
62 return "Did not find the string ?Error parsing orchestration file? in the log file with timestamp within the last 5 minutes";
64 String error = recentErrors.get(0);
67 + error.substring(error.indexOf("Error parsing orchestration file:") + 34);
71 public void getNearestDates() throws ParseException {
73 for (int i = singleLines.length - 1; i >= 0; i--) {
74 if (singleLines[i].contains("Starting orchestration of file backed up to")
75 || singleLines[i].contains("Error parsing orchestration file:")) {
76 result = checkDateTime(singleLines[i]);
77 if (result == IN_TIME) {
78 recentErrors.add(singleLines[i]);
79 } else if (result == NOT_IN_TIME) {
86 private int checkDateTime(String line) {
89 newDate = dFormat.parse(line.substring(0, 19));
90 if ((todaysDate.getTime() - newDate.getTime()) <= 5 * minMilli) {
95 } catch (ParseException e) {