check_smb.sh
changeset 0 6b1d52c756d5
equal deleted inserted replaced
-1:000000000000 0:6b1d52c756d5
       
     1 #!/bin/sh
       
     2 
       
     3 REVISION=0.1
       
     4 PROGNAME=$(/usr/bin/basename $0)
       
     5 
       
     6 STATE_OK=0
       
     7 STATE_WARNING=1
       
     8 STATE_CRITICAL=2
       
     9 STATE_UNKNOWN=3
       
    10 STATE_DEPENDENT=4
       
    11 
       
    12 print_revision() {
       
    13     echo "$1 v$2 (nagios-plugins 1.4.15)"
       
    14     echo "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute\ncopies of the plugins under the terms of the GNU General Public License.\nFor more information about these matters, see the file named COPYING.\n"
       
    15 }
       
    16 
       
    17 support() {
       
    18     echo "Send email to nagios-users@lists.sourceforge.net if you have questions\nregarding use of this software. To submit patches or suggest improvements,\nsend email to nagiosplug-devel@lists.sourceforge.net.\nPlease include version information with all correspondence (when possible,\nuse output from the --version option of the plugin itself).\n"
       
    19 }
       
    20 
       
    21 usage () {
       
    22     echo "\
       
    23 Nagios plugin to check if (anonymous) access to SMB on host works.
       
    24 
       
    25 Usage:
       
    26   $PROGNAME -H <host>
       
    27   $PROGNAME --help
       
    28   $PROGNAME --version
       
    29 "
       
    30 }
       
    31 
       
    32 help () {
       
    33     print_revision $PROGNAME $REVISION
       
    34     echo; usage; echo; support
       
    35 }
       
    36 
       
    37 if [ $# -lt 1 ] || [ $# -gt 2 ]; then
       
    38     usage
       
    39     exit $STATE_UNKNOWN
       
    40 fi
       
    41 
       
    42 while test -n "$1"; do
       
    43     case "$1" in
       
    44         --help | -h)
       
    45             help
       
    46             exit $STATE_OK;;
       
    47         --version | -V)
       
    48             print_revision $PROGNAME $REVISION
       
    49             exit $STATE_OK;;
       
    50         -H)
       
    51             shift
       
    52             host=$1;;
       
    53         *)
       
    54             usage; exit $STATE_UNKNOWN;;
       
    55     esac
       
    56     shift
       
    57 done
       
    58 
       
    59 stdout=$(/usr/bin/smbclient -U guest -N -L "$host" 2>&1)
       
    60 
       
    61 if [ $? -eq 0 ]; then
       
    62     header=$(echo "$stdout" | grep Server= | head -n 1)
       
    63     echo "OK $header"
       
    64     exit $STATE_OK
       
    65 else
       
    66     err=$(echo "$stdout" | head -n 1)
       
    67     echo "CRITICAL SMB anon access: $err"
       
    68     exit $STATE_CRITICAL
       
    69 fi