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 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
#!/usr/bin/perl
#
# Make an attempt at converting a bb-hosts file into
# a "mon.cf" file.
#
# I wouldn't recommend using the output of this in the
# long-term, but use it just to get yourself up and running
# with mon while you learn the syntax of the configuration
# file.
#
# Jim Trocki, trockij@transmeta.com
#
# $Id: convert-bb-hosts,v 1.3 1998/01/18 17:32:45 trockij Exp $
#
# 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
#
use Getopt::Std;
getopts ("d");
while (<>) {
next if (/^\s*#/ || /^\s*$/);
chomp;
($ip, $host, $directives) =
/^\s*(\d+\.\d+\.\d+\.\d+)\s+([a-zA-Z0-9-]+)(\s*#.*)?/;
if (!defined($directives)) {
print "watch $host\n";
print "\tservice fping\n";
print "\t\tinterval 10m\n";
print "\t\tmonitor fping.monitor\n";
print "\t\tperiod wd {Sun-Sat}\n";
print "\t\t\talert mail.alert user\n";
print "\t\t\talertevery 1h\n";
print "\n";
next;
}
$directives =~ s/BBDISPLAY//i;
$directives =~ s/BBPAGER//i;
$directives =~ s/^\s*#\s*//;
$directives =~ s/\s*$//;
@services = split (/\s+/, $directives);
next if (@services == 0);
print "watch $host\n";
print "\tservice fping\n";
print "\t\tinterval 10m\n";
print "\t\tmonitor fping.monitor\n";
print "\t\tperiod wd {Sun-Sat}\n";
print "\t\t\talert mail.alert user\n";
print "\t\t\talertevery 1h\n";
foreach $s (@services) {
if ($s =~ /^ftp/i) {
print "\tservice ftp\n";
print "\t\tinterval 5m\n";
print "\t\tmonitor ftp.monitor\n";
print "\t\tperiod wd {Sun-Sat}\n";
print "\t\t\talert mail.alert user\n";
print "\t\t\talertevery 1h\n";
} elsif ($s =~ /^smtp/i) {
print "\tservice smtp\n";
print "\t\tinterval 8m\n";
print "\t\tmonitor smtp.monitor\n";
print "\t\tperiod wd {Sun-Sat}\n";
print "\t\t\talert mail.alert user\n";
print "\t\t\talertevery 1h\n";
} elsif ($s =~ /^pop3/i) {
print "\tservice pop3\n";
print "\t\tinterval 18m\n";
print "\t\tmonitor pop3.monitor\n";
print "\t\tperiod wd {Sun-Sat}\n";
print "\t\t\talert mail.alert user\n";
print "\t\t\talertevery 1h\n";
} elsif ($s =~ /^http/i) {
print "\tservice http\n";
print "\t\tinterval 12m\n";
print "\t\tmonitor http.monitor\n";
print "\t\tperiod wd {Sun-Sat}\n";
print "\t\t\talert mail.alert user\n";
print "\t\t\talertevery 1h\n";
} else {
print STDERR "I don't know about the '$s' directive!\n";
}
}
print "\n";
}
|