From 652f87ec74eed5f3be2289972953bd533b5d084a Mon Sep 17 00:00:00 2001 From: Digimer Date: Wed, 12 Jan 2022 23:27:44 -0500 Subject: [PATCH] * Updated scan-network to also clean up the media type. * Updated anvil-daemon to check for files in /mnt/shared/incoming on striker dashboards and add them to the media library if needed. Signed-off-by: Digimer --- notes | 21 ++++--- scancore-agents/scan-network/scan-network | 7 +++ tools/anvil-daemon | 74 +++++++++++++++++++++++ 3 files changed, 92 insertions(+), 10 deletions(-) diff --git a/notes b/notes index 81134638..f4e94ab5 100644 --- a/notes +++ b/notes @@ -744,6 +744,8 @@ mediawiki on EL8 install notes (starting from a minimal install); dnf module reset php dnf module enable php:7.4 + +# PgSQL dnf install httpd php php-gd php-xml php-mbstring php-json \ vim bash-completion wget tar rsync mlocate php-pecl-apcu \ memcached php-pear icu php-intl php-pgsql bzip2 @@ -792,16 +794,6 @@ MariaDB [(none)]> exit # Back to terminal systemctl enable mariadb -# Common -systemctl start httpd.service -systemctl enable httpd.service -systemctl start memcached.service -systemctl enable memcached.service -firewall-cmd --permanent --zone=public --add-service=http -firewall-cmd --permanent --zone=public --add-service=https -systemctl restart firewalld - - # diff -u /var/lib/pgsql/data/pg_hba.conf.orig /var/lib/pgsql/data/pg_hba.conf ==== --- /var/lib/pgsql/data/pg_hba.conf.orig 2021-02-17 02:50:10.959000000 -0500 @@ -836,6 +828,15 @@ systemctl restart firewalld ;;;; ; Note: packaged extension modules are now loaded via the .ini files + + +# Download and install +cd /var/www/ +wget https://releases.wikimedia.org/mediawiki/1.37/mediawiki-1.37.1.tar.gz +tar -xvzf mediawiki-1.37.1.tar.gz +cd /var/www/html +ln -s ../mediawiki-1.37.1 ./w + ==== Dell S4128T-ON Configuration diff --git a/scancore-agents/scan-network/scan-network b/scancore-agents/scan-network/scan-network index 71fc5b73..7267fd8e 100755 --- a/scancore-agents/scan-network/scan-network +++ b/scancore-agents/scan-network/scan-network @@ -565,6 +565,13 @@ sub collect_data { $media = lc($1); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { media => $media }}); + + # This can be 'tp mii', which breaks json. + if ($media =~ /\t/) + { + $media =~ s/\t/,/g; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { media => $media }}); + } last; } } diff --git a/tools/anvil-daemon b/tools/anvil-daemon index f4d4e6d3..72ac9d04 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -508,6 +508,9 @@ sub handle_periodic_tasks # Check mail server config. my $problem = $anvil->Email->check_config({debug => 3}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { problem => $problem }}); + + # Check if any files have been uploaded to /mnt/shared/incoming on striker + check_incoming($anvil); } # Now check to see if it's time to run less frequent tasks. @@ -695,6 +698,77 @@ sub handle_periodic_tasks return(0); } +# On dashboards, this checks to see if any files are in /mnt/shared/incoming and, if so, that they've been processed. +sub check_incoming +{ + my ($anvil) = @_; + + my $system_type = $anvil->Get->host_type(); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { system_type => $system_type }}); + if ($system_type eq "striker") + { + # Look for files in /mnt/shared/incoming that are not yet in the database. + my $directory = $anvil->data->{path}{directories}{shared}{incoming}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { directory => $directory }}); + + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { directory => $directory }}); + local(*DIRECTORY); + opendir(DIRECTORY, $directory); + while(my $file = readdir(DIRECTORY)) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { file => $file }}); + next if $file eq "."; + next if $file eq ".."; + next if $file =~ /^\./; # This is files being rsync'ed still + my $full_path = $directory."/".$file; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { full_path => $full_path }}); + + # Skip anything that is not a file. + next if not -f $full_path; + + # Is this file already in the DB? + my $query = "SELECT file_uuid FROM files WHERE file_name = ".$anvil->Database->quote($file).";"; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, 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 => 2, list => { + results => $results, + count => $count, + }}); + if (not $count) + { + # Add it to the database. + my $size = (stat($full_path))[7]; + my $say_size_human = $anvil->Convert->bytes_to_human_readable({'bytes' => $size}); + my $say_size_comma = $anvil->Convert->add_commas({number => $size}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + size => $size, + say_size_human => $say_size_human, + say_size_comma => $say_size_comma, + }}); + + # Register a job to call anvil-sync-shared + my ($job_uuid) = $anvil->Database->insert_or_update_jobs({ + file => $THIS_FILE, + line => __LINE__, + job_command => $anvil->data->{path}{exe}{'anvil-sync-shared'}, + job_data => "file=".$full_path, + job_name => "storage::move_incoming", + job_title => "job_0132", + job_description => "job_0133", + job_progress => 0, + job_host_uuid => $anvil->data->{sys}{host_uuid}, + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); + } + + } + closedir(DIRECTORY); + } + + return(0); +} + # This calls striker-manage-install-target to see if the dhcpd is running or not. If it is or isn't, the config # variable 'install-target::enabled' is set/updated. On non-Striker hosts, this simply returns without doing # anything.