* 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. 56
      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}) if (not $an->data->{sys}{db_timestamp})
{ {
my $query = "SELECT cast(now() AS timestamp with time zone)::timestamptz(0);"; 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->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 => { $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_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 $host_uuid = $parameter->{host_uuid} ? $parameter->{host_uuid} : $an->Get->host_uuid;
my $id = $parameter->{id} ? $parameter->{id} : ""; 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_name => $host_name,
host_type => $host_type, host_type => $host_type,
host_uuid => $host_uuid, host_uuid => $host_uuid,
@ -1378,11 +1378,11 @@ FROM
WHERE WHERE
host_uuid = ".$an->data->{sys}{use_db_fh}->quote($host_uuid)." 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 $results = $an->Database->query({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; 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, results => $results,
count => $count, count => $count,
}}); }});
@ -1390,7 +1390,7 @@ WHERE
{ {
$old_host_name = $row->[0]; $old_host_name = $row->[0];
$old_host_type = $row->[1]; $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_name => $old_host_name,
old_host_type => $old_host_type, old_host_type => $old_host_type,
}}); }});
@ -1414,7 +1414,7 @@ INSERT INTO
); );
"; ";
$query =~ s/'NULL'/NULL/g; $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__}); $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)) 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)." host_uuid = ".$an->data->{sys}{use_db_fh}->quote($host_uuid)."
;"; ;";
$query =~ s/'NULL'/NULL/g; $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__}); $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_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_speed = defined $parameter->{network_interface_speed} ? $parameter->{network_interface_speed} : "--";
my $network_interface_uuid = defined $parameter->{network_interface_uuid} ? $parameter->{interface_uuid} : ""; 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, id => $id,
network_interface_bond_uuid => $network_interface_bond_uuid, network_interface_bond_uuid => $network_interface_bond_uuid,
network_interface_bridge_uuid => $network_interface_bridge_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. # 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).";"; 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 = $an->Database->query({query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$network_interface_uuid = "" if not defined $network_interface_uuid; $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. # Now, if we're inserting or updating, we'll need to require different bits.
@ -1576,11 +1576,11 @@ FROM
WHERE WHERE
network_interface_uuid = ".$an->data->{sys}{use_db_fh}->quote($network_interface_uuid)."; 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 $results = $an->Database->query({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; 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, results => $results,
count => $count, count => $count,
}}); }});
@ -1597,7 +1597,7 @@ WHERE
my $old_network_interface_medium = defined $row->[8] ? $row->[8] : ""; 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_bond_uuid = defined $row->[9] ? $row->[9] : "";
my $old_network_interface_bridge_uuid = defined $row->[10] ? $row->[10] : ""; 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_host_uuid => $old_network_interface_host_uuid,
old_network_interface_mac_address => $old_network_interface_mac_address, old_network_interface_mac_address => $old_network_interface_mac_address,
old_network_interface_name => $old_network_interface_name, 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)." network_interface_uuid = ".$an->data->{sys}{use_db_fh}->quote($network_interface_uuid)."
;"; ;";
$query =~ s/'NULL'/NULL/g; $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__}); $an->Database->write({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
} }
else else
@ -1728,7 +1728,7 @@ WHERE
# And INSERT # And INSERT
$network_interface_uuid = $an->Get->uuid; $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 = " my $query = "
INSERT INTO INSERT INTO
@ -1764,7 +1764,7 @@ INSERT INTO
); );
"; ";
$query =~ s/'NULL'/NULL/g; $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__}); $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_uuid = $parameter->{variable_source_uuid} ? $parameter->{variable_source_uuid} : "NULL";
my $variable_source_table = $parameter->{variable_source_table} ? $parameter->{variable_source_table} : "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}; 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_uuid => $variable_uuid,
variable_name => $variable_name, variable_name => $variable_name,
variable_source_uuid => $variable_source_uuid, variable_source_uuid => $variable_source_uuid,
@ -2811,13 +2811,13 @@ AND
} }
} }
$query .= ";"; $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 $variable_value = "";
my $modified_date = ""; my $modified_date = "";
my $results = $an->Database->query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__}); my $results = $an->Database->query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results}; 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, results => $results,
count => $count, count => $count,
}}); }});
@ -2826,14 +2826,14 @@ AND
$variable_value = defined $row->[0] ? $row->[0] : ""; $variable_value = defined $row->[0] ? $row->[0] : "";
$variable_uuid = $row->[1]; $variable_uuid = $row->[1];
$modified_date = $row->[2]; $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_value => $variable_value,
variable_uuid => $variable_uuid, variable_uuid => $variable_uuid,
modified_date => $modified_date, 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_value => $variable_value,
variable_uuid => $variable_uuid, variable_uuid => $variable_uuid,
modified_date => $modified_date, modified_date => $modified_date,

