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 java.text.ParseException;
28 import java.text.SimpleDateFormat;
29 import java.util.ArrayList;
30 import java.util.Date;
31 import java.util.List;
32 import com.att.eelf.configuration.EELFLogger;
33 import com.att.eelf.configuration.EELFManager;
35 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<String>();;
40 private Date todaysDate = new Date();
41 private SimpleDateFormat dFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
42 private final int minMilli = 60000;
43 private final int IN_TIME = 0;
44 private final int NOT_IN_TIME = 1;
45 private final int NO_DATE = 2;
47 public String parseErrorLog(String data) {
48 singleLines = data.split("\\r?\\n");
52 } catch (Exception e) {
55 if (recentErrors.size() == 0) {
57 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";
58 } else if (recentErrors.size() == 1) {
60 return "Did not find the string ?Error parsing orchestration file? in the log file with timestamp within the last 5 minutes";
62 String error = recentErrors.get(0);
65 + error.substring(error.indexOf("Error parsing orchestration file:") + 34);
69 public void getNearestDates() throws ParseException {
71 for (int i = singleLines.length - 1; i >= 0; i--) {
72 if (singleLines[i].contains("Starting orchestration of file backed up to")
73 || singleLines[i].contains("Error parsing orchestration file:")) {
74 result = checkDateTime(singleLines[i]);
75 if (result == IN_TIME)
76 recentErrors.add(singleLines[i]);
77 else if (result == NOT_IN_TIME) {
84 private int checkDateTime(String line) {
87 newDate = dFormat.parse(line.substring(0, 19));
88 if ((todaysDate.getTime() - newDate.getTime()) <= 5 * minMilli) {
92 } catch (ParseException e) {