mirror of
https://github.com/m8tin/cis.git
synced 2026-06-02 14:56:58 +02:00
Refactoring to remove printOwnDomain.sh in the future
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
#!/bin/bash
|
||||
source /cis/core/base.module.sh
|
||||
|
||||
_SCRIPT="$(readlink -f "${0}" 2> /dev/null)"
|
||||
|
||||
# Folders always ends with an tailing '/'
|
||||
_CIS_ROOT="${_SCRIPT%%/script/monitor/*}/" #Removes longest matching pattern '/script/monitor/*' from the end
|
||||
_DOMAIN="$("${_CIS_ROOT:?"Missing CIS_ROOT"}core/printOwnDomain.sh")"
|
||||
_COMPOSITIONS="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/${_DOMAIN:?"Missing DOMAIN"}/compositions/"
|
||||
|
||||
_REMOTE_HOST="${1:?"FQDN of server missing: e.g. host.example.net[:port]"}"
|
||||
base.set _REMOTE_HOST "${1:?"FQDN of server missing: e.g. host.example.net[:port]"}" '^([a-zA-Z0-9][a-zA-Z0-9.-]*)+(:[0-9]+)?$'
|
||||
_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}:"
|
||||
@@ -21,9 +17,11 @@ _SOCKET='~/.ssh/%r@%h:%p'
|
||||
# - default value for the filter part is extracted from the first parameter (FQDN)
|
||||
# - but you can override this part to to adapt the test during a change of the domain.
|
||||
# (e.g. the short hostname can be an option - or even a better default in the future)
|
||||
_ZFS_SNAPSHOT_FILTER="@SYNC_${2:-"${_REMOTE_HOSTNAME_FQDN:?"Missing REMOTE_HOSTNAME_FQDN"}"}"
|
||||
base.set _GIVEN_REMOTE_HOSTNAME_FQDN "${2}" '^([a-zA-Z0-9][a-zA-Z0-9.-]*)?$'
|
||||
_DEFINED_REMOTE_HOSTNAME_FQDN="${_GIVEN_REMOTE_HOSTNAME_FQDN:-"${_REMOTE_HOSTNAME_FQDN:?"Missing REMOTE_HOSTNAME_FQDN"}"}"
|
||||
_ZFS_SNAPSHOT_FILTER="@SYNC_${_DEFINED_REMOTE_HOSTNAME_FQDN}"
|
||||
|
||||
_MODE="${3:-"normal"}"
|
||||
base.set _MODE "${3:-"normal"}" '^(debug|normal)$'
|
||||
_NOW_UTC_UNIXTIME=$(date -u +%s)
|
||||
_DEBUG_PATH="/tmp/monitor/"
|
||||
|
||||
@@ -53,7 +51,7 @@ function checkSync() {
|
||||
&& mkdir -p "${_DEBUG_PATH}" > /dev/null \
|
||||
&& echo "Now: ${_NOW_UTC_UNIXTIME}" > ${_DEBUG_PATH}SECONDS_BEHIND_${_REMOTE_HOSTNAME_FQDN}.txt
|
||||
|
||||
! [ -d "${_COMPOSITIONS:?"Missing COMPOSITIONS"}" ] \
|
||||
! [ -d "${CIS[COMPOSITIONS]:?"Missing global parameter CIS_COMPOSITIONS"}" ] \
|
||||
&& echo "WARN#no compositions" \
|
||||
&& return 0
|
||||
|
||||
@@ -71,7 +69,7 @@ function checkSync() {
|
||||
|
||||
echo "OK#Checks running"
|
||||
|
||||
for _COMPOSITION_PATH in ${_COMPOSITIONS}*; do
|
||||
for _COMPOSITION_PATH in "${CIS[COMPOSITIONS]}"*; do
|
||||
|
||||
# If remote host is found than it is responsible for this container-composition, otherwise skip
|
||||
# (grep -E "^[[:blank:]]*something" means. Line has to start with "something", leading blank chars are ok.)
|
||||
|
||||
Reference in New Issue
Block a user