From cc3da0eb079b9b8e9b76d43ff59d979232c89597 Mon Sep 17 00:00:00 2001
From: Tomas Plesnik <plesnik@ics.muni.cz>
Date: Tue, 29 Jan 2013 13:59:07 +0100
Subject: [PATCH] presunuto nacitani konfiguracniho souboru; zmena formatovani
 if podminek

---
 src/warden-server/bin/getClients.pl | 30 ++++++-----
 src/warden-server/bin/getStatus.pl  | 80 +++++++++++++++++++----------
 2 files changed, 69 insertions(+), 41 deletions(-)

diff --git a/src/warden-server/bin/getClients.pl b/src/warden-server/bin/getClients.pl
index 015c769..c3aef65 100755
--- a/src/warden-server/bin/getClients.pl
+++ b/src/warden-server/bin/getClients.pl
@@ -22,6 +22,18 @@ use WardenCommon;
 our $VERSION = "2.2";
 my $etc = "$FindBin::RealBin/../etc";
 
+# read config file
+my $conf_file = "$etc/warden-server.conf";
+our $DB_NAME            = undef;
+our $DB_USER            = undef;
+our $DB_PASS            = undef;
+our $DB_HOST            = undef;
+unless (do $conf_file) {
+  die("Errors in config file '$conf_file': $@") if $@;
+  die("Can't read config file '$conf_file': $!") unless defined $_;
+  # if $_ defined, it's retvalue of last statement of conf, for which we don't care
+}
+
 
 
 ################################################################################
@@ -43,22 +55,14 @@ die usage unless getopts("h");
 my $help = $opt_h;
 
 # catch help param
-if ($help) {usage}
+if ($help) {
+  usage;
+}
 
 # superuser controle
 my $UID = $<;
