diff --git a/src/warden-server/bin/getStatus.pl b/src/warden-server/bin/getStatus.pl index e8988812333511275f33179dd03465ddca0a9090..c93b89aed540cc1a03098cb982082b2f8a56f4a6 100755 --- a/src/warden-server/bin/getStatus.pl +++ b/src/warden-server/bin/getStatus.pl @@ -115,7 +115,8 @@ print "\n"; # check if sum of registered client isn't 0 if ($server_status[15] != 0) { - print "Statistics of registered senders:\n"; + print "Statistics of active registered senders:\n"; + print "========================================\n"; print "+----------------------------------------------------------------------------------------------------------------+\n"; print "| Client ID | Hostname | Service | Stored events | Last insertion (UTC) |\n"; print "+----------------------------------------------------------------------------------------------------------------+\n"; diff --git a/src/warden-server/doc/README b/src/warden-server/doc/README index afcfbaa4528790444642bd2c69d1170472ebd595..b964138930e6669d31ef2e6f51515bffda328a6d 100644 --- a/src/warden-server/doc/README +++ b/src/warden-server/doc/README @@ -315,7 +315,8 @@ F. Status Info 1. Get Status Function getStatus is accessible via getStatus.pl. Function has no input - parameters and returns info about the Warden server and its DB status. + parameters and returns info about the Warden server, its DB status and + event's statistics of active registered senders. 2. Get Clients diff --git a/src/warden-server/lib/Warden.pm b/src/warden-server/lib/Warden.pm index 3bfe6874879ebf6e111f3658a5995bca0a20d571..cae626682ca3e8019b17fbfb71e6ff411f33214a 100755 --- a/src/warden-server/lib/Warden.pm +++ b/src/warden-server/lib/Warden.pm @@ -71,7 +71,7 @@ sub sendMsg my $soap_msg = shift; my $filename = File::Basename::basename($0); - if ($SYSLOG_VERBOSE == 1) { + if ($SYSLOG_VERBOSE == 1 && ($severity eq "err" || $severity eq "debug")) { $syslog_msg .= "\nStack info: " . Carp::longmess(); } @@ -124,11 +124,13 @@ sub authorizeClient # obtain cidr based on rigth common name and alternate names, service and client_type if($function_name eq 'saveNewEvent') { $sth = $DBH->prepare("SELECT hostname, ip_net_client, receive_own_events - FROM clients WHERE hostname IN ($alt_names) AND service = ? AND client_type = ? + FROM clients + WHERE hostname IN ($alt_names) AND service = ? AND client_type = ? ORDER BY SUBSTRING_INDEX(ip_net_client,'/', -1) DESC;"); } elsif($function_name eq 'getNewEvents') { $sth = $DBH->prepare("SELECT hostname, ip_net_client, receive_own_events - FROM clients WHERE hostname IN ($alt_names) AND (type = ? OR type = '_any_') AND client_type = ? + FROM clients + WHERE hostname IN ($alt_names) AND (type = ? OR type = '_any_') AND client_type = ? ORDER BY SUBSTRING_INDEX(ip_net_client,'/', -1) DESC;"); } @@ -689,6 +691,9 @@ sub getStatus my $function_name = 'getStatus'; + #----------------------------------------------------------------------------- + # Warden server stats + if ($local_ip ne $ip) { sendMsg("err", "Unauthorized access to function '$function_name' from: '$ip' ('$cn') - access allowed only from localhost", @@ -786,50 +791,31 @@ sub getStatus )); push(@status, $server_status); - # statistics of senders + #--------------------------------------------------------------------------- + # Statistics table of senders + if ($clients_sum != 0) { - $sth = $DBH->prepare("SELECT client_id, hostname, service FROM clients WHERE client_type = 's' ORDER BY client_id ASC;"); + $sth = $DBH->prepare("SELECT clients.client_id, clients.hostname, clients.service, count(*), max(received) + FROM events + LEFT JOIN clients ON (events.hostname=clients.hostname AND events.service=clients.service) + GROUP BY hostname, service;"); if (!defined $sth) { sendMsg("err", "Cannot prepare statement in function '$function_name': $DBH->errstr", "Internal 'prepare' server error"); } $sth->execute; - my ($client_id, $hostname, $service); - my $client_status; - while(($client_id, $hostname, $service) = $sth->fetchrow()) { - my $sth2; - # sum of stored events - $sth2 = $DBH->prepare("SELECT count(*) FROM events WHERE hostname = ? AND service = ?;"); - if (!defined $sth2) { - sendMsg("err", - "Cannot prepare statement in function '$function_name': $DBH->errstr", - "Internal 'prepare' server error"); - } - $sth2->execute($hostname, $service); - my $count = $sth2->fetchrow(); - if (!defined $count) {$count = "none"} - - # timestamp of last stored event - $sth2 = $DBH->prepare("SELECT max(received) FROM events WHERE hostname = ? AND service = ?;"); - if (!defined $sth2) { - sendMsg("err", - "Cannot prepare statement in function '$function_name': $DBH->errstr\n", - "Internal 'prepare' server error"); - } - $sth2->execute($hostname, $service); - my $timestamp = $sth2->fetchrow(); - if (!defined $timestamp) {$timestamp = "none"} - - # create SOAP data object + my ($hash_ref, $client_id, $hostname, $service, $count, $timestamp, $client_status); + $hash_ref = $sth->fetchall_hashref("client_id"); + foreach my $key (sort {$a<=>$b} keys %$hash_ref) { $client_status = SOAP::Data->name(client_status => \SOAP::Data->value( - SOAP::Data->name(CLIENT_ID => $client_id), - SOAP::Data->name(HOSTNAME => $hostname), - SOAP::Data->name(SERVICE => $service), - SOAP::Data->name(COUNT => $count), - SOAP::Data->name(TIMESTAMP => $timestamp), + SOAP::Data->name(CLIENT_ID => $hash_ref->{$key}->{client_id}), + SOAP::Data->name(HOSTNAME => $hash_ref->{$key}->{hostname}), + SOAP::Data->name(SERVICE => $hash_ref->{$key}->{service}), + SOAP::Data->name(COUNT => $hash_ref->{$key}->{"count(*)"}), + SOAP::Data->name(TIMESTAMP => $hash_ref->{$key}->{"max(received)"}), )); - push(@status, $client_status); + push(@status, $client_status); } } sendMsg("info",