* Fixed a couple remaining issues from the recent merger. Specifically, '$$anvil' was fixed from a bad regex and the path/names of our tools were fixed.

Signed-off-by: Digimer <digimer@alteeve.ca>
main
Digimer 7 years ago
parent db8632ca1b
commit 2b9c6c26dc
  1. 3
      Anvil/Tools.pm
  2. 9
      Anvil/Tools/System.pm
  3. 2
      anvil.conf
  4. 32
      tools/anvil-daemon
  5. 62
      tools/anvil-update-states

@ -719,7 +719,8 @@ sub _set_paths
units => "/usr/lib/systemd/system",
},
exe => {
'anvil-update-states' => "/sbin/anvil/anvil-update-states",
'anvil-prep-database' => "/usr/sbin/anvil/anvil-prep-database",
'anvil-update-states' => "/usr/sbin/anvil/anvil-update-states",
'anvil-report-memory' => "/usr/sbin/anvil-report-memory",
'chmod' => "/usr/bin/chmod",
'chown' => "/usr/bin/chown",

@ -120,11 +120,12 @@ sub call
my $parameter = shift;
my $anvil = $self->parent;
my $debug = 2;
my $line = defined $parameter->{line} ? $parameter->{line} : __LINE__;
my $shell_call = defined $parameter->{shell_call} ? $parameter->{shell_call} : "";
my $secure = defined $parameter->{secure} ? $parameter->{secure} : 0;
my $source = defined $parameter->{source} ? $parameter->{source} : $THIS_FILE;
$anvil->Log->variables({source => $source, line => $line, level => 3, secure => $secure, list => { shell_call => $shell_call }});
$anvil->Log->variables({source => $source, line => $line, level => $debug, secure => $secure, list => { shell_call => $shell_call }});
my $output = "#!error!#";
if (not $shell_call)
@ -136,7 +137,7 @@ sub call
{
# Make the system call
$output = "";
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => $secure, key => "log_0011", variables => { shell_call => $shell_call }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, key => "log_0011", variables => { shell_call => $shell_call }});
open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => $secure, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }});
while(<$file_handle>)
{
@ -144,7 +145,7 @@ sub call
my $line = $_;
$line =~ s/\n$//;
$line =~ s/\r$//;
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure => $secure, key => "log_0017", variables => { line => $line }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, key => "log_0017", variables => { line => $line }});
$output .= $line."\n";
}
close $file_handle;
@ -152,7 +153,7 @@ sub call
$output =~ s/\n$//s;
}
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, secure => $secure, list => { output => $output }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, secure => $secure, list => { output => $output }});
return($output);
}

@ -16,7 +16,7 @@ database::2::password = Initial1
database::2::ping_before_connect = 1
# This is the schema for the ScanCore database.
sys::database::schema = /etc/scancore/scancore.sql
sys::database::schema = /usr/sbin/anvil/anvil.sql
# 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

@ -20,15 +20,7 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$| = 1;
my $anvil = Anvil::Tools->new();
$$anvil->Log->level({set => 2});
# Paths
$$anvil->data->{path}{tools}{'an-prep-database'} = "/usr/sbin/striker/an-prep-database";
$$anvil->data->{path}{tools}{'scancore-update-states'} = "/usr/sbin/striker/scancore-update-states";
$$anvil->data->{path}{config}{'striker.conf'} = "/etc/striker/striker.conf";
# Read our config.
$$anvil->Storage->read_config({file => $$anvil->data->{path}{config}{'striker.conf'}});
$anvil->Log->level({set => 2});
# There are some things we only want to run on (re)start and don't need to always run.
run_once($anvil);
@ -41,14 +33,14 @@ while(1)
# Exit if called with '--run-once'
if ($$anvil->data->{switches}{'run-once'})
if ($anvil->data->{switches}{'run-once'})
{
$$anvil->nice_exit({code => 0});
$anvil->nice_exit({code => 0});
}
sleep 2;
}
$$anvil->nice_exit({code => 0});
$anvil->nice_exit({code => 0});
#############################################################################################################
# Functions #
@ -60,12 +52,12 @@ sub run_once
my ($anvil) = @_;
# Check that the database is ready.
my $shell_call = $$anvil->data->{path}{tools}{'an-prep-database'};
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my $database_output = $$anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
my $shell_call = $anvil->data->{path}{exe}{'anvil-prep-database'};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my $database_output = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
if ($database_output)
{
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_output => $database_output }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { database_output => $database_output }});
}
return(0);
@ -88,13 +80,13 @@ sub update_state_file
{
my ($anvil) = @_;
my $shell_call = $$anvil->data->{path}{tools}{'scancore-update-states'};
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my $shell_call = $anvil->data->{path}{exe}{'anvil-update-states'};
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
my $states_output = $$anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
my $states_output = $anvil->System->call({shell_call => $shell_call, source => $THIS_FILE, line => __LINE__});
if ($states_output)
{
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { states_output => $states_output }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { states_output => $states_output }});
}
return(0);

