From 54c6954cc00fab0207a5b61db0a67c806a7d415f Mon Sep 17 00:00:00 2001 From: Will Budicm Date: Mon, 31 Aug 2020 14:21:59 +1000 Subject: [PATCH] Bug 28 Fix. --- Current Development Check List.md | 1 + htdocs/cgi-bin/stats.cgi | 49 ++++++++++++++++--------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Current Development Check List.md b/Current Development Check List.md index 23aaa1d..8dcc319 100644 --- a/Current Development Check List.md +++ b/Current Development Check List.md @@ -118,6 +118,7 @@ ### v. 1.9 Encountered/Fixed +* ✔ Bug 28 - System info stats logs not reporting host anymore. * Bug 27 - Restore of old backups not working anymore. * Bug 26 - In Chrome editing log entry not working. Something refreshes page, after 5 seconds. * ✔ Bug 25 - SQLite view not properly sorting in new databases. Newer records listed last. diff --git a/htdocs/cgi-bin/stats.cgi b/htdocs/cgi-bin/stats.cgi index a5dd1bd..8c041b5 100755 --- a/htdocs/cgi-bin/stats.cgi +++ b/htdocs/cgi-bin/stats.cgi @@ -110,31 +110,33 @@ my $gross = big_money($income - $expense); $expense = big_money(sprintf("%.2f",$expense)); $income = big_money(sprintf("%.2f",$income)); - #Under perlbrew, sometimes STDOUT is not piped back to our cgi, #utility inxi could be a perl written version on newer systems. #So I use the inter processing module here for inxi. -- @wbudic -my $HS = ""; +my $buff = ""; my @cmd = ("/usr/bin/inxi", "-b", "-c0"); -#Gatter into $HS -run \@cmd, '>&', \$HS; #instead of -> system("inxi",'-b', '-c0'); -$HS .= `uptime -p`; - - -my $hardware_status = $HS;#`inxi -b -c0; uptime -p`; -my $syslog = "".substr $HS, index($HS, 'Host:'), index($HS, 'Console:'); - $syslog .= "\n".substr $HS, rindex($HS, 'Info:'); - $HS = "
\n".`df -h -l -x tmpfs`."
"; - $syslog .= $HS; -$hardware_status =~ s/\n//g; -$hardware_status =~ s/Memory:/Memory:/g; -$hardware_status =~ s/Init:/<\/b>Initial:/g; -$hardware_status =~ s/up\s/Server is up: /g; -$hardware_status .= ''; +my $uptime = `uptime -p`; +my @ht = split(m/\s/,`hostname -I`); +my $hst = ""; + $hst = `hostname` . "($ht[0])" if (@ht); + + +#Gather into $buff +run \@cmd, ">&", \$buff; #instead of -> system("inxi",'-b', '-c0'); +my @matches = $buff =~ /^(System.*)|(Machine.*)|(CPU.*)|(Drives.*)|(Info.*)|(Init.*)$/gm;#$txt=~/^(?=.*?\bone\b)(?=.*?\btwo\b)(?=.*?\bthree\b).*$/gim); +push (@matches, $uptime); +my $hardware_status = "Host: $hst
".join("\t", map { defined ? $_ : '' } @matches); + $hardware_status =~ s/<.*filter>//gm; #remove crap + $hardware_status =~ s/^(\w+:)/$1<\/b>/m; + #$hardware_status =~ s/(\t\w+:)/$1<\/b>/gms; + $hardware_status =~ s/\t+/
/gm; #TODO: This temp. resolves the regex needs to be adjusted so we join with
+ $hardware_status =~ s/Memory:/
Memory: <\/b>/g; + $hardware_status =~ s/up\s/Server is up: <\/b>/g; + my $prc = 'ps -eo size,pid,user,command --sort -size | awk \'{ hr=$1/1024 ; printf("%13.2f Mb ",hr) } { for ( x=4 ; x<=NF ; x++ ) { printf("%s ",$x) } print "" }\''; -my $processes = `$prc | sort -u -r -`; -my $dbSize = (uc format_bytes($stat[7], bs => 1000)); +my $processes = `$prc | sort -u -r -`; +my $dbSize = (uc format_bytes($stat[7], bs => 1000)); #Strip kernel 0 processes reported $processes =~ s/\s*0.00.*//gd; #trim reduce prefixed spacing @@ -166,11 +168,10 @@ print qq(