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
0e2ed820
Commit
0e2ed820
authored
1 year ago
by
Hahn Axel (hahn)
Browse files
Options
Downloads
Patches
Plain Diff
add help page; use smartctl --scan to detect devices
parent
06a567a2
Branches
Branches containing commit
No related tags found
1 merge request
!271
Update docs
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
check_smartstatus
+62
-9
62 additions, 9 deletions
check_smartstatus
with
62 additions
and
9 deletions
check_smartstatus
+
62
−
9
View file @
0e2ed820
...
...
@@ -38,11 +38,14 @@
# 2021-10-28 v1.3 <axel.hahn@iml.unibe.ch> detect -d param for smartctl
# 2022-07-08 v1.4 <axel.hahn@iml.unibe.ch> remove pipe in status line
# 2023-10-20 v1.5 <axel.hahn@unibe.ch> harden sudo command execution
# 2024-06-07 v1.6 <axel.hahn@unibe.ch> add help page; use smartctl --scan to detect devices
# ======================================================================
.
$(
dirname
$0
)
/inc_pluginfunctions
self_APPVERSION
=
1.6
typeset
-i
iFound
=
0
typeset
-i
iErrors
=
0
sOut
=
...
...
@@ -56,6 +59,35 @@ export PATH
# functions
# ----------------------------------------------------------------------
# show help
function
showHelp
(){
local
self
=
$(
basename
$0
)
cat
<<
EOH
$(
ph.showImlHelpHeader
)
Show status of local S.M.A.R.T. devices.
SYNTAX:
$self
[-h] [-l] [devices]
OPTIONS:
-h|--help show this help.
-l|--list list devices only.
PARAMETERS:
EXAMPLES
$self
Scan all local disks
$self
-l
List all local disks without scanning them.
EOH
}
function
detectParam
(){
local
_mydevice
=
$1
local
_moreparam
...
...
@@ -74,7 +106,8 @@ function checkDrive(){
sLabel
=
"^SMART.*Health"
sOK
=
"(ok|passed)"
sOut
=
"
$sOut
;
${
device
}
:"
test
-n
"
$sOut
"
&&
sOut
=
"
$sOut
; "
sOut
=
"
${
device
}
:"
ls
-ld
$device
>
/dev/null 2>&1
...
...
@@ -91,7 +124,7 @@ function checkDrive(){
# --- check health
moreparam
=
$(
detectParam
$device
)
echo sudo
smartctl
-Ha
$device
$moreparam
>>
$tmpfile
2>&1
sudo
smartctl
-Ha
$device
$moreparam
>>
$tmpfile
2>&1
sudo
-n
smartctl
-Ha
$device
$moreparam
>>
$tmpfile
2>&1
rcs
=
$?
echo
$device
-
rc
=
$rcs
>>
$tmpfile
echo
>>
$tmpfile
...
...
@@ -103,7 +136,7 @@ function checkDrive(){
else
grep
-i
"
$sLabel
"
$tmpfile
>
/dev/null
if
[
$?
-eq
0
]
;
then
status
=
`
grep
-i
"
$sLabel
"
$tmpfile
|
cut
-f
2
-d
":"
`
status
=
$(
grep
-i
"
$sLabel
"
$tmpfile
|
cut
-f
2
-d
":"
)
sOut
=
"
$sOut
${
status
}
"
echo
$status
|
grep
-Ei
"
$sOK
"
>>
$tmpfile
if
[
$?
-ne
0
]
;
then
...
...
@@ -124,10 +157,26 @@ function checkDrive(){
fi
}
function
listDevices
(){
sudo
-n
smartctl
--scan
|
grep
-v
"/dev/bus/"
}
# ----------------------------------------------------------------------
# main
# ----------------------------------------------------------------------
# parse params
customaction
=
while
[[
"$#"
-gt
0
]]
;
do case
$1
in
-h
|
--help
)
showHelp
;
exit
0
;;
-l
|
--list
)
customaction
=
"list"
;
shift
1
;;
*
)
if
grep
"^-"
<<<
"
$1
"
>
/dev/null
;
then
echo
;
echo
"ERROR: Unknown parameter:
$1
"
;
echo
;
exit
2
fi
break
;
;;
esac
;
done
ph.require smartctl
rm
-f
$tmpDetailsfile
2>/dev/null
...
...
@@ -137,8 +186,15 @@ if ! sudo -n smartctl -h >/dev/null 2>&1; then
ph.abort
"UNKNOWN: No sudo permissions to execute smartctl."
fi
if
[
"
$customaction
"
==
"list"
]
;
then
echo
"Devices to scan:"
listDevices |
sed
"s#^#- #"
exit
0
fi
# --- loop over sd devices
for
mydevice
in
$(
ls
-1
/dev/sd
*
|
grep
-v
"[0-9]"
)
# for mydevice in $(ls -1 /dev/sd* | grep -v "[0-9]")
for
mydevice
in
$(
listDevices |
cut
-f
1
-d
" "
)
do
iFound
=
$iFound
+1
...
...
@@ -154,12 +210,9 @@ do
checkDrive
$mydevice
done
ph.status
"SMART check on
$iFound
HDs -
$iErrors
errors -
$sOut
"
cat
$tmpDetailsfile
rm
-f
$tmpDetailsfile
ph.status
"SMART check on
$iFound
Disks -
$iErrors
errors -
$sOut
"
cat
$tmpDetailsfile
2>&1
&&
rm
-f
$tmpDetailsfile
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