new: [add] init commit, elab-update, elab-manage-install & scripts

This commit is contained in:
default
2024-05-30 17:42:32 +02:00
commit 4767e76060
6 changed files with 152 additions and 0 deletions

16
README.md Normal file
View File

@@ -0,0 +1,16 @@
# Elabore Manage monitoring Script
This allow to handle alerting and monitoring using cron scripts + send function from myc-manage
> Warning : your server should be under myc-manage administration to have the send function installed
## Usage :
1. Clone the repo
2. run the script in `bin/elab-manage-install`
Then each time you want to update this repos : `elab-update` from the server
## Adding a new script :
Take exemple on the simples scripts that are in cron.daily or cron.hourly and make your own

20
bin/elab-manage-install Executable file
View File

@@ -0,0 +1,20 @@
#!/bin/bash
# Get the directory where the script resides
SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# TODO: ${##*/}
# Define the destination directory where the elab-update symbolic link will be created
DEST_DIR="/usr/local/bin/"
# Check if the elab-update script exists in the source directory
if [ ! -f "$SOURCE_DIR/elab-update" ]; then
echo "Error: elab-update script not found in the source directory."
exit 1
fi
# Create a symbolic link to the elab-update script in the destination directory
echo "Creating symbolic link to elab-update script in $DEST_DIR..."
sudo ln -sf "$SOURCE_DIR/elab-update" "$DEST_DIR" || { echo "Error: Unable to create symbolic link."; exit 1; }
echo "elab-update command has been successfully installed as a symbolic link."

37
bin/elab-update Executable file
View File

@@ -0,0 +1,37 @@
#!/bin/bash
# Define the repository path
REPO_PATH="/opt/apps/elab-manage"
# Function to update the git repository
update_repo() {
echo "Updating the git repository..."
cd "$REPO_PATH" || {
echo "Error: Unable to find the repository at $REPO_PATH";
exit 1;
}
git pull -r || {
echo "Error: Unable to update the repository";
exit 1;
}
}
# Function to update symbolic links
update_symlinks() {
echo "Updating symbolic links for cron.daily..."
# Update or add new symbolic links for cron.daily and cron.hourly
for dir in "cron."{daily,hourly}; do
find -L /etc/$dir -maxdepth 1 -type l -ilname $REPO_PATH/etc/$dir\* -delete
ln -sf $REPO_PATH/etc/$dir/* /etc/$dir
done
echo "Symbolic links have been successfully updated."
}
# Update the git repository and symbolic links
update_repo
update_symlinks
echo "Elabore Update complete."

View File

@@ -0,0 +1,7 @@
#!/bin/bash
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
## Remove every .state file older than 48h -- Cleanup script if the others arent strong enougth
find /var/run/elab-manage -name "*.state" -type f -mtime +2 -delete

40
etc/cron.hourly/disk_usage Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
## check disk usage and send a notification if it's above 75% or 90%
percent_usage=$(df /srv -h)
percent_usage=${percent_usage##*$'\n'}
percent_usage=${percent_usage% *}
percent_usage=${percent_usage##* }
percent_usage=${percent_usage%\%}
STATE_WORKING_DIR="/var/run/elab-manage"
mkdir -p "$STATE_WORKING_DIR"
if [ "$percent_usage" -ge "90" ]; then
if [ -e $STATE_WORKING_DIR/disk_usage_90.state ]; then
exit 0
else
touch $STATE_WORKING_DIR/disk_usage_90.state
message="$(hostname): WARNING disk usage >=90%"
send -c disk.crit "$message"
fi
elif [ "$percent_usage" -ge "75" ]; then
if [ -e $STATE_WORKING_DIR/disk_usage_75.state ]; then
exit 0
else
touch $STATE_WORKING_DIR/disk_usage_75.state
message="$(hostname): WARNING disk usage >=75 <90%"
send -c disk.alert "$message"
fi
else
if [ -e $STATE_WORKING_DIR/disk_usage_75.state ]; then
rm $STATE_WORKING_DIR/disk_usage_75.state
fi
if [ -e $STATE_WORKING_DIR/disk_usage_90.state ]; then
rm $STATE_WORKING_DIR/disk_usage_90.state
fi
fi

View File

@@ -0,0 +1,32 @@
#!/bin/bash
SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
MAX_PER_PROC=3
## integer only for the 5m load avg
LOCK_WORKING_DIR="/var/run/elab-manage"
mkdir -p "$LOCK_WORKING_DIR"
int_avg=$(while read line; do
echo "$line"
done < /proc/loadavg)
int_avg=${int_avg#* }
int_avg=${int_avg%%.*}
max=$[$MAX_PER_PROC * $(grep -c ^processor /proc/cpuinfo)]
if [ "$int_avg" -gt "$max" ]; then
if [ -e $LOCK_WORKING_DIR/load_average_max.lock ]; then
exit 0
else
touch $LOCK_WORKING_DIR/load_average_max.lock
message="[$(hostname)] : WARNING - load average ($int_avg) is above max per processor : ($MAX_PER_PROC * $(grep -c ^processor /proc/cpuinfo) = $max)"
echo $message | logger -t load_average_max
send "$message"
fi
else
if [ -e $LOCK_WORKING_DIR/load_average_max.lock ]; then
rm $LOCK_WORKING_DIR/load_average_max.lock
fi
fi