mirror of
https://github.com/m8tin/cis.git
synced 2026-04-02 19:01:30 +02:00
Improved generic monitoring checks for usage of block devides and zfs pools
This commit is contained in:
57
script/monitor/generic/DEV_USAGE_CHECK.sh
Executable file
57
script/monitor/generic/DEV_USAGE_CHECK.sh
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
_REMOTE_HOST="${1:?"FQDN of server missing: e.g. host.example.net[:port]"}"
|
||||||
|
_REMOTE_HOSTNAME_FQDN="${_REMOTE_HOST%%:*}" #Removes longest matching pattern ':*' from the end
|
||||||
|
_REMOTE_HOSTNAME_SHORT="${_REMOTE_HOSTNAME_FQDN%%.*}" #Removes longest matching pattern '.*' from the end
|
||||||
|
_REMOTE_PORT="${_REMOTE_HOST}:"
|
||||||
|
_REMOTE_PORT="${_REMOTE_PORT#*:}" #Removes shortest matching pattern '*:' from the begin
|
||||||
|
_REMOTE_PORT="${_REMOTE_PORT%%:*}" #Removes longest matching pattern ':*' from the end
|
||||||
|
_REMOTE_PORT="${_REMOTE_PORT:-"22"}"
|
||||||
|
_REMOTE_USER="monitoring"
|
||||||
|
_SOCKET='~/.ssh/%r@%h:%p'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function checkOrStartSSHMaster() {
|
||||||
|
timeout --preserve-status 1 ssh -O check -S ${_SOCKET} -p ${_REMOTE_PORT} ${_REMOTE_USER}@${_REMOTE_HOSTNAME_FQDN} 2>&1 | grep -q -F 'Master running' \
|
||||||
|
&& return 0
|
||||||
|
|
||||||
|
ssh -O stop -S ${_SOCKET} -p ${_REMOTE_PORT} ${_REMOTE_USER}@${_REMOTE_HOSTNAME_FQDN} &> /dev/null
|
||||||
|
ssh -o ControlMaster=auto \
|
||||||
|
-o ControlPath=${_SOCKET} \
|
||||||
|
-o ControlPersist=65 \
|
||||||
|
-p ${_REMOTE_PORT} \
|
||||||
|
-f ${_REMOTE_USER}@${_REMOTE_HOSTNAME_FQDN} exit &> /dev/null \
|
||||||
|
&& return 0
|
||||||
|
|
||||||
|
echo "FAIL#SSH connection (setup ok?)"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSpace(){
|
||||||
|
checkOrStartSSHMaster \
|
||||||
|
|| return 1
|
||||||
|
|
||||||
|
local _RESULT="$(ssh -S ${_SOCKET} -p ${_REMOTE_PORT} ${_REMOTE_USER}@${_REMOTE_HOSTNAME_FQDN} 'df "/" | tail -n1 | tr -s "[:blank:]" " " | cut -d" " -f1,5')"
|
||||||
|
local _DEV=$(echo "${_RESULT}" | /usr/bin/tail -n 1 | /usr/bin/cut -d' ' -f1)
|
||||||
|
local _SPACE_USED=$(echo "${_RESULT}" | /usr/bin/tail -n 1 | /usr/bin/cut -d' ' -f2)
|
||||||
|
|
||||||
|
[ -z "${_SPACE_USED}" ] \
|
||||||
|
&& echo "FAIL#NO value" \
|
||||||
|
&& return 0
|
||||||
|
|
||||||
|
[ "${1:?"Missing OK_THRESHOLD"}" -ge "${_SPACE_USED%\%*}" ] \
|
||||||
|
&& echo "OK#${_SPACE_USED} used ${_DEV}." \
|
||||||
|
&& return 0
|
||||||
|
|
||||||
|
[ "${2:?"Missing INFO_THRESHOLD"}" -ge "${_SPACE_USED%\%*}" ] \
|
||||||
|
&& echo "INFO#${_SPACE_USED} already used ${_DEV}." \
|
||||||
|
&& return 0
|
||||||
|
|
||||||
|
echo "FAIL#${_SPACE_USED} used ${_DEV}!"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
testSpace 80 90 && exit 0
|
||||||
|
|
||||||
|
exit 1
|
||||||
@@ -32,9 +32,9 @@ function testSpace(){
|
|||||||
checkOrStartSSHMaster \
|
checkOrStartSSHMaster \
|
||||||
|| return 1
|
|| return 1
|
||||||
|
|
||||||
local _RESULT="$(ssh -S ${_SOCKET} -p ${_REMOTE_PORT} ${_REMOTE_USER}@${_REMOTE_HOSTNAME_FQDN} 'zpool list -H -o capacity,name')"
|
local _RESULT="$(ssh -S ${_SOCKET} -p ${_REMOTE_PORT} ${_REMOTE_USER}@${_REMOTE_HOSTNAME_FQDN} 'zpool list -H -o name,capacity')"
|
||||||
local _SPACE_USED=$(echo "${_RESULT}" | /usr/bin/tail -n 1 | /usr/bin/cut -f1)
|
local _POOL=$(echo "${_RESULT}" | /usr/bin/tail -n 1 | /usr/bin/cut -f1)
|
||||||
local _POOL=$(echo "${_RESULT}" | /usr/bin/tail -n 1 | /usr/bin/cut -f2)
|
local _SPACE_USED=$(echo "${_RESULT}" | /usr/bin/tail -n 1 | /usr/bin/cut -f2)
|
||||||
|
|
||||||
[ -z "${_SPACE_USED}" ] \
|
[ -z "${_SPACE_USED}" ] \
|
||||||
&& echo "FAIL#NO value" \
|
&& echo "FAIL#NO value" \
|
||||||
|
|||||||
Reference in New Issue
Block a user