diff --git a/xymon/xymon.procs.alert.sh b/xymon/xymon.procs.alert.sh index 21a332c..84be298 100755 --- a/xymon/xymon.procs.alert.sh +++ b/xymon/xymon.procs.alert.sh @@ -8,16 +8,16 @@ BBHOSTNAME="HOST.DOMAIN.ORG" BBSVCNAME="procs" BBALPHAMSG="HOST.DOMAIN.ORG:procs red [729848] red Fri Aug 10 15:35:26 CEST 2018 - Processes NOT ok -&green journald (found 1, req. 1 or more) -&green logind (found 1, req. 1 or more) -&green CRON (found 1, req. 1 or more) -&yellow ATD (found 0, req. 1 or more) -&green MTA-Stretch (found 2, req. 1 or more) -&green SSHD (found 3, req. 1 or more) -&green SSSD (found 1, req. 1 or more) +&green systemd-journald (found 1, req. between 1 and 1) +&green systemd-logind (found 1, req. between 1 and 1) +&green CRON (found 1, req. between 1 and 999) +&yellow ATD (found 1, req. between 1 and 999) +&green MTA-Stretch (found 1, req. between 1 and 1) +&green SSHD (found 3, req. between 1 and 20) +&green SSSD (found 1, req. between 1 and 1) &red Fail2Ban (found 0, req. 1 or more) -&green tftpd (found 1, req. between 1 and 1) -&green ARPwatch (found 1, req. between 1 and 1) +&red tftpd-hpa (found 0, req. between 1 and 1) +&yellow ARPwatch (found 0, req. between 1 and 1) PID PPID USER STARTED S PRI %CPU TIME %MEM RSZ VSZ CMD 1 0 root Aug 02 S 19 0.0 00:00:03 0.5 5492 217412 /sbin/init @@ -63,31 +63,43 @@ red Fri Aug 10 15:35:26 CEST 2018 - Processes NOT ok 595044 595038 xymon 15:35:26 S 19 0.0 00:00:00 0.4 5188 18300 \\_ /usr/bin/perl -w /usr/lib/xymon/client/ext/apt 595081 595044 xymon 15:35:26 R 19 0.0 00:00:00 3.9 40956 70040 \\_ apt-cache policy acl adduser apt apt-listchanges apt-transport-https apt-utils aptitude aptitude-common arpwatch at base-files base-passwd bash bash-completion bind9-host binutils bsd-mailx bsdmainutils bsdutils bzip2 ca-certificates coreutils cpio cpp cpp-6 cracklib-runtime cron curl dash dbus dctrl-tools debconf debconf-i18n debian-archive-keyring debian-faq debian-goodies debianutils debsecan debsums dh-python diffutils dirmngr distro-info-data dmidecode dmsetup doc-debian dpkg e2fslibs:amd64 e2fsprogs ed etckeeper fail2ban file findutils fontconfig-config fonts-dejavu-core fonts-font-awesome fping gcc-6-base:amd64 gettext-base git git-man gnupg gnupg-agent gnutls-bin gpgv grep groff-base gzip hobbit-plugins hostname htop iftop ifupdown init init-system-helpers DOMAINoute2 iputils-ping isc-dhcp-client isc-dhcp-common kmod krb5-locales less libacl1:amd64 libapparmor1:amd64 libapt-inst2.0:amd64 libapt-pkg5.0:amd64 libasprintf0v5:amd64 libassuan0:amd64 libattr1:amd64 libaudit-common libaudit1:amd64 libavahi-client3:amd64 libavahi-common-data:amd64 libavahi-common3:amd64 libbasicobjects0:amd64 libbind9-140:amd64 libblkid1:amd64 libboost-filesystem1.62.0:amd64 libboost-iostreams1.62.0:amd64 libboost-system1.62.0:amd64 libbsd0:amd64 libbz2-1.0:amd64 libc-ares2:amd64 libc-bin libc-l10n libc6:amd64 libcap-ng0:amd64 libcap2-bin libcap2:amd64 libclass-isa-perl libcollection4:amd64 libcomerr2:amd64 libcrack2:amd64 libcryptsetup4:amd64 libcups2:amd64 libcurl3-gnutls:amd64 libcurl3:amd64 libcwidget3v5:amd64 libdb5.3:amd64 libdbus-1-3:amd64 libdebconfclient0:amd64 libdevmapper1.02.1:amd64 libdhash1:amd64 libdns-export162 libdns162:amd64 libdpkg-perl libdrm2:amd64 libedit2:amd64 libelf1:amd64 liberror-perl libestr0 libev4 libevent-2.0-5:amd64 libexpat1:amd64 libfas" -temp_dir=$(mktemp -d -t xymon-alert-XXXXXX.tmp) +temp_dir=$(mktemp -d -t xymon-procs-alert-XXXXXX.tmp) +debug_stdout="${temp_dir}/debug.stdout" +debug_stderr="${temp_dir}/debug.stderr" service_list="${temp_dir}/services.error.list" # }}} -[ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : ${BBHOSTNAME} — ${BBSVCNAME} error" +# Create log files +touch "${debug_stdout}" "${debug_stderr}" -# Temp dir for this alert -if [ ! -d "${temp_dir}" ] ; then - mkdir -p -- "${temp_dir}" - [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : ${temp_dir} — created." +# Manage only procs probe {{{ +if [ "${BBSVCNAME}" = "procs" ]; then + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : ${BBHOSTNAME} — ${BBSVCNAME} error" >> "${debug_stdout}" +else + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : ${BBHOSTNAME} — ${BBSVCNAME} probe is not managed." >> "${debug_stderr}" + [ "${DEBUG}" -eq "0" ] || rm -rf -- "${temp_dir}" + exit 0 fi +# }}} # Get the list of processes with an error echo "${BBALPHAMSG}" | grep -E "&(red|yellow)" | cut -d" " -f2 | tr '[:upper:]' '[:lower:]' > "${service_list}" # If any error on a process if [ -s "${service_list}" ]; then - [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : process list — Some processes seems to be in error." + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : process list — Some processes seems to be in error." >> "${debug_stdout}" while IFS= read -r process; do - [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : while process loop — ${process} service need to be restarted." + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : while process loop — ${process} service need to be restarted." >> "${debug_stdout}" done < "${service_list}" else - [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : process list — No error on any process." + [ "${DEBUG}" -eq "0" ] && printf '\e[1;35m%-6s\e[m\n' "DEBUG : process list — No error on any process." >> "${debug_stdout}" fi -rm -rf -- "${temp_dir}" +# Remove empty error file +[ -s "${debug_stderr}" ] || rm -f "${debug_stderr}" + +# Remove temp_dir if DEBUG is disable +[ "${DEBUG}" -eq "0" ] || rm -rf -- "${temp_dir}" + exit 0