mirror of
https://github.com/m8tin/cis.git
synced 2025-12-06 07:48:26 +01:00
Handling of overwritten domain improved incl. monitoring and its documentation.
This commit is contained in:
46
script/monitor/generic/OVERRIDDEN_DOMAIN_CHECK.sh
Executable file
46
script/monitor/generic/OVERRIDDEN_DOMAIN_CHECK.sh
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/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}" &> /dev/null \
|
||||
&& echo "master checked" \
|
||||
&& 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 testDomain(){
|
||||
checkOrStartSSHMaster \
|
||||
|| return 1
|
||||
|
||||
local _RESULT="$(ssh -S ${_SOCKET} -p ${_REMOTE_PORT} ${_REMOTE_USER}@${_REMOTE_HOSTNAME_FQDN} 'bash /cis/core/printOwnDomain.sh' 2>&1 1>/dev/null)"
|
||||
|
||||
[ -z "${_RESULT}" ] \
|
||||
&& echo "OK" \
|
||||
&& return 0
|
||||
|
||||
echo "WARNING#Check hosts '/cis/core/printOwnDomain'"
|
||||
return 0
|
||||
}
|
||||
|
||||
testDomain && exit 0
|
||||
Reference in New Issue
Block a user