diff --git a/AN/Tools/Database.pm b/AN/Tools/Database.pm index 690f5797..bb54979a 100755 --- a/AN/Tools/Database.pm +++ b/AN/Tools/Database.pm @@ -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, diff --git a/cgi-bin/home b/cgi-bin/home index a743ba03..c12bb9e1 100755 --- a/cgi-bin/home +++ b/cgi-bin/home @@ -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} = { - mac => $data->{interface}{$interface}{mac}, - speed => $data->{interface}{$interface}{speed}, - 'link' => $data->{interface}{$interface}{'link'} + 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}, + 'state' => $data->{interface}{$interface}{'state'}, }; - $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { - "interfaces::${interface}::mac" => $an->data->{interfaces}{$interface}{mac}, - "interfaces::${interface}::speed" => $an->data->{interfaces}{$interface}{speed}, - "interfaces::${interface}::link" => $an->data->{interfaces}{$interface}{'link'}, + $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}::state" => $an->data->{interfaces}{$interface}{'state'}, }}); } } @@ -774,17 +788,19 @@ sub get_network_details_form { $interface_list .= "$interface,"; $network .= $an->Template->get({file => "main.html", name => "network_entry", variables => { - #mac => $data->{interface}{$interface}{mac}, - mac => "", - mac_id => $interface."_mac", - name => $interface, - name_id => $interface."_name", - #speed => $data->{interface}{$interface}{speed}, - speed => "", - speed_id => $interface."_speed", - #'link' => $data->{interface}{$interface}{'link'}, - 'link' => "", - link_id => $interface."_link", + #mac => $data->{interface}{$interface}{mac}, + mac => "", + mac_id => $interface."_mac", + name => $interface, + name_id => $interface."_name", + #speed => $data->{interface}{$interface}{speed}, + speed => "", + speed_id => $interface."_speed", + #'link' => $data->{interface}{$interface}{'link'}, + 'link' => "", + link_id => $interface."_link", + order => "", + order_id => $interface."_order", }}); } $interface_list =~ s/,$//; diff --git a/cgi-bin/words.xml b/cgi-bin/words.xml index 53abc504..93597962 100644 --- a/cgi-bin/words.xml +++ b/cgi-bin/words.xml @@ -22,9 +22,10 @@ This is the AN::Tools master 'words' file. Current Network Interfaces and States MAC Address - Current Name - Link State - Link Speed (Mbps) + Name + State + Speed + Up Order Welcome! Lets setup your #!string!brand_0003!# dashboard... diff --git a/html/skins/alteeve/main.html b/html/skins/alteeve/main.html index 3d29491e..d4cf7a85 100644 --- a/html/skins/alteeve/main.html +++ b/html/skins/alteeve/main.html @@ -294,6 +294,9 @@ #!string!header_0005!# + + #!string!header_0006!# + @@ -311,6 +314,9 @@ #!variable!speed!# + + #!variable!order!# + diff --git a/html/skins/alteeve/main.js b/html/skins/alteeve/main.js index c226eede..7fdbb355 100644 --- a/html/skins/alteeve/main.js +++ b/html/skins/alteeve/main.js @@ -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); diff --git a/tools/scancore-update-states b/tools/scancore-update-states index 7a357a52..e9ecdf8f 100755 --- a/tools/scancore-update-states +++ b/tools/scancore-update-states @@ -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 = "\n"; + $network_xml .= "\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 .= " \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 .= "\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); }