Skip to content
Snippets Groups Projects
Commit 85924b79 authored by Tomáš Plesník's avatar Tomáš Plesník
Browse files

zmena tahani statistik z DB pomoci jednoho selectu, zruseno dotazovani se na...

zmena tahani statistik z DB pomoci jednoho selectu, zruseno dotazovani se na statistiky kazdeho klienta pomoci cyklu
parent bc1d5e82
No related branches found
Tags warden-server-2.1-aplha1
No related merge requests found
......@@ -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";
......
......@@ -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
......
......@@ -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",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment