Update monitor.service

Added check before the script runs / loops to see what services are installed.
This prevents services that are not installed to show up as offline services and ports.

Added Nginx service check if Homer is installed with the corresponding port.

Made some changes for readability.

Fixed copy/paste error where all services had the subtitle broker behind them.

Set sleep timer to 30s.
This commit is contained in:
Beeranco 2023-08-24 19:20:44 +02:00 committed by GitHub
parent fbcf9d78bc
commit 26d566d6e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,19 @@ RED='\033[1;31m'
RESET='\033[0m' RESET='\033[0m'
KERNEL=`uname -r` KERNEL=`uname -r`
if grep -q Homer "/etc/installedmodules"; then
NGINX=yes
fi
if grep -q Domoticz "/etc/installedmodules"; then
DOMOTICZ=yes
fi
if grep -q Node-RED "/etc/installedmodules"; then
NODERED=yes
fi
if grep -q Zigbee2MQTT "/etc/installedmodules"; then
ZB2MQTT=yes
fi
##--------------## ##--------------##
# Start loop # # Start loop #
@ -26,6 +39,7 @@ systemctl is-active --quiet domoticz.service && Domo=Online || Domo=Offline
systemctl is-active --quiet nodered.service && Node=Online || Node=Offline systemctl is-active --quiet nodered.service && Node=Online || Node=Offline
systemctl is-active --quiet zigbee2mqtt.service && ZB2M=Online || ZB2M=Offline systemctl is-active --quiet zigbee2mqtt.service && ZB2M=Online || ZB2M=Offline
systemctl is-active --quiet mosquitto.service && MQTT=Online || MQTT=Offline systemctl is-active --quiet mosquitto.service && MQTT=Online || MQTT=Offline
systemctl is-active --quiet nginx.service && NGIX=Online || NGIX=Offline
##----------------## ##----------------##
@ -36,54 +50,70 @@ if [[ ! -z "$DATE" ]] ; then
echo $DATE echo $DATE
echo "" echo ""
fi fi
echo "OS status:" echo "OS status:"
if [[ -z "$IP" ]] ; then if [[ -z "$IP" ]] ; then
echo -e "My IP is: ${RED}unavailable${RESET}" echo -e "My IP is: ${RED}unavailable${RESET}"
else else
echo "My IP is: $IP" echo "My IP is: $IP"
fi fi
echo "CPU usage: $CPUstat" echo "CPU usage: $CPUstat"
echo "RAM usage: $MEMstat" echo "RAM usage: $MEMstat"
if [[ $UFW == *in* ]] || [[ -z "$UFW" ]] ; then if [[ $UFW == *in* ]] || [[ -z "$UFW" ]] ; then
echo -e "Firewall: ${RED}inactive${RESET}" echo -e "Firewall: ${RED}inactive${RESET}"
else else
echo -e "Firewall: ${GREEN}active${RESET}" echo -e "Firewall: ${GREEN}active${RESET}"
fi fi
echo "Kernel $KERNEL" echo "Kernel $KERNEL"
echo ""
echo ""
if [[ ! -z "$IP" ]]; then if [[ ! -z "$IP" ]]; then
echo "Services and Ports:" echo "Services and Ports:"
else else
echo "Services:" echo "Services:"
fi fi
if [[ $MQTT == "Online" ]] && [[ ! -z "$IP" ]]; then if [[ $NGINX == "yes" ]]; then
echo -e "MQTT broker: ${GREEN}online${RESET} @1883" if [[ $NGIX == "Online" ]] && [[ ! -z "$IP" ]]; then
elif [[ $MQTT == "Online" ]]; then echo -e "Nginx: ${GREEN}online${RESET} @80"
echo -e "MQTT broker: ${GREEN}online${RESET}" elif [[ $MQTT == "Online" ]]; then
else echo -e "Nginx: ${GREEN}online${RESET}"
echo -e "MQTT broker: ${RED}offline${RESET}" else
echo -e "Nginx: ${RED}offline${RESET}"
fi
fi fi
if [[ $Domo == "Online" ]] && [[ ! -z "$IP" ]]; then if [[ $DOMOTICZ == "yes" ]]; then
echo -e "Domoticz broker: ${GREEN}online${RESET} @8080" if [[ $Domo == "Online" ]] && [[ ! -z "$IP" ]]; then
elif [[ $Domo == "Online" ]]; then echo -e "Domoticz: ${GREEN}online${RESET} @8080"
echo -e "Domoticz broker: ${GREEN}online${RESET}" elif [[ $Domo == "Online" ]]; then
else echo -e "Domoticz: ${GREEN}online${RESET}"
echo -e "Domoticz broker: ${RED}offline${RESET}" else
echo -e "Domoticz: ${RED}offline${RESET}"
fi
fi fi
if [[ $Node == "Online" ]] && [[ ! -z "$IP" ]]; then if [[ $NODERED == "yes" ]] || [[ $ZB2MQTT == "yes" ]]; then
echo -e "Node-RED broker: ${GREEN}online${RESET} @1880" if [[ $MQTT == "Online" ]] && [[ ! -z "$IP" ]]; then
elif [[ $Node == "Online" ]]; then echo -e "MQTT broker: ${GREEN}online${RESET} @1883"
echo -e "Node-RED broker: ${GREEN}online${RESET}" elif [[ $MQTT == "Online" ]]; then
else echo -e "MQTT broker: ${GREEN}online${RESET}"
echo -e "Node-RED broker: ${RED}offline${RESET}" else
echo -e "MQTT broker: ${RED}offline${RESET}"
fi
fi fi
if [[ $ZB2M == "Online" ]] && [[ ! -z "$IP" ]]; then if [[ $NODERED == "yes" ]]; then
echo -e "Zigbee2MQTT broker: ${GREEN}online${RESET} @5002" if [[ $Node == "Online" ]] && [[ ! -z "$IP" ]]; then
elif [[ $ZB2M == "Online" ]]; then echo -e "Node-RED: ${GREEN}online${RESET} @1880"
echo -e "Zigbee2MQTT broker: ${GREEN}online${RESET}" elif [[ $Node == "Online" ]]; then
else echo -e "Node-RED: ${GREEN}online${RESET}"
echo -e "Zigbee2MQTT broker: ${RED}offline${RESET}" else
echo -e "Node-RED: ${RED}offline${RESET}"
fi
fi
if [[ $ZB2MQTT == "yes" ]]; then
if [[ $ZB2M == "Online" ]] && [[ ! -z "$IP" ]]; then
echo -e "Zigbee2MQTT: ${GREEN}online${RESET} @5002"
elif [[ $ZB2M == "Online" ]]; then
echo -e "Zigbee2MQTT: ${GREEN}online${RESET}"
else
echo -e "Zigbee2MQTT: ${RED}offline${RESET}"
fi
fi fi
@ -102,5 +132,5 @@ UFW=`ufw status`
# Restart loop # # Restart loop #
##----------------## ##----------------##
sleep 15 sleep 30
done done