mirror of
https://github.com/m8tin/cis.git
synced 2025-12-06 07:48:26 +01:00
Setup of monitoring host and monitored host added, definition is per domain now
This commit is contained in:
@@ -2,14 +2,13 @@
|
||||
|
||||
# Folders always ends with an tailing '/'
|
||||
_SCRIPT="$(readlink -f "${0}" 2> /dev/null)"
|
||||
_SCRIPT_PATH="$(dirname ${_SCRIPT:?"Missing SCRIPT"} 2> /dev/null)/"
|
||||
_CIS_ROOT="$(dirname $(dirname ${_SCRIPT_PATH:?"Missing SCRIPT_PATH"} 2> /dev/null) 2> /dev/null)/"
|
||||
_CIS_ROOT="${_SCRIPT%%/script/monitor/*}/" #Removes longest matching pattern '/script/monitor/*' from the end
|
||||
_CORE_SCRIPTS="${_CIS_ROOT:?"Missing CIS_ROOT"}core/"
|
||||
_CURRENT_DOMAIN="$("${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}printOwnDomain.sh")"
|
||||
_DEFINITIONS="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/${_CURRENT_DOMAIN:?"Missing CURRENT_DOMAIN"}/"
|
||||
|
||||
_ALL_CHECKS="${_DEFINITIONS:?"Missing DEFINITIONS"}monitor/host/all/"
|
||||
_OWN_CHECKS="${_DEFINITIONS:?"Missing DEFINITIONS"}monitor/host/$(hostname -s)/"
|
||||
# Checks for the entire domain
|
||||
_DOMAIN_CHECKS="${_DEFINITIONS:?"Missing DEFINITIONS"}monitor/checks/"
|
||||
|
||||
|
||||
|
||||
@@ -21,18 +20,12 @@ function doChecks(){
|
||||
mkdir -p ${_TMPDIR}
|
||||
rm ${_TMPDIR}/* > /dev/null 2>&1
|
||||
|
||||
for check in ${_ALL_CHECKS}*.on
|
||||
for check in ${_DOMAIN_CHECKS}*.on
|
||||
do
|
||||
local _CHECK_FILENAME="${check##*/}"
|
||||
echo -n "${_CHECK_FILENAME%%.on}?" > "${_TMPDIR}/${_CHECK_FILENAME}"
|
||||
timeout -k 10s 20s bash ${check} >> "${_TMPDIR}/${_CHECK_FILENAME}" 2> /dev/null || echo "TIMEOUT#Timeout" >> "${_TMPDIR}/${_CHECK_FILENAME}" &
|
||||
done
|
||||
# for check in ${_OWN_CHECKS}*.on
|
||||
# do
|
||||
# local _CHECK_FILENAME="${check##*/}"
|
||||
# echo -n "${_CHECK_FILENAME%%.on}?" > "${_TMPDIR}/${_CHECK_FILENAME}"
|
||||
# timeout -k 10s 20s bash ${check} >> "${_TMPDIR}/${_CHECK_FILENAME}" 2> /dev/null || echo "TIMEOUT#Timeout" >> "${_TMPDIR}/${_CHECK_FILENAME}" &
|
||||
# done
|
||||
wait
|
||||
|
||||
local _FAILED=0
|
||||
|
||||
57
script/monitor/setupMonitoringHost.sh
Executable file
57
script/monitor/setupMonitoringHost.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ "$(id -u)" != "0" ] \
|
||||
&& sudo "${0}" \
|
||||
&& exit 0
|
||||
|
||||
|
||||
|
||||
_SETUP="$(readlink -f "${0}" 2> /dev/null)"
|
||||
|
||||
# Folders always ends with an tailing '/'
|
||||
_CIS_ROOT="${_SETUP%%/script/monitor/*}/" #Removes longest matching pattern '/script/monitor/*' from the end
|
||||
_DOMAIN="$("${_CIS_ROOT:?"Missing CIS_ROOT"}core/printOwnDomain.sh")"
|
||||
_DEFINITIONS="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/${_DOMAIN:?"Missing DOMAIN"}/"
|
||||
|
||||
|
||||
|
||||
function printSelectedDefinition() {
|
||||
local _FILE_DEFINED_DOMAIN _FILE_DEFINED_DEFAULT
|
||||
_FILE_DEFINED_DOMAIN="${_DEFINITIONS:?"Missing DEFINITIONS"}monitor${1:?"Missing CURRENT_FULLFILE"}"
|
||||
_FILE_DEFINED_DEFAULT="${_CIS_ROOT:?"Missing CIS_ROOT"}script/monitor/${1:?"Missing CURRENT_FULLFILE"}"
|
||||
readonly _FILE_DEFINED_DOMAIN _FILE_DEFINED_DEFAULT
|
||||
|
||||
[ -s "${_FILE_DEFINED_DOMAIN}" ] \
|
||||
&& echo "${_FILE_DEFINED_DOMAIN}" \
|
||||
&& return 0
|
||||
|
||||
[ -s "${_FILE_DEFINED_DEFAULT}" ] \
|
||||
&& echo "${_FILE_DEFINED_DEFAULT}" \
|
||||
&& return 0
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
function setupPublicFile() {
|
||||
! [ -d "/var/www/html" ] \
|
||||
&& echo "Missing folder '/var/www/html'. Is a webserver installed?" \
|
||||
&& return 1
|
||||
|
||||
[ -L "/var/www/html/${1:?"Missing filename"}" ] \
|
||||
&& [ "$(readlink -f /var/www/html/${1:?"Missing filename"})" == "$(printSelectedDefinition ${1:?"Missing filename"})" ] \
|
||||
&& echo "Link '/var/www/html/${1:?"Missing filename"}' already exists pointing to the expected file:" \
|
||||
&& echo " - '$(readlink -f /var/www/html/${1:?"Missing filename"})'" \
|
||||
&& return 0
|
||||
|
||||
ln -f -s "$(printSelectedDefinition ${1:?"Missing filename"})" "/var/www/html/${1:?"Missing filename"}" \
|
||||
&& echo "Link '/var/www/html/${1:?"Missing filename"}' created successfully:" \
|
||||
&& echo " - '$(readlink -f /var/www/html/${1:?"Missing filename"})'" \
|
||||
&& return 0
|
||||
}
|
||||
|
||||
echo "Setup the monitoring host that monitors the others ... " \
|
||||
&& setupPublicFile "check.html" \
|
||||
&& setupPublicFile "logo.png" \
|
||||
&& exit 0
|
||||
|
||||
exit 1
|
||||
25
script/monitor/setupServiceProvidingHost.sh
Executable file
25
script/monitor/setupServiceProvidingHost.sh
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
[ "$(id -u)" != "0" ] \
|
||||
&& sudo "${0}" \
|
||||
&& exit 0
|
||||
|
||||
|
||||
|
||||
_SETUP="$(readlink -f "${0}" 2> /dev/null)"
|
||||
|
||||
# Folders always ends with an tailing '/'
|
||||
_CIS_ROOT="${_SETUP%%/script/monitor/*}/" #Removes longest matching pattern '/script/monitor/*' from the end
|
||||
_CORE_SCRIPTS="${_CIS_ROOT:?"Missing CIS_ROOT"}core/"
|
||||
_DOMAIN="$("${_CIS_ROOT:?"Missing CIS_ROOT"}core/printOwnDomain.sh")"
|
||||
_DEFINITIONS="${_CIS_ROOT:?"Missing CIS_ROOT"}definitions/${_DOMAIN:?"Missing DOMAIN"}/"
|
||||
|
||||
|
||||
|
||||
echo "Setup the user and permission to enable the monitoring this host ... " \
|
||||
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}addNormalUser.sh" monitoring \
|
||||
&& echo \
|
||||
&& "${_CORE_SCRIPTS:?"Missing CORE_SCRIPTS"}defineAuthorizedKeysOfUser.sh" "${_DEFINITIONS}" monitoring \
|
||||
&& exit 0
|
||||
|
||||
exit 1
|
||||
Reference in New Issue
Block a user