Nagios check_smb_status.sh
Posted: Mon Aug 29, 2022 6:03 am
I am having a little issue here with this plugin. When run locally on the samba server machine it works fine:
./check_smb_status.sh
Total Users/Process:21 Total Machines:16 Total Files:67 |Total Users/Process=21 Total Machines=16 Total Files=67
But when run with NRPE plugin from the nagios server it's output is not correct:
./check_nrpe -H -t 500 -c check_smb_status
Total Users/Process:0 Total Machines:0 Total Files:68 |Total Users/Process=0 Total Machines=0 Total Files=67
Here is the source of check_smb_status.sh:
#!/bin/bash
#
# Program : check_smb_status
# :
# Purpose : Nagios plugin to return the number of user/processes into a smb
# : server, total machines connected and the number of files open.
# :
# Parameters : --help
# : --version
# :
# Returns : Standard Nagios status_* codes as defined in utils.sh
# :
# Notes :
#============:==============================================================
# 1.0 : may/08/2011
#
PROGPATH=`/bin/echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`/bin/echo '$Revision: 1.0 $' | /bin/sed -e 's/[^0-9.]//g'`
SMBSTATUS_P="/tmp/smbstatus_p"
SMBSTATUS_L="/tmp/smbstatus_L"
/usr/bin/smbstatus -p > $SMBSTATUS_P 2> /dev/null
/usr/bin/smbstatus -L > $SMBSTATUS_L 2> /dev/null
. $PROGPATH/utils.sh
print_usage() {
/bin/echo "Usage: $PROGNAME --help"
/bin/echo "Usage: $PROGNAME --version"
}
print_help() {
print_revision $PROGNAME $REVISION
/bin/echo ""
print_usage
/bin/echo ""
/bin/echo "Samba status check."
/bin/echo ""
support
}
if [ $# -gt 1 ]; then
print_usage
exit $STATE_UNKNOWN
fi
exitstatus=$STATE_WARNING
while test -n "$1"; do
case "$1" in
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
--version)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-V)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
*)
echo "Unknown argument: $1"
print_usage
exit $STATE_UNKNOWN
;;
esac
shift
done
total_usersProcess=$(/bin/egrep "^([0-9]| +[0-9])" $SMBSTATUS_P | wc -l)
total_files=$(/bin/egrep "^([0-9]| +[0-9])" $SMBSTATUS_L | wc -l)
total_machines=$(/bin/egrep "^([0-9]| +[0-9])" $SMBSTATUS_P | awk '{print $5}' | sort -u | wc -l)
/bin/echo "Total Users/Process:$total_usersProcess Total Machines:$total_machines Total Files:$total_files |Total Users/Process=$total_usersProcess Total Machines=$total_machines Total Files=$total_files"
/bin/rm -f $SMBSTATUS_P omegle shagle voojio $SMBSTATUS_L
exit $STATE_OK
./check_smb_status.sh
Total Users/Process:21 Total Machines:16 Total Files:67 |Total Users/Process=21 Total Machines=16 Total Files=67
But when run with NRPE plugin from the nagios server it's output is not correct:
./check_nrpe -H -t 500 -c check_smb_status
Total Users/Process:0 Total Machines:0 Total Files:68 |Total Users/Process=0 Total Machines=0 Total Files=67
Here is the source of check_smb_status.sh:
#!/bin/bash
#
# Program : check_smb_status
# :
# Purpose : Nagios plugin to return the number of user/processes into a smb
# : server, total machines connected and the number of files open.
# :
# Parameters : --help
# : --version
# :
# Returns : Standard Nagios status_* codes as defined in utils.sh
# :
# Notes :
#============:==============================================================
# 1.0 : may/08/2011
#
PROGPATH=`/bin/echo $0 | /bin/sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`/bin/echo '$Revision: 1.0 $' | /bin/sed -e 's/[^0-9.]//g'`
SMBSTATUS_P="/tmp/smbstatus_p"
SMBSTATUS_L="/tmp/smbstatus_L"
/usr/bin/smbstatus -p > $SMBSTATUS_P 2> /dev/null
/usr/bin/smbstatus -L > $SMBSTATUS_L 2> /dev/null
. $PROGPATH/utils.sh
print_usage() {
/bin/echo "Usage: $PROGNAME --help"
/bin/echo "Usage: $PROGNAME --version"
}
print_help() {
print_revision $PROGNAME $REVISION
/bin/echo ""
print_usage
/bin/echo ""
/bin/echo "Samba status check."
/bin/echo ""
support
}
if [ $# -gt 1 ]; then
print_usage
exit $STATE_UNKNOWN
fi
exitstatus=$STATE_WARNING
while test -n "$1"; do
case "$1" in
--help)
print_help
exit $STATE_OK
;;
-h)
print_help
exit $STATE_OK
;;
--version)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-V)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
*)
echo "Unknown argument: $1"
print_usage
exit $STATE_UNKNOWN
;;
esac
shift
done
total_usersProcess=$(/bin/egrep "^([0-9]| +[0-9])" $SMBSTATUS_P | wc -l)
total_files=$(/bin/egrep "^([0-9]| +[0-9])" $SMBSTATUS_L | wc -l)
total_machines=$(/bin/egrep "^([0-9]| +[0-9])" $SMBSTATUS_P | awk '{print $5}' | sort -u | wc -l)
/bin/echo "Total Users/Process:$total_usersProcess Total Machines:$total_machines Total Files:$total_files |Total Users/Process=$total_usersProcess Total Machines=$total_machines Total Files=$total_files"
/bin/rm -f $SMBSTATUS_P omegle shagle voojio $SMBSTATUS_L
exit $STATE_OK