Skip to content
Snippets Groups Projects
Commit 5d81c769 authored by Hahn Axel (hahn)'s avatar Hahn Axel (hahn)
Browse files

Merge branch '6908_check_rearbackup' into 'master'

6908 check rearbackup

See merge request !223
parents 280e543e 528c306a
No related branches found
No related tags found
1 merge request!2236908 check rearbackup
......@@ -10,11 +10,12 @@
# 2020-07-27 v0.x <axel.hahn@iml.unibe.ch>
# 2023-12-20 v0.2 <axel.hahn@iml.unibe.ch>
# 2023-12-21 v1.0 <axel.hahn@iml.unibe.ch> first version
# 2023-12-21 v1.1 <axel.hahn@iml.unibe.ch> Update help text
# ======================================================================
. $(dirname $0)/inc_pluginfunctions
export self_APPVERSION=1.0
export self_APPVERSION=1.1
sInstalldir=/opt/imlbackup/server
sScript=storage_helper.sh
......@@ -24,6 +25,7 @@ sMode=
# FUNCTIONS
# ----------------------------------------------------------------------
# show help
function showHelp(){
local _self; _self=$(basename $0)
cat <<EOF
......@@ -35,33 +37,48 @@ You can get the count of connections or the status of server backup.
See https://os-docs.iml.unibe.ch/iml-backup-server/
SYNTAX:
$_self [-d DIRECTORY] -m MODE
OPTIONS:
-h or --help show this help.
-d or --dir set installation dir of iml deployment to find its check skript
-h, --help
show this help.
-d, --dir PATH
set installation dir of iml deployment to find its check skript
default dir: ${sInstalldir}
script: ${sInstalldir}/${sScript}
-m or --mode mode: set type of result; one of status|backupstatus
-m, --mode MODE
mode: set type of result; one of status|backupstatus
backupstatus status of backup sets of all servers
status count of connected servers
EXAMPLE:
$_self -m status
$_self -m backupstatus
EOF
}
# get all server entries with a given status
# param string status character in 1st column; one of .|?|D|E
# param string text to parse
function _getServerOfStatus(){
local _key="$1"
local _data="$2"
grep "$_key .*| [0-9].* |" <<< "$_data"
}
# get count of servers with a given status
# param string status character in 1st column; one of .|?|D|E
# param string text to parse
function _getStatusCount(){
_getServerOfStatus "$1" "$2" | wc -l
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
......
#!/bin/bash
# ======================================================================
#
# Check REAR BACKUP
#
# ----------------------------------------------------------------------
# 2023-12-22 v1.0 <axel.hahn@unibe.ch>
# ======================================================================
. $( dirname $0 )/inc_pluginfunctions
export self_APPVERSION=1.0
dir_reardata=/rearshare/rear-backup
typeset -i iAgeSec
typeset -i iAgeD
typeset -i iTotal
typeset -i iOK
typeset -i iWarning
typeset -i iCritical
typeset -i iLimitWarning=7
typeset -i iLimitCritical=14
# ----------------------------------------------------------------------
# FUNCTIONS
# ----------------------------------------------------------------------
# show help text
function showHelp(){
local _self; _self=$(basename $0)
cat <<EOF
$( ph.showImlHelpHeader )
Check if iso files of rear backup are not out of date.
You can customize the values for
* backup directory
* limits for warning and critical
This plugin sends performancedata.
SYNTAX:
$_self [-h] [--dir PATH] [--critical VALUE] [--warning VALUE]
OPTIONS:
-h, --help
this help
PARAMETERS:
-d, --dir PATH
set installation dir of iml deployment to find its check skript
default dir: ${dir_reardata}
-c, --critical VALUE
critical level in days (default: $iLimitCritical)
-w. --warning VALUE
warning level in days (default: $iLimitWarning)
EXAMPLE:
$_self
Check backup data with initial values
$_self -d /data/mybackups
Check iso files a given directory
$_self -d /data/mybackups -w 14 -c 28
Check iso files a given directory and customized limits
EOF
}
# get age of a file in sec
# param string filename to test
function _getFileAge(){
echo $(($(date +%s) - $(date +%s -r "$1")))
}
# get a list of iso files in rear backup dir in alphabetic order
function _getIsofiles(){
find "${dir_reardata}" -type f -name "*.iso" | sort
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
# --- check param -h
while [[ "$#" -gt 0 ]]; do case $1 in
-h|--help) showHelp; exit 0;;
-d|--dir) dir_reardata=$2; shift ;shift;;
-c|--critcal) iLimitCritical=$2; shift ;shift;;
-w|--warning) iLimitWarning=$2; shift ;shift;;
*) echo "ERROR: Unknown parameter: $1"; showHelp; exit 1;
esac; done
# --- test
if [ $iLimitWarning -ge $iLimitCritical ]; then
ph.abort "ERROR: limit for warning ($iLimitWarning) must be lower than critical ($iLimitCritical). Get help with -h."
fi
if [ ! -d "$dir_reardata" ]; then
ph.abort "ERROR: directory [$dir_reardata] does not exist. Set it with -d. Get help with -h."
fi
if [ ! -r "$dir_reardata" ]; then
ph.abort "ERROR: unable to read the existing dir [$dir_reardata]. Check the permissions for $USER."
fi
# --- output data
data="$( for myiso in $( _getIsofiles )
do
iAgeSec=$( _getFileAge "$myiso" )
iAgeD=$iAgeSec/60/60/24
sBar=$( yes '#' | head -n $iAgeD | tr -d "\n" )
sStatus="OK"
if [ $iAgeD -ge $iLimitWarning ]; then
if [ $iAgeD -ge $iLimitCritical ]; then
sStatus="CRITICAL"
else
sStatus="WARNING"
fi
fi
printf "%-9s %3s d %-10s %s\n" $sStatus $iAgeD "$sBar" "$( ls -l $myiso )"
done
)"
# --- Counters
iTotal=$( grep -c "." <<< "$data" )
iOK=$( grep -c "^OK" <<< "$data" )
iWarning=$( grep -c "^WARNING" <<< "$data" )
iCritical=$( grep -c "^CRITICAL" <<< "$data" )
test $iWarning -gt 0 && ph.setStatus "warning"
test $iCritical -gt 0 && ph.setStatus "critical"
# --- ouput
ph.status "Rear backup $dir_reardata - $iTotal total - $iCritical critical ($iLimitCritical d) .. $iWarning warnings ($iLimitWarning d) .. $iOK OK"
echo "All iso files in alphabetic order:"
echo "$data"
# --- performance data
ph.perfadd "ok" "$iOK" "" "" 0 $iTotal
ph.perfadd "warning" "$iWarning" "" "" 0 $iTotal
ph.perfadd "critical" "$iCritical" "" "" 0 $iTotal
ph.exit
# ----------------------------------------------------------------------
......@@ -40,6 +40,7 @@ There is one include script used by all checks:
* check_proc_ressources
* check_proc_zombie
* [check_psqlserver](check_psqlserver.md)
* [check_rearbackup](check_rearbackup.md)
* [check_reboot_required](check_reboot_required.md)
* check_requirements
* check_sensuplugins
......
......@@ -26,7 +26,7 @@ uid=1041(icingaclient) gid=1041(icingaclient) groups=1041(icingaclient),1031(iml
______________________________________________________________________
CHECK_IML_BACKUP_SERVER
v1.0
v1.1
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
......@@ -40,18 +40,26 @@ You can get the count of connections or the status of server backup.
See https://os-docs.iml.unibe.ch/iml-backup-server/
SYNTAX:
check_iml_backup_server [-d DIRECTORY] -m MODE
OPTIONS:
-h or --help show this help.
-d or --dir set installation dir of iml deployment to find its check skript
-h, --help
show this help.
-d, --dir PATH
set installation dir of iml deployment to find its check skript
default dir: /opt/imlbackup/server
script: /opt/imlbackup/server/storage_helper.sh
-m or --mode mode: set type of result; one of status|backupstatus
-m, --mode MODE
mode: set type of result; one of status|backupstatus
backupstatus status of backup sets of all servers
status count of connected servers
EXAMPLE:
check_iml_backup_server -m status
check_iml_backup_server -m backupstatus
......@@ -61,9 +69,6 @@ check_iml_backup_server -m backupstatus
### Backup server status
``check_http -u https://www.example.com/`` is a check that makes an http GET request.
The queck is OK if the responded status code is no error - if it is 2xx (OK) or a redirect (3xx).
```txt
# ./check_iml_backup_server -m backupstatus
OK: Server Backups - 36 servers in backup - 0 errors - 7 disbled - 0 running
......
# Check Rear backup
## Introduction
This check can verify the age of all iso files in the backup target directory.
## Requirements
There can be a permission issue to reach the backup target directory.
On our servers the backup target is using a user *imlbackup*. To give access to its resources we added the group "imlrear" for icinga.
```txt
$ id icingaclient
uid=1041(icingaclient) gid=1041(icingaclient) groups=1041(icingaclient),1056(imlrear)
^
|
additional group for icinga client user -----+
```
## Syntax
```txt
______________________________________________________________________
CHECK_REARBACKUP
v1.0
(c) Institute for Medical Education - University of Bern
Licence: GNU GPL 3
https://os-docs.iml.unibe.ch/icinga-checks/Checks/check_rearbackup.html
______________________________________________________________________
Check if iso files of rear backup are not out of date.
You can customize the values for
* backup directory
* limits for warning and critical
This plugin sends performancedata.
SYNTAX:
check_rearbackup [-h] [--dir PATH] [--critical VALUE] [--warning VALUE]
OPTIONS:
-h, --help
this help
PARAMETERS:
-d, --dir PATH
set installation dir of iml deployment to find its check skript
default dir: /rearshare/rear-backup
-c, --critical VALUE
critical level in days (default: 14)
-w. --warning VALUE
warning level in days (default: 7)
EXAMPLE:
check_rearbackup
Check backup data with initial values
check_rearbackup -d /data/mybackups
Check iso files a given directory
check_rearbackup -d /data/mybackups -w 14 -c 28
Check iso files a given directory and customized limits
```
## Examples
### Rear backup status
```txt
# ./check_rearbackup
CRITICAL: Rear backup /rearshare/rear-backup - 20 total - 0 critical (7 d) .. 2 warnings (14 d) .. 18 OK
All iso files in alphabetic order:
OK 4 d #### -rw-rw-r--. 1 imlrear imlrear 3907082240 Dec 17 10:28 /rearshare/rear-backup/admin/admin.example.com_backup.iso
OK 5 d ##### -rw-rw-r--. 1 imlrear imlrear 573384704 Dec 16 18:07 /rearshare/rear-backup/awx/awx.example.com_backup.iso
(...)
|ok=18;;;0;20 warning=2;;;0;20 critical=0;;;0;20
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment