diff --git a/nagios/files/check_smb b/nagios/files/check_smb new file mode 100755 index 0000000..82f75b7 --- /dev/null +++ b/nagios/files/check_smb @@ -0,0 +1,39 @@ +#!/usr/bin/perl -w + +use strict; +use Getopt::Long qw(:config no_ignore_case); +use Time::HiRes qw/ time sleep /; + +sub usage() { + print "Usage: check_smb -H \n" +} + +my $host; +my $result = GetOptions( + "H|host=s" => \$host, + ); + +if (!$host) { + usage(); + exit 3; +} + +my ($start, $end, $time, @output, $status); + +$start = time; +@output = `/usr/bin/smbclient -N -L '$host' 2>&1`; +$status = $?; +$end = time; + +$time = sprintf("%.3f", $end - $start); + +if ($status != 0) { + print "SMB CRITICAL: " . join(" ", @output); + exit(2); +} else { + foreach(@output) { + next unless /^Domain=.*/; + print "SMB OK: ${time} seconds response time. $_"; + exit(0); + } +} diff --git a/nagios/files/check_wins b/nagios/files/check_wins new file mode 100755 index 0000000..af0b11f --- /dev/null +++ b/nagios/files/check_wins @@ -0,0 +1,41 @@ +#!/usr/bin/perl -w + +use strict; +use Getopt::Long qw(:config no_ignore_case); +use Time::HiRes qw/ time sleep /; + +sub usage() { + print "Usage: check_wins -H -q [-t ]\n" +} + +my ($host, $query, $type); +my $result = GetOptions( + "H|host=s" => \$host, + "q|query=s" => \$query, + "t|type=s" => \$type, + ); + +if (!$type) { + $type = "00" +} +if (!$host || !$query) { + usage(); + exit 3; +} + +my ($start, $end, $time); + +$start = time; +$result = `/usr/bin/nmblookup -R -U "$host" "$query#$type"`; +$end = time; + +$time = sprintf("%.3f", $end - $start); +$result =~ s/\n/: /; + +if ($result =~ /name_query failed/) { + print "WINS CRITICAL: ${result}"; + exit(2); +} else { + print "WINS OK: ${time} seconds response time. ${result}"; + exit(0); +} diff --git a/nagios/files/commands.cfg b/nagios/files/commands.cfg index aea1223..7e31091 100644 --- a/nagios/files/commands.cfg +++ b/nagios/files/commands.cfg @@ -162,6 +162,13 @@ define command{ } +# 'check_smb' command definition +define command{ + command_name check_smb + command_line $USER1$/check_smb -H $HOSTADDRESS$ + } + + # 'check_ssh' command definition define command{ command_name check_ssh @@ -169,6 +176,13 @@ define command{ } +# 'check_wins' command definition +define command{ + command_name check_wins + command_line $USER1$/check_wins -H $HOSTADDRESS$ -q $ARG1$ + } + + # 'check_dig' command definition define command{ command_name check_dig diff --git a/nagios/manifests/init.pp b/nagios/manifests/init.pp index a2897b5..bc9c95a 100644 --- a/nagios/manifests/init.pp +++ b/nagios/manifests/init.pp @@ -275,6 +275,26 @@ class nagios::server::manual inherits nagios::common { notify => Service["nagios"], } + require samba::client + file { "${nagios::common::libdir}/check_wins": + ensure => present, + mode => "0755", + owner => "root", + group => "root", + source => "puppet:///modules/nagios/check_wins", + require => Package["nagios"], + before => Service["nagios"], + } + file { "${nagios::common::libdir}/check_smb": + ensure => present, + mode => "0755", + owner => "root", + group => "root", + source => "puppet:///modules/nagios/check_smb", + require => Package["nagios"], + before => Service["nagios"], + } + } diff --git a/nagios/manifests/target.pp b/nagios/manifests/target.pp index 66aae74..7907e34 100644 --- a/nagios/manifests/target.pp +++ b/nagios/manifests/target.pp @@ -198,6 +198,18 @@ class nagios::target::pop3s inherits nagios::target { } +# Configure SMB service target. +# +class nagios::target::smb inherits nagios::target { + + @@nagios::service { "${::homename}_smb": + command => "check_smb", + description => "SMB", + } + +} + + # Configure smtp service target. # class nagios::target::smtp inherits nagios::target { @@ -263,6 +275,27 @@ define nagios::target::tcp($port, $description=undef) { } +# Configure WINS service target. +# +# === Parameters: +# +# $query: +# Address to query from WINS. Defaults to $homename. +# +# $type: +# Record type to query. Defaults to 00 (workstation service). +# For different types see: http://support.microsoft.com/kb/830578 +# +class nagios::target::wins($query="${::homename}", $type="00") inherits nagios::target { + + @@nagios::service { "${::homename}_wins": + command => "check_wins!${query} -t ${type}", + description => "WINS", + } + +} + + # Configure nagios nrpe target. # # === Global variables