* Created Database->insert_or_update_network_interfaces to handle pushing data into update_network_interfaces.

* Updated Database->connect to always test if hosts table exists and load the core schema if not.
* Fixed Database->write to log all SQL when 'sys::database::log_transactions' is set.
* Got tools/scancore-update-states scanning and recording network interface data to the database. Also removed it writing out the XML status file.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent 65636100c6
commit 96670756ab
  1. 1
      AN/Tools.pm
  2. 375
      AN/Tools/Database.pm
  3. 3
      AN/an-tools.xml
  4. 4
      cgi-bin/home
  5. 14
      html/skins/alteeve/main.js
  6. 134
      scancore.sql
  7. 3
      striker.conf
  8. 60
      tools/scancore-update-states

@ -706,6 +706,7 @@ sub _set_paths
createuser => "/usr/bin/createuser", createuser => "/usr/bin/createuser",
dmidecode => "/usr/sbin/dmidecode", dmidecode => "/usr/sbin/dmidecode",
echo => "/usr/bin/echo", echo => "/usr/bin/echo",
ethtool => "/usr/sbin/ethtool",
'firewall-cmd' => "/usr/bin/firewall-cmd", 'firewall-cmd' => "/usr/bin/firewall-cmd",
gethostip => "/usr/bin/gethostip", gethostip => "/usr/bin/gethostip",
hostname => "/usr/bin/hostname", hostname => "/usr/bin/hostname",

