improved disk-watchdog : the e-mail now includes the user triggering the script
This commit is contained in:
parent
3c0c41d142
commit
9c8b3933d9
|
@ -3,17 +3,17 @@
|
||||||
# see https://bugzilla.ipr.univ-rennes1.fr/show_bug.cgi?id=3193 for details
|
# see https://bugzilla.ipr.univ-rennes1.fr/show_bug.cgi?id=3193 for details
|
||||||
|
|
||||||
# test run:
|
# test run:
|
||||||
# graffy@work:~/bug3193$ ./disk-watchdog.sh /mnt/work/graffy/workspaces/meniscus $HOME/var/run/ipr/cluster/disk-watchdog /opt/ipr/cluster/work.global 90 guillaume.raffy@univ-rennes1.fr "graffy (manual trigger)" 20
|
# graffy@work:~/bug3193$ ./disk-watchdog.sh /mnt/work/graffy/workspaces/meniscus $HOME/var/run/ipr/cluster/disk-watchdog /opt/ipr/cluster/work.global 90 guillaume.raffy@univ-rennes1.fr "manual trigger" 20
|
||||||
|
|
||||||
# production run:
|
# production run:
|
||||||
# graffy@work:~/bug3193$ sudo ./disk-watchdog.sh /mnt/work /var/run/ipr/cluster/disk-watchdog /opt/ipr/cluster/work.global 90 ipr-cluster@listes.univ-rennes1.fr "graffy (manual trigger)" 20
|
# graffy@work:~/bug3193$ sudo ./disk-watchdog.sh /mnt/work /var/run/ipr/cluster/disk-watchdog /opt/ipr/cluster/work.global 90 ipr-cluster@listes.univ-rennes1.fr "cron" 20
|
||||||
|
|
||||||
SHARED_DISK_ROOT="$1" # eg '/mnt/work'
|
SHARED_DISK_ROOT="$1" # eg '/mnt/work'
|
||||||
REPORTS_ROOT_PATH="$2" # eg "$HOME/var/run/ipr/cluster/disk-watchdog"
|
REPORTS_ROOT_PATH="$2" # eg "$HOME/var/run/ipr/cluster/disk-watchdog"
|
||||||
DISK_PUBLIC_PATH="$3" # 'eg /opt/ipr/cluster/work.global'
|
DISK_PUBLIC_PATH="$3" # 'eg /opt/ipr/cluster/work.global'
|
||||||
FULLNESS_THRESHOLD="$4" # disk fullness percentage above which an e-mail is sent (eg. '90' for 90%)
|
FULLNESS_THRESHOLD="$4" # disk fullness percentage above which an e-mail is sent (eg. '90' for 90%)
|
||||||
DEST_EMAIL="$5" # eg ipr-cluster@listes.univ-rennes1.fr
|
DEST_EMAIL="$5" # eg ipr-cluster@listes.univ-rennes1.fr
|
||||||
TRIGGERER="$6" # eg "daily cron"
|
TRIGGER_REASON="$6" # eg "daily cron"
|
||||||
TOP_SIZE="$7" # # number of biggest directories reported (eg 20)"
|
TOP_SIZE="$7" # # number of biggest directories reported (eg 20)"
|
||||||
|
|
||||||
RETURNCODE_SUCCESS=0
|
RETURNCODE_SUCCESS=0
|
||||||
|
@ -130,12 +130,12 @@ function check_disk_usage()
|
||||||
local disk_public_path="$3" # eg /opt/ipr/cluster/work.global
|
local disk_public_path="$3" # eg /opt/ipr/cluster/work.global
|
||||||
local fullness_threshold="$4" # eg '90' for 90%
|
local fullness_threshold="$4" # eg '90' for 90%
|
||||||
local dest_email="$5" # eg ipr-cluster@listes.univ-rennes1.fr
|
local dest_email="$5" # eg ipr-cluster@listes.univ-rennes1.fr
|
||||||
local triggerer="$6" # eg "work.ipr.univ-rennes1.fr:/etc/cron.daily"
|
local trigger_reason="$6" # eg "cron.daily"
|
||||||
local top_size="$7" # number of biggest directories reported (eg 20)
|
local top_size="$7" # number of biggest directories reported (eg 20)
|
||||||
local trigger_date="$(date)"
|
local trigger_date="$(date)"
|
||||||
|
|
||||||
disk_id=$(basename "${shared_disk_root}")
|
disk_id=$(basename "${shared_disk_root}")
|
||||||
log "check of ${shared_disk_root} triggered by ${triggerer} with threshold ${fullness_threshold} %"
|
log "check of ${shared_disk_root} triggered by ${trigger_reason} with threshold ${fullness_threshold} %"
|
||||||
|
|
||||||
mkdir -p "{$reports_root_path}"
|
mkdir -p "{$reports_root_path}"
|
||||||
this_report_dir="${reports_root_path}/${disk_id}-$(date +'%Y-%m-%d-%H-%M-%S')"
|
this_report_dir="${reports_root_path}/${disk_id}-$(date +'%Y-%m-%d-%H-%M-%S')"
|
||||||
|
@ -188,7 +188,7 @@ function check_disk_usage()
|
||||||
fi
|
fi
|
||||||
html_content="${html_content}${localized_message}"
|
html_content="${html_content}${localized_message}"
|
||||||
done
|
done
|
||||||
html_content="${html_content}<small>disk-watchdog.ipr.univ-rennes1.fr v1.0 - triggered from $(hostname --fqdn) by : ${triggerer} on ${trigger_date}</small>"
|
html_content="${html_content}<small>disk-watchdog.ipr.univ-rennes1.fr v1.0 - triggered from $(hostname --fqdn) by : $(whoami) (${trigger_reason}) on ${trigger_date}</small>"
|
||||||
|
|
||||||
local sendmail_stdin="To: ${to}\nFrom: ${from}\nSubject: ${subject}\nContent-Type: text/html; charset=\"UTF-8\"\n<html>${html_content}</html>\n"
|
local sendmail_stdin="To: ${to}\nFrom: ${from}\nSubject: ${subject}\nContent-Type: text/html; charset=\"UTF-8\"\n<html>${html_content}</html>\n"
|
||||||
printf "$sendmail_stdin" | /usr/sbin/sendmail "${to}"
|
printf "$sendmail_stdin" | /usr/sbin/sendmail "${to}"
|
||||||
|
@ -200,7 +200,7 @@ set -o errexit
|
||||||
|
|
||||||
if [ $# = 7 ]
|
if [ $# = 7 ]
|
||||||
then
|
then
|
||||||
check_disk_usage "${SHARED_DISK_ROOT}" "${REPORTS_ROOT_PATH}" "${DISK_PUBLIC_PATH}" "${FULLNESS_THRESHOLD}" "${DEST_EMAIL}" "${TRIGGERER}" "${TOP_SIZE}"
|
check_disk_usage "${SHARED_DISK_ROOT}" "${REPORTS_ROOT_PATH}" "${DISK_PUBLIC_PATH}" "${FULLNESS_THRESHOLD}" "${DEST_EMAIL}" "${TRIGGER_REASON}" "${TOP_SIZE}"
|
||||||
else
|
else
|
||||||
error "wrong number of arguments"
|
error "wrong number of arguments"
|
||||||
exit "${RETURNCODE_ERROR}"
|
exit "${RETURNCODE_ERROR}"
|
||||||
|
|
Loading…
Reference in New Issue