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 {