commit
9aabf27fe6
23 changed files with 1399 additions and 105 deletions
@ -0,0 +1,188 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# This prints JSON formated data reporting the status of CPUs. |
||||
# |
||||
|
||||
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 $target = $anvil->Get->short_host_name(); |
||||
my $hash = {}; |
||||
my $anvil_uuid = ""; |
||||
if ($anvil->data->{cgi}{anvil_uuid}{value}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{cgi}{anvil_uuid}{value}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
elsif ($anvil->data->{switches}{'anvil-uuid'}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{switches}{'anvil-uuid'}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
if ((not $anvil_uuid) or (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})) |
||||
{ |
||||
$anvil->data->{anvil_status}{anvil_name} = "!!invalid!anvil_uuid!!"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'anvil_status::anvil_name' => $anvil->data->{anvil_status}{anvil_name} }}); |
||||
} |
||||
else |
||||
{ |
||||
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 $dr1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
node1_uuid => $node1_uuid, |
||||
node2_uuid => $node2_uuid, |
||||
dr1_uuid => $dr1_uuid, |
||||
}}); |
||||
|
||||
$hash->{cores} = 0; |
||||
$hash->{threads} = 0; |
||||
$hash->{allocated} = 0; |
||||
|
||||
# Do the query |
||||
my $query = " |
||||
SELECT |
||||
a.host_uuid, |
||||
a.host_name, |
||||
b.scan_hardware_cpu_cores, |
||||
b.scan_hardware_cpu_threads |
||||
FROM |
||||
hosts a, scan_hardware b |
||||
WHERE |
||||
a.host_uuid = b.scan_hardware_host_uuid |
||||
AND |
||||
( |
||||
a.host_uuid = ".$anvil->Database->quote($node1_uuid)." |
||||
OR |
||||
a.host_uuid = ".$anvil->Database->quote($node2_uuid); |
||||
if ($dr1_uuid) |
||||
{ |
||||
$query .= " |
||||
OR |
||||
a.host_uuid = ".$anvil->Database->quote($dr1_uuid); |
||||
} |
||||
$query .= " |
||||
) |
||||
ORDER BY |
||||
a.host_name ASC |
||||
;"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); |
||||
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); |
||||
my $count = @{$results}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count, |
||||
}}); |
||||
foreach my $row (@{$results}) |
||||
{ |
||||
my $host_uuid = $row->[0]; |
||||
my $host_name = $row->[1]; |
||||
my $scan_hardware_cpu_cores = $row->[2]; |
||||
my $scan_hardware_cpu_threads = $row->[3]; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
host_uuid => $host_uuid, |
||||
host_name => $host_name, |
||||
scan_hardware_cpu_cores => $scan_hardware_cpu_cores, |
||||
scan_hardware_cpu_threads => $scan_hardware_cpu_threads, |
||||
}}); |
||||
|
||||
if (not $hash->{cores}) |
||||
{ |
||||
$hash->{cores} = $scan_hardware_cpu_cores; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->cores' => $hash->{cores} }}); |
||||
} |
||||
elsif ($scan_hardware_cpu_cores < $hash->{cores}) |
||||
{ |
||||
$hash->{cores} = $scan_hardware_cpu_cores; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->cores' => $hash->{cores} }}); |
||||
} |
||||
if (not $hash->{threads}) |
||||
{ |
||||
$hash->{threads} = $scan_hardware_cpu_threads; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->threads' => $hash->{threads} }}); |
||||
} |
||||
elsif ($scan_hardware_cpu_threads < $hash->{threads}) |
||||
{ |
||||
$hash->{threads} = $scan_hardware_cpu_threads; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->threads' => $hash->{threads} }}); |
||||
} |
||||
} |
||||
|
||||
# Now get the servers from the Anvil! |
||||
$query = " |
||||
SELECT |
||||
a.server_uuid, |
||||
a.server_name, |
||||
b.server_definition_xml |
||||
FROM |
||||
servers a, |
||||
server_definitions b |
||||
WHERE |
||||
a.server_uuid = b.server_definition_server_uuid |
||||
AND |
||||
a.server_anvil_uuid = ".$anvil->Database->quote($anvil_uuid)." |
||||
;"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); |
||||
$results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); |
||||
$count = @{$results}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count, |
||||
}}); |
||||
foreach my $row (@{$results}) |
||||
{ |
||||
my $server_uuid = $row->[0]; |
||||
my $server_name = $row->[1]; |
||||
my $server_definition_xml = $row->[2]; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
's1:server_name' => $server_name, |
||||
's2:server_uuid' => $server_uuid, |
||||
's3:server_definition_xml' => $server_definition_xml, |
||||
}}); |
||||
|
||||
$anvil->Server->parse_definition({ |
||||
server => $server_name, |
||||
source => "from_db", |
||||
definition => $server_definition_xml, |
||||
}); |
||||
|
||||
$hash->{allocated} += $anvil->data->{server}{$target}{$server_name}{from_db}{cpu}{total_cores}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->allocated' => $hash->{allocated} }}); |
||||
} |
||||
|
||||
} |
||||
|
||||
print JSON->new->utf8->encode($hash)."\n"; |
@ -0,0 +1,189 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# This prints JSON formated data reporting the status of RAM on the system. |
||||
# |
||||
|
||||
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 $target = $anvil->Get->short_host_name(); |
||||
my $hash = {}; |
||||
my $anvil_uuid = ""; |
||||
if ($anvil->data->{cgi}{anvil_uuid}{value}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{cgi}{anvil_uuid}{value}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
elsif ($anvil->data->{switches}{'anvil-uuid'}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{switches}{'anvil-uuid'}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
if ((not $anvil_uuid) or (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})) |
||||
{ |
||||
$anvil->data->{anvil_status}{anvil_name} = "!!invalid!anvil_uuid!!"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'anvil_status::anvil_name' => $anvil->data->{anvil_status}{anvil_name} }}); |
||||
} |
||||
else |
||||
{ |
||||
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 $dr1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
node1_uuid => $node1_uuid, |
||||
node2_uuid => $node2_uuid, |
||||
dr1_uuid => $dr1_uuid, |
||||
}}); |
||||
|
||||
$hash->{total} = 0; |
||||
$hash->{allocated} = 0; |
||||
$hash->{nodes} = []; |
||||
|
||||
my @hosts = ($node1_uuid, $node2_uuid); |
||||
if ($dr1_uuid) |
||||
{ |
||||
push @hosts, $dr1_uuid; |
||||
$anvil->data->{raw}{newest_record}{$dr1_uuid} = 0; |
||||
} |
||||
|
||||
foreach my $host_uuid (@hosts) |
||||
{ |
||||
# Do the query |
||||
my $query = " |
||||
SELECT |
||||
a.host_name, |
||||
b.scan_hardware_ram_total, |
||||
b.scan_hardware_memory_free, |
||||
b.scan_hardware_swap_total, |
||||
b.scan_hardware_swap_free |
||||
FROM |
||||
hosts a, scan_hardware b |
||||
WHERE |
||||
a.host_uuid = b.scan_hardware_host_uuid |
||||
AND |
||||
a.host_uuid = ".$anvil->Database->quote($host_uuid)." |
||||
;"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); |
||||
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); |
||||
my $count = @{$results}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count, |
||||
}}); |
||||
foreach my $row (@{$results}) |
||||
{ |
||||
my $host_name = $row->[0]; |
||||
my $scan_hardware_ram_total = $row->[1]; |
||||
my $scan_hardware_memory_free = $row->[2]; |
||||
my $scan_hardware_swap_total = $row->[3]; |
||||
my $scan_hardware_swap_free = $row->[4]; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
host_name => $host_name, |
||||
scan_hardware_ram_total => $anvil->Convert->add_commas({number => $scan_hardware_ram_total})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $scan_hardware_ram_total}).")", |
||||
scan_hardware_memory_free => $anvil->Convert->add_commas({number => $scan_hardware_memory_free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $scan_hardware_memory_free}).")", |
||||
scan_hardware_swap_total => $anvil->Convert->add_commas({number => $scan_hardware_swap_total})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $scan_hardware_swap_total}).")", |
||||
scan_hardware_swap_free => $anvil->Convert->add_commas({number => $scan_hardware_swap_free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $scan_hardware_swap_free}).")", |
||||
}}); |
||||
|
||||
|
||||
if (not $hash->{total}) |
||||
{ |
||||
$hash->{total} = $scan_hardware_ram_total; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->total' => $hash->{total} }}); |
||||
} |
||||
elsif ($scan_hardware_ram_total < $hash->{total}) |
||||
{ |
||||
$hash->{total} = $scan_hardware_ram_total; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'hash->total' => $hash->{total} }}); |
||||
} |
||||
|
||||
push @{$hash->{nodes}}, { |
||||
host_uuid => $host_uuid, |
||||
total => $scan_hardware_ram_total, |
||||
free => $scan_hardware_memory_free, |
||||
swap_total => $scan_hardware_swap_total, |
||||
swap_used => $scan_hardware_swap_free, |
||||
}; |
||||
} |
||||
} |
||||
|
||||
# Now get the servers from the Anvil! |
||||
my $query = " |
||||
SELECT |
||||
a.server_uuid, |
||||
a.server_name, |
||||
b.server_definition_xml |
||||
FROM |
||||
servers a, |
||||
server_definitions b |
||||
WHERE |
||||
a.server_uuid = b.server_definition_server_uuid |
||||
AND |
||||
a.server_anvil_uuid = ".$anvil->Database->quote($anvil_uuid)." |
||||
;"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); |
||||
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); |
||||
my $count = @{$results}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count, |
||||
}}); |
||||
foreach my $row (@{$results}) |
||||
{ |
||||
my $server_uuid = $row->[0]; |
||||
my $server_name = $row->[1]; |
||||
my $server_definition_xml = $row->[2]; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
's1:server_name' => $server_name, |
||||
's2:server_uuid' => $server_uuid, |
||||
's3:server_definition_xml' => $server_definition_xml, |
||||
}}); |
||||
|
||||
$anvil->Server->parse_definition({ |
||||
server => $server_name, |
||||
source => "from_db", |
||||
definition => $server_definition_xml, |
||||
}); |
||||
|
||||
$hash->{allocated} += $anvil->data->{server}{$target}{$server_name}{from_db}{memory}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
'hash->allocated' => $anvil->Convert->add_commas({number => $hash->{allocated}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $hash->{allocated}}).")", |
||||
}}); |
||||
} |
||||
|
||||
} |
||||
|
||||
print JSON->new->utf8->encode($hash)."\n"; |
@ -0,0 +1,304 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# This prints JSON formated data reporting the status of DRBD resources and volumes. |
||||
# |
||||
|
||||
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(); |
||||
$anvil->DRBD->gather_data(); |
||||
|
||||
print $anvil->Template->get({file => "shared.html", name => "json_headers", show_name => 0})."\n"; |
||||
|
||||
my $hash = {}; |
||||
my $anvil_uuid = ""; |
||||
my $active_resource = ""; |
||||
my $volume_array = ""; |
||||
my $connection_array = ""; |
||||
my $target_array = ""; |
||||
$hash->{resources} = []; |
||||
if ($anvil->data->{cgi}{anvil_uuid}{value}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{cgi}{anvil_uuid}{value}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
elsif ($anvil->data->{switches}{'anvil-uuid'}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{switches}{'anvil-uuid'}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
if ((not $anvil_uuid) or (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})) |
||||
{ |
||||
$anvil->data->{anvil_status}{anvil_name} = "!!invalid!anvil_uuid!!"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'anvil_status::anvil_name' => $anvil->data->{anvil_status}{anvil_name} }}); |
||||
} |
||||
else |
||||
{ |
||||
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 $dr1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
node1_uuid => $node1_uuid, |
||||
node2_uuid => $node2_uuid, |
||||
dr1_uuid => $dr1_uuid, |
||||
}}); |
||||
|
||||
$anvil->data->{raw}{newest_record}{$node1_uuid} = 0; |
||||
$anvil->data->{raw}{newest_record}{$node2_uuid} = 0; |
||||
my @hosts = ($node1_uuid, $node2_uuid); |
||||
if ($dr1_uuid) |
||||
{ |
||||
push @hosts, $dr1_uuid; |
||||
$anvil->data->{raw}{newest_record}{$dr1_uuid} = 0; |
||||
} |
||||
|
||||
foreach my $host_uuid (@hosts) |
||||
{ |
||||
my $host_name = $anvil->Get->host_name_from_uuid({host_uuid => $host_uuid}); |
||||
my $short_host_name = $host_name; |
||||
$short_host_name =~ s/\..*$//; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
host_uuid => $host_uuid, |
||||
host_name => $host_name, |
||||
short_host_name => $short_host_name |
||||
}}); |
||||
my $query = " |
||||
SELECT |
||||
scan_drbd_resource_uuid, |
||||
scan_drbd_resource_name, |
||||
scan_drbd_resource_up, |
||||
round(extract(epoch from modified_date)) |
||||
FROM |
||||
scan_drbd_resources |
||||
WHERE |
||||
scan_drbd_resource_host_uuid = ".$anvil->Database->quote($host_uuid)." |
||||
;"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); |
||||
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); |
||||
my $count = @{$results}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count, |
||||
}}); |
||||
foreach my $row (@{$results}) |
||||
{ |
||||
my $scan_drbd_resource_uuid = $row->[0]; |
||||
my $scan_drbd_resource_name = $row->[1]; |
||||
my $scan_drbd_resource_up = $row->[2]; |
||||
my $modified_date = $row->[3]; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
scan_drbd_resource_uuid => $scan_drbd_resource_uuid, |
||||
scan_drbd_resource_name => $scan_drbd_resource_name, |
||||
scan_drbd_resource_up => $scan_drbd_resource_up, |
||||
modified_date => $modified_date, |
||||
}}); |
||||
|
||||
if ($modified_date > $anvil->data->{raw}{newest_record}{$host_uuid}) |
||||
{ |
||||
$anvil->data->{raw}{newest_record}{$host_uuid} = $modified_date; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
"raw::newest_record::${host_uuid}" => $anvil->data->{raw}{newest_record}{$host_uuid}, |
||||
}}); |
||||
} |
||||
|
||||
my $volumes = []; |
||||
my $resource_hash = { |
||||
resource_name => $scan_drbd_resource_name, |
||||
resource_host_uuid => $host_uuid, |
||||
is_active => $scan_drbd_resource_up, |
||||
timestamp => $anvil->data->{raw}{newest_record}{$host_uuid}, |
||||
volumes => $volumes, |
||||
}; |
||||
|
||||
push @{$hash->{resources}}, $resource_hash; |
||||
|
||||
my $query = " |
||||
SELECT |
||||
scan_drbd_volume_uuid, |
||||
scan_drbd_volume_number, |
||||
scan_drbd_volume_device_path, |
||||
scan_drbd_volume_device_minor, |
||||
scan_drbd_volume_size, |
||||
round(extract(epoch from modified_date)) |
||||
FROM |
||||
scan_drbd_volumes |
||||
WHERE |
||||
scan_drbd_volume_scan_drbd_resource_uuid = ".$anvil->Database->quote($scan_drbd_resource_uuid)." |
||||
;"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); |
||||
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); |
||||
my $count = @{$results}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count, |
||||
}}); |
||||
foreach my $row (@{$results}) |
||||
{ |
||||
my $scan_drbd_volume_uuid = $row->[0]; |
||||
my $scan_drbd_volume_number = $row->[1]; |
||||
my $scan_drbd_volume_device_path = $row->[2]; |
||||
my $scan_drbd_volume_device_minor = $row->[3]; |
||||
my $scan_drbd_volume_size = $row->[4]; |
||||
my $modified_date = $row->[5]; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
scan_drbd_volume_uuid => $scan_drbd_volume_uuid, |
||||
scan_drbd_volume_number => $scan_drbd_volume_number, |
||||
scan_drbd_volume_device_path => $scan_drbd_volume_device_path, |
||||
scan_drbd_volume_device_minor => $scan_drbd_volume_device_minor, |
||||
scan_drbd_volume_size => $scan_drbd_volume_size, |
||||
modified_date => $modified_date, |
||||
}}); |
||||
|
||||
if ($modified_date > $anvil->data->{raw}{newest_record}{$host_uuid}) |
||||
{ |
||||
$anvil->data->{raw}{newest_record}{$host_uuid} = $modified_date; |
||||
$resource_hash->{timestamp} = $modified_date; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
"raw::newest_record::${host_uuid}" => $anvil->data->{raw}{newest_record}{$host_uuid}, |
||||
}}); |
||||
} |
||||
|
||||
my $connections = []; |
||||
push @{$volumes}, { |
||||
number => $scan_drbd_volume_number, |
||||
drbd_device_path => $scan_drbd_volume_device_path, |
||||
drbd_device_minor => $scan_drbd_volume_device_minor, |
||||
size => $scan_drbd_volume_size, |
||||
connections => $connections, |
||||
}; |
||||
|
||||
my $query = " |
||||
SELECT |
||||
scan_drbd_peer_host_name, |
||||
scan_drbd_peer_connection_state, |
||||
scan_drbd_peer_local_disk_state, |
||||
scan_drbd_peer_disk_state, |
||||
scan_drbd_peer_local_role, |
||||
scan_drbd_peer_role, |
||||
scan_drbd_peer_out_of_sync_size, |
||||
scan_drbd_peer_replication_speed, |
||||
scan_drbd_peer_estimated_time_to_sync, |
||||
scan_drbd_peer_ip_address, |
||||
scan_drbd_peer_tcp_port, |
||||
scan_drbd_peer_protocol, |
||||
scan_drbd_peer_fencing, |
||||
round(extract(epoch from modified_date)) |
||||
FROM |
||||
scan_drbd_peers |
||||
WHERE |
||||
scan_drbd_peer_scan_drbd_volume_uuid = ".$anvil->Database->quote($scan_drbd_volume_uuid)." |
||||
;"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); |
||||
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); |
||||
my $count = @{$results}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count, |
||||
}}); |
||||
foreach my $row (@{$results}) |
||||
{ |
||||
my $scan_drbd_peer_host_name = $row->[0]; |
||||
my $scan_drbd_peer_connection_state = $row->[1]; |
||||
my $scan_drbd_peer_local_disk_state = $row->[2]; |
||||
my $scan_drbd_peer_disk_state = $row->[3]; |
||||
my $scan_drbd_peer_local_role = $row->[4]; |
||||
my $scan_drbd_peer_role = $row->[5]; |
||||
my $scan_drbd_peer_out_of_sync_size = $row->[6]; |
||||
my $scan_drbd_peer_replication_speed = $row->[7]; |
||||
my $scan_drbd_peer_estimated_time_to_sync = $row->[8]; |
||||
my $scan_drbd_peer_ip_address = $row->[9]; |
||||
my $scan_drbd_peer_tcp_port = $row->[10]; |
||||
my $scan_drbd_peer_protocol = $row->[11]; |
||||
my $scan_drbd_peer_fencing = $row->[12]; |
||||
my $modified_date = $row->[13]; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
scan_drbd_peer_host_name => $scan_drbd_peer_host_name, |
||||
scan_drbd_peer_connection_state => $scan_drbd_peer_connection_state, |
||||
scan_drbd_peer_local_disk_state => $scan_drbd_peer_local_disk_state, |
||||
scan_drbd_peer_disk_state => $scan_drbd_peer_disk_state, |
||||
scan_drbd_peer_local_role => $scan_drbd_peer_local_role, |
||||
scan_drbd_peer_role => $scan_drbd_peer_role, |
||||
scan_drbd_peer_out_of_sync_size => $scan_drbd_peer_out_of_sync_size, |
||||
scan_drbd_peer_replication_speed => $scan_drbd_peer_replication_speed, |
||||
scan_drbd_peer_estimated_time_to_sync => $scan_drbd_peer_estimated_time_to_sync, |
||||
scan_drbd_peer_ip_address => $scan_drbd_peer_ip_address, |
||||
scan_drbd_peer_tcp_port => $scan_drbd_peer_tcp_port, |
||||
scan_drbd_peer_protocol => $scan_drbd_peer_protocol, |
||||
scan_drbd_peer_fencing => $scan_drbd_peer_fencing, |
||||
modified_date => $modified_date, |
||||
}}); |
||||
if ($modified_date > $anvil->data->{raw}{newest_record}{$host_uuid}) |
||||
{ |
||||
$anvil->data->{raw}{newest_record}{$host_uuid} = $modified_date; |
||||
$resource_hash->{timestamp} = $modified_date; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
"raw::newest_record::${host_uuid}" => $anvil->data->{raw}{newest_record}{$host_uuid}, |
||||
}}); |
||||
} |
||||
|
||||
push @{$connections}, { |
||||
protocol => "async_".lc($scan_drbd_peer_protocol), |
||||
connection => $scan_drbd_peer_connection_state, |
||||
ip_address => $scan_drbd_peer_ip_address, |
||||
tcp_port => $scan_drbd_peer_tcp_port, |
||||
fencing => $scan_drbd_peer_fencing, |
||||
targets => [ |
||||
# Local |
||||
{ |
||||
target_name => $short_host_name, |
||||
target_host_uuid => $host_uuid, |
||||
role => $scan_drbd_peer_local_role, |
||||
disk_states => $scan_drbd_peer_local_disk_state, |
||||
}, |
||||
# Peer |
||||
{ |
||||
target_name => $scan_drbd_peer_host_name, |
||||
target_host_uuid => $anvil->Get->host_uuid_from_name({host_name => $scan_drbd_peer_host_name}), |
||||
role => $scan_drbd_peer_role, |
||||
disk_states => $scan_drbd_peer_disk_state, |
||||
}, |
||||
], |
||||
resync => { |
||||
rate => $scan_drbd_peer_replication_speed, # Bytes / second |
||||
percent_complete => (($scan_drbd_peer_out_of_sync_size / $scan_drbd_volume_size) * 100), |
||||
oos_size => $scan_drbd_peer_out_of_sync_size, |
||||
time_remain => $scan_drbd_peer_estimated_time_to_sync, |
||||
}, |
||||
}; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
print JSON->new->utf8->encode($hash)."\n"; |
@ -0,0 +1,172 @@ |
||||
#!/usr/bin/perl |
||||
# |
||||
# This prints JSON formated data reporting the status of an Anvil!'s nodes. |
||||
# |
||||
|
||||
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 $hash = {}; |
||||
my $anvil_uuid = ""; |
||||
if ($anvil->data->{cgi}{anvil_uuid}{value}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{cgi}{anvil_uuid}{value}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
elsif ($anvil->data->{switches}{'anvil-uuid'}) |
||||
{ |
||||
$anvil_uuid = $anvil->data->{switches}{'anvil-uuid'}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { anvil_uuid => $anvil_uuid }}); |
||||
} |
||||
if ((not $anvil_uuid) or (not exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid})) |
||||
{ |
||||
$anvil->data->{anvil_status}{anvil_name} = "!!invalid!anvil_uuid!!"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'anvil_status::anvil_name' => $anvil->data->{anvil_status}{anvil_name} }}); |
||||
} |
||||
else |
||||
{ |
||||
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 $dr1_uuid = $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}{anvil_dr1_host_uuid}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
node1_uuid => $node1_uuid, |
||||
node2_uuid => $node2_uuid, |
||||
dr1_uuid => $dr1_uuid, |
||||
}}); |
||||
|
||||
my $query = " |
||||
SELECT |
||||
|
||||
FROM |
||||
hosts a, |
||||
scan_filesystems b |
||||
WHERE |
||||
a.host_uuid = b.scan_filesystem_host_uuid |
||||
AND |
||||
( |
||||
a.host_uuid = ".$anvil->Database->quote($node1_uuid)." |
||||
OR |
||||
a.host_uuid = ".$anvil->Database->quote($node2_uuid); |
||||
if ($dr1_uuid) |
||||
{ |
||||
$query .= " |
||||
OR |
||||
a.host_uuid = ".$anvil->Database->quote($dr1_uuid); |
||||
} |
||||
$query .= " |
||||
) |
||||
ORDER BY |
||||
a.host_name ASC, |
||||
b.scan_filesystem_mount_point DESC |
||||
;"; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); |
||||
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); |
||||
my $count = @{$results}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
results => $results, |
||||
count => $count, |
||||
}}); |
||||
foreach my $row (@{$results}) |
||||
{ |
||||
my $host_uuid = $row->[0]; |
||||
my $host_name = $row->[1]; |
||||
my $mount_point = $row->[2]; |
||||
my $size = $row->[3]; |
||||
my $used = $row->[4]; |
||||
my $free = $size - $used; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
host_uuid => $host_uuid, |
||||
host_name => $host_name, |
||||
mount_point => $mount_point, |
||||
size => $anvil->Convert->add_commas({number => $size})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $size}).")",, |
||||
used => $anvil->Convert->add_commas({number => $used})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $used}).")",, |
||||
free => $anvil->Convert->add_commas({number => $free})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $free}).")",, |
||||
}}); |
||||
|
||||
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name} = $host_name; |
||||
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total} = $size; |
||||
$anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free} = $free; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
"raw::file_systems::${mount_point}::nodes::${host_uuid}::host_name" => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name}, |
||||
"raw::file_systems::${mount_point}::nodes::${host_uuid}::total" => $anvil->Convert->add_commas({number => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}}).")",, |
||||
"raw::file_systems::${mount_point}::nodes::${host_uuid}::free" => $anvil->Convert->add_commas({number => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}}).")",, |
||||
}}); |
||||
} |
||||
|
||||
$anvil->data->{file_systems} = []; |
||||
|
||||
foreach my $mount_point (sort {$a cmp $b} keys %{$anvil->data->{raw}{file_systems}}) |
||||
{ |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { mount_point => $mount_point }}); |
||||
$hash->{mount_point} = $mount_point; |
||||
$hash->{nodes} = []; |
||||
my $nodes = [$node1_uuid, $node2_uuid]; |
||||
if ($dr1_uuid) |
||||
{ |
||||
push @{$nodes}, $dr1_uuid; |
||||
} |
||||
foreach my $host_uuid (@{$nodes}) |
||||
{ |
||||
my $host_name = $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name}; |
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { |
||||
host_uuid => $host_uuid, |
||||
host_name => $host_name, |
||||
}}); |
||||
if (exists $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}) |
||||
{ |
||||
push @{$hash->{nodes}}, { |
||||
host_uuid => $host_uuid, |
||||
host_name => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{host_name}, |
||||
is_mounted => 1, |
||||
total => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{total}, |
||||
free => $anvil->data->{raw}{file_systems}{$mount_point}{nodes}{$host_uuid}{free}, |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
push @{$hash->{nodes}}, { |
||||
host_uuid => $host_uuid, |
||||
host_name => $anvil->data->{hosts}{host_uuid}{$host_uuid}{host_name}, |
||||
is_mounted => 0, |
||||
total => 0, |
||||
free => 0, |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
print JSON->new->utf8->encode($hash)."\n"; |
Loading…
Reference in new issue