add check_nfs_shares, adjust level on check_systemd_timer

This commit is contained in:
Cyberes 2024-06-22 19:58:00 -06:00
parent f8c436d5e0
commit 1a4f3f5ffd
2 changed files with 51 additions and 1 deletions

50
check_nfs_shares.sh Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
# Function to print help
print_help() {
echo "Usage: $0 <host> <shares>"
echo "Checks if the specified NFS shares are exported on the given host."
echo ""
echo "<host> The IP address or hostname of the NFS server."
echo "<shares> 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 <host>'"
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

View File

@ -117,7 +117,7 @@ def check_timer(timer_name):
else: else:
quit_check(f'{timer_name} is not active.', nagios.STATE_CRIT) quit_check(f'{timer_name} is not active.', nagios.STATE_CRIT)
except dbus.exceptions.DBusException: 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__': if __name__ == '__main__':