mon-commit Mailing List for mon (Page 8)
Brought to you by:
trockij
You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(36) |
Jul
(21) |
Aug
(9) |
Sep
(1) |
Oct
(2) |
Nov
(12) |
Dec
(6) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(4) |
Feb
(10) |
Mar
(5) |
Apr
(22) |
May
(17) |
Jun
(3) |
Jul
(4) |
Aug
(10) |
Sep
(2) |
Oct
(1) |
Nov
(2) |
Dec
(2) |
2006 |
Jan
|
Feb
(4) |
Mar
|
Apr
|
May
|
Jun
|
Jul
(2) |
Aug
|
Sep
(6) |
Oct
|
Nov
|
Dec
(2) |
2007 |
Jan
|
Feb
|
Mar
|
Apr
(2) |
May
(22) |
Jun
(19) |
Jul
(7) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(6) |
2008 |
Jan
(1) |
Feb
(1) |
Mar
(3) |
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
|
Oct
(7) |
Nov
(1) |
Dec
|
2009 |
Jan
(2) |
Feb
(9) |
Mar
(1) |
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(5) |
2010 |
Jan
(2) |
Feb
(1) |
Mar
|
Apr
|
May
(4) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
(2) |
Apr
(1) |
May
(2) |
Jun
(2) |
Jul
(65) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: David N. <vi...@us...> - 2006-07-13 12:03:45
|
Update of /cvsroot/mon/mon In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv16088 Modified Files: mon Log Message: Fixed a bug where unknown traps could never get mapped to default:default, only to default:XYZ, where XYZ is the service in the trap. Index: mon =================================================================== RCS file: /cvsroot/mon/mon/mon,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** mon 12 Dec 2005 19:44:58 -0000 1.21 --- mon 13 Jul 2006 12:03:39 -0000 1.22 *************** *** 4338,4353 **** if (!defined $watch{$trap{"grp"}} && defined $watch{"default"}) { $trap{"grp"} = "default"; } ! if ((!defined ($groups{$trap{"grp"}}) && ! !defined $watch{$trap{"grp"}}->{$trap{"svc"}}) && ! (defined($groups{'default'}) && ! defined($watch{'default'}->{'default'}))) { - $intended = "$trap{'grp'}:$trap{'svc'}"; - $trap{"grp"} = "default"; $trap{"svc"} = "default"; } if (!defined ($groups{$trap{"grp"}})) { --- 4338,4352 ---- if (!defined $watch{$trap{"grp"}} && defined $watch{"default"}) { + $intended = "$trap{'grp'}:$trap{'svc'}"; $trap{"grp"} = "default"; } ! if ($trap{"grp"} eq 'default' ! && !defined($watch{default}->{$trap{"svc"}}) ! && defined($watch{'default'}->{'default'})) { $trap{"svc"} = "default"; } + if (!defined ($groups{$trap{"grp"}})) { |
From: David N. <vi...@us...> - 2006-07-13 12:02:42
|
Update of /cvsroot/mon/mon/alert.d In directory sc8-pr-cvs7.sourceforge.net:/tmp/cvs-serv15955 Removed Files: remote.alert Log Message: Removed deprecated remote.alert. use trap.alert instead. --- remote.alert DELETED --- |
From: Jim T. <tr...@us...> - 2006-02-28 13:25:03
|
Update of /cvsroot/mon/mon-contrib/utils/snmptrap2mon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3118/snmptrap2mon Added Files: snmptrap2mon snmptrap2mon.README Log Message: added snmptrap2mon --- NEW FILE: snmptrap2mon.README --- Date: Thu, 2 Feb 2006 10:53:37 -0800 (PST) From: Eric Sorenson <er...@tr...> To: mo...@li... Subject: snmptrap2mon converter Here's a little program to integrate snmp traps into your mon setup. It's meant to be used as an 'EXEC'ed program from snmptt (http://snmptt.sf.net), which does most of the heavy lifting. I had written something like this in the past that got lost, I'm sending out this version to the list for storage in contrib/ or, minimally, in google's archive :-) As the comment block says: # to be used in conjunction with snmptt : it hands us # the results of an snmp trap and we forward it on in # a format mon will understand. # usage: # snmptrap2mon [(--watch|-w) watchname] [(--service|-s) servicename] # [(--host|-h) hostname] [(--name|-n) trapname] [(--time|-t) timestamp] # "Quoted longform text of alert to send" # - 'watchname' and 'servicename' should map to your mon config; # leave them off and they will be set to 'default' # - 'host' is the host sending the trap, as best snmptt can tell # - 'trapname' is the unique string configured for this trap in snmptt.conf # - 'timestamp' will be the time alert was received/queued ($x or $X) # # Example, from /etc/snmp/snmptt.conf: # EVENT communicationLost .1.3.6.1.4.1.318.0.1 "Status Events" CRITICAL # FORMAT APC UPS: Communication lost between the agent and the UPS. # EXEC snmptrap2mon -w symmetra-ups -s trap -h $A -n $N \ # -t "$x" "APC UPS: Communication lost between the agent and the UPS." # # See README.traps in the mon distribution to setup your mon.cf. -- Eric Sorenson - Unix / Networks / MIS Manager - Transmeta Corporation --- NEW FILE: snmptrap2mon --- #!/usr/bin/perl # # to be used in conjunction with snmptt : it hands us # the results of an snmp trap and we forward it on in # a format mon will understand. # usage: # snmptrap2mon [(--watch|-w) watchname] [(--service|-s) servicename] # [(--host|-h) hostname] [(--name|-n) trapname] [(--time|-t) timestamp] # "Quoted longform text of alert to send" # - 'watchname' and 'servicename' should map to your mon config; # leave them off and they will be set to 'default' # - 'host' is the host sending the trap, as best snmptt can tell # - 'trapname' is the unique string configured for this trap in snmptt.conf # - 'timestamp' will be the time alert was received/queued ($x or $X) # # Example, from /etc/snmp/snmptt.conf: # EVENT communicationLost .1.3.6.1.4.1.318.0.1 "Status Events" CRITICAL # FORMAT APC UPS: Communication lost between the agent and the UPS. # EXEC snmptrap2mon -w symmetra-ups -s trap -h $A -n $N \ # -t "$x" "APC UPS: Communication lost between the agent and the UPS." # # See README.traps in the mon distribution to setup your mon.cf. use Carp; use Mon::Client; use Getopt::Std; getopts("w:s:h:n:t:u"); my $detail = join(" ",@ARGV); my $monhost = 'monhost.domain.com'; my $monport = 2583; my $watch = $opt_w or 'default'; my $service = $opt_s or 'default'; my $status = $opt_u ? 'ok' : 'fail' ; croak "Need all of -h, -n and -t" unless (defined $opt_h and defined $opt_n and defined $opt_t); my $alerthost = $opt_h; my $alertname = $opt_n; my $alerttime = $opt_t; my $summary = "$alertname trap from $alerthost at $alerttime"; $mon = new Mon::Client( host => $monhost, port => $monport ); croak "Couldn't make a new Mon::Client to $monhost on $monport" unless $mon; $t = $mon->send_trap(group => $watch, service => $service, retval => 1, opstatus => $status, summary => $summary, detail => $detail, ); exit ( $t ); |
From: Jim T. <tr...@us...> - 2006-02-28 13:23:24
|
Update of /cvsroot/mon/mon-contrib/utils/snmptrap2mon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2139/snmptrap2mon Log Message: Directory /cvsroot/mon/mon-contrib/utils/snmptrap2mon added to the repository |
From: Ed R. <er...@us...> - 2006-02-14 19:26:40
|
Update of /cvsroot/mon/mon-contrib/monitors/ospf In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20563 Added Files: ospf.monitor Log Message: Monitor OSPF adjacencies on a router that supports the RFC1253 MIB. The script detects all interfaces on which OSPF is listening - you may want to adjust your router config to minimize which intefaces are enabled for OSPF. All interfaces enabled for OSPF, and their states, are listed out as the "Mon details". Use the "--exclude" option to not alarm for an interface which you know will not form an adjacency. The interface and its state will still be listed out. Inspired by "bgp.monitor" which has a similar strategy of listing out all configured neighbors and their status. --- NEW FILE: ospf.monitor --- #!/usr/bin/perl # # Router ospf (Open Shortest Path First) monitor # Look at each router and get the status of all OSPF neighbors. # Issue alarm if any interfaces configured for neighbors do not # have a full adjacencies # Detail log shows status of all enabled OSPF interfaces. # Usage: # ospf.monitor [--exclude pattern] [--community str] router1 [...] # # --exclude - don't alarm for IP addresses that match <pattern>. Periods # in the IP address will be escaped so that they only match periods. Use # [0-9] or the like if you need character class matching. Use 'ip|ip|ip' # to exclude multiple peers. # # --community - SNMPv1 community name to use. But it's more secure # to pass the community in via the environment variable COMMUNITY. # # Edit history below # Version 0.1 # # By Ed Ravin <er...@pa...> This code is made available courtesy of # PANIX http://www.panix.com. # Copyright 2005, by Ed Ravin # # License: GNU GPL v2, see http://www.gnu.org/copyleft/gpl.html # # Loosely based on bgp.monitor which is: # Copyright 2002, by Marc Hauswirth, Safe Host SA <ma...@sa...> # # Some inspiration is taked from others mon monitors and from # routerinfo.pl by Ben Buxton (bb...@zi...), also under GPL, see http://www.zipworld.com.au/~bb/linux/ # and from routerint.monitor by P. Strauss (ph...@ph...) and me self (ma...@sa...). # # This script need the SNMP Session module from Simon Leinen <si...@sw...> # Wich you could found under http://www.switch.ch/misc/leinen/snmp/perl/ # It is also part of MRTG (http://people.ee.ethz.ch/~oetiker/webtools/mrtg/) use SNMP; use SNMP_Session; use Getopt::Long; use strict; my %opt; $opt{'community'}= undef; $opt{'exclude'}= ""; $opt{'debug'}= undef; my $usage="Usage: [COMMUNITY=str] ospf.monitor [--exclude regexp] [--community str] [--timeout usecs] [--version N] [--retries nn] router [...]\n"; GetOptions(\%opt, "exclude=s", "community=s", "timeout=i", "version=i", "retries=i", "debug") or die $usage; # It's highly unlikely someone wants dots in an IP address to be treated # as a regexp pattern, so we'll escape them to make behavior more predictable. # If you really want to use pattern matching, use a character class like # [0-9] instead. $opt{exclude} =~ s/\./\\./g; $opt{exclude}= '^(' . $opt{exclude} . ')'; $opt{exclude}= "NOT_USED" if $opt{exclude} eq "^()"; ## -- my $community = $opt{'community'} || $ENV{'COMMUNITY'} || "public"; my $timeout= $opt{'timeout'} || 5000000; my $retries= $opt{'retries'} || 3; my $version= $opt{'version'} || 1; ## -- my @failures; my @details; $ENV{'MIBS'}= ""; # all OIDs needed are specified in script # OID's to the SNMP elements that I want to show... # From Cisco's MIB and RFC's # http://sunsite.cnlab-switch.ch/ftp/doc/standard/rfc/16xx/1657 # http://www.telecomm.uh.edu/stats/rfc/BGP4-MIB.html my %oids = ( "SysUptime" => "1.3.6.1.2.1.1.3.0", "ifDescr" => "1.3.6.1.2.1.2.2.1.2", "ospfRouterId" => "1.3.6.1.2.1.14.1.1" , "ospfIfIpAddress" => "1.3.6.1.2.1.14.7.1.1" , "ospfAddressLessIf" => "1.3.6.1.2.1.14.7.1.2" , "ospfIfAdminStat" => "1.3.6.1.2.1.14.7.1.5" , "ospfIfState" => "1.3.6.1.2.1.14.7.1.12" , ); my %ospfIfStates = ( 1 => "down", 2 => "loopback", 3 => "waiting", 4 => "pointToPoint", 5 => "designatedRouter", 6 => "backupDesignatedRouter", 7 => "otherDesignatedRouter", ); my %ospfAdminStatus = ( 1 => "enabled", 2 => "disabled", ); use vars qw($router); sub snmpget1 # session, oid-hashstr, instance { my $session= shift; my $oidstr= shift; my $instance = shift; my $result= $session->get(".$oids{$oidstr}.$instance"); if ($session->{ErrorNum}) { push @failures, $router; push @details, "$router: error on SNMP get of $oidstr.$instance: $session->{ErrorStr}"; return 0; } return $result; } foreach $router (@ARGV) { # Get some infos about this router my $sess = new SNMP::Session ( DestHost => $router, Community => $community, Version=> $version, Timeout=> $timeout, Retries=> $retries, ); if (!defined($sess)) { push @failures, $router; push @details, "$router: cannot create SNMP session"; next; } my $ospfRouterID = snmpget1($sess, "ospfRouterId", "0") || next; push @details, "$router (Router-ID $ospfRouterID)"; # Find the indexes of the interfaces with OSPF enabled my @ospfinterfaces; my $vars = new SNMP::VarList([$oids{ospfIfAdminStat}]); for (my @vals = $sess->getnext($vars); $vars->[0]->tag =~ /1\.3\.6\.1\.2\.1\.14\.7\.1\.5/ # still in table (Did you have a cleaner solutions ?) and not $sess->{ErrorStr}; # and not end of mib or other error @vals = $sess->getnext($vars)) { my $textIfAdminStatus = $ospfAdminStatus{$vals[0]}; push @ospfinterfaces, $vars->[0]->tag if $textIfAdminStatus eq "enabled"; } # trim down OID to keep just the interface part, which we will use # shortly as an instance ID map {s/^\.$oids{ospfIfAdminStat}\.//} @ospfinterfaces; foreach my $int (@ospfinterfaces) { my $ifstate = snmpget1($sess, "ospfIfState", "$int"); my $ifinfo= $int; if ($int =~ /0\.0\.0\.0\.(\d+)$/) { my $ifindex= $1; $ifinfo= snmpget1($sess, "ifDescr", $ifindex) . " (.$ifindex)"; } push @details, sprintf("$router: Interface %-23s %-15s",$ifinfo, $ospfIfStates{$ifstate}); # if ospfIfState not in [4..7] (OSPF full adjacency states) if ($ifstate < 4 or $ifstate > 7) { push @failures, $router unless $int =~ /$opt{exclude}\b/ or grep(/^$router$/, @failures); $details[$#details] .= " [NO ADJACENCY]"; } } } if (@failures) { print join(' ', @failures), "\n"; }; if (@details) { print "\n"; print join("\n", @details), "\n"; } if (@failures) { # Error state exit exit 1; } else { # Correct exit exit 0; }; |
From: Ed R. <er...@us...> - 2006-02-14 19:01:24
|
Update of /cvsroot/mon/mon-contrib/monitors/ospf In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14170/ospf Log Message: Directory /cvsroot/mon/mon-contrib/monitors/ospf added to the repository |
From: David N. <vi...@us...> - 2005-12-12 19:45:07
|
Update of /cvsroot/mon/mon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6958 Modified Files: mon Log Message: replaced %m with $! in syslog calls, since we're not permitting printf semantics in syslog anymore also added a missing /g from a couple regexps in summary comparison code Index: mon =================================================================== RCS file: /cvsroot/mon/mon/mon,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** mon 12 Dec 2005 16:12:56 -0000 1.20 --- mon 12 Dec 2005 19:44:58 -0000 1.21 *************** *** 623,629 **** my $strippedsummary = $summary; ! $strippedsummary =~ s/\s//m; my $strippedprevious = $prevsumm; ! $strippedprevious =~ s/\s//m; # If the summary changed, un-acknowledge the service if 'unack_summary' is set if ($sref->{'_ack'} != 0 --- 623,629 ---- my $strippedsummary = $summary; ! $strippedsummary =~ s/\s//mg; my $strippedprevious = $prevsumm; ! $strippedprevious =~ s/\s//mg; # If the summary changed, un-acknowledge the service if 'unack_summary' is set if ($sref->{'_ack'} != 0 *************** *** 631,635 **** && $strippedsummary ne $strippedprevious && !($flags & ($FL_UPALERT|$FL_ACKALERT|$FL_DISABLEALERT))) { ! print STDERR "Summary: X".$strippedsummary."X\nPrevious: X".$strippedprevious."X\n"; $sref->{"_ack"} = 0; $sref->{"_ack_comment"} = ""; --- 631,635 ---- && $strippedsummary ne $strippedprevious && !($flags & ($FL_UPALERT|$FL_ACKALERT|$FL_DISABLEALERT))) { ! print STDERR "Unacking $group/$service:\nSummary: X".$strippedsummary."X\nPrevious: X".$strippedprevious."X\n"; $sref->{"_ack"} = 0; $sref->{"_ack_comment"} = ""; *************** *** 3157,3161 **** if (!open (N, "+>>" . $CF{"MONERRFILE"})) { ! syslog ("err", "could not open error output file $CF{'MONERRFILE'}: %m"); exit (1); } --- 3157,3161 ---- if (!open (N, "+>>" . $CF{"MONERRFILE"})) { ! syslog ("err", "could not open error output file $CF{'MONERRFILE'}: $!"); exit (1); } *************** *** 3167,3171 **** if (!open (STDIN, "/dev/null")) { ! syslog ("err", 'could not open STDIN from /dev/null: %m'); exit (1); } --- 3167,3171 ---- if (!open (STDIN, "/dev/null")) { ! syslog ("err", "could not open STDIN from /dev/null: $!"); exit (1); } *************** *** 3174,3178 **** if (!open(STDOUT, ">&N") || !open (STDERR, ">&N")) { ! syslog ("err", 'could not redirect: %m'); exit(1); } --- 3174,3178 ---- if (!open(STDOUT, ">&N") || !open (STDERR, ">&N")) { ! syslog ("err", "could not redirect: $!"); exit(1); } |
From: David N. <vi...@us...> - 2005-12-12 16:13:06
|
Update of /cvsroot/mon/mon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19817 Modified Files: mon Log Message: Added syslog wrapper to remove possible security concerns Index: mon =================================================================== RCS file: /cvsroot/mon/mon/mon,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** mon 10 Nov 2005 23:30:39 -0000 1.19 --- mon 12 Dec 2005 16:12:56 -0000 1.20 *************** *** 5383,5386 **** --- 5383,5395 ---- } + no warnings; # Redefining syslog + sub syslog { + eval { + local $SIG{"__DIE__"}= sub { }; + my @log = map { s/\%//mg; } @_; + Sys::Syslog::syslog(@log); + } + } + use warnings; # |
From: David N. <vi...@us...> - 2005-11-10 23:30:46
|
Update of /cvsroot/mon/mon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21884 Modified Files: mon Log Message: Bug fixes from Ed Ravin for ack alerts Fixed options parsing to make debug switch (-d) incrementable. i.e '-d -d' will set it to 2, which was the expected behavior. Index: mon =================================================================== RCS file: /cvsroot/mon/mon/mon,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** mon 7 Nov 2005 15:37:13 -0000 1.18 --- mon 10 Nov 2005 23:30:39 -0000 1.19 *************** *** 218,222 **** b|basedir=s c|configfile=s ! d|debug f|fork h|help --- 218,222 ---- b|basedir=s c|configfile=s ! d|debug+ f|fork h|help *************** *** 668,677 **** # ! # skip upalerts not paired with down alerts # disable by setting "no_comp_alerts" in period section # ! if (!$pref->{"no_comp_alerts"} && ($flags & $FL_UPALERT) && !$pref->{"_alert_sent"}) { ! syslog ('debug', "$group/$service/$periodlabel: Suppressing upalert since no down alert was sent."); next; } --- 668,678 ---- # ! # skip upalerts/ackalerts not paired with down alerts # disable by setting "no_comp_alerts" in period section # ! if (!$pref->{"no_comp_alerts"} && ($flags & ($FL_UPALERT | $FL_ACKALERT)) && !$pref->{"_alert_sent"}) { ! syslog ('debug', "$group/$service/$periodlabel: Suppressing upalert since no down alert was sent.") if ($flags & $FL_UPALERT); ! syslog ('debug', "$group/$service/$periodlabel: Suppressing ackalert since no down alert was sent.") if ($flags & $FL_ACKALERT); next; } *************** *** 3363,3366 **** --- 3364,3369 ---- || (($tmnow - $sref->{"_first_failure"}) >= $sref->{"upalertafter"})))) { + # Save the last failing monitor's output for posterity + $sref->{"_upalertoutput"}= $sref->{"_last_output"}; do_alert ($group, $service, $sref->{"_upalertoutput"}, 0, $FL_UPALERT); } |
From: David N. <vi...@us...> - 2005-11-07 15:37:22
|
Update of /cvsroot/mon/mon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6826 Modified Files: mon Log Message: Fixed a bug where config file parsing was using 'if ($args)' to test to see if a value was passed, where $args could be 0. Use defined instead. Index: mon =================================================================== RCS file: /cvsroot/mon/mon/mon,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** mon 11 Oct 2005 10:58:57 -0000 1.17 --- mon 7 Nov 2005 15:37:13 -0000 1.18 *************** *** 1130,1134 **** } elsif ($1 eq "unack_summary") { ! if ($2) { if ($2 =~ /y(es)?/i) { $2 = 1; --- 1130,1134 ---- } elsif ($1 eq "unack_summary") { ! if (defined $2) { if ($2 =~ /y(es)?/i) { $2 = 1; *************** *** 1697,1701 **** elsif ($var eq "unack_summary") { ! if ($args) { if ($args =~ /y(es)?/i) { $args = 1; --- 1697,1701 ---- elsif ($var eq "unack_summary") { ! if (defined $args) { if ($args =~ /y(es)?/i) { $args = 1; |
From: David N. <vi...@us...> - 2005-10-11 10:58:50
|
Update of /cvsroot/mon/mon In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16088 Modified Files: mon Log Message: Added experimental support for a global exclude_period Index: mon =================================================================== RCS file: /cvsroot/mon/mon/mon,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** mon 31 Jul 2005 16:20:02 -0000 1.16 --- mon 11 Oct 2005 10:58:57 -0000 1.17 *************** *** 419,505 **** # if (!$STOPPED) { ! foreach my $group (keys %watch) { ! foreach my $service (keys %{$watch{$group}}) { ! ! my $sref = \%{$watch{$group}->{$service}}; ! my $t = $tm - $lasttm; ! $t = 1 if ($t <= 0); ! # ! # trap timer ! # ! if ($sref->{"traptimeout"}) { ! $sref->{"_trap_timer"} -= $t; ! if ($sref->{"_trap_timer"} <= 0 && ! $tm - $sref->{"_last_trap"} > $sref->{"traptimeout"}) ! { ! $sref->{"_trap_timer"} = $sref->{"traptimeout"}; ! handle_trap_timeout ($group, $service); } - } - - # - # trap duration timer - # - if (defined ($sref->{"_trap_duration_timer"})) { - $sref->{"_trap_duration_timer"} -= $t; ! if ($sref->{"_trap_duration_timer"} <= 0) { ! set_op_status ($group, $service, $STAT_OK); ! undef $sref->{"_trap_duration_timer"}; } - } ! # ! # polling monitor timer ! # ! if ($sref->{"interval"} && $sref->{"_timer"} <= 0 && !$running{"$group/$service"}) ! { ! if (!$CF{"MAXPROCS"} || $procs < $CF{"MAXPROCS"}) ! { ! if (defined $sref->{"exclude_period"} ! && $sref->{"exclude_period"} ne "" && ! inPeriod (time, $sref->{"exclude_period"})) ! { ! debug (1, "not running $group,$service because of exclude_period\n"); ! } ! ! elsif (($sref->{"dep_behavior"} eq "m" && ! defined $sref->{"depend"} && $sref->{"depend"} ne "") ! || (defined $sref->{"monitordepend"} && $sref->{"monitordepend"} ne "")) ! { ! if (dep_ok ($sref, 'm')) { ! run_monitor ($group, $service); } ! else { ! debug (1, "not running $group,$service because of depend\n"); } ! } ! ! else ! { ! run_monitor ($group, $service); ! } ! } else ! { ! syslog ('info', "throttled at $procs processes"); ! } ! } ! ! else ! { ! $sref->{"_timer"} -= $t; ! if ($sref->{"_timer"} < 0) ! { ! $sref->{"_timer"} = 0; ! } } } --- 419,511 ---- # if (!$STOPPED) { ! if (defined $CF{"EXCLUDE_PERIOD"} ! && $CF{"EXCLUDE_PERIOD"} ne "" && ! inPeriod (time, $CF{"EXCLUDE_PERIOD"})) { ! debug (1, "not running monitors because of global exclude_period\n"); ! } else { ! foreach my $group (keys %watch) { ! foreach my $service (keys %{$watch{$group}}) { ! my $sref = \%{$watch{$group}->{$service}}; ! my $t = $tm - $lasttm; ! $t = 1 if ($t <= 0); ! # ! # trap timer ! # ! if ($sref->{"traptimeout"}) { ! $sref->{"_trap_timer"} -= $t; ! ! if ($sref->{"_trap_timer"} <= 0 && ! $tm - $sref->{"_last_trap"} > $sref->{"traptimeout"}) ! { ! $sref->{"_trap_timer"} = $sref->{"traptimeout"}; ! handle_trap_timeout ($group, $service); ! } } ! # ! # trap duration timer ! # ! if (defined ($sref->{"_trap_duration_timer"})) { ! $sref->{"_trap_duration_timer"} -= $t; ! ! if ($sref->{"_trap_duration_timer"} <= 0) { ! set_op_status ($group, $service, $STAT_OK); ! undef $sref->{"_trap_duration_timer"}; ! } } ! # ! # polling monitor timer ! # ! if ($sref->{"interval"} && $sref->{"_timer"} <= 0 && !$running{"$group/$service"}) ! { ! if (!$CF{"MAXPROCS"} || $procs < $CF{"MAXPROCS"}) { ! if (defined $sref->{"exclude_period"} ! && $sref->{"exclude_period"} ne "" && ! inPeriod (time, $sref->{"exclude_period"})) ! { ! debug (1, "not running $group,$service because of exclude_period\n"); ! } ! ! elsif (($sref->{"dep_behavior"} eq "m" && ! defined $sref->{"depend"} && $sref->{"depend"} ne "") ! || (defined $sref->{"monitordepend"} && $sref->{"monitordepend"} ne "")) ! { ! if (dep_ok ($sref, 'm')) ! { ! run_monitor ($group, $service); ! } ! ! else ! { ! debug (1, "not running $group,$service because of depend\n"); ! } ! } ! ! else ! { ! run_monitor ($group, $service); ! } } ! else { ! syslog ('info', "throttled at $procs processes"); } ! } else ! { ! $sref->{"_timer"} -= $t; ! if ($sref->{"_timer"} < 0) ! { ! $sref->{"_timer"} = 0; ! } ! } } } *************** *** 1152,1155 **** --- 1158,1168 ---- $new_CF{"MONREMOTE"} = $2; + } elsif ($1 eq "exclude_period") { + if (inPeriod (time, $2) == -1) + { + close (CFG); + return "cf error: malformed exclude_period '$2' (the specified time period is not valid as per Time::Period::inPeriod), line $line_num"; + } + $new_CF{"EXCLUDE_PERIOD"} = $2; } else { close (CFG); |
From: Jim T. <tr...@us...> - 2005-09-18 12:40:04
|
Update of /cvsroot/mon/mon-contrib/alerts/sms/bulksms In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28216/bulksms Added Files: README bulksms.alert.py bulksms.conf Log Message: added bulksms from Aled Treharne <ale...@gm...> --- NEW FILE: README --- Date: Thu, 15 Sep 2005 14:41:09 +0100 From: Aled Treharne <ale...@gm...> To: mo...@li... Subject: New alert for sending sms alerts through www.bulksms.co.uk Hi. To get around a problem we have here, I've written an alert script which uses bulksms.co.uk to send sms messages to preconfigured mobiles phones for alerting. It's attached, however a few caveats: 1) I'm a python geek, not a perl geek, so it's written in python. Sorry. :) 2) It requires the BulkSMS API as found on their site as well as a few other python bits. 3) It uses FreeBSD assumptions for file locations. Any problems, please let me know. Thanks, Aled. _______________________________________________ mon mailing list mo...@li... http://linux.kernel.org/mailman/listinfo/mon --- NEW FILE: bulksms.conf --- [BulkSMS] # Defaults for all BulkSMS operations # Your BulkSMS user details username: boxuk password: 0ffice # Which is your preferred cost route - see http://www.bulksms.co.uk/w/pricing.htm default_cost_route: 1 # From address # Not necessarily honoured, see BulkSMS documentation # ' delimited string source: '447956548902' # Recipients, specified as a python list recipients: ['447956548902'] --- NEW FILE: bulksms.alert.py --- #!/usr/local/bin/python ''' bulksms.alert - Alert script for mon to pass SMS messages to the www.bulksms.co.uk system. ''' import BulkSMS # API for Bulksms.co.uk - see import ConfigParser import os import getopt import sys import string import time # Keep the main settings in a config file so that we can share them # Look in /usr/local/etc/mon/bulksms.conf and ./bulksms.conf def get_config(): # Set all of our default config options # NB: During testing, pretend is default settings = ConfigParser.ConfigParser() settings.read(['/usr/local/etc/mon/bulksms.conf','./bulksms.conf']) config = { 'userid' : settings.get('BulkSMS','username'), 'password' : settings.get('BulkSMS','password'), 'cost' : settings.get('BulkSMS','default_cost_route'), 'from' : settings.get('BulkSMS','source'), 'recipients' : string.split(settings.get('BulkSMS','recipients'),','), 'LAST_SUMMARY' : os.getenv('MON_LAST_SUMMARY'), 'LAST_OUTPUT' : os.getenv('MON_LAST_OUTPUT'), 'LAST_FAILURE' : os.getenv('MON_LAST_FAILURE'), 'FIRST_FAILURE' : os.getenv('MON_FIRST_FAILURE'), 'LAST_SUCCESS' : os.getenv('MON_LAST_SUCCESS'), 'DESCRIPTION' : os.getenv('MON_DESCRIPTION'), 'GROUP' : os.getenv('MON_GROUP'), 'SERVICE' : os.getenv('MON_SERVICE'), 'RETVAL' : os.getenv('MON_RETVAL'), 'OPSTATUS' : os.getenv('MON_OPSTATUS'), 'ALERTTYPE' : os.getenv('MON_ALERTTYPE'), 'TRAP_INTENDED' : os.getenv('MON_TRAP_INTENDED'), 'LOGDIR' : os.getenv('MON_LOGDIR'), 'STATEDIR' : os.getenv('MON_STATEDIR'), 'subject' : sys.stdin.readline(), 'hosts' : '', 'alertevery' : '', 'trap_timeout' : 0, 'time' : '', 'trap_triggered': 0, 'upalert': 0 } short_opt = 's:g:h:l:Ot:Tu?' try: (opts, extras) = getopt.getopt(sys.argv[1:], short_opt) except getopt.GetoptError, ex: raise UsageError, ex debug(opts) debug(extras) debug(sys.argv) for item in opts: if item[0] == '-s': config['SERVICE'] = item[1] elif item[0] == '-g': config['GROUP'] = item[1] elif item[0] == '-h': config['hosts'] = item[1] elif item[0] == '-l': config['alertevery'] = item[1] elif item[0] == '-O': config['trap_timeout'] = 1 elif item[0] == '-t': if item[1].isdigit(): config['time'] = time.ctime(float(item[1])) else: raise RuntimeError, 'Type mismatch on time parameter: not float' elif item[0] == '-T': config['trap_triggered'] = 1 elif item[0] == '-u': config['upalert'] = 1 elif item[0] == '-?': raise UsageError, 'Help requested' else: raise RuntimeError, 'Error in parameters' return config def debug(message): debug=1 errlog = open('/tmp/bulksms.log','a') if debug: errlog.write('%s\n' % message) errlog.close() def usage(ex): if str(ex) == 'Help requested': print __doc__ elif str(ex) == 'Version information requested': version_info() else: sys.stderr.write("\n%s\n" % __doc__) sys.stderr.write("Error: %s\n" % str(ex)) def version_info(): version = "%s v%s" % (os.path.basename(sys.argv[0]), __version__) print version class UsageError(Exception): pass # Here endeth the standard lesson...er...section. ################################################ # Ok, up until this point it's all been stuff about making this pretty. # Here's where the actual guts of the thing starts. # The main bit. def main(): #Get the config sorted debug('started') config=get_config() debug('Got config.') debug(config) #Set up our BulkSMS interface sms = BulkSMS.BulkSMS(config['userid'],config['password']) sms.cost_route = config['cost'] if config['upalert']: message = 'UPALERT %s/%s: %s is now showing OK' % ( config['GROUP'], config['SERVICE'], config['hosts'] ) else: message = 'ALERT %s/%s: %s (Last tested OK %s)' % ( config['GROUP'], config['SERVICE'], config['hosts'], config['LAST_SUCCESS']) debug(message) ## fd = open('/tmp/output.test','w') ## debug(fd) msgid = sms.send_sms(config['recipients'], message, sender = config['from']) debug(msgid) ## fd.write(message) ## fd.write('%s' % msgid) ## fd.close # EOG (End of Guts - the end of the guts of the application) # This is the main application. It does nothing except pump us back up # into where we should be and raise a usage exception if something screwed up. if __name__ == '__main__': try: main() except UsageError, ex: usage(ex) |
From: Jim T. <tr...@us...> - 2005-09-18 12:36:21
|
Update of /cvsroot/mon/mon-contrib/alerts/sms/bulksms In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27413/bulksms Log Message: Directory /cvsroot/mon/mon-contrib/alerts/sms/bulksms added to the repository |
From: David N. <vi...@us...> - 2005-08-20 18:14:44
|
Update of /cvsroot/mon/mon-contrib/monitors/cisco In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20934 Added Files: cisco-env.monitor Log Message: Added monitor script for testing environmental sensors in various cisco devices. Works in at least 6500 and 3750 series devices. --- NEW FILE: cisco-env.monitor --- #!/usr/bin/perl # # Monitor Cisco device for certain environmental conditions via snmp # On devices that export this data, this script will detect and report: # - power supply failures # - fan blade failures # - temperature alarms # - chassis minor/major alarms # # Can parse monitor-auth.cf for snmp community string, or read from command line # # Arguments are: # # [-C monitor-auth.cf] [-c community] host [host ...] # # # cisco-env.monitor written by # Carnegie Mellon University, Computing Services # # # Copyright (c) 2004 Carnegie Mellon University. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. The name "Carnegie Mellon University" must not be used to endorse or # promote products derived from this software without prior written # permission. For permission or any legal details, please contact: # Office of Technology Transfer # Carnegie Mellon University # 5000 Forbes Avenue # Pittsburgh, PA 15213-3890 # (412) 268-4387, fax: (412) 268-7395 # tec...@an... # # 4. Redistributions of any form whatsoever must retain the following # acknowledgment: "This product includes software developed by Computing # Services at Carnegie Mellon University (http://www.cmu.edu/computing/)." # # CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS # SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, # IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR ANY SPECIAL, # INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. # # $Id: cisco-env.monitor,v 1.1 2005/08/20 18:14:32 vitroth Exp $ # use SNMP; use Getopt::Std; use IO::File; use strict; my ($community, $timeout, %failures, %opts); getopts("c:t:C:", \%opts); $community = $opts{'c'}; $timeout = ($opts{'t'} || 3) * 1000 * 1000; my $RETVAL = 0; my %communities; my $group=$ENV{MON_GROUP}; my $service=$ENV{MON_SERVICE}; my $file = $ENV{MON_CFBASEDIR}."/monitor-auth.cf"; my $cf; if ($cf = new IO::File "<$file") { while (<$cf>) { chomp; if (/^(\S+):readcommunity\s*=\s*(\S+)$/) { $communities{$1}=$2; } } $community ||= $communities{"$group:$service"}; $community ||= $communities{"$group:*"}; $community ||= $communities{"*:$service"}; $community ||= $communities{"*:*"}; } $community ||= 'public'; foreach my $host (@ARGV) { my $session = new SNMP::Session(DestHost => $host, Community => $community, Timeout => $timeout, Retries => 2, UseNumeric => 1, UseLongNames => 2); if (!defined ($session)) { $RETVAL = ($RETVAL == 1) ? 1 : 2; $failures{$host} = "$host: could not get SNMP session"; next; } my $desc = $session->get([".1.3.6.1.2.1.1.1.0"]); if (!$desc) { $RETVAL = 1; $failures{$host} = "$host: cannot contact snmpd"; next; } my %Capture = ('ps1status' => {'oid' => '.1.3.6.1.4.1.9.5.1.2.4.0', 'desc' => 'Power Supply 1', 'res' => {'1' => 'ok', '2' => 'ok', '3' => 'minor fault', '4' => 'major fault'}, }, 'ps2status' => {'oid' =>'.1.3.6.1.4.1.9.5.1.2.7.0', 'desc' => 'Power Supply 2', 'res' => {'1' => 'ok', '2' => 'ok', '3' => 'minor fault', '4' => 'major fault'}, }, 'fanstatus' => {'oid' => '.1.3.6.1.4.1.9.5.1.2.9.0', 'desc' => 'Fan Tray', 'res' => {'1' => 'ok', '2' => 'ok', '3' => 'minor fault', '4' => 'major fault'}, }, 'tempstatus' => {'oid' => '.1.3.6.1.4.1.9.5.1.2.13.0', 'desc' => 'Temperature Status', 'res' => {'1' => 'ok', '2' => 'ok', '3' => 'minor fault', '4' => 'major fault'}, }, 'minoralarm' => {'oid' => '.1.3.6.1.4.1.9.5.1.2.11.0', 'desc' => 'Chassis Minor Alarm', 'res' => {'1' => 'ok', '2' => 'activated'}, }, 'majoralarm' => {'oid' => '.1.3.6.1.4.1.9.5.1.2.12.0', 'desc' => 'Chassis Major Alarm', 'res' => {'1' => 'ok', '2' => 'activated'}, }, # 1- normal, 5- notPresent 'env-tempstatus' => {'oid' => '.1.3.6.1.4.1.9.9.13.1.3.1.6', 'desc' => 'Temperature State', 'res' => {'1' => 'ok', '2' => 'warning', '3' => 'critical', '4' => 'shutdown', '5' => 'ok', '6' => 'notFunctioning'}, 'type' => 'walk', }, 'env-fanstate' => {'oid' => '.1.3.6.1.4.1.9.9.13.1.4.1.3', 'desc' => 'Fan State', 'res' => {'1' => 'ok', '2' => 'warning', '3' => 'critical', '4' => 'shutdown', '5' => 'ok', '6' => 'notFunctioning'}, 'type' => 'walk', }, 'env-psstate' => {'oid' => '.1.3.6.1.4.1.9.9.13.1.5.1.3', 'desc' => 'Power Supply State', 'res' => {'1' => 'ok', '2' => 'warning', '3' => 'critical', '4' => 'shutdown', '5' => 'ok', '6' => 'notFunctioning'}, 'type' => 'walk', }, ); foreach my $K (keys %Capture) { my @Results; if ($Capture{$K}->{'type'} eq 'walk') { @Results = l_snmpwalk_values($session, $Capture{$K}->{'oid'}); }else{ push(@Results, $session->get($Capture{$K}->{'oid'})); } foreach my $Res (@Results) { if (defined $Capture{$K}->{'res'}->{$Res}) { if ($Capture{$K}->{'res'}->{$Res} ne 'ok') { $RETVAL = 1; $failures{$host} .= '; ' unless ($failures{$host} eq ''); $failures{$host} .= $Capture{$K}->{'desc'}." ". $Capture{$K}->{'res'}->{$Res}; } } } } } print join (" ", sort keys %failures), "\n\n" if (scalar keys %failures); foreach my $host (sort keys %failures) { print $host.': '.$failures{$host}, "\n"; } exit $RETVAL; sub l_snmpwalk_values { my ($session, $oid) = @_; my $rootlen = length($oid); $session->{ErrorStr} = ''; my $var = new SNMP::Varbind(["$oid"]); my $val = $session->getnext($var); my $name = $var->[$SNMP::Varbind::tag_f].".".$var->[$SNMP::Varbind::iid_f]; my %walk; while (!$session->{ErrorStr} && substr($name, 0, $rootlen) eq $oid){ my $value=$var->[$SNMP::Varbind::val_f]; $walk{"$name"} = $value; $val = $session->getnext($var); $name=$var->[$SNMP::Varbind::tag_f]; $name.=".$var->[$SNMP::Varbind::iid_f]" if $var->[$SNMP::Varbind::iid_f]; } #while return values %walk; } |
From: David N. <vi...@us...> - 2005-08-20 18:06:44
|
Update of /cvsroot/mon/mon-contrib/monitors/cyrus In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19297 Added Files: lmtp.monitor Log Message: Adding LMTP monitor script --- NEW FILE: lmtp.monitor --- #!/usr/bin/perl # # Use try to connect to a LMTP server (part of a Cyrus IMAP delivery # infrastucture, among others), and wait for the right output. # # For use with "mon". # # Arguments are "-p port -t timeout host [host...]" # # Adapted from "smtp.monitor" by # Chaskiel Grundman, cg...@an... # Adapted from "http.monitor" by # Jim Trocki, tr...@tr... # # http.monitor written by # # Jon Meek # American Cyanamid Company # Princeton, NJ # # $Id: lmtp.monitor,v 1.1 2005/08/20 18:06:36 vitroth 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; use English; getopts ("p:t:"); $PORT = $opt_p || 2003; $TIMEOUT = $opt_t || 30; @failures = (); foreach $host (@ARGV) { if (! &smtpGET($host, $PORT)) { push (@failures, $host); } } if (@failures == 0) { exit 0; } print join (" ", sort @failures), "\n"; foreach $msg (@details) { print "$msg\n"; } exit 1; sub smtpGET { use Socket; use Sys::Hostname; my($Server, $Port) = @_; my($ServerOK, $TheContent); my ($OurHostname); $ServerOK = 0; $TheContent = ''; $Path = '/'; ############################################################### eval { 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 push(@details, "${Server}: Unable to create SMTP connection to port $Port"); return ''; } $in = <S>; $in = <S> while $in =~ /^220-/; if ($in !~ /^220 /) { alarm 0; push(@details, "${Server}: $in"); return 0; } $OurHostname = &hostname; print S "LHLO $OurHostname\r\n"; $in = <S>; $in = <S> while $in =~ /^250-/; if ($in !~ /^250 /) { alarm 0; push(@details, "${Server}: $in"); return 0; } print S "quit\r\n"; $in = <S>; if ($in !~ /^221 /) { alarm 0; push(@details, "${Server}: $in"); return 0; } $ServerOK = 1; close(S); alarm 0; # Cancel the alarm }; if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { push(@details, "${Server}: Connection timed out"); return 0; } return $ServerOK; } sub OpenSocket { # # Make a Berkeley socket connection between this program and a TCP port # 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; ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $Port) = getservbyname($Port, 'tcp') unless $Port =~ /^\d+$/; ($name, $aliases, $type, $len, $ThisAddr) = gethostbyname($OurHostname); ($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; select(S); $| = 1; select(STDOUT); # set S to be un-buffered return 1; # success } |
From: David N. <vi...@us...> - 2005-08-20 17:54:17
|
Update of /cvsroot/mon/mon-contrib/monitors/smtp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16999 Added Files: smtp-ssl.monitor Log Message: Adding smtp over ssl monitoring script. --- NEW FILE: smtp-ssl.monitor --- #!/usr/bin/perl # # Use try to connect to a SMTP server over SSL, and # wait for the right output. Can also warn about cert expiration. # # For use with "mon". # # Arguments are "-p port -t timeout host [host...]" # # Adapted from "smtp.monitor" by # David Nolan, vit...@cm... # # Which was adapted from "http.monitor" by # Jim Trocki, tr...@tr... # # http.monitor written by # # Jon Meek # American Cyanamid Company # Princeton, NJ # # $Id: smtp-ssl.monitor,v 1.1 2005/08/20 17:54:09 vitroth 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; use Net::SSLeay::Handle qw/shutdown/; use English; use Time::ParseDate; getopts ("p:t:T:w:"); $PORT = $opt_p || 465; $TIMEOUT = $opt_t || 30; $THRESHOLD = $opt_T || 0; $EXPIREWARN = $opt_w ; # How long in advance to warn about cert expiration. 0 means don't warn $EXPIREWARN = 0 if (!defined $EXPIREWARN); # Don't warn by default @failures = (); foreach $host (@ARGV) { if (! &smtpGET($host, $PORT)) { push (@failures, $host); } } if (@failures == 0) { exit 0; } print join (" ", sort @failures), "\n"; foreach $msg (@details) { print "$msg\n"; } if (@failures <= $THRESHOLD) { exit @failures; } exit 255; sub smtpGET { use Socket; use Sys::Hostname; my($Server, $Port) = @_; my($ServerOK, $TheContent); my ($OurHostname); $ServerOK = 0; $TheContent = ''; $Path = '/'; ############################################################### eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; alarm $TIMEOUT; tie(*S2, "Net::SSLeay::Handle", $Server, $Port); $in = <S2>; $in = <S2> while $in =~ /^220-/; if ($in !~ /^220 /) { alarm 0; push(@details, "${Server}: $in"); return 0; } $OurHostname = &hostname; print S2 "HELO $OurHostname\r\n"; $in = <S2>; $in = <S2> while $in =~ /^250-/; if ($in !~ /^250 /) { alarm 0; push(@details, "${Server}: $in"); return 0; } print S2 "quit\r\n"; $in = <S2>; if ($in !~ /^221 /) { alarm 0; push(@details, "${Server}: $in"); return 0; } $ServerOK = 1; alarm 0; # Cancel the alarm if ($EXPIREWARN) { my $ssl = Net::SSLeay::Handle::_get_ssl(\*S2); my $cert = Net::SSLeay::get_peer_certificate($ssl); my $servercertname = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_subject_name($cert)); my $signingcertname = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($cert)); my $notafter = Net::SSLeay::P_ASN1_UTCTIME_put2string (Net::SSLeay::X509_get_notAfter($cert)); my $notbefore = Net::SSLeay::P_ASN1_UTCTIME_put2string (Net::SSLeay::X509_get_notBefore($cert)); my $na_time = parsedate($notafter); my $nb_time = parsedate($notbefore); my $now = time; my $later = $now + (86400 * $EXPIREWARN); print STDERR "XXXXX\nnotbefore $notbefore\nnotafter $notafter\nna_time $na_time\nnb_time $nb_time\nnow $now\nlater $later\n" if $opt_v; if ( $now < $nb_time ) { push @details,"$Server: Certificate not valid until $notbefore\ncertificate: $servercertname\nCA certificate: $signingcertname"; $ServerOK = 0; } if ($now > $na_time) { push @details,"$Server: Certificate expired as of $notafter\ncertificate: $servercertname\nCA certificate: $signingcertname"; $ServerOK = 0; } elsif ($later > $na_time ) { push @details,"$Server: Certificate will expire at $notafter\ncertificate: $servercertname\nCA certificate: $signingcertname"; $ServerOK = 0; } } shutdown(\*S2, 1); close(S2); }; if ($EVAL_ERROR) { if ($EVAL_ERROR =~ /^Timeout Alarm/) { push(@details, "${Server}: Connection timed out"); return 0; } else { push(@details, "${Server}: $EVAL_ERROR"); return 0; } } return $ServerOK; } sub OpenSocket { # # Make a Berkeley socket connection between this program and a TCP port # 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; ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $Port) = getservbyname($Port, 'tcp') unless $Port =~ /^\d+$/; ($name, $aliases, $type, $len, $ThisAddr) = gethostbyname($OurHostname); ($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; select(S); $| = 1; select(STDOUT); # set S to be un-buffered return 1; # success } |
From: David N. <vi...@us...> - 2005-08-20 17:50:57
|
Update of /cvsroot/mon/mon-contrib/monitors/pubcookie In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16533 Added Files: pubcookielogin.monitor webapp.monitor Log Message: Added monitor scripts for a pubcookie login server and for web applications protected with pubcookie --- NEW FILE: webapp.monitor --- #!/usr/bin/perl # # Try to establish a connection to a web application using pubcookie # authentication. See http://www.pubcookie.org # # User, password, realm and pubcookie login server can either be # specified on the command line or in the monitor-auth.cf file. # # Arguments are "[-c monitor-auth-config] [-U user] [-P pass] [-R # realm] [-L pubcookie-login-server] [-t timeout] [-u urlsuffix] host # [host...]" # # Adapted from "nis.monitor" by # Carnegie Mellon University, Computing Services # # nis.monitor written by Juha Ylitalo <jyl...@ik...> # # Copyright (C) 1999, Juha Ylitalo # # 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 strict; use vars qw(@failures @report $ua $cj $pubcookie_status $TIMEOUT $appurl $debug $opt_t $opt_u $opt_d $opt_U $opt_P $opt_R $opt_L $opt_c $user $password $realm $pcserver); use Getopt::Std; use English; use IO::File; use LWP; use HTTP::Request; use HTTP::Cookies; getopts ("u:t:d:U:P:R:L:c:"); $TIMEOUT = $opt_t || 30; $appurl = $opt_u || ""; $debug = $opt_d || 0; $user = $opt_U; $password = $opt_P; $realm = $opt_R; $pcserver = $opt_L; if ($debug > 1) { require LWP::Debug; import LWP::Debug qw(+); } unless (&parse_cf) { print join(' ', @ARGV) . "\n\nMonitoring Error!\nNo user/password specified on command line and can't open or parse config file\n"; exit 254; } @failures = (); @report = (); $ua= new LWP::UserAgent; $cj= new HTTP::Cookies; # Masquerade as MSIE, because some servers return an error for a user agent of libwww-perl. # suck suck suck $ua->agent('Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'); $ua->cookie_jar($cj); $pubcookie_status=pubcookie_login($ua, $cj, $pcserver); if ($pubcookie_status) { print join(' ', @ARGV) . "\n\nUnable to complete initial pubcookie login!\n$pubcookie_status\n"; exit(254); } foreach my $server ( @ARGV ) { &webapp_poll($ua, $pcserver, $server ); } if (@failures == 0) { exit 0; } print "@failures\n\n"; print join "\n\n", @report; print "\n"; exit scalar(@failures); sub pubcookie_login { my ($ua, $cj, $pcserver ) = @_; my ($fail); undef $fail; ############################################################### warn "Authenticating to pubcookie server $pcserver.\n" if ($debug); eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; alarm $TIMEOUT; my $request= new HTTP::Request (POST => "https://$pcserver/login.cgi"); $request->content_type('application/x-www-form-urlencoded'); $request->content("user=$user"); $request->add_content("&realm=$realm"); $request->add_content("&pass=$password"); $request->add_content("&one=$pcserver"); $request->add_content("&two=pinit"); $request->add_content("&creds_from_greq=1"); $request->add_content("&three=1"); $request->add_content("&four="); $request->add_content("&five="); $request->add_content("&six=$pcserver"); $request->add_content("&seven=/login.cgi"); $request->add_content("&reply=1"); my $res = $ua->request($request); if ($res->is_success) { my %cookies; $cj->scan(sub{ warn "COOKIE: $_[1]\n" if ($debug > 1); $cookies{$_[1]}=1; }); if ($cookies{pubcookie_cred}) { print "Pubcookie login OK\n" if ($debug); } else { print "auth reply cookies not present\n" if ($debug); $fail="$pcserver: authentication request failed\n"; } print $cj->as_string(), "\n\n\n" if ($debug > 1); print $res->as_string(), "\n" if ($debug > 1); } else { $fail=$pcserver .": " . $res->status_line(); } alarm 0; # Cancel the alarm }; if ($EVAL_ERROR and ($EVAL_ERROR eq 'Timeout Alarm')) { $fail="$pcserver: Time Out\n"; } return $fail; } sub pubcookie_appsrvreq { my ($ua, $pcserver, $appurl ) = @_; my ($fail); my $res; undef $fail; ############################################################### warn "Talking to $pcserver about access to $$appurl\n" if ($debug); eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; alarm $TIMEOUT; my $request= new HTTP::Request (GET => "https://$pcserver/"); # my $request2=$request->clone; # $ua->cookie_jar->add_cookie_header($request2); # print "-=-=-=-=-=-=\n",$request2->as_string(), "\n-=-=-=-=-=-=-=\n"; $res = $ua->request($request); alarm 0; # Cancel the alarm }; if ($EVAL_ERROR and ($EVAL_ERROR eq 'Timeout Alarm')) { return "$pcserver request Timed Out"; } elsif ($EVAL_ERROR) { return $EVAL_ERROR } if ($res->is_success) { warn $cj->as_string(), "\n\n\n" if ($debug > 1); warn $res->as_string(), "\n" if ($debug > 1); my %cookies; $cj->scan(sub{ $cookies{$_[1]}=1; }); if ($cookies{pubcookie_l}) { warn "OK\n" if ($debug > 1); } else { warn "$pcserver refused application request\n" if ($debug); return "$pcserver refused application request\n"; } } else { warn "$pcserver request failed: " . $res->status_line() if ($debug); return "$pcserver request failed: " . $res->status_line(); } my $refr=$res->header("Refresh"); if ($refr) { warn "Got refresh $refr\n" if ($debug); if ($refr =~ m,\d+;URL=[a-z]+://[^/]+/(\S+)$,) { $$appurl=$1; } } return undef; } sub webapp_poll { my ( $ua, $pcserver, $appsrv) = @_; my $retry = 0; my $retry_limit = 3; my $res; my $pubcookie_status; my $justreturn; my $appsvc; ############################################################### warn "Attempting to access https://$appsrv\n" if ($debug); eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; my $url="https://$appsrv"; alarm $TIMEOUT; my $request= new HTTP::Request (HEAD => "$url"); $res = $ua->simple_request($request); alarm 0; my $subj=$res->header("Client-SSL-Cert-Subject"); if ($subj =~ /CN=([\.\w]+)$/) { $appsvc=$1; } }; if ($EVAL_ERROR and ($EVAL_ERROR eq 'Timeout Alarm')) { push @failures, $appsrv; push @report, $appsrv . ":\nUnable to authenticate via pubcookie to $appsrv.\nFailed to establish initial connection to https://$appsrv, connection timed out.\n"; return @failures; } retry: eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; my $url="https://$appsrv/$appurl"; alarm $TIMEOUT; # LWP::UserAgent deletes the host and cookie headers when it recurses on # a redirect. We don't want that. On the other hand, we do want to make # sure there are no off-server redirects, so we use simple_request and # process redirects ourselves while (my $i++ < 10) { warn "Fetching $url\n" if ($debug); my $request= new HTTP::Request (GET => "$url"); $request->header("Host", $appsvc) if ($appsvc); $res = $ua->simple_request($request); alarm 0; # Cancel the alarm warn "HTTP request success.\n" if ($debug && $res->is_success); warn "HTTP response code ".$res->code."\n" if ($debug); last if ($res->is_success); my $code=$res->code; if ($code == &HTTP::Status::RC_MOVED_PERMANENTLY or $code == &HTTP::Status::RC_MOVED_TEMPORARILY) { $url=$res->header("Location"); { # code taken from LWP::UserAgent local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1; my $base = $res->base; $url = $HTTP::URI_CLASS->new($url, $base) ->abs($base); warn "Got redirect to $url\n" if ($debug); } # some things (e.g. the portal) will issue absolute redirects # to the load-balanced name. We want to do all testing against # the actual requested target if ($appsvc && $url =~ m,https://$appsvc,) { $url=~ s/$appsvc/$appsrv/; } if ($url !~ m,https://$appsrv,) { push @failures, $appsrv; push @report, $appsrv . ":\nUnable to authenticate via pubcookie to https://$appsrv/$appurl\nReceived unexpected redirect to $url\n"; $justreturn=1; last; } } else { last; } } }; if ($EVAL_ERROR and ($EVAL_ERROR eq 'Timeout Alarm')) { push @failures, $appsrv; push @report, $appsrv . ":\nUnable to authenticate via pubcookie to https://$appsrv/$appurl, connection timed out.\n"; } return @failures if ($justreturn); if ($res->is_success) { my $refr=$res->header('Refresh'); if ($refr && $refr =~ /^0;/) { warn "Got refresh $refr, pcserver = $pcserver, Retry is $retry.\n" if ($debug); if (($retry <= $retry_limit) && ($refr =~ /$pcserver/)) { $pubcookie_status=pubcookie_appsrvreq($ua, $pcserver, \$appurl); if ($pubcookie_status) { push @failures, $appsrv; push @report, $appsrv . ":\nUnable to authenticate via pubcookie to https://$appsrv/$appurl\n" . $pubcookie_status; } else { $retry++; goto retry; } } else { push @failures, $appsrv; push @report, $appsrv . ":\nUnable to authenticate via pubcookie to https://$appsrv/$appurl\nToo many redirects ($retry), received redirect to $refr"; } } else { warn "$appsrv request OK\n" if ($debug); } warn $cj->as_string(), "\n\n\n" if ($debug > 1); warn $res->as_string(), "\n" if ($debug > 1); } else { push @failures, $appsrv; push @report, $appsrv . ":\nUnable to authenticate via pubcookie to https://$appsrv/$appurl\n". $res->status_line(); } return @failures; } sub parse_cf { my (%users, %passwords, %realms, %pcservers, $cf); my $g=$ENV{MON_GROUP}; my $s=$ENV{MON_SERVICE}; warn "Parsing config file.\n" if ($debug); my $file = $opt_c || $ENV{MON_CFBASEDIR}."/monitor-auth.cf"; $cf=new IO::File "<$file" or return 0; while (<$cf>) { if (/^(\S+):user\s*=\s*(\S+)$/) { $users{$1}=$2; } if (/^(\S+):password\s*=\s*(\S+)$/) { $passwords{$1}=$2; } if (/^(\S+):realm\s*=\s*(\S+)$/) { $realms{$1}=$2; } if (/^(\S+):pubcookie_server\s*=\s*(\S+)$/) { $pcservers{$1}=$2; } } $user ||= $users{"$g:$s"}; $user ||= $users{"$g:*"}; $user ||= $users{"*:$s"}; $user ||= $users{"*:*"}; $password ||= $passwords{"$g:$s"}; $password ||= $passwords{"$g:*"}; $password ||= $passwords{"*:$s"}; $password ||= $passwords{"*:*"}; $realm ||= $realms{"$g:$s"}; $realm ||= $realms{"$g:*"}; $realm ||= $realms{"*:$s"}; $realm ||= $realms{"*:*"}; $pcserver ||= $pcservers{"$g:$s"}; $pcserver ||= $pcservers{"$g:*"}; $pcserver ||= $pcservers{"*:$s"}; $pcserver ||= $pcservers{"*:*"}; warn "Config is: user:$user, password:$password, realm:$realm, pcserver:$pcserver\n" if ($debug > 1); return 0 unless (defined($user) && defined($password) && defined($realm) && defined($pcserver)); return 1; } --- NEW FILE: pubcookielogin.monitor --- #!/usr/bin/perl # # Try to authenticate to a pubcookie login server. See http://www.pubcookie.org # User, password and realm can either be specified on the command line # or in the monitor-auth.cf file. # # Arguments are "[-c monitor-auth-config] [-u user] [-p pass] [-r realm] [-t timeout] host [host...]" # # Adapted from "nis.monitor" by # Carnegie Mellon University, Computing Services # # nis.monitor written by Juha Ylitalo <jyl...@ik...> # # Copyright (C) 1999, Juha Ylitalo # # 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; use English; use IO::File; use LWP; use HTTP::Request; use HTTP::Cookies; #use LWP::Debug qw(+); getopts ("c:p:r:t:u:"); $TIMEOUT = $opt_t || 30; $user = $opt_u; $password = $opt_p; $realm = $opt_r; unless (&parse_cf) { print "Monitoring Error\nNo user/password specified on command line and Can't open or parse config file\n"; exit 255; } @failures = (); @report = (); foreach $server ( @ARGV ) { &pubcookie_login_poll( $server ); } if (@failures == 0) { exit 0; } print "@failures\n\n"; print join "\n", @report; print "\n"; exit 1; sub pubcookie_login_poll { my ( $server ) = @_; my ($pin, $pout); my ($cell, $cmd, $pid); my $service; ############################################################### eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; my $ua= new LWP::UserAgent; my $url="https://$server"; alarm $TIMEOUT; my $request= new HTTP::Request (HEAD => "$url"); $res = $ua->simple_request($request); alarm 0; my $subj=$res->header("Client-SSL-Cert-Subject"); if ($subj =~ /CN=([\.\w]+)$/) { $service=$1; } }; if ($EVAL_ERROR and ($EVAL_ERROR eq 'Timeout Alarm')) { push @failures, $appsrv; push @report, $appsrv . ":Timed Out\n"; return @failures; } eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; alarm $TIMEOUT; my $ua= new LWP::UserAgent; my $cj= new HTTP::Cookies; $ua->cookie_jar($cj); my $request= new HTTP::Request (POST => "https://$server/login.cgi"); $request->content_type('application/x-www-form-urlencoded'); if ($service) { $request->header("host", $service); } $request->content("user=$user"); $request->add_content("&realm=$realm"); $request->add_content("&pass=$password"); $request->add_content("&one=webiso.andrew.cmu.edu"); $request->add_content("&two=pinit"); $request->add_content("&creds_from_greq=1"); $request->add_content("&three=1"); $request->add_content("&four="); $request->add_content("&five="); $request->add_content("&six=webiso.andrew.cmu.edu"); $request->add_content("&seven=/login.cgi"); $request->add_content("&pinit=true"); $request->add_content("&reply=1"); my $res = $ua->request($request); if ($res->is_success) { my %cookies; $cj->scan(sub{ #print "COOKIE: $_[1]:$_[4]\n"; $cookies{$_[1]}=1; }); # pubcookie_cred and pubcookie_l will be rejected by HTTP::Cookies # if the servername doesn't match if ($cookies{pubcookie_g}) { if (not defined($cookies{pubcookie_l}) or not defined($cookies{pubcookie_cred})) { # wrong service name.... complain or not? } #print "OK\n"; } else { #print "auth reply cookies not present\n"; push @failures, $server; push @report, $server . ": authentication request failed\n"; } #print $cj->as_string(0), "\n\n\n"; #print $res->as_string(), "\n"; } else { push @failures, $server; push @report, $server . ": " . $res->status_line(); } alarm 0; # Cancel the alarm }; if ($EVAL_ERROR and ($EVAL_ERROR eq 'Timeout Alarm')) { push @report , "$server: Time Out\n"; push @failures , $server; } return @failures; } sub parse_cf { my (%users, %passwords, %realms); my $g=$ENV{MON_GROUP}; my $s=$ENV{MON_SERVICE}; my $file = $opt_c || $ENV{MON_CFBASEDIR}."/monitor-auth.cf"; $cf=new IO::File "<$file" or return 0; while (<$cf>) { if (/^(\S+):user\s*=\s*(\S+)$/) { $users{$1}=$2; } if (/^(\S+):password\s*=\s*(\S+)$/) { $passwords{$1}=$2; } if (/^(\S+):realm\s*=\s*(\S+)$/) { $realms{$1}=$2; } } $user ||= $users{"$g:$s"}; $user ||= $users{"$g:*"}; $user ||= $users{"*:$s"}; $user ||= $users{"*:*"}; $password ||= $passwords{"$g:$s"}; $password ||= $passwords{"$g:*"}; $password ||= $passwords{"*:$s"}; $password ||= $passwords{"*:*"}; $realm ||= $realms{"$g:$s"}; $realm ||= $realms{"$g:*"}; $realm ||= $realms{"*:$s"}; $realm ||= $realms{"*:*"}; return 0 unless (defined($user) && defined($password) && defined($realm)); return 1; } |
From: David N. <vi...@us...> - 2005-08-20 17:50:02
|
Update of /cvsroot/mon/mon-contrib/monitors/pubcookie In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16409/pubcookie Log Message: Directory /cvsroot/mon/mon-contrib/monitors/pubcookie added to the repository |
From: David N. <vi...@us...> - 2005-08-20 15:28:04
|
Update of /cvsroot/mon/mon/mon.d In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22088 Modified Files: imap.monitor Log Message: Added support for examining a mailbox and erroring if unable to do so. Index: imap.monitor =================================================================== RCS file: /cvsroot/mon/mon/mon.d/imap.monitor,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** imap.monitor 17 Apr 2005 07:42:27 -0000 1.2 --- imap.monitor 20 Aug 2005 15:27:56 -0000 1.3 *************** *** 9,13 **** # # Adapted from "http.monitor" by ! # Jim Trocki, tr...@ar... # # http.monitor written by --- 9,13 ---- # # Adapted from "http.monitor" by ! # Jim Trocki, tr...@tr... # # http.monitor written by *************** *** 38,44 **** use English; ! getopts ("p:t:"); $PORT = $opt_p || 143; $TIMEOUT = $opt_t || 30; @failures = (); --- 38,45 ---- use English; ! getopts ("m:p:t:"); $PORT = $opt_p || 143; $TIMEOUT = $opt_t || 30; + $MAILBOX=$opt_m || undef; @failures = (); *************** *** 55,60 **** } ! print join (" ", sort @failures), "\n"; ! print sort @details if (scalar @details) > 0; exit 1; --- 56,60 ---- } ! print join (" ", sort @failures), "\n\n", join ("\n", @longerr), "\n"; exit 1; *************** *** 66,70 **** my($Server, $Port) = @_; ! my($ServerOK, $TheContent); $ServerOK = 0; --- 66,70 ---- my($Server, $Port) = @_; ! my($ServerOK, $TheContent, $cmd); $ServerOK = 0; *************** *** 81,84 **** --- 81,85 ---- $result = &OpenSocket($Server, $Port); # Open a connection to the server if ($result == 0) { # Failure to open the socket + push @longerr, "$Server: Unable to connect"; return ''; } *************** *** 87,103 **** if ($in !~ /^\* (OK|PREAUTH|BYE)/) { alarm 0; return 0; } ! print S "A1 LOGOUT\r\n"; while (defined($in=<S>)) { ! if ($in =~ /^A1 OK/) { last; - $ServerOK = 0; } } - $ServerOK = 1; close(S); --- 88,150 ---- if ($in !~ /^\* (OK|PREAUTH|BYE)/) { alarm 0; + push @longerr, "$Server: No IMAP banner received"; return 0; } ! $cmd="login"; ! print S "A1 LOGIN ANONYMOUS ANONYMOUS\r\n"; while (defined($in=<S>)) { ! if ($in =~ /^A1 (\w+) (.*)/) { ! if ($1 eq "OK") { ! $ServerOK = 1; ! } else { ! $errmsg="$1 $2"; ! } last; } } + + if ($ServerOK && $MAILBOX) { + $cmd="examine"; + $ServerOK=0; + print S "A2 EXAMINE $MAILBOX\r\n"; + + while (defined($in=<S>)) { + if ($in =~ /^A2 (\w+) (.*)/) { + if ($1 eq "OK") { + $ServerOK = 1; + } else { + $errmsg="$1 $2"; + } + last; + } + } + } + + if ($ServerOK) { + $cmd="logout"; + $ServerOK=0; + print S "A3 LOGOUT\r\n"; + + while (defined($in=<S>)) { + if ($in =~ /^A3 (\w+) (.*)/) { + if ($1 eq "OK") { + $ServerOK = 1; + } else { + $errmsg="$1 $2"; + } + last; + } + } + } + if (!$ServerOK) { + if ($errmsg) { + push @longerr, "$Server: bad response to $cmd: $errmsg"; + } else { + push @longerr, "$Server: No response to $cmd"; + } + } close(S); *************** *** 107,112 **** if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { ! push(@details, "$host: timeout($TIMEOUT)\n"); return 0; } return $ServerOK; --- 154,162 ---- if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { ! push @longerr, "$Server: **** Time Out\n"; return 0; + } elsif ($EVAL_ERROR) { + push @longerr, "$Server: $EVAL_ERROR"; + return 0; } return $ServerOK; *************** *** 129,146 **** ($name, $aliases, $type, $len, $OtherHostAddr) = gethostbyname($OtherHostname); - if (!defined $OtherHostAddr) - { - push (@details, "$host: cannot resolve hostname\n"); - return undef; - } - my $that = sockaddr_in ($Port, $OtherHostAddr); ! if (! ($result = socket(S, &PF_INET, &SOCK_STREAM, $proto)) || ! (! ($result = connect(S, $that))) ) ! { ! push (@details, "$host: $!\n"); ! return undef; ! } select(S); $| = 1; select(STDOUT); # set S to be un-buffered --- 179,187 ---- ($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; select(S); $| = 1; select(STDOUT); # set S to be un-buffered |
From: David N. <vi...@us...> - 2005-08-20 15:24:59
|
Update of /cvsroot/mon/mon-contrib/monitors/cyrus In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21656 Added Files: imsp.monitor mupdate.monitor Log Message: Adding monitor tests for IMSP and MUPDATE servers --- NEW FILE: mupdate.monitor --- #!/usr/bin/perl # # Use try to connect to an MUPDATE server, and # wait for the right output. (MUPDATE is a core part # of a distributed Cyrus IMAP server infrastructure.) # # For use with "mon". # # Arguments are "-p port -t timeout host [host...]" # # Adapted from "imap.monitor" by # David Nolan, vit...@cm... # # Which was dapted from "http.monitor" by # Jim Trocki, tr...@tr... # # http.monitor written by # # Jon Meek # American Cyanamid Company # Princeton, NJ # # $Id: mupdate.monitor,v 1.1 2005/08/20 15:24:50 vitroth 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; use English; getopts ("p:t:"); $PORT = $opt_p || 3905; $TIMEOUT = $opt_t || 30; @failures = (); foreach $host (@ARGV) { if (! &mupdateGET($host, $PORT)) { push (@failures, $host); } } if (@failures == 0) { exit 0; } print join (" ", sort @failures), "\n\n", join ("\n", @longerr), "\n"; exit 1; sub mupdateGET { use Socket; use Sys::Hostname; my($Server, $Port) = @_; my($ServerOK, $TheContent); $ServerOK = 0; $TheContent = ''; $Path = '/'; ############################################################### eval { 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 push @longerr, "$Server: Unable to connect"; return ''; } my $error = 0; $in = <S>; if ($in !~ /^\* AUTH/) { $error = 1; } else { $in = <S>; while ($in !~ /^\* OK MUPDATE/) { $in = <S>; } } if($error) { alarm 0; push @longerr, "$Server: No MUPDATE banner received"; return 0; } print S "L LOGOUT\r\n"; while (defined($in=<S>)) { if ($in =~ /^L OK/) { $ServerOK = 1; last; } } if (!$ServerOK) { push @longerr, "$Server: No response to logout"; } close(S); alarm 0; # Cancel the alarm }; if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { push @longerr, "$Server: **** Time Out\n"; return 0; } elsif ($EVAL_ERROR) { push @longerr, "$Server: $EVAL_ERROR"; return 0; } return $ServerOK; } sub OpenSocket { # # Make a Berkeley socket connection between this program and a TCP port # 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; ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $Port) = getservbyname($Port, 'tcp') unless $Port =~ /^\d+$/; ($name, $aliases, $type, $len, $ThisAddr) = gethostbyname($OurHostname); ($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; select(S); $| = 1; select(STDOUT); # set S to be un-buffered return 1; # success } --- NEW FILE: imsp.monitor --- #!/usr/bin/perl # # Use try to connect to an IMSP server, and # wait for the right output. # # For use with "mon". # # Arguments are "-p port -t timeout host [host...]" # # Adapted from "imap.monitor" by # David Nolan, vit...@cm... # # Which was adapted from "http.monitor" by # Jim Trocki, tr...@tr... # # http.monitor written by # # Jon Meek # American Cyanamid Company # Princeton, NJ # # $Id: imsp.monitor,v 1.1 2005/08/20 15:24:50 vitroth 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; use English; getopts ("p:t:"); $PORT = $opt_p || 406; $TIMEOUT = $opt_t || 30; @failures = (); %details; foreach $host (@ARGV) { if (! &imspGET($host, $PORT)) { push (@failures, $host); } } if (@failures == 0) { exit 0; } print join (" ", sort @failures), "\n"; foreach (sort @failures) { if (exists $details{$_}) { print "$_: $details{$_}\n"; } } exit scalar @failures; sub imspGET { use Socket; use Sys::Hostname; my($Server, $Port) = @_; my($ServerOK, $TheContent); $ServerOK = 0; $TheContent = ''; $Path = '/'; ############################################################### eval { 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 alarm 0; $details{$Server} = "Connection refused"; return 0; } $in = <S>; if ($in !~ /^\* (OK|PREAUTH|BYE)/) { alarm 0; $details{$Server} = "No IMSP banner. Not an IMSP server?"; return 0; } print S "A1 LOGOUT\r\n"; while (defined($in=<S>)) { if ($in =~ /^A1 OK/) { last; } } $ServerOK = 1; close(S); alarm 0; # Cancel the alarm }; if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { $details{$Server} = "Connection timed out after $TIMEOUT seconds\n"; return 0; } return $ServerOK; } sub OpenSocket { # # Make a Berkeley socket connection between this program and a TCP port # 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; ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $Port) = getservbyname($Port, 'tcp') unless $Port =~ /^\d+$/; ($name, $aliases, $type, $len, $ThisAddr) = gethostbyname($OurHostname); ($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; select(S); $| = 1; select(STDOUT); # set S to be un-buffered return 1; # success } |
From: David N. <vi...@us...> - 2005-08-20 15:24:41
|
Update of /cvsroot/mon/mon-contrib/monitors/cyrus In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21590/cyrus Log Message: Directory /cvsroot/mon/mon-contrib/monitors/cyrus added to the repository |
From: David N. <vi...@us...> - 2005-08-20 15:21:07
|
Update of /cvsroot/mon/mon-contrib/monitors/imap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20962 Added Files: imap-ptp.monitor imap-ssl.monitor imap-starttls.monitor Log Message: Adding monitor scripts for: IMAP with plain text password login IMAP over SSL IMAP w/ STARTTLS --- NEW FILE: imap-starttls.monitor --- #!/usr/bin/perl # # Try to connect to an IMAP server, and issue a STARTTLS command, and # wait for the right output. # # For use with "mon". # # Arguments are "-p port -t timeout host [host...]" # # Adapted from "imap.monitor" by # David Nolan, vi...@cm... # # Which in turn was adapted from 'http.monitor' by # Jim Trocki, tr...@tr... # # http.monitor was written by # # Jon Meek # American Cyanamid Company # Princeton, NJ # # # $Id: imap-starttls.monitor,v 1.1 2005/08/20 15:20:57 vitroth 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; use Net::SSLeay::Handle qw/shutdown/; use English; getopts ("p:t:"); $PORT = $opt_p || 143; $TIMEOUT = $opt_t || 30; @failures = (); foreach $host (@ARGV) { if (! &imapGET($host, $PORT)) { push (@failures, $host); } } if (@failures == 0) { exit 0; } print join (" ", sort @failures), "\n\n", join ("\n", @longerr), "\n"; exit 1; sub imapGET { use Socket; use IO::Socket::INET; use Sys::Hostname; use Symbol; my($Server, $Port) = @_; my($ServerOK, $TheContent); $ServerOK = 0; $TheContent = ''; $Path = '/'; ############################################################### eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; alarm $TIMEOUT; my $socket = gensym; # Necessary to allow $socket and $sslsocket to be used multiple times for my $sslsocket = gensym; # the Net::SSLeay::Handle tie $result = &OpenSocket($socket, $Server, $Port); # Open a connection to the server if ($result == 0) { # Failure to open the socket push @longerr, "$Server: Unable to connect"; return ''; } $in = <$socket>; if ($in !~ /^\* (OK|PREAUTH|BYE)/) { alarm 0; push @longerr, "$Server: No IMAP banner received"; return 0; } print $socket "A1 STARTTLS\r\n"; $in = <$socket>; if ($in !~ /^A1 OK/) { alarm 0; push @longerr, "$Server: STARTTLS request denied"; return 0; } tie(*$sslsocket, "Net::SSLeay::Handle", $socket); print $sslsocket "A1 LOGOUT\r\n"; while (defined($in=<$sslsocket>)) { if ($in =~ /^A1 OK/) { $ServerOK = 1; last; } } if (!$ServerOK) { push @longerr, "$Server: No response to logout, STARTTLS negotiation failed?"; } close($sslsocket); alarm 0; # Cancel the alarm }; if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { push @longerr, "$Server: **** Time Out\n"; return 0; } elsif ($EVAL_ERROR) { push @longerr, "$Server: $EVAL_ERROR"; return 0; } return $ServerOK; } sub OpenSocket { # # Make a Berkeley socket connection between this program and a TCP port # on another (or this) host. Port can be a number or a named service # local($socket, $OtherHostname, $Port) = @_; local($OurHostname, $sockaddr, $name, $aliases, $proto, $type, $len, $ThisAddr, $that); $OurHostname = &hostname; ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $Port) = getservbyname($Port, 'tcp') unless $Port =~ /^\d+$/; ($name, $aliases, $type, $len, $ThisAddr) = gethostbyname($OurHostname); ($name, $aliases, $type, $len, $OtherHostAddr) = gethostbyname($OtherHostname); my $that = sockaddr_in ($Port, $OtherHostAddr); $result = socket($socket, &PF_INET, &SOCK_STREAM, $proto) || return undef; $result = connect($socket, $that) || return undef; select($socket); $| = 1; select(STDOUT); # set S to be un-buffered return 1; # success } --- NEW FILE: imap-ssl.monitor --- #!/usr/bin/perl # # Try to connect to an IMAP server, over SSL, and # wait for the right output. # # For use with "mon". # # Arguments are "[-p port] [-t timeout] [-w cert-expiration-warning-window ] host [host...]" # # Adapted from "imap.monitor" by # David Nolan, vi...@cm... # # Which in turn was adapted from 'http.monitor' by # Jim Trocki, tr...@tr... # # http.monitor was written by # # Jon Meek # American Cyanamid Company # Princeton, NJ # # $Id: imap-ssl.monitor,v 1.1 2005/08/20 15:20:57 vitroth 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; use Net::SSLeay::Handle qw/shutdown/; use English; use Time::ParseDate; getopts ("p:t:w:"); $PORT = $opt_p || 993; $TIMEOUT = $opt_t || 30; $EXPIREWARN = $opt_w ; # How long in advance to warn about cert expiration. 0 means don't warn $EXPIREWARN = 0 if (!defined $EXPIREWARN); # Don't warn by default @failures = (); foreach $host (@ARGV) { if (! &imapGET($host, $PORT)) { push (@failures, $host); } } if (@failures == 0) { exit 0; } print join (" ", sort @failures), "\n\n", join ("\n", @longerr), "\n"; exit 1; sub imapGET { use Socket; use Sys::Hostname; my($Server, $Port) = @_; my($ServerOK, $TheContent); $ServerOK = 0; $TheContent = ''; $Path = '/'; ############################################################### eval { local $SIG{ALRM} = sub { die "Timeout Alarm" }; alarm $TIMEOUT; tie(*S2, "Net::SSLeay::Handle", $Server, $Port); $in = <S2>; if ($in !~ /^\* (OK|PREAUTH|BYE)/) { alarm 0; push @longerr, "$Server: No IMAP banner received"; shutdown(\*S2, 1); close(S2); return 0; } print S2 "A1 LOGOUT\r\n"; while (defined($in=<S2>)) { if ($in =~ /^A1 OK/) { $ServerOK = 1; last; } } if (!$ServerOK) { push @longerr, "$Server: No response to logout"; } alarm 0; # Cancel the alarm if ($EXPIREWARN) { my $ssl = Net::SSLeay::Handle::_get_ssl(\*S2); my $cert = Net::SSLeay::get_peer_certificate($ssl); my $servercertname = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_subject_name($cert)); my $signingcertname = Net::SSLeay::X509_NAME_oneline(Net::SSLeay::X509_get_issuer_name($cert)); my $notafter = Net::SSLeay::P_ASN1_UTCTIME_put2string (Net::SSLeay::X509_get_notAfter($cert)); my $notbefore = Net::SSLeay::P_ASN1_UTCTIME_put2string (Net::SSLeay::X509_get_notBefore($cert)); my $na_time = parsedate($notafter); my $nb_time = parsedate($notbefore); my $now = time; my $later = $now + (86400 * $EXPIREWARN); print STDERR "XXXXX\nnotbefore $notbefore\nnotafter $notafter\nna_time $na_time\nnb_time $nb_time\nnow $now\nlater $later\n" if $opt_v; if ( $now < $nb_time ) { push @longerr,"$Server: Certificate not valid until $notbefore\ncertificate: $servercertname\nCA certificate: $signingcertname"; $ServerOK = 0; } if ($now > $na_time) { push @longerr,"$Server: Certificate expired as of $notafter\ncertificate: $servercertname\nCA certificate: $signingcertname"; $ServerOK = 0; } elsif ($later > $na_time ) { push @longerr,"$Server: Certificate will expire at $notafter\ncertificate: $servercertname\nCA certificate: $signingcertname"; $ServerOK = 0; } } shutdown(\*S2, 1); close(S2); }; if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { push @longerr, "$Server: **** Time Out\n"; return 0; } elsif ($EVAL_ERROR) { push @longerr, "$Server: $EVAL_ERROR"; return 0; } return $ServerOK; } sub OpenSocket { # # Make a Berkeley socket connection between this program and a TCP port # 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; ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $Port) = getservbyname($Port, 'tcp') unless $Port =~ /^\d+$/; ($name, $aliases, $type, $len, $ThisAddr) = gethostbyname($OurHostname); ($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; select(S); $| = 1; select(STDOUT); # set S to be un-buffered return 1; # success } --- NEW FILE: imap-ptp.monitor --- #!/usr/bin/perl # # This script will attempt to login to an imap server # with a plain-text password. Password can either be specified on the # command line or in the monitor-auth.cf file. # # For use with "mon". # # Arguments are "[-u user] [-p pass] [-P port] [-t timeout] [-m mailbox] host [host...]" # # Adapted from "imap.monitor" by # David Nolan, vit...@cm... # # Which was adapted from "http.monitor" by # Jim Trocki, tr...@tr... # # http.monitor written by # # Jon Meek # American Cyanamid Company # Princeton, NJ # # $Id: imap-ptp.monitor,v 1.1 2005/08/20 15:20:57 vitroth 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 strict; use Getopt::Std; use English; use IO::File; use Socket; use vars qw($opt_p $opt_t $opt_u $opt_c $opt_P $opt_m $PASS $PORT $USER $TIMEOUT $MAILBOX $MONAUTHFILE @failures @longerr); getopts ("p:t:u:c:P:m:"); $PASS = $opt_p || ""; $USER = $opt_u || ""; $TIMEOUT = $opt_t || 30; $MAILBOX = $opt_m || "INBOX"; $PORT = $opt_P || 143; $MONAUTHFILE = $opt_c || $ENV{MON_CFBASEDIR}."/monitor-auth.cf"; @failures = (); @longerr = (); if (my $cf=new IO::File "<$MONAUTHFILE") { my (%users, %passwords); my $g=$ENV{MON_GROUP}; my $s=$ENV{MON_SERVICE}; while (<$cf>) { chomp; if (/^(\S+):user\s*=\s*(\S+)$/) { $users{$1}=$2; } if (/^(\S+):password\s*=\s*(\S+)$/) { $passwords{$1}=$2; } } $USER ||= $users{"$g:$s"}; $PASS ||= $passwords{"$g:$s"}; $USER ||= $users{"$g:*"}; $PASS ||= $passwords{"$g:*"}; $USER ||= $users{"*:$s"}; $PASS ||= $passwords{"*:$s"}; $USER ||= $users{"*:*"}; $PASS ||= $passwords{"*:*"}; } foreach my $host (@ARGV) { if (! &imapGET($host, $PORT)) { push (@failures, $host); } } if (@failures == 0) { exit 0; } print join (" ", sort @failures), "\n\n", join ("\n", @longerr), "\n"; exit 1; sub imapGET { use Sys::Hostname; my($Server, $Port) = @_; my($ServerOK, $TheContent, $Path, $result, $cmd, $in, $errmsg); $ServerOK = 0; $TheContent = ''; $Path = '/'; ############################################################### # $ServerOK = eval { # local $SIG{ALRM} = sub { die "Timeout Alarm" }; # alarm $TIMEOUT; # $c = Cyrus::IMAP->new("$Server"); # if (!$c) { # alarm 0; # push @longerr, "$Server: Unable to connect"; # return 0; # } # if ($USER && $PASS # && !$c->send('', '', 'LOGIN %s %s', $USER, $PASS)) { # alarm 0; # push @longerr, "$Server: Unable to login as $USER: $@"; # return 0; # } # if (!$c->send('', '', 'EXAMINE %s', $MAILBOX)) { # alarm 0; # push @longerr, "$Server: Unable to examine $MAILBOX as $USER: $@"; # return 0; # } # if (!$c->send('', '', 'LOGOUT')) { # alarm 0; # push @longerr, "$Server: Unable to logout: $@"; # return 0; # } # alarm 0; # return 1; # }; eval { 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 push @longerr, "$Server: Unable to connect"; return ''; } $in = <S>; if ($in !~ /^\* (OK|PREAUTH|BYE)/) { alarm 0; push @longerr, "$Server: No IMAP banner received"; return 0; } $cmd="login"; print S "A1 LOGIN $USER $PASS\r\n"; while (defined($in=<S>)) { if ($in =~ /^A1 (\w+) (.*)/) { if ($1 eq "OK") { $ServerOK = 1; } else { $errmsg="$1 $2"; } last; } } if ($ServerOK && $MAILBOX) { $cmd="examine"; $ServerOK=0; print S "A2 EXAMINE $MAILBOX\r\n"; while (defined($in=<S>)) { if ($in =~ /^A2 (\w+) (.*)/) { if ($1 eq "OK") { $ServerOK = 1; } else { $errmsg="$1 $2"; } last; } } } if ($ServerOK) { $cmd="logout"; $ServerOK=0; print S "A3 LOGOUT\r\n"; while (defined($in=<S>)) { if ($in =~ /^A3 (\w+) (.*)/) { if ($1 eq "OK") { $ServerOK = 1; } else { $errmsg="$1 $2"; } last; } } } if (!$ServerOK) { if ($errmsg) { push @longerr, "$Server: bad response to $cmd: $errmsg"; } else { push @longerr, "$Server: No response to $cmd"; } } close(S); alarm 0; # Cancel the alarm }; if ($EVAL_ERROR and ($EVAL_ERROR =~ /^Timeout Alarm/)) { push @longerr, "$Server: **** Time Out"; return 0; } elsif ($EVAL_ERROR) { push @longerr, "$Server: $EVAL_ERROR"; return 0; } return $ServerOK; } sub OpenSocket { # # Make a Berkeley socket connection between this program and a TCP port # 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, $result); $OurHostname = &hostname; ($name, $aliases, $proto) = getprotobyname('tcp'); ($name, $aliases, $Port) = getservbyname($Port, 'tcp') unless $Port =~ /^\d+$/; ($name, $aliases, $type, $len, $ThisAddr) = gethostbyname($OurHostname); ($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; select(S); $| = 1; select(STDOUT); # set S to be un-buffered return 1; # success } |
From: David N. <vi...@us...> - 2005-08-20 14:38:20
|
Update of /cvsroot/mon/mon-contrib/monitors/imap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14597/imap Log Message: Directory /cvsroot/mon/mon-contrib/monitors/imap added to the repository |
From: David N. <vi...@us...> - 2005-07-31 17:02:47
|
Update of /cvsroot/mon/mon/doc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12955 Modified Files: mon.8 README.protocol Log Message: Added documentation of view related commands and configuration. Index: mon.8 =================================================================== RCS file: /cvsroot/mon/mon/doc/mon.8,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** mon.8 31 Jul 2005 15:49:23 -0000 1.5 --- mon.8 31 Jul 2005 17:02:38 -0000 1.6 *************** *** 208,211 **** --- 208,217 ---- availability, or SNMP events. .TP + .BI view + A collection of hostgroups, used to filter mon output for client display. + i.e. a 'network-services' view might be defined so your network staff + can see just the hostgroups which matter to them, without having to see + all hostgroups defined in Mon. + .TP .BI watch A collection of services which apply to a particular group. *************** *** 944,947 **** --- 950,973 ---- .RE + .SS "View Entries" + View entries begin with the keyword + .BR view , + and are followed by a view tag and the names of one or more + hostgroups. The view tag must be composed of alphanumeric + characters, a dash ("-"), a period ("."), + or an underscore ("_"). Non-blank lines following + the first view line are interpreted as more hostgroup names. + The view definition ends with a blank line. For example: + + .RS + .nf + view servers dns-servers web-servers file-servers + mail-servers + + view network-services routers switches vpn-servers + .fi + .RE + + .SS "Watch Group Entries" Index: README.protocol =================================================================== RCS file: /cvsroot/mon/mon/doc/README.protocol,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** README.protocol 9 Jun 2004 05:18:06 -0000 1.1.1.1 --- README.protocol 31 Jul 2005 17:02:38 -0000 1.2 *************** *** 114,117 **** --- 114,121 ---- set {group} {service} {variable} {value} + setview {view} + + getview + get maxkeep *************** *** 152,155 **** --- 156,161 ---- list dtlog + list views + ack {group} {service} {comment} |
From: David N. <vi...@us...> - 2005-07-31 16:59:23
|
Update of /cvsroot/mon/mon/clients In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12163 Modified Files: mon.cgi Log Message: Added views support. Index: mon.cgi =================================================================== RCS file: /cvsroot/mon/mon/clients/mon.cgi,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** mon.cgi 17 Apr 2005 07:42:26 -0000 1.3 --- mon.cgi 31 Jul 2005 16:59:13 -0000 1.4 *************** *** 141,144 **** --- 141,145 ---- $logo $logo_link $reload_time $monhost $monport $url $login_expire_time $cookie_name $cookie_path %cgiparams + $vcookie_name $vcookie_path $vcookie @views $curview $monhost_and_port_args $monhost_and_port_args_meta $has_read_config $moncgi_config_file $cf_file_mtime *************** *** 219,222 **** --- 220,226 ---- $cookie_path = "/"; # path for auth cookie # Set this to "" for auto-path set + $vcookie_name = "monview-cookie"; #name of cookie given to browser for auth + $vcookie_path = "/"; # path for auth cookie + # Set this to "" for auto-path set $untaint_ack_msgs = "yes"; # Use HTML::Entities to scrub user-supplied ack messages (recommended!) # Define optional regexes in the @show_watch variable, *************** *** 478,481 **** --- 482,486 ---- # sub mon_connect ; + sub mon_views; sub mon_list_group ; sub mon_list_watch ; *************** *** 754,759 **** -path=>"$cookie_path", ); print $webpage->header( ! -cookie=>$cookie, -refresh=>"$reload_time; URL=$refresh_url", ); --- 759,765 ---- -path=>"$cookie_path", ); + mon_views(); print $webpage->header( ! -cookie=>[$cookie,$vcookie], -refresh=>"$reload_time; URL=$refresh_url", ); *************** *** 761,765 **** --- 767,773 ---- # Plain & simple, no cookie, no passsword $encrypted_password = "" ; + mon_views(); print $webpage->header( + -cookie => [$vcookie], -refresh=>"$reload_time; URL=$refresh_url", ); *************** *** 802,806 **** } else { #just print the generic page with no logo and no link ! $webpage->print("<h1><font color=$title_color>MON: $title</font></h1>\n"); } &print_bar; --- 810,823 ---- } else { #just print the generic page with no logo and no link ! $webpage->print("<table width=100% border=0><tr><td><h1><font color=$title_color>MON: $title</font></h1></td>\n"); ! if (@views) { ! $webpage->print("<td align=right valign=bottom>", ! $webpage->start_form, ! $webpage->popup_menu(-name=>'setview', -values=>["--all--",sort(@views)], -default=>$curview), ! $webpage->submit(-name=>'Change View'), ! $webpage->end_form, ! "</td>"); ! } ! $webpage->print("</tr></table>\n"); } &print_bar; *************** *** 830,833 **** --- 847,853 ---- (" (<a href=\"$url?${monhost_and_port_args}command=moncgi_login\">log in</a>)"); } + if ($curview && $curview ne '--all--') { + $webpage->print("<br />Current View: $curview. If you're not seeing what you're expecting to see, try changing views via the menu at the top of this page."); + } $webpage->print(".</center>"); *************** *** 2147,2150 **** --- 2167,2197 ---- } + sub mon_views { + my ($viewreq); + + my $conn = &mon_connect ; + return 0 if $conn == 0; + + @views = $c->list_views (); + print STDERR "list_views failed" if ($c->error); + $viewreq = $webpage->param(-name=>"setview"); + if ($viewreq && ($viewreq eq '--all--' || grep(/^$viewreq$/, @views))) { + $vcookie = $webpage->cookie(-name=>"$vcookie_name", + -value=>"$viewreq", + -expires=>"+1y", + -path=>"$vcookie_path", + ); + $curview = $viewreq; + } else { + $curview = $webpage->cookie(-name=>"$vcookie_name"); + } + + if ($curview && $curview ne '--all--') { + $c->setview($curview); + } + + return 1; + } + sub mon_list_group { |