mirror of
https://github.com/Cacti/cacti.git
synced 2026-10-30 00:26:50 +09:00
* add perl syntax checking for scripts * Update .github/workflows/syntax.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * only show syntax errors * Add support for ss Fixed shell injection risk from piped netstat | grep by removing shell pipelines. Added use strict; use warnings; and localized variables. Added runtime fallback to ss when netstat is unavailable, with a clear failure when neither exists. * Fix shell injection risk apply fixes (safe open, strict/warnings, key whitelist, error handling). * Update query_unix_partitions.pl * Update unix_users.pl add use strict/warnings to flag issues add better error handling * Update weatherbug.pl * add better suport for gree bsd * Update loadavg.pl --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: TheWitness <thewitness@cacti.net>
33 lines
713 B
Perl
33 lines
713 B
Perl
#!/usr/bin/env perl
|
|
use strict;
|
|
use warnings;
|
|
|
|
|
|
delete @ENV{qw(PATH)};
|
|
$ENV{PATH} = '/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/sbin';
|
|
|
|
my $val1 = $ARGV[0] // '';
|
|
($val1) = $val1 =~ /^([\d]+)$/ if $val1 ne '';
|
|
|
|
#get load avg for 5;15;30 min
|
|
open(PROCESS, '-|', 'uptime');
|
|
my $avg = <PROCESS>;
|
|
$avg =~ s/.*:\s*//;
|
|
close(PROCESS);
|
|
|
|
if (($val1 eq "5") || ($val1 eq "15") || ($val1 eq "30")) {
|
|
my @parts = split(/\s*,\s*/, $avg);
|
|
if ($val1 eq "5") {
|
|
$avg = $parts[0];
|
|
} elsif ($val1 eq "15") {
|
|
$avg = $parts[1];
|
|
} elsif ($val1 eq "30") {
|
|
$avg = $parts[2];
|
|
}
|
|
}
|
|
|
|
chomp $avg;
|
|
$avg =~ s/,//;
|
|
$avg =~ s/\n//;
|
|
print $avg;
|