-if ($UID != 0) {WardenCommon::errMsg("You must be root for running this script!")}
-
-# read config file
-my $conf_file = "$etc/warden-server.conf";
-our $DB_NAME            = undef;
-our $DB_USER            = undef;
-our $DB_PASS            = undef;
-our $DB_HOST            = undef;
-unless (do $conf_file) {
-  die("Errors in config file '$conf_file': $@") if $@;
-  die("Can't read config file '$conf_file': $!") unless defined $_;
-  # if $_ defined, it's retvalue of last statement of conf, for which we don't care
+if ($UID != 0) {
+  WardenCommon::errMsg("You must be root for running this script!");
 }
 
 # connect to DB
diff --git a/src/warden-server/bin/getStatus.pl b/src/warden-server/bin/getStatus.pl
index fd043bd..aef66c9 100755
--- a/src/warden-server/bin/getStatus.pl
+++ b/src/warden-server/bin/getStatus.pl
@@ -23,6 +23,23 @@ use WardenCommon;
 our $VERSION = "2.2";
 my $etc = "$FindBin::RealBin/../etc";
 
+# read config file
+my $conf_file = "$etc/warden-server.conf";
+our $BASEDIR		= undef
+our $SYSLOG             = undef;
+our $SYSLOG_VERBOSE     = undef;
+our $SYSLOG_FACILITY    = undef;
+our $DB_NAME            = undef;
+our $DB_USER            = undef;
+our $DB_PASS            = undef;
+our $DB_HOST            = undef;
+our $MAX_EVENTS_LIMIT 	= undef;
+unless (do $conf_file) {
+  die("Errors in config file '$conf_file': $@") if $@;
+  die("Can't read config file '$conf_file': $!") unless defined $_;
+  # if $_ defined, it's retvalue of last statement of conf, for which we don't care
+}
+
 
 
 ################################################################################
@@ -44,27 +61,14 @@ die usage unless getopts("h");
 my $help = $opt_h;
 
 # catch help param
-if ($help) {usage}
+if ($help) {
+  usage;
+}
 
 # superuser controle
 my $UID = $<;
-if ($UID != 0) {WardenCommon::errMsg("You must be root for running this script!")}
-
-# read config file
-my $conf_file = "$etc/warden-server.conf";
-our $BASEDIR		= undef
-our $SYSLOG             = undef;
-our $SYSLOG_VERBOSE     = undef;
-our $SYSLOG_FACILITY    = undef;
-our $DB_NAME            = undef;
-our $DB_USER            = undef;
-our $DB_PASS            = undef;
-our $DB_HOST            = undef;
-our $MAX_EVENTS_LIMIT 	= undef;
-unless (do $conf_file) {
-  die("Errors in config file '$conf_file': $@") if $@;
-  die("Can't read config file '$conf_file': $!") unless defined $_;
-  # if $_ defined, it's retvalue of last statement of conf, for which we don't care
+if ($UID != 0) {
+  WardenCommon::errMsg("You must be root for running this script!");
 }
 
 # connect to DB
@@ -103,61 +107,81 @@ my $db_size = defined $size ? Format::Human::Bytes::base10($size) : "none";
 $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 = $sth->fetchrow();
-if (!defined $events_sum) {$events_sum = "none"}
+if (!defined $events_sum) {
+  $events_sum = "none";
+}
 
 # sum of records in table events (with invalid)
 $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_inv = $sth->fetchrow();
-if (!defined $events_sum_inv) {$events_sum_inv = "none"}
+if (!defined $events_sum_inv) {
+  $events_sum_inv = "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) {$events_last_id = "none"}
+if (!defined $events_last_id) {
+  $events_last_id = "none";
+}
 
 # id of last record in table events (with invalid)
 $sth = $DBH->prepare("SELECT max(id) FROM events;") or die "Cannot prepare statement: " . $DBH->errstr;
 $sth->execute or die "Cannot execute statement: " . $sth->errstr;
 my $events_last_id_inv = $sth->fetchrow();
-if (!defined $events_last_id_inv) {$events_last_id_inv = "none"}
+if (!defined $events_last_id_inv) {
+  $events_last_id_inv = "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) {$events_first_timestamp = "none"}
+if (!defined $events_first_timestamp) {
+  $events_first_timestamp = "none";
+}
 
 # timestamp of first record in table events (with invalid)
 $sth = $DBH->prepare("SELECT received FROM events WHERE id = (SELECT min(id) FROM events);") or die "Cannot prepare statement: " . $DBH->errstr;
 $sth->execute or die "Cannot execute statement: " . $sth->errstr;
 my $events_first_timestamp_inv = $sth->fetchrow();
-if (!defined $events_first_timestamp_inv) {$events_first_timestamp_inv = "none"}
+if (!defined $events_first_timestamp_inv) {
+  $events_first_timestamp_inv = "none";
+}
 
 # timestamp of last record in table events
 $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) {$events_last_timestamp = "none"}
+if (!defined $events_last_timestamp) {
+  $events_last_timestamp = "none";
+}
 
 # timestamp of last record in table events (with invalid)
 $sth = $DBH->prepare("SELECT received FROM events WHERE id = (SELECT max(id) FROM events);") or die "Cannot prepare statement: " . $DBH->errstr;
 $sth->execute or die "Cannot execute statement: " . $sth->errstr;
 my $events_last_timestamp_inv = $sth->fetchrow();
-if (!defined $events_last_timestamp_inv) {$events_last_timestamp_inv = "none"}
+if (!defined $events_last_timestamp_inv) {
+  $events_last_timestamp_inv = "none";
+}
 
 # sum of records in table clients
 $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 = $sth->fetchrow();
-if (!defined $clients_sum) {$clients_sum = "none"}
+if (!defined $clients_sum) {
+  $clients_sum = "none";
+}
 
 # sum of records in table clients (with invalid)
 $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_inv = $sth->fetchrow();
-if (!defined $clients_sum_inv) {$clients_sum_inv = "none"}
+if (!defined $clients_sum_inv) {
+  $clients_sum_inv = "none";
+}
 
 #-------------------------------------------------------------------------------
 # Statistics of active registered senders
-- 
GitLab