Files
NodeMgmt/defaults.inc
2019-02-05 09:44:55 -06:00

79 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
VERS='1.02052019'
NODE_HOSTS=10.5.10.51,10.5.10.52,10.5.10.53
NODE_SERVICES=mysql,nginx,gitea,haproxy,keepalived,maxscale
CERT_DAEMON='/usr/bin/certbot'
FOLDER=/opt/idssys/nodemgmt
SCRIPT=${FOLDER}/nodemgmt-scripts.sh
IFS=,
NODE_HOSTS=(${NODE_HOSTS})
NODE_SERVICES=(${NODE_SERVICES})
LOCAL_SERVICES=(${LOCAL_SERVICES})
unset IFS
declare -A NM_SERVICES
NM_SERVICES['mysql']='MySQL'
NM_SERVICES['nginx']='NGINX'
NM_SERVICES['gogs']='Gogs'
NM_SERVICES['gitea']='Gitea'
NM_SERVICES['haproxy']='HAProxy'
NM_SERVICES['keepalived']='Keepalived'
NM_SERVICES['maxscale']='MaxScale'
NM_SERVICES['cmon']='CC-Controller'
NM_SERVICES['cmon-events']='CC-Events Manager'
NM_SERVICES['cmon-cloud']='CC-Cloud Daemon'
DISP_HEADER(){
if [ "$1" = true ]; then
clear
fi
echo ""
echo -e "${idsCL[Yellow]} NodeMgmt - Galera/NGINX Node Management${idsCL[Default]} ${idsCL[DarkGray]}(ver-${VERS})${idsCL[Default]}"
DIVIDER
if [ "$2" = true ]; then
echo -e "Node hostname: ${idsST[Bold]}${idsCL[LightCyan]}${NODE_HOSTNAME}${idsCL[Default]}${idsST[Reset]}"
if [ -z ${LOCAL_SERVICES+x} ]; then SERVICES=$( IFS=$','; echo "${NODE_SERVICES[*]}" )
else SERVICES=$( IFS=$','; echo "${LOCAL_SERVICES[*]}" )
fi
IFS=,; SERVICES2=(${SERVICES}); unset IFS
for srvc in "${SERVICES2[@]}"; do
if [[ "mysql,nginx,gitea,haproxy,keepalived,maxscale" = *"${srvc}"* ]]; then spc=" "; else spc=""; fi
echo -en "${NM_SERVICES[${srvc}]} $spc"
if [ $(pgrep ${srvc} | wc -l) -gt "0" ]; then
echo -e "${idsCL[Green]}Running${idsCL[Default]}"
else echo -e "${idsCL[Red]}Not Running${idsCL[Default]}"
fi
done
DIVIDER
fi
echo ""
}
DIVIDER(){
echo -e "${idsCL[Yellow]}-------------------------------------------------------------${idsCL[Default]}"
if [ "$1" = true ]; then
echo ""
fi
}
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
}