Mailing List Archive

[PATCH] ldirectord: Add/change some useful log output for "monitorfile" option
Hi,

I added the "monitorfile" option to ldirectord some time ago. The patch
below by Fernanda Weiden adds some useful log output for other check
types than HTTP and also changes the log format to something more
human-readable.

Julius

diff -r e0f9eeef2e31 ldirectord/ldirectord.in
--- a/ldirectord/ldirectord.in Thu Aug 07 17:15:05 2008 +1000
+++ b/ldirectord/ldirectord.in Fri Aug 08 15:37:30 2008 +0200
@@ -2452,7 +2452,7 @@ sub check_http
my $recstr = $$r{receive};
if ($res->is_success && (!($recstr =~ /.+/) ||
$res->content =~ /$recstr/)) {
- service_set($v, $r, "up", {do_log => 1}, $res->content);
+ service_set($v, $r, "up", {do_log => 1}, $res->status_line);
&ld_debug(2, "check_http: $$r{url} is up\n");
return $SERVICE_UP;
}
@@ -2629,7 +2629,7 @@ sub check_ldap
my $ldap = Net::LDAP->new("$$r{server}", port => $port,
timeout => $$v{negotiatetimeout});
if(!$ldap) {
- service_set($v, $r, "down", {do_log => 1});
+ service_set($v, $r, "down", {do_log => 1}, "Connection failed");
&ld_debug(4, "Connection failed");
return $SERVICE_DOWN;
}
@@ -2642,7 +2642,7 @@ sub check_ldap
$mesg = $ldap->bind ;
}
if ($mesg->is_error) {
- service_set($v, $r, "down", {do_log => 1});
+ service_set($v, $r, "down", {do_log => 1}, "Bind failed");
&ld_debug(4, "Bind failed");
return $SERVICE_DOWN;
}
@@ -2655,7 +2655,7 @@ sub check_ldap
);

if($result->count != 1) {
- service_set($v, $r, "down", {do_log => 1});
+ service_set($v, $r, "down", {do_log => 1}, "No answer received");
&ld_debug(2, "Count failed : " . $result->count);
return $SERVICE_DOWN;
}
@@ -2663,10 +2663,10 @@ sub check_ldap
my $href = $result->as_struct;
my @arrayOfDNs = keys %$href ;
if (!($recstr =~ /.+/) || $arrayOfDNs[0] =~ /$recstr/) {
- service_set($v, $r, "up", {do_log => 1});
- return $SERVICE_UP;
- } else {
- service_set($v, $r, "down", {do_log => 1});
+ service_set($v, $r, "up", {do_log => 1}, "Success");
+ return $SERVICE_UP;
+ } else {
+ service_set($v, $r, "down", {do_log => 1}, "Response mismatch");
&ld_debug(4,"Message differs : " . ", " . $$r{receive}
. ", " . $arrayOfDNs[0] . ".");
return $SERVICE_DOWN;
@@ -3178,19 +3178,19 @@ sub check_dns
};

if (@$ eq "timeout\n" or ! $query) {
- service_set($v, $r, "down", {do_log => 1});
+ service_set($v, $r, "down", {do_log => 1}, "Connection timed out");
return $SERVICE_DOWN;
}

foreach $rr ($query->answer) {
if (($rr->type eq "A" and $rr->address eq $$r{"receive"}) or
($rr->type eq "PTR" and $rr->ptrdname eq $$r{"receive"})) {
- service_set($v, $r, "up", {do_log => 1});
+ service_set($v, $r, "up", {do_log => 1}, "Success");
return $SERVICE_UP;
}
}

- service_set($v, $r, "down", {do_log => 1});
+ service_set($v, $r, "down", {do_log => 1}, "Response mismatch");
return $SERVICE_DOWN;
}

@@ -3264,7 +3264,7 @@ sub service_set()
my ($real, $virtual, $virt, $now);

if ($$flags{'do_log'}) {
- $now = time();
+ $now = localtime();

if (!defined($log_msg)) {
$log_msg = "-";
@@ -3311,9 +3311,12 @@ sub service_set()
}

if ($$v{"monitorfile"} and $$flags{"do_log"}) {
+ my $real_log_msg = $real_id;
+ $real_log_msg =~ tr/:/ /s;
+ $real_log_msg =~ s/\\//g;
unless(
open(CHECKLOG, ">>$$v{monitorfile}") and
- print CHECKLOG "$now|$$|$real_id|$state|$log_msg\n" and
+ print CHECKLOG "[$now] [$$] $real_log_msg [$state] $log_msg\n" and
close(CHECKLOG)
) { die("Error writing to monitorfile '$$v{monitorfile}': $!"); }
}

_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/
Re: [PATCH] ldirectord: Add/change some useful log output for "monitorfile" option [ In reply to ]
On Fri, Aug 08, 2008 at 04:33:16PM +0200, Julius Volz wrote:
> Hi,
>
> I added the "monitorfile" option to ldirectord some time ago. The patch
> below by Fernanda Weiden adds some useful log output for other check
> types than HTTP and also changes the log format to something more
> human-readable.

Thanks Julius, applied.
_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/