icinga2-checks/check_nfs_shares.sh

52 lines
1.2 KiB
Bash
Raw Normal View History

#!/bin/bash
print_help() {
2024-06-22 20:02:36 -06:00
echo "Usage: $0 -h <host> -s <shares>"
echo "Checks if the specified NFS shares are exported on the given host."
echo ""
2024-06-22 20:02:36 -06:00
echo "-h The IP address or hostname of the NFS server."
echo "-s 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
}
2024-06-22 20:02:36 -06:00
if [ "$#" -ne 4 ] || [ "$1" == "-help" ] || [ "$1" == "--help" ]; then
print_help
fi
2024-06-22 20:02:36 -06:00
while getopts "h:s:" opt; do
case ${opt} in
h )
host=$OPTARG
;;
s )
shares=$OPTARG
;;
\? )
print_help
;;
esac
done
share_count=0
2024-06-22 20:02:36 -06:00
all_ok=true
IFS=',' read -r -a share_array <<< "$shares"
for share in "${share_array[@]}"; do
output=$(showmount -e $host | grep $share)
if [[ $output != *"$share"* ]]; then
echo "CRITICAL - $share is not exported on $host"
exit 2
fi
share_count=$((share_count+1))
done
if $all_ok; then
echo "OK - All specified shares are exported on $host | share_count=$share_count"
fi
exit 0