diff --git a/Anvil/Tools/Network.pm b/Anvil/Tools/Network.pm index 3c9eb8e1..66b3e34c 100755 --- a/Anvil/Tools/Network.pm +++ b/Anvil/Tools/Network.pm @@ -648,16 +648,26 @@ sub find_matches second => $second, }}); - if (ref($anvil->data->{network}{$first}) ne "HASH") + if (not $first) { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->find_matches()", parameter => "first" }}); return(""); } - if (ref($anvil->data->{network}{$second}) ne "HASH") + elsif (ref($anvil->data->{network}{$first}) ne "HASH") + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0106", variables => { key => "first -> network::".$first }}); + return(""); + } + if (not $second) { $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Network->find_matches()", parameter => "second" }}); return(""); } + elsif (ref($anvil->data->{network}{$second}) ne "HASH") + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0106", variables => { key => "second -> network::".$second }}); + return(""); + } # Loop through the first, and on each interface with an IP/subnet mask, look for a match in the second. my $match = {}; @@ -1165,7 +1175,7 @@ FROM ip_addresses WHERE ip_address_host_uuid = ".$anvil->Database->quote($host_uuid)." -"; +;"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { query => $query }}); my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__}); my $count = @{$results}; diff --git a/Anvil/Tools/Striker.pm b/Anvil/Tools/Striker.pm index 72a96e4c..51347f6a 100644 --- a/Anvil/Tools/Striker.pm +++ b/Anvil/Tools/Striker.pm @@ -350,6 +350,13 @@ sub parse_all_status_json delete $anvil->data->{json}{all_status}; } + # We're going to look for matches as we go, so look + $anvil->Network->load_ips({ + debug => $debug, + host => 'local', + host_uuid => $anvil->data->{sys}{host_uuid}, + }); + # We'll be adding data to this JSON file over time. So this will be an ever evolving method. foreach my $host_hash (@{$data->{hosts}}) { @@ -361,12 +368,54 @@ sub parse_all_status_json $anvil->data->{json}{all_status}{hosts}{$host_name}{short_host_name} = $host_hash->{short_name}; $anvil->data->{json}{all_status}{hosts}{$host_name}{configured} = $host_hash->{configured}; $anvil->data->{json}{all_status}{hosts}{$host_name}{ssh_fingerprint} = $host_hash->{ssh_fingerprint}; + $anvil->data->{json}{all_status}{hosts}{$host_name}{matched_interface} = $host_hash->{matched_interface}; + $anvil->data->{json}{all_status}{hosts}{$host_name}{matched_ip_address} = $host_hash->{matched_ip_address}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "json::all_status::hosts::${host_name}::host_uuid" => $anvil->data->{json}{all_status}{hosts}{$host_name}{host_uuid}, + "json::all_status::hosts::${host_name}::type" => $anvil->data->{json}{all_status}{hosts}{$host_name}{type}, + "json::all_status::hosts::${host_name}::short_host_name" => $anvil->data->{json}{all_status}{hosts}{$host_name}{short_host_name}, + "json::all_status::hosts::${host_name}::configured" => $anvil->data->{json}{all_status}{hosts}{$host_name}{configured}, + "json::all_status::hosts::${host_name}::ssh_fingerprint" => $anvil->data->{json}{all_status}{hosts}{$host_name}{ssh_fingerprint}, + "json::all_status::hosts::${host_name}::matched_interface" => $anvil->data->{json}{all_status}{hosts}{$host_name}{matched_interface}, + "json::all_status::hosts::${host_name}::matched_ip_address" => $anvil->data->{json}{all_status}{hosts}{$host_name}{matched_ip_address}, + }}); + + # Find what interface on this host we can use to talk to it (if we're not looking at ourselves). + my $matched_interface = ""; + my $matched_ip_address = ""; + if ($host_name ne $anvil->_host_name) + { + $anvil->Network->load_ips({ + debug => $debug, + host => $short_name, + host_uuid => $anvil->data->{json}{all_status}{hosts}{$host_name}{host_uuid}, + }); + my ($match) = $anvil->Network->find_matches({ + debug => 3, + first => 'local', + second => $short_name, + }); + if ($match) + { + # Yup! + my $match_found = 0; + foreach my $interface (sort {$a cmp $b} keys %{$match->{$short_name}}) + { + $matched_interface = $interface; + $matched_ip_address = $match->{$short_name}{$interface}{ip}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + matched_interface => $matched_interface, + matched_ip_address => $matched_ip_address, + }}); + last; + } + } + } + $anvil->data->{json}{all_status}{hosts}{$host_name}{matched_interface} = $matched_interface; + $anvil->data->{json}{all_status}{hosts}{$host_name}{matched_ip_address} = $matched_ip_address; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - "json::all_status::hosts::${host_name}::host_uuid" => $anvil->data->{json}{all_status}{hosts}{$host_name}{host_uuid}, - "json::all_status::hosts::${host_name}::type" => $anvil->data->{json}{all_status}{hosts}{$host_name}{type}, - "json::all_status::hosts::${host_name}::short_host_name" => $anvil->data->{json}{all_status}{hosts}{$host_name}{short_host_name}, - "json::all_status::hosts::${host_name}::configured" => $anvil->data->{json}{all_status}{hosts}{$host_name}{configured}, - "json::all_status::hosts::${host_name}::ssh_fingerprint" => $anvil->data->{json}{all_status}{hosts}{$host_name}{ssh_fingerprint}, + "json::all_status::hosts::${host_name}::matched_interface" => $anvil->data->{json}{all_status}{hosts}{$host_name}{matched_interface}, + "json::all_status::hosts::${host_name}::matched_ip_address" => $anvil->data->{json}{all_status}{hosts}{$host_name}{matched_ip_address}, }}); foreach my $interface_hash (@{$host_hash->{network_interfaces}}) diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index f5d34f32..46432506 100644 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -813,6 +813,13 @@ sub generate_state_json my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->generate_state_json()" }}); + # We're going to look for matches as we go, so look + $anvil->Network->load_ips({ + debug => $debug, + host => 'local', + host_uuid => $anvil->data->{sys}{host_uuid}, + }); + $anvil->data->{json}{all_systems}{hosts} = []; $anvil->Database->get_hosts_info({debug => 3}); foreach my $host_uuid (keys %{$anvil->data->{machine}{host_uuid}}) @@ -824,7 +831,7 @@ sub generate_state_json my $configured = defined $anvil->data->{machine}{host_uuid}{$host_uuid}{variables}{'system::configured'} ? $anvil->data->{machine}{host_uuid}{$host_uuid}{variables}{'system::configured'} : 0; my $ifaces_array = []; my $host = $short_host_name; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "s1:host_name" => $host_name, "s2:short_host_name" => $short_host_name, "s3:host_type" => $host_type, @@ -838,6 +845,36 @@ sub generate_state_json host_uuid => $host_uuid, host => $short_host_name, }); + + # Find what interface on this host we can use to talk to it (if we're not looking at ourselves). + my $matched_interface = ""; + my $matched_ip_address = ""; + if ($host_name ne $anvil->_host_name) + { + # Don't need to call 'local_ips', it was called by load_interfaces above. + my ($match) = $anvil->Network->find_matches({ + debug => $debug, + first => 'local', + second => $short_host_name, + }); + + if ($match) + { + # Yup! + my $match_found = 0; + foreach my $interface (sort {$a cmp $b} keys %{$match->{$short_host_name}}) + { + $matched_interface = $interface; + $matched_ip_address = $match->{$short_host_name}{$interface}{ip}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + matched_interface => $matched_interface, + matched_ip_address => $matched_ip_address, + }}); + last; + } + } + } + foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$host}{interface}}) { my $type = $anvil->data->{network}{$host}{interface}{$interface}{type}; @@ -1138,6 +1175,8 @@ sub generate_state_json host_uuid => $host_uuid, configured => $configured, ssh_fingerprint => $host_key, + matched_interface => $matched_interface, + matched_ip_address => $matched_ip_address, network_interfaces => $ifaces_array, }; } diff --git a/Anvil/Tools/Words.pm b/Anvil/Tools/Words.pm index 85ef2436..acad4a63 100644 --- a/Anvil/Tools/Words.pm +++ b/Anvil/Tools/Words.pm @@ -357,6 +357,12 @@ sub parse_banged_string while ($variable_string) { my $pair = ($variable_string =~ /^(!!.*?!.*?!!).*$/)[0]; + if (not defined $pair) + { + print $THIS_FILE." ".__LINE__."; Failed to parse the pair from: [".$variable_string."]\n"; + print $THIS_FILE." ".__LINE__."; Was parsing message: [".$message."] from key string: [".$key_string."]\n"; + die; + } my ($variable, $value) = ($pair =~ /^!!(.*?)!(.*?)!!$/); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "s1:pair" => $pair, diff --git a/html/skins/alteeve/anvil.html b/html/skins/alteeve/anvil.html index b0268f0b..d8d1f46b 100644 --- a/html/skins/alteeve/anvil.html +++ b/html/skins/alteeve/anvil.html @@ -25,11 +25,26 @@ - - + + - #!string!striker_0130!# + #!string!striker_0130!# + + + + + +