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
digimer-bot 4 years ago committed by GitHub
commit ae0873c790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      Anvil/Tools/Database.pm
  2. 1
      Anvil/Tools/Template.pm
  3. 5
      cgi-bin/Makefile.am
  4. 65
      cgi-bin/get_anvil_status
  5. 40
      cgi-bin/get_anvils
  6. 4
      html/skins/alteeve/shared.html

@ -1976,7 +1976,7 @@ WHERE
my $anvil_node1_host_uuid = defined $row->[4] ? $row->[4] : "";
my $anvil_node2_host_uuid = defined $row->[5] ? $row->[5] : "";
my $anvil_dr1_host_uuid = defined $row->[6] ? $row->[6] : "";
my $modified_date = $row->[5];
my $modified_date = $row->[7];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
anvil_uuid => $anvil_uuid,
anvil_name => $anvil_name,
@ -2006,6 +2006,8 @@ WHERE
"anvils::anvil_uuid::${anvil_uuid}::modified_date" => $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{modified_date},
}});
### NOTE: This is used in the 'get_anvils' CGI so we store the query time to allow the client
### side to know that the data is fresh.
$anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_uuid} = $anvil_uuid;
$anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_description} = $anvil_description;
$anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_password} = $anvil_password;
@ -2013,6 +2015,7 @@ WHERE
$anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_node2_host_uuid} = $anvil_node2_host_uuid;
$anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_dr1_host_uuid} = $anvil_dr1_host_uuid;
$anvil->data->{anvils}{anvil_name}{$anvil_name}{modified_date} = $modified_date;
$anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{query_time} = time;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
"anvils::anvil_name::${anvil_name}::anvil_uuid" => $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_uuid},
"anvils::anvil_name::${anvil_name}::anvil_description" => $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_description},
@ -2021,6 +2024,7 @@ WHERE
"anvils::anvil_name::${anvil_name}::anvil_node2_host_uuid" => $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_node2_host_uuid},
"anvils::anvil_name::${anvil_name}::anvil_dr1_host_uuid" => $anvil->data->{anvils}{anvil_name}{$anvil_name}{anvil_dr1_host_uuid},
"anvils::anvil_name::${anvil_name}::modified_date" => $anvil->data->{anvils}{anvil_name}{$anvil_name}{modified_date},
"anvils::anvil_name::${anvil_name}::query_time" => $anvil->data->{anvils}{anvil_name}{$anvil_name}{query_time},
}});
if ($anvil_node1_host_uuid)

@ -149,6 +149,7 @@ sub get
# The 'http_headers' template can never show the name
$show_name = 0 if $name eq "http_headers";
$show_name = 0 if $name eq "json_headers";
my $error = 0;
if (not $file)

@ -3,4 +3,7 @@ MAINTAINERCLEANFILES = Makefile.in
cgibindir = $(localstatedir)/www/cgi-bin
dist_cgibin_SCRIPTS = \
striker \
upload.pl
upload.pl \
get_anvils \
get_anvil_status

@ -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";

@ -2,6 +2,10 @@
Content-type: text/html; charset=utf-8
<!-- end http_headers -->
<!-- start json_headers -->
Content-type: application/json; charset=utf-8
<!-- end json_headers -->
<!-- start http_headers-no-cache -->
Content-type: text/html; charset=utf-8
Cache-Control: no-cache, no-store, must-revalidate

Loading…
Cancel
Save