259b2cb03865df786e55b54cea9ec01f7dcffe8e
[policy/engine.git] / LogParser / src / main / java / org / onap / xacml / parser / ParseLog.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * LogParser
4  * ================================================================================
5  * Copyright (C) 2017-2018 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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.xacml.parser;
22
23 import java.io.File;
24 import java.io.FileInputStream;
25 import java.io.FileReader;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import java.io.LineNumberReader;
29 import java.io.RandomAccessFile;
30 import java.nio.charset.Charset;
31 import java.nio.file.Files;
32 import java.nio.file.Path;
33 import java.nio.file.Paths;
34 import java.sql.Connection;
35 import java.sql.DriverManager;
36 import java.sql.PreparedStatement;
37 import java.sql.SQLException;
38 import java.text.Format;
39 import java.text.ParseException;
40 import java.text.SimpleDateFormat;
41 import java.util.Date;
42 import java.util.Properties;
43 import java.util.Timer;
44 import java.util.regex.Matcher;
45 import java.util.regex.Pattern;
46 import java.util.stream.Stream;
47
48 import org.apache.log4j.Logger;
49 import org.onap.policy.common.im.AdministrativeStateException;
50 import org.onap.policy.common.im.IntegrityMonitor;
51 import org.onap.policy.common.im.StandbyStatusException;
52 import org.onap.policy.common.logging.flexlogger.FlexLogger;
53 import org.onap.policy.utils.CryptoUtils;
54 import org.onap.xacml.parser.LogEntryObject.LOGTYPE;
55
56 /**
57  * Parse log files and store the information in a H2 database.
58  * 
59  *
60  */
61 public class ParseLog {
62         
63         // only logging last line of each log file processed to the log4j log file defined by property - PARSERLOGPATH
64         private static final Logger log4jlogger = Logger.getLogger(ParseLog.class.getName());
65
66         // processing logging 
67         private static org.onap.policy.common.logging.flexlogger.Logger logger = FlexLogger.getLogger(ParseLog.class.getName());
68
69         private static String system;
70         private static int lastNumberRead = 0;
71         private static int debuglastNumberRead = 0;
72         private static int errorlastNumberRead = 0;
73         private static String type;
74         private static long startFileSize;
75         private static long debugStartFileSize;
76         private static long errorStartFileSize;
77         private static String systemLogFile;
78         private static String logFile;
79         private static String debuglogFile;
80         private static String errorlogFile;
81         private static String jdbcUrl;
82         private static String jdbcUser;
83         private static String jdbcPassword;
84         private static String jdbcDriver;
85         private static int maxLength = 255;   //Max length that is allowed in the DB table
86         private static String resourceName;
87         private static long sleepTimer = 50000;
88         static  IntegrityMonitor im;
89         private static boolean isMissingLogFile;
90         //Default:Timer initial delay and the delay between in milliseconds before task is to be execute
91         private static final int TIMER_DELAY_TIME = 1000;       
92         //Default:Timer scheduleAtFixedRate period - time in milliseconds between successive task executions
93         private static int checkInterval = 86400000;  // run this clean up once a day   
94         private static String loggingProcess = "Error processing line in ";
95         private static int defaultTimeFrame = 5;        
96         private static String message =" value read in: ";      
97         private static String lineFormat = "(\\r\\n|\\n)";      
98         private static String lineRead = "-line-Read:"; 
99         private static String br= "<br />";
100         private static String last = "Last-";
101         private static String breakLoop = "break the loop.";
102         private static String dateFormat = "yyyy-MM-dd HH:mm:ss";
103         
104         public static void main(String[] args) throws Exception {
105
106                 Properties logProperties = getPropertiesValue("parserlog.properties");
107                 
108                 if(logProperties == null || isMissingLogFile){
109                         // missing the path of log file in the properties file, so stop the process
110                         logger.error("logProperties is null or LOGPATH is missing in parserlog.properties, so stop the process.");
111                         return;
112                 }
113                 
114                 //trigger the cleanup systemLogDb timer
115                 startCleanUp();
116      
117                 File fileLog = new File(systemLogFile);
118
119         im = IntegrityMonitor.getInstance(resourceName,logProperties );
120                 
121                 startDebugLogParser(fileLog);
122                 startErrorLogParser(fileLog);
123                 startAPIRestLogParser(fileLog); 
124         
125         }       
126         
127         private static boolean processLine(Path debugfilePath, String dataFileName, int lastNmRead, LOGTYPE logType){
128                 // log4jlogger must use .info
129                 try(Stream<String> lines = Files.lines(debugfilePath, Charset.defaultCharset()).onClose(() -> log4jlogger.info(last+dataFileName+ lineRead + lastNmRead)).skip(lastNmRead)){
130                         lines.forEachOrdered(line -> process(line, type, logType));
131                 } catch (IOException e) {
132                         logger.error(loggingProcess + dataFileName, e);
133                         logger.error(breakLoop);
134                         return true;
135                 }
136                 return false;
137         }
138         private static void processDebugLogParser(File debugfile, Path debugfilePath, String dataFileName){
139                 
140                 Runnable  runnable = new Runnable (){
141                         boolean isStop = false;                         
142                         public void run(){
143                                 while (!isStop){                                     
144                                         if (debugfile.isFile()){
145                                                 isStop = processLine(debugfilePath, dataFileName, debuglastNumberRead, LOGTYPE.DEBUG);
146                                         }
147                                         try {
148                                                 Thread.sleep(sleepTimer);
149                                                 debugStartFileSize =  countLines(debuglogFile);
150                                         } catch (Exception e) {
151                                                 logger.error(loggingProcess + dataFileName, e);
152                                                 logger.error(breakLoop);
153                                                 isStop = true;
154                                         }                                               
155                                         logger.debug("File Line Count of debug.log: " + debugStartFileSize + message + debuglastNumberRead);
156                                         if (debugStartFileSize < debuglastNumberRead ){
157                                                 logger.debug("Failed Rolled: set Last number read to 0");
158                                                 debuglastNumberRead = 0;
159                                         }
160                                 }       
161                         }
162                 };
163                 
164                 Thread thread = new Thread(runnable);
165                 thread.start();
166         }
167         
168         private static void startDebugLogParser(File fileLog) throws IOException{
169                 
170                 if(debuglogFile != null && !debuglogFile.isEmpty()){
171                         
172                         // pull the last line number 
173                         String dataFileName = "debug.log";
174                         String filesRead = pullLastLineRead(fileLog, dataFileName);  
175                         if (filesRead!= null){                  
176                                 filesRead = filesRead.replaceAll(lineFormat, br);
177                                 debuglastNumberRead= Integer.parseInt(filesRead.trim());
178                         }else{
179                                 debuglastNumberRead = 0;
180                         }       
181                         
182                         debugStartFileSize =  countLines(debuglogFile);
183                         if (debugStartFileSize < debuglastNumberRead ){ 
184                                 logger.error("Filed Rolled: set Last debug number read to 0");
185                                 debuglastNumberRead = 0;
186                         }
187                         
188                         isMissingLogFile = false; 
189                         Path debugfilePath = Paths.get(debuglogFile);
190                         File debugfile = new File(debuglogFile);
191                         debugStartFileSize = debugfile.length();
192                         
193                         // start process debug.log file
194                         processDebugLogParser(debugfile, debugfilePath, dataFileName);
195                 
196                 }       
197         }
198         
199         private static void processErrorLogParser(File errorfile, Path errorfilePath, String dataFileName){
200                 Runnable  runnable = new Runnable (){
201                         boolean isStop = false;
202                         public void run(){
203                 
204                                 while (!isStop){
205                                         if (errorfile.isFile()){
206                                                 isStop = processLine(errorfilePath, dataFileName, errorlastNumberRead, LOGTYPE.ERROR);
207                                         }
208                                         try {
209                                                 Thread.sleep(sleepTimer);
210                                                 errorStartFileSize =  countLines(errorlogFile);
211                                         } catch (Exception e) {
212                                                 logger.error(loggingProcess + dataFileName, e);
213                                                 logger.error(breakLoop);
214                                                 isStop = true;
215                                         }
216                                         
217                                         logger.debug("File Line Count of error.log: " + errorStartFileSize + message + errorlastNumberRead);
218                                         if (errorStartFileSize < errorlastNumberRead ){
219                                                 logger.debug("Failed Rolled: set Last error number read to 0");
220                                                 errorlastNumberRead = 0;
221                                         }
222                                 }       
223                         }
224                 };
225                 
226                 Thread thread = new Thread(runnable);
227                 thread.start();
228         }
229
230         private static void startErrorLogParser(File fileLog) throws IOException{
231                 
232                 if(errorlogFile != null && !errorlogFile.isEmpty()){
233                         
234                         // pull the last line number 
235                         String dataFileName = "error.log";
236                         String filesRead = pullLastLineRead(fileLog, dataFileName);  
237                         if (filesRead!= null){                  
238                                 filesRead = filesRead.replaceAll(lineFormat, br);
239                                 errorlastNumberRead= Integer.parseInt(filesRead.trim());
240                         }else{
241                                 errorlastNumberRead = 0;
242                         }       
243                         
244                         errorStartFileSize =  countLines(errorlogFile);
245                         if (errorStartFileSize < errorlastNumberRead ){
246                                 logger.error("Filed Rolled: set Last error number read to 0");
247                                 errorlastNumberRead = 0;
248                         }
249                         
250                         isMissingLogFile = false;                       
251                         Path errorfilePath = Paths.get(errorlogFile);
252                         File errorfile = new File(errorlogFile);
253                         errorStartFileSize = errorfile.length();
254                         // start process error.log file
255                         processErrorLogParser(errorfile, errorfilePath, dataFileName);
256
257                 }               
258         }
259         
260         private static void processAPIRestLog(File file, Path filePath, String dataFileName){
261                 
262                 Runnable  runnable = new Runnable () {
263                         boolean isStop = false;
264                         public void run(){
265                                 while (!isStop){                
266                                         
267                                         if (file.isFile()){
268                                                 isStop = processLine(filePath, dataFileName, lastNumberRead, LOGTYPE.INFO);
269                                         }
270                                         try {
271                                                 Thread.sleep(sleepTimer);
272                                                 startFileSize =  countLines(logFile);
273                                         } catch (Exception e) {
274                                                 logger.error(loggingProcess + dataFileName, e);
275                                                 logger.error(breakLoop);
276                                                 isStop = true;
277                                         }
278                                         
279                                         logger.debug("File Line Count of " + dataFileName+": " + startFileSize + message + lastNumberRead);
280                                         if (startFileSize < lastNumberRead ){
281                                                 logger.debug("Failed Rolled: set Last number read to 0");
282                                                 lastNumberRead = 0;
283                                         }
284                                 }       
285                         }
286                 };
287                         
288                 Thread thread = new Thread(runnable);
289                 thread.start();
290         }
291         
292         private static void startAPIRestLogParser(File fileLog) throws IOException{
293                 
294                 if(logFile != null && !logFile.isEmpty()){
295                         
296                         // pull the last line number 
297                         String dataFileName = type.toLowerCase()+"-rest.log";
298                         String filesRead = pullLastLineRead(fileLog, dataFileName);  
299                         if (filesRead!= null){                  
300                                 filesRead = filesRead.replaceAll(lineFormat, br);
301                                 lastNumberRead= Integer.parseInt(filesRead.trim());
302                         }else{
303                                 lastNumberRead = 0;
304                         }                       
305                         startFileSize =  countLines(logFile);
306                         if (startFileSize < lastNumberRead ){
307                                 logger.error("Filed Rolled: set Last number read to 0");
308                                 lastNumberRead = 0;
309                         }
310                         
311                         isMissingLogFile = false;
312                 Path filePath = Paths.get(logFile);
313                 File file = new File(logFile);          
314                         startFileSize = file.length();
315                         // start process pap/pdp-rest.log file
316                         processAPIRestLog(file, filePath, dataFileName);
317                 }               
318         }
319         
320         public static int countLines(String filename){
321             int cnt = 0;        
322                 try (
323                         FileReader freader = new FileReader(filename);
324                         LineNumberReader reader  = new LineNumberReader(freader);
325                 ) {
326                     String line= null;
327                     while ((line = reader.readLine()) != null) {
328                         logger.debug("Reading the Logs"+line);
329                     }
330                     cnt = reader.getLineNumber();
331                     logger.info("Line number:"+cnt);
332                     reader.close();
333                     freader.close();
334                     
335                 }catch(Exception e){
336                         logger.error(e);
337                 } 
338
339             return cnt;
340         }       
341         
342         public static String pullLastLineRead(File file, String dataFileName) throws IOException {
343                 if(!file.exists()){
344                         file.createNewFile();
345                         return null;
346                 }
347                 try(RandomAccessFile randomAccessFile = new RandomAccessFile(file, "r");){
348                     StringBuilder builder = new StringBuilder();
349                     long length = file.length();
350                     logger.debug("dataFileName: " +dataFileName);
351                     if(length > 0){
352                         length--;               
353                         randomAccessFile.seek(length);
354                         for(long seek = length; seek >= 0; --seek){
355                             randomAccessFile.seek(seek);
356                             char c = (char)randomAccessFile.read();
357                             builder.append(c);
358                             if(c == '\n'){
359                                 builder = builder.reverse();
360                                 logger.debug("builder.toString(): " +builder.toString());
361                                 if (builder.toString().contains(last+dataFileName+lineRead)){
362                                     String[] parseString = builder.toString().split(last+dataFileName+lineRead);
363                                     String returnValue = parseString[1].replace("\r", "");
364                                     randomAccessFile.close();
365                                     return returnValue.trim();
366                                 }
367                                 builder = new StringBuilder();
368                             }   
369                         }
370                     }
371                     randomAccessFile.close();
372                 }
373                 return null;
374         }
375
376         private static LogEntryObject getDebugOutLogValue (String line, String type){
377                 
378                 Date date;
379                 LogEntryObject logEntry = new LogEntryObject();
380                 logEntry.setSystemType(type);
381                 logEntry.setSystem(system);
382                 String info1 = "||INFO||";
383                 String info2 = "INFO:";
384                 String error1 = "||ERROR||";
385                 String error2 = "ERROR:";
386                 
387                 if(line.contains(info1) || line.contains(error1) || line.contains(info2) || line.contains(error2)){
388                         String[] splitString = null;
389                         if(line.contains(info1) || line.contains(error1)){
390                                 splitString = line.split("[||]");
391                         }else if(line.contains(info2)){
392                                 splitString = line.split(info2);
393                         }else{
394                                 splitString = line.split(error2);
395                         }
396                         String dateString = splitString[0].substring(0, 19);
397                         logEntry.setDescription(splitString[splitString.length-1]);     
398
399                         //parse out date
400                         date = parseDate(dateString.replace("T", " "), dateFormat, false);
401                         logEntry.setDate(date);
402                         
403                         logEntry.setRemote(parseRemoteSystem(line));
404                         if (line.contains(info2) || line.contains(info1)){
405                                 logEntry.setLogType(LOGTYPE.INFO);
406                         }else{
407                                 logEntry.setLogType(LOGTYPE.ERROR);
408                         }
409
410                         return logEntry;
411                 }
412                 
413                 return null;
414         }
415         
416         private static LogEntryObject getRestAPIOutLogValue (String line, String type){
417                 Date date;
418                 LogEntryObject logEntry = new LogEntryObject();
419                 logEntry.setSystemType(type);
420                 logEntry.setSystem(system);
421                 String info3 = "INFO";
422
423         // from PDP/PAP rest log file below
424                 if (line.contains(info3) && line.contains(")-")){ 
425                         //parse out description
426                         logEntry.setDescription(line.substring(line.indexOf(")-")+3));
427
428                         date = parseDate(line, dateFormat, true);
429                         logEntry.setDate(date);
430         
431                         logEntry.setRemote(parseRemoteSystem(line));
432                         logEntry.setLogType(LOGTYPE.INFO);
433                         
434                         return logEntry;
435                 } 
436                         
437                 return null;
438         }
439         
440         private static LogEntryObject getInfoOutLogValue (String line, String type){
441                 Date date;
442                 LogEntryObject logEntry = new LogEntryObject();
443                 logEntry.setSystemType(type);
444                 logEntry.setSystem(system);
445                 String info3 = "INFO";          
446                 
447                 if (line.contains(info3) && line.contains("--- [")){
448                         //parse out description
449                         String temp = line.substring(line.indexOf("---")+1);
450                         String[] split = temp.split(":");
451
452                         logEntry.setDescription(split[1]);
453
454                         //parse out date
455                         date = parseDate(line, dateFormat, false);
456                         logEntry.setDate(date);
457                         
458                         //remote system
459                         logEntry.setRemote(parseRemoteSystem(line));
460                         logEntry.setLogType(LOGTYPE.INFO);
461                         
462                         return logEntry;
463                 }
464                         
465                 return null;
466                 
467         }
468         private static LogEntryObject getSevereOutLogValue (String line, String type){  
469                 Date date;
470                 LogEntryObject logEntry = new LogEntryObject();
471                 logEntry.setSystemType(type);
472                 logEntry.setSystem(system);
473                 if (line.contains("SEVERE") && line.contains("[main]")){                        
474                         String[] splitString = line.split(" ");
475                         StringBuilder description = new StringBuilder();
476                         for (int i = 5; i < splitString.length; i++){
477                                 description.append(" " + splitString[i]);
478                         }
479         
480                         logEntry.setDescription(description.toString());
481                         //parse out date
482                         date = parseDate(line, dateFormat, false);
483                         logEntry.setDate(date);
484                         logEntry.setLogType(LOGTYPE.SEVERE);
485                         
486                         return logEntry;
487                 } 
488             
489             if (line.contains("ERROR") && line.contains(")-")){
490                         //parse out description
491                         StringBuilder description = new StringBuilder();
492                         description.append(line.substring(line.indexOf(")-")+3));
493                         //parse out date
494                         date = parseDate(line, dateFormat, true);
495                         logEntry.setDate(date);
496                         logEntry.setDescription(description.toString());
497                         //remote system
498                         logEntry.setRemote(parseRemoteSystem(line));
499                         logEntry.setLogType(LOGTYPE.ERROR);
500                         
501                         return logEntry;
502                 }       
503                 
504                 return null;
505         }
506         
507         private static LogEntryObject getWarnOutLogValue (String line, String type){    
508                 Date date;
509                 LogEntryObject logEntry = new LogEntryObject();
510                 logEntry.setSystemType(type);
511                 logEntry.setSystem(system);
512             if (line.contains("WARN") && line.contains(")-")){
513                         //parse out description
514         
515                         logEntry.setDescription(line.substring(line.indexOf(")-")+3));
516         
517                         //parse out date
518                         date = parseDate(line, dateFormat, true);
519                         logEntry.setDate(date);
520                         
521                         //remote system
522                         logEntry.setRemote(parseRemoteSystem(line));
523                         logEntry.setLogType(LOGTYPE.WARN);
524                         
525                         return logEntry;
526                 }
527             
528             if (line.contains("WARNING") && type =="PyPDP"){
529                         String[] splitString = line.split(" ");
530                         StringBuilder description = new StringBuilder();
531
532                         for (int i = 5; i < splitString.length; i++){
533                                 description.append(" " + splitString[i]);
534                         }
535
536                         //parse out date
537                         date = parseDate(line, dateFormat, false);
538                         logEntry.setDate(date);
539                         logEntry.setLogType(LOGTYPE.WARN);
540                         logEntry.setDescription(description.toString());
541                         return logEntry;
542                 }
543             
544       return null;
545       
546         }   
547         public static LogEntryObject pullOutLogValues(String line, String type){
548                 
549                 LogEntryObject logEntry = getDebugOutLogValue(line, type);
550
551                 if(logEntry == null){
552                    logEntry = getRestAPIOutLogValue(line, type);
553                 }
554                 if(logEntry == null){
555                    logEntry = getInfoOutLogValue(line, type);
556                 }
557                 if(logEntry == null){           
558                    logEntry = getSevereOutLogValue(line, type);
559                 }
560                 if(logEntry == null){
561                         logEntry = getWarnOutLogValue(line, type);
562                 }
563
564                 return logEntry;
565         }
566
567         private static void dbClose(Connection conn) {
568                 try {
569                         conn.close();
570                 } catch (SQLException e) {
571                         logger.error("Error closing DB Connection: " + e);
572                         
573                 }
574         }
575
576         public static void process(String line, String type, LOGTYPE logFile)  {
577                 
578                 LogEntryObject returnLogValue = null;
579                 if (im!=null){
580                         try {
581                                 im.startTransaction();
582                         } catch (AdministrativeStateException e) {
583                                 logger.error("Error received" + e);                             
584                         } catch (StandbyStatusException ex) {
585                                 logger.error("Error received" + ex);
586                         }
587                 }
588                 returnLogValue = pullOutLogValues(line, type);
589                 
590                 if(logFile.equals(LOGTYPE.DEBUG)){
591                    debuglastNumberRead++;
592                 }else if(logFile.equals(LOGTYPE.ERROR)){
593                    errorlastNumberRead++;
594                 }else if(logFile.equals(LOGTYPE.INFO)){
595                    lastNumberRead++;
596                 }
597                 if (returnLogValue!=null){
598                         writeDB(returnLogValue);
599                 }
600                 if (im!=null){
601                         im.endTransaction();
602                 }
603         }
604         
605         private static void writeDB(LogEntryObject returnLogValue) {
606
607                 Connection conn = dbConnection(jdbcDriver, jdbcUrl, jdbcUser,jdbcPassword);
608                 dbAccesss(conn, returnLogValue.getSystem(), returnLogValue.getDescription(),  
609                                                 returnLogValue.getDate(), returnLogValue.getRemote(), 
610                                                 returnLogValue.getSystemType(), returnLogValue.getLogType().toString());
611                 dbClose(conn);  
612         }
613
614         private static Connection dbConnection(String driver, String jdbc, String user, String pass){
615         
616         try {
617                 Class.forName(driver);
618                         return DriverManager.getConnection(jdbc, user, pass);
619                 } catch ( Exception e) {
620                         logger.error("Error connecting to DB: " + e);
621                 }
622                 return null;
623         }
624         private static void dbAccesss(Connection conn, String system, String description, Date date, String remote, String type, String logType)  {
625                 
626                 String sdate = null;
627                 if (date!=null){
628                         Format formatter = new SimpleDateFormat(dateFormat);
629                         sdate = formatter.format(date); 
630                         logger.debug("DBAccesss : sdate : " + sdate);
631                 }else{
632                         logger.debug("DBAccesss : sdate is null");
633                 }
634                 
635                 //ensure the length of description is less than the maximumm db char length
636                 if (description.length() > maxLength) {
637                         description = description.substring(0, maxLength);
638                 }
639                 
640                 try (
641                                 PreparedStatement prep = conn.prepareStatement("insert into SYSTEMLOGDB values (NULL, ?, ?, ?,  ?,  ?, ?);");
642                 ){
643                         
644                         prep.setString(1, system);
645                         prep.setString(2, description);
646                         prep.setString(3, remote);
647                         prep.setString(4, type);
648                         prep.setString(5, sdate);
649                         prep.setString(6, logType);
650
651                         prep.executeUpdate();
652                         prep.close();
653
654                 } catch (SQLException e1) {
655                         logger.error("Error trying to excute SQL Statment: " + e1);
656                 }  
657         }
658
659         public static Date parseDate(String dateline, String pattern, boolean singleSplit)  {
660                 
661                 Date returnDate;
662                 String[] splitString = dateline.split(" ");
663                 SimpleDateFormat formatter = new SimpleDateFormat(pattern);     
664                 if (singleSplit){
665                         try {
666                                 returnDate = formatter.parse(dateline);
667                         } catch (ParseException e) {
668                                 logger.error("Unable to parse date for line: " + dateline);
669                                 returnDate = null;
670                         }
671                 }else{
672                         String tmpString = splitString[0] + " " + splitString[1];
673                         try {
674                                 returnDate = formatter.parse(tmpString);
675                         } catch (ParseException e) {
676                                 logger.error("Unable to parse date for line: " + dateline);
677                                 returnDate = null;
678                         }
679                 }
680                         
681                 return returnDate; 
682         }
683
684         
685         public static String parseRemoteSystem(String line) {
686                 
687                 if (line.contains("http") && !(line.contains("www.w3.org"))){
688         
689                         Pattern pattern = Pattern.compile("://(.+?)/");
690                         Matcher remote = pattern.matcher(line);
691                         if (remote.find())
692                         {
693                                 return remote.group(1);
694                         } 
695                 }
696                 return null;
697         }
698         
699         public static String[] getPaths(String logPath){        
700                 String[] oneFile = null;
701                 if(logPath != null && !logPath.isEmpty()){
702                         if(logPath.contains(";")){
703                        return logPath.split(";");
704                         }else{
705                                  oneFile = new String[1];
706                                  oneFile[0] = logPath;
707                         }
708                 }
709                 
710             return oneFile;     
711         }
712         
713         private static void setCleanUpProperties(String cleanupInterval, String timeFrame){
714                 if(cleanupInterval != null && !cleanupInterval.isEmpty()){
715                         int intCheckInterval = Integer.parseInt(cleanupInterval);
716                         if(intCheckInterval > 300000) {//must be longer than 5 minutes
717                                         checkInterval = intCheckInterval;
718                         }
719                 }else{
720                          logger.debug("No value defined for CHECK_INTERVAL in parserlog.properties, so use its default value:" + checkInterval + " milliseconds");
721                 }
722                 
723                 if(timeFrame != null && !timeFrame.trim().isEmpty()){
724                     int intTimeFrame = defaultTimeFrame;
725                     try{
726                         intTimeFrame = Integer.parseInt(timeFrame);
727                     }catch(NumberFormatException e){
728                         logger.debug("Improper value defined for TIME_FRAME in parserlog.properties, so use its default value:" + defaultTimeFrame + " days");
729                     }
730                         if(intTimeFrame > 0){
731                                 defaultTimeFrame = intTimeFrame;
732                         }
733                 }else{
734                          logger.debug("No value defined for TIME_FRAME in parserlog.properties, so use its default value:" + defaultTimeFrame + " days");
735                 }
736         }
737         
738         private static void setDebuglogFile(String fileName){
739                         debuglogFile = fileName;
740                         if(debuglogFile != null && !debuglogFile.isEmpty()){
741                                 debuglogFile = debuglogFile.trim();
742                         }else{
743                                 debuglogFile = null;
744                         }
745         }
746         
747         private static void setErrorlogFile(String fileName){
748                         errorlogFile = fileName;
749                         if(errorlogFile != null && !errorlogFile.isEmpty()){
750                                 errorlogFile = errorlogFile.trim();
751                         }else{
752                                 errorlogFile = null;
753                         }
754         }
755         
756         private static void setLogFileProperties(String[] splitString){
757                 if(splitString != null){
758             for(int i=0;  i < splitString.length; i++){
759                 
760                 if(splitString[i].contains("debug")){
761                                         // get path of debug.log file
762                         setDebuglogFile(splitString[i]);
763                 }else if(splitString[i].contains("error")){
764                                         // get path of error.log file
765                         setErrorlogFile(splitString[i]);
766                 }else {
767                                         // get path of default file
768                         logFile = splitString[i];
769                                         if(logFile != null && !logFile.isEmpty()){
770                                                 logFile = logFile.trim();
771                                         }else{
772                                                 logFile = null;
773                                         }
774                 }
775             }
776                 }
777         }
778         
779         public static Properties getPropertiesValue(String fileName) {
780                 Properties config = new Properties();
781                 Path file = Paths.get(fileName);
782                 if (file.toFile().exists()) {
783                          
784                         if (file.toString().endsWith(".properties")) {
785                                 InputStream in;
786                                 try {
787                                         in = new FileInputStream(file.toFile());
788                                         config.load(in);
789                                                         
790                                         resourceName = config.getProperty("RESOURCE_NAME");
791                                         system = config.getProperty("SERVER");
792                                         type = config.getProperty("LOGTYPE");
793                                         systemLogFile = config.getProperty("PARSERLOGPATH");
794                                         String logFiles = config.getProperty("LOGPATH");
795                                         String cleanupInterval= config.getProperty("CHECK_INTERVAL");
796                                         String timeFrame = config.getProperty("TIME_FRAME");
797                                         
798                                         setCleanUpProperties(cleanupInterval, timeFrame);
799                                         
800                                         if(logFiles == null || logFiles.isEmpty()){
801                                                 isMissingLogFile = true;
802                                                 return null;
803                                         }
804                                         
805                                         String[] splitString = getPaths(logFiles);
806                                         
807                                         setLogFileProperties(splitString);
808                                         
809                                         jdbcUrl = config.getProperty("JDBC_URL").replace("'", "");
810                                         jdbcUser = config.getProperty("JDBC_USER");
811                                         jdbcDriver =  config.getProperty("JDBC_DRIVER");
812                                         jdbcPassword = CryptoUtils.decryptTxtNoExStr(config.getProperty("JDBC_PASSWORD", ""));
813                                         config.setProperty("javax.persistence.jdbc.password", CryptoUtils.decryptTxtNoExStr(config.getProperty("javax.persistence.jdbc.password", "")));
814                                         return config;
815
816                                 } catch (IOException e) {                                       
817                                         logger.error("Error porcessing Config file will be unable to create Health Check" + e);
818                                 }catch(Exception e){
819                                         logger.error("Error getPropertiesValue on TIME_FRAME", e);
820                                         logger.debug("Error getPropertiesValue on TIME_FRAME, so use its default value:" + defaultTimeFrame + " days");
821                                 }                               
822                         }
823
824                 }else{
825                         
826                         logger.debug("File doesn't exist in the specified Path "        + file.toString());
827                 }
828                 return null;
829         }
830         
831         public static Connection getDbConnection(){
832                 return dbConnection(jdbcDriver, jdbcUrl, jdbcUser,jdbcPassword);
833         }
834         private static void startCleanUp(){
835                 Connection conn = dbConnection(jdbcDriver, jdbcUrl, jdbcUser,jdbcPassword);
836                 CleanUpSystemLogDB cleanUp = new CleanUpSystemLogDB(conn, defaultTimeFrame); 
837                 Timer timer = new Timer(true);
838                 timer.scheduleAtFixedRate(cleanUp, TIMER_DELAY_TIME, checkInterval);
839                 logger.info("startCleanUp begins! : " + new Date());
840         }
841 }