2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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 * ============LICENSE_END=========================================================
24 package org.onap.sdnc.config.generator.tool;
26 import com.att.eelf.configuration.EELFLogger;
27 import com.att.eelf.configuration.EELFManager;
28 import java.text.ParseException;
29 import java.text.SimpleDateFormat;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.List;
34 public class LogParserTool {
36 private static final EELFLogger log = EELFManager.getInstance().getLogger(JSONTool.class);
38 private String[] singleLines;
39 private List<String> recentErrors = new ArrayList<>();
40 private Date todaysDate = new Date();
41 private SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
43 private static final int MIN_MILLI = 60000;
44 private static final int IN_TIME = 0;
45 private static final int NOT_IN_TIME = 1;
46 private static final int NO_DATE = 2;
48 public String parseErrorLog(String data) {
49 singleLines = data.split("\\r?\\n");
53 } catch (Exception e) {
54 log.error("Failed to get nearest dates", e);
56 if (recentErrors.isEmpty()) {
58 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";
59 } else if (recentErrors.size() == 1) {
61 return "Did not find the string ?Error parsing orchestration file? in the log file with timestamp within the last 5 minutes";
63 String error = recentErrors.get(0);
66 + error.substring(error.indexOf("Error parsing orchestration file:") + 34);
70 private void getNearestDates() throws ParseException {
72 for (int i = singleLines.length - 1; i >= 0; i--) {
73 if (singleLines[i].contains("Starting orchestration of file backed up to")
74 || singleLines[i].contains("Error parsing orchestration file:")) {
75 result = checkDateTime(singleLines[i]);
76 if (result == IN_TIME) {
77 recentErrors.add(singleLines[i]);
78 } else if (result == NOT_IN_TIME) {
85 private int checkDateTime(String line) {
88 newDate = dFormat.parse(line.substring(0, 19));
89 if ((todaysDate.getTime() - newDate.getTime()) <= 5 * MIN_MILLI) {
94 } catch (ParseException e) {
95 log.error("Failed to parse date", e);