#!/usr/bin/perl # # Prints JSON formatted data reporting the status of shared storage (a.k.a. storage groups/shared VGs) # 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(); sub handle_invalid_uuid { my $parameters = shift; my $name = $parameters->{name}; my $uuid = $parameters->{uuid}; $anvil->Log->entry({ source => $THIS_FILE, line => __LINE__, level => 0, 'print' => 1, priority => "err", key => "error_0160", variables => { name => $name, uuid => $uuid } }); $anvil->nice_exit({ exit_code => 1 }); } $anvil->Get->switches; # Temporary; for debugging $anvil->Log->level({ set => 2 }); $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 = exists $anvil->data->{cgi}{anvil_uuid}{value} ? $anvil->data->{cgi}{anvil_uuid}{value} : $anvil->data->{switches}{'anvil-uuid'}; my $anvil_uuid_variable_name = "anvil UUID"; my $response_body = {}; if ($anvil_uuid) { if (exists $anvil->data->{anvils}{anvil_uuid}{$anvil_uuid}) { $anvil->Log->variables({ source => $THIS_FILE, line => __LINE__, level => 2, list => { message => "Valid ".$anvil_uuid_variable_name." received.", anvil_uuid => $anvil_uuid } }); } else { handle_invalid_uuid({ name => $anvil_uuid_variable_name, uuid => $anvil_uuid }); } } else { handle_invalid_uuid({ name => $anvil_uuid_variable_name, uuid => $anvil_uuid }); } print JSON->new->utf8->encode($response_body)."\n";