@ -14,12 +14,12 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
$running_directory =~ s/^\./$ENV{PWD}/;
}
my $$anvil = Anvil::Tools->new();
$$anvil->Log->level({set => 2});
my $anvil = Anvil::Tools->new();
$anvil->Log->level({set => 2});
$$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
my $connections = $$anvil->Database->connect({
sql_file => $$anvil->data->{sys}{database}{schema},
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
my $connections = $anvil->Database->connect({
sql_file => $anvil->data->{sys}{database}{schema},
test_table => "network_interfaces",
});
@ -40,9 +40,9 @@ sub report_network
my ($anvil) = @_;
# Write out the data in json format.
my $directory = $$anvil->data->{path}{sysfs}{network_interfaces};
my $directory = $anvil->data->{path}{sysfs}{network_interfaces};
local(*DIRECTORY);
$$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0018", variables => { directory => $directory }});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0018", variables => { directory => $directory }});
opendir(DIRECTORY, $directory);
while(my $file = readdir(DIRECTORY))
{
@ -50,17 +50,17 @@ sub report_network
next if $file eq "..";
next if $file eq "lo";
my $full_path = "$directory/$file";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { full_path => $full_path }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { full_path => $full_path }});
if (-d $full_path)
{
# Pull out the data I want.
my $interface = $file;
my $mac_address = $$anvil->Storage->read_file({file => $full_path."/address"});
my $link_state = $$anvil->Storage->read_file({file => $full_path."/carrier"});
my $mtu = $$anvil->Storage->read_file({file => $full_path."/mtu"});
my $duplex = $$anvil->Storage->read_file({file => $full_path."/duplex"}); # full or half?
my $operational = $$anvil->Storage->read_file({file => $full_path."/operstate"}); # up or down
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
my $mac_address = $anvil->Storage->read_file({file => $full_path."/address"});
my $link_state = $anvil->Storage->read_file({file => $full_path."/carrier"});
my $mtu = $anvil->Storage->read_file({file => $full_path."/mtu"});
my $duplex = $anvil->Storage->read_file({file => $full_path."/duplex"}); # full or half?
my $operational = $anvil->Storage->read_file({file => $full_path."/operstate"}); # up or down
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
if ($speed > 100000)
{
# NOTE: This is probably 0 now... Though someday >100 Gbps will be reasonable
@ -70,7 +70,7 @@ sub report_network
# Find the media, if possible.
my $media = "unknown";
my $ethtool = $$anvil->System->call({shell_call => $$anvil->data->{path}{exe}{ethtool}});
my $ethtool = $anvil->System->call({shell_call => $anvil->data->{path}{exe}{ethtool}});
foreach my $line (split/\n/, $ethtool)
{
if ($line =~ /Supported ports: \[ (.*?) \]/i)
@ -81,7 +81,7 @@ sub report_network
}
# Log
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
interface => $interface,
mac_address => $mac_address,
link_state => $link_state,
@ -92,7 +92,7 @@ sub report_network
media => $media,
}});
$$anvil->Database->insert_or_update_network_interfaces({
$anvil->Database->insert_or_update_network_interfaces({
network_interface_name => $interface,
network_interface_duplex => $duplex,
network_interface_link_state => $link_state,
@ -110,7 +110,7 @@ sub report_network
### TODO: Create $anvil "ip" table and record IPs on this system, linking back to $anvil interface, bond or
### bridge.
# Run 'ip addr' to see what IPs are in use.
$$anvil->System->get_ips;
$anvil->System->get_ips;
# Write out the XML file and JSON file.
my $order = 1;
@ -132,14 +132,14 @@ SELECT
FROM
network_interfaces
WHERE
network_interface_host_uuid = ".$$anvil->data->{sys}{use_db_fh}->quote($$anvil->Get->host_uuid)."
network_interface_host_uuid = ".$anvil->data->{sys}{use_db_fh}->quote($anvil->Get->host_uuid)."
ORDER BY
modified_date DESC
;";
$$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
my $results = $$anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0124", variables => { query => $query }});
my $results = $anvil->Database->query({query => $query, source => $THIS_FILE, line => __LINE__});
my $count = @{$results};
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
results => $results,
count => $count,
}});
@ -155,7 +155,7 @@ ORDER BY
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] : "";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
$anvil->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,
@ -175,16 +175,16 @@ ORDER BY
$network_json =~ s/,$//s;
$network_json .= "]}\n";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_json => $network_json }});
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_json => $network_json }});
$network_xml .= "</network>\n";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { network_xml => $network_xml }});
$anvil->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 = $$anvil->data->{path}{directories}{html}."/status/network.json";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_json }});
$$anvil->Storage->write_file({
my $output_json = $anvil->data->{path}{directories}{html}."/status/network.json";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_json }});
$anvil->Storage->write_file({
file => $output_json,
body => $network_json,
overwrite => 1,
@ -194,9 +194,9 @@ ORDER BY
});
# Write the XML file.
my $output_xml = $$anvil->data->{path}{directories}{html}."/status/network.xml";
$$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_xml }});
$$anvil->Storage->write_file({
my $output_xml = $anvil->data->{path}{directories}{html}."/status/network.xml";
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output_xml => $output_xml }});
$anvil->Storage->write_file({
file => $output_xml,
body => $network_xml,
overwrite => 1,

Loading…
Cancel
Save