* Updated the configuration step 2 to properly show interface link changes again (had to add the network status XML generator back), and added displaying the 'up order', which tells the order that interfaces last cycles. This allows a user to unplug and plug the network cables in without watching the screen and be able to determine which interfaces cycled in a given order. This makes it easier to map MAC addresses to desired roles.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent fa11459543
commit 3d385a5731
  1. 44
      AN/Tools/Database.pm
  2. 26
      cgi-bin/home
  3. 7
      cgi-bin/words.xml
  4. 6
      html/skins/alteeve/main.html
  5. 3
      html/skins/alteeve/main.js
  6. 81
      tools/scancore-update-states

@ -902,10 +902,10 @@ sub connect
if (not $an->data->{sys}{db_timestamp})
{
my $query = "SELECT cast(now() AS timestamp with time zone)::timestamptz(0);";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
$an->data->{sys}{db_timestamp} = $an->Database->query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { "sys::db_timestamp" => $an->data->{sys}{db_timestamp} }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { "sys::db_timestamp" => $an->data->{sys}{db_timestamp} }});
}
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
@ -1346,7 +1346,7 @@ sub insert_or_update_hosts
my $host_type = $parameter->{host_type} ? $parameter->{host_type} : $an->System->determine_host_type;
my $host_uuid = $parameter->{host_uuid} ? $parameter->{host_uuid} : $an->Get->host_uuid;
my $id = $parameter->{id} ? $parameter->{id} : "";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
host_name => $host_name,
host_type => $host_type,
host_uuid => $host_uuid,
@ -1378,11 +1378,11 @@ FROM
WHERE
host_uuid = ".$an->data->{sys}{use_db_fh}->quote($host_uuid)."
;";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
my $results = $an->Database->query({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results,
count => $count,
}});
@ -1390,7 +1390,7 @@ WHERE
{
$old_host_name = $row->[0];
$old_host_type = $row->[1];
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
old_host_name => $old_host_name,
old_host_type => $old_host_type,
}});
@ -1414,7 +1414,7 @@ INSERT INTO
);
";
$query =~ s/'NULL'/NULL/g;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
$an->Database->write({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
}
elsif (($old_host_name ne $host_name) or ($old_host_type ne $host_type))
@ -1431,7 +1431,7 @@ WHERE
host_uuid = ".$an->data->{sys}{use_db_fh}->quote($host_uuid)."
;";
$query =~ s/'NULL'/NULL/g;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
$an->Database->write({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
}
@ -1521,7 +1521,7 @@ sub insert_or_update_network_interfaces
my $network_interface_name = defined $parameter->{network_interface_name} ? $parameter->{network_interface_name} : "--";
my $network_interface_speed = defined $parameter->{network_interface_speed} ? $parameter->{network_interface_speed} : "--";
my $network_interface_uuid = defined $parameter->{network_interface_uuid} ? $parameter->{interface_uuid} : "";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
id => $id,
network_interface_bond_uuid => $network_interface_bond_uuid,
network_interface_bridge_uuid => $network_interface_bridge_uuid,
@ -1547,11 +1547,11 @@ sub insert_or_update_network_interfaces
{
# See if I know this NIC by referencing it's MAC.
my $query = "SELECT network_interface_uuid FROM network_interfaces WHERE network_interface_mac_address = ".$an->data->{sys}{use_db_fh}->quote($network_interface_mac_address).";";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
$network_interface_uuid = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$network_interface_uuid = "" if not defined $network_interface_uuid;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_interface_uuid => $network_interface_uuid }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_interface_uuid => $network_interface_uuid }});
}
# Now, if we're inserting or updating, we'll need to require different bits.
@ -1576,11 +1576,11 @@ FROM
WHERE
network_interface_uuid = ".$an->data->{sys}{use_db_fh}->quote($network_interface_uuid).";
";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
my $results = $an->Database->query({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results,
count => $count,
}});
@ -1597,7 +1597,7 @@ WHERE
my $old_network_interface_medium = defined $row->[8] ? $row->[8] : "";
my $old_network_interface_bond_uuid = defined $row->[9] ? $row->[9] : "";
my $old_network_interface_bridge_uuid = defined $row->[10] ? $row->[10] : "";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
old_network_interface_host_uuid => $old_network_interface_host_uuid,
old_network_interface_mac_address => $old_network_interface_mac_address,
old_network_interface_name => $old_network_interface_name,
@ -1679,7 +1679,7 @@ WHERE
network_interface_uuid = ".$an->data->{sys}{use_db_fh}->quote($network_interface_uuid)."
;";
$query =~ s/'NULL'/NULL/g;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
$an->Database->write({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
}
else
@ -1728,7 +1728,7 @@ WHERE
# And INSERT
$network_interface_uuid = $an->Get->uuid;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { network_interface_uuid => $network_interface_uuid }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_interface_uuid => $network_interface_uuid }});
my $query = "
INSERT INTO
@ -1764,7 +1764,7 @@ INSERT INTO
);
";
$query =~ s/'NULL'/NULL/g;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
$an->Database->write({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
}
@ -2767,7 +2767,7 @@ sub read_variable
my $variable_source_uuid = $parameter->{variable_source_uuid} ? $parameter->{variable_source_uuid} : "NULL";
my $variable_source_table = $parameter->{variable_source_table} ? $parameter->{variable_source_table} : "NULL";
my $id = $parameter->{id} ? $parameter->{id} : $an->data->{sys}{read_db_id};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
variable_uuid => $variable_uuid,
variable_name => $variable_name,
variable_source_uuid => $variable_source_uuid,
@ -2811,13 +2811,13 @@ AND
}
}
$query .= ";";
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
my $variable_value = "";
my $modified_date = "";
my $results = $an->Database->query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results,
count => $count,
}});
@ -2826,14 +2826,14 @@ AND
$variable_value = defined $row->[0] ? $row->[0] : "";
$variable_uuid = $row->[1];
$modified_date = $row->[2];
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
variable_value => $variable_value,
variable_uuid => $variable_uuid,
modified_date => $modified_date,
}});
}
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
variable_value => $variable_value,
variable_uuid => $variable_uuid,
modified_date => $modified_date,

