#!/bin/bash log_host="127.0.0.1" log_port="514" log_path=$(systemctl cat hc-safe-logger|grep -i "LOG_DIRECTORY"|awk -F'=' '{gsub(/"/,"",$3); print $3}') [[ -z "${log_path}" ]] && log_path="/var/log/nc_audit/hc-safe-logger" # check process if ! (pidof hc-safe-logger > /dev/null 2>&1); then echo "CRITICAL! hc-safe-logger: Process doesn't exist." exit 2 fi # check connection if ! (nc -zu "${log_host}" "${log_port}"); then echo "CRITICAL! hc-safe-logger: Connection refused." exit 2 fi # check new records logger --server "${log_host}" --port "${log_port}" -p local0.info "check hc-safe-logger" -t "HEALTH_CHECK" && sleep 3 files=$(find "${log_path}" -mmin -59 -type f) if [[ -z "${files}" ]]; then echo "CRITICAL! hc-safe-logger: No records in log from last hour." exit 2 fi # all check passed echo "OK. hc-safe-logger: Healthy." exit 0