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

uprava db dotazu pro vetsi prehlednost; lepsi prehlednost kodu (nahrazeni...

uprava db dotazu pro vetsi prehlednost; lepsi prehlednost kodu (nahrazeni negovanych ifu za unless); smazani stareho dotazu
parent 9fbeb904
No related branches found
No related tags found
No related merge requests found
......@@ -105,12 +105,11 @@ $sth->execute($WardenCommon::DB_NAME, 'events') or die "Cannot execute statement
my $size = $sth->fetchrow();
my $db_size = defined $size ? Format::Human::Bytes::base10($size) : "none";
# sum of all records in table events
$sth = $dbh->prepare("SELECT count(*) FROM events;") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $events_sum = $sth->fetchrow();
if (!defined $events_sum) {
unless (defined $events_sum) {
$events_sum = "none";
}
......@@ -118,7 +117,7 @@ if (!defined $events_sum) {
$sth = $dbh->prepare("SELECT count(*) FROM events WHERE valid = 't';") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $events_sum_valid = $sth->fetchrow();
if (!defined $events_sum_valid) {
unless (defined $events_sum_valid) {
$events_sum_valid = "none";
}
......@@ -126,7 +125,7 @@ if (!defined $events_sum_valid) {
$sth = $dbh->prepare("SELECT count(*) FROM events WHERE valid = 'o';") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $events_sum_obsolete = $sth->fetchrow();
if (!defined $events_sum_obsolete) {
unless (defined $events_sum_obsolete) {
$events_sum_obsolete = "none";
}
......@@ -134,25 +133,23 @@ if (!defined $events_sum_obsolete) {
$sth = $dbh->prepare("SELECT count(*) FROM events WHERE valid = 'f';") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $events_sum_invalid = $sth->fetchrow();
if (!defined $events_sum_invalid) {
unless (defined $events_sum_invalid) {
$events_sum_invalid = "none";
}
# id of last record in table events
$sth = $dbh->prepare("SELECT max(id) FROM events WHERE valid = 't';") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $events_last_id = $sth->fetchrow();
if (!defined $events_last_id) {
unless (defined $events_last_id) {
$events_last_id = "none";
}
# timestamp of first record in table events
$sth = $dbh->prepare("SELECT received FROM events WHERE id = (SELECT min(id) FROM events WHERE valid = 't');") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $events_first_timestamp = $sth->fetchrow();
if (!defined $events_first_timestamp) {
unless (defined $events_first_timestamp) {
$events_first_timestamp = "none";
}
......@@ -160,7 +157,7 @@ if (!defined $events_first_timestamp) {
$sth = $dbh->prepare("SELECT received FROM events WHERE id = (SELECT max(id) FROM events WHERE valid = 't');") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $events_last_timestamp = $sth->fetchrow();
if (!defined $events_last_timestamp) {
unless (defined $events_last_timestamp) {
$events_last_timestamp = "none";
}
......@@ -169,7 +166,7 @@ if (!defined $events_last_timestamp) {
$sth = $dbh->prepare("SELECT count(*) FROM clients;") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $clients_sum = $sth->fetchrow();
if (!defined $clients_sum) {
unless (defined $clients_sum) {
$clients_sum = "none";
}
......@@ -177,25 +174,23 @@ if (!defined $clients_sum) {
$sth = $dbh->prepare("SELECT count(*) FROM clients WHERE valid = 't';") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $clients_sum_valid = $sth->fetchrow();
if (!defined $clients_sum_valid) {
unless (defined $clients_sum_valid) {
$clients_sum_valid = "none";
}
# sum of invaled records in table clients
# sum of invalid records in table clients
$sth = $dbh->prepare("SELECT count(*) FROM clients WHERE valid = 'f';") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my $clients_sum_invalid = $sth->fetchrow();
if (!defined $clients_sum_invalid) {
unless (defined $clients_sum_invalid) {
$clients_sum_invalid = "none";
}
#-------------------------------------------------------------------------------
# Statistics of active registered senders
my $hash_ref;
if ($clients_sum != 0) {
# $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) WHERE clients.valid='t' AND events.valid='t' GROUP BY client_id;") or die "Cannot prepare statement: " . $dbh->errstr;
$sth = $dbh->prepare("SELECT clients.client_id, clients.hostname, clients.service, count(*), max(received) FROM events LEFT JOIN clients ON (events.client_id=clients.client_id) WHERE clients.valid='t' AND events.valid='t' GROUP BY client_id;") or die "Cannot prepare statement: " . $dbh->errstr;
unless ($clients_sum == 0) {
$sth = $dbh->prepare("SELECT clients.client_id, hostname, service, count(*), max(received) FROM events LEFT JOIN clients ON events.client_id = clients.client_id WHERE clients.valid='t' AND events.valid='t' GROUP BY clients.client_id;") or die "Cannot prepare statement: " . $dbh->errstr;
$sth->execute or die "Cannot execute statement: " . $sth->errstr;
my ($client_id, $hostname, $service, $count, $timestamp, $client_status);
$hash_ref = $sth->fetchall_hashref("client_id");
......@@ -234,7 +229,7 @@ print " - count of valid registered clients:\t$clients_sum_valid\n";
print " - count of invalid registered clients:\t$clients_sum_invalid\n";
print "\n";
if ($clients_sum != 0) {
unless ($clients_sum == 0) {
print "Statistics of ACTIVE and VALID registered senders:\n";
print "==================================================\n";
print "+------------------------------------------------------------------------------------------------------------------------+\n";
......
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