init III
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::DiskPartitionOTRS;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
);
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
# Check if used OS is a linux system
|
||||
if ( $^O !~ /(linux|unix|netbsd|freebsd|darwin)/i ) {
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
# find OTRS partition
|
||||
my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
|
||||
|
||||
my $OTRSPartition = `df -P $Home | tail -1 | cut -d' ' -f 1`;
|
||||
chomp $OTRSPartition;
|
||||
|
||||
$Self->AddResultInformation(
|
||||
Label => Translatable('OTRS Disk Partition'),
|
||||
Value => $OTRSPartition,
|
||||
);
|
||||
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,99 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::DiskSpace;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
);
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
# This plugin is temporary disabled
|
||||
# A new logic is required to calculate the space
|
||||
# TODO: fix
|
||||
return $Self->GetResults();
|
||||
|
||||
# # Check if used OS is a linux system
|
||||
# if ( $^O !~ /(linux|unix|netbsd|freebsd|darwin)/i ) {
|
||||
# return $Self->GetResults();
|
||||
# }
|
||||
#
|
||||
# # find OTRS partition
|
||||
# my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
|
||||
#
|
||||
# my $OTRSPartition = `df -P $Home | tail -1 | cut -d' ' -f 1`;
|
||||
# chomp $OTRSPartition;
|
||||
#
|
||||
# my $Commandline = "df -lx tmpfs -x iso9660 -x udf -x squashfs";
|
||||
#
|
||||
# # current MacOS and FreeBSD does not support the -x flag for df
|
||||
# if ( $^O =~ /(darwin|freebsd)/i ) {
|
||||
# $Commandline = "df -l";
|
||||
# }
|
||||
#
|
||||
# my $In;
|
||||
# if ( open( $In, "-|", "$Commandline" ) ) {
|
||||
#
|
||||
# my ( @ProblemPartitions, $StatusProblem );
|
||||
#
|
||||
# # TODO change from percent to megabytes used.
|
||||
# while (<$In>) {
|
||||
# if ( $_ =~ /^$OTRSPartition\s.*/ && $_ =~ /^(.+?)\s.*\s(\d+)%.+?$/ ) {
|
||||
# my ( $Partition, $UsedPercent ) = $_ =~ /^(.+?)\s.*?\s(\d+)%.+?$/;
|
||||
# if ( $UsedPercent > 90 ) {
|
||||
# push @ProblemPartitions, "$Partition \[$UsedPercent%\]";
|
||||
# $StatusProblem = 1;
|
||||
# }
|
||||
# elsif ( $UsedPercent > 80 ) {
|
||||
# push @ProblemPartitions, "$Partition \[$UsedPercent%\]";
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
# close($In);
|
||||
# if (@ProblemPartitions) {
|
||||
# if ($StatusProblem) {
|
||||
# $Self->AddResultProblem(
|
||||
# Label => Translatable('Disk Usage'),
|
||||
# Value => join( ', ', @ProblemPartitions ),
|
||||
# Message => Translatable('The partition where OTRS is located is almost full.'),
|
||||
# );
|
||||
# }
|
||||
# else {
|
||||
# $Self->AddResultWarning(
|
||||
# Label => Translatable('Disk Usage'),
|
||||
# Value => join( ', ', @ProblemPartitions ),
|
||||
# Message => Translatable('The partition where OTRS is located is almost full.'),
|
||||
# );
|
||||
# }
|
||||
# }
|
||||
# else {
|
||||
# $Self->AddResultOk(
|
||||
# Label => Translatable('Disk Usage'),
|
||||
# Value => '',
|
||||
# Message => Translatable('The partition where OTRS is located has no disk space problems.'),
|
||||
# );
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,111 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::DiskSpacePartitions;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = ();
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System') . '/' . Translatable('Disk Partitions Usage');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
# Check if used OS is a Linux system
|
||||
if ( $^O !~ /(linux|unix|netbsd|freebsd|darwin)/i ) {
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
my $Commandline = "df -lHx tmpfs -x iso9660 -x udf -x squashfs";
|
||||
|
||||
# current MacOS and FreeBSD does not support the -x flag for df
|
||||
if ( $^O =~ /(darwin|freebsd)/i ) {
|
||||
$Commandline = "df -lH";
|
||||
}
|
||||
|
||||
# run the command an store the result on an array
|
||||
my @Lines;
|
||||
if ( open( my $In, "-|", "$Commandline" ) ) {
|
||||
@Lines = <$In>;
|
||||
close($In);
|
||||
}
|
||||
|
||||
# clean results, in some systems when partition is too long it splits the line in two, it is
|
||||
# needed to have all partition information in just one line for example
|
||||
# From:
|
||||
# /dev/mapper/system-tmp
|
||||
# 2064208 85644 1873708 5% /tmp
|
||||
# To:
|
||||
# /dev/mapper/system-tmp 2064208 85644 1873708 5% /tmp
|
||||
my @CleanLines;
|
||||
my $PreviousLine;
|
||||
|
||||
LINE:
|
||||
for my $Line (@Lines) {
|
||||
|
||||
chomp $Line;
|
||||
|
||||
# if line does not have percent number (then it should only contain the partition)
|
||||
if ( $Line !~ m{\d+%} ) {
|
||||
|
||||
# remember the line
|
||||
$PreviousLine = $Line;
|
||||
next LINE;
|
||||
}
|
||||
|
||||
# if line starts with just spaces and have a percent number
|
||||
elsif ( $Line =~ m{\A \s+ (?: \d+ | \s+)+ \d+ % .+? \z}msx ) {
|
||||
|
||||
# concatenate previous line and store it
|
||||
push @CleanLines, $PreviousLine . $Line;
|
||||
$PreviousLine = '';
|
||||
next LINE;
|
||||
}
|
||||
|
||||
# otherwise store the line as it is
|
||||
push @CleanLines, $Line;
|
||||
$PreviousLine = '';
|
||||
}
|
||||
|
||||
my %SeenPartitions;
|
||||
LINE:
|
||||
for my $Line (@CleanLines) {
|
||||
|
||||
# remove leading white spaces in line
|
||||
$Line =~ s{\A\s+}{};
|
||||
|
||||
if ( $Line =~ m{\A .+? \s .* \s \d+ % .+? \z}msx ) {
|
||||
my ( $Partition, $Size, $UsedPercent, $MountPoint )
|
||||
= $Line =~ m{\A (.+?) \s+ ([\d\.KGMT]*) \s+ .*? \s+ (\d+)%.+? (\/.*) \z}msx;
|
||||
|
||||
$MountPoint //= '';
|
||||
|
||||
$Partition = "$MountPoint ($Partition)";
|
||||
|
||||
next LINE if $SeenPartitions{$Partition}++;
|
||||
|
||||
$Self->AddResultInformation(
|
||||
Identifier => $Partition,
|
||||
Label => $Partition,
|
||||
Value => $Size . ' (Used: ' . $UsedPercent . '%)',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,49 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::Distribution;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Environment',
|
||||
);
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
my %OSInfo = $Kernel::OM->Get('Kernel::System::Environment')->OSInfoGet();
|
||||
|
||||
# if OSname starts with Unknown, test was not successful
|
||||
if ( $OSInfo{OSName} =~ /\A Unknown /xms ) {
|
||||
$Self->AddResultProblem(
|
||||
Label => Translatable('Distribution'),
|
||||
Value => $OSInfo{OSName},
|
||||
Message => Translatable('Could not determine distribution.')
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Self->AddResultInformation(
|
||||
Label => Translatable('Distribution'),
|
||||
Value => $OSInfo{OSName},
|
||||
);
|
||||
}
|
||||
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,61 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::KernelVersion;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = ();
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
# Check if used OS is a linux system
|
||||
if ( $^O !~ /(linux|unix|netbsd|freebsd|darwin)/i ) {
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
my $KernelVersion = "";
|
||||
my $KernelInfo;
|
||||
if ( open( $KernelInfo, "-|", "uname -a" ) ) {
|
||||
while (<$KernelInfo>) {
|
||||
$KernelVersion .= $_;
|
||||
}
|
||||
close($KernelInfo);
|
||||
if ($KernelVersion) {
|
||||
$KernelVersion =~ s/^\s+|\s+$//g;
|
||||
}
|
||||
}
|
||||
|
||||
if ($KernelVersion) {
|
||||
$Self->AddResultInformation(
|
||||
Label => Translatable('Kernel Version'),
|
||||
Value => $KernelVersion,
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Self->AddResultProblem(
|
||||
Label => Translatable('Kernel Version'),
|
||||
Value => $KernelVersion,
|
||||
Value => Translatable('Could not determine kernel version.'),
|
||||
);
|
||||
}
|
||||
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,74 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::Load;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = ();
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
# Check if used OS is a linux system
|
||||
if ( $^O !~ /(linux|unix|netbsd|freebsd|darwin)/i ) {
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
my @Loads;
|
||||
|
||||
# If used OS is a linux system
|
||||
if ( $^O =~ /(linux|unix|netbsd|freebsd|darwin)/i ) {
|
||||
|
||||
# linux systems
|
||||
if ( -e "/proc/loadavg" ) {
|
||||
my $LoadFile;
|
||||
open( $LoadFile, '<', "/proc/loadavg" ); ## no critic
|
||||
while (<$LoadFile>) {
|
||||
@Loads = split( " ", $_ );
|
||||
}
|
||||
close($LoadFile);
|
||||
}
|
||||
|
||||
# mac os
|
||||
elsif ( $^O =~ /darwin/i ) {
|
||||
if ( open( my $In, "-|", "sysctl vm.loadavg" ) ) { ## no critic
|
||||
while (<$In>) {
|
||||
if ( my ($Loads) = $_ =~ /vm\.loadavg: \s* \{ \s* (.*) \s* \}/smx ) {
|
||||
@Loads = split ' ', $Loads;
|
||||
}
|
||||
}
|
||||
close $In;
|
||||
}
|
||||
}
|
||||
|
||||
if (@Loads) {
|
||||
$Self->AddResultInformation(
|
||||
Label => Translatable('System Load'),
|
||||
Value => $Loads[2],
|
||||
Message =>
|
||||
Translatable(
|
||||
'The system load should be at maximum the number of CPUs the system has (e.g. a load of 8 or less on a system with 8 CPUs is OK).'
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,60 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::PerlModules;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
);
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
my $Home = $Kernel::OM->Get('Kernel::Config')->Get('Home');
|
||||
|
||||
my $Output;
|
||||
open( my $FH, "-|", "perl $Home/bin/otrs.CheckModules.pl nocolors --all" );
|
||||
|
||||
while (<$FH>) {
|
||||
$Output .= $_;
|
||||
}
|
||||
close($FH);
|
||||
|
||||
if (
|
||||
$Output =~ m{Not \s installed! \s \(required}ismx
|
||||
|| $Output =~ m{failed!}ismx
|
||||
)
|
||||
{
|
||||
$Self->AddResultProblem(
|
||||
Label => Translatable('Perl Modules'),
|
||||
Value => $Output,
|
||||
Message => Translatable('Not all required Perl modules are correctly installed.'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Self->AddResultOk(
|
||||
Label => Translatable('Perl Modules'),
|
||||
Value => $Output,
|
||||
);
|
||||
}
|
||||
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,61 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::PerlModulesAudit;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Console::Command::Dev::Code::CPANAudit',
|
||||
'Kernel::System::Log',
|
||||
);
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
my $CommandObject = $Kernel::OM->Get('Kernel::System::Console::Command::Dev::Code::CPANAudit');
|
||||
|
||||
my ( $CommandOutput, $ExitCode );
|
||||
|
||||
{
|
||||
local *STDOUT;
|
||||
open STDOUT, '>:utf8', \$CommandOutput; ## no critic
|
||||
$ExitCode = $CommandObject->Execute();
|
||||
}
|
||||
|
||||
if ( $ExitCode != 0 ) {
|
||||
$Self->AddResultWarning(
|
||||
Label => Translatable('Perl Modules Audit'),
|
||||
Value => $CommandOutput,
|
||||
Message => Translatable(
|
||||
'CPAN::Audit reported that one or more installed Perl modules have known vulnerabilities. Please note that there might be false positives for distributions patching Perl modules without changing their version number.'
|
||||
),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Self->AddResultOk(
|
||||
Label => Translatable('Perl Modules Audit'),
|
||||
Value => '',
|
||||
Message =>
|
||||
Translatable('CPAN::Audit did not report any known vulnerabilities in the installed Perl modules.'),
|
||||
);
|
||||
}
|
||||
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,40 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::PerlVersion;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::Main',
|
||||
);
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
my $Version = sprintf "%vd", $^V;
|
||||
my $OS = $^O;
|
||||
|
||||
$Self->AddResultInformation(
|
||||
Label => Translatable('Perl Version'),
|
||||
Value => "$Version ($OS)",
|
||||
);
|
||||
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
116
Perl OTRS/Kernel/System/SupportDataCollector/Plugin/OS/Swap.pm
Normal file
116
Perl OTRS/Kernel/System/SupportDataCollector/Plugin/OS/Swap.pm
Normal file
@@ -0,0 +1,116 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::SupportDataCollector::Plugin::OS::Swap;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::SupportDataCollector::PluginBase);
|
||||
|
||||
use Kernel::Language qw(Translatable);
|
||||
|
||||
our @ObjectDependencies = ();
|
||||
|
||||
sub GetDisplayPath {
|
||||
return Translatable('Operating System');
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my $Self = shift;
|
||||
|
||||
# Check if used OS is a linux system
|
||||
if ( $^O !~ /(linux|unix|netbsd|freebsd|darwin)/i ) {
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
my $MemInfoFile;
|
||||
my ( $MemTotal, $MemFree, $SwapTotal, $SwapFree );
|
||||
|
||||
# If used OS is a linux system
|
||||
if ( -e "/proc/meminfo" && open( $MemInfoFile, '<', "/proc/meminfo" ) ) { ## no critic
|
||||
while (<$MemInfoFile>) {
|
||||
my $TmpLine = $_;
|
||||
if ( $TmpLine =~ /MemTotal/ ) {
|
||||
$TmpLine =~ s/^.*?(\d+).*$/$1/;
|
||||
$MemTotal = int($TmpLine);
|
||||
}
|
||||
elsif ( $TmpLine =~ /MemFree/ ) {
|
||||
$TmpLine =~ s/^.*?(\d+).*$/$1/;
|
||||
$MemFree = int($TmpLine);
|
||||
}
|
||||
elsif ( $TmpLine =~ /SwapTotal/ ) {
|
||||
$TmpLine =~ s/^.*?(\d+).*$/$1/;
|
||||
$SwapTotal = int($TmpLine);
|
||||
}
|
||||
elsif ( $TmpLine =~ /SwapFree/ ) {
|
||||
$TmpLine =~ s/^.*?(\d+).*$/$1/;
|
||||
$SwapFree = int($TmpLine);
|
||||
}
|
||||
}
|
||||
close($MemInfoFile);
|
||||
}
|
||||
|
||||
if ($MemTotal) {
|
||||
|
||||
if ( !$SwapTotal ) {
|
||||
$Self->AddResultProblem(
|
||||
Identifier => 'SwapFree',
|
||||
Label => Translatable('Free Swap Space (%)'),
|
||||
Value => 0,
|
||||
Message => Translatable('No swap enabled.'),
|
||||
);
|
||||
$Self->AddResultProblem(
|
||||
Identifier => 'SwapUsed',
|
||||
Label => Translatable('Used Swap Space (MB)'),
|
||||
Value => 0,
|
||||
Message => Translatable('No swap enabled.'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
my $SwapFreeRelative = int( $SwapFree / $SwapTotal * 100 );
|
||||
if ( $SwapFreeRelative < 60 ) {
|
||||
$Self->AddResultProblem(
|
||||
Identifier => 'SwapFree',
|
||||
Label => Translatable('Free Swap Space (%)'),
|
||||
Value => $SwapFreeRelative,
|
||||
Message => Translatable('There should be more than 60% free swap space.'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Self->AddResultOk(
|
||||
Identifier => 'SwapFree',
|
||||
Label => Translatable('Free Swap Space (%)'),
|
||||
Value => $SwapFreeRelative,
|
||||
);
|
||||
}
|
||||
|
||||
my $SwapUsed = ( $SwapTotal - $SwapFree ) / 1024;
|
||||
|
||||
if ( $SwapUsed > 200 ) {
|
||||
$Self->AddResultProblem(
|
||||
Identifier => 'SwapUsed',
|
||||
Label => Translatable('Used Swap Space (MB)'),
|
||||
Value => $SwapUsed,
|
||||
Message => Translatable('There should be no more than 200 MB swap space used.'),
|
||||
);
|
||||
}
|
||||
else {
|
||||
$Self->AddResultOk(
|
||||
Identifier => 'SwapUsed',
|
||||
Label => Translatable('Used Swap Space (MB)'),
|
||||
Value => $SwapUsed,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $Self->GetResults();
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user