#!/bin/bash # # Nagios plugin to check paste version # # Author : Obitanz # Date : 18 Jul 2023 # OK=0 WARNING=1 CRITICAL=2 UNKNOWN=3 function usage { echo "Usage : $0" echo "This script check if minetest services are UP (except test instance)" echo " and if UDP ports are listening" result=${UNKNOWN} } if [ "$#" -ne 0 ]; then usage else nb_problem=0 for instance in $(ls -1d /srv/minetest.chapril.org/instances/* | grep -v "30000-test"); do shortname=$(echo ${instance} | cut -d "/" -f 5) instance_port=$(echo ${shortname} | cut -d "-" -f 1) is_active=$(systemctl is-active minetest-server@${shortname}.service) check_if_port_is_listening="netstat -l | grep udp | grep ${instance_port} > /dev/null 2>&1" eval $check_if_port_is_listening port_is_listening=$? if [ "${is_active}" = "active" ]; then result_msg="${result_msg}\n${shortname} service is UP" else result_msg="${result_msg}\n${shortname} service is DOWN" ((nb_problem++)) fi if [ ${port_is_listening} -eq 0 ]; then result_msg="${result_msg}\n${shortname}'s port (${instance_port}) is listening" else result_msg="${result_msg}\n${shortname}'s port (${instance_port}) has a problem (not listening)" ((nb_problem++)) fi done if [ ${nb_problem} -eq 0 ]; then echo "OK - all minetest services are UP and all minetest ports are listening" result=${OK} elif [ ${nb_problem} -eq 1 ]; then echo -e "WARNING - there is one problem with minetest services or ports${result_msg}" result=${WARNING} elif [ ${nb_problem} -ge 2 ]; then echo -e "CRITICAL - there are at least two problems with minetest services or ports${result_msg}" result=${CRITICAL} else echo "UNKNOWN - script failed" result=${UNKNOWN} fi fi exit $result