Search
j0ke.net Open Build Service
>
Projects
>
server:monitoring
>
nagios-plugins-automysqlbackup
> check_mysql_backup_files
Sign Up
|
Log In
Username
Password
Cancel
Overview
Repositories
Revisions
Requests
Users
Advanced
Attributes
Meta
File check_mysql_backup_files of Package nagios-plugins-automysqlbackup (Revision 4)
Currently displaying revision
4
,
show latest
#!/usr/bin/env bash # Author: Marek Rzepala <Marek.Rzepala@internetx.com> # Version: 3.01 # Last changed: 27.10.2021 # Upstream URL: https://gitlab.muc.internetx.com/p-s/nagios/check_mysql_backup_files IFS=$'\n' warn_daily=86400 # one day crit_daily=$(($warn_daily * 2)) warn_weekly=$(($warn_daily * 36)) crit_weekly=$(($warn_weekly + $crit_daily)) warn_monthly=$(($warn_daily * 151)) crit_monthly=$(($warn_monthly + $crit_daily)) now=$(date +'%s') confdir=/etc/multimysqlbackup.d/ backdirs+=($(awk -F ";" '{print $1}' <(grep -vh ^# $confdir/*.conf) | awk -F ":" '{print $1}')) stat=0 stat_warn=0 stat_crit=0 #### data gathering for rota in daily weekly monthly do for ((i=0;i<${#backdirs[@]};i++)) do for backstat in $(find /backup/mysql/${backdirs[i]}/$rota/* -maxdepth 0 -type d -printf '%p %Cs\n') do diff=$(($now - $(awk '{print $2}' <(printf $backstat)))) case $rota in daily) case $((($diff >= $warn_daily && $diff <= $crit_daily) * 1 + ($diff >= $crit_daily ) * 2)) in 1) warns+=($(echo "${backdirs[i]}_daily $backstat $(($diff / 3600))")) && stat_warn=1 ;; 2) crits+=($(echo "${backdirs[i]}_daily $backstat $(($diff / 3600))")) && stat_crit=2 ;; esac ;; weekly) case $((($diff >= $warn_weekly && $diff <= $crit_weekly) * 1 + ($diff >= $crit_weekly ) * 2)) in 1) warns+=($(echo "${backdirs[i]}_weekly $backstat $(($diff / 3600))")) && stat_warn=1 ;; 2) crits+=($(echo "${backdirs[i]}_weekly $backstat $(($diff / 3600))")) && stat_crit=2 ;; esac ;; monthly) case $((($diff >= $warn_monthly && $diff <= $crit_monthly) * 1 + ($diff >= $crit_monthly ) * 2)) in 1) warns+=($(echo "${backdirs[i]}_monthly $backstat $(($diff / 3600))")) && stat_warn=1 ;; 2) crits+=($(echo "${backdirs[i]}_monthly $backstat $(($diff / 3600))")) && stat_crit=2 ;; esac ;; esac done done done #### #### functions for printing warnings und criticals gathered in prior for loop stat=$(($stat_warn+$stat_crit)) print_warns () { for ((i=0;i<${#warns[@]};i++)) do echo -n "{$(awk '{print $1}' <(echo ${warns[i]})) backup " echo -n $(awk -F "/" '{print $NF}' <(echo ${warns[i]})| awk '{print $1}') echo -n " $(awk '{print $NF}' <(echo ${warns[i]})) hours old!}" done } print_crits () { for ((i=0;i<${#crits[@]};i++)) do echo -n "{$(awk '{print $1}' <(echo ${crits[i]})) backup " echo -n $(awk -F "/" '{print $NF}' <(echo ${crits[i]})| awk '{print $1}') echo -n " $(awk '{print $NF}' <(echo ${crits[i]})) hours old!}" done } #### print and exit depending on $stat set in data gathering loop case $stat in 1) echo -n "WARNING check backup " print_warns exit 1 ;; 2) echo -n "CRITICAL " print_crits exit 2 ;; 3) echo -n "CRITICAL " print_warns echo -n "WARNING " print_crits exit 2 ;; 0) echo "we gucci" exit 0 ;; esac