Merge branch 'ent-621-automonitorizacion-del-servidor-usa-comandos-de-otro-sistema-operativo' into 'develop'

Fixed automonitoring on Windows

See merge request artica/pandorafms!971
This commit is contained in:
vgilc 2017-11-29 16:56:10 +01:00
commit dad457b4d6
2 changed files with 50 additions and 15 deletions

View File

@ -4724,23 +4724,29 @@ sub pandora_self_monitoring ($$) {
$xml_output .=" <data>$agents_unknown</data>";
$xml_output .=" </module>";
$xml_output .=" <module>";
$xml_output .=" <name>System_Load_AVG</name>";
$xml_output .=" <type>generic_data</type>";
$xml_output .=" <data>$load_average</data>";
$xml_output .=" </module>";
if (defined($load_average)) {
$xml_output .=" <module>";
$xml_output .=" <name>System_Load_AVG</name>";
$xml_output .=" <type>generic_data</type>";
$xml_output .=" <data>$load_average</data>";
$xml_output .=" </module>";
}
$xml_output .=" <module>";
$xml_output .=" <name>Free_RAM</name>";
$xml_output .=" <type>generic_data</type>";
$xml_output .=" <data>$free_mem</data>";
$xml_output .=" </module>";
if (defined($free_mem)) {
$xml_output .=" <module>";
$xml_output .=" <name>Free_RAM</name>";
$xml_output .=" <type>generic_data</type>";
$xml_output .=" <data>$free_mem</data>";
$xml_output .=" </module>";
}
$xml_output .=" <module>";
$xml_output .=" <name>FreeDisk_SpoolDir</name>";
$xml_output .=" <type>generic_data</type>";
$xml_output .=" <data>$free_disk_spool</data>";
$xml_output .=" </module>";
if (defined($free_disk_spool)) {
$xml_output .=" <module>";
$xml_output .=" <name>FreeDisk_SpoolDir</name>";
$xml_output .=" <type>generic_data</type>";
$xml_output .=" <data>$free_disk_spool</data>";
$xml_output .=" </module>";
}
$xml_output .= "</agent_data>";

View File

@ -873,6 +873,24 @@ sub dateTimeToTimestamp {
sub disk_free ($) {
my $target = $_[0];
my $OSNAME = $^O;
# Get the free disk on data_in folder unit
if ($OSNAME eq "MSWin32") {
# Check relative path
my $unit;
if ($target =~ m/^([a-zA-Z]):/gi) {
$unit = $1/(1024*1024);
} else {
return;
}
# Get the free space of unit found
my $all_disk_info = `wmic logicaldisk get caption, freespace`;
if ($all_disk_info =~ m/$unit:\D*(\d+)/gmi){
return $1;
}
return;
}
# Try to use df command with Posix parameters...
my $command = "df -k -P ".$target." | tail -1 | awk '{ print \$4/1024}'";
my $output = `$command`;
@ -886,6 +904,9 @@ sub load_average {
if ($OSNAME eq "freebsd"){
$load_average = ((split(/\s+/, `/sbin/sysctl -n vm.loadavg`))[1]);
} elsif ($OSNAME eq "MSWin32") {
# Windows hasn't got load average.
$load_average = undef;
}
# by default LINUX calls
else {
@ -908,6 +929,14 @@ sub free_mem {
elsif ($OSNAME eq "netbsd"){
$free_mem = `cat /proc/meminfo | grep MemFree | awk '{ print \$2 }'`;
}
elsif ($OSNAME eq "MSWin32"){
$free_mem = `wmic OS get FreePhysicalMemory /Value`;
if ($free_mem =~ m/=(.*)$/gm) {
$free_mem = $1;
} else {
$free_mem = undef;
}
}
# by default LINUX calls
else {
$free_mem = `free | grep Mem | awk '{ print \$4 }'`;