From 4a024c447677fe12bad28491e43c3d2f0688faad Mon Sep 17 00:00:00 2001 From: Julian Arndt Date: Mon, 10 Apr 2023 19:18:43 +0200 Subject: [PATCH] Improve logging to telegram --- jenkinsfiles/APIFootballUpdater/Jenkinsfile | 24 ++++++++++------- jenkinsfiles/SupercupUpdater/Jenkinsfile | 24 ++++++++++------- jenkinsfiles/TippligaUpdater/Jenkinsfile | 28 ++++++++++++-------- jenkinsfiles/WTLPokalUpdater/Jenkinsfile | 29 +++++++++++---------- jenkinsfiles/build/Jenkinsfile | 19 +++++++++----- 5 files changed, 74 insertions(+), 50 deletions(-) diff --git a/jenkinsfiles/APIFootballUpdater/Jenkinsfile b/jenkinsfiles/APIFootballUpdater/Jenkinsfile index e1d18db..e605ee2 100644 --- a/jenkinsfiles/APIFootballUpdater/Jenkinsfile +++ b/jenkinsfiles/APIFootballUpdater/Jenkinsfile @@ -21,8 +21,9 @@ pipeline { } String output = readFile 'log.txt' if(output != "") { - output = clean(output) - output.split('\n').each { + ArrayList outputList = outputString.replace("\n\n", "\n").split('\n').toList() + outputList = clean(outputList) + outputList.each { telegramSendManual(it) } } @@ -48,14 +49,19 @@ pipeline { } } -private String clean(String orig) { - orig = orig.replace("\n\n", "\n") - while(orig.indexOf(" [main] INFO de.jeyp91.App - ") > 0) { - int index = orig.indexOf(" [main] INFO de.jeyp91.App - ") - String newString = orig.substring(0, index-12) + orig.substring(index+30, orig.size()) - orig = newString +private ArrayList clean(ArrayList orig) { + ArrayList cleaned = new ArrayList() + orig.each{line -> + if(line.indexOf(" [main] INFO de.jeyp91 - ") >= 0) { + line = line.substring(20, line.size()) + } + + if(line.indexOf(" [main] ERROR de.jeyp91") >= 0) { + line = line.substring(20, line.size()) + } + cleaned.add(line) } - return orig + return cleaned.unique() } def telegramSendManual(String text) { diff --git a/jenkinsfiles/SupercupUpdater/Jenkinsfile b/jenkinsfiles/SupercupUpdater/Jenkinsfile index 2852896..ee89bb2 100644 --- a/jenkinsfiles/SupercupUpdater/Jenkinsfile +++ b/jenkinsfiles/SupercupUpdater/Jenkinsfile @@ -42,8 +42,9 @@ pipeline { } } if(errorOutput != "") { - errorOutput = clean(errorOutput) - errorOutput.split('\n').toList().unique().each { + ArrayList outputList = outputString.replace("\n\n", "\n").split('\n').toList() + outputList = clean(outputList) + outputList.each { telegramSendManual(it) } } @@ -65,14 +66,19 @@ pipeline { } } -private String clean(String orig) { - orig = orig.replace("\n\n", "\n") - while(orig.indexOf(" [main] INFO de.jeyp91.App - ") > 0) { - int index = orig.indexOf(" [main] INFO de.jeyp91.App - ") - String newString = orig.substring(0, index-12) + orig.substring(index+30, orig.size()) - orig = newString +private ArrayList clean(ArrayList orig) { + ArrayList cleaned = new ArrayList() + orig.each{line -> + if(line.indexOf(" [main] INFO de.jeyp91 - ") >= 0) { + line = line.substring(20, line.size()) + } + + if(line.indexOf(" [main] ERROR de.jeyp91") >= 0) { + line = line.substring(20, line.size()) + } + cleaned.add(line) } - return orig + return cleaned.unique() } def telegramSendManual(String text) { diff --git a/jenkinsfiles/TippligaUpdater/Jenkinsfile b/jenkinsfiles/TippligaUpdater/Jenkinsfile index 81c4ba8..17dfb87 100644 --- a/jenkinsfiles/TippligaUpdater/Jenkinsfile +++ b/jenkinsfiles/TippligaUpdater/Jenkinsfile @@ -24,10 +24,11 @@ pipeline { } catch (Exception e) { telegramSendManual("TLW-Database-Tool crashed!") } - String output = readFile 'log.txt' - if(output != "") { - output = clean(output) - output.split('\n').toList().unique().each { + String outputString = readFile 'log.txt' + if(outputString != "") { + ArrayList outputList = outputString.replace("\n\n", "\n").split('\n').toList() + outputList = clean(outputList) + outputList.each { telegramSendManual(it) } } @@ -47,14 +48,19 @@ pipeline { } } -private String clean(String orig) { - orig = orig.replace("\n\n", "\n") - while(orig.indexOf(" [main] INFO de.jeyp91.App - ") > 0) { - int index = orig.indexOf(" [main] INFO de.jeyp91.App - ") - String newString = orig.substring(0, index-12) + orig.substring(index+30, orig.size()) - orig = newString +private ArrayList clean(ArrayList orig) { + ArrayList cleaned = new ArrayList() + orig.each{line -> + if(line.indexOf(" [main] INFO de.jeyp91 - ") >= 0) { + line = line.substring(20, line.size()) + } + + if(line.indexOf(" [main] ERROR de.jeyp91") >= 0) { + line = line.substring(20, line.size()) + } + cleaned.add(line) } - return orig + return cleaned.unique() } def telegramSendManual(String text) { diff --git a/jenkinsfiles/WTLPokalUpdater/Jenkinsfile b/jenkinsfiles/WTLPokalUpdater/Jenkinsfile index f34a8f1..aaef557 100644 --- a/jenkinsfiles/WTLPokalUpdater/Jenkinsfile +++ b/jenkinsfiles/WTLPokalUpdater/Jenkinsfile @@ -42,8 +42,9 @@ pipeline { } } if(errorOutput != "") { - errorOutput = clean(errorOutput) - errorOutput.split('\n').toList().unique().each { + ArrayList outputList = outputString.replace("\n\n", "\n").split('\n').toList() + outputList = clean(outputList) + outputList.each { telegramSendManual(it) } } @@ -65,19 +66,19 @@ pipeline { } } -private String clean(String orig) { - orig = orig.replace("\n\n", "\n") - while(orig.indexOf(" [main] INFO de.jeyp91 - ") > 0) { - int index = orig.indexOf(" [main] INFO de.jeyp91 - ") - String newString = orig.substring(0, index-12) + orig.substring(index+30, orig.size()) - orig = newString +private ArrayList clean(ArrayList orig) { + ArrayList cleaned = new ArrayList() + orig.each{line -> + if(line.indexOf(" [main] INFO de.jeyp91 - ") >= 0) { + line = line.substring(20, line.size()) + } + + if(line.indexOf(" [main] ERROR de.jeyp91") >= 0) { + line = line.substring(20, line.size()) + } + cleaned.add(line) } - while(orig.indexOf(" [main] ERROR de.jeyp91 - ") > 0) { - int index = orig.indexOf(" [main] ERROR de.jeyp91 - ") - String newString = orig.substring(0, index-12) + orig.substring(index+31, orig.size()) - orig = newString - } - return orig + return cleaned.unique() } def telegramSendManual(String text) { diff --git a/jenkinsfiles/build/Jenkinsfile b/jenkinsfiles/build/Jenkinsfile index 0f6d4ae..119b783 100644 --- a/jenkinsfiles/build/Jenkinsfile +++ b/jenkinsfiles/build/Jenkinsfile @@ -41,14 +41,19 @@ pipeline { } } -private String clean(String orig) { - orig = orig.replace("\n\n", "\n") - while(orig.indexOf(" [main] INFO de.jeyp91.App - ") > 0) { - int index = orig.indexOf(" [main] INFO de.jeyp91.App - ") - String newString = orig.substring(0, index-12) + orig.substring(index+30, orig.size()) - orig = newString +private ArrayList clean(ArrayList orig) { + ArrayList cleaned = new ArrayList() + orig.each{line -> + if(line.indexOf(" [main] INFO de.jeyp91 - ") >= 0) { + line = line.substring(20, line.size()) + } + + if(line.indexOf(" [main] ERROR de.jeyp91") >= 0) { + line = line.substring(20, line.size()) + } + cleaned.add(line) } - return orig + return cleaned.unique() } def telegramSendManual(String text) {