Fixed a bug in initializing DROP'ed DBs.

* Got more work done on adding network_interfaces to the database in
  scan-server.

Signed-off-by: digimer <mkelly@alteeve.ca>
main
digimer 12 months ago
parent ec11335197
commit 9c67b97fdd
  1. 43
      Anvil/Tools/Database.pm
  2. 23
      Anvil/Tools/Network.pm
  3. 198
      scancore-agents/scan-network/scan-network
  4. 26
      share/anvil.sql
  5. 162
      tools/anvil-version-changes

@ -786,7 +786,11 @@ If the system is already configured, this method will do nothing, so it is safe
If the method completes, C<< 0 >> is returned. If this method is called without C<< root >> access, it returns C<< 1 >> without doing anything. If there is a problem, C<< !!error!! >> is returned.
This method takes no parameters.
Parameters;
=head3 check_db_exists (optional, default 0)
If set, the database will be checked to see if the schema exists. This is normally not needed, but can be triggered if the database was DROP'ed by a user.
=cut
### TODO: Much of this logic is in striker-prep-database, consolidate!
@ -797,6 +801,11 @@ sub configure_pgsql
my $anvil = $self->parent;
my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Database->configure_pgsql()" }});
my $check_db_exists = defined $parameter->{check_db_exists} ? $parameter->{check_db_exists} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
check_db_exists => $check_db_exists,
}});
# The local host_uuid is the ID of the local database, so get that.
my $uuid = $anvil->Get->host_uuid();
@ -1012,7 +1021,7 @@ sub configure_pgsql
's2:update_postgresql_file' => $update_postgresql_file,
's3:update_pg_hba_file' => $update_pg_hba_file,
}});
if (($initialized) or ($update_postgresql_file) or ($update_pg_hba_file))
if (($initialized) or ($update_postgresql_file) or ($update_pg_hba_file) or ($check_db_exists))
{
# Create the .pgpass file, if needed.
my $created_pgpass = 0;
@ -1366,7 +1375,11 @@ sub connect
# This method just returns if nothing is needed.
if (($local_host_type eq "striker") && ($check_if_configured) && ($< == 0) && ($> == 0))
{
$anvil->Database->configure_pgsql({debug => 2, uuid => $local_host_uuid});
$anvil->Database->configure_pgsql({
debug => 2,
uuid => $local_host_uuid,
check_db_exists => $check_if_configured,
});
}
# Now setup or however-many connections
@ -11422,7 +11435,7 @@ This is the maximum transmit unit (MTU) that this interface supports, in bytes p
This is the nmcli 'connection.id' name (bios device name) for the current device of this interface. If the previously recorded MAC address is no longer found, but a new/unknown interface with this name is found, it is sane to configure the device with this name as the replacement 'network_interface_device'.
=head3 network_interface_nmcli_uuid (optional)
=head3 network_interface_nm_uuid (optional)
This is the network manager's UUID for this interface.
@ -11463,7 +11476,7 @@ sub insert_or_update_network_interfaces
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} : 0;
my $network_interface_name = defined $parameter->{network_interface_name} ? $parameter->{network_interface_name} : "";
my $network_interface_nmcli_uuid = defined $parameter->{network_interface_nmcli_uuid} ? $parameter->{network_interface_nmcli_uuid} : "";
my $network_interface_nm_uuid = defined $parameter->{network_interface_nm_uuid} ? $parameter->{network_interface_nm_uuid} : "";
my $network_interface_speed = defined $parameter->{network_interface_speed} ? $parameter->{network_interface_speed} : 0;
my $network_interface_uuid = defined $parameter->{network_interface_uuid} ? $parameter->{network_interface_uuid} : "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
@ -11483,7 +11496,7 @@ sub insert_or_update_network_interfaces
network_interface_medium => $network_interface_medium,
network_interface_mtu => $network_interface_mtu,
network_interface_name => $network_interface_name,
network_interface_nmcli_uuid => $network_interface_nmcli_uuid,
network_interface_nm_uuid => $network_interface_nm_uuid,
network_interface_speed => $network_interface_speed,
network_interface_uuid => $network_interface_uuid,
}});
@ -11624,7 +11637,7 @@ WHERE
my $query = "
SELECT
network_interface_host_uuid,
network_interface_nmcli_uuid,
network_interface_nm_uuid,
network_interface_mac_address,
network_interface_name,
network_interface_device,
@ -11658,7 +11671,7 @@ WHERE
foreach my $row (@{$results})
{
my $old_network_interface_host_uuid = $row->[0];
my $old_network_interface_nmcli_uuid = defined $row->[1] ? $row->[1] : 'NULL';
my $old_network_interface_nm_uuid = defined $row->[1] ? $row->[1] : 'NULL';
my $old_network_interface_mac_address = $row->[1];
my $old_network_interface_name = $row->[2];
my $old_network_interface_device = $row->[3];
@ -11672,7 +11685,7 @@ WHERE
my $old_network_interface_bridge_uuid = defined $row->[11] ? $row->[11] : 'NULL';
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
old_network_interface_host_uuid => $old_network_interface_host_uuid,
old_network_interface_nmcli_uuid => $old_network_interface_nmcli_uuid,
old_network_interface_nm_uuid => $old_network_interface_nm_uuid,
old_network_interface_mac_address => $old_network_interface_mac_address,
old_network_interface_name => $old_network_interface_name,
old_network_interface_device => $old_network_interface_device,
@ -11689,7 +11702,7 @@ WHERE
# If 'link_only' is set, we're only checking/updating a subset of values.
if ($link_only)
{
if (($network_interface_nmcli_uuid ne $old_network_interface_nmcli_uuid) or
if (($network_interface_nm_uuid ne $old_network_interface_nm_uuid) or
($network_interface_name ne $old_network_interface_name) or
($network_interface_device ne $old_network_interface_device) or
($network_interface_link_state ne $old_network_interface_link_state) or
@ -11703,7 +11716,7 @@ UPDATE
network_interfaces
SET
network_interface_host_uuid = ".$anvil->Database->quote($network_interface_host_uuid).",
network_interface_nmcli_uuid = ".$anvil->Database->quote($network_interface_nmcli_uuid).",
network_interface_nm_uuid = ".$anvil->Database->quote($network_interface_nm_uuid).",
network_interface_name = ".$anvil->Database->quote($network_interface_name).",
network_interface_device = ".$anvil->Database->quote($network_interface_device).",
network_interface_link_state = ".$anvil->Database->quote($network_interface_link_state).",
@ -11725,7 +11738,7 @@ WHERE
# not passed in, we want to not compare it.
if (($network_interface_bond_uuid ne $old_network_interface_bond_uuid) or
($network_interface_bridge_uuid ne $old_network_interface_bridge_uuid) or
($network_interface_nmcli_uuid ne $old_network_interface_nmcli_uuid) or
($network_interface_nm_uuid ne $old_network_interface_nm_uuid) or
($network_interface_name ne $old_network_interface_name) or
($network_interface_device ne $old_network_interface_device) or
($network_interface_duplex ne $old_network_interface_duplex) or
@ -11743,7 +11756,7 @@ UPDATE
network_interfaces
SET
network_interface_host_uuid = ".$anvil->Database->quote($network_interface_host_uuid).",
network_interface_nmcli_uuid = ".$anvil->Database->quote($network_interface_nmcli_uuid).",
network_interface_nm_uuid = ".$anvil->Database->quote($network_interface_nm_uuid).",
network_interface_bond_uuid = ".$anvil->Database->quote($network_interface_bond_uuid).",
network_interface_bridge_uuid = ".$anvil->Database->quote($network_interface_bridge_uuid).",
network_interface_name = ".$anvil->Database->quote($network_interface_name).",
@ -11776,7 +11789,7 @@ INSERT INTO
network_interfaces
(
network_interface_uuid,
network_interface_nmcli_uuid,
network_interface_nm_uuid,
network_interface_bond_uuid,
network_interface_bridge_uuid,
network_interface_name,
@ -11792,7 +11805,7 @@ INSERT INTO
modified_date
) VALUES (
".$anvil->Database->quote($network_interface_uuid).",
".$anvil->Database->quote($network_interface_nmcli_uuid).",
".$anvil->Database->quote($network_interface_nm_uuid).",
".$anvil->Database->quote($network_interface_bond_uuid).",
".$anvil->Database->quote($network_interface_bridge_uuid).",
".$anvil->Database->quote($network_interface_name).",

@ -1172,16 +1172,33 @@ sub collect_data
{
my $connection_interface_name = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.interface-name'} // "";
my $general_devices = $anvil->data->{nmcli}{uuid}{$uuid}{'GENERAL.DEVICES'} // "";
my $general_ip_iface = $anvil->data->{nmcli}{uuid}{$uuid}{'GENERAL.IP-IFACE'} // "";
my $device_type = $anvil->data->{nmcli}{uuid}{$uuid}{'connection.type'} // "";
my $device = $connection_interface_name ne "--" ? $connection_interface_name : $general_devices;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
's1:uuid' => $uuid,
's2:connection_interface_name' => $connection_interface_name,
's3:general_devices' => $general_devices,
's4:device_type' => $device_type,
's5:device' => $device,
's4:general_ip_iface' => $general_ip_iface,
's5:device_type' => $device_type,
}});
my $device = "";
if (($general_ip_iface) && ($general_ip_iface ne "--"))
{
$device = $general_ip_iface;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device => $device }});
}
elsif (($connection_interface_name) && ($connection_interface_name ne "--"))
{
$device = $connection_interface_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device => $device }});
}
elsif (($general_devices) && ($general_devices ne "--"))
{
$device = $connection_interface_name;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { device => $device }});
}
if ($device)
{
$anvil->data->{nmcli}{device}{$device}{uuid} = $uuid;

@ -537,27 +537,28 @@ sub collect_data
{
# Pull out the data I want. Note that some of these don't exist with virtio-net interfaces.
my $interface = $file;
my $nm_uuid = $anvil->data->{nmcli}{interface}{$interface}{uuid} ? $anvil->data->{nmcli}{interface}{$interface}{uuid} : "";
my $nm_device = "";
my $link_state = -e $full_path."/carrier" ? $anvil->Storage->read_file({file => $full_path."/carrier"}) : 0;
$link_state =~ s/\n$//;
my $mtu = -e $full_path."/mtu" ? $anvil->Storage->read_file({file => $full_path."/mtu"}) : 0;
$mtu =~ s/\n$//;
my $duplex = -e $full_path."/duplex" ? $anvil->Storage->read_file({file => $full_path."/duplex"}) : "unknown"; # full or half?
$duplex =~ s/\n$//;
my $operational = -e $full_path."/operstate" ? $anvil->Storage->read_file({file => $full_path."/operstate"}) : "unknown"; # up or down
$operational =~ s/\n$//;
my $modalias = -e $full_path."/device/modalias" ? $anvil->Storage->read_file({file => $full_path."/device/modalias"}) : "unknown";
$modalias =~ s/\n$//;
my $speed = $link_state ? $anvil->Storage->read_file({file => $full_path."/speed"}) : 0; # Mbps (ie: 1000 = Gbps), gives a very high number for unplugged link
$speed =~ s/\n$//;
my $media = "unknown";
my $type = "interface";
my $driver = "";
my $tx_bytes = 0; # How many bytes transmitted
my $rx_bytes = 0; # How many bytes received
# Clean up some newlines.
$link_state =~ s/\n$//;
$mtu =~ s/\n$//;
$duplex =~ s/\n$//;
$operational =~ s/\n$//;
$speed =~ s/\n$//;
$modalias =~ s/\n$//;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
interface => $interface,
nm_uuid => $nm_uuid,
link_state => $link_state,
mtu => $mtu,
duplex => $duplex,
@ -680,7 +681,12 @@ sub collect_data
{
# Yup, we'll neet to dig into the bond proc files to get the proper slaved
# interface MAC addresses.
$type = "bond";
$type = "bond";
$nm_uuid = $anvil->data->{nmcli}{bond}{$interface}{uuid};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
type => $type,
nm_uuid => $nm_uuid,
}});
# Read the bond mode.
$bond_mode = $anvil->Storage->read_file({file => "/sys/devices/virtual/net/".$interface."/bonding/mode"});
@ -722,15 +728,17 @@ sub collect_data
{
# It's a bridge
$type = "bridge";
$nm_uuid = $anvil->data->{nmcli}{bridge}{$interface}{uuid};
$bridge_id = $anvil->Storage->read_file({debug => 3, file => $full_path."/bridge/bridge_id"});
$bridge_stp_enabled = $anvil->Storage->read_file({debug => 3, file => $full_path."/bridge/stp_state"});
$bridge_id =~ s/\n$//;
$bridge_stp_enabled =~ s/\n$//;
$speed = 0;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
type => $type,
nm_uuid => $nm_uuid,
bridge_id => $bridge_id,
bridge_stp_enabled => $bridge_stp_enabled,
type => $type,
}});
if ($bridge_stp_enabled eq "0")
{
@ -747,6 +755,12 @@ sub collect_data
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { bridge_stp_enabled => $bridge_stp_enabled }});
}
if ($nm_uuid)
{
$nm_device = $anvil->data->{nmcli}{uuid}{$nm_uuid}{device};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { nm_device => $nm_device }});
}
# If this is a 'vnet' device, set 'operational' to up
if ($interface =~ /^vnet/)
{
@ -822,6 +836,8 @@ sub collect_data
}
# Store new information we found.
$anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid} = $nm_uuid;
$anvil->data->{network}{$local_host}{interface}{$interface}{nm_device} = $nm_device;
$anvil->data->{network}{$local_host}{interface}{$interface}{active_interface} = $active_interface;
$anvil->data->{network}{$local_host}{interface}{$interface}{bond_mode} = $bond_mode;
$anvil->data->{network}{$local_host}{interface}{$interface}{bond_master} = $bond_master;
@ -843,6 +859,8 @@ sub collect_data
$anvil->data->{network}{$local_host}{interface}{$interface}{type} = $type;
$anvil->data->{network}{$local_host}{interface}{$interface}{up_delay} = $up_delay;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"network::${local_host}::interface::${interface}::nm_uuid" => $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid},
"network::${local_host}::interface::${interface}::nm_device" => $anvil->data->{network}{$local_host}{interface}{$interface}{nm_device},
"network::${local_host}::interface::${interface}::active_interface" => $anvil->data->{network}{$local_host}{interface}{$interface}{active_interface},
"network::${local_host}::interface::${interface}::bond_mode" => $anvil->data->{network}{$local_host}{interface}{$interface}{bond_mode},
"network::${local_host}::interface::${interface}::bond_master" => $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master},
@ -881,7 +899,139 @@ sub collect_data
}
closedir(DIRECTORY);
die;
# Find what interfaces are connected to which bridges
$anvil->Network->bridge_info({debug => 2});
foreach my $interface (sort {$a cmp $b} keys %{$anvil->data->{network}{$local_host}{interface}})
{
my $ip_address = $anvil->data->{network}{$local_host}{interface}{$interface}{ip};
my $type = $anvil->data->{network}{$local_host}{interface}{$interface}{type};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
interface => $interface,
ip_address => $ip_address,
type => $type,
}});
$anvil->data->{interface}{name_to_type}{$interface} = $type;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"interface::name_to_type::${interface}" => $anvil->data->{interface}{name_to_type}{$interface},
}});
if ($type eq "bridge")
{
# Store the bridge
$anvil->data->{new}{bridge}{$interface}{nm_uuid} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid};
$anvil->data->{new}{bridge}{$interface}{id} = $anvil->data->{network}{$local_host}{interface}{$interface}{bridge_id};
$anvil->data->{new}{bridge}{$interface}{mac_address} = $anvil->data->{network}{$local_host}{interface}{$interface}{mac_address};
$anvil->data->{new}{bridge}{$interface}{mtu} = $anvil->data->{network}{$local_host}{interface}{$interface}{mtu};
$anvil->data->{new}{bridge}{$interface}{stp_enabled} = $anvil->data->{network}{$local_host}{interface}{$interface}{bridge_stp_enabled};
$anvil->data->{new}{bridge}{$interface}{tx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{tx_bytes};
$anvil->data->{new}{bridge}{$interface}{rx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{rx_bytes};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::bridge::${interface}::nm_uuid" => $anvil->data->{new}{bridge}{$interface}{nm_uuid},
"new::bridge::${interface}::id" => $anvil->data->{new}{bridge}{$interface}{id},
"new::bridge::${interface}::mac_address" => $anvil->data->{new}{bridge}{$interface}{mac_address},
"new::bridge::${interface}::mtu" => $anvil->data->{new}{bridge}{$interface}{mtu},
"new::bridge::${interface}::stp_enabled" => $anvil->data->{new}{bridge}{$interface}{stp_enabled},
"new::bridge::${interface}::tx_bytes" => $anvil->data->{new}{bridge}{$interface}{tx_bytes}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{new}{bridge}{$interface}{tx_bytes}}).")",
"new::bridge::${interface}::rx_bytes" => $anvil->data->{new}{bridge}{$interface}{rx_bytes}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{new}{bridge}{$interface}{rx_bytes}}).")",
}});
}
elsif ($type eq "bond")
{
# Store the bond
$anvil->data->{new}{bond}{$interface}{nm_uuid} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid};
$anvil->data->{new}{bond}{$interface}{mode} = $anvil->data->{network}{$local_host}{interface}{$interface}{bond_mode};
$anvil->data->{new}{bond}{$interface}{mtu} = $anvil->data->{network}{$local_host}{interface}{$interface}{mtu};
$anvil->data->{new}{bond}{$interface}{master} = $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master};
$anvil->data->{new}{bond}{$interface}{link_state} = $anvil->data->{network}{$local_host}{interface}{$interface}{link_state};
$anvil->data->{new}{bond}{$interface}{operational} = $anvil->data->{network}{$local_host}{interface}{$interface}{operational};
$anvil->data->{new}{bond}{$interface}{mac_address} = $anvil->data->{network}{$local_host}{interface}{$interface}{mac_address};
$anvil->data->{new}{bond}{$interface}{primary_interface} = $anvil->data->{network}{$local_host}{interface}{$interface}{primary_interface};
$anvil->data->{new}{bond}{$interface}{primary_reselect} = $anvil->data->{network}{$local_host}{interface}{$interface}{primary_reselect};
$anvil->data->{new}{bond}{$interface}{active_interface} = $anvil->data->{network}{$local_host}{interface}{$interface}{active_interface};
$anvil->data->{new}{bond}{$interface}{mii_polling_interval} = $anvil->data->{network}{$local_host}{interface}{$interface}{mii_polling_interval};
$anvil->data->{new}{bond}{$interface}{up_delay} = $anvil->data->{network}{$local_host}{interface}{$interface}{up_delay};
$anvil->data->{new}{bond}{$interface}{down_delay} = $anvil->data->{network}{$local_host}{interface}{$interface}{down_delay};
$anvil->data->{new}{bond}{$interface}{bridge_uuid} = ""; # We'll dig his out later as the bridge might not be in the database yet.
$anvil->data->{new}{bond}{$interface}{tx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{tx_bytes};
$anvil->data->{new}{bond}{$interface}{rx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{rx_bytes};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::bond::${interface}::nm_uuid" => $anvil->data->{new}{bond}{$interface}{nm_uuid},
"new::bond::${interface}::mode" => $anvil->data->{new}{bond}{$interface}{mode},
"new::bond::${interface}::mtu" => $anvil->data->{new}{bond}{$interface}{mtu},
"new::bond::${interface}::master" => $anvil->data->{new}{bond}{$interface}{master},
"new::bond::${interface}::link_state" => $anvil->data->{new}{bond}{$interface}{link_state},
"new::bond::${interface}::operational" => $anvil->data->{new}{bond}{$interface}{operational},
"new::bond::${interface}::mac_address" => $anvil->data->{new}{bond}{$interface}{mac_address},
"new::bond::${interface}::primary_interface" => $anvil->data->{new}{bond}{$interface}{primary_interface},
"new::bond::${interface}::primary_reselect" => $anvil->data->{new}{bond}{$interface}{primary_reselect},
"new::bond::${interface}::active_interface" => $anvil->data->{new}{bond}{$interface}{active_interface},
"new::bond::${interface}::mii_polling_interval" => $anvil->data->{new}{bond}{$interface}{mii_polling_interval},
"new::bond::${interface}::up_delay" => $anvil->data->{new}{bond}{$interface}{up_delay},
"new::bond::${interface}::down_delay" => $anvil->data->{new}{bond}{$interface}{down_delay},
"new::bond::${interface}::bridge_uuid" => $anvil->data->{new}{bond}{$interface}{bridge_uuid},
"new::bond::${interface}::tx_bytes" => $anvil->data->{new}{bond}{$interface}{tx_bytes}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{new}{bond}{$interface}{tx_bytes}}).")",
"new::bond::${interface}::rx_bytes" => $anvil->data->{new}{bond}{$interface}{rx_bytes}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{new}{bond}{$interface}{rx_bytes}}).")",
}});
}
elsif ($type eq "interface")
{
# Store the interface
$anvil->data->{new}{interface}{$interface}{nm_uuid} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid};
$anvil->data->{new}{interface}{$interface}{nm_device} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_device};
$anvil->data->{new}{interface}{$interface}{bond_uuid} = "";
$anvil->data->{new}{interface}{$interface}{bond_name} = $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master};
$anvil->data->{new}{interface}{$interface}{bridge_uuid} = "";
$anvil->data->{new}{interface}{$interface}{bridge_name} = "";
$anvil->data->{new}{interface}{$interface}{duplex} = $anvil->data->{network}{$local_host}{interface}{$interface}{duplex};
$anvil->data->{new}{interface}{$interface}{link_state} = $anvil->data->{network}{$local_host}{interface}{$interface}{link_state};
$anvil->data->{new}{interface}{$interface}{operational} = $anvil->data->{network}{$local_host}{interface}{$interface}{operational};
$anvil->data->{new}{interface}{$interface}{mac_address} = $anvil->data->{network}{$local_host}{interface}{$interface}{mac_address};
$anvil->data->{new}{interface}{$interface}{medium} = $anvil->data->{network}{$local_host}{interface}{$interface}{media};
$anvil->data->{new}{interface}{$interface}{mtu} = $anvil->data->{network}{$local_host}{interface}{$interface}{mtu};
$anvil->data->{new}{interface}{$interface}{speed} = $anvil->data->{network}{$local_host}{interface}{$interface}{speed};
$anvil->data->{new}{interface}{$interface}{tx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{tx_bytes};
$anvil->data->{new}{interface}{$interface}{rx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{rx_bytes};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::interface::${interface}::nm_uuid" => $anvil->data->{new}{interface}{$interface}{nm_uuid},
"new::interface::${interface}::nm_device" => $anvil->data->{new}{interface}{$interface}{nm_device},
"new::interface::${interface}::bond_uuid" => $anvil->data->{new}{interface}{$interface}{bond_uuid},
"new::interface::${interface}::bond_name" => $anvil->data->{new}{interface}{$interface}{bond_name},
"new::interface::${interface}::bridge_uuid" => $anvil->data->{new}{interface}{$interface}{bridge_uuid},
"new::interface::${interface}::bridge_name" => $anvil->data->{new}{interface}{$interface}{bridge_name},
"new::interface::${interface}::duplex" => $anvil->data->{new}{interface}{$interface}{duplex},
"new::interface::${interface}::link_state" => $anvil->data->{new}{interface}{$interface}{link_state},
"new::interface::${interface}::operational" => $anvil->data->{new}{interface}{$interface}{operational},
"new::interface::${interface}::mac_address" => $anvil->data->{new}{interface}{$interface}{mac_address},
"new::interface::${interface}::medium" => $anvil->data->{new}{interface}{$interface}{medium},
"new::interface::${interface}::mtu" => $anvil->data->{new}{interface}{$interface}{mtu},
"new::interface::${interface}::speed" => $anvil->data->{new}{interface}{$interface}{speed},
"new::interface::${interface}::tx_bytes" => $anvil->data->{new}{interface}{$interface}{tx_bytes}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{new}{interface}{$interface}{tx_bytes}}).")",
"new::interface::${interface}::rx_bytes" => $anvil->data->{new}{interface}{$interface}{rx_bytes}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{new}{interface}{$interface}{rx_bytes}}).")",
}});
}
# Record the IP address info.
if ($ip_address)
{
$anvil->data->{new}{ip_address}{$ip_address}{on_interface} = $interface;
$anvil->data->{new}{ip_address}{$ip_address}{subnet_mask} = $anvil->data->{network}{$local_host}{interface}{$interface}{subnet_mask};
$anvil->data->{new}{ip_address}{$ip_address}{gateway} = $anvil->data->{network}{$local_host}{interface}{$interface}{gateway};
$anvil->data->{new}{ip_address}{$ip_address}{default_gateway} = $anvil->data->{network}{$local_host}{interface}{$interface}{default_gateway};
$anvil->data->{new}{ip_address}{$ip_address}{dns} = $anvil->data->{network}{$local_host}{interface}{$interface}{dns};
$anvil->data->{new}{ip_address}{$ip_address}{on_uuid} = "";
$anvil->data->{new}{ip_address}{$ip_address}{note} = "";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::ip_address::${ip_address}::on_interface" => $anvil->data->{new}{ip_address}{$ip_address}{on_interface},
"new::ip_address::${ip_address}::subnet_mask" => $anvil->data->{new}{ip_address}{$ip_address}{subnet_mask},
"new::ip_address::${ip_address}::gateway" => $anvil->data->{new}{ip_address}{$ip_address}{gateway},
"new::ip_address::${ip_address}::default_gateway" => $anvil->data->{new}{ip_address}{$ip_address}{default_gateway},
"new::ip_address::${ip_address}::dns" => $anvil->data->{new}{ip_address}{$ip_address}{dns},
"new::ip_address::${ip_address}::on_uuid" => $anvil->data->{new}{ip_address}{$ip_address}{on_uuid},
"new::ip_address::${ip_address}::note" => $anvil->data->{new}{ip_address}{$ip_address}{note},
}});
}
}
return(0);
}
@ -1288,6 +1438,7 @@ sub collect_data_ifcfg
if ($type eq "bridge")
{
# Store the bridge
$anvil->data->{new}{bridge}{$interface}{nm_uuid} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid};
$anvil->data->{new}{bridge}{$interface}{id} = $anvil->data->{network}{$local_host}{interface}{$interface}{bridge_id};
$anvil->data->{new}{bridge}{$interface}{mac_address} = $anvil->data->{network}{$local_host}{interface}{$interface}{mac_address};
$anvil->data->{new}{bridge}{$interface}{mtu} = $anvil->data->{network}{$local_host}{interface}{$interface}{mtu};
@ -1295,6 +1446,7 @@ sub collect_data_ifcfg
$anvil->data->{new}{bridge}{$interface}{tx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{tx_bytes};
$anvil->data->{new}{bridge}{$interface}{rx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{rx_bytes};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::bridge::${interface}::nm_uuid" => $anvil->data->{new}{bridge}{$interface}{nm_uuid},
"new::bridge::${interface}::id" => $anvil->data->{new}{bridge}{$interface}{id},
"new::bridge::${interface}::mac_address" => $anvil->data->{new}{bridge}{$interface}{mac_address},
"new::bridge::${interface}::mtu" => $anvil->data->{new}{bridge}{$interface}{mtu},
@ -1306,6 +1458,7 @@ sub collect_data_ifcfg
elsif ($type eq "bond")
{
# Store the bond
$anvil->data->{new}{bond}{$interface}{nm_uuid} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid};
$anvil->data->{new}{bond}{$interface}{mode} = $anvil->data->{network}{$local_host}{interface}{$interface}{bond_mode};
$anvil->data->{new}{bond}{$interface}{mtu} = $anvil->data->{network}{$local_host}{interface}{$interface}{mtu};
$anvil->data->{new}{bond}{$interface}{master} = $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master};
@ -1322,6 +1475,7 @@ sub collect_data_ifcfg
$anvil->data->{new}{bond}{$interface}{tx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{tx_bytes};
$anvil->data->{new}{bond}{$interface}{rx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{rx_bytes};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::bond::${interface}::nm_uuid" => $anvil->data->{new}{bond}{$interface}{nm_uuid},
"new::bond::${interface}::mode" => $anvil->data->{new}{bond}{$interface}{mode},
"new::bond::${interface}::mtu" => $anvil->data->{new}{bond}{$interface}{mtu},
"new::bond::${interface}::master" => $anvil->data->{new}{bond}{$interface}{master},
@ -1342,6 +1496,8 @@ sub collect_data_ifcfg
elsif ($type eq "interface")
{
# Store the interface
$anvil->data->{new}{interface}{$interface}{nm_uuid} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_uuid};
$anvil->data->{new}{interface}{$interface}{nm_device} = $anvil->data->{network}{$local_host}{interface}{$interface}{nm_device};
$anvil->data->{new}{interface}{$interface}{bond_uuid} = "";
$anvil->data->{new}{interface}{$interface}{bond_name} = $anvil->data->{network}{$local_host}{interface}{$interface}{bond_master};
$anvil->data->{new}{interface}{$interface}{bridge_uuid} = "";
@ -1356,6 +1512,8 @@ sub collect_data_ifcfg
$anvil->data->{new}{interface}{$interface}{tx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{tx_bytes};
$anvil->data->{new}{interface}{$interface}{rx_bytes} = $anvil->data->{network}{$local_host}{interface}{$interface}{rx_bytes};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"new::interface::${interface}::nm_uuid" => $anvil->data->{new}{interface}{$interface}{nm_uuid},
"new::interface::${interface}::nm_device" => $anvil->data->{new}{interface}{$interface}{nm_device},
"new::interface::${interface}::bond_uuid" => $anvil->data->{new}{interface}{$interface}{bond_uuid},
"new::interface::${interface}::bond_name" => $anvil->data->{new}{interface}{$interface}{bond_name},
"new::interface::${interface}::bridge_uuid" => $anvil->data->{new}{interface}{$interface}{bridge_uuid},
@ -2719,8 +2877,12 @@ sub check_interfaces
{
my ($anvil) = @_;
my $interfaces = keys %{$anvil->data->{new}{interface}};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { interfaces => $interfaces }});
foreach my $network_interface_name (sort {$a cmp $b} keys %{$anvil->data->{new}{interface}})
{
my $new_nm_uuid = $anvil->data->{new}{interface}{$network_interface_name}{nm_uuid};
my $new_nm_device = $anvil->data->{new}{interface}{$network_interface_name}{nm_device};
my $new_bond_uuid = $anvil->data->{new}{interface}{$network_interface_name}{bond_uuid};
my $new_bond_name = $anvil->data->{new}{interface}{$network_interface_name}{bond_name};
my $new_bridge_uuid = $anvil->data->{new}{interface}{$network_interface_name}{bridge_uuid};
@ -2736,6 +2898,8 @@ sub check_interfaces
my $new_rx_bytes = $anvil->data->{new}{interface}{$network_interface_name}{rx_bytes};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
network_interface_name => $network_interface_name,
new_nm_uuid => $new_nm_uuid,
new_nm_device => $new_nm_device,
new_bond_uuid => $new_bond_uuid,
new_bond_name => $new_bond_name,
new_bridge_uuid => $new_bridge_uuid,
@ -2751,8 +2915,6 @@ sub check_interfaces
new_rx_bytes => $new_rx_bytes,
}});
my $new_nmcli_uuid = "";
# Find the bridge, if any, and the bond UUID, if there's a bond name.
if ($new_bond_name)
{
@ -3155,11 +3317,11 @@ sub check_interfaces
{
my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({
debug => 2,
network_interface_nmcli_uuid => $new_nmcli_uuid,
network_interface_nm_uuid => $new_nm_uuid,
network_interface_bond_uuid => $new_bond_uuid,
network_interface_bridge_uuid => $new_bridge_uuid,
network_interface_name => $network_interface_name,
network_interface_device => $network_interface_device,
network_interface_device => $new_nm_device,
network_interface_duplex => $new_duplex,
network_interface_link_state => $new_link_state,
network_interface_operational => $new_operational,
@ -3290,11 +3452,11 @@ sub check_interfaces
# Record the interface
my $network_interface_uuid = $anvil->Database->insert_or_update_network_interfaces({
debug => 2,
network_interface_nmcli_uuid => $new_nmcli_uuid,
network_interface_nm_uuid => $new_nm_uuid,
network_interface_bond_uuid => $new_bond_uuid,
network_interface_bridge_uuid => $new_bridge_uuid,
network_interface_name => $network_interface_name,
network_interface_device => $network_interface_device,
network_interface_device => $new_nm_device,
network_interface_duplex => $new_duplex,
network_interface_link_state => $new_link_state,
network_interface_operational => $new_operational,
@ -3423,6 +3585,7 @@ sub check_bonds
foreach my $bond_name (sort {$a cmp $b} keys %{$anvil->data->{new}{bond}})
{
# Store the bond
my $new_nm_uuid = $anvil->data->{new}{bond}{$bond_name}{nm_uuid};
my $new_mode = $anvil->data->{new}{bond}{$bond_name}{mode};
my $new_mtu = $anvil->data->{new}{bond}{$bond_name}{mtu};
my $new_operational = $anvil->data->{new}{bond}{$bond_name}{operational};
@ -3793,6 +3956,7 @@ sub check_bonds
{
my $bond_uuid = $anvil->Database->insert_or_update_bonds({
debug => 2,
bond_nm_uuid => $new_nm_uuid,
bond_name => $bond_name,
bond_mode => $new_mode,
bond_mtu => $new_mtu,

@ -855,6 +855,7 @@ CREATE TRIGGER trigger_jobs
CREATE TABLE bridges (
bridge_uuid uuid not null primary key,
bridge_host_uuid uuid not null,
bridge_nm_uuid uuid not null, -- This is the network manager UUID for this bridge interface
bridge_name text not null,
bridge_id text not null,
bridge_mac_address text not null,
@ -870,6 +871,7 @@ CREATE TABLE history.bridges (
history_id bigserial,
bridge_uuid uuid,
bridge_host_uuid uuid,
bridge_nm_uuid uuid,
bridge_name text,
bridge_id text,
bridge_mac_address text,
@ -888,6 +890,7 @@ BEGIN
INSERT INTO history.bridges
(bridge_uuid,
bridge_host_uuid,
bridge_nm_uuid,
bridge_name,
bridge_id,
bridge_mac_address,
@ -897,6 +900,7 @@ BEGIN
VALUES
(history_bridges.bridge_uuid,
history_bridges.bridge_host_uuid,
history_bridges.bridge_nm_uuid,
history_bridges.bridge_name,
history_bridges.bridge_id,
history_bridges.bridge_mac_address,
@ -918,6 +922,7 @@ CREATE TRIGGER trigger_bridges
CREATE TABLE bonds (
bond_uuid uuid not null primary key,
bond_host_uuid uuid not null,
bond_nm_uuid uuid not null, -- The is the network manager UUID for this bond.
bond_name text not null,
bond_mode text not null, -- This is the numerical bond type (will translate to the user's language in the Anvil!)
bond_mtu bigint not null,
@ -941,6 +946,7 @@ CREATE TABLE history.bonds (
history_id bigserial,
bond_uuid uuid,
bond_host_uuid uuid,
bond_nm_uuid uuid,
bond_name text,
bond_mode text,
bond_mtu bigint,
@ -964,8 +970,9 @@ DECLARE
BEGIN
SELECT INTO history_bonds * FROM bonds WHERE bond_uuid = new.bond_uuid;
INSERT INTO history.bonds
(bond_uuid,
bond_host_uuid,
(bond_uuid,
bond_host_uuid,
bond_nm_uuid,
bond_name,
bond_mode,
bond_mtu,
@ -980,8 +987,9 @@ BEGIN
bond_bridge_uuid,
modified_date)
VALUES
(history_bonds.bond_uuid,
history_bonds.bond_host_uuid,
(history_bonds.bond_uuid,
history_bonds.bond_host_uuid,
history_bonds.bond_nm_uuid,
history_bonds.bond_name,
history_bonds.bond_mode,
history_bonds.bond_mtu,
@ -1011,10 +1019,10 @@ CREATE TRIGGER trigger_bonds
CREATE TABLE network_interfaces (
network_interface_uuid uuid not null primary key,
network_interface_host_uuid uuid not null,
network_interface_nmcli_uuid uuid, -- This is the nmcli UUID used to track the device. It can change, so we can't used this as the main UUID
network_interface_nm_uuid uuid, -- This is the network manager UUID used to track the device. It can change, so we can't used this as the main UUID
network_interface_mac_address text not null, -- This is the interface MAC address, and it can change if a failed controller it replaced.
network_interface_name text not null, -- This is the current name (network manager's connection.id) of the interface.
network_interface_device text not null, -- This is the current device name (network manager's ) of the interface.
network_interface_device text not null, -- This is the current device name (network manager's GENERAL.IP-IFACE) of the interface.
network_interface_speed bigint not null, -- This is the speed, in bits-per-second, of the interface.
network_interface_mtu bigint not null, -- This is the MTU (Maximum Transmitable Size), in bytes, for this interface.
network_interface_link_state text not null, -- 0 or 1
@ -1035,7 +1043,7 @@ CREATE TABLE history.network_interfaces (
history_id bigserial,
network_interface_uuid uuid not null,
network_interface_host_uuid uuid,
network_interface_nmcli_uuid uuid,
network_interface_nm_uuid uuid,
network_interface_mac_address text,
network_interface_name text,
network_interface_device text,
@ -1060,7 +1068,7 @@ BEGIN
INSERT INTO history.network_interfaces
(network_interface_uuid,
network_interface_host_uuid,
network_interface_nmcli_uuid,
network_interface_nm_uuid,
network_interface_mac_address,
network_interface_name,
network_interface_device,
@ -1076,7 +1084,7 @@ BEGIN
VALUES
(history_network_interfaces.network_interface_uuid,
history_network_interfaces.network_interface_host_uuid,
history_network_interfaces.network_interface_nmcli_uuid,
history_network_interfaces.network_interface_nm_uuid,
history_network_interfaces.network_interface_mac_address,
history_network_interfaces.network_interface_name,
history_network_interfaces.network_interface_device,

@ -63,8 +63,10 @@ sub striker_checks
{
my ($anvil) = @_;
# This checks to make sure that the new 'file_locations' -> 'file_location_ready' column exists.
# This checks to make sure that the new network manager columns are in place
update_network_interfaces($anvil);
update_bonds($anvil);
update_bridges($anvil);
# This checks to make sure that the new 'file_locations' -> 'file_location_ready' column exists.
update_file_location_ready($anvil);
@ -246,6 +248,150 @@ CREATE TRIGGER trigger_dr_links
return(0);
}
sub update_bridges
{
my ($anvil) = @_;
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{
my $query = "SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'bridges' AND column_name = 'bridge_nm_uuid';";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $count = $anvil->Database->query({query => $query, uuid => $uuid, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
if (not $count)
{
my $queries = [];
push @{$queries}, "ALTER TABLE public.bridges ADD COLUMN bridge_nm_uuid uuid;";
push @{$queries}, "ALTER TABLE history.bridges ADD COLUMN bridge_nm_uuid uuid;";
push @{$queries}, "DROP FUNCTION history_bridges() CASCADE;";
push @{$queries}, q|CREATE FUNCTION history_bridges() RETURNS trigger
AS $$
DECLARE
history_bridges RECORD;
BEGIN
SELECT INTO history_bridges * FROM bridges WHERE bridge_uuid = new.bridge_uuid;
INSERT INTO history.bridges
(bridge_uuid,
bridge_host_uuid,
bridge_nm_uuid,
bridge_name,
bridge_id,
bridge_mac_address,
bridge_mtu,
bridge_stp_enabled,
modified_date)
VALUES
(history_bridges.bridge_uuid,
history_bridges.bridge_host_uuid,
history_bridges.bridge_nm_uuid,
history_bridges.bridge_name,
history_bridges.bridge_id,
history_bridges.bridge_mac_address,
history_bridges.bridge_mtu,
history_bridges.bridge_stp_enabled,
history_bridges.modified_date);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
ALTER FUNCTION history_bridges() OWNER TO admin;
CREATE TRIGGER trigger_bridges
AFTER INSERT OR UPDATE ON bridges
FOR EACH ROW EXECUTE PROCEDURE history_bridges();
|;
foreach my $query (@{$queries})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
}
$anvil->Database->write({debug => 2, uuid => $uuid, query => $queries, source => $THIS_FILE, line => __LINE__});
}
}
return(0);
}
sub update_bonds
{
my ($anvil) = @_;
foreach my $uuid (sort {$a cmp $b} keys %{$anvil->data->{cache}{database_handle}})
{
my $query = "SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'bonds' AND column_name = 'bond_nm_uuid';";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
my $count = $anvil->Database->query({query => $query, uuid => $uuid, source => $THIS_FILE, line => __LINE__})->[0]->[0];
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { count => $count }});
if (not $count)
{
my $queries = [];
push @{$queries}, "ALTER TABLE public.bonds ADD COLUMN bond_nm_uuid uuid;";
push @{$queries}, "ALTER TABLE history.bonds ADD COLUMN bond_nm_uuid uuid;";
push @{$queries}, "DROP FUNCTION history_bonds() CASCADE;";
push @{$queries}, q|CREATE FUNCTION history_bonds() RETURNS trigger
AS $$
DECLARE
history_bonds RECORD;
BEGIN
SELECT INTO history_bonds * FROM bonds WHERE bond_uuid = new.bond_uuid;
INSERT INTO history.bonds
(bond_uuid,
bond_host_uuid,
bond_nm_uuid,
bond_name,
bond_mode,
bond_mtu,
bond_primary_interface,
bond_primary_reselect,
bond_active_interface,
bond_mii_polling_interval,
bond_up_delay,
bond_down_delay,
bond_mac_address,
bond_operational,
bond_bridge_uuid,
modified_date)
VALUES
(history_bonds.bond_uuid,
history_bonds.bond_host_uuid,
history_bonds.bond_nm_uuid,
history_bonds.bond_name,
history_bonds.bond_mode,
history_bonds.bond_mtu,
history_bonds.bond_primary_interface,
history_bonds.bond_primary_reselect,
history_bonds.bond_active_interface,
history_bonds.bond_mii_polling_interval,
history_bonds.bond_up_delay,
history_bonds.bond_down_delay,
history_bonds.bond_mac_address,
history_bonds.bond_operational,
history_bonds.bond_bridge_uuid,
history_bonds.modified_date);
RETURN NULL;
END;
$$
LANGUAGE plpgsql;
ALTER FUNCTION history_bonds() OWNER TO admin;
CREATE TRIGGER trigger_bonds
AFTER INSERT OR UPDATE ON bonds
FOR EACH ROW EXECUTE PROCEDURE history_bonds();
|;
foreach my $query (@{$queries})
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0124", variables => { query => $query }});
}
$anvil->Database->write({debug => 2, uuid => $uuid, query => $queries, source => $THIS_FILE, line => __LINE__});
}
}
return(0);
}
sub update_network_interfaces
{
my ($anvil) = @_;
@ -273,7 +419,7 @@ BEGIN
INSERT INTO history.network_interfaces
(network_interface_uuid,
network_interface_host_uuid,
network_interface_nmcli_uuid,
network_interface_nm_uuid,
network_interface_mac_address,
network_interface_name,
network_interface_device,
@ -289,7 +435,7 @@ BEGIN
VALUES
(history_network_interfaces.network_interface_uuid,
history_network_interfaces.network_interface_host_uuid,
history_network_interfaces.network_interface_nmcli_uuid,
history_network_interfaces.network_interface_nm_uuid,
history_network_interfaces.network_interface_mac_address,
history_network_interfaces.network_interface_name,
history_network_interfaces.network_interface_device,
@ -319,7 +465,7 @@ CREATE TRIGGER trigger_network_interfaces
$anvil->Database->write({debug => 2, uuid => $uuid, query => $queries, source => $THIS_FILE, line => __LINE__});
}
$query = "SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'network_interfaces' AND column_name = 'network_interface_nmcli_uuid';";
$query = "SELECT COUNT(*) FROM information_schema.columns WHERE table_schema = 'public' AND table_name = 'network_interfaces' AND column_name = 'network_interface_nm_uuid';";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }});
$count = $anvil->Database->query({query => $query, uuid => $uuid, source => $THIS_FILE, line => __LINE__})->[0]->[0];
@ -328,8 +474,8 @@ CREATE TRIGGER trigger_network_interfaces
if (not $count)
{
my $queries = [];
push @{$queries}, "ALTER TABLE public.network_interfaces ADD COLUMN network_interface_nmcli_uuid uuid;";
push @{$queries}, "ALTER TABLE history.network_interfaces ADD COLUMN network_interface_nmcli_uuid uuid;";
push @{$queries}, "ALTER TABLE public.network_interfaces ADD COLUMN network_interface_nm_uuid uuid;";
push @{$queries}, "ALTER TABLE history.network_interfaces ADD COLUMN network_interface_nm_uuid uuid;";
push @{$queries}, "DROP FUNCTION history_network_interfaces() CASCADE;";
push @{$queries}, q|CREATE FUNCTION history_network_interfaces() RETURNS trigger
AS $$
@ -340,7 +486,7 @@ BEGIN
INSERT INTO history.network_interfaces
(network_interface_uuid,
network_interface_host_uuid,
network_interface_nmcli_uuid,
network_interface_nm_uuid,
network_interface_mac_address,
network_interface_name,
network_interface_device,
@ -356,7 +502,7 @@ BEGIN
VALUES
(history_network_interfaces.network_interface_uuid,
history_network_interfaces.network_interface_host_uuid,
history_network_interfaces.network_interface_nmcli_uuid,
history_network_interfaces.network_interface_nm_uuid,
history_network_interfaces.network_interface_mac_address,
history_network_interfaces.network_interface_name,
history_network_interfaces.network_interface_device,

Loading…
Cancel
Save