Files
NodeMgmt/defaults.inc
2023-07-03 22:14:27 -05:00

125 lines
2.9 KiB
PHP
Executable File

VERS='4.7.160-07032023'
noheader=' service status-check nightlyrephp7.3-fpm,new backup report check checkcerts gitea update-nodes copynpmcerts singleservercheck update-dyndns '
CERT_DAEMON='/snap/bin/certbot'
FOLDER=/opt/idssys/nodemgmt
SCRIPT=${FOLDER}/nodemgmt-scripts.sh
TMPFOLDER=${FOLDER}/.tmp
LOGFOLDER=${FOLDER}/logs
LOGFILE=${LOGFOLDER}/logfile
RENOTIFY=1800
[ ! -d ${TMPFOLDER} ] && mkdir ${TMPFOLDER}
[ ! -d ${LOGFOLDER} ] && mkdir ${LOGFOLDER}
declare -i errtime
NM_SRVCOPT=(start stop restart reload enable disable)
if [ -f ${FOLDER}/defaults.local.inc ]; then
source ${FOLDER}/defaults.local.inc
IFS=,
LOCAL_SERVICES=(${LOCAL_SERVICES})
WEB_DOCKER=(${WEBDOCKER})
LB_DOCKER=(${LBDOCKER})
WM_DOCKER=(${WMDOCKER})
PW_DOCKER=(${PWDOCKER})
WEB_SINGLESRVR_SERVICES=(${WEB_SINGLESRVRSERVICES})
WEB_SINGLESRVR_DOCKERS=(${WEB_SINGLESRVRDOCKERS})
declare -a NODE_TYPES
for nmtype in "${!NM_HOSTS[@]}"; do
NODE_TYPES+=(${nmtype})
done
for ntype in "${NODE_TYPES[@]}"; do
arr ${ntype}_HOSTS
arr ${ntype}_SERVICES_CHECK
var=(${NM_HOSTS[${ntype}]})
for value in "${var[@]}"; do
arr_insert ${ntype}_HOSTS $value
done
var=(${NM_SERVICES_CHECK[${ntype}]})
for value in "${var[@]}"; do
arr_insert ${ntype}_SERVICES_CHECK $value
done
done
unset IFS
fi
echo "HERE: "
# arr_get ${ntype}_HOSTS
for test in "${MYSQL_HOSTS[@]}"; do
echo $test
done
GET-CHECKCERT-DOMAINS(){
declare -A CHECKCERT_DOMAINS
IFS=$'\n'
for LINE in `egrep -v '(^#|^$)' ${FOLDER}/ssl-cert-check/ssldomains`; do
HOST=${LINE%% *}
PORT=${LINE#* }
IFS=" "
CHECKCERT_DOMAINS[${HOST}]=${PORT}
done
unset IFS
}
DISP_HEADER(){
declare -i cw; declare -i spc1; declare -i c
if [ "$1" = true ]; then
clear
fi
echo
echo -e "${idsCL[LightGreen]} NodeMgmt - Node Monitoring & Management${idsCL[Default]} ${idsCL[DarkGray]}(ver-${VERS})${idsCL[Default]}"
DIVIDER . lightGreen
echo
}
CERT-CHECK(){
TARGET="mysite.example.net";
RECIPIENT="hostmaster@mysite.example.net";
DAYS=7;
echo "checking if $TARGET expires in less than $DAYS days";
expirationdate=$(date -d "$(: | openssl s_client -connect $TARGET:443 -servername $TARGET 2>/dev/null \
| openssl x509 -text \
| grep 'Not After' \
|awk '{print $4,$5,$7}')" '+%s');
in7days=$(($(date +%s) + (86400*$DAYS)));
if [ $in7days -gt $expirationdate ]; then
echo "KO - Certificate for $TARGET expires in less than $DAYS days, on $(date -d @$expirationdate '+%Y-%m-%d')" \
| mail -s "Certificate expiration warning for $TARGET" $RECIPIENT ;
else
echo "OK - Certificate expires on $expirationdate";
fi
}
SENDNOTICE(){
[ "${PUSHOVER_APP_TOKEN}" != "" ] && PUSH_TO_MOBILE "${2}
$(date)" "${1}" ${3} &
[ "${EMAIL_NOTICE}" != "" ] && echo -e "${1}\n\n$(date)" | mail -s "${2}" ${EMAIL_NOTICE}
}