You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.7 KiB
76 lines
2.7 KiB
#!/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}); |
|
} |
|
|
|
my $cookie_problem = $anvil->Account->read_cookies(); |
|
|
|
# Don't do anything data-related if the user is not logged in. |
|
if ($cookie_problem) |
|
{ |
|
$anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0307" }); |
|
$anvil->nice_exit({ exit_code => 1 }); |
|
} |
|
|
|
# Read in any CGI variables, if needed. |
|
$anvil->Get->cgi(); |
|
|
|
$anvil->Database->get_hosts(); |
|
$anvil->Database->get_anvils(); |
|
|
|
my $json_hash = {}; |
|
$json_hash->{anvils} = []; |
|
|
|
foreach my $anvil_uuid (keys %{$anvil->data->{anvils}{anvil_uuid}}) |
|
{ |
|
my $anvil_name = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_name}; |
|
my $anvil_description = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_description}; |
|
my $anvil_password = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_password}; |
|
my $anvil_node1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node1_host_uuid}; |
|
my $anvil_node1_host_name = $anvil->data->{hosts}{host_uuid}{$anvil_node1_host_uuid}{short_host_name}; |
|
my $anvil_node2_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_node2_host_uuid}; |
|
my $anvil_node2_host_name = $anvil->data->{hosts}{host_uuid}{$anvil_node2_host_uuid}{short_host_name}; |
|
my $anvil_dr1_host_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}; |
|
my $anvil_dr1_host_name = $anvil->data->{hosts}{host_uuid}{$anvil_dr1_host_uuid}{short_host_name}; |
|
|
|
push @{$json_hash->{anvils}}, { |
|
anvil_name => $anvil_name, |
|
anvil_uuid => $anvil_uuid, |
|
hosts => [ |
|
{ host_name => $anvil_node1_host_name, host_uuid => $anvil_node1_host_uuid }, |
|
{ host_name => $anvil_node2_host_name, host_uuid => $anvil_node2_host_uuid }, |
|
{ host_name => $anvil_dr1_host_name, host_uuid => $anvil_dr1_host_uuid } |
|
] |
|
}; |
|
} |
|
|
|
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n"; |
|
print JSON->new->utf8->encode($json_hash)."\n";
|
|
|