* Fixed some string and path issues from the 'anvil' merger.
* Added a 'debug' parameter to System->ping() to allow per-call log levels. Signed-off-by: Digimer <digimer@alteeve.ca>
This commit is contained in:
parent
665f2217d9
commit
d03213b860
@ -707,7 +707,7 @@ sub _set_paths
|
||||
},
|
||||
data => {
|
||||
group => "/etc/group",
|
||||
host_uuid => "/etc/an/host.uuid",
|
||||
host_uuid => "/etc/anvil/host.uuid",
|
||||
passwd => "/etc/passwd",
|
||||
},
|
||||
directories => {
|
||||
|
@ -3843,7 +3843,7 @@ sub _archive_table
|
||||
column_count => $column_count
|
||||
}});
|
||||
|
||||
print Dumper $columns;
|
||||
#print Dumper $columns;
|
||||
|
||||
# See m2's DB->archive_if_needed() for old version of this.
|
||||
|
||||
|
@ -351,6 +351,7 @@ sub host_uuid
|
||||
|
||||
my $set = defined $parameter->{set} ? $parameter->{set} : "";
|
||||
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { set => $set }});
|
||||
if ($set)
|
||||
{
|
||||
$anvil->data->{HOST}{UUID} = $set;
|
||||
@ -359,10 +360,11 @@ sub host_uuid
|
||||
{
|
||||
# Read dmidecode if I am root, and the cache if not.
|
||||
my $uuid = "";
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { '$<' => $<, '$>' => $> }});
|
||||
if (($< == 0) or ($> == 0))
|
||||
{
|
||||
my $shell_call = $anvil->data->{path}{exe}{dmidecode}." --string system-uuid";
|
||||
#print $THIS_FILE." ".__LINE__."; [ Debug ] - shell_call: [$shell_call]\n";
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
|
||||
open(my $file_handle, $shell_call." 2>&1 |") or warn $THIS_FILE." ".__LINE__."; [ Warning ] - Failed to call: [".$shell_call."], the error was: $!\n";
|
||||
while(<$file_handle>)
|
||||
{
|
||||
@ -377,6 +379,7 @@ sub host_uuid
|
||||
{
|
||||
# Not running as root, so I have to rely on the cache file, or die if it doesn't
|
||||
# exist.
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { 'path::data::host_uuid' => $anvil->data->{path}{data}{host_uuid} }});
|
||||
if (not -e $anvil->data->{path}{data}{host_uuid})
|
||||
{
|
||||
# We're done.
|
||||
@ -385,6 +388,7 @@ sub host_uuid
|
||||
else
|
||||
{
|
||||
$uuid = $anvil->Storage->read_file({ file => $anvil->data->{path}{data}{host_uuid} });
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uuid => $uuid }});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -783,6 +783,10 @@ Parameters;
|
||||
|
||||
This tells the method how many time to try to ping the target. The method will return as soon as any ping attemp succeeds (unlike pinging from the command line, which always pings the requested count times).
|
||||
|
||||
=head3 debug (optional, default '3')
|
||||
|
||||
This is an optional way to alter to level at which this method is logged. Useful when the caller is trying to debug a problem. Generally this can be ignored.
|
||||
|
||||
=head3 fragment (optional, default '1')
|
||||
|
||||
When set to C<< 0 >>, the ping will fail if the packet has to be fragmented. This is meant to be used along side C<< payload >> for testing MTU sizes.
|
||||
@ -816,13 +820,14 @@ sub ping
|
||||
|
||||
# If we were passed a target, try pinging from it instead of locally
|
||||
my $count = $parameter->{count} ? $parameter->{count} : 1; # How many times to try to ping it? Will exit as soon as one succeeds
|
||||
my $debug = $parameter->{debug} ? $parameter->{deug} : 3;
|
||||
my $fragment = $parameter->{fragment} ? $parameter->{fragment} : 1; # Allow fragmented packets? Set to '0' to check MTU.
|
||||
my $password = $parameter->{password} ? $parameter->{password} : "";
|
||||
my $payload = $parameter->{payload} ? $parameter->{payload} : 0; # The size of the ping payload. Use when checking MTU.
|
||||
my $ping = $parameter->{ping} ? $parameter->{ping} : "";
|
||||
my $port = $parameter->{port} ? $parameter->{port} : "";
|
||||
my $target = $parameter->{target} ? $parameter->{target} : "";
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||||
count => $count,
|
||||
fragment => $fragment,
|
||||
payload => $payload,
|
||||
@ -836,22 +841,22 @@ sub ping
|
||||
if ($payload)
|
||||
{
|
||||
$payload -= 28;
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { payload => $payload }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { payload => $payload }});
|
||||
}
|
||||
|
||||
# Build the call. Note that we use 'timeout' because if there is no connection and the hostname is
|
||||
# used to ping and DNS is not available, it could take upwards of 30 seconds time timeout otherwise.
|
||||
my $shell_call = $anvil->data->{path}{exe}{timeout}." 2 ".$anvil->data->{path}{exe}{'ping'}." -W 1 -n $ping -c 1";
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { shell_call => $shell_call }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
|
||||
if (not $fragment)
|
||||
{
|
||||
$shell_call .= " -M do";
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { shell_call => $shell_call }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
|
||||
}
|
||||
if ($payload)
|
||||
{
|
||||
$shell_call .= " -s $payload";
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { shell_call => $shell_call }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }});
|
||||
}
|
||||
$shell_call .= " || ".$anvil->data->{path}{exe}{echo}." timeout";
|
||||
|
||||
@ -859,7 +864,7 @@ sub ping
|
||||
my $average_ping_time = 0;
|
||||
foreach my $try (1..$count)
|
||||
{
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { count => $count, try => $try }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { count => $count, try => $try }});
|
||||
last if $pinged;
|
||||
|
||||
my $output = "";
|
||||
@ -874,24 +879,24 @@ sub ping
|
||||
port => $port,
|
||||
password => $password,
|
||||
});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output => $output }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output }});
|
||||
}
|
||||
else
|
||||
{
|
||||
### Local calls
|
||||
$output = $anvil->System->call({shell_call => $shell_call});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { output => $output }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output }});
|
||||
}
|
||||
|
||||
foreach my $line (split/\n/, $output)
|
||||
{
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { line => $line }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }});
|
||||
if ($line =~ /(\d+) packets transmitted, (\d+) received/)
|
||||
{
|
||||
# This isn't really needed, but might help folks watching the logs.
|
||||
my $pings_sent = $1;
|
||||
my $pings_received = $2;
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||||
pings_sent => $pings_sent,
|
||||
pings_received => $pings_received,
|
||||
}});
|
||||
@ -900,7 +905,7 @@ sub ping
|
||||
{
|
||||
# Contact!
|
||||
$pinged = 1;
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { pinged => $pinged }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { pinged => $pinged }});
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -912,14 +917,14 @@ sub ping
|
||||
if ($line =~ /min\/avg\/max\/mdev = .*?\/(.*?)\//)
|
||||
{
|
||||
$average_ping_time = $1;
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { average_ping_time => $average_ping_time }});
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { average_ping_time => $average_ping_time }});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# 0 == Ping failed
|
||||
# 1 == Ping success
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => {
|
||||
pinged => $pinged,
|
||||
average_ping_time => $average_ping_time,
|
||||
}});
|
||||
|
@ -308,6 +308,7 @@ sub read
|
||||
$error .= "===========================================================\n";
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", raw => $error});
|
||||
$return_code = 4;
|
||||
die;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -397,11 +398,11 @@ sub string
|
||||
# Setup default values
|
||||
my $key = defined $parameter->{key} ? $parameter->{key} : "";
|
||||
my $language = defined $parameter->{language} ? $parameter->{language} : $anvil->Words->language;
|
||||
my $file = defined $parameter->{file} ? $parameter->{file} : "";
|
||||
my $file = defined $parameter->{file} ? $parameter->{file} : $anvil->data->{path}{words}{'words.xml'};
|
||||
my $string = defined $parameter->{string} ? $parameter->{string} : "";
|
||||
my $variables = defined $parameter->{variables} ? $parameter->{variables} : "";
|
||||
|
||||
# If we weren't passed a raw string, we'll get the string from our ->key() method, the inject any
|
||||
# If we weren't passed a raw string, we'll get the string from our ->key() method, then inject any
|
||||
# variables, if needed. This also handles the initial sanity checks. If we get back '#!not_found!#',
|
||||
# we'll exit.
|
||||
if (not $string)
|
||||
|
@ -54,13 +54,13 @@ if ($local_id)
|
||||
if (not -e $anvil->data->{path}{configs}{'pg_hba.conf'})
|
||||
{
|
||||
# Failed...
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0001"});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0050"});
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
# Initialized!
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0001"});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0055"});
|
||||
}
|
||||
|
||||
# Setup postgresql.conf
|
||||
@ -98,7 +98,7 @@ if ($local_id)
|
||||
mode => "0600",
|
||||
overwrite => 1,
|
||||
});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0002", variables => { file => $anvil->data->{path}{configs}{'postgresql.conf'} }});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0056", variables => { file => $anvil->data->{path}{configs}{'postgresql.conf'} }});
|
||||
}
|
||||
|
||||
# Setup pg_hba.conf now
|
||||
@ -140,7 +140,7 @@ if ($local_id)
|
||||
mode => "0600",
|
||||
overwrite => 1,
|
||||
});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0003", variables => { file => $anvil->data->{path}{configs}{'postgresql.conf'} }});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0057", variables => { file => $anvil->data->{path}{configs}{'postgresql.conf'} }});
|
||||
}
|
||||
}
|
||||
|
||||
@ -150,7 +150,7 @@ if ($local_id)
|
||||
if ($started)
|
||||
{
|
||||
# Started the daemon.
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "message_0004"});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "log_0059"});
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -204,7 +204,7 @@ if ($local_id)
|
||||
{
|
||||
# User exists already
|
||||
my $id = $1;
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "message_0005", variables => { user => $scancore_user, id => $id }});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0060", variables => { user => $scancore_user, id => $id }});
|
||||
$create_user = 0;
|
||||
last;
|
||||
}
|
||||
@ -223,14 +223,14 @@ if ($local_id)
|
||||
{
|
||||
# Success!
|
||||
my $id = $1;
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "message_0006", variables => { user => $scancore_user, id => $id }});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0095", variables => { user => $scancore_user, id => $id }});
|
||||
$user_exists = 1;
|
||||
last;
|
||||
}
|
||||
}
|
||||
if (not $user_exists)
|
||||
{
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "error_0004", variables => { user => $scancore_user }});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0096", variables => { user => $scancore_user }});
|
||||
exit(4);
|
||||
}
|
||||
|
||||
@ -246,7 +246,7 @@ if ($local_id)
|
||||
if ($line =~ /ALTER ROLE/)
|
||||
{
|
||||
# Password set
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "message_0007", variables => { user => $user }});
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0100", variables => { user => $user }});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ if (($running_directory =~ /^\./) && ($ENV{PWD}))
|
||||
}
|
||||
|
||||
my $anvil = Anvil::Tools->new();
|
||||
print $THIS_FILE." ".__LINE__."; anvil: [".$anvil."]\n";
|
||||
$anvil->Log->level({set => 2});
|
||||
|
||||
$anvil->Storage->read_config({file => "/etc/anvil/anvil.conf"});
|
||||
@ -25,6 +26,7 @@ my $connections = $anvil->Database->connect({
|
||||
sql_file => $anvil->data->{sys}{database}{schema},
|
||||
test_table => "network_interfaces",
|
||||
});
|
||||
print $THIS_FILE." ".__LINE__."; connections: [".$connections."]\n";
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0132", variables => { connections => $connections }});
|
||||
if (not $connections)
|
||||
{
|
||||
@ -48,6 +50,7 @@ sub report_network
|
||||
|
||||
# Write out the data in json format.
|
||||
my $directory = $anvil->data->{path}{sysfs}{network_interfaces};
|
||||
print $THIS_FILE." ".__LINE__."; directory: [".$directory."]\n";
|
||||
local(*DIRECTORY);
|
||||
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, key => "log_0018", variables => { directory => $directory }});
|
||||
opendir(DIRECTORY, $directory);
|
||||
@ -57,6 +60,7 @@ sub report_network
|
||||
next if $file eq "..";
|
||||
next if $file eq "lo";
|
||||
my $full_path = "$directory/$file";
|
||||
print $THIS_FILE." ".__LINE__."; full_path: [".$full_path."]\n";
|
||||
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { full_path => $full_path }});
|
||||
if (-d $full_path)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user