From 5d7746a655c2bd5eb23bfa52ec1882349151216e Mon Sep 17 00:00:00 2001 From: slerena <slerena@gmail.com> Date: Fri, 15 Oct 2010 10:56:56 +0000 Subject: [PATCH] 2010-10-15 SAncho Lerena <slerena@artica.es> * plugins/nagios_plugin_wrapper: Added new plugin. * pandora_agent: Version update. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3408 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/unix/ChangeLog | 6 ++ pandora_agents/unix/pandora_agent | 7 +- .../unix/plugins/nagios_plugin_wrapper | 70 +++++++++++++++++++ 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100755 pandora_agents/unix/plugins/nagios_plugin_wrapper diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog index 7316e9ca1f..80c57e9ba7 100644 --- a/pandora_agents/unix/ChangeLog +++ b/pandora_agents/unix/ChangeLog @@ -1,3 +1,9 @@ +2010-10-15 SAncho Lerena <slerena@artica.es> + + * plugins/nagios_plugin_wrapper: Added new plugin. + + * pandora_agent: Version update. + 2010-10-08 Ramon Novoa <rnovoa@artica.es> * pandora_agent: Pass server_pwd and server_ssl configuration tokens diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index 3ef43d6aa4..db6fbf3b12 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -1,6 +1,6 @@ #!/usr/bin/perl # ********************************************************************** -# Pandora FMS Generic Linux Agent +# Pandora FMS Generic Unix/Perl Agent # (c) 2010 Artica Soluciones Tecnológicas # with the help of many people. Please see http://pandorafms.org # This code is licensed under GPL 2.0 license. @@ -12,7 +12,7 @@ pandora_agent - Pandora FMS Agent =head1 VERSION -Version 3.1 +Version 3.2 =head1 USAGE @@ -57,7 +57,7 @@ if (!$@) { } use constant AGENT_VERSION => '3.2dev'; -use constant AGENT_BUILD => '101008'; +use constant AGENT_BUILD => '101015'; # Commands to retrieve total memory information in kB use constant TOTALMEMORY_CMDS => { @@ -1423,6 +1423,7 @@ while (1) { } # Go to sleep + # sleep ($Conf{'interval'}); } diff --git a/pandora_agents/unix/plugins/nagios_plugin_wrapper b/pandora_agents/unix/plugins/nagios_plugin_wrapper new file mode 100755 index 0000000000..63b9058380 --- /dev/null +++ b/pandora_agents/unix/plugins/nagios_plugin_wrapper @@ -0,0 +1,70 @@ +#!/usr/bin/perl +########################################################################## +# nagios_plugin_wrapper +# +# Executes the given nagios plugin and produces an XML with data for pandora +# to be used as agent plugin. This allows to have DATA based on the errorlevel +# and use the descriptive information on description for the module +# +# Usage: nagios_plugin_wrapper <module_name> <nagios plugin execution with its parameters> +########################################################################## +# Copyright (c) 2010 Artica Soluciones Tecnologicas S.L +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; version 2. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +########################################################################## + +use strict; +use warnings; + +my $command = ""; +my @opts = @ARGV; +my $module_name = shift(@opts); +$command = join(' ', @opts); + +if ($command ne ""){ + my $module_data = `$command`; + my $module_description = $module_data; + my $ReturnCode = ($? >> 8) & 0xff; + + + # Get the errorlevel if is a Nagios plugin type (parsing the errorlevel) + # Nagios errorlevels: + #('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4); + + # By default is unknown + $module_data = ""; + + if ($ReturnCode == 2){ + $module_data = 0; + } + elsif ($ReturnCode == 3){ + $module_data = ''; # not defined = Uknown + } + elsif ($ReturnCode == 0){ + $module_data = 1; + } + elsif ($ReturnCode == 1){ + $module_data = 2; # need to be managed on module thresholds + } + elsif ($ReturnCode == 4){ + $module_data = 3; # need to be managed on module thresholds + } + + print "<module>"; + print "<name>".$module_name."</name>\n"; + print "<type>generic_proc</type>\n"; + print "<data>".$module_data."</data>\n"; + print "<description><![CDATA[" . $module_description . "]]></description>\n"; + print "</module>\n"; + +}