@ -840,6 +840,22 @@ sub connect
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { 'sys::use_db_fh' => $an->data->{sys}{use_db_fh} }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { 'sys::use_db_fh' => $an->data->{sys}{use_db_fh} }});
} }
# If the '$test_table' isn't the same as 'defaults::sql::test_table', see if the core schema needs loading first.
if ($test_table ne $an->data->{defaults}{sql}{test_table})
{
my $query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename=".$an->data->{sys}{use_db_fh}->quote($an->data->{defaults}{sql}{test_table})." AND schemaname='public';";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
my $count = $an->Database->query({id => $id, query => $query, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { count => $count }});
if ($count < 1)
{
# Need to load the database.
$an->Database->initialize({id => $id, sql_file => $an->data->{path}{sql}{'Tools.sql'}});
}
}
# Now that I have connected, see if my 'hosts' table exists. # Now that I have connected, see if my 'hosts' table exists.
my $query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename=".$an->data->{sys}{use_db_fh}->quote($test_table)." AND schemaname='public';"; my $query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename=".$an->data->{sys}{use_db_fh}->quote($test_table)." AND schemaname='public';";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { query => $query }});
@ -1424,6 +1440,356 @@ WHERE
} }
=head2 insert_or_update_network_interfaces
This updates (or inserts) a record in the 'interfaces' table. This table is used to store physical network interface information.
If there is an error, an empty string is returned. Otherwise, the record's UUID is returned.
Parameters;
=head3 id (optional)
If set, only the corresponding database will be written to.
=head3 network_interface_bond_uuid (optional)
If this interface is part of a bond, this UUID will be the C<< bonds >> -> C<< bond_uuid >> that this interface is slaved to.
=head3 network_interface_bridge_uuid (optional)
If this interface is connected to a bridge, this is the C<< bridges >> -> C<< bridge_uuid >> of that bridge.
=head3 network_interface_current_name (required)
This is the current device name for this interface.
=head3 network_interface_duplex (optional)
This can be set to C<< full >>, C<< half >> or C<< unknown >>, with the later being the default.
=head3 network_interface_host_uuid (optional)
This is the host's UUID, as set in C<< sys::host_uuid >>. If not passed, the host's UUID will be read from the system.
=head3 network_interface_link_state (optional)
This can be set to C<< 0 >> or C<< 1 >>, with the later being the default. This indicates if a physical link is present.
=head3 network_interface_mac_address (required)
This is the MAC address of the interface.
=head3 network_interface_medium (required)
This is the medium the interface uses. This is generally C<< copper >>, C<< fiber >>, C<< radio >>, etc.
=head3 network_interface_mtu (optional)
This is the maximum transmit unit (MTU) that this interface supports, in bytes per second. This is usally C<< 1500 >>.
=head3 network_interface_operational (optional)
This can be set to C<< up >>, C<< down >> or C<< unknown >>, with the later being the default. This indicates whether the interface is active or not.
=head3 network_interface_requested_name (optional)
This can be set to a different device name from what is currently assigned. If it is set, and if it differs from the current device name, it will be reconfigured the next time the network is updated.
=head3 network_interface_speed (optional)
This is the current speed of the network interface in Mbps (megabits per second). If it is not passed, it is set to 0.
=head3 network_interface_uuid (optional)
This is the UUID of an existing record to be updated. If this is not passed, the UUID will be searched using the interface's MAC address. If no match is found, the record will be INSERTed and a new random UUID generated.
=cut
sub insert_or_update_network_interfaces
{
my $self = shift;
my $parameter = shift;
my $an = $self->parent;
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0125", variables => { method => "Database->insert_or_update_network_interfaces()" }});
my $id = defined $parameter->{id} ? $parameter->{id} : "";
my $network_interface_bond_uuid = defined $parameter->{network_interface_bond_uuid} ? $parameter->{network_interface_bond_uuid} : "--";
my $network_interface_bridge_uuid = defined $parameter->{network_interface_bridge_uuid} ? $parameter->{network_interface_bridge_uuid} : "--";
my $network_interface_current_name = defined $parameter->{network_interface_current_name} ? $parameter->{network_interface_current_name} : "--";
my $network_interface_duplex = defined $parameter->{network_interface_duplex} ? $parameter->{network_interface_duplex} : "--";
my $network_interface_host_uuid = defined $parameter->{network_interface_host_uuid} ? $parameter->{network_interface_host_uuid} : $an->Get->host_uuid;
my $network_interface_link_state = defined $parameter->{network_interface_link_state} ? $parameter->{network_interface_link_state} : "--";
my $network_interface_operational = defined $parameter->{network_interface_operational} ? $parameter->{network_interface_operational} : "--";
my $network_interface_mac_address = defined $parameter->{network_interface_mac_address} ? $parameter->{network_interface_mac_address} : "--";
my $network_interface_medium = defined $parameter->{network_interface_medium} ? $parameter->{network_interface_medium} : "--";
my $network_interface_mtu = defined $parameter->{network_interface_mtu} ? $parameter->{network_interface_mtu} : "--";
my $network_interface_requested_name = defined $parameter->{network_interface_requested_name} ? $parameter->{network_interface_requested_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 => {
id => $id,
network_interface_bond_uuid => $network_interface_bond_uuid,
network_interface_bridge_uuid => $network_interface_bridge_uuid,
network_interface_current_name => $network_interface_current_name,
network_interface_duplex => $network_interface_duplex,
network_interface_host_uuid => $network_interface_host_uuid,
network_interface_link_state => $network_interface_link_state,
network_interface_operational => $network_interface_operational,
network_interface_mac_address => $network_interface_mac_address,
network_interface_medium => $network_interface_medium,
network_interface_mtu => $network_interface_mtu,
network_interface_requested_name => $network_interface_requested_name,
network_interface_speed => $network_interface_speed,
network_interface_uuid => $network_interface_uuid,
}});
# I will need a MAC address and a UUID. If I don't have one, use the other to look it up.
if ((not $network_interface_mac_address) && (not $network_interface_uuid))
{
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_mac_address" }});
return("");
}
elsif (not $network_interface_uuid)
{
# 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 }});
$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 }});
}
# Now, if we're inserting or updating, we'll need to require different bits.
if ($network_interface_uuid)
{
# Update
my $query = "
SELECT
network_interface_host_uuid,
network_interface_mac_address,
network_interface_current_name,
network_interface_requested_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_uuid = ".$an->data->{sys}{use_db_fh}->quote($network_interface_uuid).";
";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, 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 => {
results => $results,
count => $count,
}});
foreach my $row (@{$results})
{
my $old_network_interface_host_uuid = $row->[0];
my $old_network_interface_mac_address = $row->[1];
my $old_network_interface_current_name = $row->[2];
my $old_network_interface_requested_name = defined $row->[3] ? $row->[3] : "";
my $old_network_interface_speed = $row->[4];
my $old_network_interface_mtu = defined $row->[5] ? $row->[5] : "";
my $old_network_interface_link_state = $row->[6];
my $old_network_interface_operational = $row->[7];
my $old_network_interface_duplex = $row->[8];
my $old_network_interface_medium = defined $row->[9] ? $row->[9] : "";
my $old_network_interface_bond_uuid = defined $row->[10] ? $row->[10] : "";
my $old_network_interface_bridge_uuid = defined $row->[10] ? $row->[11] : "";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
old_network_interface_host_uuid => $old_network_interface_host_uuid,
old_network_interface_mac_address => $old_network_interface_mac_address,
old_network_interface_current_name => $old_network_interface_current_name,
old_network_interface_requested_name => $old_network_interface_requested_name,
old_network_interface_speed => $old_network_interface_speed,
old_network_interface_mtu => $old_network_interface_mtu,
old_network_interface_link_state => $old_network_interface_link_state,
old_network_interface_operational => $old_network_interface_operational,
old_network_interface_duplex => $old_network_interface_duplex,
old_network_interface_medium => $old_network_interface_medium,
old_network_interface_bond_uuid => $old_network_interface_bond_uuid,
old_network_interface_bridge_uuid => $old_network_interface_bridge_uuid,
}});
# If the caller didn't pass some values, we'll treat the
# Anything to update? This is a little extra complicated because if a variable was
# not passed in, we want to not compare it.
if ((($network_interface_bond_uuid ne "--") && ($network_interface_bond_uuid ne $old_network_interface_bond_uuid)) or
(($network_interface_bridge_uuid ne "--") && ($network_interface_bridge_uuid ne $old_network_interface_bridge_uuid)) or
(($network_interface_current_name ne "--") && ($network_interface_current_name ne $old_network_interface_current_name)) or
(($network_interface_duplex ne "--") && ($network_interface_duplex ne $old_network_interface_duplex)) or
(($network_interface_link_state ne "--") && ($network_interface_link_state ne $old_network_interface_link_state)) or
(($network_interface_operational ne "--") && ($network_interface_operational ne $old_network_interface_operational)) or
(($network_interface_mac_address ne "--") && ($network_interface_mac_address ne $old_network_interface_mac_address)) or
(($network_interface_medium ne "--") && ($network_interface_medium ne $old_network_interface_medium)) or
(($network_interface_mtu ne "--") && ($network_interface_mtu ne $old_network_interface_mtu)) or
(($network_interface_requested_name ne "--") && ($network_interface_requested_name ne $old_network_interface_requested_name)) or
(($network_interface_speed ne "--") && ($network_interface_speed ne $old_network_interface_speed)) or
($network_interface_host_uuid ne $old_network_interface_host_uuid))
{
# UPDATE any rows passed to us.
my $query = "
UPDATE
network_interfaces
SET
network_interface_host_uuid = ".$an->data->{sys}{use_db_fh}->quote($network_interface_host_uuid).",
";
if ($network_interface_bond_uuid ne "--")
{
$query .= " network_interface_bond_uuid = ".$an->data->{sys}{use_db_fh}->quote($network_interface_bond_uuid).", \n";
}
if ($network_interface_bridge_uuid ne "--")
{
$query .= " network_interface_bridge_uuid = ".$an->data->{sys}{use_db_fh}->quote($network_interface_bridge_uuid).", \n";
}
if ($network_interface_current_name ne "--")
{
$query .= " network_interface_current_name = ".$an->data->{sys}{use_db_fh}->quote($network_interface_current_name).", \n";
}
if ($network_interface_duplex ne "--")
{
$query .= " network_interface_duplex = ".$an->data->{sys}{use_db_fh}->quote($network_interface_duplex).", \n";
}
if ($network_interface_link_state ne "--")
{
$query .= " network_interface_link_state = ".$an->data->{sys}{use_db_fh}->quote($network_interface_link_state).", \n";
}
if ($network_interface_operational ne "--")
{
$query .= " network_interface_operational = ".$an->data->{sys}{use_db_fh}->quote($network_interface_operational).", \n";
}
if ($network_interface_mac_address ne "--")
{
$query .= " network_interface_mac_address = ".$an->data->{sys}{use_db_fh}->quote($network_interface_mac_address).", \n";
}
if ($network_interface_medium ne "--")
{
$query .= " network_interface_medium = ".$an->data->{sys}{use_db_fh}->quote($network_interface_medium).", \n";
}
if ($network_interface_mtu ne "--")
{
$query .= " network_interface_mtu = ".$an->data->{sys}{use_db_fh}->quote($network_interface_mtu).", \n";
}
if ($network_interface_requested_name ne "--")
{
$query .= " network_interface_requested_name = ".$an->data->{sys}{use_db_fh}->quote($network_interface_requested_name).", \n";
}
if ($network_interface_speed ne "--")
{
$query .= " network_interface_speed = ".$an->data->{sys}{use_db_fh}->quote($network_interface_speed).", \n";
}
$query .= " modified_date = ".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{db_timestamp})."
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->Database->write({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
}
else
{
# No change.
}
}
}
else
{
# INSERT, but make sure we have enough data first.
if (($network_interface_mac_address eq "--") or (not $network_interface_mac_address))
{
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_mac_address" }});
return("");
}
if (($network_interface_current_name eq "--") or (not $network_interface_current_name))
{
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_current_name" }});
return("");
}
# Convert unpassed values to their defaults.
$network_interface_bond_uuid = "NULL" if $network_interface_bond_uuid eq "--";
$network_interface_bridge_uuid = "NULL" if $network_interface_bridge_uuid eq "--";
$network_interface_duplex = "unknown" if $network_interface_duplex eq "--";
$network_interface_link_state = 0 if $network_interface_link_state eq "--";
$network_interface_operational = "unknown" if $network_interface_operational eq "--";
$network_interface_medium = "" if $network_interface_medium eq "--";
$network_interface_requested_name = "" if $network_interface_requested_name eq "--";
$network_interface_speed = 0 if $network_interface_speed eq "--";
$network_interface_mtu = 0 if $network_interface_mtu eq "--";
# Make sure the UUIDs are sane.
if (($network_interface_bond_uuid ne "NULL") && (not $an->Validate->is_uuid({uuid => $network_interface_bond_uuid})))
{
# Bad UUID.
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_current_name", uuid => $network_interface_bond_uuid }});
return("");
}
if (($network_interface_bridge_uuid ne "NULL") && (not $an->Validate->is_uuid({uuid => $network_interface_bridge_uuid})))
{
# Bad UUID.
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0130", variables => { method => "Database->insert_or_update_network_interfaces()", parameter => "network_interface_current_name", uuid => $network_interface_bridge_uuid }});
return("");
}
# 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 }});
my $query = "
INSERT INTO
network_interfaces
(
network_interface_uuid,
network_interface_bond_uuid,
network_interface_bridge_uuid,
network_interface_current_name,
network_interface_duplex,
network_interface_host_uuid,
network_interface_link_state,
network_interface_operational,
network_interface_mac_address,
network_interface_medium,
network_interface_mtu,
network_interface_requested_name,
network_interface_speed,
modified_date
) VALUES (
".$an->data->{sys}{use_db_fh}->quote($network_interface_uuid).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_bond_uuid).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_bridge_uuid).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_current_name).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_duplex).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_host_uuid).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_link_state).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_operational).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_mac_address).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_medium).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_mtu).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_requested_name).",
".$an->data->{sys}{use_db_fh}->quote($network_interface_speed).",
".$an->data->{sys}{use_db_fh}->quote($an->data->{sys}{db_timestamp})."
);
";
$query =~ s/'NULL'/NULL/g;
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$an->Database->write({query => $query, id => $id, source => $THIS_FILE, line => __LINE__});
}
$an->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0126", variables => { method => "Database->insert_or_update_network_interfaces()" }});
return($network_interface_uuid);
}
=head2 insert_or_update_states =head2 insert_or_update_states
This updates (or inserts) a record in the 'states' table. The C<< state_uuid >> referencing the database row will be returned. This updates (or inserts) a record in the 'states' table. The C<< state_uuid >> referencing the database row will be returned.
@ -3020,11 +3386,12 @@ sub write
foreach my $query (@{$query_set}) foreach my $query (@{$query_set})
{ {
# TODO: Record the query if ($an->data->{sys}{database}{log_transactions})
#if ($an->Log->db_transactions())
if (1)
{ {
$an->Log->entry({source => $source, line => $line, secure => $secure, level => 2, key => "log_0074", variables => { id => $id, query => $query }}); $an->Log->entry({source => $source, line => $line, secure => $secure, level => 0, key => "log_0083", variables => {
id => $id,
query => $query,
}});
} }
if (not $an->data->{cache}{db_fh}{$id}) if (not $an->data->{cache}{db_fh}{$id})

@ -143,7 +143,7 @@ The database connection error was:
<key name="log_0080"><![CDATA[[ Error ] - The method Database->initialize() was asked to initialize the database: [#!variable!server!#] (id: [#!variable!id!#]) but the core SQL file: [#!variable!sql_file!#] doesn't exist.]]></key> <key name="log_0080"><![CDATA[[ Error ] - The method Database->initialize() was asked to initialize the database: [#!variable!server!#] (id: [#!variable!id!#]) but the core SQL file: [#!variable!sql_file!#] doesn't exist.]]></key>
<key name="log_0081"><![CDATA[[ Error ] - The method Database->initialize() was asked to initialize the database: [#!variable!server!#] (id: [#!variable!id!#]) but the core SQL file: [#!variable!sql_file!#] exist, but can't be read.]]></key> <key name="log_0081"><![CDATA[[ Error ] - The method Database->initialize() was asked to initialize the database: [#!variable!server!#] (id: [#!variable!id!#]) but the core SQL file: [#!variable!sql_file!#] exist, but can't be read.]]></key>
<key name="log_0082">The database: [#!variable!server!#] needs to be initialized using: [#!variable!sql_file!#].</key> <key name="log_0082">The database: [#!variable!server!#] needs to be initialized using: [#!variable!sql_file!#].</key>
<key name="log_0083"></key> <key name="log_0083">About to record: [#!variable!id!#]:[#!variable!query!#]</key>
<key name="log_0084"><![CDATA[[ Error ] - The method Database->query() was asked to query the database: [#!variable!server!#] but no query was given.]]></key> <key name="log_0084"><![CDATA[[ Error ] - The method Database->query() was asked to query the database: [#!variable!server!#] but no query was given.]]></key>
<key name="log_0085"><![CDATA[[ Error ] - The method Database->write() was asked to write to the database: [#!variable!server!#] but no query was given.]]></key> <key name="log_0085"><![CDATA[[ Error ] - The method Database->write() was asked to write to the database: [#!variable!server!#] but no query was given.]]></key>
<key name="log_0086"><![CDATA[[ Error ] - The method System->check_memory() was called without a program name to check.]]></key> <key name="log_0086"><![CDATA[[ Error ] - The method System->check_memory() was called without a program name to check.]]></key>
@ -198,6 +198,7 @@ The database connection error was:
<key name="log_0127">Firewalld was not running, re-enabling it. If you do not want this behaviour, please set 'sys::daemons::restart_firewalld = 0' in the configuration file for this program (or in 'tools.conf').</key> <key name="log_0127">Firewalld was not running, re-enabling it. If you do not want this behaviour, please set 'sys::daemons::restart_firewalld = 0' in the configuration file for this program (or in 'tools.conf').</key>
<key name="log_0128">Firewalld was not running, and 'sys::daemons::restart_firewalld = 0' is set. NOT starting it.</key> <key name="log_0128">Firewalld was not running, and 'sys::daemons::restart_firewalld = 0' is set. NOT starting it.</key>
<key name="log_0129">all</key> <!-- Used when logging DB writes to all DBs --> <key name="log_0129">all</key> <!-- Used when logging DB writes to all DBs -->
<key name="log_0130"><![CDATA[[ Error ] - The method: [#!variable!method!#] was called and the parameter: [#!variable!parameter!#] was passed an invalid UUID: [#!variable!uuid!#].]]></key>
<!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. --> <!-- Test words. Do NOT change unless you update 't/Words.t' or tests will needlessly fail. -->
<key name="t_0000">Test</key> <key name="t_0000">Test</key>

@ -123,7 +123,7 @@ sub config_step2
foreach my $interface (sort {$a cmp $b} keys %{$an->data->{interfaces}}) foreach my $interface (sort {$a cmp $b} keys %{$an->data->{interfaces}})
{ {
my $this_mac = $an->data->{interfaces}{$interface}{mac}; my $this_mac = $an->data->{interfaces}{$interface}{mac};
push @{$interface_options}, $this_mac; push @{$interface_options}, $this_mac."#!#".$this_mac." (".$interface.")";
} }
my $problem = 0; my $problem = 0;
@ -184,7 +184,7 @@ sub config_step2
my $ifn_count = $an->data->{cgi}{ifn_count}{value} ? $an->data->{cgi}{ifn_count}{value} : 1; my $ifn_count = $an->data->{cgi}{ifn_count}{value} ? $an->data->{cgi}{ifn_count}{value} : 1;
foreach my $ifn (1..$ifn_count) foreach my $ifn (1..$ifn_count)
{ {
push @{$links}, "ifn_link".$bcn; push @{$links}, "ifn_link".$ifn;
my $this_ifn_key = "ifn".$ifn; my $this_ifn_key = "ifn".$ifn;
my $this_ip_key = "ifn".$ifn."_ip"; my $this_ip_key = "ifn".$ifn."_ip";
my $this_subnet_key = "ifn".$ifn."_subnet"; my $this_subnet_key = "ifn".$ifn."_subnet";

@ -1,6 +1,6 @@
// $.ajaxSetup({ $.ajaxSetup({
// cache: false cache: false
// }); });
$(function() { $(function() {
var say_up = $('#network_link_state').data('up'); var say_up = $('#network_link_state').data('up');
var say_down = $('#network_link_state').data('down'); var say_down = $('#network_link_state').data('down');
@ -11,7 +11,9 @@ $(function() {
setInterval(function() { setInterval(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+']');
var link = say_up; var link = say_up;
if (element.link == 0) { if (element.link == 0) {
link = say_down; link = say_down;
@ -23,6 +25,10 @@ $(function() {
}); });
}, 1000); }, 1000);
} }
else
{
alert('network status does not exist.');
}
if($("#disk_status").length) { if($("#disk_status").length) {
//alert('disk status exists.'); //alert('disk status exists.');
//$("#bar").text('B'); //$("#bar").text('B');

@ -9,45 +9,47 @@
CREATE TABLE network_interfaces ( CREATE TABLE network_interfaces (
network_interface_uuid uuid not null primary key, network_interface_uuid uuid not null primary key,
network_interface_host_uuid uuid not null, network_interface_host_uuid uuid not null,
network_interface_mac_address text, -- This is allowed to be NULL to support bonds and bridges network_interface_mac_address text not null,
network_interface_current_name text not null, -- This is the current name of the interface. network_interface_current_name text not null, -- This is the current name of the interface.
network_interface_requested_name text, -- This is the name of the interface that the user requested. This will differ from the current name pending a commit request by the user. network_interface_requested_name text, -- This is the name of the interface that the user requested. This will differ from the current name pending a commit request by the user.
network_interface_speed number not null, -- This is the speed, in bits-per-second, of the interface. network_interface_speed bigint not null, -- This is the speed, in bits-per-second, of the interface.
network_interface_mtu number, -- This is the MTU (Maximum Transmitable Size), in bytes, for this interface. network_interface_mtu bigint, -- This is the MTU (Maximum Transmitable Size), in bytes, for this interface.
network_interface_link_state text not null, -- This is 'up', 'down' or 'unknown' network_interface_link_state text not null, -- 0 or 1
network_interface_operational text not null, -- This is 'up', 'down' or 'unknown'
network_interface_duplex text not null, -- This is 'full', 'half' or 'unknown' network_interface_duplex text not null, -- This is 'full', 'half' or 'unknown'
network_interface_medium text not null, -- This is 'tp' (twisted pair), 'fiber' or whatever they invent in the future. network_interface_medium text, -- This is 'tp' (twisted pair), 'fiber' or whatever they invent in the future.
network_interface_bond_uuid uuid, -- If this iface is in a bond, this will contain the 'bonds -> bond_uuid' that it is slaved to. network_interface_bond_uuid uuid, -- If this iface is in a bond, this will contain the 'bonds -> bond_uuid' that it is slaved to.
network_interface_bridge_uuid uuid, -- If this iface is attached to a bridge, this will contain the 'bridgess -> bridge_uuid' that it is connected to. network_interface_bridge_uuid uuid, -- If this iface is attached to a bridge, this will contain the 'bridgess -> bridge_uuid' that it is connected to.
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
ALTER TABLE network_interface OWNER TO #!variable!user!#; ALTER TABLE network_interfaces OWNER TO #!variable!user!#;
CREATE TABLE history.network_interface ( CREATE TABLE history.network_interfaces (
history_id bigserial, history_id bigserial,
network_interface_uuid uuid not null, network_interface_uuid uuid not null,
network_interface_host_uuid uuid, network_interface_host_uuid uuid,
network_interface_mac_address text, network_interface_mac_address text,
network_interface_current_name text, network_interface_current_name text,
network_interface_requested_name text, network_interface_requested_name text,
network_interface_speed number, network_interface_speed bigint,
network_interface_mtu number, network_interface_mtu bigint,
network_interface_link_state text, network_interface_link_state text,
network_interface_operational text,
network_interface_duplex text, network_interface_duplex text,
network_interface_medium text, network_interface_medium text,
network_interface_bond_uuid uuid, network_interface_bond_uuid uuid,
network_interface_bridge_uuid uuid, network_interface_bridge_uuid uuid,
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
ALTER TABLE history.network_interface OWNER TO #!variable!user!#; ALTER TABLE history.network_interfaces OWNER TO #!variable!user!#;
CREATE FUNCTION history_network_interface() RETURNS trigger CREATE FUNCTION history_network_interfaces() RETURNS trigger
AS $$ AS $$
DECLARE DECLARE
history_network_interface RECORD; history_network_interfaces RECORD;
BEGIN BEGIN
SELECT INTO history_network_interface * FROM network_interface WHERE host_uuid = new.host_uuid; SELECT INTO history_network_interfaces * FROM network_interfaces WHERE network_interface_host_uuid = new.network_interface_host_uuid;
INSERT INTO history.network_interface INSERT INTO history.network_interfaces
(network_interface_uuid, (network_interface_uuid,
network_interface_host_uuid, network_interface_host_uuid,
network_interface_mac_address, network_interface_mac_address,
@ -56,34 +58,36 @@ BEGIN
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_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,
modified_date) modified_date)
VALUES VALUES
(history_network_interface.network_interface_uuid, (history_network_interfaces.network_interface_uuid,
history_network_interface.network_interface_host_uuid, history_network_interfaces.network_interface_host_uuid,
history_network_interface.network_interface_mac_address, history_network_interfaces.network_interface_mac_address,
history_network_interface.network_interface_current_name, history_network_interfaces.network_interface_current_name,
history_network_interface.network_interface_requested_name, history_network_interfaces.network_interface_requested_name,
history_network_interface.network_interface_speed, history_network_interfaces.network_interface_speed,
history_network_interface.network_interface_mtu, history_network_interfaces.network_interface_mtu,
history_network_interface.network_interface_link_state, history_network_interfaces.network_interface_link_state,
history_network_interface.network_interface_duplex, history_network_interfaces.network_interface_operational,
history_network_interface.network_interface_medium, history_network_interfaces.network_interface_duplex,
history_network_interface.network_interface_bond_uuid, history_network_interfaces.network_interface_medium,
history_network_interface.network_interface_bridge_uuid, history_network_interfaces.network_interface_bond_uuid,
history_network_interface.modified_date); history_network_interfaces.network_interface_bridge_uuid,
history_network_interfaces.modified_date);
RETURN NULL; RETURN NULL;
END; END;
$$ $$
LANGUAGE plpgsql; LANGUAGE plpgsql;
ALTER FUNCTION history_network_interface() OWNER TO #!variable!user!#; ALTER FUNCTION history_network_interfaces() OWNER TO #!variable!user!#;
CREATE TRIGGER trigger_network_interface CREATE TRIGGER trigger_network_interfaces
AFTER INSERT OR UPDATE ON network_interface AFTER INSERT OR UPDATE ON network_interfaces
FOR EACH ROW EXECUTE PROCEDURE history_network_interface(); FOR EACH ROW EXECUTE PROCEDURE history_network_interfaces();
-- This stores information about network bonds (mode=1) on a hosts. -- This stores information about network bonds (mode=1) on a hosts.
@ -91,15 +95,15 @@ CREATE TABLE bonds (
bond_uuid uuid primary key, bond_uuid uuid primary key,
bond_host_uuid uuid not null, bond_host_uuid uuid not null,
bond_name text not null, bond_name text not null,
bond_mode numeric not null, -- This is the numerical bond type (will translate to the user's language in ScanCore) bond_mode integer not null, -- This is the numerical bond type (will translate to the user's language in ScanCore)
bond_mtu numeric, bond_mtu bigint,
bond_primary_slave text, bond_primary_slave text,
bond_primary_reselect text, bond_primary_reselect text,
bond_active_slave text, bond_active_slave text,
bond_mii_status text, bond_mii_status text,
bond_mii_polling_interval numeric, bond_mii_polling_interval bigint,
bond_up_delay numeric, bond_up_delay bigint,
bond_down_delay numeric, bond_down_delay bigint,
modified_date timestamp with time zone not null, modified_date timestamp with time zone not null,
FOREIGN KEY(bond_host_uuid) REFERENCES hosts(host_uuid) FOREIGN KEY(bond_host_uuid) REFERENCES hosts(host_uuid)
@ -111,15 +115,15 @@ CREATE TABLE history.bonds (
bond_uuid uuid, bond_uuid uuid,
bond_host_uuid uuid, bond_host_uuid uuid,
bond_name text, bond_name text,
bond_mode numeric, bond_mode integer,
bond_mtu numeric, bond_mtu bigint,
bond_primary_slave text, bond_primary_slave text,
bond_primary_reselect text, bond_primary_reselect text,
bond_active_slave text, bond_active_slave text,
bond_mii_status text, bond_mii_status text,
bond_mii_polling_interval numeric, bond_mii_polling_interval bigint,
bond_up_delay numeric, bond_up_delay bigint,
bond_down_delay numeric, bond_down_delay bigint,
modified_date timestamp with time zone not null modified_date timestamp with time zone not null
); );
ALTER TABLE history.bonds OWNER TO #!variable!user!#; ALTER TABLE history.bonds OWNER TO #!variable!user!#;
@ -145,28 +149,28 @@ BEGIN
bond_down_delay, bond_down_delay,
modified_date) modified_date)
VALUES VALUES
(history_bond.bond_uuid, (history_bonds.bond_uuid,
history_bond.bond_host_uuid, history_bonds.bond_host_uuid,
history_bond.bond_name, history_bonds.bond_name,
history_bond.bond_mode, history_bonds.bond_mode,
history_bond.bond_mtu, history_bonds.bond_mtu,
history_bond.bond_primary_slave, history_bonds.bond_primary_slave,
history_bond.bond_primary_reselect, history_bonds.bond_primary_reselect,
history_bond.bond_active_slave, history_bonds.bond_active_slave,
history_bond.bond_mii_status, history_bonds.bond_mii_status,
history_bond.bond_mii_polling_interval, history_bonds.bond_mii_polling_interval,
history_bond.bond_up_delay, history_bonds.bond_up_delay,
history_bond.bond_down_delay, history_bonds.bond_down_delay,
history_bond.modified_date); history_bonds.modified_date);
RETURN NULL; RETURN NULL;
END; END;
$$ $$
LANGUAGE plpgsql; LANGUAGE plpgsql;
ALTER FUNCTION history_bonds() OWNER TO #!variable!user!#; ALTER FUNCTION history_bonds() OWNER TO #!variable!user!#;
CREATE TRIGGER trigger_bond CREATE TRIGGER trigger_bonds
AFTER INSERT OR UPDATE ON bonds AFTER INSERT OR UPDATE ON bonds
FOR EACH ROW EXECUTE PROCEDURE history_bond(); FOR EACH ROW EXECUTE PROCEDURE history_bonds();
-- This stores information about network bridges. -- This stores information about network bridges.
@ -208,20 +212,20 @@ BEGIN
bridge_stp_enabled, bridge_stp_enabled,
modified_date) modified_date)
VALUES VALUES
(history_bridge.bridge_uuid, (history_bridges.bridge_uuid,
history_bridge.bridge_host_uuid, history_bridges.bridge_host_uuid,
history_bridge.bridge_name, history_bridges.bridge_name,
history_bridge.bridge_name, history_bridges.bridge_name,
history_bridge.bridge_id, history_bridges.bridge_id,
history_bridge.bridge_stp_enabled, history_bridges.bridge_stp_enabled,
history_bridge.modified_date); history_bridges.modified_date);
RETURN NULL; RETURN NULL;
END; END;
$$ $$
LANGUAGE plpgsql; LANGUAGE plpgsql;
ALTER FUNCTION history_bridges() OWNER TO #!variable!user!#; ALTER FUNCTION history_bridges() OWNER TO #!variable!user!#;
CREATE TRIGGER trigger_bridge CREATE TRIGGER trigger_bridges
AFTER INSERT OR UPDATE ON bridges AFTER INSERT OR UPDATE ON bridges
FOR EACH ROW EXECUTE PROCEDURE history_bridge(); FOR EACH ROW EXECUTE PROCEDURE history_bridges();

@ -15,6 +15,9 @@ database::2::user = admin
database::2::password = Initial1 database::2::password = Initial1
database::2::ping_before_connect = 1 database::2::ping_before_connect = 1
# This is the schema for the ScanCore database.
sys::database::schema = /etc/scancore/scancore.sql
# This puts a limit on how many queries (writes, generally) to make in a single batch transaction. This is # This puts a limit on how many queries (writes, generally) to make in a single batch transaction. This is
# useful when doing very large transacions, like resync'ing a large table, by limiting how long a given # useful when doing very large transacions, like resync'ing a large table, by limiting how long a given
# transaction can take and how much memory is used. # transaction can take and how much memory is used.

@ -18,6 +18,10 @@ my $an = AN::Tools->new();
$an->Log->level({set => 2}); $an->Log->level({set => 2});
$an->Storage->read_config({file => "/etc/striker/striker.conf"}); $an->Storage->read_config({file => "/etc/striker/striker.conf"});
my $connections = $an->Database->connect({
sql_file => $an->data->{sys}{database}{schema},
test_table => "network_interfaces",
});
# Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete. # Turn off buffering so that the pinwheel will display while waiting for the SSH call(s) to complete.
$| = 1; $| = 1;
@ -37,10 +41,7 @@ sub report_network
# Write out the data in json format. # Write out the data in json format.
my $network_json = "{\"networks\":[\n"; my $network_json = "{\"networks\":[\n";
my $network_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; my $directory = $an->data->{path}{sysfs}{network_interfaces};
$network_xml .= "<network>\n";
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 }});
opendir(DIRECTORY, $directory); opendir(DIRECTORY, $directory);
@ -63,11 +64,25 @@ sub report_network
my $speed = $link_state ? $an->Storage->read_file({file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link my $speed = $link_state ? $an->Storage->read_file({file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link
if ($speed > 100000) if ($speed > 100000)
{ {
# This is probably 0 now... Though someday >100 Gbps will be reasonable and # NOTE: This is probably 0 now... Though someday >100 Gbps will be reasonable
# we'll need to change this. # and we'll need to change this.
$speed = 0; $speed = 0;
} }
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
# Find the media, if possible.
my $media = "unknown";
my $ethtool = $an->System->call({shell_call => $an->data->{path}{exe}{ethtool}});
foreach my $line (split/\n/, $ethtool)
{
if ($line =~ /Supported ports: \[ (.*?) \]/i)
{
$media = lc($1);
last;
}
}
# Log
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
interface => $interface, interface => $interface,
mac_address => $mac_address, mac_address => $mac_address,
link_state => $link_state, link_state => $link_state,
@ -75,10 +90,21 @@ sub report_network
duplex => $duplex, duplex => $duplex,
operational => $operational, operational => $operational,
speed => $speed, speed => $speed,
media => $media,
}}); }});
$network_json .= " { \"name\":\"$interface\", \"mac\":\"$mac_address\", \"link\":\"$link_state\", \"duplex\":\"$duplex\", \"state\":\"$operational\", \"speed\":\"$speed\" },\n"; $an->Database->insert_or_update_network_interfaces({
$network_xml .= " <interface name=\"$interface\" mac=\"$mac_address\" link=\"$link_state\" duplex=\"$duplex\" state=\"$operational\" speed=\"$speed\" />\n"; network_interface_current_name => $interface,
network_interface_duplex => $duplex,
network_interface_link_state => $link_state,
network_interface_operational => $operational,
network_interface_mac_address => $mac_address,
network_interface_medium => $media,
network_interface_mtu => $mtu,
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);
@ -86,10 +112,7 @@ sub report_network
$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"; ### TODO: Set the 'status/network.json' name into 'striker.conf'
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_xml => $network_xml }});
### TODO: Set the 'status/network.xml' and 'status/network.json' names 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";
$an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_json }}); $an->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_json }});
@ -101,17 +124,6 @@ sub report_network
user => "apache", user => "apache",
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