1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#!/usr/bin/perl
#
# popup.alert - SMB popup (winpopup) alerts for mon
# version .03
# Copyright (C) 2001, Matthew Rechs - rechsm@hotmail.com
#
# popup.alert is based on the alert.template distributed by mon, which is
# Copyright (C) 1998, Jim Trocki
#
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# 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
#
# example alert line in mon.cf:
#
# alert popup.alert netbios-name
#
# where netbios-name is the name of the workstation (not the user)
# that you want to send the popup to
#
use Getopt::Std;
use Text::Wrap;
use Cwd;
getopts ("S:s:g:h:t:l:u");
@checkdirs = ('/usr/local/samba/bin/', '/usr/local/bin/', '/usr/bin/');
# Set this if you don't want popup.alert to find your smbclient for you
#$smbclient = '/path/to/smbclient';
while ($checkpath = shift @checkdirs && ! $smbclient) {
$check = $checkpath . 'smbclient';
if (-x $check) {
$smbclient = $check;
last ;
}
}
#
# Last ditch attempt to find smbclient
#
if (! $smbclient ) {
$smbclient = `which smbclient`; chomp $smbclient;
}
die("Couldn't find $smbclient - tried " . join(@checkdirs, ',') . ' and which') unless $smbclient;
$summary=<STDIN>;
chomp $summary;
while (<STDIN>) {
$details .= $_;
}
$summary = $opt_S if (defined $opt_S);
$ALERT = $opt_u ? "UPALERT" : "ALERT";
$t = localtime($opt_t);
($wday,$mon,$day,$tm) = split (/\s+/, $t);
$alerttext = "
ALERT $opt_g/$opt_s: $summary ($wday $mon $day $tm)
Group : $opt_g
Service : $opt_s
Time noticed : $t
Secs until next alert : $opt_l
Members : $opt_h
-------------------------------
$details ";
local $SIG{PIPE} = sub { die "pipe to smbclient was broken - $! $?"};
foreach $dest (@ARGV) {
open(POPUP, "| $smbclient -M $dest > /dev/null") || die("Couldn't open pipe to $smbclient - $!");
print POPUP $alerttext;
close POPUP || die "broken pipe to $smbclient - $! $?";
}
|