#!/usr/local/bin/perl # # bb-wms.pl - a Big Brother module to check the status of Windows Media Servers # # By: Simon McCorkindale NOSPAM akibageeks.com> # Version: 0.1 April 2005 # # This is a very simple script. All it does is try to connect to port 1755 # on the host machine and see if the port is open. Port 1755 is the default # port Windows Media Server runs on. You can change the port configuration # below where $wmsport is defined. I could get a bit more complicated and try # and implement some basic MMS protocol (the Windows Media Server streaming # protocol) commands but I didn't have the time when I hacked this script # together. # # INSTALLTION: # # 1. Place this script in $BBHOME/ext/ # 2. Edit $BBHOME/etc/bb-bbexttab and add the following line (w/out the #): # : : bb-wms.pl # 3. Restart Big Brother as the Big Brother user: # bb@foo$ $BBHOME/runbb.sh restart # # REQUIREMENTS: # # BigBrother.pm - a perl module with some functions to aid external Big Brother # modules written in Perl. Lots of Big Brother perl modules I came across said # they also required BigBrother.pm and that it was available on the site # http://www.deadcat.net/ but it was hard to find. Here's a link straight to it: # http://www.deadcat.net/1/BigBrother.pm # Place it in $BBHOME/ext/perl. # # I also included the functions read_hosts_file and build_hosts_array from Craig # Cook's fping.pl script. Kudos to him for making my job a little easier. # His script can also be found at http://www.deadcat.net/viewfile.php?fileid=661 # # Licence: Such a simple script like this doesn't even deserve a licence but # for what it's worth I'll stamp it with the famous official 3 letters GPL. # Do whatever ya like with this script in otherwords but share your work :-) # My variables use IO::Socket; my $timeout = 10; # timeout for attempting connection (in seconds) my $wmsport = 1755; # default port for Windows Media Server my $wmsservice = "wms"; # service name for this script used in bb-hosts my $greenstr = "Windows Media Server seems to be running on port $wmsport. Connection was established."; my $redstr = "Connection refused to port $wmsport (Windows Media Server port)."; # Get the hosts that are configured to have their WMS checked (Craig Cook's stuff) use lib $ENV{'BBHOME'}."/ext/perl/"; # Please point this at BigBrother.pm if not # already in your perl dir use BigBrother; my @all_hosts; my $hostsfile = $ENV{'BBHOME'}."/etc/bb-hosts"; my ($line, $ip, $hostname, $pound); my $line_num = 0; &read_hosts_file; &build_hosts_array; #################### # Start of my code # #################### foreach (@all_hosts) { my $sock = new IO::Socket::INET ( PeerAddr => $_->{hostname}, PeerPort => $wmsport, Timeout => $timeout, Proto => 'tcp', ); # report green back to BB if wms port is open, otherwise report red if ($sock) { # green BigBrother->Report($_->{hostname}, $wmsservice, "green", $greenstr); } else { # red BigBrother->Report($_->{hostname}, $wmsservice, "red", $redstr); } close($sock); exit; } ################################### # Craig Cook's fping.pl functions # ################################### sub read_hosts_file { open (HOSTS, "$hostsfile"); while ($line = ) { $line_num++; $line_with_row_number = join (' ', $line_num, $line); push @raw_hosts_file_array , $line_with_row_number; } close HOSTS; } # End sub read_hosts_file sub build_hosts_array { foreach my $line (@raw_hosts_file_array) { my %current_host ; chomp $line; ($line_num, $ip, $hostname, $pound, $services) = split /\s+/, $line, 5; next if ($ip !~ /^\d+/ ); $current_host{ip} = $ip; $current_host{hostname} = $hostname; if ($services eq "") { $services = undef; } $current_host{services} = $services; push @all_hosts, { %current_host } if $current_host{services} =~ /$wmsservice/i; } } # End sub build_hosts_array