Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
icinga-checks
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IML Open Source
icinga-checks
Commits
f9a95f3f
Commit
f9a95f3f
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add check_rearbackup
parent
280e543e
Branches
Branches containing commit
No related tags found
1 merge request
!223
6908 check rearbackup
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_rearbackup
+170
-0
170 additions, 0 deletions
check_rearbackup
with
170 additions
and
0 deletions
check_rearbackup
0 → 100755
+
170
−
0
View file @
f9a95f3f
#!/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
# ----------------------------------------------------------------------
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment