diff --git a/src/warden-server/bin/getClients.pl b/src/warden-server/bin/getClients.pl index 015c769fb5b09b9bef072ef663007dd84d5775d6..c3aef65e969ead249381898640bc518372c7d2c8 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 fd043bd4f8efefee4d023237c72f66dbef10285e..aef66c97dbb66a91e55c586ffe742bf4246efb41 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