From 54708105343d117e8f3a1be8115735a99ef3cdf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20=22KPTN=22=20OUDOT?= Date: Mon, 16 Sep 2024 08:47:19 +0200 Subject: [PATCH 1/3] Add task name and task mode in status (#302) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Log task name+mode as well (#300) * log task name and task mode as well * reverted BUILD.txt * Fix wrong task mode name --------- Co-authored-by: Bram Daams Co-authored-by: Clément "KPTN" OUDOT * Get task name and task mode in status, and use them in monitoring script output * Remove deprecated monitoring script --------- Co-authored-by: brammeleman <43443291+brammeleman@users.noreply.github.com> Co-authored-by: Bram Daams --- src/install/check_lsc.sh | 145 ------------------ src/install/check_lsc_status_file.pl | 10 +- .../java/org/lsc/AbstractSynchronize.java | 24 +-- 3 files changed, 19 insertions(+), 160 deletions(-) delete mode 100755 src/install/check_lsc.sh diff --git a/src/install/check_lsc.sh b/src/install/check_lsc.sh deleted file mode 100755 index 7de8a9a7..00000000 --- a/src/install/check_lsc.sh +++ /dev/null @@ -1,145 +0,0 @@ -#!/bin/bash - -#========================================================================== -# Summary -#========================================================================== -# Log file analyzer for LSC for Nagios -# -# This can read LSC logs to detect time since last succesful execution. -# An alert will be thrown if either of these durations exceeds a limit. -# -# -# Copyright (c) 2009 - 2011 LSC Project -# Copyright (C) 2008 Jonathan Clarke -# Copyright (C) 2008 LINAGORA -# -#========================================================================== -# Original license: GPLv2, -#========================================================================== -# Contributed by jclarke@linagora.com under LSC original BSD license -#========================================================================== - -#========================================================================== -# Changelog -#========================================================================== -# Version 1.0 (2008/02/28): -# - First version -# Author: Jonathan Clarke -#========================================================================== - -# -# Usage: ./check_lsc -F -w -c -# - -# Pattern to match in log file -SUCCESS_PATTERN="Starting LSC" - -# Paths to commands used in this script. These -# may have to be modified to match your system setup. - -PROGNAME=`basename $0` -PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'` -REVISION=`echo '$Revision: 1.0 $' | sed -e 's/[^0-9.]//g'` - -. $PROGPATH/utils.sh - -print_usage() { - echo "Usage: $PROGNAME -F logfile -w warnlevel -c criticallevel" - echo "Usage: $PROGNAME --help" - echo "Usage: $PROGNAME --version" -} - -print_help() { - print_revision $PROGNAME $REVISION - echo "" - print_usage - echo "" - echo "Log file analyzer for LSC for Nagios" - echo "" - support -} - -# Make sure the correct number of command line -# arguments have been supplied - -if [ $# -lt 6 ]; then - print_usage - exit $STATE_UNKNOWN -fi - -# Grab the command line arguments - -exitstatus=$STATE_UNKNOWN #default -while test -n "$1"; do - case "$1" in - --help) - print_help - exit $STATE_OK - ;; - -h) - print_help - exit $STATE_OK - ;; - --version) - print_revision $PROGNAME $REVISION - exit $STATE_OK - ;; - -V) - print_revision $PROGNAME $REVISION - exit $STATE_OK - ;; - --filename) - logfile=$2 - shift - ;; - -F) - logfile=$2 - shift - ;; - -w) - warnlevel=$2 - shift - ;; - -c) - criticallevel=$2 - shift - ;; - *) - echo "Unknown argument: $1" - print_usage - exit $STATE_UNKNOWN - ;; - esac - shift -done - -# If the log file doesn't exist, exit - -if [ ! -e $logfile ]; then - echo "Log check error: Log file $logfile does not exist!\n" - exit $STATE_UNKNOWN -elif [ ! -r $logfile ] ; then - echo "Log check error: Log file $logfile is not readable!\n" - exit $STATE_UNKNOWN -fi - -# Get the last matching entry in the diff file -lastentry=`grep "$SUCCESS_PATTERN" $logfile | tail -1` - -timeLastEntry=`echo $lastentry | sed 's/\([0-9]\{4\}\/[0-9]\{2\}\/[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}\).*/\1/'` -timestampLastEntry=`date -d "$timeLastEntry" +%s` -timestampNow=`date +%s` -age=$(( ($timestampNow - $timestampLastEntry) / 60)) - -if [[ $age -lt $warnlevel ]]; then # recent execution, exit with no error - echo "OK: Last successful execution $age minutes ago" - exitstatus=$STATE_OK -elif [[ $age -ge $warnlevel && $age -lt $criticallevel ]]; then - echo "WARN: Last successful execution $age minutes ago" - exitstatus=$STATE_WARNING -elif [[ $age -ge $criticallevel ]]; then - echo "CRITICAL: Last successful execution $age minutes ago" - exitstatus=$STATE_CRITICAL -fi - -exit $exitstatus diff --git a/src/install/check_lsc_status_file.pl b/src/install/check_lsc_status_file.pl index 5c64b42e..7c6a50cd 100755 --- a/src/install/check_lsc_status_file.pl +++ b/src/install/check_lsc_status_file.pl @@ -205,9 +205,9 @@ sub check_critical_param { } # Get statistics -my ( $all, $modify, $modified, $errors ) = +my ( $taskname, $taskmode, $all, $modify, $modified, $errors ) = ( $last =~ -/All entries: (\d+), to modify entries: (\d+), (?:successfully )?modified entries: (\d+), errors: (\d+)/mi +/(\w+) - (\w+) - All entries: (\d+), to modify entries: (\d+), (?:successfully )?modified entries: (\d+), errors: (\d+)/mi ); #========================================================================== @@ -224,17 +224,17 @@ sub check_critical_param { # Test the errors and exit if ( $errors == 0 or $errors < $warning ) { print -"OK - LSC is running with $errors errors (W:$warning - C:$critical)$perfparse\n"; +"OK - LSC task $taskname in mode $taskmode is running with $errors errors (W:$warning - C:$critical)$perfparse\n"; exit $ERRORS{'OK'}; } elsif ( $errors >= $warning and $errors < $critical ) { print -"WARNING - LSC is running with $errors errors (W:$warning - C:$critical)$perfparse\n"; +"WARNING - LSC task $taskname in mode $taskmode is running with $errors errors (W:$warning - C:$critical)$perfparse\n"; exit $ERRORS{'WARNING'}; } else { print -"CRITICAL - LSC is running with $errors errors (W:$warning - C:$critical)$perfparse\n"; +"CRITICAL - LSC task $taskname in mode $taskmode is running with $errors errors (W:$warning - C:$critical)$perfparse\n"; exit $ERRORS{'CRITICAL'}; } diff --git a/src/main/java/org/lsc/AbstractSynchronize.java b/src/main/java/org/lsc/AbstractSynchronize.java index ff553181..d8dd0517 100644 --- a/src/main/java/org/lsc/AbstractSynchronize.java +++ b/src/main/java/org/lsc/AbstractSynchronize.java @@ -183,7 +183,7 @@ protected final boolean clean2Ldap(Task task) { LOGGER.info("If you want to avoid this message, " + "increase the time limit by using dedicated parameter."); } - logStatus(counter); + logStatus(task.getName(), Task.Mode.clean.toString(), counter); return counter.getCountError() == 0; } @@ -231,7 +231,7 @@ protected final boolean synchronize2Ldap(final Task task) { LOGGER.info("If you want to avoid this message, " + "increase the time limit by using dedicated parameter."); } - logStatus(counter); + logStatus(task.getName(), Task.Mode.sync.toString(), counter); return counter.getCountError() == 0; } @@ -298,7 +298,7 @@ public final String getTaskFullStatus(final String syncName) { if(asyncThread != null && asyncThread.isAlive()) { AsynchronousRunner asyncRunner = mapSTasks.get(syncName); InfoCounter counter = asyncRunner.getCounter(); - return getLogStatus(counter); + return getLogStatus(syncName, Task.Mode.async.toString(), counter); } else { return null; } @@ -392,8 +392,8 @@ public final void logShouldAction(final LscModifications lm, final String syncNa LSCStructuralLogger.DESTINATION.debug("", lm); } - protected void logStatus(InfoCounter counter) { - String totalsLogMessage = getLogStatus(counter); + protected void logStatus(String taskName, String taskMode, InfoCounter counter) { + String totalsLogMessage = getLogStatus(taskName, taskMode, counter); if (counter.getCountError() > 0) { LOGGER.error(totalsLogMessage); } else { @@ -401,11 +401,15 @@ protected void logStatus(InfoCounter counter) { } } - protected String getLogStatus(InfoCounter counter) { - return "All entries: "+ counter.getCountAll() + - ", to modify entries: "+ counter.getCountModifiable() + - ", successfully modified entries: "+counter.getCountCompleted()+ - ", errors: "+counter.getCountError(); + protected String getLogStatus(String taskName, String taskMode, InfoCounter counter) { + + String totalsLogMessage = + taskName + " - " + taskMode + + " - All entries: "+ counter.getCountAll() + + ", to modify entries: "+ counter.getCountModifiable() + + ", successfully modified entries: "+counter.getCountCompleted()+ + ", errors: "+counter.getCountError(); + return totalsLogMessage; } public IBean getBean(Task task, IService service, String pivotName, LscDatasets pivotAttributes, boolean fromSameService, boolean fromSource) throws LscServiceException { From bfd929d25a7d220c143b6d4224aba838df727a1b Mon Sep 17 00:00:00 2001 From: Abhishek Pai Date: Mon, 16 Sep 2024 08:48:26 +0200 Subject: [PATCH 2/3] #106 updating dependencies (#306) * Bump org.bouncycastle:bcprov-jdk18on from 1.75 to 1.78 Bumps [org.bouncycastle:bcprov-jdk18on](https://github.com/bcgit/bc-java) from 1.75 to 1.78. - [Changelog](https://github.com/bcgit/bc-java/blob/main/docs/releasenotes.html) - [Commits](https://github.com/bcgit/bc-java/commits) --- updated-dependencies: - dependency-name: org.bouncycastle:bcprov-jdk18on dependency-type: direct:production ... Signed-off-by: dependabot[bot] * Updating libraries - commons-io to v2.16.1 - commons-logging to v1.3.4 - rhino to v1.7.15 - bcprov-jdk18on to v1.78.1 - commons-cli to v1.9.0 - jcifs to v1.3.17 - junit to v4.13.2 - guava to v33.3.0-jre - javax.xml.bind:jaxb-api to jakarta.xml.bind:jakarta.xml.bind-api v2.3.3 - jaxb-core to v3.0.0 - jaxb-impl to v4.0.5 - javax.resource:connector-api to jakarta.resource:jakarta.resource-api v2.1.0 - org.codehaus.groovy:groovy-all to org.apache.groovy:groovy-all v4.0.22 - api-all to 2.1.7 - xml-apis to v2.0.2 - jackson-databind to v2.17.2 --------- Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- pom.xml | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/pom.xml b/pom.xml index 0df0468d..cff4f867 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,6 @@ ${project.build.directory}/staging 1.5 22.3.1 - 2.12.7.1 ${project.build.directory}/compiler @@ -695,7 +694,7 @@ commons-io commons-io - 2.11.0 + 2.16.1 jar false @@ -709,7 +708,7 @@ commons-logging commons-logging - 1.2 + 1.3.4 com.thoughtworks.xstream @@ -721,7 +720,7 @@ org.slf4j slf4j-api - 2.0.9 + 2.0.16 jar false @@ -749,7 +748,7 @@ org.mozilla rhino - 1.7.14 + 1.7.15 jar false @@ -761,21 +760,21 @@ org.bouncycastle bcprov-jdk18on - 1.78 + 1.78.1 jar false commons-cli commons-cli - 1.5.0 + 1.9.0 jar false - org.samba.jcifs + jcifs jcifs - 1.3.3 + 1.3.17 jar false @@ -801,7 +800,7 @@ junit junit - 4.13.1 + 4.13.2 jar false @@ -813,7 +812,7 @@ com.google.guava guava - 32.0.0-jre + 33.3.0-jre javax.transaction @@ -829,19 +828,19 @@ jaxb 2.3.6 with maven-jaxb2-plugin 0.15.1 --> - javax.xml.bind - jaxb-api - 2.3.1 + jakarta.xml.bind + jakarta.xml.bind-api + 2.3.3 org.glassfish.jaxb jaxb-core - 2.3.0.1 + 3.0.0 com.sun.xml.bind jaxb-impl - 2.3.6 + 4.0.5 net.java.xadisk @@ -849,9 +848,9 @@ 1.2.2 - javax.resource - connector-api - 1.5 + jakarta.resource + jakarta.resource-api + 2.1.0 org.codehaus.btm @@ -859,24 +858,25 @@ 2.1.4 - org.codehaus.groovy + org.apache.groovy groovy-all - 2.4.21 + 4.0.22 + pom org.apache.directory.api api-all - 2.1.3 + 2.1.7 xml-apis xml-apis - 1.4.01 + 2.0.2 com.fasterxml.jackson.core jackson-databind - ${jackson.version} + 2.17.2 From 418acd89c8b637630c20765d358aba71489441b7 Mon Sep 17 00:00:00 2001 From: philippe lhardy Date: Mon, 16 Sep 2024 08:49:15 +0200 Subject: [PATCH 3/3] fallback to rhino if no default javascript is found .3 (lscproject#280) (#304) * fallback to rhino if no default javascript is found .3 (lscproject#280) - avoid NullPointerException even if rhino and js are missing * #304: Using java 8 compatible Optional code --------- Co-authored-by: philha Co-authored-by: Abhishek Pai --- src/main/java/org/lsc/utils/ScriptingEvaluator.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/lsc/utils/ScriptingEvaluator.java b/src/main/java/org/lsc/utils/ScriptingEvaluator.java index 895c8fd1..b69c3b88 100644 --- a/src/main/java/org/lsc/utils/ScriptingEvaluator.java +++ b/src/main/java/org/lsc/utils/ScriptingEvaluator.java @@ -3,6 +3,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.function.Predicate; import javax.script.*; @@ -31,7 +32,7 @@ public class ScriptingEvaluator { private Map instancesTypeCache; - private ScriptableEvaluator defaultImplementation; + private Optional defaultImplementation; static { implementetionsCache = new HashMap>(); @@ -87,10 +88,11 @@ else if ("graal.js".equals(name)) { bindings.put( "polyglot.js.nashorn-compat", true); JScriptEvaluator graaljsevaluator = new JScriptEvaluator(graaljsEngine); instancesTypeCache.put("gj", graaljsevaluator); - defaultImplementation = graaljsevaluator; + defaultImplementation = Optional.of(graaljsevaluator); } else { - defaultImplementation = instancesTypeCache.get("js"); + defaultImplementation = Optional.ofNullable(Optional.ofNullable(instancesTypeCache.get("js")) + .orElse(instancesTypeCache.get("rjs"))); } } @@ -111,13 +113,13 @@ public static void contribute(String implementationName, implementetionsCache.put(implementationName, implementationClass); } - private ScriptableEvaluator identifyScriptingEngine(String expression) { + private ScriptableEvaluator identifyScriptingEngine(String expression) throws LscServiceException { String[] parts = expression.split(":"); if (parts != null && parts.length > 0 && parts[0].length() < 10 && instancesTypeCache.containsKey(parts[0])) { return instancesTypeCache.get(parts[0]); } - return defaultImplementation; + return defaultImplementation.orElseThrow(() -> new LscServiceException("Missing Script evaluator")); } /**