diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index 807ea2455a..0c451a74ba 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,8 @@ +2009-09-02 Sancho Lerena + + * lib/PandoraFMS/PluginServer.pm, util/pandora_exec: Nagis plugin + support implemented and working. + 2009-09-02 Ramon Novoa * lib/PandoraFMS/Core.pm: Fixed the matches_value alert option (was not diff --git a/pandora_server/lib/PandoraFMS/PluginServer.pm b/pandora_server/lib/PandoraFMS/PluginServer.pm index 89d6b40c6f..5c70a35627 100644 --- a/pandora_server/lib/PandoraFMS/PluginServer.pm +++ b/pandora_server/lib/PandoraFMS/PluginServer.pm @@ -167,6 +167,37 @@ sub data_consumer ($$) { # Execute command $command = $pa_config->{'plugin_exec'} . ' ' . $timeout . ' ' . $command; my $module_data = `$command`; + my $ReturnCode = ($? >> 8) & 0xff; + + if ($plugin->{'plugin_type'} == 1) { + + # Get the errorlevel if is a Nagios plugin type (parsing the errorlevel) + # Nagios errorlevels: + #('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); + + # Numerical modules (Data) or Alphanumeric modules (String) + # get reported data as is, ignoring return code. + # Boolean data, transform module data depending on returning error code. + + if ($module->{'id_tipo_modulo'} == 2){ + if ($ReturnCode == 0){ + $module_data = 1; + } + elsif ($ReturnCode == 1){ + $module_data = -1; + } + elsif ($ReturnCode == 2){ + $module_data = 0; + } + elsif ($ReturnCode == 3){ + $module_data = ''; # not defined = Uknown + } + elsif ($ReturnCode == 4){ + $module_data = 1; + } + } + } + if (! defined $module_data || $module_data eq '') { pandora_update_module_on_error ($pa_config, $module_id, $dbh); return; diff --git a/pandora_server/util/pandora_exec b/pandora_server/util/pandora_exec index 9b78dea4c3..76de45ecae 100755 --- a/pandora_server/util/pandora_exec +++ b/pandora_server/util/pandora_exec @@ -37,6 +37,8 @@ my $timeout = shift(@opts); my $command = quotemeta(shift(@opts)); my $arguments = join(' ', @opts); my $output = ''; +my $ReturnCode = 0; + # Check that the command exists if (system("$command >/dev/null 2>&1") == 32512) { @@ -49,6 +51,7 @@ eval { alarm $timeout; $output = `$command $arguments`; + $ReturnCode = ($? >> 8) & 0xff; alarm 0; }; @@ -59,4 +62,4 @@ if ($@ eq "alarm\n") { print $output; -exit 0; +exit $ReturnCode;