@ -23,7 +23,7 @@ my $an = AN::Tools->new();
print $an->Template->get({file => "shared.html", name => "http_headers"})."\n"; 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. # 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. # Read in our words file.
$an->Words->read({file => $an->data->{path}{directories}{'cgi-bin'}."/words.xml"}); $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 # Now read the network.xml
my $file = $an->data->{path}{directories}{html}."/status/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... # Parse...
my $xml = XML::Simple->new(); my $xml = XML::Simple->new();
@ -732,14 +732,28 @@ sub get_network_details
foreach my $interface (sort {$a cmp $b} keys %{$data->{interface}}) foreach my $interface (sort {$a cmp $b} keys %{$data->{interface}})
{ {
$an->data->{interfaces}{$interface} = { $an->data->{interfaces}{$interface} = {
mac => $data->{interface}{$interface}{mac}, bond => $data->{interface}{$interface}{bond},
speed => $data->{interface}{$interface}{speed}, bridge => $data->{interface}{$interface}{bridge},
'link' => $data->{interface}{$interface}{'link'} 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},
'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}::mac" => $an->data->{interfaces}{$interface}{mac}, "interfaces::${interface}::bond" => $an->data->{interfaces}{$interface}{bond},
"interfaces::${interface}::speed" => $an->data->{interfaces}{$interface}{speed}, "interfaces::${interface}::bridge" => $an->data->{interfaces}{$interface}{bridge},
"interfaces::${interface}::link" => $an->data->{interfaces}{$interface}{'link'}, "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}::state" => $an->data->{interfaces}{$interface}{'state'},
}}); }});
} }
} }
@ -774,17 +788,19 @@ sub get_network_details_form
{ {
$interface_list .= "$interface,"; $interface_list .= "$interface,";
$network .= $an->Template->get({file => "main.html", name => "network_entry", variables => { $network .= $an->Template->get({file => "main.html", name => "network_entry", variables => {
#mac => $data->{interface}{$interface}{mac}, #mac => $data->{interface}{$interface}{mac},
mac => "", mac => "",
mac_id => $interface."_mac", mac_id => $interface."_mac",
name => $interface, name => $interface,
name_id => $interface."_name", name_id => $interface."_name",
#speed => $data->{interface}{$interface}{speed}, #speed => $data->{interface}{$interface}{speed},
speed => "", speed => "",
speed_id => $interface."_speed", speed_id => $interface."_speed",
#'link' => $data->{interface}{$interface}{'link'}, #'link' => $data->{interface}{$interface}{'link'},
'link' => "", 'link' => "",
link_id => $interface."_link", link_id => $interface."_link",
order => "",
order_id => $interface."_order",
}}); }});
} }
$interface_list =~ s/,$//; $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_0001">Current Network Interfaces and States</key>
<key name="header_0002">MAC Address</key> <key name="header_0002">MAC Address</key>
<key name="header_0003">Current Name</key> <key name="header_0003">Name</key>
<key name="header_0004">Link State</key> <key name="header_0004">State</key>
<key name="header_0005">Link Speed (Mbps)</key> <key name="header_0005">Speed</key>
<key name="header_0006">Up Order</key>
<!-- General strings shown in Striker --> <!-- General strings shown in Striker -->
<key name="striker_0001">Welcome! Lets setup your #!string!brand_0003!# dashboard...</key> <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"> <td id="network_link_speed" data-mbps="#!string!js_0003!#" class="column_row_name">
#!string!header_0005!# #!string!header_0005!#
</td> </td>
<td class="column_row_name">
#!string!header_0006!#
</td>
</tr> </tr>
<!-- end network_header --> <!-- end network_header -->
@ -311,6 +314,9 @@
<td class="column_row_value_fixed_centered"> <td class="column_row_value_fixed_centered">
<span name="#!variable!speed_id!#" id="#!variable!speed_id!#">#!variable!speed!#</span> <span name="#!variable!speed_id!#" id="#!variable!speed_id!#">#!variable!speed!#</span>
</td> </td>
<td class="column_row_value_fixed_centered">
<span name="#!variable!order_id!#" id="#!variable!order_id!#">#!variable!order!#</span>
</td>
</tr> </tr>
<!-- end network_entry --> <!-- end network_entry -->

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

@ -40,7 +40,6 @@ sub report_network
my ($an) = @_; my ($an) = @_;
# Write out the data in json format. # Write out the data in json format.
my $network_json = "{\"networks\":[\n";
my $directory = $an->data->{path}{sysfs}{network_interfaces}; my $directory = $an->data->{path}{sysfs}{network_interfaces};
local(*DIRECTORY); local(*DIRECTORY);
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0018", variables => { directory => $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 # 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, interface => $interface,
mac_address => $mac_address, mac_address => $mac_address,
link_state => $link_state, link_state => $link_state,
@ -104,14 +103,78 @@ sub report_network
network_interface_speed => $speed, 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); 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 =~ s/,$//s;
$network_json .= "]}\n"; $network_json .= "]}\n";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_json => $network_json }}); $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' ### TODO: Set the 'status/network.json' name into 'striker.conf'
# Write the JSON file. # Write the JSON file.
my $output_json = $an->data->{path}{directories}{html}."/status/network.json"; my $output_json = $an->data->{path}{directories}{html}."/status/network.json";
@ -125,5 +188,17 @@ sub report_network
group => "apache" 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); return(0);
} }

Loading…
Cancel
Save