01-26-2011 08:58 AM
01-26-2011 10:17 AM
01-26-2011 01:07 PM
01-27-2011 03:49 AM
08-03-2011 05:02 AM
#!/bin/sh
# #################################################################
# Script to monitor a server
# #################################################################
####################
# CONFIGURATION USER
####################
### Check Disk Space
CHECK_DISKSPACE_ENABLE="true" #"true" or "false"
# Write the partition with the limit maximum size(if the limit is a size, put the same unit than the command "df -h" show the partition
# "/dev/sda1=90%" means that an alert mail will be sent if the disk used is more or egal than 90%
# "/dev/sda1=10G" means that an alert mail will be sent if the disk used is more or egal than 10G
CHECK_DISKSPACE_PARTITIONS_LIMITS=("/dev/sda1=80%")
### Check WebSite
CHECK_WEBSITE_ENABLE="true" #"true" or "false"
CHECK_WEBSITE_ADDRESS="http://localhost:8080/alfresco"
### Mail
MAIL_NOTIFICATION_ENABLE="true" # true or false
MAIL_NOTIFICATION_SENDER="ged@domain.ch"
MAIL_NOTIFICATION_DESTINATION="watchdog@domain.ch"
MAIL_NOTIFICATION_LOCATION="YourCompagny" # Where the script is running
MAIL_NOTIFICATION_TYPE_SERVER="GED" # Type of the server
MAIL_NOTIFICATION_TYPE_SCRIPT="Monitoring" # Type of the script like Backup, Monitoring…
### LogFile
LOGFILE="/var/log/gedMonitoring.log"
### Message
SUCCESS="SUCCESS"
ERROR="ERROR"
WARNING="WARNING"
TRUE="TRUE"
FALSE="FALSE"
######
# Init
######
### Check Disk Space
# Get the list of partition in a compact format
partitionDetails=$( df -Ph | sed -r "s/ {1,}/@/g" )
# Position elements in the output of the command "df"
POSITION_PARTITION=1
POSITION_USEDSPACE_PERCENT=5
POSITION_USEDSPACE_SIZE=3
### Check WebSite
# Success message get from command wget
CHECK_WEBSITE_WGET_SUCCESS="200 OK"
###############################################
# Get the date of the day
###############################################
getTime(){
        date="$(date +'%b %e %H:%M:%S')"
        echo "$date"
}
############################################################
# Check the disk space (configure in the partitionsLimites).
############################################################
checkDiskSpace(){
        message="`getTime` CheckDiskSpace"
        echo "$message"
        echo "$message" >> $LOGFILE
        # Read all partitions with the limit
        for partitionsToCheck in ${CHECK_DISKSPACE_PARTITIONS_LIMITS[@]}
        do
                # Get the values of the parameters in the list (partition, limit)
                partitionInList=${partitionsToCheck%%=*}
                limitInList=${partitionsToCheck##*=}
                # Read all partition on the disk
                checkPartition="false" # The partition in the liste has been compared
                for partitionOnDisk in $partitionDetails
                do
                        # Check if it's the good partition
                        if [ "$partitionInList" != "$( echo "$partitionOnDisk" | awk -F@ '{print$1}')" ]; then
                                continue
                        fi
                        # The partition in the list has been found on the system
                        checkPartition="true"
                        # Read the unit (G, M, %) of the limit
                        typLimit=${limitInList:(-1)}
                        valueLimit=$(echo "$limitInList" | tr -d $typLimit)
                        echo "Check $partitionInList with the limit fixed with $limitInList"
                        # Search if the limit is fixed in "%" or unit like G, M…
                        if [ "$typLimit" = "%" ]; then
                                # The size is in %
                                valueToCheck=$POSITION_USEDSPACE_PERCENT
                        else
                                # The size is in unit G, M …
                                valueToCheck=$POSITION_USEDSPACE_SIZE
                        fi
                        usedSpace=$( echo "$partitionOnDisk" | awk -F@ -vposition=$valueToCheck '{print$position}' | tr -d $typLimit)
                        # Comparaison
                        if [ $usedSpace -ge $valueLimit ]; then
                                # Alert !!!
                                message "$WARNING : Not enough space on $partitionOnDisk.The maximum is fixed on $limitInList."
                        else
                                echo "All is ok with $partitionOnDisk with the maximum limit fixed on $limitInList"
                        fi
               done
                # Check if the partition in the list has been found in the system
                if [ $checkPartition == "false" ]; then
                        message "$ERROR : The partition $partitionInList has not been found !!! Please check the configuration of the script."
                fi
        done
}
############################################################
# Check if the web site is up.
############################################################
checkWebSite(){
        message="`getTime` CheckWebSite"
        echo "$message"
        echo "$message" >> $LOGFILE
        resultWget=$(wget –spider $CHECK_WEBSITE_ADDRESS 2>&1)
        if [[ "$resultWget" = *"$CHECK_WEBSITE_WGET_SUCCESS"* ]];then
                echo "The website $CHECK_WEBSITE_ADDRESS is up."
        else
                message "$ERROR : The WebSite $CHECK_WEBSITE_ADDRESS is not responding."
        fi
}
#############################################################################
# Send a mail. Do not use it directly… Use function message()
# Use it like this :
#       message="I am a message"
#       sendMail "%I - $MAIL_NOTIFICATION_LOCATION - GED - Backup" "$message"
#############################################################################
sendMail(){
        echo "Send mail notification to : $MAIL_NOTIFICATION_DESTINATION"
        echo "$2" | mail -s "$1" "$MAIL_NOTIFICATION_DESTINATION" – -r "$MAIL_NOTIFICATION_SENDER"
        if [ $? -gt 0 ] ; then
                message="`getTime` Unable to send mail notification"
                echo "$message"
                echo $MESSAGE_SEE_LOG
                echo "$message" >> $LOGFILE
        fi
}
#############################################################################################
# Write a message in the console and send a mail
# Use it like this :
#       message "$ERROR : Unable to give permissions on the directory to link to the share"
#       message "$WARNING : Unable to remove mysql file : $BACKUP_FILE_MYSQL_SLQ"
#       message "End backup ($SUCCESS)"
############################################################################################
message(){
        message="`getTime` $1"
        echo "$message"
        echo $MESSAGE_SEE_LOG
        echo "$message" >> $LOGFILE
        # Sendmail ?
        if [ "$MAIL_NOTIFICATION_ENABLE" = "true" ]; then
                # Success
                echo "$message" | grep "$SUCCESS" 1>/dev/null
                if [ $? = 0 ] ; then
                       typeMessage="Info"
                fi
                # WARNING
                echo "$message" | grep "$WARNING" 1>/dev/null
                if [ $? = 0 ] ; then
                       typeMessage="Warning"
                fi
                # ERROR
                echo "$message" | grep "$ERROR" 1>/dev/null
                if [ $? = 0 ] ; then
                       typeMessage="Error"
                fi
                # SendMail
                sendMail "$typeMessage - $MAIL_NOTIFICATION_LOCATION - $MAIL_NOTIFICATION_TYPE_SERVER - $MAIL_NOTIFICATION_TYPE_SCRIPT" "$message"
        fi
}
######
# Main
######
# Information startup
message="`getTime` Start Monitoring"
echo "$message"
echo "The log file is here : $LOGFILE"
echo ""
echo "$message" >> $LOGFILE
# CheckDiskSpace
if [ "$TRUE" = "$(echo $CHECK_DISKSPACE_ENABLE | tr "[:lower:]" "[:upper:]")" ]; then
        checkDiskSpace
fi
# CheckWebSite
if [ "$TRUE" = "$(echo $CHECK_WEBSITE_ENABLE | tr "[:lower:]" "[:upper:]")" ]; then
        checkWebSite
fi
# Information end
message="`getTime` End of monitoring"
echo "$message"
echo "$message" >> $LOGFILE
# Monitor the server
0 7,14 * * * /usr/local/bin/monitoring.sh > /var/log/crontab.log 2>&1
					
				
			
			
				
			
			
			
			
			
			
			
		12-11-2016 01:50 AM
Bonjour,
C'est pas les possibilités qui manquent, pour savoir si Alfresco tourne, c'est à pas à Tomcat de le dire, mais à Alfresco, ce qui donne :
Voilà un exemple en PHP-CURL qui retourne un nombre d'élément...pis le jour ou y a rien -> Alert !
$url_for_alf = 'http://127.0.0.1:8080/alfresco/api/-default-/public/cmis/versions/1.1/browser/'
$ch = curl_init();
 curl_setopt($ch, CURLOPT_URL,$url_for_alfl);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
 curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
 curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$result = curl_exec($ch);
 curl_close($ch); # on referme la liaison
$obj2 = (json_decode($result,true));
Il faudrait peaufiner le code mais çà fonctionne et c'est rapide à faire, $obj2 retourne une erreur ou contient des données  ![]()
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.