smb.monitor is a script for use with the mon package. It simply connects to a host and lists the shares to detect failures from name resolution or authentication.


To install the script simply download it to the mon scriptdir, usually set to '/usr/local/lib/mon/mon.d:/usr/lib/mon/mon.d'. Then add the settings for this to the file.


It configures like any other mon script, the specific parameters are -p and -u for password and username. A sample is provided below.

hostgroup smb_devices

watch smb_devices
  service smb
    interval 1m
    monitor smb.monitor -p secret -u jsmith
    period all_the_time: wd {Sun-Sat}
      alertafter 3 10m
      alert mail.alert someone@somewhere.tld


# Test SMB Connections using smbclient, you'll need Samba
#  Just tries to get a list of shares from the box
# For use with "mon".
# smb.monitor -p password -u username host1 [ hostN... ] 
#    Copyright (C) 2005, David Busby
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    GNU General Public License for more details.
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

exit 0 if (!@ARGV);

use Getopt::Std;
getopts ("p:u:");

# Samba Default
#my $resolve_order = "lmhosts hosts wins bcast"
my $resolve_order = 'wins bcast';
my $debug_level = 1;
my %bad;

# Check the hosts
foreach my $host (@ARGV)
  my $res = do
    my $x;
    my $cmd = "/usr/bin/smbclient -d $debug_level -L $host -R '$resolve_order' -U '$opt_u\%$opt_p' 2>&1";
    my $buf = `$cmd`;
    $x->{status} = $?;
    $x->{buffer} = $buf;
  if ($res->{status}!=0)
    $bad{$host} = $res;

# Write messages about the failures
foreach my $h (keys %bad)
  print "SMB FAILURE: $h $bad{$h}->{status} - $bad{$h}->{buffer}\n";

exit scalar(keys(%bad));

See Also

  • mon - The mon packages home page