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
af13fb0f
Commit
af13fb0f
authored
11 months ago
by
Martin
Browse files
Options
Downloads
Patches
Plain Diff
add check check_file_age
parent
877105fd
Branches
Branches containing commit
No related tags found
1 merge request
!275
add check check_file_age
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_file_age
+176
-0
176 additions, 0 deletions
check_file_age
with
176 additions
and
0 deletions
check_file_age
0 → 100644
+
176
−
0
View file @
af13fb0f
#!/bin/bash
# ======================================================================
#
# Check file age
#
# ----------------------------------------------------------------------
# 2024-06-21 v1.0 <martin.gasser@unibe.ch>
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
export
self_APPVERSION
=
1.0
dir_files
=
/var/iml-backup
filter_files
=
'*.*'
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 files are not out of date.
You can customize the values for
* directory
* limits for warning and critical
* filename filter pattern
This plugin sends performancedata.
SYNTAX:
$_self
[-h] [--dir PATH] [--filter FILTER] [--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_files
}
-c, --critical VALUE
critical level in days (default:
$iLimitCritical
)
-w. --warning VALUE
warning level in days (default:
$iLimitWarning
)
-f --filter FILTER
filter for filenames (default:
${
filter_files
}
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 files in dir in alphabetic order
function
_getfiles
(){
find
"
${
dir_files
}
"
-type
f
-name
"
${
filter_files
}
"
|
sort
}
# ----------------------------------------------------------------------
# MAIN
# ----------------------------------------------------------------------
# --- check param -h
while
[[
"$#"
-gt
0
]]
;
do case
$1
in
-h
|
--help
)
showHelp
;
exit
0
;;
-d
|
--dir
)
dir_files
=
$2
;
shift
;
shift
;;
-c
|
--critcal
)
iLimitCritical
=
$2
;
shift
;
shift
;;
-w
|
--warning
)
iLimitWarning
=
$2
;
shift
;
shift
;;
-f
|
--filter
)
filter_files
=
$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_files
"
]
;
then
ph.abort
"ERROR: directory [
$dir_files
] does not exist. Set it with -d. Get help with -h."
fi
if
[
!
-r
"
$dir_files
"
]
;
then
ph.abort
"ERROR: unable to read the existing dir [
$dir_files
]. Check the permissions for
$USER
."
fi
# --- output data
data
=
"
$(
for
myfile
in
$(
_getfiles
)
do
iAgeSec
=
$(
_getFileAge
"
$myfile
"
)
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
-lh
$myfile
)
"
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
"File age
$dir_files
-
$iTotal
total -
$iCritical
critical (
$iLimitCritical
d) ..
$iWarning
warnings (
$iLimitWarning
d) ..
$iOK
OK"
echo
"All 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