@ -23,7 +23,7 @@ my $an = AN::Tools->new();
print $an->Template->get({file => "shared.html", name => "http_headers"})."\n";
# Set the log level to 2. Setting 3 slows he program down a LOT.
$an->Log->level({set => 3});
$an->Log->level({set => 2});
# Read in our words file.
$an->Words->read({file => $an->data->{path}{directories}{'cgi-bin'}."/words.xml"});
@ -711,7 +711,7 @@ sub get_network_details
# Now read the network.xml
my $file = $an->data->{path}{directories}{html}."/status/network.xml";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { file => $file }});
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file => $file }});
# Parse...
my $xml = XML::Simple->new();
@ -732,14 +732,28 @@ sub get_network_details
foreach my $interface (sort {$a cmp $b} keys %{$data->{interface}})
{
$an->data->{interfaces}{$interface} = {
bond => $data->{interface}{$interface}{bond},
bridge => $data->{interface}{$interface}{bridge},
duplex => $data->{interface}{$interface}{duplex},
'link' => $data->{interface}{$interface}{'link'},
mac => $data->{interface}{$interface}{mac},
media => $data->{interface}{$interface}{media},
mtu => $data->{interface}{$interface}{mtu},
order => $data->{interface}{$interface}{order},
speed => $data->{interface}{$interface}{speed},
'link' => $data->{interface}{$interface}{'link'}
'state' => $data->{interface}{$interface}{'state'},
};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"interfaces::${interface}::bond" => $an->data->{interfaces}{$interface}{bond},
"interfaces::${interface}::bridge" => $an->data->{interfaces}{$interface}{bridge},
"interfaces::${interface}::duplex" => $an->data->{interfaces}{$interface}{duplex},
"interfaces::${interface}::link" => $an->data->{interfaces}{$interface}{'link'},
"interfaces::${interface}::mac" => $an->data->{interfaces}{$interface}{mac},
"interfaces::${interface}::media" => $an->data->{interfaces}{$interface}{media},
"interfaces::${interface}::mtu" => $an->data->{interfaces}{$interface}{mtu},
"interfaces::${interface}::order" => $an->data->{interfaces}{$interface}{order},
"interfaces::${interface}::speed" => $an->data->{interfaces}{$interface}{speed},
"interfaces::${interface}::link" => $an->data->{interfaces}{$interface}{'link'},
"interfaces::${interface}::state" => $an->data->{interfaces}{$interface}{'state'},
}});
}
}
@ -785,6 +799,8 @@ sub get_network_details_form
#'link' => $data->{interface}{$interface}{'link'},
'link' => "",
link_id => $interface."_link",
order => "",
order_id => $interface."_order",
}});
}
$interface_list =~ s/,$//;

@ -22,9 +22,10 @@ This is the AN::Tools master 'words' file.
<key name="header_0001">Current Network Interfaces and States</key>
<key name="header_0002">MAC Address</key>
<key name="header_0003">Current Name</key>
<key name="header_0004">Link State</key>
<key name="header_0005">Link Speed (Mbps)</key>
<key name="header_0003">Name</key>
<key name="header_0004">State</key>
<key name="header_0005">Speed</key>
<key name="header_0006">Up Order</key>
<!-- General strings shown in Striker -->
<key name="striker_0001">Welcome! Lets setup your #!string!brand_0003!# dashboard...</key>

@ -294,6 +294,9 @@
<td id="network_link_speed" data-mbps="#!string!js_0003!#" class="column_row_name">
#!string!header_0005!#
</td>
<td class="column_row_name">
#!string!header_0006!#
</td>
</tr>
<!-- end network_header -->
@ -311,6 +314,9 @@
<td class="column_row_value_fixed_centered">
<span name="#!variable!speed_id!#" id="#!variable!speed_id!#">#!variable!speed!#</span>
</td>
<td class="column_row_value_fixed_centered">
<span name="#!variable!order_id!#" id="#!variable!order_id!#">#!variable!order!#</span>
</td>
</tr>
<!-- end network_entry -->

