From 1a4f3f5ffdb6355d3a55d093189f0e1df94fb7a8 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Sat, 22 Jun 2024 19:58:00 -0600 Subject: [PATCH] add check_nfs_shares, adjust level on check_systemd_timer --- check_nfs_shares.sh | 50 ++++++++++++++++++++++++++++++++++++++++++ check_systemd_timer.py | 2 +- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100755 check_nfs_shares.sh diff --git a/check_nfs_shares.sh b/check_nfs_shares.sh new file mode 100755 index 0000000..9c0e019 --- /dev/null +++ b/check_nfs_shares.sh @@ -0,0 +1,50 @@ +#!/bin/bash + +# Function to print help +print_help() { + echo "Usage: $0 " + echo "Checks if the specified NFS shares are exported on the given host." + echo "" + echo " The IP address or hostname of the NFS server." + echo " A comma-separated list of NFS shares to check. For example: '/mnt/test,/mnt/export'" + echo "" + echo "You can list the exported shares on an NFS server using the command 'showmount -e '" + echo "This script assumes that 'showmount' is installed on the system where it is run." + exit 1 +} + +# Check if help is requested or the correct number of arguments is provided +if [ "$#" -ne 2 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + print_help +fi + +# Assign arguments to variables +host=$1 +shares=$2 +share_count=0 + +# Convert comma-separated shares into an array +IFS=',' read -r -a share_array <<< "$shares" + +# Flag to track if all shares are exported +all_ok=true + +# Iterate over each share +for share in "${share_array[@]}"; do + # Use showmount to check if the share is exported + output=$(showmount -e $host | grep $share) + + # Check if the share is found in the output + if [[ $output != *"$share"* ]]; then + echo "CRITICAL - $share is not exported on $host" + exit 2 + fi + share_count=$((share_count+1)) +done + +# Print final status +if $all_ok; then + echo "OK - All specified shares are exported on $host | share_count=$share_count" +fi + +exit 0 diff --git a/check_systemd_timer.py b/check_systemd_timer.py index 63b6a80..8422f4a 100755 --- a/check_systemd_timer.py +++ b/check_systemd_timer.py @@ -117,7 +117,7 @@ def check_timer(timer_name): else: quit_check(f'{timer_name} is not active.', nagios.STATE_CRIT) except dbus.exceptions.DBusException: - quit_check(f'{timer_name} could not be found.', nagios.STATE_UNKNOWN) + quit_check(f'{timer_name} could not be found.', nagios.STATE_CRIT) if __name__ == '__main__':