Re: [Mon-devel] [Mon-commit] mon/mon.d nntp.monitor,1.3,1.4
Brought to you by:
trockij
From: Augie S. <aug...@gm...> - 2008-01-09 23:00:46
|
So this is a pretty hefty diff and I hope everyone is OK with it. Basically I needed the nntp monitor to recognize the difference between a real problem and a maintenance window; Diablo 'pauses' during this time, so I added a "-m" flag that does not see this state as a failure. Other changes I made while in there: Reworked the conditionals to handle an arbitrary number of cases. Enabled "strict". Added proper error reporting; push @failures $host and push @details "$host: Detail message." . Everything basically works the same and I have it running in production now against a cluster of about 10 different News servers. --Augie On Jan 9, 2008 2:47 PM, Augie Schwer <as...@us...> wrote: > Update of /cvsroot/mon/mon/mon.d > In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv7698 > > Modified Files: > nntp.monitor > Log Message: > Added a maintenance mode, propper error reporting and work in a 'use strict' environment. > > Index: nntp.monitor > =================================================================== > RCS file: /cvsroot/mon/mon/mon.d/nntp.monitor,v > retrieving revision 1.3 > retrieving revision 1.4 > diff -C2 -d -r1.3 -r1.4 > *** nntp.monitor 17 Jul 2007 18:03:17 -0000 1.3 > --- nntp.monitor 9 Jan 2008 22:47:49 -0000 1.4 > *************** > *** 9,13 **** > # For use with "mon". > # > ! # Arguments are "-p port -t timeout [-g group] [-f] host [host...] -u username -a password" > # > # This monitor connects to the NNTP server(s), checks for a greeting, logs in, > --- 9,13 ---- > # For use with "mon". > # > ! # Arguments are "[-m] -p port -t timeout [-g group] [-f] host [host...] -u username -a password" > # > # This monitor connects to the NNTP server(s), checks for a greeting, logs in, > *************** > *** 49,92 **** > use Getopt::Std; > use English; > > ! getopts ("fg:p:t:d:u:a:"); > ! $GROUP = $opt_g || 'control'; > ! $PORT = $opt_p || 119; > ! $TIMEOUT = $opt_t || 30; > ! $FEEDER = $opt_f; > ! $DEBUG = $opt_d || ""; > ! $USER = $opt_u || ''; > ! $PASS = $opt_a || ''; > ! > ! @failures = (); > ! > ! foreach $host (@ARGV) { > ! > ! if (! &nntpGET($host, $PORT)) { > ! push (@failures, $host); > ! } > ! } > ! > ! if (@failures == 0) { > ! exit 0; > ! } > ! > ! print join (" ", sort @failures), "\n"; > ! > ! exit 1; > ! > ! > ! sub nntpGET { > ! use Socket; > ! use Sys::Hostname; > > ! my($Server, $Port) = @_; > ! my($ServerOK, $TheContent); > > ! $ServerOK = 0; > > ! $TheContent = ''; > > ! $Path = '/'; > > ############################################################### > --- 49,74 ---- > use Getopt::Std; > use English; > + use Socket; > + use Sys::Hostname; > + use strict; > > ! getopts ("fg:p:t:d:u:a:m"); > ! our ($opt_g,$opt_p,$opt_t,$opt_f,$opt_u,$opt_a,$opt_m); > ! my $GROUP = $opt_g || 'control'; > ! my $PORT = $opt_p || 119; > ! my $TIMEOUT = $opt_t || 30; > ! my $FEEDER = $opt_f; > ! my $USER = $opt_u || ''; > ! my $PASS = $opt_a || ''; > ! my $MAINT = $opt_m; > > ! my @failures = (); > ! my @details = (); > > ! foreach my $host (@ARGV) { > > ! my $TheContent = ''; > > ! my $Path = '/'; > > ############################################################### > *************** > *** 95,115 **** > local $SIG{ALRM} = sub { die "Timeout Alarm" }; > alarm $TIMEOUT; > ! $result = &OpenSocket($Server, $Port); # Open a connection to the server > if ($result == 0) { # Failure to open the socket > ! print "Unable to open socket\n" if $DEBUG; > ! return ''; > } > > ! # > ! # welcome message > ! # > ! $in = <S>; > ! if ($in !~ /^2\d\d/) { > ! alarm 0; > ! print "No welcome message\n" if $DEBUG; > ! return 0; > } > > - if (!$FEEDER) { > if ($USER ne "") > { > --- 77,156 ---- > local $SIG{ALRM} = sub { die "Timeout Alarm" }; > alarm $TIMEOUT; > ! my $result = &OpenSocket($host, $PORT); # Open a connection to the server > if ($result == 0) { # Failure to open the socket > ! print "Host: $host\n"; > ! print "Port: $PORT\n"; > ! push @failures , $host; > ! push @details , "$host: Unable to open socket."; > ! alarm 0; > ! next; > } > > ! if ($FEEDER) > ! { > ! # welcome message > ! my $in = <S>; > ! if ($in !~ /^2\d\d/) { > ! alarm 0; > ! push @failures , $host; > ! push @details , "$host: No welcome message."; > ! next; > ! } > ! > ! print S "quit\r\n"; > ! > ! $in = <S>; > ! if ($in !~ /^2\d\d/) { > ! alarm 0; > ! push @failures , $host; > ! push @details , "$host: No response on 'quit' command."; > ! next; > ! } > ! > ! close(S); > ! alarm 0; # Cancel the alarm > } > + elsif ($MAINT) > + { > + # Is the server currently in a maintenance mode? > + my $in = <S>; > + if ( $in =~ /^502 .+ System currently paused.*/ ) > + { > + close(S); > + alarm 0; # Cancel the alarm > + } > + elsif ( $in =~ /^2\d\d/ ) # Server not in maintenance mode, but is accepting connections. > + { > + print S "quit\r\n"; > + > + $in = <S>; > + if ($in !~ /^2\d\d/) { > + alarm 0; > + push @failures , $host; > + push @details , "$host: No response on 'quit' command."; > + next; > + } > + > + close(S); > + alarm 0; # Cancel the alarm > + } > + else # Server is not OK. > + { > + alarm 0; > + push @failures , $host; > + push @details , "$host: Server is not accepting connections."; > + next; > + } > + } > + else { > + # welcome message > + my $in = <S>; > + if ($in !~ /^2\d\d/) { > + alarm 0; > + push @failures , $host; > + push @details , "$host: No welcome message."; > + next; > + } > > if ($USER ne "") > { > *************** > *** 118,124 **** > $in = <S>; > if ($in !~ /^381/) { > ! alarm 0; > ! print "No reaction to authinfo user\n" if $DEBUG; > ! return 0; > } > # password > --- 159,166 ---- > $in = <S>; > if ($in !~ /^381/) { > ! alarm 0; > ! push @failures , $host; > ! push @details , "$host: No reaction to authinfo user."; > ! next; > } > # password > *************** > *** 127,132 **** > if ($in !~ /^281/) { > alarm 0; > ! print "No reaction to authinfo pass or wrong password\n" if $DEBUG; > ! return 0; > } > } > --- 169,175 ---- > if ($in !~ /^281/) { > alarm 0; > ! push @failures , $host; > ! push @details , "$host: No reaction to authinfo pass or wrong password."; > ! next; > } > } > *************** > *** 139,144 **** > if ($in !~ /^2\d\d/) { > alarm 0; > ! print "Unable to perform 'mode reader'\n" if $DEBUG; > ! return 0; > } > > --- 182,188 ---- > if ($in !~ /^2\d\d/) { > alarm 0; > ! push @failures , $host; > ! push @details , "$host: Unable to perform 'mode reader'."; > ! next; > } > > *************** > *** 151,186 **** > if ($in !~ /^2\d\d/) { > alarm 0; > ! print "Unable to select group '$GROUP'\n" if $DEBUG; > ! return 0; > } > - } > - > - # > - # log out > - # > - print S "quit\r\n"; > > ! $in = <S>; > ! if ($in !~ /^2\d\d/) { > ! alarm 0; > ! print "No response on 'quit' command.\n" if $DEBUG; > ! return 0; > } > - > - $ServerOK = 1; > - > - close(S); > - alarm 0; # Cancel the alarm > - > }; > > if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { > ! print "**** Time Out\n"; > ! return 0; > } > - return $ServerOK; > > } > > sub OpenSocket { > # > --- 195,244 ---- > if ($in !~ /^2\d\d/) { > alarm 0; > ! push @failures , $host; > ! push @details , "$host: Unable to select group '$GROUP'."; > ! next; > ! } > ! # > ! # log out > ! # > ! print S "quit\r\n"; > ! $in = <S>; > ! if ($in !~ /^2\d\d/) { > ! alarm 0; > ! push @failures , $host; > ! push @details , "$host: No response on 'quit' command."; > ! next; > } > > ! close(S); > ! alarm 0; # Cancel the alarm > } > }; > > if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { > ! push @failures , $host; > ! push @details , "$host: Time Out."; > ! next; > ! } > ! } > ! > ! if (@failures) > ! { > ! print join (" ", sort @failures), "\n"; > ! > ! if (@details) > ! { > ! print join ("\n", @details), "\n"; > } > > + exit 1; > + } > + else > + { > + print "no failures\n"; > + exit 0; > } > > + > sub OpenSocket { > # > *************** > *** 188,194 **** > # on another (or this) host. Port can be a number or a named service > # > ! local($OtherHostname, $Port) = @_; > ! local($OurHostname, $sockaddr, $name, $aliases, $proto, $type, $len, > ! $ThisAddr, $that); > $OurHostname = &hostname; > > --- 246,252 ---- > # on another (or this) host. Port can be a number or a named service > # > ! my ($OtherHostname, $Port) = @_; > ! my ($OurHostname, $sockaddr, $name, $aliases, $proto, $type, $len, > ! $ThisAddr, $that, $OtherHostAddr); > $OurHostname = &hostname; > > *************** > *** 198,204 **** > ($name, $aliases, $type, $len, $OtherHostAddr) = gethostbyname($OtherHostname); > > ! my $that = sockaddr_in ($Port, $OtherHostAddr); > > ! $result = socket(S, &PF_INET, &SOCK_STREAM, $proto) || return undef; > > $result = connect(S, $that) || return undef; > --- 256,262 ---- > ($name, $aliases, $type, $len, $OtherHostAddr) = gethostbyname($OtherHostname); > > ! $that = sockaddr_in ($Port, $OtherHostAddr); > > ! my $result = socket(S, &PF_INET, &SOCK_STREAM, $proto) || return undef; > > $result = connect(S, $that) || return undef; > > > ------------------------------------------------------------------------- > Check out the new SourceForge.net Marketplace. > It's the best place to buy or sell services for > just about anything Open Source. > http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace > _______________________________________________ > Mon-commit mailing list > Mon...@li... > https://lists.sourceforge.net/lists/listinfo/mon-commit > -- Augie Schwer - Augie@Schwer.us - http://schwer.us Key fingerprint = 9815 AE19 AFD1 1FE7 5DEE 2AC3 CB99 2784 27B0 C072 |