-
Tomáš Plesník authoredTomáš Plesník authored
getStatus.pl 9.57 KiB
#!/usr/bin/perl -w
#
# getStatus.pl
#
# Copyright (C) 2011-2013 Cesnet z.s.p.o
#
# Use of this source is governed by a BSD-style license, see LICENSE file.
use strict;
use Getopt::Std;
use DBI;
use DBD::mysql;
use Format::Human::Bytes;
use FindBin qw($RealBin $RealScript);
use lib "$FindBin::RealBin/../lib";
use WardenCommon;
################################################################################
# VARIABLES
################################################################################
our $VERSION = "2.2";
my $etc = "$FindBin::RealBin/../etc";
# read config file
my $conf_file = "$etc/warden-server.conf";
WardenCommon::loadConf($conf_file);
################################################################################
# FUNCTIONS
################################################################################
sub usage {
print "Usage: $RealScript [without parameters]\n";
exit 1;
}
################################################################################
# MAIN
################################################################################
our ($opt_h);
die usage unless getopts("h");
my $help = $opt_h;
# catch help param
if ($help) {
usage;
}
# superuser controle
my $UID = $<;
if ($UID != 0) {
WardenCommon::errMsg("You must be root for running this script!");
}
# connect to DB
our $DBH = DBI->connect("DBI:mysql:database=$WardenCommon::DB_NAME;host=$WardenCommon::DB_HOST", $WardenCommon::DB_USER, $WardenCommon::DB_PASS, {RaiseError => 1, mysql_auto_reconnect => 1})
|| die "Could not connect to database: $DBI::errstr";
#-----------------------------------------------------------------------------
# Warden server variables
my $package_version = WardenCommon::trim(`cat /opt/warden-server/etc/package_version`);
my $version = substr($package_version, 14);
my $hostname = WardenCommon::trim(`hostname -f`);
my $ip_address = WardenCommon::trim(`hostname -i`);