File: nagios_plugin_wrapper

package info (click to toggle)
pandorafms-agent 6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 588 kB
  • sloc: perl: 3,800; sh: 924; makefile: 5
file content (70 lines) | stat: -rwxr-xr-x 2,484 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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><![CDATA[".$module_name."]]></name>\n";
    print "<type><![CDATA[generic_proc]]></type>\n";
    print "<data><![CDATA[".$module_data."]]></data>\n";
    print "<description><![CDATA[" . $module_description . "]]></description>\n";
    print "</module>\n";

}