"Fossies" - the Fresh Open Source Software Archive

Member "unix/plugins/nagios_plugin_wrapper" (15 Sep 2021, 2484 Bytes) of package /linux/misc/pandorafms_agent_unix-7.0NG.757.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/perl
    2 ##########################################################################
    3 # nagios_plugin_wrapper
    4 #
    5 # Executes the given nagios plugin and produces an XML with data for pandora
    6 # to be used as agent plugin. This allows to have DATA based on the errorlevel
    7 # and use the descriptive information on description for the module
    8 #
    9 # Usage: nagios_plugin_wrapper <module_name> <nagios plugin execution with its parameters>
   10 ##########################################################################
   11 # Copyright (c) 2010 Artica Soluciones Tecnologicas S.L
   12 #
   13 # This program is free software; you can redistribute it and/or
   14 # modify it under the terms of the GNU General Public License
   15 # as published by the Free Software Foundation; version 2.
   16 #
   17 # This program is distributed in the hope that it will be useful,
   18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20 # GNU General Public License for more details.
   21 # You should have received a copy of the GNU General Public License
   22 # along with this program; if not, write to the Free Software
   23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   24 ##########################################################################
   25 
   26 use strict;
   27 use warnings;
   28 
   29 my $command = "";
   30 my @opts = @ARGV;
   31 my $module_name = shift(@opts);
   32 $command = join(' ', @opts);
   33 
   34 if ($command ne ""){
   35     my $module_data = `$command`;
   36     my $module_description = $module_data;
   37     my $ReturnCode = ($? >> 8) & 0xff;
   38 
   39 
   40     # Get the errorlevel if is a Nagios plugin type (parsing the errorlevel)
   41     # Nagios errorlevels:   
   42     #('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
   43 
   44     # By default is unknown
   45     $module_data = "";
   46 
   47     if ($ReturnCode == 2){
   48         $module_data = 0;
   49     } 
   50     elsif ($ReturnCode == 3){
   51         $module_data = ''; # not defined = Uknown 
   52     } 
   53     elsif ($ReturnCode == 0){
   54         $module_data = 1; 
   55     } 
   56     elsif ($ReturnCode == 1){
   57         $module_data = 2;  # need to be managed on module thresholds
   58     } 
   59     elsif ($ReturnCode == 4){
   60         $module_data = 3; # need to be managed on module thresholds
   61     }
   62 
   63     print "<module>";
   64     print "<name><![CDATA[".$module_name."]]></name>\n";
   65     print "<type><![CDATA[generic_proc]]></type>\n";
   66     print "<data><![CDATA[".$module_data."]]></data>\n";
   67     print "<description><![CDATA[" . $module_description . "]]></description>\n";
   68     print "</module>\n";
   69 
   70 }