@ -12,7 +12,7 @@ $(function() {
$.getJSON('/status/network.json', { get_param: 'value' }, function(data) {
$.each(data.networks, function(index, element) {
console.log('entry: ['+index+'], name: ['+element.name+'], mac: ['+element.mac+'], link: ['+element.link+']');
console.log('entry: ['+index+'], name: ['+element.name+'], mac: ['+element.mac+'], link: ['+element.link+'], up order: ['+element.order+']');
var link = say_up;
if (element.link == 0) {
@ -21,6 +21,7 @@ $(function() {
$("#"+element.name+"_mac").text(element.mac);
$("#"+element.name+"_link").text(link);
$("#"+element.name+"_speed").text(element.speed+' '+say_speed_suffix);
$("#"+element.name+"_order").text(element.order);
});
});
}, 1000);

@ -40,7 +40,6 @@ sub report_network
my ($an) = @_;
# Write out the data in json format.
my $network_json = "{\"networks\":[\n";
my $directory = $an->data->{path}{sysfs}{network_interfaces};
local(*DIRECTORY);
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0018", variables => { directory => $directory }});
@ -82,7 +81,7 @@ sub report_network
}
# Log
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
interface => $interface,
mac_address => $mac_address,
link_state => $link_state,
@ -104,14 +103,78 @@ sub report_network
network_interface_speed => $speed,
});
$network_json .= " { \"name\":\"$interface\", \"mac\":\"$mac_address\", \"link\":\"$link_state\", \"mtu\":\"$mtu\" \"duplex\":\"$duplex\", \"state\":\"$operational\", \"speed\":\"$speed\", \"media\":\"$media\" },\n";
}
}
closedir(DIRECTORY);
# Write out the XML file and JSON file.
my $order = 1;
my $network_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
$network_xml .= "<network>\n";
my $network_json = "{\"networks\":[\n";
my $query = "
SELECT
network_interface_mac_address,
network_interface_name,
network_interface_speed,
network_interface_mtu,
network_interface_link_state,
network_interface_operational,
network_interface_duplex,
network_interface_medium,
network_interface_bond_uuid,
network_interface_bridge_uuid
FROM
network_interfaces
WHERE
network_interface_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($an->Get->host_uuid)."
ORDER BY
modified_date DESC
;";
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
my $results = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $network_interface_mac_address = $row->[0];
my $network_interface_name = $row->[1];
my $network_interface_speed = $row->[2];
my $network_interface_mtu = defined $row->[3] ? $row->[3] : "";
my $network_interface_link_state = $row->[4];
my $network_interface_operational = $row->[5];
my $network_interface_duplex = $row->[6];
my $network_interface_medium = defined $row->[7] ? $row->[7] : "";
my $network_interface_bond_uuid = defined $row->[8] ? $row->[8] : "";
my $network_interface_bridge_uuid = defined $row->[9] ? $row->[9] : "";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
network_interface_mac_address => $network_interface_mac_address,
network_interface_name => $network_interface_name,
network_interface_speed => $network_interface_speed,
network_interface_mtu => $network_interface_mtu,
network_interface_link_state => $network_interface_link_state,
network_interface_operational => $network_interface_operational,
network_interface_duplex => $network_interface_duplex,
network_interface_medium => $network_interface_medium,
network_interface_bond_uuid => $network_interface_bond_uuid,
network_interface_bridge_uuid => $network_interface_bridge_uuid,
order => $order,
}});
$network_json .= " { \"name\":\"$network_interface_name\", \"mac\":\"$network_interface_mac_address\", \"link\":\"$network_interface_link_state\", \"speed\":\"$network_interface_speed\", \"mtu\":\"$network_interface_mtu\", \"duplex\":\"$network_interface_duplex\", \"state\":\"$network_interface_operational\", \"media\":\"$network_interface_medium\", \"bond\":\"$network_interface_bond_uuid\", \"bridge\":\"$network_interface_bridge_uuid\", \"order\":\"$order\" },\n";
$network_xml .= " <interface name=\"$network_interface_name\" mac=\"$network_interface_mac_address\" link=\"$network_interface_link_state\" speed=\"$network_interface_speed\" mtu=\"$network_interface_mtu\" duplex=\"$network_interface_duplex\" state=\"$network_interface_operational\" media=\"$network_interface_medium\" bond=\"$network_interface_bond_uuid\" bridge=\"$network_interface_bridge_uuid\" order=\"$order\" />\n";
$order++;
}
$network_json =~ s/,$//s;
$network_json .= "]}\n";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_json => $network_json }});
$network_xml .= "</network>\n";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_xml => $network_xml }});
### TODO: Set the 'status/network.json' name into 'striker.conf'
# Write the JSON file.
my $output_json = $an->data->{path}{directories}{html}."/status/network.json";
@ -125,5 +188,17 @@ sub report_network
group => "apache"
});
# Write the XML file.
my $output_xml = $an->data->{path}{directories}{html}."/status/network.xml";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_xml }});
$an->Storage->write_file({
file => $output_xml,
body => $network_xml,
overwrite => 1,
mode => "0644",
user => "apache",
group => "apache"
});
return(0);
}

Loading…
Cancel
Save