Merge pull request #38 from ClusterLabs/webui_anvil_page
* This adds two new files; cgi-bin/get_anvils and cgi-bin/get_anvil_s…main
commit
ae0873c790
6 changed files with 120 additions and 3 deletions
@ -0,0 +1,65 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# This prints JSON formated data reporting the status of an Anvil! system and it's member hosts. |
||||
# |
||||
|
||||
use strict; |
||||
use warnings; |
||||
use Anvil::Tools; |
||||
use Data::Dumper; |
||||
use JSON; |
||||
|
||||
$| = 1; |
||||
|
||||
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
||||
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
||||
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
||||
{ |
||||
$running_directory =~ s/^\./$ENV{PWD}/; |
||||
} |
||||
|
||||
my $anvil = Anvil::Tools->new(); |
||||
|
||||
$anvil->Get->switches; |
||||
|
||||
$anvil->Database->connect; |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); |
||||
if (not $anvil->data->{sys}{database}{connections}) |
||||
{ |
||||
# No databases, exit. |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"}); |
||||
$anvil->nice_exit({exit_code => 1}); |
||||
} |
||||
|
||||
# Read in any CGI variables, if needed. |
||||
$anvil->Get->cgi(); |
||||
|
||||
$anvil->Database->get_hosts(); |
||||
$anvil->Database->get_anvils(); |
||||
|
||||
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n"; |
||||
|
||||
my $anvil_uuid = $anvil->data->{cgi}{anvil_uuid}{value}; |
||||
if ((not $anvil_uuid) or (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})) |
||||
{ |
||||
$anvil->data->{anvil_status}{anvil_name} = "!!invalid!anvil_uuid!!"; |
||||
} |
||||
else |
||||
{ |
||||
$anvil->data->{anvil_status}{anvil_name} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name}; |
||||
$anvil->data->{anvil_status}{anvil_description} = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_description}; |
||||
$anvil->data->{anvil_status}{timestamp} = time; |
||||
|
||||
my $node1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; |
||||
my $node2_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid}; |
||||
my $node2_status = $anvil->data->{hosts}{host_uuid}{$node2_uuid}{host_status} eq "online" ? 1 : 0; |
||||
|
||||
$anvil->data->{anvil_status}{nodes}{node1}{host_name} = $anvil->data->{hosts}{host_uuid}{$node1_uuid}{host_name}; |
||||
$anvil->data->{anvil_status}{nodes}{node1}{host_uuid} = $node1_uuid; |
||||
$anvil->data->{anvil_status}{nodes}{node1}{host_status} = $anvil->data->{hosts}{host_uuid}{$node1_uuid}{host_status} eq "online" ? 1 : 0; |
||||
$anvil->data->{anvil_status}{nodes}{node2}{host_name} = $anvil->data->{hosts}{host_uuid}{$node2_uuid}{host_name}; |
||||
$anvil->data->{anvil_status}{nodes}{node2}{host_uuid} = $node2_uuid; |
||||
$anvil->data->{anvil_status}{nodes}{node2}{host_status} = $anvil->data->{hosts}{host_uuid}{$node2_uuid}{host_status} eq "online" ? 1 : 0; |
||||
} |
||||
|
||||
print JSON->new->utf8->encode($anvil->data->{anvil_status})."\n"; |
@ -0,0 +1,40 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# This prints JSON formated data reporting the Anvil! systems in the database (ignoring DELETED ones). |
||||
# |
||||
|
||||
use strict; |
||||
use warnings; |
||||
use Anvil::Tools; |
||||
use Data::Dumper; |
||||
use JSON; |
||||
|
||||
$| = 1; |
||||
|
||||
my $THIS_FILE = ($0 =~ /^.*\/(.*)$/)[0]; |
||||
my $running_directory = ($0 =~ /^(.*?)\/$THIS_FILE$/)[0]; |
||||
if (($running_directory =~ /^\./) && ($ENV{PWD})) |
||||
{ |
||||
$running_directory =~ s/^\./$ENV{PWD}/; |
||||
} |
||||
|
||||
my $anvil = Anvil::Tools->new(); |
||||
|
||||
$anvil->Get->switches; |
||||
|
||||
$anvil->Database->connect; |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => "log_0132"}); |
||||
if (not $anvil->data->{sys}{database}{connections}) |
||||
{ |
||||
# No databases, exit. |
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0003"}); |
||||
$anvil->nice_exit({exit_code => 1}); |
||||
} |
||||
|
||||
# Read in any CGI variables, if needed. |
||||
$anvil->Get->cgi(); |
||||
$anvil->Database->get_anvils(); |
||||
|
||||
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n"; |
||||
print JSON->new->utf8->encode($anvil->data->{anvils}{anvil_name})."\n"; |
||||
|
Loading…
Reference in new issue