git-svn-id: http://svn.centreon.com/Plugins/Dev@2611 6bcd3966-0018-0410-8128-fd23d134de7e

This commit is contained in:
Mat Sugumaran 2007-07-09 13:36:26 +00:00
parent aec14beb7f
commit 8fb52e74ed
39 changed files with 0 additions and 15728 deletions

View File

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Plugins</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View File

@ -1,22 +0,0 @@
##########################
# Oreon Plugins Change Log
##########################
1.2.3 - 02/11/2005
----------------
* Enhanced Oreon Perl Package oreon.pm (wistof)
* Integration of some Manubulon plugins (wistof)
* New install script for plugins (wistof)
* Minor bug fixes
1.2.2 - xx/08/2005
----------------
* Add Oreon Perl Package oreon.pm (gollum123)
* Globalization of paths in oreon.conf (gollum123)
* Management of RRDTOOL errors (wistof)
* Use Net::SNMP instead of snmpwalk and snmpget (wistof)
* Disable regex for '-H' option (wistof)
* Minor bug fixes

View File

@ -1,8 +0,0 @@
############################
# Oreon Plugins Installation
############################
- just run install.sh in src/ directory
- don't directly copy plugins in Nagios plugins directory

View File

@ -1,12 +0,0 @@
###########################
# Oreon Plugins Requirement
###########################
- Perl in /usr/bin/perl - or just run 'perl script'
- Net::SNMP
- Config::IniFiles
- RRDTool installed (RRDs.pm)
- Oreon perl module (oreon.pm)
- Oreon configuration file for Oreon perl module (oreon.conf)
- file 'utils.pm' in plugin diretory (/usr/local/nagios/libexec)
- sed program for installation script

View File

@ -1,228 +0,0 @@
#!/bin/sh
#
# Oreon is developped with Apache Licence 2.0 :
# http://www.apache.org/licenses/LICENSE-2.0.txt
# Developped by : Julien Mathis - Romain Le Merlus
# Christophe Coraboeuf - Mathieu Chateau
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
#Load install script functions
. ../functions
##
## VARIABLES
##
## Make sure you know what you do if you modify it !!
PWD=`pwd`
PLUGINS_DIR=""
LOG_FILE="../log/install_oreon.log"
date > $LOG_FILE
echo
echo "##########################################################################"
echo "# OREON Project (www.oreon-project.org) #"
echo "# Thanks for using OREON #"
echo "# #"
echo "# v 1.2.3 #"
echo "# #"
echo "# infos@oreon-project.org #"
echo "# #"
echo "# Make sure you have installed and configured #"
echo "# perl - sed #"
echo "# #"
echo "# #"
echo "##########################################################################"
echo "# The Team OREON #"
echo "##########################################################################"
echo ""
echo ""
$SETCOLOR_WARNING
echo " Make sure you have root permissions !"
$SETCOLOR_NORMAL
echo ""
echo "Are you sure to continue?"
echo -n "[y/n], default to [n]:"
read temp
if [ -z $temp ];then
temp=n
fi
if [ $temp = "n" ];then
echo "Bye bye !"
exit
fi
test_answer()
{
#$1 variable to fill
#$2 text typed by user
if [ ! -z $2 ];then
if [ $2 != "" ];then
eval $1=$2
fi
fi
}
##
## CONFIGURATION
##
if test -a $OREON_CONF ; then
echo ""
echo_success "Finding Oreon configuration file '$OREON_CONF' :" "OK"
echo "You already seem to have to install Oreon."
echo "Do you want use last Oreon install parameters ?"
echo -n "[y/n], default to [y]:"
read temp
if [ -z $temp ];then
temp=y
fi
if [ $temp = "y" ];then
echo ""
echo_passed "Using '$OREON_CONF' :" "PASSED"
. $OREON_CONF
echo ""
else
echo ""
echo "First, let's talk about you !"
echo "-----------------------------"
echo ""
fi
fi
if [ -z $INSTALL_DIR_NAGIOS ];then
INSTALL_DIR_NAGIOS="/usr/local/nagios"
echo "Where is installed Nagios ?"
echo -n "default to [$INSTALL_DIR_NAGIOS]:"
read temp
test_answer INSTALL_DIR_NAGIOS $temp
echo ""
fi
if [ -z $NAGIOS_ETC ];then
#nagios etc directory for oreon
NAGIOS_ETC="$INSTALL_DIR_NAGIOS/etc"
echo "Where are your nagios etc directory ?"
echo -n "default to [$NAGIOS_ETC]:"
read temp
test_answer NAGIOS_ETC $temp
echo ""
fi
if [ -z $NAGIOS_PLUGIN ];then
#nagios plugins directory for oreon
NAGIOS_PLUGIN="$INSTALL_DIR_NAGIOS/libexec"
echo "Where are your nagios plugin / libexec directory ?"
echo -n "default to [$NAGIOS_PLUGIN]:"
read temp
test_answer NAGIOS_PLUGIN $temp
echo ""
fi
if [ -z $INSTALL_DIR_OREON ];then
#setup directory for oreon
INSTALL_DIR_OREON="/usr/local/oreon"
echo "Where do I install Oreon ?"
echo -n "default to [$INSTALL_DIR_OREON]:"
read temp
test_answer INSTALL_DIR_OREON $temp
echo ""
fi
if [ -z $SUDO_FILE ];then
#Configuration file for sudo
SUDO_FILE="/etc/sudoers"
echo "Where is sudo ?"
echo -n "default to [$SUDO_FILE]:"
read temp
test_answer SUDO_FILE $temp
echo ""
fi
if [ -z $RRD_PERL ];then
#RRDTOOL perl module directory
RRD_PERL="/usr/local/rrdtool/lib/perl"
echo "Where is RRD perl modules RRDs.pm ?"
echo -n "default to [$RRD_PERL]:"
read temp
test_answer RRD_PERL $temp
echo ""
fi
##
## FUNCTION
##
# When exit on error
function error()
{
echo "ERROR"
exit 2
}
# install OREON PLUGIN
function confirm_oreon()
{
install_oreon_plugins
}
# installation script
#check_group_nagios
#check_user_nagios
#check_group_nagiocmd
#confirm_oreon
##
## INSTALL
##
echo "Users Management"
echo "----------------"
# check for httpd directory
check_httpd_directory
## group apache
check_group_apache
## user apache
check_user_apache
check_group_nagios
check_user_nagios
echo ""
echo "Other Stuff"
echo "------------"
if test -d $NAGIOS_PLUGIN ; then
echo_success "Nagios libexec directory" "OK"
else
mkdir -p $NAGIOS_PLUGIN > /dev/null
echo_success "Nagios libexec directory created" "OK"
fi
# installation script
confirm_oreon
#oreon_post_install
echo ""
echo "###############################################################################"
echo "# #"
echo "# Report bugs at bugs@oreon-project.org #"
echo "# #"
echo "# Thanks for using OREON. #"
echo "# ----------------------- #"
echo "# Contact : infos@oreon-project.org #"
echo "# http://www.oreon-project.org #"
echo "###############################################################################"

View File

@ -1,147 +0,0 @@
#! /usr/bin/perl -w
#
# $Id: check_TcpConn.pl,v 1.2 2005/11/17 10:21:49 Sugumaran Mat $
#
# This plugin is developped under GPL Licence:
# http://www.fsf.org/licenses/gpl.txt
#
# Developped by Merethis SARL : http://www.merethis.com
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# MERETHIS makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the LINAGORA web site.
# In no event will MERETHIS be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if MERETHIS has
# been previously advised of the possibility of such damages.
##
## Plugin init
##
use strict;
use Net::SNMP qw(:snmp);
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_p $opt_c $opt_w);
use vars qw($snmp);
$PROGNAME = "ckeck_TcpConn";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"v=s" => \$opt_v, "snmp_version" => \$opt_v,
"V" => \$opt_V, "version" => \$opt_V,
"H=s" => \$opt_H, "Hostname" => \$opt_H,
"p=i" => \$opt_p, "port" => \$opt_p,
<<<<<<< .mine
"C=s" => \$opt_c, "Community" => \$opt_c
=======
"C=s" => \$opt_C, "Community" => \$opt_C,
"c=s" => \$opt_c, "w=s" => \$opt_w
>>>>>>> .r479
);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.0');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
$opt_p = shift unless ($opt_p);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_p);
($opt_v) || ($opt_v = shift) || ($opt_v = "v1");
my $snmp = $1 if ($opt_v =~ /(\d)/);
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
my $name = $0;
$name =~ s/\.pl.*//g;
my $day = 0;
#=== create a SNMP session ====
# 1.3.6.1.4.1.232.1.2.2.1.1.6
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
if (!defined($session)) {
print("CRITICAL: $error");
exit $ERRORS{'CRITICAL'};
}
my $OID_TCP_PORT = ".1.3.6.1.2.1.6.13.1.3";
my $result = $session->get_table(Baseoid => $OID_TCP_PORT);
if (!defined($result)) {
printf("ERROR: Description Table : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $cpt = 0;
foreach my $key (oid_lex_sort(keys %$result)) {
if ($result->{$key} == $opt_p) {
$cpt++;
}
}
if (!defined($opt_w)){$opt_w = 20;}
if (!defined($opt_c)){$opt_c = 30;}
print "Number of connections on port $opt_p : $cpt |nb_conn=$cpt\n";
if ($cpt >= $opt_w && $cpt < $opt_c){
exit $ERRORS{'WARNING'};
} elsif ($cpt >= $opt_c){
exit $ERRORS{'CRITICAL'};
} else {
exit $ERRORS{'OK'};
}
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -p (--port) port you want to check - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "#=========================================\n";
print "# Copyright (c) 2005 Merethis SARL =\n";
print "# Developped by Julien Mathis =\n";
print "# Bugs to http://www.oreon-project.org/ =\n";
print "#=========================================\n";
print_usage();
print "\n";
}

View File

@ -1,180 +0,0 @@
#! /usr/bin/perl -w
#
# $Id: check_graph_dell_temperature,v 1.4 2005/07/27 22:22:48 wistof Exp $
#
# Oreon's plugins are developped with GPL Licence :
# http://www.fsf.org/licenses/gpl.txt
# Developped by : Wistof
#
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf - Sugumaran Mathavarajan
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
##
## Plugin init
##
use strict;
use Net::SNMP qw(:snmp oid_lex_sort);
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME $VERSION);
use Getopt::Long;
use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_s $opt_t $sensor $OID $OID_DESC);
##
## Plugin var init
##
$VERSION = '$Revision: 1.1 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
$PROGNAME = $0;
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"V" => \$opt_V, "version" => \$opt_V,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"s" => \$opt_s, "show" => \$opt_s,
"t=s" => \$opt_t, "sensor=s" => \$opt_t,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.1 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
my $snmp = $1 if ($opt_v =~ /(\d)/);
($opt_t) || ($opt_t = shift) || ($opt_t = "1");
my $sensor = $1 if ($opt_t =~ /(\d)/);
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
my $start=time;
my $name = $0;
$name =~ s/\.pl.*//g;
##
## Plugin snmp requests
##
my $OID = ".1.3.6.1.4.1.674.10892.1.700.20.1.6.1";
my $OID_DESC = ".1.3.6.1.4.1.674.10892.1.700.20.1.8.1";
# create a SNMP session
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
if ( !defined($session) ) {
print("UNKNOWN: $error");
exit $ERRORS{'UNKNOWN'};
}
if ($opt_s) {
# Get desctiption table
my $result = $session->get_table(
Baseoid => $OID_DESC
);
if (!defined($result)) {
printf("ERROR: Description Table : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
foreach my $key ( oid_lex_sort(keys %$result)) {
my @oid_list = split (/\./,$key);
my $index = pop (@oid_list) ;
print "Temperature Sensor $index :: $$result{$key}\n";
}
exit $ERRORS{'OK'};
}
my $result = $session->get_request(
-varbindlist => [$OID.".".$sensor,
$OID_DESC.".".$sensor]
);
if (!defined($result)) {
printf("UNKNOWN: %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $return_result = $result->{$OID.".".$sensor};
my $un = 0;
if ($return_result =~ /(\d+)/ ) {
$un = $1;
} else {
printf("UNKNOWN: Unable to parse SNMP Output :: %s", $return_result );
$session->close;
exit $ERRORS{'UNKNOWN'};
}
$un = sprintf("%02.2f", $un / 10);
##
## Plugin return code
##
if ($un || ( $un == 0) ){
print "OK - ". $result->{$OID_DESC.".".$sensor} ." : $un\n";
exit $ERRORS{'OK'};
}
else{
print "CRITICAL Host unavailable\n";
exit $ERRORS{'CRITICAL'};
}
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -t (--sensor) Set the sensor number (1 by default)\n";
print " -s (--show) Describes all sensors \n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "Copyright (c) 2005 Oreon\n";
print "Bugs to http://www.oreon.org/\n";
print "\n";
print_usage();
print "\n";
}

View File

@ -1,191 +0,0 @@
#! /usr/bin/perl -w
#
# $Id: check_graph_http,v 1.4 2005/08/01 18:03:52 gollum123 Exp $
#
# This plugin is developped under GPL Licence:
# http://www.fsf.org/licenses/gpl.txt
#
# Modified for Oreon Project by : Sugumaran Mathavarajan - Mathieu Chateau - Christophe Coraboeuf
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
##
## Plugin init
##
use strict;
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use Getopt::Long;
use vars qw($opt_h $opt_V $opt_g $opt_D $opt_S $opt_H $opt_I $opt_e $opt_s $opt_u $opt_p $opt_P $opt_w $opt_c
$opt_t $opt_a $opt_L $opt_f $opt_l $opt_r $opt_R $opt_z $opt_C $opt_step $step);
use vars qw($PROGNAME);
##
## Plugin var init
##
my $pathtolibexechttp = $oreon{GLOBAL}{ NAGIOS_LIBEXEC}."check_http";
$PROGNAME = "$0";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"V" => \$opt_V, "version" => \$opt_V,
"H=s" => \$opt_H, "hostname=s" => \$opt_H,
"I=s" => \$opt_I, "IP-address=s" => \$opt_I,
"e=s" => \$opt_e, "expect=s" => \$opt_e,
"s=s" => \$opt_s, "string=s" => \$opt_s,
"u=s" => \$opt_u, "url=s" => \$opt_u,
"p=s" => \$opt_p, "port=s" => \$opt_p,
"P=s" => \$opt_P, "post=s" => \$opt_P,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"t=s" => \$opt_t, "timeout=s" => \$opt_t,
"a=s" => \$opt_a, "authorization=s" => \$opt_a,
"L=s" => \$opt_L, "link=s" => \$opt_L,
"f=s" => \$opt_f, "onredirect=s" => \$opt_f,
"l=s" => \$opt_l, "linespan=s" => \$opt_l,
"r=s" => \$opt_r, "regex=s" => \$opt_r,
"R=s" => \$opt_R, "eregi=s" => \$opt_R,
"C=s" => \$opt_C, "certificate=s" => \$opt_C,
"z" => \$opt_R, "ssl" => \$opt_z
);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.3 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
($opt_step) || ($opt_step = shift) || ($opt_step = "300");
$step = $1 if ($opt_step =~ /(\d+)/);
my $args_check_http = "";
if ( $opt_H ) {
$args_check_http .= " -H $opt_H";
}
if ( $opt_I ) {
$args_check_http .= " -I $opt_I";
}
if ( $opt_e ) {
$args_check_http .= " -e $opt_e";
}
if ( $opt_s ) {
$args_check_http .= " -s $opt_s";
}
if ( $opt_u ) {
$args_check_http .= " -u $opt_u";
}
if ( $opt_p ) {
$args_check_http .= " -p $opt_p";
}
if ( $opt_P ) {
$args_check_http .= " -P $opt_P";
}
if ( $opt_I ) {
$args_check_http .= " -I $opt_I";
}
if ( $opt_e ) {
$args_check_http .= " -e $opt_e";
}
if ( $opt_w ) {
$args_check_http .= " -w $opt_w";
}
if ( $opt_c ) {
$args_check_http .= " -c $opt_c";
}
if ( $opt_t ) {
$args_check_http .= " -t $opt_t";
}
if ( $opt_a ) {
$args_check_http .= " -a $opt_a";
}
if ( $opt_L ) {
$args_check_http .= " -L $opt_L";
}
if ( $opt_f ) {
$args_check_http .= " -f $opt_f";
}
if ( $opt_l ) {
$args_check_http .= " -l $opt_l";
}
if ( $opt_r ) {
$args_check_http .= " -r $opt_r";
}
if ( $opt_R ) {
$args_check_http .= " -R $opt_R";
}
if ( $opt_C ) {
$args_check_http .= " -C $opt_C";
}
if ( $opt_z ) {
$args_check_http .= " --ssl";
}
my $start=time;
my $name = $0;
$name =~ s/\.pl.*//g;
##
## Plugin requests
##
# print "args: $args_check_http \n";
my $result = `$pathtolibexechttp $args_check_http`;
my $return_code = $? / 256;
$_ = $result;
m/time=\s*(\d*\.\d*)/;
my $time = $1;
print "$result";
exit $return_code;
##
## Plugin return code
##
sub print_usage () {
my $screen = `$pathtolibexechttp -h`;
$screen =~ s/check_http/check_graph_http/g;
$screen =~ s/-S/-Z/;
print $screen;
}
sub print_help () {
print "Copyright (c) 2005 LINAGORA SA\n";
print "Bugs to http://www.linagora.com/\n";
print "\n";
print_usage();
print "\n";
}

View File

@ -1,336 +0,0 @@
#! /usr/bin/perl -w
#
# $Id: check_graph_nt.pl,v 1.4 2005/08/01 18:04:00 gollum123 Exp $
#
# Oreon's plugins are developped with GPL Licence :
# http://www.fsf.org/licenses/gpl.txt
# Developped by : Julien Mathis - Mathieu Mettre
#
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
# Modified for Oreon Project by : Sugumaran Mathavarajan - msugumaran@merethis.com
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
##
## Plugin init
##
use strict;
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_H $opt_p $opt_s $opt_v $opt_V $opt_h $opt_w $opt_c $opt_S $opt_g $opt_t $opt_l $opt_d $opt_D $opt_step $step $opt_f);
##
## Plugin var init
##
my $pathtolibexecnt = $oreon{GLOBAL}{NAGIOS_LIBEXEC}."check_nt";
my($op_v, $op_d, $op_s, $op_t, $op_l, $port, @values, @test, @test2, @test3, @test4, @test5, $warning, $critical, @w, @c, $uptime);
my($warning2, $critical2, $warning3, $critical3, $warning4, $critical4, @output);
$PROGNAME = "$0";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"p=s" => \$opt_p, "port=s" => \$opt_p,
"V" => \$opt_V, "version" => \$opt_V,
"s=s" => \$opt_s, "password=s" => \$opt_s,
"d=s" => \$opt_d, "showall=s" => \$opt_d,
"v=s" => \$opt_v, "variable=s" => \$opt_v,
"D=s" => \$opt_D, "directory=s" => \$opt_D,
"t=s" => \$opt_t, "timeout=s" => \$opt_t,
"l:s" => \$opt_l, "parameter:s" => \$opt_l,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
if ($opt_V) {
$_ = `$pathtolibexecnt -V`;
print "$_";
exit $ERRORS{'OK'};
}
if ($opt_p) {
if ($opt_p =~ /([0-9]+)/){
$port = $1;
}
else{
print "Unknown -p number expected... or it doesn't exist, try another port - number\n";
exit $ERRORS{'UNKNOWN'};
}
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
if ($opt_c) {
($opt_c) || ($opt_c = shift);
$critical = $1 if ($opt_c =~ /([0-9]+)/);
}
if ($opt_w) {
($opt_w) || ($opt_w = shift);
$warning = $1 if ($opt_w =~ /([0-9]+)/);
}
if (($critical && $warning) && ($critical <= $warning)) {
print "(--crit) must be superior to (--warn)";
print_usage();
exit $ERRORS{'OK'};
}
if ($opt_t) {
($opt_t) || ($opt_t = shift);
$op_t = $1 if ($opt_t =~ /([-\.,\w]+)/);
}
if ($opt_l) {
($opt_l) || ($opt_l = shift);
$op_l = $1 if ($opt_l =~ /(.+)/);
}
if ($opt_s) {
($opt_s) || ($opt_s = shift);
$op_s = $1 if ($opt_s =~ /([-.,A-Za-z0-9]+)/);
}
if ($opt_d) {
($opt_d) || ($opt_d = shift);
$op_d = $1 if ($opt_d =~ /([-.,A-Za-z0-9]+)/);
}
if ($opt_v) {
($opt_v) || ($opt_v = shift);
$op_v = $1 if ($opt_v =~ /([-.,A-Za-z0-9]+)/);
}
($opt_step) || ($opt_step = shift) || ($opt_step = 300);
$step = $1 if ($opt_step =~ /(\d+)/);
my $name = $0;
$name =~ s/\.pl.*//g;
my $return_code;
##
## Plugin requests
##
my $start=time;
if ($op_v) {
if ($op_v) {$op_v = "-v ".$op_v;}
if ($port) {$port = "-p ".$port;} else { $port = " ";}
if ($warning) {$warning = "-w ".$warning;} else { $warning = " ";}
if ($critical) {$critical = "-c ".$critical;} else { $critical = " ";}
if ($op_l) {$op_l = "-l \"".$op_l ."\"";} else { $op_l = " ";}
if ($op_t) {$op_t = "-t ".$op_t;} else { $op_t = " ";}
if ($op_s) {$op_s = "-s ".$op_s;} else { $op_s = " ";}
if ($op_d) {$op_d = "-d ".$op_d;} else { $op_d = " ";}
# print "$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d\n";
$_ = `$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d 2>/dev/null`;
my $return = $_;
$return =~ s/\\//g;
$return_code = $? / 256;
##
## CLIENTVERSION
##
if ($op_v =~ /CLIENTVERSION/){
print "CLIENTVERSION impossible to Graph!\n";
exit $ERRORS{'UNKNOWN'};
}
if (($op_v =~ /CPULOAD/) && ($op_l =~ /([-\.,\w]+)/)){ ## CPULOAD
@output = split(/\|/,$_);
@values = $output[0] =~ /(\d*)\%/g ;
$start=time;
## Print Plugins Output
$return =~ s/\n/ /g;
if (@values){
if (defined($opt_c) && defined($opt_w)){
print $return . "|cpu=@values;$opt_w;$opt_c\n";
} else {
print $return . "|cpu=@values\n";
}
} else {
print $return . "\n";
}
exit $return_code;
} elsif ($op_v =~ /UPTIME/){ ## UPTIME
if ($_ =~ /.*[-:]+\s(\d+)\s.*$/ ) {
$uptime = $1;
} else {
print "unable to parse check_nt output: $_\n" ;
exit $ERRORS{'UNKNOWN'};
}
$_ =~ s/\n/ /g;
if (defined($uptime)){
print $_ . "|uptime=".$uptime."d\n";
} else {
print $_ . "\n";
}
exit $return_code;
} elsif (($op_v =~ /USEDDISKSPACE/) && ($op_l =~ /([-\.,\w]+)/)){ ## USEDDISKSPACE
my @test = split(/ /,$_);
if (defined($test[9]) && defined($test2[1])){
@test2 = split(/\(/, $test[9]);
@test3 = split(/\%/, $test2[1]);
}
@c = split(/ /, $critical);
$critical = $c[1];
@w = split(/ /, $warning);
$warning = $w[1];
## Print Plugins Output
$return =~ s/\n/ /g;
$return =~ s/%/ pct/g;
if (defined($test[3]) && defined($test[7]) && defined($test[12])){
print $return . "|total=".$test[3]."Mo used=".$test[7]."Mo free=".$test[12]."Mo\n";
} else {
print $return . "\n";
}
exit $return_code;
} elsif ($op_v =~ /MEMUSE/){ ## MEMUSE
$start=time;
my @test = split(/ /,$_);
if (defined($test[2])){
@test4 = split(/:/, $test[2]);
}
@c = split(/ /, $critical);
$critical = $c[1];
@w = split(/ /, $warning);
$warning = $w[1];
## Print Plugins Output
$return =~ s/\n/ /g;
$return =~ s/%/ pct/g;
if ($test4[1] && $test[6] && $test[11]){
print $return . "|total=".$test4[1]." used=".$test[6]." free=".$test[11]."\n";
} else {
print $return . "\n";
}
exit $return_code;
} elsif ($op_v =~ /SERVICESTATE/){## SERVICESTATE
my (@tab, $process, $nom, $etat);
@tab = split (' - ',$_);
foreach $process (@tab) {
($nom,$etat) = split (': ', $process);
if (defined($etat)) {
$etat =~ s/\n//;
} else {
$etat = "Unknow";
}
if ($etat =~ /Started/)
{$etat=1;}
elsif ($etat =~ /Stopped/)
{$etat=0;}
elsif ($etat =~ /Unknown/)
{$etat=-1;}
else {
print "Unable to get $nom status [$etat]: \n\t$_\n";
exit $ERRORS{'UNKNOWN'};
}
}
$return =~ s/%/ pct/g;
print $return;
exit $return_code;
} elsif ($op_v =~ /PROCSTATE/){## PROCSTATE
print "PROCSTATE not graphed\n";
exit $ERRORS{'UNKNOWN'};
} elsif (($op_v =~ /COUNTER/) && ($op_l =~ /(.+)/)) { ## COUNTER
@output = split(/\|/,$_);
@values = $output[0] =~ /([,\.\d]*)\s?\%/ ;
if (!@values) {@values = $output[0] =~ /([\d]*)/;}
$start=time;
## Print Plugins Output
$return =~ s/\n/ /g;
$return =~ s/%/ pct/g;
print $return . "|counter=".@values."\n";
exit $return_code;
}
} else {
print "Could not parse arguments\n";
exit $ERRORS{'UNKNOWN'};
}
##
## Plugin return code
##
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " Usage: check_graph_nt -H host -v variable [-p port] [-s password] [-w warning] [-c critical] [-l params] [-d SHOWALL] [-t timeout] \n";
print " Options:\n";
print " -H, --hostname=HOST\n";
print " Name of the host to check\n";
print " -p, --port=INTEGER\n";
print " Optional port number (default: 1248)\n";
print " -s <password>\n";
print " Password needed for the request\n";
print " -v, --variable=STRING\n";
print " Variable to check. Valid variables are:\n";
print " CLIENTVERSION = Not Graphed. Get the NSClient version\n";
print " CPULOAD = Average CPU load on last x minutes. Request a -l parameter with the following syntax:\n";
print " -l <minutes range>,<warning threshold>,<critical threshold>. <minute range> should be less than 24*60.\n";
print " Thresholds are percentage and up to 10 requests can be done in one shot. ie: -l 60,90,95,120,90,95\n";
print " and 4 requests can be graphed.\n";
print " UPTIME = Only Days are graphed. Get the uptime of the machine. No specific parameters. No warning or critical threshold.\n";
print " USEDDISKSPACE = Size and percentage of disk use. Request a -l parameter containing the drive letter only.\n";
print " Warning and critical thresholds can be specified with -w and -c.\n";
print " MEMUSE = Memory use. Warning and critical thresholds can be specified with -w and -c.\n";
print " SERVICESTATE = Check and graph the state of one service. Request a -l parameters with the following syntax:\n";
print " -l <service1>... You MUST specify -d SHOWALL in the input command.\n";
print " 1: Service Started - 0: Service Stopped - -1: Service Unknown.\n";
# print " SERVICESTATE = Not Graphed. Check the state of one or several services. Request a -l parameters with the following syntax:\n";
# print " -l <service1>,<service2>,<service3>,... You can specify -d SHOWALL in case you want to see working services\n";
# print " in the returned string.\n";
print " PROCSTATE = Not Graphed. Check if one or several process are running. Same syntax as SERVICESTATE.\n";
print " COUNTER = Check any performance counter of Windows NT/2000. Request a -l parameters with the following syntax:\n";
print " -l \"<performance object>counter\",\"<description>\" The <description> parameter is optional and\n";
print " is given to a printf output command which require a float parameters. Some examples:\n";
print " \"Paging file usage is %.2f %%\" or \"%.f %% paging file used.\"\n";
print " -w, --warning=INTEGER\n";
print " Threshold which will result in a warning status\n";
print " -c, --critical=INTEGER\n";
print " Threshold which will result in a critical status\n";
print " -t, --timeout=INTEGER\n";
print " Seconds before connection attempt times out (default: 10)\n";
print " -h, --help\n";
print " Print this help screen\n";
print " -V, --version\n";
print " Print version information\n";
}
sub print_help () {
print "Copyright (c) 2004 OREON\n";
print "Bugs to http://www.oreon.org/\n";
print "\n";
print_usage();
print "\n";
}

View File

@ -1,243 +0,0 @@
#! /usr/bin/perl -w
#
# $Id: check_packetsErrors.pl,v 1.2 2005/07/27 22:21:49 Julio $
#
# Oreon's plugins are developped with GPL Licence :
# http://www.fsf.org/licenses/gpl.txt
# Developped by : Julien Mathis - Romain Le Merlus - Sugumaran Mat
#
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
# Modified By Julien Mathis For Merethis Company
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
#
# Plugin init
#
use strict;
use Net::SNMP qw(:snmp oid_lex_sort);
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($VERSION %oreon);
use vars qw(%oreon);
$VERSION = '$Revision: 1.2 $';
$VERSION =~ s/^\$.*:\W(.*)\W.+?$/$1/;
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_w $opt_c);
#
# Plugin var init
#
$PROGNAME = "$0";
my ($row, @flg_created, @last_check_time, @last_in_errors, @last_out_errors, $result_in, $result_out, @nb_out_errors, @nb_in_errors, $update_time, $db_file);
my $pathtolibexecnt = $oreon{NAGIOS_LIBEXEC};
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"V" => \$opt_V, "version" => \$opt_V,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
##################################################
##### Verify Options
##
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
my $snmp = $1 if ($opt_v =~ /(\d)/);
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
($opt_c) || ($opt_c = shift) || ($opt_c = 100);
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
($opt_w) || ($opt_w = shift) || ($opt_w = 80);
my $warning = $1 if ($opt_w =~ /([0-9]+)/);
if ($critical <= $warning){
print "(--crit) must be superior to (--warn)";
print_usage();
exit $ERRORS{'OK'};
}
my $start=time;
#################################################
##### Plugin snmp requests
##
my $OID_IN_ERRORS = ".1.3.6.1.2.1.2.2.1.14";
my $OID_OUT_ERRORS = ".1.3.6.1.2.1.2.2.1.20";
# create a SNMP session
my ($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error");
exit $ERRORS{'UNKNOWN'};
}
####### Get IN ERRORS
$result_in = $session->get_table(Baseoid => $OID_IN_ERRORS);
if (!defined($result_in)) {
printf("ERROR: IN_ERRORS : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
# loop for each interface
foreach my $err (oid_lex_sort(keys %$result_in)) {
$nb_in_errors[scalar(@nb_in_errors)] = $result_in->{$err};
}
# ####### Get OUT ERRORS
$result_out = $session->get_table(Baseoid => $OID_OUT_ERRORS);
if (!defined($result_out)) {
printf("ERROR: OUT_ERRORS : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
foreach my $err (oid_lex_sort(keys %$result_out)) {
$nb_out_errors[scalar(@nb_out_errors)] = $result_out->{$err};
}
# #############################################
# ##### read and write in buffer file
# ##
for (my $i = 0; $i < scalar(@nb_in_errors); $i++) {
if (-e "/tmp/packet_errors_if".$i."_".$opt_H.".tmp") {
open(FILE,"<"."/tmp/packet_errors_if".$i."_".$opt_H.".tmp");
while($row = <FILE>){
my @last_values = split(":",$row);
$last_check_time[$i] = $last_values[0];
$last_in_errors[$i] = $last_values[1];
$last_out_errors[$i] = $last_values[2];
$flg_created[$i] = 1;
}
close(FILE);
} else {
$flg_created[$i] = 0;
}
$update_time = time;
unless (open(FILE,">"."/tmp/packet_errors_if".$i."_".$opt_H.".tmp")){
print "Unknown - /tmp/tmp/packet_errors_if".$i."_".$opt_H.".tmp!\n";
exit $ERRORS{"UNKNOWN"};
}
print FILE "$update_time:$nb_in_errors[$i]:$nb_out_errors[$i]";
close(FILE);
if ($flg_created[$i] eq 0){
print "First execution : Buffer in creation.... \n";
}
}
# #############################################
# ##### return result
# ##
my $status = "OK";
my @msg;
my $diff_test = 0;
for (my $i = 0; $i < scalar(@nb_in_errors); $i++) {
my $interface = $i+1;
if ($flg_created[$i]) {
if (($nb_in_errors[$i] - $last_in_errors[$i] >= $critical) or ($nb_out_errors[$i] - $last_out_errors[$i] >= $critical)){
$msg[$i] = "$interface:critical ";
$status = "CRITICAL";
}
if(($nb_in_errors[$i] - $last_in_errors[$i] >= $warning) or ($nb_out_errors[$i] - $last_out_errors[$i] >= $warning)){
if (!defined($msg[$i])) {
$msg[$i] = "$interface:warning ";
}
if ($status ne "CRITICAL") {
$status = "WARNING";
}
}
$diff_test = 1;
}
}
if (!$diff_test) {
exit($ERRORS{'UNKNOWN'});
}
my $output = "";
for (my $i = 0; $i < scalar (@msg); $i++) {
if (defined($msg[$i])) {
$output .= $msg[$i];
}
}
if ($output ne ""){
print $output."\n";
}else {
print "Status OK on all interfaces\n";
}
exit($ERRORS{$status});
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (default to public)\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -w (--warn) Signal strength at which a warning message will be generated\n";
print " (default 80)\n";
print " -c (--crit) Signal strength at which a critical message will be generated\n";
print " (default 100)\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "##########################################\n";
print "# Copyright (c) 2004-2006 Oreon #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "##########################################\n";
print_usage();
print "\n";
}

View File

@ -1,201 +0,0 @@
#! /usr/bin/perl -w
#
# $Id: check_oreon_ping,v 1.3 2006/04/28 10:21:49 Julien Mathis $
#
# Oreon's plugins are developped with GPL Licence :
# http://www.fsf.org/licenses/gpl.txt
# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus
#
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
# Modified By Julien Mathis - Sugumaran Mathavarajan For Merethis Company
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
#
# Plugin init
#
use strict;
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_g $opt_H $opt_D $opt_w $opt_c $opt_n $opt_f $opt_S $rta_critical $rta_warning $pl_critical $pl_warning $opt_s $opt_step $step );
#
# Plugin var init
#
my $ping = `whereis -b ping`;
$ping =~ /^.*:\s(.*)$/;
$ping = $1;
$PROGNAME = "$0";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"V" => \$opt_V, "version" => \$opt_V,
"rrd_step=s" => \$opt_step,"f" => \$opt_f,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"n=s" => \$opt_n, "number=s" => \$opt_n,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
($opt_c) || ($opt_c = shift) || ($opt_c = "500,40%");
if ($opt_c =~ /([0-9]+),([0-9]+)%/) {
$rta_critical = $1;
$pl_critical = $2;
}
($opt_w) || ($opt_w = shift) || ($opt_w = "200,20%");
if ($opt_w =~ /([0-9]+),([0-9]+)%/) {
$rta_warning = $1;
$pl_warning = $2;
}
if (!$rta_warning || !$rta_critical || !$pl_warning || !$pl_critical) {
print "bad initialisation of Treshholds\n";
exit $ERRORS{'OK'};
}
if ( ($rta_critical <= $rta_warning) || ($pl_critical <= $pl_warning) ) {
print "critical must be superior to warning\n";
print_usage();
exit $ERRORS{'OK'};
}
($opt_n) || ($opt_n = shift) || ($opt_n = 1);
my $NbPing;
if ($opt_n =~ /([0-9]+)/){
$NbPing = $1;
} else{
print "Unknown ping number\n";
exit $ERRORS{'UNKNOWN'};
}
my $start=time;
#
# RRDTools create rrd
#
#
# Plugin requests
#
$_ = `$ping -n -c $NbPing $opt_H 2>/dev/null`;
my $return = $? / 256;
#
# Get Data From Ping Result
#
if (!$_) {
print "no value returned by ping\n";
exit $ERRORS{'UNKNOWN'};
}
my $ping_result = $_;
my @ping_result_array = split(/\n/,$ping_result);
my @ping_subresult1_array;
my @ping_subresult2_array;
my $rta = 0;
my $pl;
my $time_answer;
if( ( $return != 0 ) || $ping_result_array[@ping_result_array -2 ] =~ /100% packet loss/) {
$rta = -1;
$time_answer = 0;
} else {
@ping_subresult1_array = split(/=/,$ping_result_array[@ping_result_array -1 ]);
@ping_subresult2_array = split(/,/,$ping_result_array[@ping_result_array -2 ]);
@ping_subresult1_array = split(/\//,$ping_subresult1_array[1]);
@ping_subresult2_array = split(/ /,$ping_subresult2_array[2]);
$rta = $ping_subresult1_array[1];
$pl = $ping_subresult2_array[1];
$time_answer = $ping_subresult1_array[1];
$pl =~ /([0-9]+)\%/;
$pl = $1;
}
#
# Plugin return code
#
my $result_str = "";
if( $rta == -1 ) {
$ping_result_array[@ping_result_array -2 ] =~ s/\%/percent/g;
print "GPING CRITICAL - ".$ping_result_array[@ping_result_array -2 ]."|time=0 ok=0\n";
exit $ERRORS{'CRITICAL'};
} elsif ( ($pl >= $pl_critical) || ($rta >= $rta_critical) ) {
$ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g;
my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]);
print "GPING CRITICAL - ". $tab[1] ."|time=".$time_answer."ms;$pl_warning;$pl_critical;; ok=1\n";
exit $ERRORS{'CRITICAL'};
} elsif ( ($pl >= $pl_warning) || ($rta >= $rta_warning) ) {
$ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g;
my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]);
print "GPING WARNING - ".$tab[0]."|time=".$time_answer."ms;$pl_warning;$pl_critical;; ok=1\n";
exit $ERRORS{'WARNING'};
} else {
$ping_result_array[@ping_result_array -1 ] =~ s/\%/percent/g;
my @tab = split(/,/,$ping_result_array[@ping_result_array -1 ]);
print "GPING OK - ".$tab[0]."|time=".$time_answer."ms;$pl_warning;$pl_critical;; ok=1\n";
exit $ERRORS{'OK'};
}
sub print_usage () {
print "Usage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query (Required)\n";
print " -g (--rrdgraph) Create a rrd base if necessary and add datas into this one\n";
print " --rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)\n";
print " -S (--ServiceId) Oreon Service Id\n";
print " -w (--warning) Threshold pair (Default: 200,20%)\n";
print " -c (--critical) Threshold pair (Default: 500,40%)\n";
print " -n (--number) number of ICMP ECHO packets to send (Default: 1)\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "######################################################\n";
print "# Copyright (c) 2004-2006 Oreon-project #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "######################################################\n";
print_usage();
print "\n";
}

View File

@ -1,203 +0,0 @@
#! /usr/bin/perl -w
###################################################################
# Oreon is developped with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
# Developped by : Julien Mathis - Romain Le Merlus
# Mathavarajan Sugumaran
#
###################################################################
# 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# For information : contact@merethis.com
####################################################################
#
# Script init
#
use strict;
use Net::SNMP qw(:snmp);
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw($VERSION %oreon);
%oreon = get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_H $opt_c $opt_w $opt_D $snmp $opt_k $opt_u $opt_p @critical @warning);
# Plugin var init
my($return_code);
$PROGNAME = "$0";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"u=s" => \$opt_u, "username=s" => \$opt_u,
"p=s" => \$opt_p, "password=s" => \$opt_p,
"k=s" => \$opt_k, "key=s" => \$opt_k,
"V" => \$opt_V, "version" => \$opt_V,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
if (!$opt_H) {
print_usage();
exit $ERRORS{'OK'};
}
my $snmp = "1";
$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/);
@critical = ('2', '4', '6');
if ($opt_c && $opt_c =~ /^([0-9]+),([0-9]+),([0-9]+)$/) {
@critical = ($1,$2,$3);
} else {
print "Specify three critical treshold separated with a coma\n";
exit $ERRORS{'OK'};
}
@warning = ('1', '3', '5');
if ($opt_w && $opt_w =~ /^([0-9]+),([0-9]+),([0-9]+)$/) {
@warning = ($1,$2,$3);
} else {
print "Specify three warning treshold separated with a coma\n";
exit $ERRORS{'OK'};
}
for (my $i = 0; $i < scalar(@warning); $i++) {
if ($warning[$i] >= $critical[$i]) {
print "Critical tresholds must be superior to warning tresholds.\n";
exit $ERRORS{'OK'};
}
}
if ($snmp eq "3") {
if (!$opt_u) {
print "Option -u (--username) is required for snmpV3\n";
exit $ERRORS{'OK'};
}
if (!$opt_p && !$opt_k) {
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
exit $ERRORS{'OK'};
} elsif ($opt_p && $opt_k) {
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
exit $ERRORS{'OK'};
}
}
$opt_C = "public" if (!$opt_C);
my $name = $0;
$name =~ s/\.pl.*//g;
# Plugin snmp requests
my $OID_CPULOAD_1 =$oreon{UNIX}{CPU_LOAD_1M};
my $OID_CPULOAD_5 =$oreon{UNIX}{CPU_LOAD_5M};
my $OID_CPULOAD_15 =$oreon{UNIX}{CPU_LOAD_15M};
my ($session, $error);
if ($snmp eq "1" || $snmp eq "2") {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}elsif ($opt_k) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}elsif ($opt_p) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}
my $result = $session->get_request(
-varbindlist => [$OID_CPULOAD_1, $OID_CPULOAD_5, $OID_CPULOAD_15 ]
);
if (!defined($result)) {
printf("UNKNOWN: %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $un = $result->{$OID_CPULOAD_1};
my $cinq = $result->{$OID_CPULOAD_5};
my $quinze = $result->{$OID_CPULOAD_15};
# Plugin return code
my $status = "OK";
if ($warning[0] <= $un || $warning[1] <= $cinq || $warning[2] <= $quinze) {
$status = "WARNING";
}
if ($critical[0] <= $un || $critical[1] <= $cinq || $critical[2] <= $quinze) {
$status = "CRITICAL";
}
print "load average: ".$un.", ".$cinq.", ".$quinze.".|load1=".$un." load5=".$cinq." load15=".$quinze."\n";
exit $ERRORS{$status};
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " -c (--critical) Three critical tresholds (defaults : 2,4,6)\n";
print " -w (--warning) Three warning tresholds (defaults : 1,3,5)\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -k (--key) snmp V3 key\n";
print " -p (--password) snmp V3 password\n";
print " -u (--username) snmp v3 username \n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "######################################################\n";
print "# Copyright (c) 2004-2007 Oreon-project #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "######################################################\n";
print_usage();
print "\n";
}

View File

@ -1,210 +0,0 @@
#! /usr/bin/perl -w
###################################################################
# Oreon is developped with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
# Developped by : Julien Mathis - Romain Le Merlus
# Christophe Coraboeuf - Sugumaran Mathavarajan
#
###################################################################
# 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# For information : contact@merethis.com
####################################################################
#
# Script init
#
use strict;
use Net::SNMP qw(:snmp oid_lex_sort);
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_p $opt_H $opt_n $opt_k $opt_u $opt_x $result @result %process_list %STATUS);
# Plugin var init
my($proc, $proc_run);
$PROGNAME = $0;
sub print_help ();
sub print_usage ();
%STATUS=(1=>'running',2=>'runnable',3=>'notRunnable',4=>'invalid');
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"u=s" => \$opt_u, "username=s" => \$opt_u,
"x=s" => \$opt_x, "password=s" => \$opt_x,
"k=s" => \$opt_k, "key=s" => \$opt_k,
"V" => \$opt_V, "version" => \$opt_V,
"n" => \$opt_n, "number" => \$opt_n,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"p=s" => \$opt_p, "process=s" => \$opt_p,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
if (!$opt_H) {
print_usage();
exit $ERRORS{'OK'};
}
my $snmp = "1";
$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/);
if ($snmp eq "3") {
if (!$opt_u) {
print "Option -u (--username) is required for snmpV3\n";
exit $ERRORS{'OK'};
}
if (!$opt_x && !$opt_k) {
print "Option -k (--key) or -x (--password) is required for snmpV3\n";
exit $ERRORS{'OK'};
} elsif ($opt_x && $opt_k) {
print "Only option -k (--key) or -x (--password) is needed for snmpV3\n";
exit $ERRORS{'OK'};
}
}
$opt_C = "public" if (!$opt_C);
my $process;
if(!$opt_p) {
print_usage();
exit $ERRORS{'OK'};
} elsif ($opt_p !~ /([-.A-Za-z0-9]+)/){
print_usage();
exit $ERRORS{'OK'};
}
$process = $opt_p;
my $name = $0;
$name =~ s/\.pl.*//g;
# Plugin snmp requests
my $OID_SW_RunName = $oreon{MIB2}{SW_RUNNAME};
my $OID_SW_RunIndex =$oreon{MIB2}{SW_RUNINDEX};
my $OID_SW_RunStatus =$oreon{MIB2}{SW_RUNSTATUS};
my ($session, $error);
if ($snmp eq "1" || $snmp eq "2") {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
} elsif ($opt_k) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
} elsif ($opt_x) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_x);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}
$result = $session->get_table(Baseoid => $OID_SW_RunName);
if (!defined($result)) {
printf("UNKNOWN: %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
$proc = 0;
foreach my $key (oid_lex_sort(keys %$result)) {
my @oid_list = split (/\./,$key);
$process_list{$$result{$key}} = pop (@oid_list) ;
if (defined($opt_p) && $opt_p ne ""){
$proc++ if ($$result{$key} eq $opt_p);
} else {
$proc++;
}
}
if (!($opt_n)) {
if ($process_list{$process}) {
$result = $session->get_request(-varbindlist => [$OID_SW_RunStatus . "." . $process_list{$process}]);
if (!defined($result)) {
printf("UNKNOWN: %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
$proc_run = $result->{$OID_SW_RunStatus . "." . $process_list{$process} };
}
}
# Plugin return code
if ($opt_n){
print "Processes OK - Number of current processes: $proc|nbproc=$proc\n";
exit $ERRORS{'OK'};
} else {
if ($proc_run){
print "Process OK - $process: $STATUS{$proc_run}|procstatus=$proc_run\n";
exit $ERRORS{'OK'};
} else {
print "Process CRITICAL - $process not in 'running' state\n";
exit $ERRORS{'CRITICAL'};
}
}
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -n (--number) Return the number of current running processes. \n";
print " -p (--process) Set the process name ex: by default smbd\n";
print " -k (--key) snmp V3 key\n";
print " -x (--password) snmp V3 password\n";
print " -u (--username) snmp v3 username \n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "######################################################\n";
print "# Copyright (c) 2004-2007 Oreon-project #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "######################################################\n";
print_usage();
print "\n";
}

View File

@ -1,329 +0,0 @@
#! /usr/bin/perl -w
###################################################################
# Oreon is developped with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
# Developped by : Julien Mathis - Romain Le Merlus
# Christophe Coraboeuf - Sugumaran Mathavarajan
#
###################################################################
# 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# For information : contact@merethis.com
####################################################################
#
# Script init
#
use strict;
use Net::SNMP qw(:snmp);
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw(%oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $opt_f $opt_C $opt_d $opt_k $opt_u $opt_p $opt_n $opt_w $opt_c $opt_H $opt_s @test);
# Plugin var init
my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed);
my ($AllocationUnits, $Size, $Used);
my ($tot, $used, $pourcent, $return_code);
$PROGNAME = "$0";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"u=s" => \$opt_u, "username=s" => \$opt_u,
"p=s" => \$opt_p, "password=s" => \$opt_p,
"k=s" => \$opt_k, "key=s" => \$opt_k,
"V" => \$opt_V, "version" => \$opt_V,
"s" => \$opt_s, "show" => \$opt_s,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"d=s" => \$opt_d, "disk=s" => \$opt_d,
"f" => \$opt_f, "perfparse" => \$opt_f,
"n" => \$opt_n, "name" => \$opt_n,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
if (!$opt_H) {
print_usage();
exit $ERRORS{'OK'};
}
if ($opt_n && !$opt_d) {
print "Option -n (--name) need option -d (--disk)\n";
exit $ERRORS{'UNKNOWN'};
}
my $snmp = "1";
$snmp = $opt_v if ($opt_v && $opt_v =~ /^[0-9]$/);
if ($snmp eq "3") {
if (!$opt_u) {
print "Option -u (--username) is required for snmpV3\n";
exit $ERRORS{'OK'};
}
if (!$opt_p && !$opt_k) {
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
exit $ERRORS{'OK'};
} elsif ($opt_p && $opt_k) {
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
exit $ERRORS{'OK'};
}
}
$opt_C = "public" if (!$opt_C);
$opt_d = 2 if (!$opt_d);
($opt_d) || ($opt_d = shift) || ($opt_d = 2);
my $partition = 0;
if ($opt_d =~ /([0-9]+)/ && !$opt_n){
$partition = $1;
} elsif (!$opt_n){
print "Unknown -d number expected... or it doesn't exist, try another disk - number\n";
exit $ERRORS{'UNKNOWN'};
}
my $critical = 95;
if ($opt_c && $opt_c =~ /^[0-9]+$/) {
$critical = $opt_c;
}
my $warning = 90;
if ($opt_w && $opt_w =~ /^[0-9]+$/) {
$warning = $opt_w;
}
if ($critical <= $warning){
print "(--crit) must be superior to (--warn)";
print_usage();
exit $ERRORS{'OK'};
}
my $name = $0;
$name =~ s/\.pl.*//g;
# Plugin snmp requests
my $OID_hrStorageDescr =$oreon{MIB2}{HR_STORAGE_DESCR};
my $OID_hrStorageAllocationUnits =$oreon{MIB2}{HR_STORAGE_ALLOCATION_UNITS};
my $OID_hrStorageSize =$oreon{MIB2}{HR_STORAGE_SIZE};
my $OID_hrStorageUsed =$oreon{MIB2}{HR_STORAGE_USED};
# create a SNMP session
my ($session, $error);
if ($snmp eq "1" || $snmp eq "2") {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}elsif ($opt_k) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}elsif ($opt_p) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}
#getting partition using its name instead of its oid index
if ($opt_n) {
my $result = $session->get_table(Baseoid => $OID_hrStorageDescr);
if (!defined($result)) {
printf("ERROR: hrStorageDescr Table : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $expr = "";
if ($opt_d =~ m/^[A-Za-z]:/) {
$opt_d =~ s/\\/\\\\/g;
$expr = "^$opt_d";
}elsif ($opt_d =~ m/^\//) {
$expr = "$opt_d\$";
}else {
$expr = "$opt_d";
}
foreach my $key ( oid_lex_sort(keys %$result)) {
if ($result->{$key} =~ m/$expr/) {
my @oid_list = split (/\./,$key);
$partition = pop (@oid_list) ;
}
}
}
if ($opt_s) {
# Get description table
my $result = $session->get_table(
Baseoid => $OID_hrStorageDescr
);
if (!defined($result)) {
printf("ERROR: hrStorageDescr Table : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
foreach my $key ( oid_lex_sort(keys %$result)) {
my @oid_list = split (/\./,$key);
my $index = pop (@oid_list) ;
print "hrStorage $index :: $$result{$key}\n";
}
exit $ERRORS{'OK'};
}
my $result = $session->get_request(
-varbindlist => [$OID_hrStorageDescr.".".$partition ,
$OID_hrStorageAllocationUnits.".".$partition ,
$OID_hrStorageSize.".".$partition,
$OID_hrStorageUsed.".".$partition
]
);
if (!defined($result)) {
printf("ERROR: %s", $session->error);
if ($opt_n) { print(" - You must specify the disk name when option -n is used");}
print ".\n";
$session->close;
exit $ERRORS{'UNKNOWN'};
}
$hrStorageDescr = $result->{$OID_hrStorageDescr.".".$partition };
$AllocationUnits = $result->{$OID_hrStorageAllocationUnits.".".$partition };
$Size = $result->{$OID_hrStorageSize.".".$partition };
$Used = $result->{$OID_hrStorageUsed.".".$partition };
# Plugins var treatment
if (!$Size){
print "Disk CRITICAL - no output (-p number expected... it doesn't exist, try another disk - number\n";
exit $ERRORS{'CRITICAL'};
}
if (($Size =~ /([0-9]+)/) && ($AllocationUnits =~ /([0-9]+)/)){
if (!$Size){
print "The number of the option -p is not a hard drive\n";
exit $ERRORS{'CRITICAL'};
}
$tot = 1;
$tot = $Size * $AllocationUnits;
if (!$tot){$tot = 1;}
$used = $Used * $AllocationUnits;
$pourcent = ($used * 100) / $tot;
if (length($pourcent) > 2){
@test = split (/\./, $pourcent);
$pourcent = $test[0];
}
my $lastTot = $tot;
$tot = $tot / 1073741824;
$Used = ($Used * $AllocationUnits) / 1073741824;
# Plugin return code
if ($pourcent >= $critical){
print "Disk CRITICAL - ";
$return_code = 2;
} elsif ($pourcent >= $warning){
print "Disk WARNING - ";
$return_code = 1;
} else {
print "Disk OK - ";
$return_code = 0;
}
if ($hrStorageDescr){
print $hrStorageDescr . " TOTAL: ";
printf("%.3f", $tot);
print " Go USED: " . $pourcent . "% : ";
printf("%.3f", $Used);
print " Go";
if ($opt_f){
my $size_o = $Used * 1073741824;
my $warn = $opt_w * $size_o;
my $crit = $opt_c * $size_o;
print "|size=".$lastTot."o used=".$size_o.";".$warn.";".$crit;
}
print "\n";
exit $return_code;
} else {
print "TOTAL: ";
printf("%.3f", $tot);
print " Go USED: " . $pourcent . "% : ";
printf("%.3f", $Used);
print " Go\n";
exit $return_code;
}
} else {
print "Disk CRITICAL - no output (-d number expected... it doesn't exist, try another disk - number\n";
exit $ERRORS{'CRITICAL'};
}
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -d (--disk) Set the disk (number expected) ex: 1, 2,... (defaults to 2 )\n";
print " -n (--name) Allows to use disk name with option -d instead of disk oid index\n";
print " (ex: -d \"C:\" -n, -d \"E:\" -n, -d \"Swap Memory\" -n, -d \"Real Memory\" -n\n";
print " (choose an unique expression for each disk)\n";
print " -s (--show) Describes all disk (debug mode)\n";
print " -w (--warn) Signal strength at which a warning message will be generated\n";
print " (default 80)\n";
print " -c (--crit) Signal strength at which a critical message will be generated\n";
print " (default 95)\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "######################################################\n";
print "# Copyright (c) 2004-2007 Oreon-project #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "######################################################\n";
print_usage();
print "\n";
}

View File

@ -1,453 +0,0 @@
#! /usr/bin/perl -w
###################################################################
# Oreon is developped with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
# Developped by : Julien Mathis - Romain Le Merlus
# Christophe Coraboeuf - Sugumaran Mathavarajan
#
###################################################################
# 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# For information : contact@merethis.com
####################################################################
#
# Script init
#
use strict;
use Net::SNMP qw(:snmp oid_lex_sort);
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw(%oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_v $opt_C $opt_b $opt_k $opt_u $opt_p $opt_H $opt_D $opt_i $opt_n $opt_w $opt_c $opt_s $opt_T);
# Plugin var init
my($proc, $proc_run, @test, $row, @laste_values, $last_check_time, $last_in_bits, $last_out_bits, @last_values, $update_time, $db_file, $in_traffic, $out_traffic, $in_usage, $out_usage);
$PROGNAME = "$0";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"u=s" => \$opt_u, "username=s" => \$opt_u,
"p=s" => \$opt_p, "password=s" => \$opt_p,
"k=s" => \$opt_k, "key=s" => \$opt_k,
"s" => \$opt_s, "show" => \$opt_s,
"V" => \$opt_V, "version" => \$opt_V,
"i=s" => \$opt_i, "interface=s" => \$opt_i,
"n" => \$opt_n, "name" => \$opt_n,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"b=s" => \$opt_b, "bps=s" => \$opt_b,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"T=s" => \$opt_T,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
Getopt::Long::Configure('bundling');
}
##################################################
##### Verify Options
##
if (!$opt_H) {
print_usage();
exit $ERRORS{'OK'};
}
my $snmp = "1";
if ($opt_v && $opt_v =~ /^[0-9]$/) {
$snmp = $opt_v;
}
if ($snmp eq "3") {
if (!$opt_u) {
print "Option -u (--username) is required for snmpV3\n";
exit $ERRORS{'OK'};
}
if (!$opt_p && !$opt_k) {
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
exit $ERRORS{'OK'};
}elsif ($opt_p && $opt_k) {
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
exit $ERRORS{'OK'};
}
}
if ($opt_n && !$opt_i) {
print "Option -n (--name) need option -i (--interface)\n";
exit $ERRORS{'UNKNOWN'};
}
if (!$opt_C) {
$opt_C = "public";
}
if (!$opt_i) {
$opt_i = 2;
}
if (!$opt_b) {
$opt_b = 95;
}
if ($opt_b =~ /([0-9]+)/) {
my $bps = $1;
}
my $critical = 95;
if ($opt_c && $opt_c =~ /[0-9]+/) {
$critical = $opt_c;
}
my $warning = 80;
if ($opt_w && $opt_w =~ /[0-9]+/) {
$warning = $opt_w;
}
my $interface = 0;
if ($opt_i =~ /([0-9]+)/ && !$opt_n){
$interface = $1;
} elsif (!$opt_n) {
print "Unknown -i number expected... or it doesn't exist, try another interface - number\n";
exit $ERRORS{'UNKNOWN'};
}
if ($critical <= $warning){
print "(--crit) must be superior to (--warn)";
print_usage();
exit $ERRORS{'OK'};
}
#################################################
##### Plugin snmp requests
##
my $OID_DESC =$oreon{MIB2}{IF_DESC};
# create a SNMP session
my ($session, $error);
if ($snmp eq "1" || $snmp eq "2") {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}elsif ($opt_k) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}elsif ($opt_p) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}
#getting interface using its name instead of its oid index
if ($opt_n) {
my $result = $session->get_table(Baseoid => $OID_DESC);
if (!defined($result)) {
printf("ERROR: Description Table : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
foreach my $key ( oid_lex_sort(keys %$result)) {
if ($result->{$key} =~ m/$opt_i/) {
my @oid_list = split (/\./,$key);
$interface = pop (@oid_list) ;
}
}
}
my $OID_IN =$oreon{MIB2}{IF_IN_OCTET}.".".$interface;
my $OID_OUT = $oreon{MIB2}{IF_OUT_OCTET}.".".$interface;
my $OID_SPEED = $oreon{MIB2}{IF_SPEED}.".".$interface;
# Get desctiption table
if ($opt_s) {
my $result = $session->get_table(Baseoid => $OID_DESC);
if (!defined($result)) {
printf("ERROR: Description Table : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
foreach my $key ( oid_lex_sort(keys %$result)) {
my @oid_list = split (/\./,$key);
my $index = pop (@oid_list) ;
print "Interface $index :: $$result{$key}\n";
}
exit $ERRORS{'OK'};
}
####### Get IN bytes
my $in_bits;
my $result = $session->get_request(-varbindlist => [$OID_IN]);
if (!defined($result)) {
printf("ERROR: IN Bits : %s", $session->error);
if ($opt_n) { print " - You must specify interface name when option -n is used";}
print ".\n";
$session->close;
exit $ERRORS{'UNKNOWN'};
}
$in_bits = $result->{$OID_IN} * 8;
####### Get OUT bytes
my $out_bits;
$result = $session->get_request(-varbindlist => [$OID_OUT]);
if (!defined($result)) {
printf("ERROR: Out Bits : %s", $session->error);
if ($opt_n) { print " - You must specify interface name when option -n is used";}
print ".\n";
$session->close;
exit $ERRORS{'UNKNOWN'};
}
$out_bits = $result->{$OID_OUT} * 8;
####### Get SPEED of interface
my $speed_card;
$result = $session->get_request(-varbindlist => [$OID_SPEED]);
if (!defined($result)) {
printf("ERROR: Interface Speed : %s", $session->error);
if ($opt_n) { print " - You must specify interface name when option -n is used";}
print ".\n";
$session->close;
exit $ERRORS{'UNKNOWN'};
}
if (defined($opt_T)){
$speed_card = $opt_T * 1000000;
} else {
$speed_card = $result->{$OID_SPEED};
}
#############################################
##### Plugin return code
##
$last_in_bits = 0;
$last_out_bits = 0;
my $flg_created = 0;
if (-e "/tmp/oreon_traffic_if".$interface."_".$opt_H) {
open(FILE,"<"."/tmp/oreon_traffic_if".$interface."_".$opt_H);
while($row = <FILE>){
@last_values = split(":",$row);
$last_check_time = $last_values[0];
$last_in_bits = $last_values[1];
$last_out_bits = $last_values[2];
$flg_created = 1;
}
close(FILE);
} else {
$flg_created = 0;
}
$update_time = time();
unless (open(FILE,">"."/tmp/oreon_traffic_if".$interface."_".$opt_H)){
print "Unknown - /tmp/oreon_traffic_if".$interface."_".$opt_H. " !\n";
exit $ERRORS{"UNKNOWN"};
}
print FILE "$update_time:$in_bits:$out_bits";
close(FILE);
if ($flg_created == 0){
print "First execution : Buffer in creation.... \n";
exit($ERRORS{"UNKNOWN"});
}
## Bandwith = IN + OUT / Delta(T) = 6 Mb/s
## (100 * Bandwith) / (2(si full duplex) * Ispeed)
## Count must round at 4294967296
##
if (($in_bits - $last_in_bits > 0) && defined($last_in_bits)) {
my $total = 0;
if ($in_bits - $last_in_bits < 0){
$total = 4294967296 - $last_in_bits + $in_bits;
} else {
$total = $in_bits - $last_in_bits;
}
my $diff = time() - $last_check_time;
if ($diff == 0){$diff = 1;}
my $pct_in_traffic = $in_traffic = abs($total / $diff);
} else {
$in_traffic = 0;
}
if ($out_bits - $last_out_bits > 0 && defined($last_out_bits)) {
my $total = 0;
if ($out_bits - $last_out_bits < 0){
$total = 4294967296 - $last_out_bits + $out_bits;
} else {
$total = $out_bits - $last_out_bits;
}
my $diff = time() - $last_check_time;
if ($diff == 0){$diff = 1;}
my $pct_out_traffic = $out_traffic = abs($total / $diff);
} else {
$out_traffic = 0;
}
if ( $speed_card != 0 ) {
$in_usage = sprintf("%.1f",($in_traffic*100) / $speed_card);
$out_usage = sprintf("%.1f",($out_traffic*100) / $speed_card);
}
my $in_prefix = "";
my $out_prefix = "";
my $in_perfparse_traffic = $in_traffic;
my $out_perfparse_traffic = $out_traffic;
if ($in_traffic > 1000) {
$in_traffic = $in_traffic / 1000;
$in_prefix = "k";
if($in_traffic > 1000){
$in_traffic = $in_traffic / 1000;
$in_prefix = "M";
}
if($in_traffic > 1000){
$in_traffic = $in_traffic / 1000;
$in_prefix = "G";
}
}
if ($out_traffic > 1000){
$out_traffic = $out_traffic / 1000;
$out_prefix = "k";
if ($out_traffic > 1000){
$out_traffic = $out_traffic / 1000;
$out_prefix = "M";
}
if ($out_traffic > 1000){
$out_traffic = $out_traffic / 1000;
$out_prefix = "G";
}
}
my $in_bits_unit = "";
$in_bits = $in_bits/1048576;
if ($in_bits > 1000){
$in_bits = $in_bits / 1000;
$in_bits_unit = "G";
} else {
$in_bits_unit = "M";
}
my $out_bits_unit = "";
$out_bits = $out_bits/1048576;
if ($out_bits > 1000){
$out_bits = $out_bits / 1000;
$out_bits_unit = "G";
} else {
$out_bits_unit = "M";
}
if ( $speed_card == 0 ) {
print "CRITICAL: Interface speed equal 0! Interface must be down.|traffic_in=0B/s traffic_out=0B/s\n";
exit($ERRORS{"CRITICAL"});
}
#####################################
##### Display result
##
my $in_perfparse_traffic_str = sprintf("%.1f",abs($in_perfparse_traffic));
my $out_perfparse_traffic_str = sprintf("%.1f",abs($out_perfparse_traffic));
$in_perfparse_traffic_str =~ s/\./,/g;
$out_perfparse_traffic_str =~ s/\./,/g;
my $status = "OK";
if(($in_usage > $warning) or ($out_usage > $warning)){
$status = "WARNING";
}
if (($in_usage > $critical) or ($out_usage > $critical)){
$status = "CRITICAL";
}
printf("Traffic In : %.2f ".$in_prefix."b/s (".$in_usage." %%), Out : %.2f ".$out_prefix."b/s (".$out_usage." %%) - ", $in_traffic, $out_traffic);
printf("Total RX Bits In : %.2f ".$in_bits_unit."B, Out : %.2f ".$out_bits_unit."b", $in_bits, $out_bits);
printf("|traffic_in=".$in_perfparse_traffic_str."Bits/s traffic_out=".$out_perfparse_traffic_str."Bits/s\n");
exit($ERRORS{$status});
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -s (--show) Describes all interfaces number (debug mode)\n";
print " -i (--interface) Set the interface number (2 by default)\n";
print " -n (--name) Allows to use interface name with option -d instead of interface oid index\n";
print " (ex: -i \"eth0\" -n, -i \"VMware Virtual Ethernet Adapter for VMnet8\" -n\n";
print " (choose an unique expression for each interface)\n";
print " -w (--warn) Signal strength at which a warning message will be generated\n";
print " (default 80)\n";
print " -c (--crit) Signal strength at which a critical message will be generated\n";
print " -T Max Banwidth\n";
print " (default 95)\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "######################################################\n";
print "# Copyright (c) 2004-2007 Oreon-project #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "######################################################\n";
print_usage();
print "\n";
}

View File

@ -1,181 +0,0 @@
#! /usr/bin/perl -w
#
# $Id: check_graph_uptime.pl,v 1.3 2005/07/27 22:21:49 wistof Exp $
#
# This plugin is developped under GPL Licence:
# http://www.fsf.org/licenses/gpl.txt
# Developped by Linagora SA: http://www.linagora.com
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
# Modified For Oreon compatibility by Julien Mathis - Sugumaran mathavarajan For Merethis
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# LINAGORA makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the LINAGORA web site.
# In no event will LINAGORA be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if LINAGORA has
# been previously advised of the possibility of such damages.
# based on "graph plugins" developped by Oreon Team. See http://www.oreon.org.
##
## Plugin init
##
use strict;
use Net::SNMP qw(:snmp);
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_d $day);
$PROGNAME = $0;
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"V" => \$opt_V, "version" => \$opt_V,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"d" => \$opt_d, "day" => \$opt_d,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
($opt_v) || ($opt_v = shift) || ($opt_v = "1");
my $snmp = $1 if ($opt_v =~ /(\d)/);
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
my $start=time;
my $name = $0;
$name =~ s/\.pl.*//g;
my $day = 0;
##
## Plugin snmp requests
##
my $OID_OBJECTID =$oreon{MIB2}{OBJECTID};
my $OID_UPTIME_WINDOWS =$oreon{MIB2}{UPTIME_WINDOWS};
my $OID_UPTIME_OTHER =$oreon{MIB2}{UPTIME_OTHER};
# create a SNMP session
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
if ( !defined($session) ) {
print("CRITICAL: $error");
exit $ERRORS{'CRITICAL'};
}
my $result = $session->get_request(
-varbindlist => [$OID_OBJECTID]
);
if (!defined($result)) {
printf("UNKNOWN: %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $return_result = $result->{$OID_OBJECTID};
my $OID = "";
if ($return_result =~ /.*Windows.*/i ) {
$OID = $OID_UPTIME_WINDOWS;
} else {
$OID = $OID_UPTIME_OTHER;
}
$result = $session->get_request(
-varbindlist => [$OID]
);
if (!defined($result)) {
printf("UNKNOWN: %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $un = 0;
$return_result = $result->{$OID};
if ( $return_result =~ m/(\d*) day[s]?,\s*(\d*):(\d*):(\d*).(\d*)/ ) {
$un = $5 + $4 * 100 + $3 * 100 * 60 + $2 * 100 * 60 * 60 + $1 * 100 * 60 * 60 * 24;
$day = $1;
}
if ( $return_result =~ m/(\d*) hour.*(\d*):(\d*).(\d*)/ ) {
$un = $4 + $3 * 100 + $3 * 100 * 60 + $1 * 100 * 60 * 60 ;
}
if ($opt_d) {
$un = $day;
}
#print "un : $un\n";
##
## Plugin return code
##
if ($un || ( $un == 0) ){
if ($opt_d) {
print "OK - Uptime (in day): $un|uptime=".$un."hs\n";
} else {
print "OK - Uptime (in hundredths of a second): $un|uptime=".$un."hs\n";
}
exit $ERRORS{'OK'};
}
else{
print "CRITICAL Host unavailable\n";
exit $ERRORS{'CRITICAL'};
}
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -d (--day) Uptime in day\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "Copyright (c) 2005 Linagora\n";
print "Modified by Merethis \n";
print "Bugs to http://www.linagora.com/\n";
print "\n";
print_usage();
print "\n";
}

View File

@ -1,204 +0,0 @@
#! /usr/bin/perl -w
###################################################################
# Oreon is developped with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
# Developped by : Julien Mathis - Romain Le Merlus
# Christophe Coraboeuf - Sugumaran Mathavarajan
#
###################################################################
# 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# For information : contact@merethis.com
####################################################################
#
# Script init
#
use strict;
use Net::SNMP qw(:snmp);
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_h $opt_V $opt_H $opt_C $opt_v $opt_o $opt_c $opt_w $opt_t $opt_p $opt_k $opt_u);
$PROGNAME = $0;
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"u=s" => \$opt_u, "username=s" => \$opt_u,
"p=s" => \$opt_p, "password=s" => \$opt_p,
"k=s" => \$opt_k, "key=s" => \$opt_k,
"V" => \$opt_V, "version" => \$opt_V,
"v=s" => \$opt_v, "snmp=s" => \$opt_v,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"o=s" => \$opt_o, "oid=s" => \$opt_o,
"t=s" => \$opt_t, "type=s" => \$opt_t,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.0');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
my $snmp = "1";
if ($opt_v && $opt_v =~ /^[0-9]$/) {
$snmp = $opt_v;
}
if ($snmp eq "3") {
if (!$opt_u) {
print "Option -u (--username) is required for snmpV3\n";
exit $ERRORS{'OK'};
}
if (!$opt_p && !$opt_k) {
print "Option -k (--key) or -p (--password) is required for snmpV3\n";
exit $ERRORS{'OK'};
}elsif ($opt_p && $opt_k) {
print "Only option -k (--key) or -p (--password) is needed for snmpV3\n";
exit $ERRORS{'OK'};
}
}
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
my $DS_type = "GAUGE";
($opt_t) || ($opt_t = shift) || ($opt_t = "GAUGE");
$DS_type = $1 if ($opt_t =~ /(GAUGE)/ || $opt_t =~ /(COUNTER)/);
if (!$opt_c || !$opt_w) {
print "You must specify -c and -w options\n";
exit $ERRORS{'OK'};
}
($opt_c) || ($opt_c = shift);
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
($opt_w) || ($opt_w = shift);
my $warning = $1 if ($opt_w =~ /([0-9]+)/);
if ($critical <= $warning){
print "(--critical) must be superior to (--warning)";
print_usage();
exit $ERRORS{'OK'};
}
if (!$opt_o) {
print "Option -o needed.\n";
exit $ERRORS{'OK'};
}elsif (!($opt_o =~ /^[0-9\.]+$/)) {
print "Wrong OID format\n";
exit $ERRORS{'OK'};
}
my $name = $0;
$name =~ s/\.pl.*//g;
my $day = 0;
#=== create a SNMP session ====
my ($session, $error);
if ($snmp eq "1" || $snmp eq "2") {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -community => $opt_C, -version => $snmp);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}elsif ($opt_k) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authkey => $opt_k);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}elsif ($opt_p) {
($session, $error) = Net::SNMP->session(-hostname => $opt_H, -version => $snmp, -username => $opt_u, -authpassword => $opt_p);
if (!defined($session)) {
print("UNKNOWN: SNMP Session : $error\n");
exit $ERRORS{'UNKNOWN'};
}
}
my $result = $session->get_request(-varbindlist => [$opt_o]);
if (!defined($result)) {
printf("UNKNOWN: %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $return_result = $result->{$opt_o};
#=== Plugin return code ====
if (defined($return_result)){
if ($return_result !~ /^[0-9]$/) {
print "Snmp return value isn't numeric.\n";
exit $ERRORS{'OK'};
}
if ($opt_w && $opt_c && $return_result < $opt_w){
print "Ok value : " . $return_result . "|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";
exit $ERRORS{'OK'};
} elsif ($opt_w && $opt_c && $return_result >= $opt_w && $return_result < $opt_c){
print "Warning value : " . $return_result . "|value=$return_result;".$opt_w.";".$opt_c.";;\n";
exit $ERRORS{'WARNING'};
} elsif ($opt_w && $opt_c && $return_result >= $opt_c){
print "Critical value : " . $return_result."|value=".$return_result.";".$opt_w.";".$opt_c.";;\n";
exit $ERRORS{'CRITICAL'};
}
} else {
print "CRITICAL Host unavailable\n";
exit $ERRORS{'CRITICAL'};
}
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -t (--type) Data Source Type (GAUGE or COUNTER) (GAUGE by default)\n";
print " -o (--oid) OID to check\n";
print " -k (--key) snmp V3 key\n";
print " -p (--password) snmp V3 password\n";
print " -u (--username) snmp v3 username \n";
print " -w (--warning) Warning level\n";
print " -c (--critical) Critical level\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "######################################################\n";
print "# Copyright (c) 2004-2007 Oreon-project #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "######################################################\n";
print_usage();
print "\n";
}

View File

@ -1,406 +0,0 @@
#! /usr/bin/perl -w
#
# $Id: check_meta_service.pl,v 1.2 2005/07/27 22:21:49 Julio $
#
# Oreon's plugins are developped with GPL Licence :
# http://www.fsf.org/licenses/gpl.txt
# Developped by : Julien Mathis - Romain Le Merlus
#
# Developped by Julien Mathis for Merethis SARL
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
##
## Plugin init
##
use strict;
use DBI;
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_H $opt_h $opt_i);
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
## For Debug mode = 1
my $debug = 0;
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h,
"help" => \$opt_h,
"V" => \$opt_V,
"i=s" => \$opt_i);
###########################
## Set Database information
###########################
use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd);
require "@CENTREON_PATH@/ODS/etc/conf.pm";
my $dbh = DBI->connect("DBI:mysql:database=$mysql_database_oreon;host=$mysql_host",
"$mysql_user", "$mysql_passwd",
{'RaiseError' => 1});
my $dbh2 = DBI->connect("DBI:mysql:database=$mysql_database_ods;host=$mysql_host",
"$mysql_user", "$mysql_passwd",
{'RaiseError' => 1});
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 0.1 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
my $result;
my $warning;
my $critical;
my $metric_id;
sub return_value($$$){
my $sth_output = $dbh->prepare("SELECT meta_display FROM `meta_service`");
if (!$sth_output->execute) {die "Error:" . $sth_output->errstr . "\n";}
my $sth_output_data = $sth_output->fetchrow_hashref();
my $output = $sth_output_data->{'meta_display'};
if ($output) {
$output =~ s/\%d/$result/g;
}
if ($warning ne $critical){
if ($warning < $critical){ # Bon sens
if ($result < $warning){
if ($output) {
print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n";
}else {
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
}
exit $ERRORS{'OK'};
} elsif (($result >= $warning) && ($result < $critical)){
if ($output) {
print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n";
}else {
print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
}
exit $ERRORS{'WARNING'};
} elsif ($result >= $critical){
if ($output) {
print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n";
}else {
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
}
exit $ERRORS{'CRITICAL'};
}
} else { # sens inverse
if ($result < $critical){
if ($output) {
print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n";
}else {
print "CRITICAL result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
}
exit $ERRORS{'CRITICAL'};
} elsif ($result >= $critical && $result < $warning){
if ($output) {
print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n";
}else {
print "WARNING result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
}
exit $ERRORS{'WARNING'};
} elsif ($result >= $warning){
if ($output) {
print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n";
}else {
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
}
exit $ERRORS{'OK'};
} else{
if ($output) {
print $output. "|OMS=" . $result . ";".$warning.";".$critical."\n";
}else {
print "OK result : " . $result . "|OMS=" . $result . ";".$warning.";".$critical."\n";
}
exit $ERRORS{'OK'};
}
}
} else {
print "ERROR : warnig level = critical level";
exit $ERRORS{'CRITICAL'};
}
}
my $ref;
my $svc_id;
my $metric;
my $host_id;
## Get Value by metric Option
sub get_value_in_database_metric_id($$$$){
## Get last entry in perfparse database for this service
my $str = "SELECT value FROM data_bin WHERE id_metric = '".$metric_id."'";
if ($debug) {print $str . "\n";}
my $sth_deb2 = $dbh2->prepare($str);
if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";}
my $sth_deb2_data = $sth_deb2->fetchrow_hashref();
return $sth_deb2_data->{'value'};
}
## Get value For Regexp Options
sub get_value_in_database($$$$$){
my $str;
## Get hostname and service description for perfparse request
$str = "SELECT host_name,service_description FROM host,host_service_relation,service WHERE host.host_id = host_service_relation.host_host_id AND
service.service_id = host_service_relation.service_service_id AND service.service_id = '".$svc_id."'";
if ($debug) {print $str . "\n";}
my $host_data = $dbh->prepare($str);
if (!$host_data->execute) {die "Error:" . $host_data->errstr . "\n";}
my $data = $host_data->fetchrow_hashref();
## Get last entry in perfparse database for this service
my $sth_deb2 = $dbh2->prepare("SELECT value FROM metrics m, data_bin d, index_data i WHERE i.host_name = '".$data->{'host_name'}."' AND i.service_description = '".$data->{'service_description'}."' AND and m.index_id=i.id AND m.metric_id = d.id_metric AND m.metric_name = '".$metric."'");
if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";}
my $sth_deb2_data = $sth_deb2->fetchrow_hashref();
return $sth_deb2_data->{'value'};
}
sub get_value_in_database_by_host($$$$$){
my $str;
## Get hostname and service description for perfparse request
$str = "SELECT host_name,service_description FROM host,host_service_relation,service WHERE host.host_id = host_service_relation.host_host_id AND service.service_id = host_service_relation.service_service_id AND service.service_id = '".$svc_id."'";
if ($debug) {print $str . "\n";}
my $host_data = $dbh->prepare($str);
if (!$host_data->execute) {die "Error:" . $host_data->errstr . "\n";}
my $data = $host_data->fetchrow_hashref();
## Get last entry in perfparse database for this service
my $sth_deb2 = $dbh2->prepare("SELECT value FROM metrics m, data_bin d, index_data i WHERE i.host_name = '".$data->{'host_name'}."' AND i.service_description = '".$data->{'service_description'}."' AND m.index_id=i.id AND m.metric_id = d.id_metric AND m.metric_name = '".$metric."'");
if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";}
my $sth_deb2_data = $sth_deb2->fetchrow_hashref();
return $sth_deb2_data->{'value'};
}
sub get_value_in_database_by_hg($$$$$$){
my $str;
## Get hostname
$str = "SELECT host_name FROM host WHERE host.host_id = '".$host_id."'";
if ($debug) {print $str . "\n";}
my $hd = $dbh->prepare($str);
if (!$hd->execute) {die "Error:" . $hd->errstr . "\n";}
my $host_data = $hd->fetchrow_hashref();
## Get service description
$str = "SELECT service_description FROM service WHERE service.service_id = '".$svc_id."'";
if ($debug) {print $str . "\n";}
my $sd = $dbh->prepare($str);
if (!$sd->execute) {die "Error:" . $sd->errstr . "\n";}
my $service_data = $sd->fetchrow_hashref();
## Get last entry in perfparse database for this service
my $sth_deb2 = $dbh2->prepare("SELECT value FROM metrics m, data_bin d, index_data i WHERE i.host_name = '".$host_data->{'host_name'}."' AND i.service_description = '".$service_data->{'service_description'}."' AND m.index_id=i.id AND m.metric_id = d.id_metric AND m.metric_name = '".$metric."'");
if (!$sth_deb2->execute) {die "Error:" . $sth_deb2->errstr . "\n";}
my $sth_deb2_data = $sth_deb2->fetchrow_hashref();
return $sth_deb2_data->{'value'};
}
my $cpt = 0;
my $total = 0;
my $max = 0;
my $min = 999999999;
my $svc;
my $value = 0;
my $svc_relation2;
if ($opt_i){
my $str;
# get osl info
my $sth = $dbh->prepare("SELECT calcul_type,regexp_str,warning,critical,metric, meta_select_mode FROM meta_service WHERE meta_id = '".$opt_i."'");
if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";}
$ref = $sth->fetchrow_hashref();
if (!defined($ref->{'calcul_type'})){
print "Unvalidate Meta Service\n";
exit $ERRORS{'CRITICAL'};
}
$warning = $ref->{'warning'};
$critical = $ref->{'critical'};
# Get Service List by regexp
if ($ref->{'meta_select_mode'} eq '2'){
###############################################
$str = "SELECT service_id FROM service WHERE `service_description` LIKE '".$ref->{'regexp_str'}."' AND service_activate = '1' AND service_register = '1'";
if ($debug) {print $str . "\n";}
$sth = $dbh->prepare($str);
if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";}
while ($svc = $sth->fetchrow_hashref()){
my $sth2 = $dbh->prepare("SELECT * FROM host_service_relation WHERE service_service_id = '".$svc->{'service_id'}."'");
if (!$sth2->execute) {die "Error:" . $sth2->errstr . "\n";}
my $svc_relation = $sth2->fetchrow_hashref();
if (defined($svc_relation->{'host_host_id'}) && $svc_relation->{'host_host_id'}){
#### Par Host
if (defined($svc->{'service_id'})){$svc_id = $svc->{'service_id'};} else {$svc_id = $svc->{'svc_id'};}
if (defined($ref->{'regexp_str'})){$metric = $ref->{'metric'};} else {$metric = $svc->{'metric'};}
$value = get_value_in_database_by_host($dbh,$dbh2,$svc_id,$metric,$debug);
if ($ref->{'calcul_type'} =~ "AVE"){
if (defined($value) && $value){$total += $value;}
if ($debug) {print "total = " . $total . " value = ".$value."\n";}
$cpt++;
$result = $total / $cpt;
} elsif ($ref->{'calcul_type'} =~ "SOM"){
if ($value){$total += $value;}
if ($debug){print "total = " . $total . " value = ".$value."\n";}
$result = $total;
} elsif ($ref->{'calcul_type'} =~ "MIN"){
if ($debug){print " min : " . $min . " value = ".$value."\n";}
if ($value && $value <= $min){$min = $value;}
$result = $min;
} elsif ($ref->{'calcul_type'} =~ "MAX"){
if ($debug){print "max = " . $max . " value = ".$value."\n";}
if ($value && $value >= $max){$max = $value;}
$result = $max;
}
} elsif (defined($svc_relation->{'hostgroup_hg_id'}) && $svc_relation->{'hostgroup_hg_id'}) {
### Par Hostgroup
my $sth3 = $dbh->prepare("SELECT host_host_id FROM hostgroup_relation WHERE hostgroup_hg_id = '".$svc_relation->{'hostgroup_hg_id'}."'");
if (!$sth3->execute) {die "Error:" . $sth3->errstr . "\n";}
while ($svc_relation2 = $sth3->fetchrow_hashref()){
if (defined($svc->{'service_id'})){
$svc_id = $svc->{'service_id'};
} else {
$svc_id = $svc->{'svc_id'};
}
if (defined($ref->{'regexp_str'})){
$metric = $ref->{'metric'};
} else {
$metric = $svc->{'metric'};
}
$host_id = $svc_relation2->{'host_host_id'};
$value = get_value_in_database_by_hg($dbh,$dbh2,$svc_id, $host_id, $metric, $debug);
if ($ref->{'calcul_type'} =~ "AVE"){
if (defined($value) && $value){
$total += $value;
}
if ($debug) {print "total = " . $total . " value = ".$value."\n";}
$cpt++;
} elsif ($ref->{'calcul_type'} =~ "SOM"){
if ($value){
$total += $value;
}
if ($debug){print "total = " . $total . " value = ".$value."\n";}
} elsif ($ref->{'calcul_type'} =~ "MIN"){
if ($debug){print " min : " . $min . " value = ".$value."\n";}
if ($value && $value <= $min){
$min = $value;
}
} elsif ($ref->{'calcul_type'} =~ "MAX"){
if ($debug){print "max = " . $max . " value = ".$value."\n";}
if ($value && $value >= $max){
$max = $value;
}
}
}
if ($ref->{'calcul_type'} =~ "AVE"){
$result = $total / $cpt;
} elsif ($ref->{'calcul_type'} =~ "SOM"){
$result = $total;
} elsif ($ref->{'calcul_type'} =~ "MIN"){
$result = $min;
} elsif ($ref->{'calcul_type'} =~ "MAX"){
$result = $max;
}
}
}
return_value($result, $warning, $critical);
###############################################
} else {
$sth = $dbh->prepare("SELECT metric_id FROM `meta_service_relation` WHERE meta_id = '".$opt_i."'");
if (!$sth->execute) {die "Error:" . $sth->errstr . "\n";}
if ($ref->{'calcul_type'} =~ "AVE"){
if (!$sth->rows) {
print "no result in table meta_service_relation for id $opt_i\n";
exit $ERRORS{'UNKNOWN'};
}
while ($svc = $sth->fetchrow_hashref()){
if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};}
$value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug);
if (defined($value) && $value){$total += $value;}
$cpt++;
}
$result = $total / $cpt;
} elsif ($ref->{'calcul_type'} =~ "SOM"){
while ($svc = $sth->fetchrow_hashref()){
if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};}
$value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug);
if ($value){$total += $value;}
if ($debug){print "total = " . $total . " value = ".$value."\n";}
}
$result = $total;
} elsif ($ref->{'calcul_type'} =~ "MIN"){
while ($svc = $sth->fetchrow_hashref()){
if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};}
$value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug);
if ($debug){print " min : " . $min . " value = ".$value."\n";}
if ($value && $value <= $min){$min = $value;}
}
$result = $min;
} elsif ($ref->{'calcul_type'} =~ "MAX"){
while ($svc = $sth->fetchrow_hashref()){
if (defined($svc->{'metric_id'})){$metric_id = $svc->{'metric_id'};}
$value = get_value_in_database_metric_id($dbh,$dbh2,$metric_id,$debug);
if ($debug){print "max = " . $max . " value = ".$value."\n";}
if ($value && $value >= $max){$max = $value;}
}
$result = $max;
}
return_value($result, $warning, $critical);
}
}
sub print_usage () {
print "Usage:\n";
print " check_meta_service.pl\n";
print " -i Meta Service id\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help ()
{
print "###########################################\n";
print "# #\n";
print "# Copyright (c) 2004-2007 Merethis #\n";
print "# Bugs to http://www.oreon-services.com #\n";
print "# #\n";
print "###########################################\n";
print_usage();
print "\n";
}

View File

@ -1,344 +0,0 @@
#! /usr/bin/perl
#
# $Id: check_graph_nt.pl,v 1.3 2005/08/01 18:04:00 gollum123 Exp $
#
# Oreon's plugins are developped with GPL Licence :
# http://www.fsf.org/licenses/gpl.txt
# Developped by : Julien Mathis - Mathieu Mettre
# Under control of Flavien Astraud, Jerome Landrieu for Epitech.
# Oreon's plugins are developped in partnership with Linagora company.
#
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
## Plugin init
use strict;
use FindBin;
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_H $opt_p $opt_s $opt_v $opt_V $opt_h $opt_w $opt_c $opt_S $opt_g $opt_t $opt_l $opt_d $opt_D $opt_step $step $opt_f);
## Plugin var init
my $pathtolibexecnt = $oreon{GLOBAL}{NAGIOS_LIBEXEC}."check_nt";
my($op_v, $op_d, $op_s, $op_t, $op_l, $port, @values, @test, @test2, @test3, @test4, @test5, $warning, $critical, @w, @c, $uptime);
my($warning2, $critical2, $warning3, $critical3, $warning4, $critical4, @output);
$PROGNAME = $0;
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"p=s" => \$opt_p, "port=s" => \$opt_p,
"V" => \$opt_V, "version" => \$opt_V,
"s=s" => \$opt_s, "password=s" => \$opt_s,
"d=s" => \$opt_d, "showall=s" => \$opt_d,
"v=s" => \$opt_v, "variable=s" => \$opt_v,
"D=s" => \$opt_D, "directory=s" => \$opt_D,
"t=s" => \$opt_t, "timeout=s" => \$opt_t,
"l:s" => \$opt_l, "parameter:s" => \$opt_l,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"S=s" => \$opt_S, "ServiceId=s" => \$opt_S,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
if ($opt_V) {
$_ = `$pathtolibexecnt -V`;
print "$_";
exit $ERRORS{'OK'};
}
if ($opt_p) {
if ($opt_p =~ /([0-9]+)/){
$port = $1;
} else {
print "Unknown -p number expected... or it doesn't exist, try another port - number\n";
exit $ERRORS{'UNKNOWN'};
}
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
if ($opt_c) {
($opt_c) || ($opt_c = shift);
$critical = $1 if ($opt_c =~ /([0-9]+)/);
}
if ($opt_w) {
($opt_w) || ($opt_w = shift);
$warning = $1 if ($opt_w =~ /([0-9]+)/);
}
if (($critical && $warning) && ($critical <= $warning)) {
print "(--crit) must be superior to (--warn)";
print_usage();
exit $ERRORS{'OK'};
}
if ($opt_t) {
($opt_t) || ($opt_t = shift);
$op_t = $1 if ($opt_t =~ /([-\.,\w]+)/);
}
if ($opt_l) {
($opt_l) || ($opt_l = shift);
$op_l = $1 if ($opt_l =~ /(.+)/);
}
if ($opt_d) {
($opt_d) || ($opt_d = shift);
$op_d = $1 if ($opt_d =~ /([-.,A-Za-z0-9]+)/);
}
if ($opt_s) {
($opt_s) || ($opt_s = shift);
$op_s = $1 if ($opt_s =~ /([\_\-\.\,A-Za-z0-9]+)/);
}
if ($opt_v) {
($opt_v) || ($opt_v = shift);
$op_v = $1 if ($opt_v =~ /([-.,A-Za-z0-9]+)/);
}
my $name = $0;
$name =~ s/\.pl.*//g;
my $return_code;
## Plugin requests
my $start=time;
if ($op_v) {
if ($op_v) {$op_v = "-v ".$op_v;}
if ($port) {$port = "-p ".$port;} else { $port = " ";}
if ($warning) {$warning = "-w ".$warning;} else { $warning = " ";}
if ($critical) {$critical = "-c ".$critical;} else { $critical = " ";}
if ($op_l) {$op_l = "-l \"".$op_l ."\"";} else { $op_l = " ";}
if ($op_t) {$op_t = "-t ".$op_t;} else { $op_t = " ";}
if ($op_s) {$op_s = "-s ".$op_s;} else { $op_s = " ";}
if ($op_d) {$op_d = "-d ".$op_d;} else { $op_d = " ";}
# print "$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d\n";
$_ = `$pathtolibexecnt -H $opt_H $op_v $port $warning $critical $op_l $op_t $op_s $op_d `;
my $return = $_;
if (!defined($return) || $return eq "") {
print "Error in command, check your command options\n";
exit (3);
}
$return =~ s/\\//g;
$return_code = $? / 256;
## CLIENTVERSION
if ($op_v =~ /CLIENTVERSION/){
print "CLIENTVERSION impossible to Graph!\n";
exit $ERRORS{'UNKNOWN'};
}
if (($op_v =~ /CPULOAD/) && ($op_l =~ /([-\.,\w]+)/)){ ## CPULOAD
@output = split(/\|/,$_);
@values = $output[0] =~ /(\d*)\%/g ;
$start = time;
## Print Plugins Output
$return =~ s/\n//g;
my @return_data = split(/\|/,$return);
if (@values){
if (defined($opt_c) && defined($opt_w)){
print $return_data[0] . "|cpu=@values%;$opt_w;$opt_c\n";
} else {
print $return_data[0] . "|cpu=@values%\n";
}
} else {
print $return . "\n";
}
exit $return_code;
} elsif ($op_v =~ /UPTIME/){ ## UPTIME
if ($_ =~ /.*[-:]+\s(\d+)\s.*$/ ) {
$uptime = $1;
} else {
print "unable to parse check_nt output: $_\n" ;
exit $ERRORS{'UNKNOWN'};
}
$_ =~ s/\n/ /g;
if (defined($uptime)){
print $_ . "|uptime=".$uptime."d\n";
} else {
print $_ . "\n";
}
exit $return_code;
} elsif (($op_v =~ /USEDDISKSPACE/) && ($op_l =~ /([-\.,\w]+)/)){ ## USEDDISKSPACE
my @test = split(/ /,$_);
if (defined($test[9]) && defined($test2[1])){
@test2 = split(/\(/, $test[9]);
@test3 = split(/\%/, $test2[1]);
}
@c = split(/ /, $critical);
$critical = $c[1];
@w = split(/ /, $warning);
$warning = $w[1];
## Print Plugins Output
$return =~ s/\n/ /g;
my @return_part = split(/\|/, $return);
#$return =~ s/%/ pct/g;
## Put value in octets : Mo -> o
if (defined($test[3]) && defined($test[7]) && defined($test[12])){
$test[3] =~ s/\,/\./g;
$test[3] = eval($test[3] * 1024 * 1024 * 1024);
$test[7] =~ s/\,/\./g;
$test[7] = eval ($test[7] * 1024 * 1024 * 1024);
print $return_part[0] . "|total=".$test[3]."o used=".$test[7]."o\n";
} else {
print $return_part[0] . "\n";
}
exit $return_code;
} elsif ($op_v =~ /MEMUSE/){ ## MEMUSE
$start = time;
my @test = split(/ /,$_);
if (defined($test[2])){
@test4 = split(/:/, $test[2]);
}
@c = split(/ /, $critical);
$critical = $c[1];
@w = split(/ /, $warning);
$warning = $w[1];
## Print Plugins Output
my @return_data = split(/\|/,$return);
$return =~ s/\n/ /g;
#$return =~ s/%/ pct/g;
if ($test4[1] && $test[6] && $test[11]){
## Put value in octets : Mo -> o
$test4[1] =~ s/\,/\./g;
$test4[1] = eval($test4[1] * 1024 * 1024);
$test[6] =~ s/\,/\./g;
$test[6] = eval($test[6] * 1024 * 1024);
print $return_data[0] . "|total=".$test4[1]."o used=".$test[6]."o\n";
} else {
print $return_data[0] . "\n";
}
exit $return_code;
} elsif ($op_v =~ /SERVICESTATE/){## SERVICESTATE
my (@tab, $process, $nom, $etat);
@tab = split (' - ',$_);
foreach $process (@tab) {
($nom,$etat) = split (': ', $process);
if (defined($etat)) {
$etat =~ s/\n//;
} else {
$etat = "Unknown";
}
if ($etat =~ /Started/)
{$etat=1;}
elsif ($etat =~ /Stopped/)
{$etat=0;}
elsif ($etat =~ /Unknown/)
{$etat=-1;}
else {
print "Unable to get $nom status [$etat]: \n\t$_\n";
exit $ERRORS{'UNKNOWN'};
}
}
$return =~ s/%/ pct/g;
print $return;
exit $return_code;
} elsif ($op_v =~ /PROCSTATE/){## PROCSTATE
print "PROCSTATE not graphed\n";
exit $ERRORS{'UNKNOWN'};
} elsif (($op_v =~ /COUNTER/) && ($op_l =~ /(.+)/)) { ## COUNTER
@output = split(/\|/,$_);
@values = $output[0] =~ /([,\.\d]*)\s?\%/ ;
if (!@values) {@values = $output[0] =~ /([\d]*)/;}
$start=time;
## Print Plugins Output
$return =~ s/\n/ /g;
$return =~ s/%/ pct/g;
#print "---".$return ."---\n";
print $return . "|counter=".@values."\n";
exit $return_code;
}
} else {
print "Could not parse arguments\n";
exit $ERRORS{'UNKNOWN'};
}
##
## Plugin return code
##
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " Usage: check_graph_nt -H host -v variable [-p port] [-s password] [-w warning] [-c critical] [-l params] [-d SHOWALL] [-t timeout] [-D rrd directory] -g -S ServiceID\n";
print " Options:\n";
print " -H, --hostname=HOST\n";
print " Name of the host to check\n";
print " -p, --port=INTEGER\n";
print " Optional port number (default: 1248)\n";
print " -s <password>\n";
print " Password needed for the request\n";
print " -v, --variable=STRING\n";
print " Variable to check. Valid variables are:\n";
print " CLIENTVERSION = Not Graphed. Get the NSClient version\n";
print " CPULOAD = Average CPU load on last x minutes. Request a -l parameter with the following syntax:\n";
print " -l <minutes range>,<warning threshold>,<critical threshold>. <minute range> should be less than 24*60.\n";
print " Thresholds are percentage and up to 10 requests can be done in one shot. ie: -l 60,90,95,120,90,95\n";
print " and 4 requests can be graphed.\n";
print " UPTIME = Only Days are graphed. Get the uptime of the machine. No specific parameters. No warning or critical threshold.\n";
print " USEDDISKSPACE = Size and percentage of disk use. Request a -l parameter containing the drive letter only.\n";
print " Warning and critical thresholds can be specified with -w and -c.\n";
print " MEMUSE = Memory use. Warning and critical thresholds can be specified with -w and -c.\n";
print " SERVICESTATE = Check and graph the state of one service. Request a -l parameters with the following syntax:\n";
print " -l <service1>... You MUST specify -d SHOWALL in the input command.\n";
print " 1: Service Started - 0: Service Stopped - -1: Service Unknown.\n";
# print " SERVICESTATE = Not Graphed. Check the state of one or several services. Request a -l parameters with the following syntax:\n";
# print " -l <service1>,<service2>,<service3>,... You can specify -d SHOWALL in case you want to see working services\n";
# print " in the returned string.\n";
print " PROCSTATE = Not Graphed. Check if one or several process are running. Same syntax as SERVICESTATE.\n";
print " COUNTER = Check any performance counter of Windows NT/2000. Request a -l parameters with the following syntax:\n";
print " -l \"<performance object>counter\",\"<description>\" The <description> parameter is optional and\n";
print " is given to a printf output command which require a float parameters. Some examples:\n";
print " \"Paging file usage is %.2f %%\" or \"%.f %% paging file used.\"\n";
print " -w, --warning=INTEGER\n";
print " Threshold which will result in a warning status\n";
print " -c, --critical=INTEGER\n";
print " Threshold which will result in a critical status\n";
print " -t, --timeout=INTEGER\n";
print " Seconds before connection attempt times out (default: 10)\n";
print " -h, --help\n";
print " Print this help screen\n";
print " -V, --version\n";
print " Print version information\n";
}
sub print_help () {
print "Copyright (c) 2004 OREON\n";
print "Bugs to http://www.oreon.org/\n";
print "\n";
print_usage();
print "\n";
}

View File

@ -1,534 +0,0 @@
#!/usr/bin/perl -w
############################## check_snmp_cpfw ##############
# Version : 0.7
# Date : Oct 02 2004
# Author : Patrick Proy (patrick at proy.org)
# Help : http://www.manubulon.com/nagios/
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
# TODO :
# - check sync method
#################################################################
#
# Help : ./check_snmp_cpfw.pl -h
#
use strict;
use Net::SNMP;
use Getopt::Long;
# Nagios specific
use lib "@NAGIOS_PLUGINS@";
use utils qw(%ERRORS $TIMEOUT);
#my $TIMEOUT = 15;
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
# Oreon specific
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
########### SNMP Datas ###########
###### FW data
my $policy_state = "1.3.6.1.4.1.2620.1.1.1.0"; # "Installed"
my $policy_name = "1.3.6.1.4.1.2620.1.1.2.0"; # Installed policy name
my $connections = "1.3.6.1.4.1.2620.1.1.25.3.0"; # number of connections
#my $connections_peak = "1.3.6.1.4.1.2620.1.1.25.4.0"; # peak number of connections
my @fw_checks = ($policy_state,$policy_name,$connections);
###### SVN data
my $svn_status = "1.3.6.1.4.1.2620.1.6.102.0"; # "OK" svn status
my %svn_checks = ($svn_status,"OK");
my %svn_checks_n = ($svn_status,"SVN status");
my @svn_checks_oid = ($svn_status);
###### HA data
my $ha_active = "1.3.6.1.4.1.2620.1.5.5.0"; # "yes"
my $ha_state = "1.3.6.1.4.1.2620.1.5.6.0"; # "active"
my $ha_block_state = "1.3.6.1.4.1.2620.1.5.7.0"; #"OK" : ha blocking state
my $ha_status = "1.3.6.1.4.1.2620.1.5.102.0"; # "OK" : ha status
my %ha_checks =( $ha_active,"yes",$ha_state,"active",$ha_block_state,"OK",$ha_status,"OK");
my %ha_checks_n =( $ha_active,"HA active",$ha_state,"HA state",$ha_block_state,"HA block state",$ha_status,"ha_status");
my @ha_checks_oid =( $ha_active,$ha_state,$ha_block_state,$ha_status);
my $ha_mode = "1.3.6.1.4.1.2620.1.5.11.0"; # "Sync only" : ha Working mode
my $ha_tables = "1.3.6.1.4.1.2620.1.5.13.1"; # ha status table
my $ha_tables_index = ".1";
my $ha_tables_name = ".2";
my $ha_tables_state = ".3"; # "OK"
my $ha_tables_prbdesc = ".6"; # Description if state is != "OK"
#my @ha_table_check = ("Synchronization","Filter","cphad","fwd"); # process to check
####### MGMT data
my $mgmt_status = "1.3.6.1.4.1.2620.1.7.5.0"; # "active" : management status
my $mgmt_alive = "1.3.6.1.4.1.2620.1.7.6.0"; # 1 : management is alive if 1
my $mgmt_stat_desc = "1.3.6.1.4.1.2620.1.7.102.0"; # Management status description
my $mgmt_stats_desc_l = "1.3.6.1.4.1.2620.1.7.103.0"; # Management status long description
my %mgmt_checks = ($mgmt_status,"active",$mgmt_alive,"1");
my %mgmt_checks_n = ($mgmt_status,"Mgmt status",$mgmt_alive,"Mgmt alive");
my @mgmt_checks_oid = ($mgmt_status,$mgmt_alive);
#################################### Globals ##############################""
my $Version='0.7';
my $o_host = undef; # hostname
my $o_community = undef; # community
my $o_port = 161; # port
my $o_help= undef; # wan't some help ?
my $o_verb= undef; # verbose mode
my $o_version= undef; # print version
my $o_warn= undef; # Warning for connections
my $o_crit= undef; # Crit for connections
my $o_svn= undef; # Check for SVN status
my $o_fw= undef; # Check for FW status
my $o_ha= undef; # Check for HA status
my $o_mgmt= undef; # Check for management status
my $o_policy= undef; # Check for policy name
my $o_conn= undef; # Check for connexions
my $o_perf= undef; # Performance data output
# SNMPv3 specific
my $o_login= undef; # Login for snmpv3
my $o_passwd= undef; # Pass for snmpv3
# Oreon specific
my $o_step= undef;
my $o_g= undef;
my $o_S= undef;
my $step= undef;
my $rrd= undef;
my $start= undef;
my $ServiceId= undef;
my @rrd_data= undef;
# functions
sub p_version { print "check_snmp_cpfw version : $Version\n"; }
sub print_usage {
print "Usage: $0 [-v] -H <host> -C <snmp_community> | (-l login -x passwd) [-s] [-w [-p=pol_name] [-c=warn,crit]] [-m] [-a] [-f] [-p <port>] [-t <timeout>] [-V]\n";
}
sub isnnum { # Return true if arg is not a number
my $num = shift;
if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
return 1;
}
sub help {
print "\nSNMP Checkpoint FW-1 Monitor for Nagios version ",$Version,"\n";
print "(c)2004 - to my cat Ratoune\n\n";
print_usage();
print <<EOT;
-v, --verbose
print extra debugging information (including interface list on the system)
-h, --help
print this help message
-H, --hostname=HOST
name or IP address of host to check
-C, --community=COMMUNITY NAME
community name for the host's SNMP agent (implies v1 protocol)
-s, --svn
check for svn status
-w, --fw
check for fw status
-a, --ha
check for ha status
-m, --mgmt
check for management status
-p, --policy=POLICY_NAME
check if installed policy is POLICY_NAME (must have -w)
-c, --connexions=WARN,CRIT
check warn and critical number of connexions (must have -w)
-f, --perfparse
perfparse output (only works with -c)
-l, --login=LOGIN
Login for snmpv3 authentication (implies v3 protocol with MD5)
-x, --passwd=PASSWD
Password for snmpv3 authentication
-P, --port=PORT
SNMP port (Default 161)
-t, --timeout=INTEGER
timeout for SNMP (Default: Nagios default)
-V, --version
prints version number
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
-S (--ServiceId) Oreon Service Id
EOT
}
# For verbose output
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
sub check_options {
Getopt::Long::Configure ("bundling");
GetOptions(
'v' => \$o_verb, 'verbose' => \$o_verb,
'h' => \$o_help, 'help' => \$o_help,
'H:s' => \$o_host, 'hostname:s' => \$o_host,
'P:i' => \$o_port, 'port:i' => \$o_port,
'C:s' => \$o_community, 'community:s' => \$o_community,
'l:s' => \$o_login, 'login:s' => \$o_login,
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
't:i' => \$TIMEOUT, 'timeout:i' => \$TIMEOUT,
'V' => \$o_version, 'version' => \$o_version,
's' => \$o_svn, 'svn' => \$o_svn,
'w' => \$o_fw, 'fw' => \$o_fw,
'a' => \$o_ha, 'ha' => \$o_ha,
'm' => \$o_mgmt, 'mgmt' => \$o_mgmt,
'p:s' => \$o_policy, 'policy:s' => \$o_policy,
'c:s' => \$o_conn, 'connexions:s' => \$o_conn,
'f' => \$o_perf, 'perfparse' => \$o_perf,
# For Oreon rrdtool graph
"rrd_step:s" => \$o_step,
"g" => \$o_g, "rrdgraph" => \$o_g,
"S=s" => \$o_S, "ServiceId=s" => \$o_S
);
if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
if ( ! defined($o_host) ) # check host and filter
{ print_usage(); exit $ERRORS{"UNKNOWN"}}
# check snmp information
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
# Check firewall options
if ( defined($o_conn)) {
if ( ! defined($o_fw))
{ print "Cannot check connexions without checking fw\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
my @warncrit=split(/,/ , $o_conn);
if ( $#warncrit != 1 )
{ print "Put warn,crit levels with -c option\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
($o_warn,$o_crit)=@warncrit;
if ( isnnum($o_warn) || isnnum($o_crit) )
{ print "Numeric values for warning and critical in -c options\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
if ($o_warn >= $o_crit)
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
}
if ( defined($o_policy)) {
if (! defined($o_fw))
{ print "Cannot check policy name without checking fw\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
if ($o_policy eq "")
{ print "Put a policy name !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
}
if (defined($o_perf) && ! defined ($o_conn))
{ print "Nothing selected for perfparse !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
if (!defined($o_fw) && !defined($o_ha) && !defined($o_mgmt) && !defined($o_svn))
{ print "Must select a product to check !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
###### Oreon #######
if (!defined($o_S)) { $o_S="1_1" }
$ServiceId = is_valid_serviceid($o_S);
if (!defined($o_step)) { $o_step="300" }
$step = $1 if ($o_step =~ /(\d+)/);
}
########## MAIN #######
check_options();
$rrd = $pathtorrdbase.$ServiceId.".rrd";
$start=time;
# Check gobal timeout if snmp screws up
alarm($TIMEOUT+15);
# Connect to host
my ($session,$error);
if ( defined($o_login) && defined($o_passwd)) {
# SNMPv3 login
verb("SNMPv3 login");
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => '3',
-username => $o_login,
-authpassword => $o_passwd,
-authprotocol => 'md5',
-privpassword => $o_passwd
);
} else {
# SNMPV1 login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-community => $o_community,
-port => $o_port,
-timeout => $TIMEOUT
);
}
if (!defined($session)) {
printf("ERROR opening session: %s.\n", $error);
exit $ERRORS{"UNKNOWN"};
}
########### Global checks #################
my $global_status=0; # global status : 0=OK, 1=Warn, 2=Crit
my ($resultat,$key)=(undef,undef);
########## Check SVN status #############
my $svn_print="";
my $svn_state=0;
if (defined ($o_svn)) {
$resultat = $session->get_request(
Varbindlist => \@svn_checks_oid
);
if (defined($resultat)) {
foreach $key ( keys %svn_checks) {
verb("$svn_checks_n{$key} : $svn_checks{$key} / $$resultat{$key}");
if ( $$resultat{$key} ne $svn_checks{$key} ) {
$svn_print .= $svn_checks_n{$key} . ":" . $$resultat{$key} . " ";
$svn_state=2;
}
}
} else {
$svn_print .= "cannot find oids";
#Critical state if not found because it means soft is not activated
$svn_state=2;
}
if ($svn_state == 0) {
$svn_print="SVN : OK";
} else {
$svn_print="SVN : " . $svn_print;
}
verb("$svn_print");
}
########## Check mgmt status #############
my $mgmt_state=0;
my $mgmt_print="";
if (defined ($o_mgmt)) {
# Check all states
$resultat=undef;
$resultat = $session->get_request(
Varbindlist => \@mgmt_checks_oid
);
if (defined($resultat)) {
foreach $key ( keys %mgmt_checks) {
verb("$mgmt_checks_n{$key} : $mgmt_checks{$key} / $$resultat{$key}");
if ( $$resultat{$key} ne $mgmt_checks{$key} ) {
$mgmt_print .= $mgmt_checks_n{$key} . ":" . $$resultat{$key} . " ";
$mgmt_state=2;
}
}
} else {
$mgmt_print .= "cannot find oids";
#Critical state if not found because it means soft is not activated
$mgmt_state=2;
}
if ($mgmt_state == 0) {
$mgmt_print="MGMT : OK";
} else {
$mgmt_print="MGMT : " . $mgmt_print;
}
verb("$svn_print");
}
########### Check fw status ##############
my $fw_state=0;
my $fw_print="";
my $perf_conn=undef;
if (defined ($o_fw)) {
# Check all states
$resultat = $session->get_request(
Varbindlist => \@fw_checks
);
if (defined($resultat)) {
verb("State : $$resultat{$policy_state}");
verb("Name : $$resultat{$policy_name}");
verb("connections : $$resultat{$connections}");
if ($$resultat{$policy_state} ne "Installed") {
$fw_state=2;
$fw_print .= "Policy:". $$resultat{$policy_state}." ";
verb("Policy state not installed");
}
if (defined($o_policy)) {
if ($$resultat{$policy_name} ne $o_policy) {
$fw_state=2;
$fw_print .= "Policy installed : $$resultat{$policy_name}";
}
}
if (defined($o_conn)) {
if ($$resultat{$connections} > $o_crit) {
$fw_state=2;
$fw_print .= "Connexions : ".$$resultat{$connections}." > ".$o_crit." ";
} else {
if ($$resultat{$connections} > $o_warn) {
$fw_state=1;
$fw_print .= "Connexions : ".$$resultat{$connections}." > ".$o_warn." ";
}
}
$perf_conn=$$resultat{$connections};
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,1,$start,$step,0,"U","GAUGE");
}
update_rrd($rrd,$start, $perf_conn);
}
}
} else {
$fw_print .= "cannot find oids";
#Critical state if not found because it means soft is not activated
$fw_state=2;
}
if ($fw_state==0) {
$fw_print="FW : OK";
} else {
$fw_print="FW : " . $fw_print;
}
}
########### Check ha status ##############
my $ha_state_n=0;
my $ha_print="";
if (defined ($o_ha)) {
# Check all states
$resultat = $session->get_request(
Varbindlist => \@ha_checks_oid
);
if (defined($resultat)) {
foreach $key ( keys %ha_checks) {
verb("$ha_checks_n{$key} : $ha_checks{$key} / $$resultat{$key}");
if ( $$resultat{$key} ne $ha_checks{$key} ) {
$ha_print .= $ha_checks_n{$key} . ":" . $$resultat{$key} . " ";
$ha_state_n=2;
}
}
#my $ha_mode = "1.3.6.1.4.1.2620.1.5.11.0"; # "Sync only" : ha Working mode
} else {
$ha_print .= "cannot find oids";
#Critical state if not found because it means soft is not activated
$ha_state_n=2;
}
# get ha status table
$resultat = $session->get_table(
Baseoid => $ha_tables
);
my %status;
my (@index,@oid) = (undef,undef);
my $nindex=0;
my $index_search= $ha_tables . $ha_tables_index;
if (defined($resultat)) {
foreach $key ( keys %$resultat) {
if ( $key =~ /$index_search/) {
@oid=split (/\./,$key);
pop(@oid);
$index[$nindex]=pop(@oid);
$nindex++;
}
}
} else {
$ha_print .= "cannot find oids" if ($ha_state_n ==0);
#Critical state if not found because it means soft is not activated
$ha_state_n=2;
}
verb ("found $nindex ha softs");
if ( $nindex == 0 )
{
$ha_print .= " no ha soft found" if ($ha_state_n ==0);
$ha_state_n=2;
} else {
my $ha_soft_name=undef;
for (my $i=0;$i<$nindex;$i++) {
$key=$ha_tables . $ha_tables_name . "." . $index[$i] . ".0";
$ha_soft_name= $$resultat{$key};
$key=$ha_tables . $ha_tables_state . "." . $index[$i] . ".0";
if (($status{$ha_soft_name} = $$resultat{$key}) ne "OK") {
$key=$ha_tables . $ha_tables_prbdesc . "." . $index[$i] . ".0";
$status{$ha_soft_name} = $$resultat{$key};
$ha_print .= $ha_soft_name . ":" . $status{$ha_soft_name} . " ";
$ha_state_n=2
}
verb ("$ha_soft_name : $status{$ha_soft_name}");
}
}
if ($ha_state_n == 0) {
$ha_print = "HA : OK";
} else {
$ha_print = "HA : " . $ha_print;
}
}
$session->close;
########## print results and exit
my $f_print=undef;
if (defined ($o_fw)) { $f_print = $fw_print }
if (defined ($o_svn)) { $f_print = (defined ($f_print)) ? $f_print . " / ". $svn_print : $svn_print }
if (defined ($o_ha)) { $f_print = (defined ($f_print)) ? $f_print . " / ". $ha_print : $ha_print }
if (defined ($o_mgmt)) { $f_print = (defined ($f_print)) ? $f_print . " / ". $mgmt_print : $mgmt_print }
my $exit_status=undef;
$f_print .= " / CPFW Status : ";
if (($ha_state_n+$svn_state+$fw_state+$mgmt_state) == 0 ) {
$f_print .= "OK";
$exit_status= $ERRORS{"OK"};
} else {
if (($fw_state==1) || ($ha_state_n==1) || ($svn_state==1) || ($mgmt_state==1)) {
$f_print .= "WARNING";
$exit_status= $ERRORS{"WARNING"};
} else {
$f_print .= "CRITICAL";
$exit_status=$ERRORS{"CRITICAL"};
}
}
if (defined($o_perf) && defined ($perf_conn)) {
$f_print .= " | fw_connexions=" . $perf_conn;
}
print "$f_print\n";
exit $exit_status;

View File

@ -1,593 +0,0 @@
#!/usr/bin/perl -w
############################## check_snmp_load #################
# Version : 1.2 / BETA
# Date : Aug 27 2005
# Author : Patrick Proy ( patrick at proy.org)
# Help : http://www.manubulon.com/nagios/
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
# Changelog : HP Procurve
# TODO :
#################################################################
#
# Help : ./check_snmp_load.pl -h
#
use strict;
use Net::SNMP;
use Getopt::Long;
# Nagios specific
use lib "@NAGIOS_PLUGINS@";
use utils qw(%ERRORS $TIMEOUT);
#my $TIMEOUT = 15;
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
# Oreon specific
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
# SNMP Datas
# Generic with host-ressource-mib
my $base_proc = "1.3.6.1.2.1.25.3.3.1"; # oid for all proc info
my $proc_id = "1.3.6.1.2.1.25.3.3.1.1"; # list of processors (product ID)
my $proc_load = "1.3.6.1.2.1.25.3.3.1.2"; # %time the proc was not idle over last minute
# Linux load
my $linload_table= "1.3.6.1.4.1.2021.10.1"; # net-snmp load table
my $linload_name = "1.3.6.1.4.1.2021.10.1.2"; # text 'Load-1','Load-5', 'Load-15'
my $linload_load = "1.3.6.1.4.1.2021.10.1.3"; # effective load table
# Cisco cpu/load
my $cisco_cpu_5m = "1.3.6.1.4.1.9.2.1.58.0"; # Cisco CPU load (5min %)
my $cisco_cpu_1m = "1.3.6.1.4.1.9.2.1.57.0"; # Cisco CPU load (1min %)
my $cisco_cpu_5s = "1.3.6.1.4.1.9.2.1.56.0"; # Cisco CPU load (5sec %)
# AS/400 CPU
my $as400_cpu = "1.3.6.1.4.1.2.6.4.5.1.0"; # AS400 CPU load (10000=100%);
# Net-SNMP CPU
my $ns_cpu_idle = "1.3.6.1.4.1.2021.11.11.0"; # Net-snmp cpu idle
my $ns_cpu_user = "1.3.6.1.4.1.2021.11.9.0"; # Net-snmp user cpu usage
my $ns_cpu_system = "1.3.6.1.4.1.2021.11.10.0"; # Net-snmp system cpu usage
# Procurve CPU
my $procurve_cpu = "1.3.6.1.4.1.11.2.14.11.5.1.9.6.1.0"; # Procurve CPU Counter
# Nokia CPU
my $nokia_cpu = "1.3.6.1.4.1.94.1.21.1.7.1.0"; # Nokia CPU % usage
# Bluecoat Appliance
my $bluecoat_cpu = "1.3.6.1.4.1.3417.2.4.1.1.1.4.1"; # Bluecoat %cpu usage.
# Linkproof Appliance
my $linkproof_cpu= "1.3.6.1.4.1.89.35.1.53.0"; # Ressource utilisation (%) Considers network utilization and internal CPU utilization
# 1.3.6.1.4.1.89.35.1.54 : CPU only (%)
# 1.3.6.1.4.1.89.35.1.55 : network only (%)
# CPU OID array
my %cpu_oid = ("netsc",$ns_cpu_idle,"as400",$as400_cpu,"bc",$bluecoat_cpu,"nokia",$nokia_cpu,"hp",$procurve_cpu,"lp",$linkproof_cpu);
# Globals
my $Version='1.2';
my $o_host = undef; # hostname
my $o_community = undef; # community
my $o_port = 161; # port
my $o_help= undef; # wan't some help ?
my $o_verb= undef; # verbose mode
my $o_version= undef; # print version
my $o_check_type= "stand"; # check type : stand | netsc | netsl | as400 | cisco | bc | nokia | hp | lp
# For backward compatibility
my $o_linux= undef; # Check linux load instead of CPU
my $o_linuxC= undef; # Check Net-SNMP CPU
my $o_as400= undef; # Check for AS 400 load
my $o_cisco= undef; # Check for Cisco CPU
# End compatibility
my $o_warn= undef; # warning level
my @o_warnL= undef; # warning levels for Linux Load or Cisco CPU
my $o_crit= undef; # critical level
my @o_critL= undef; # critical level for Linux Load or Cisco CPU
my $o_timeout= 5; # Default 5s Timeout
my $o_perf= undef; # Output performance data
my $o_version2= undef; # use snmp v2c
# SNMPv3 specific
my $o_login= undef; # Login for snmpv3
my $o_passwd= undef; # Pass for snmpv3
# Oreon specific
my $o_step= undef;
my $o_g= undef;
my $o_S= undef;
my $step= undef;
my $rrd= undef;
my $start= undef;
my $ServiceId= undef;
# functions
sub p_version { print "check_snmp_load version : $Version\n"; }
sub print_usage {
print "Usage: $0 [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-p <port>] -w <warn level> -c <crit level> -T=[stand|netsl|netsc|as400|cisco|bc|nokia|hp|lp] [-f] [-t <timeout>] [-V]\n";
}
sub isnnum { # Return true if arg is not a number
my $num = shift;
if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
return 1;
}
sub help {
print "\nSNMP Load & CPU Monitor for Nagios version ",$Version,"\n";
print "(c)2004 to my cat Ratoune - Author : Patrick Proy\n\n";
print_usage();
print <<EOT;
-v, --verbose
print extra debugging information
-h, --help
print this help message
-H, --hostname=HOST
name or IP address of host to check
-C, --community=COMMUNITY NAME
community name for the host's SNMP agent (implies v1 protocol)
-2, --v2c
Use snmp v2c
-l, --login=LOGIN
Login for snmpv3 authentication (implies v3 protocol with MD5)
-x, --passwd=PASSWD
Password for snmpv3 authentication
-P, --port=PORT
SNMP port (Default 161)
-w, --warn=INTEGER | INT,INT,INT
warning level for cpu in percent (on one minute)
if -L switch then comma separated level for load-1,load-5,load-15
if -I switch then comma separated level for cpu 5s,cpu 1m,cpu 5m
-c, --crit=INTEGER | INT,INT,INT
critical level for cpu in percent (on one minute)
if -L switch then comma separated level for load-1,load-5,load-15
if -I switch then comma separated level for cpu 5s,cpu 1m,cpu 5m
-T, --type=stand|netsl|netsc|as400|cisco|bc|nokia|hp|lp
CPU check :
stand : standard MIBII (works with Windows),
can handle multiple CPU.
netsl : check linux load provided by Net SNMP
netsc : check cpu usage given by net-snmp (100-idle)
as400 : check as400 CPU usage
cisco : check cisco CPU usage
bc : check bluecoat CPU usage
nokia : check nokia CPU usage
hp : check HP procurve switch CPU usage
lp : Linkproof CPU usage
-f, --perfparse
Perfparse compatible output
-t, --timeout=INTEGER
timeout for SNMP in seconds (Default: 5)
-V, --version
prints version number
-L, --linux, -A, --as400, -I, --cisco, -N, --netsnmp
These options are for backward compatibility (version<1.2)
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
-S (--ServiceId) Oreon Service Id
EOT
}
# For verbose output
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
sub check_options {
Getopt::Long::Configure ("bundling");
GetOptions(
'v' => \$o_verb, 'verbose' => \$o_verb,
'h' => \$o_help, 'help' => \$o_help,
'H:s' => \$o_host, 'hostname:s' => \$o_host,
'p:i' => \$o_port, 'port:i' => \$o_port,
'C:s' => \$o_community, 'community:s' => \$o_community,
'l:s' => \$o_login, 'login:s' => \$o_login,
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
'V' => \$o_version, 'version' => \$o_version,
'2' => \$o_version2, 'v2c' => \$o_version2,
'c:s' => \$o_crit, 'critical:s' => \$o_crit,
'w:s' => \$o_warn, 'warn:s' => \$o_warn,
'f' => \$o_perf, 'perfparse' => \$o_perf,
'T:s' => \$o_check_type, 'type:s' => \$o_check_type,
# For backward compatibility
'L' => \$o_linux, 'linux' => \$o_linux,
'A' => \$o_as400, 'as400' => \$o_as400,
'I' => \$o_cisco, 'cisco' => \$o_cisco,
'N' => \$o_linuxC, 'netsnmp' => \$o_linuxC,
# For Oreon rrdtool graph
"rrd_step:s" => \$o_step,
"g" => \$o_g, "rrdgraph" => \$o_g,
"S=s" => \$o_S, "ServiceId=s" => \$o_S
);
# For backward compat
if (defined($o_linux)) { $o_check_type="netsl" }
if (defined($o_linuxC)) { $o_check_type="netsc" }
if (defined($o_as400)) { $o_check_type="as400"}
if (defined($o_cisco)) { $o_check_type="cisco"}
# TODO : check the -T option
if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
if ( ! defined($o_host) ) # check host and filter
{ print_usage(); exit $ERRORS{"UNKNOWN"}}
# check snmp information
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
# Check warnings and critical
if (!defined($o_warn) || !defined($o_crit))
{ print "put warning and critical info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
# Get rid of % sign
$o_warn =~ s/\%//g;
$o_crit =~ s/\%//g;
# Check for multiple warning and crit in case of -L
if (($o_warn =~ /,/) || ($o_crit =~ /,/)) {
if (($o_check_type ne "netsl") && ($o_check_type ne "cisco")) { print "Multiple warning without -L or -I switch\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
@o_warnL=split(/,/ , $o_warn);
@o_critL=split(/,/ , $o_crit);
if (($#o_warnL != 2) || ($#o_critL != 2))
{ print "3 warnings and critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
for (my $i=0;$i<3;$i++) {
if ( isnnum($o_warnL[$i]) || isnnum($o_critL[$i]))
{ print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
if ($o_warnL[$i] > $o_critL[$i])
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
}
} else {
if (($o_check_type eq "netsl") || ($o_check_type eq "cisco")) { print "Multiple warn and crit levels needed with -L or -I switch\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
if ( isnnum($o_warn) || isnnum($o_crit) )
{ print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
if ($o_warn > $o_crit)
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
}
###### Oreon #######
if (!defined($o_S)) { $o_S="1_1" }
$ServiceId = is_valid_serviceid($o_S);
if (!defined($o_step)) { $o_step="300" }
$step = $1 if ($o_step =~ /(\d+)/);
}
########## MAIN #######
check_options();
$rrd = $pathtorrdbase.$ServiceId.".rrd";
$start=time;
# Check gobal timeout if snmp screws up
if (defined($TIMEOUT)) {
verb("Alarm at $TIMEOUT + 5");
alarm($TIMEOUT+5);
} else {
verb("no timeout defined : $o_timeout + 10");
alarm ($o_timeout+10);
}
# Connect to host
my ($session,$error);
if ( defined($o_login) && defined($o_passwd)) {
# SNMPv3 login
verb("SNMPv3 login");
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => '3',
-username => $o_login,
-authpassword => $o_passwd,
-authprotocol => 'md5',
-privpassword => $o_passwd,
-timeout => $o_timeout
);
} else {
if (defined ($o_version2)) {
# SNMPv2 Login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => 2,
-community => $o_community,
-port => $o_port,
-timeout => $o_timeout
);
} else {
# SNMPV1 login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-community => $o_community,
-port => $o_port,
-timeout => $o_timeout
);
}
}
if (!defined($session)) {
printf("ERROR opening session: %s.\n", $error);
exit $ERRORS{"UNKNOWN"};
}
my $exit_val=undef;
########### Linux load check ##############
if ($o_check_type eq "netsl") {
verb("Checking linux load");
# Get load table
my $resultat = (Net::SNMP->VERSION < 4) ?
$session->get_table($linload_table)
: $session->get_table(Baseoid => $linload_table);
if (!defined($resultat)) {
printf("ERROR: Description table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
$session->close;
my @load = undef;
my @iload = undef;
my @oid=undef;
foreach my $key ( keys %$resultat) {
verb("OID : $key, Desc : $$resultat{$key}");
if ( $key =~ /$linload_name/ ) {
@oid=split (/\./,$key);
$iload[0]= pop(@oid) if ($$resultat{$key} eq "Load-1");
$iload[1]= pop(@oid) if ($$resultat{$key} eq "Load-5");
$iload[2]= pop(@oid) if ($$resultat{$key} eq "Load-15");
}
}
for (my $i=0;$i<3;$i++) { $load[$i] = $$resultat{$linload_load . "." . $iload[$i]}};
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,3,$start,$step,0,"U","GAUGE");
}
update_rrd($rrd,$start, $load[0] ,$load[1], $load[2]);
}
print "Load : $load[0] $load[1] $load[2] :";
$exit_val=$ERRORS{"OK"};
for (my $i=0;$i<3;$i++) {
if ( $load[$i] > $o_critL[$i] ) {
print " $load[$i] > $o_critL[$i] : CRITICAL";
$exit_val=$ERRORS{"CRITICAL"};
}
if ( $load[$i] > $o_warnL[$i] ) {
# output warn error only if no critical was found
if ($exit_val eq $ERRORS{"OK"}) {
print " $load[$i] > $o_warnL[$i] : WARNING";
$exit_val=$ERRORS{"WARNING"};
}
}
}
print " OK" if ($exit_val eq $ERRORS{"OK"});
if (defined($o_perf)) {
print " | load_1_min=$load[0];$o_warnL[0];$o_critL[0],";
print "load_5_min=$load[1];$o_warnL[1];$o_critL[1],";
print "load_15_min=$load[2];$o_warnL[2];$o_critL[2]\n";
} else {
print "\n";
}
exit $exit_val;
}
############## Cisco CPU check ################
if ($o_check_type eq "cisco") {
my @oidlists = ($cisco_cpu_5m, $cisco_cpu_1m, $cisco_cpu_5s);
my $resultat = (Net::SNMP->VERSION < 4) ?
$session->get_request(@oidlists)
: $session->get_request(-varbindlist => \@oidlists);
if (!defined($resultat)) {
printf("ERROR: Description table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
$session->close;
if (!defined ($$resultat{$cisco_cpu_5s})) {
print "No CPU information : UNKNOWN\n";
exit $ERRORS{"UNKNOWN"};
}
my @load = undef;
$load[0]=$$resultat{$cisco_cpu_5s};
$load[1]=$$resultat{$cisco_cpu_1m};
$load[2]=$$resultat{$cisco_cpu_5m};
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,3,$start,$step,0,"U","GAUGE");
}
update_rrd($rrd,$start,$load[0] ,$load[1], $load[2]);
}
print "CPU : $load[0] $load[1] $load[2] :";
$exit_val=$ERRORS{"OK"};
for (my $i=0;$i<3;$i++) {
if ( $load[$i] > $o_critL[$i] ) {
print " $load[$i] > $o_critL[$i] : CRITICAL";
$exit_val=$ERRORS{"CRITICAL"};
}
if ( $load[$i] > $o_warnL[$i] ) {
# output warn error only if no critical was found
if ($exit_val eq $ERRORS{"OK"}) {
print " $load[$i] > $o_warnL[$i] : WARNING";
$exit_val=$ERRORS{"WARNING"};
}
}
}
print " OK" if ($exit_val eq $ERRORS{"OK"});
if (defined($o_perf)) {
print " | load_5_sec=$load[0]%;$o_warnL[0];$o_critL[0],";
print "load_1_min=$load[1]%;$o_warnL[1];$o_critL[1],";
print "load_5_min=$load[2]%;$o_warnL[2];$o_critL[2]\n";
} else {
print "\n";
}
exit $exit_val;
}
################## CPU for : AS/400 , Netsnmp, HP, Bluecoat, linkproof ###########
if ( $o_check_type =~ /netsc|as400|bc|nokia|hp|lp/ ) {
# Get load table
my @oidlist = $cpu_oid{$o_check_type};
verb("Checking OID : @oidlist");
my $resultat = (Net::SNMP->VERSION < 4) ?
$session->get_request(@oidlist)
: $session->get_request(-varbindlist => \@oidlist);
if (!defined($resultat)) {
printf("ERROR: Description table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
$session->close;
if (!defined ($$resultat{$cpu_oid{$o_check_type}})) {
print "No CPU information : UNKNOWN\n";
exit $ERRORS{"UNKNOWN"};
}
my $load=$$resultat{$cpu_oid{$o_check_type}};
verb("OID returned $load");
# for AS400, divide by 100
if ($o_check_type eq "as400") {$load /= 100; };
# for Net-snmp : oid returned idle time so load = 100-idle.
if ($o_check_type eq "netsc") {$load = 100 - $load; };
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,1,$start,$step,0,"U","GAUGE");
}
update_rrd($rrd,$start,$load);
}
printf("CPU used %.1f%% (",$load);
$exit_val=$ERRORS{"OK"};
if ($load > $o_crit) {
print ">$o_crit) : CRITICAL";
$exit_val=$ERRORS{"CRITICAL"};
} else {
if ($load > $o_warn) {
print ">$o_warn) : WARNING";
$exit_val=$ERRORS{"WARNING"};
}
}
print "<$o_warn) : OK" if ($exit_val eq $ERRORS{"OK"});
(defined($o_perf)) ?
print " | cpu_prct_used=$load%;$o_warn;$o_crit\n"
: print "\n";
exit $exit_val;
}
########## Standard cpu usage check ############
# Get desctiption table
my $resultat = (Net::SNMP->VERSION < 4) ?
$session->get_table($base_proc)
: $session->get_table(Baseoid => $base_proc);
if (!defined($resultat)) {
printf("ERROR: Description table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
$session->close;
my ($cpu_used,$ncpu)=(0,0);
foreach my $key ( keys %$resultat) {
verb("OID : $key, Desc : $$resultat{$key}");
if ( $key =~ /$proc_load/) {
$cpu_used += $$resultat{$key};
$ncpu++;
}
}
if ($ncpu==0) {
print "Can't find CPU usage information : UNKNOWN\n";
exit $ERRORS{"UNKNOWN"};
}
$cpu_used /= $ncpu;
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,1,$start,$step,0,"U","GAUGE");
}
update_rrd($rrd,$start,$cpu_used);
}
print "$ncpu CPU, ", $ncpu==1 ? "load" : "average load";
printf(" %.1f",$cpu_used);
$exit_val=$ERRORS{"OK"};
if ($cpu_used > $o_crit) {
print " > $o_crit : CRITICAL";
$exit_val=$ERRORS{"CRITICAL"};
} else {
if ($cpu_used > $o_warn) {
print " > $o_warn : WARNING";
$exit_val=$ERRORS{"WARNING"};
}
}
print " < $o_warn : OK" if ($exit_val eq $ERRORS{"OK"});
(defined($o_perf)) ?
print " | cpu_prct_used=$cpu_used%;$o_warn;$o_crit\n"
: print "\n";
exit $exit_val;

View File

@ -1,542 +0,0 @@
#!/usr/bin/perl -w
############################## check_snmp_mem ##############
# Version : 0.9
# Date : Jul 20 2005
# Author : Patrick Proy (patrick at proy.org)
# Help : http://www.manubulon.com/nagios/
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
# TODO : snmpv3
#################################################################
#
# Help : ./check_snmp_mem.pl -h
#
use strict;
use Net::SNMP;
use Getopt::Long;
# Nagios specific
use lib "@NAGIOS_PLUGINS@";
use utils qw(%ERRORS $TIMEOUT);
#my $TIMEOUT = 15;
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
# Oreon specific
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
# SNMP Datas
# Net-snmp memory
my $nets_ram_free = "1.3.6.1.4.1.2021.4.6.0"; # Real memory free
my $nets_ram_total = "1.3.6.1.4.1.2021.4.5.0"; # Real memory total
my $nets_swap_free = "1.3.6.1.4.1.2021.4.4.0"; # swap memory free
my $nets_swap_total = "1.3.6.1.4.1.2021.4.3.0"; # Swap memory total
my @nets_oids = ($nets_ram_free,$nets_ram_total,$nets_swap_free,$nets_swap_total);
# Cisco
my $cisco_mem_pool = "1.3.6.1.4.1.9.9.48.1.1.1"; # Cisco memory pool
my $cisco_index = "1.3.6.1.4.1.9.9.48.1.1.1.2"; # memory pool name and index
my $cisco_valid = "1.3.6.1.4.1.9.9.48.1.1.1.4"; # Valid memory if 1
my $cisco_used = "1.3.6.1.4.1.9.9.48.1.1.1.5"; # Used memory
my $cisco_free = "1.3.6.1.4.1.9.9.48.1.1.1.6"; # Used memory
# .1 : type, .2 : name, .3 : alternate, .4 : valid, .5 : used, .6 : free, .7 : max free
# HP Procurve
my $hp_mem_pool = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1"; # HP memory pool
my $hp_mem_index = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.1"; # memory slot index
my $hp_mem_total = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.5"; # Total Bytes
my $hp_mem_free = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.6"; # Free Bytes
my $hp_mem_free_seg = "1.3.6.1.4.1.11.2.14.11.5.1.1.2.2.1.1.3"; # Free segments
# AS/400
# Windows NT/2K/(XP?)
# check_snmp_storage.pl -C <community> -H <hostIP> -m "^Virtual Memory$" -w <warn %> -c <crit %>
# Globals
my $Version='0.9';
my $o_host = undef; # hostname
my $o_community = undef; # community
my $o_port = 161; # port
my $o_help= undef; # wan't some help ?
my $o_verb= undef; # verbose mode
my $o_version= undef; # print version
my $o_netsnmp= 1; # Check with netsnmp (default)
my $o_cisco= undef; # Check cisco router mem
my $o_hp= undef; # Check hp procurve mem
my $o_warn= undef; # warning level option
my $o_warnR= undef; # warning level for Real memory
my $o_warnS= undef; # warning levels for swap
my $o_crit= undef; # Critical level option
my $o_critR= undef; # critical level for Real memory
my $o_critS= undef; # critical level for swap
my $o_perf= undef; # Performance data option
my $o_timeout= 5; # Default 5s Timeout
my $o_version2= undef; # use snmp v2c
# SNMPv3 specific
my $o_login= undef; # Login for snmpv3
my $o_passwd= undef; # Pass for snmpv3
# Oreon specific
my $o_step= undef;
my $o_g= undef;
my $o_S= undef;
my $step= undef;
my $rrd= undef;
my $start= undef;
my $ServiceId= undef;
# functions
sub p_version { print "check_snmp_mem version : $Version\n"; }
sub print_usage {
print "Usage: $0 [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-p <port>] -w <warn level> -c <crit level> [-I|-N|-E] [-f] [-t <timeout>] [-V]\n";
}
sub isnnum { # Return true if arg is not a number
my $num = shift;
if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
return 1;
}
sub round ($$) {
sprintf "%.$_[1]f", $_[0];
}
sub help {
print "\nSNMP Memory Monitor for Nagios version ",$Version,"\n";
print "(c)2004 to my cat Ratoune - Author: Patrick Proy\n\n";
print_usage();
print <<EOT;
-v, --verbose
print extra debugging information (including interface list on the system)
-h, --help
print this help message
-H, --hostname=HOST
name or IP address of host to check
-C, --community=COMMUNITY NAME
community name for the host's SNMP agent (implies SNMP v1 or v2c with option)
-2, --v2c
Use snmp v2c
-l, --login=LOGIN
Login for snmpv3 authentication (implies v3 protocol with MD5)
-x, --passwd=PASSWD
Password for snmpv3 authentication
-P, --port=PORT
SNMP port (Default 161)
-w, --warn=INTEGER | INT,INT
warning level for memory in percent (0 for no checks)
Default (-N switch) : comma separated level for Real Memory and Swap
-I switch : warning level
-c, --crit=INTEGER | INT,INT
critical level for memory in percent (0 for no checks)
Default (-N switch) : comma separated level for Real Memory and Swap
-I switch : critical level
-N, --netsnmp (default)
check linux memory & swap provided by Net SNMP
-I, --cisco
check cisco memory (sum of all memory pools)
-E, --hp
check HP proccurve memory
-f, --perfdata
Performance data output
-t, --timeout=INTEGER
timeout for SNMP in seconds (Default: 5)
-V, --version
prints version number
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
-S (--ServiceId) Oreon Service Id
EOT
}
# For verbose output
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
# Get the alarm signal (just in case snmp timout screws up)
$SIG{'ALRM'} = sub {
print ("ERROR: Alarm signal (Nagios time-out)\n");
exit $ERRORS{"UNKNOWN"};
};
sub check_options {
Getopt::Long::Configure ("bundling");
GetOptions(
'v' => \$o_verb, 'verbose' => \$o_verb,
'h' => \$o_help, 'help' => \$o_help,
'H:s' => \$o_host, 'hostname:s' => \$o_host,
'p:i' => \$o_port, 'port:i' => \$o_port,
'C:s' => \$o_community, 'community:s' => \$o_community,
'l:s' => \$o_login, 'login:s' => \$o_login,
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
'V' => \$o_version, 'version' => \$o_version,
'I' => \$o_cisco, 'cisco' => \$o_cisco,
'N' => \$o_netsnmp, 'netsnmp' => \$o_netsnmp,
'E' => \$o_hp, 'hp' => \$o_hp,
'2' => \$o_version2, 'v2c' => \$o_version2,
'c:s' => \$o_crit, 'critical:s' => \$o_crit,
'w:s' => \$o_warn, 'warn:s' => \$o_warn,
'f' => \$o_perf, 'perfdata' => \$o_perf,
# For Oreon rrdtool graph
"rrd_step:s" => \$o_step,
"g" => \$o_g, "rrdgraph" => \$o_g,
"S=s" => \$o_S, "ServiceId=s" => \$o_S
);
if (defined ($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
if ( ! defined($o_host) ) # check host and filter
{ print "No host defined!\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
# check snmp information
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
#Check Warning and crit are present
if ( ! defined($o_warn) || ! defined($o_crit))
{ print "Put warning and critical values!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
# Get rid of % sign
$o_warn =~ s/\%//g;
$o_crit =~ s/\%//g;
# if -N or -E switch , undef $o_netsnmp
if (defined($o_cisco) || defined($o_hp) ) {
$o_netsnmp=undef;
if ( isnnum($o_warn) || isnnum($o_crit))
{ print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"} }
if ( ($o_crit != 0) && ($o_warn > $o_crit) )
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
}
if (defined($o_netsnmp)) {
my @o_warnL=split(/,/ , $o_warn);
my @o_critL=split(/,/ , $o_crit);
if (($#o_warnL != 1) || ($#o_critL != 1))
{ print "2 warnings and critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
for (my $i=0;$i<2;$i++) {
if ( isnnum($o_warnL[$i]) || isnnum($o_critL[$i]))
{ print "Numeric value for warning or critical !\n";print_usage(); exit $ERRORS{"UNKNOWN"} }
if (($o_critL[$i]!= 0) && ($o_warnL[$i] > $o_critL[$i]))
{ print "warning <= critical ! \n";print_usage(); exit $ERRORS{"UNKNOWN"}}
if ( $o_critL[$i] > 100)
{ print "critical percent must be < 100 !\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
}
$o_warnR=$o_warnL[0];$o_warnS=$o_warnL[1];
$o_critR=$o_critL[0];$o_critS=$o_critL[1];
}
###### Oreon #######
if (!defined($o_S)) { $o_S="1_1" }
$ServiceId = is_valid_serviceid($o_S);
if (!defined($o_step)) { $o_step="300" }
$step = $1 if ($o_step =~ /(\d+)/);
}
########## MAIN #######
check_options();
$rrd = $pathtorrdbase.$ServiceId.".rrd";
$start=time;
# Check gobal timeout if snmp screws up
if (defined($TIMEOUT)) {
verb("Alarm at $TIMEOUT");
alarm($TIMEOUT);
} else {
verb("no timeout defined : $o_timeout + 10");
alarm ($o_timeout+10);
}
# Connect to host
my ($session,$error);
if ( defined($o_login) && defined($o_passwd)) {
# SNMPv3 login
verb("SNMPv3 login");
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => '3',
-username => $o_login,
-authpassword => $o_passwd,
-authprotocol => 'md5',
-privpassword => $o_passwd,
-timeout => $o_timeout
);
} else {
if (defined ($o_version2)) {
# SNMPv2 Login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => 2,
-community => $o_community,
-port => $o_port,
-timeout => $o_timeout
);
} else {
# SNMPV1 login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-community => $o_community,
-port => $o_port,
-timeout => $o_timeout
);
}
}
if (!defined($session)) {
printf("ERROR opening session: %s.\n", $error);
exit $ERRORS{"UNKNOWN"};
}
# Global variable
my $resultat=undef;
########### Cisco memory check ############
if (defined ($o_cisco)) {
# Get Cisco memory table
$resultat = (Net::SNMP->VERSION < 4) ?
$session->get_table($cisco_mem_pool)
:$session->get_table(Baseoid => $cisco_mem_pool);
if (!defined($resultat)) {
printf("ERROR: Description table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
my (@oid,@index)=(undef,undef);
my $nindex=0;
foreach my $key ( keys %$resultat) {
verb("OID : $key, Desc : $$resultat{$key}");
if ( $key =~ /$cisco_index/ ) {
@oid=split (/\./,$key);
$index[$nindex++] = pop(@oid);
}
}
# Check if at least 1 memory pool exists
if ($nindex == 0) {
printf("ERROR: No memory pools found");
$session->close;
exit $ERRORS{"UNKNOWN"};
}
# Consolidate the datas
my ($used,$free)=(0,0);
my ($c_output,$prct_free)=(undef,undef);
foreach (@index) {
if ( $$resultat{$cisco_valid . "." . $_} == 1 ) {
$c_output .="," if defined ($c_output);
$used += $$resultat{$cisco_used . "." . $_};
$free += $$resultat{$cisco_free . "." . $_};
$c_output .= $$resultat{$cisco_index . "." . $_} . ":"
.round($$resultat{$cisco_used . "." . $_}*100/($$resultat{$cisco_free . "." . $_}+$$resultat{$cisco_used . "." . $_}) ,0)
. "%";
}
}
my $total=$used+$free;
$prct_free=round($used*100/($total),0);
verb("Used : $used, Free: $free, Output : $c_output");
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,1,$start,$step,0,100,"GAUGE");
}
update_rrd($rrd,$start,$prct_free);
}
my $c_status="OK";
$c_output .=" : " . $prct_free ."% : ";
if (($o_crit!=0)&&($o_crit <= $prct_free)) {
$c_output .= " > " . $o_crit ;
$c_status="CRITICAL";
} else {
if (($o_warn!=0)&&($o_warn <= $prct_free)) {
$c_output.=" > " . $o_warn;
$c_status="WARNING";
}
}
$c_output .= " ; ".$c_status;
if (defined ($o_perf)) {
$c_output .= " | ram_used=" . $used.";";
$c_output .= ($o_warn ==0)? ";" : round($o_warn * $total/100,0).";";
$c_output .= ($o_crit ==0)? ";" : round($o_crit * $total/100,0).";";
$c_output .= "0;" . $total ;
}
$session->close;
print "$c_output \n";
exit $ERRORS{$c_status};
}
########### HP Procurve memory check ############
if (defined ($o_hp)) {
# Get hp memory table
$resultat = (Net::SNMP->VERSION < 4) ?
$session->get_table($hp_mem_pool)
:$session->get_table(Baseoid => $hp_mem_pool);
if (!defined($resultat)) {
printf("ERROR: Description table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
my (@oid,@index)=(undef,undef);
my $nindex=0;
foreach my $key ( keys %$resultat) {
verb("OID : $key, Desc : $$resultat{$key}");
if ( $key =~ /$hp_mem_index/ ) {
@oid=split (/\./,$key);
$index[$nindex++] = pop(@oid);
}
}
# Check if at least 1 memory slots exists
if ($nindex == 0) {
printf("ERROR: No memory slots found");
$session->close;
exit $ERRORS{"UNKNOWN"};
}
# Consolidate the datas
my ($total,$free)=(0,0);
my ($c_output,$prct_free)=(undef,undef);
foreach (@index) {
$c_output .="," if defined ($c_output);
$total += $$resultat{$hp_mem_total . "." . $_};
$free += $$resultat{$hp_mem_free . "." . $_};
$c_output .= "Slot " . $$resultat{$hp_mem_index . "." . $_} . ":"
.round(
100 - ($$resultat{$hp_mem_free . "." . $_} *100 /
$$resultat{$hp_mem_total . "." . $_}) ,0)
. "%";
}
my $used = $total - $free;
$prct_free=round($used*100/($total),0);
verb("Used : $used, Free: $free, Output : $c_output");
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,1,$start,$step,0,100,"GAUGE");
}
update_rrd($rrd,$start,$prct_free);
}
my $c_status="OK";
$c_output .=" : " . $prct_free ."% : ";
if (($o_crit!=0)&&($o_crit <= $prct_free)) {
$c_output .= " > " . $o_crit ;
$c_status="CRITICAL";
} else {
if (($o_warn!=0)&&($o_warn <= $prct_free)) {
$c_output.=" > " . $o_warn;
$c_status="WARNING";
}
}
$c_output .= " ; ".$c_status;
if (defined ($o_perf)) {
$c_output .= " | ram_used=" . $used.";";
$c_output .= ($o_warn ==0)? ";" : round($o_warn * $total/100,0).";";
$c_output .= ($o_crit ==0)? ";" : round($o_crit * $total/100,0).";";
$c_output .= "0;" . $total ;
}
$session->close;
print "$c_output \n";
exit $ERRORS{$c_status};
}
########### Net snmp memory check ############
if (defined ($o_netsnmp)) {
# Get NetSNMP memory values
$resultat = (Net::SNMP->VERSION < 4) ?
$session->get_request(@nets_oids)
:$session->get_request(-varbindlist => \@nets_oids);
if (!defined($resultat)) {
printf("ERROR: netsnmp : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
my ($realused,$swapused)=(undef,undef);
$realused= ($$resultat{$nets_ram_total} == 0) ? 0 :
($$resultat{$nets_ram_total}-$$resultat{$nets_ram_free})/$$resultat{$nets_ram_total};
$swapused= ($$resultat{$nets_swap_total} == 0) ? 0 :
($$resultat{$nets_swap_total}-$$resultat{$nets_swap_free})/$$resultat{$nets_swap_total};
$realused=round($realused*100,0);
$swapused=round($swapused*100,0);
verb ("Ram : $$resultat{$nets_ram_free} / $$resultat{$nets_ram_total} : $realused");
verb ("Swap : $$resultat{$nets_swap_free} / $$resultat{$nets_swap_total} : $swapused");
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,2,$start,$step,0,100,"GAUGE");
}
update_rrd($rrd,$start,$realused, $swapused );
}
my $n_status="OK";
my $n_output="Ram : " . $realused . "%, Swap : " . $swapused . "% :";
if ((($o_critR!=0)&&($o_critR <= $realused)) || (($o_critS!=0)&&($o_critS <= $swapused))) {
$n_output .= " > " . $o_critR . ", " . $o_critS;
$n_status="CRITICAL";
} else {
if ((($o_warnR!=0)&&($o_warnR <= $realused)) || (($o_warnS!=0)&&($o_warnS <= $swapused))) {
$n_output.=" > " . $o_warnR . ", " . $o_warnS;
$n_status="WARNING";
}
}
$n_output .= " ; ".$n_status;
if (defined ($o_perf)) {
$n_output .= " | ram_used=" . ($$resultat{$nets_ram_total}-$$resultat{$nets_ram_free}).";";
$n_output .= ($o_warnR ==0)? ";" : round($o_warnR * $$resultat{$nets_ram_total}/100,0).";";
$n_output .= ($o_critR ==0)? ";" : round($o_critR * $$resultat{$nets_ram_total}/100,0).";";
$n_output .= "0;" . $$resultat{$nets_ram_total}. " ";
$n_output .= "swap_used=" . ($$resultat{$nets_swap_total}-$$resultat{$nets_swap_free}).";";
$n_output .= ($o_warnS ==0)? ";" : round($o_warnS * $$resultat{$nets_swap_total}/100,0).";";
$n_output .= ($o_critS ==0)? ";" : round($o_critS * $$resultat{$nets_swap_total}/100,0).";";
$n_output .= "0;" . $$resultat{$nets_swap_total};
}
$session->close;
print "$n_output \n";
exit $ERRORS{$n_status};
}

View File

@ -1,602 +0,0 @@
#!/usr/bin/perl -w
############################## check_snmp_process ##############
# Version : 1.2.1
# Date : Dec 12 2004
# Author : Patrick Proy (patrick at proy.org)
# Help : http://www.manubulon.com/nagios/
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
# TODO : put $o_delta as an option
###############################################################
#
# help : ./check_snmp_process -h
############### BASE DIRECTORY FOR TEMP FILE ########
my $o_base_dir="/tmp/tmp_Nagios_proc.";
my $file_history=200; # number of data to keep in files.
my $delta_of_time_to_make_average=300; # 5minutes by default
use strict;
use Net::SNMP;
use Getopt::Long;
# Nagios specific
use lib "@NAGIOS_PLUGINS@";
use utils qw(%ERRORS $TIMEOUT);
#my $TIMEOUT = 5;
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
# Oreon specific
#use lib "@NAGIOS_PLUGINS@";
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
# SNMP Datas
my $process_table= '1.3.6.1.2.1.25.4.2.1';
my $index_table = '1.3.6.1.2.1.25.4.2.1.1';
my $run_name_table = '1.3.6.1.2.1.25.4.2.1.2';
my $run_path_table = '1.3.6.1.2.1.25.4.2.1.4';
my $proc_mem_table = '1.3.6.1.2.1.25.5.1.1.2'; # Kbytes
my $proc_cpu_table = '1.3.6.1.2.1.25.5.1.1.1'; # Centi sec of CPU
my $proc_run_state = '1.3.6.1.2.1.25.4.2.1.7';
# Globals
my $Version='1.2.1';
my $o_host = undef; # hostname
my $o_community =undef; # community
my $o_port = 161; # port
my $o_descr = undef; # description filter
my $o_warn = 0; # warning limit
my @o_warnL= undef; # warning limits (min,max)
my $o_crit= 0; # critical limit
my @o_critL= undef; # critical limits (min,max)
my $o_help= undef; # wan't some help ?
my $o_verb= undef; # verbose mode
my $o_version= undef; # print version
my $o_noreg= undef; # Do not use Regexp for name
my $o_path= undef; # check path instead of name
my $o_inverse= undef; # checks max instead of min number of process
my $o_timeout= 5; # Default 5s Timeout
# SNMP V3 specific
my $o_login= undef; # snmp v3 login
my $o_passwd= undef; # snmp v3 passwd
# Memory & CPU
my $o_mem= undef; # checks memory (max)
my @o_memL= undef; # warn and crit level for mem
my $o_mem_avg= undef; # cheks memory average
my $o_cpu= undef; # checks CPU usage
my @o_cpuL= undef; # warn and crit level for cpu
my $o_delta= $delta_of_time_to_make_average; # delta time for CPU check
# Oreon specific
my $o_step= undef;
my $o_g= undef;
my $o_S= undef;
my $step= undef;
my $rrd= undef;
my $start= undef;
my $ServiceId= undef;
my @rrd_data= undef;
# functions
sub p_version { print "check_snmp_process version : $Version\n"; }
sub print_usage {
print "Usage: $0 [-v] -H <host> -C <snmp_community> | (-l login -x passwd) [-p <port>] -n <name> [-w <min_proc>[,<max_proc>] -c <min_proc>[,max_proc] ] [-m<warn Mb>,<crit Mb> -a -u<warn %>,<crit%> ] [-t <timeout>] [-f ] [-r] [-V]\n";
}
sub isnotnum { # Return true if arg is not a number
my $num = shift;
if ( $num =~ /^(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
return 1;
}
# Get the alarm signal (just in case snmp timout screws up)
$SIG{'ALRM'} = sub {
print ("ERROR: Alarm signal (Nagios time-out)\n");
exit $ERRORS{"UNKNOWN"};
};
sub read_file {
# Input : File, items_number
# Returns : array of value : [line][item]
my ($traffic_file,$items_number)=@_;
my ($ligne,$n_rows)=(undef,0);
my (@last_values,@file_values,$i);
open(FILE,"<".$traffic_file) || return (1,0,0);
while($ligne = <FILE>)
{
chomp($ligne);
@file_values = split(":",$ligne);
#verb("@file_values");
if ($#file_values >= ($items_number-1)) {
# check if there is enough data, else ignore line
for ( $i=0 ; $i< $items_number ; $i++ ) {$last_values[$n_rows][$i]=$file_values[$i]; }
$n_rows++;
}
}
close FILE;
if ($n_rows != 0) {
return (0,$n_rows,@last_values);
} else {
return (1,0,0);
}
}
sub write_file {
# Input : file , rows, items, array of value : [line][item]
# Returns : 0 / OK, 1 / error
my ($file_out,$rows,$item,@file_values)=@_;
my $start_line= ($rows > $file_history) ? $rows - $file_history : 0;
if ( open(FILE2,">".$file_out) ) {
for (my $i=$start_line;$i<$rows;$i++) {
for (my $j=0;$j<$item;$j++) {
print FILE2 $file_values[$i][$j];
if ($j != ($item -1)) { print FILE2 ":" };
}
print FILE2 "\n";
}
close FILE2;
return 0;
} else {
return 1;
}
}
sub help {
print "\nSNMP Process Monitor for Nagios version ",$Version,"\n";
print "(c)2004 to my cat Ratoune - Author: Patrick Proy\n\n";
print_usage();
print <<EOT;
-v, --verbose
print extra debugging information (and lists all storages)
-h, --help
print this help message
-H, --hostname=HOST
name or IP address of host to check
-C, --community=COMMUNITY NAME
community name for the host's SNMP agent (implies SNMP v1)
-l, --login=LOGIN
Login for snmpv3 authentication (implies v3 protocol with MD5)
-x, --passwd=PASSWD
Password for snmpv3 authentication
-p, --port=PORT
SNMP port (Default 161)
-n, --name=NAME
Name of the process (regexp)
No trailing slash !
-r, --noregexp
Do not use regexp to match NAME in description OID
-f, --fullpath
Use full path name instead of process name
(Windows doesn't provide full path name)
-w, --warn=MIN[,MAX]
Number of process that will cause a warning
-c, --critical=MIN[,MAX]
number of process that will cause an error
Notes on warning and critical :
with the following options : -w m1,x1 -c m2,x2
you must have : m2 <= m1 < x1 <= x2
you can omit x1 or x2 or both
-m, --memory=WARN,CRIT
checks memory usage (default max of all process)
values are warning and critical values in Mb
-a, --average
makes an average of memory used by process instead of max
-u, --cpu=WARN,CRIT
checks cpu usage of all process
values are warning and critical values in % of CPU usage
if more than one CPU, value can be > 100% : 100%=1 CPU
-t, --timeout=INTEGER
timeout for SNMP in seconds (Default: 5)
-V, --version
prints version number
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
-S (--ServiceId) Oreon Service Id
Note :
CPU usage is in % of one cpu, so maximum can be 100% * number of CPU
example :
Browse process list : <script> -C <community> -H <host> -n <anything> -v
the -n option allows regexp in perl format :
All process of /opt/soft/bin : -n /opt/soft/bin/ -f
All 'named' process : -n named
EOT
}
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
sub check_options {
my $compat_o_cpu_sum;
Getopt::Long::Configure ("bundling");
GetOptions(
'v' => \$o_verb, 'verbose' => \$o_verb,
'h' => \$o_help, 'help' => \$o_help,
'H:s' => \$o_host, 'hostname:s' => \$o_host,
'p:i' => \$o_port, 'port:i' => \$o_port,
'C:s' => \$o_community, 'community:s' => \$o_community,
'l:s' => \$o_login, 'login:s' => \$o_login,
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
'c:s' => \$o_crit, 'critical:s' => \$o_crit,
'w:s' => \$o_warn, 'warn:s' => \$o_warn,
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
'n:s' => \$o_descr, 'name:s' => \$o_descr,
'r' => \$o_noreg, 'noregexp' => \$o_noreg,
'f' => \$o_path, 'fullpath' => \$o_path,
'm:s' => \$o_mem, 'memory:s' => \$o_mem,
'a' => \$o_mem_avg, 'average' => \$o_mem_avg,
'u:s' => \$o_cpu, 'cpu' => \$o_cpu,
#### To be compatible with version 1.2, will be removed... ####
's' => \$compat_o_cpu_sum, 'cpusum' => \$compat_o_cpu_sum,
##########
'V' => \$o_version, 'version' => \$o_version,
# For Oreon rrdtool graph
"rrd_step:s" => \$o_step,
"g" => \$o_g, "rrdgraph" => \$o_g,
"S=s" => \$o_S, "ServiceId=s" => \$o_S
);
if (defined ($o_help)) { help(); exit $ERRORS{"UNKNOWN"}};
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
# check snmp information
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
# Check compulsory attributes
if ( ! defined($o_descr) || ! defined($o_host) ) { print_usage(); exit $ERRORS{"UNKNOWN"}};
@o_warnL=split(/,/,$o_warn);
@o_critL=split(/,/,$o_crit);
verb("$#o_warnL $#o_critL");
if ( isnotnum($o_warnL[0]) || isnotnum($o_critL[0]))
{ print "Numerical values for warning and critical\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
if ((defined($o_warnL[1]) && isnotnum($o_warnL[1])) || (defined($o_critL[1]) && isnotnum($o_critL[1])))
{ print "Numerical values for warning and critical\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
# Check for positive numbers
if (($o_warnL[0] < 0) || ($o_critL[0] < 0))
{ print " warn and critical > 0 \n";print_usage(); exit $ERRORS{"UNKNOWN"}};
if ((defined($o_warnL[1]) && ($o_warnL[1] < 0)) || (defined($o_critL[1]) && ($o_critL[1] < 0)))
{ print " warn and critical > 0 \n";print_usage(); exit $ERRORS{"UNKNOWN"}};
# Check min_crit < min warn < max warn < crit warn
if ($o_warnL[0] < $o_critL[0]) { print " warn minimum must be >= crit minimum\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
if (defined($o_warnL[1])) {
if ($o_warnL[1] <= $o_warnL[0])
{ print "warn minimum must be < warn maximum\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
} elsif ( defined($o_critL[1]) && ($o_critL[1] <= $o_warnL[0]))
{ print "warn minimum must be < crit maximum when no crit warning defined\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
if ( defined($o_critL[1]) && defined($o_warnL[1]) && ($o_critL[1]<$o_warnL[1]))
{ print "warn max must be <= crit maximum\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
#### Memory checks
if (defined ($o_mem)) {
@o_memL=split(/,/,$o_mem);
if ($#o_memL != 1)
{print "2 values (warning,critical) for memory\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
if (isnotnum($o_memL[0]) || isnotnum($o_memL[1]))
{print "Numeric values for memory!\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
if ($o_memL[0]>$o_memL[1])
{print "Warning must be <= Critical for memory!\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
}
#### CPU checks
if (defined ($o_cpu)) {
@o_cpuL=split(/,/,$o_cpu);
if ($#o_cpuL != 1)
{print "2 values (warning,critical) for cpu\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
if (isnotnum($o_cpuL[0]) || isnotnum($o_cpuL[1]))
{print "Numeric values for cpu!\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
if ($o_cpuL[0]>$o_cpuL[1])
{print "Warning must be <= Critical for cpu!\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
}
###### Oreon #######
if (!defined($o_S)) { $o_S="1_1" }
$ServiceId = is_valid_serviceid($o_S);
if (!defined($o_step)) { $o_step="300" }
$step = $1 if ($o_step =~ /(\d+)/);
}
########## MAIN #######
check_options();
$rrd = $pathtorrdbase.$ServiceId.".rrd";
$start=time;
# Check gobal timeout if snmp screws up
if (defined($TIMEOUT)) {
verb("Alarm at $TIMEOUT");
alarm($TIMEOUT);
} else {
verb("no timeout defined : $o_timeout + 10");
alarm ($o_timeout+10);
}
# Connect to host
my ($session,$error);
if ( defined($o_login) && defined($o_passwd)) {
# SNMPv3 login
verb("SNMPv3 login");
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => '3',
-username => $o_login,
-authpassword => $o_passwd,
-authprotocol => 'md5',
-privpassword => $o_passwd,
-timeout => $o_timeout
);
} else {
# SNMPV1 login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-community => $o_community,
-port => $o_port,
-timeout => $o_timeout
);
}
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
exit $ERRORS{"UNKNOWN"};
}
# Look for process in name or path name table
my $resultat=undef;
if ( !defined ($o_path) ) {
$resultat = $session->get_table(
Baseoid => $run_name_table
);
} else {
$resultat = $session->get_table(
Baseoid => $run_path_table
);
}
if (!defined($resultat)) {
printf("ERROR: Process name table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
my @tindex = undef;
my @oids = undef;
my @descr = undef;
my $num_int = 0;
my $count_oid = 0;
# Select storage by regexp of exact match
# and put the oid to query in an array
verb("Filter : $o_descr");
foreach my $key ( keys %$resultat) {
verb("OID : $key, Desc : $$resultat{$key}");
# test by regexp or exact match
my $test = defined($o_noreg)
? $$resultat{$key} eq $o_descr
: $$resultat{$key} =~ /$o_descr/;
if ($test) {
# get the index number of the interface
my @oid_list = split (/\./,$key);
$tindex[$num_int] = pop (@oid_list);
# get the full description
$descr[$num_int]=$$resultat{$key};
# put the oid of running and mem (check this maybe ?) in an array.
$oids[$count_oid++]=$proc_mem_table . "." . $tindex[$num_int];
$oids[$count_oid++]=$proc_cpu_table . "." . $tindex[$num_int];
$oids[$count_oid++]=$proc_run_state . "." . $tindex[$num_int];
#verb("Name : $descr[$num_int], Index : $tindex[$num_int]");
verb($oids[$count_oid-1]);
$num_int++;
}
}
if ( $num_int == 0) {
print "No process ",(defined ($o_noreg)) ? "named " : "matching ", $o_descr, " found : CRITICAL\n";
exit $ERRORS{"CRITICAL"};
}
my $result=undef;
my $num_int_ok=0;
my %result_cons=();
#$session->max_msg_size([214748]);
if ( $count_oid >= 50) {
my @toid=undef;
my $tmp_num=0;
my $tmp_index=0;
my $tmp_count=$count_oid;
my $tmp_result=undef;
verb("More than 50 oid, splitting");
while ( $tmp_count != 0 ) {
$tmp_num = ($tmp_count >=50) ? 50 : $tmp_count;
for (my $i=0; $i<$tmp_num;$i++) {
$toid[$i]=$oids[$i+$tmp_index];
#verb("$i : $toid[$i] : $oids[$i+$tmp_index]");
}
$tmp_result = $session->get_request(
Varbindlist => \@toid
);
if (!defined($tmp_result)) { printf("ERROR: running table : %s.\n", $session->error); $session->close;
exit $ERRORS{"UNKNOWN"};
}
foreach (@toid) { $result_cons{$_}=$$tmp_result{$_}; }
$tmp_count-=$tmp_num;
$tmp_index+=$tmp_num;
}
} else {
$result = $session->get_request(
Varbindlist => \@oids
);
if (!defined($result)) { printf("ERROR: running table : %s.\n", $session->error); $session->close;
exit $ERRORS{"UNKNOWN"};
}
foreach (@oids) {$result_cons{$_}=$$result{$_};}
}
#Check if process are in running or runnable state
for (my $i=0; $i< $num_int; $i++) {
my $state=$result_cons{$proc_run_state . "." . $tindex[$i]};
my $tmpmem=$result_cons{$proc_mem_table . "." . $tindex[$i]};
my $tmpcpu=$result_cons{$proc_cpu_table . "." . $tindex[$i]};
verb ("Process $tindex[$i] in state $state using $tmpmem, and $tmpcpu CPU");
$num_int_ok++ if (($state == 1) || ($state ==2));
}
$session->close;
$rrd_data[0] = $num_int_ok;
my $final_status=0;
my ($res_memory,$res_cpu)=(0,0);
my $memory_print="";
my $cpu_print="";
###### Checks memory usage
if (defined ($o_mem) ) {
if (defined ($o_mem_avg)) {
for (my $i=0; $i< $num_int; $i++) { $res_memory += $result_cons{$proc_mem_table . "." . $tindex[$i]};}
$res_memory /= ($num_int_ok*1024);
verb("Memory average : $res_memory");
} else {
for (my $i=0; $i< $num_int; $i++) {
$res_memory = ($result_cons{$proc_mem_table . "." . $tindex[$i]} > $res_memory) ? $result_cons{$proc_mem_table . "." . $tindex[$i]} : $res_memory;
}
$res_memory /=1024;
verb("Memory max : $res_memory");
}
if ($res_memory > $o_memL[1]) {
$final_status=2;
$memory_print=", Mem : ".sprintf("%.1f",$res_memory)."Mb > ".$o_memL[1]." CRITICAL";
} elsif ( $res_memory > $o_memL[0]) {
$final_status=1;
$memory_print=", Mem : ".sprintf("%.1f",$res_memory)."Mb > ".$o_memL[0]." WARNING";
} else {
$memory_print=", Mem : ".sprintf("%.1f",$res_memory)."Mb OK";
}
push @rrd_data, $res_memory;
}
######## Checks CPU usage
if (defined ($o_cpu) ) {
my $timenow=time;
my $temp_file_name;
my ($return,@file_values)=(undef,undef);
my $n_rows=0;
my $n_items_check=2;
my $trigger=$timenow - ($o_delta - ($o_delta/10));
my $trigger_low=$timenow - 3*$o_delta;
my ($old_value,$old_time)=undef;
my $found_value=undef;
#### Get the current values
for (my $i=0; $i< $num_int; $i++) { $res_cpu += $result_cons{$proc_cpu_table . "." . $tindex[$i]};}
verb("Time: $timenow , cpu (centiseconds) : $res_cpu");
#### Read file
$temp_file_name=$o_descr;
$temp_file_name =~ s/ /_/g;
$temp_file_name = $o_base_dir . $o_host ."." . $temp_file_name;
# First, read entire file
my @ret_array=read_file($temp_file_name,$n_items_check);
$return = shift(@ret_array);
$n_rows = shift(@ret_array);
if ($n_rows != 0) { @file_values = @ret_array };
verb ("File read returns : $return with $n_rows rows");
#make the checks if the file is OK
if ($return ==0) {
my $j=$n_rows-1;
do {
if ($file_values[$j][0] < $trigger) {
if ($file_values[$j][0] > $trigger_low) {
# found value = centiseconds / seconds = %cpu
$found_value= ($res_cpu-$file_values[$j][1]) / ($timenow - $file_values[$j][0] );
}
}
$j--;
} while ( ($j>=0) && (!defined($found_value)) );
}
###### Write file
$file_values[$n_rows][0]=$timenow;
$file_values[$n_rows][1]=$res_cpu;
$n_rows++;
$return=write_file($temp_file_name,$n_rows,$n_items_check,@file_values);
if ($return != 0) { $cpu_print.="! ERROR writing file $temp_file_name !";$final_status=3;}
##### Check values (if something to check...)
if (defined($found_value)) {
if ($found_value > $o_cpuL[1]) {
$final_status=2;
$cpu_print.=", Cpu : ".sprintf("%.0f",$found_value)."% > ".$o_cpuL[1]." CRITICAL";
} elsif ( $found_value > $o_cpuL[0]) {
$final_status=($final_status==2)?2:1;
$cpu_print.=", Cpu : ".sprintf("%.0f",$found_value)."% > ".$o_cpuL[0]." WARNING";
} else {
$cpu_print.=", Cpu : ".sprintf("%.0f",$found_value)."% OK";
}
push @rrd_data, $found_value;
} else {
if ($final_status==0) { $final_status=3 };
$cpu_print.=", No data for CPU (".$n_rows." line(s)):UNKNOWN";
}
}
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,$#rrd_data+1,$start,$step,0,"U","GAUGE");
}
update_rrd($rrd,$start,@rrd_data);
}
print $num_int_ok, " process ", (defined ($o_noreg)) ? "named " : "matching ", $o_descr, " ";
#### Check for min and max number of process
if ( $num_int_ok <= $o_critL[0] ) {
print "(<= ",$o_critL[0]," : CRITICAL)";
$final_status=2;
} elsif ( $num_int_ok <= $o_warnL[0] ) {
print "(<= ",$o_warnL[0]," : WARNING)";
$final_status=($final_status==2)?2:1;
} else {
print "(> ",$o_warnL[0],")";
}
if (defined($o_critL[1]) && ($num_int_ok > $o_critL[1])) {
print " (> ",$o_critL[1]," : CRITICAL)";
$final_status=2;
} elsif (defined($o_warnL[1]) && ($num_int_ok > $o_warnL[1])) {
print " (> ",$o_warnL[1]," : WARNING)";
$final_status=($final_status==2)?2:1;
} elsif (defined($o_warnL[1])) {
print " (<= ",$o_warnL[1],"):OK";
}
print $memory_print,$cpu_print,"\n";
if ($final_status==2) { exit $ERRORS{"CRITICAL"};}
if ($final_status==1) { exit $ERRORS{"WARNING"};}
if ($final_status==3) { exit $ERRORS{"UNKNOWN"};}
exit $ERRORS{"OK"};

View File

@ -1,177 +0,0 @@
#! /usr/bin/perl
#
# $Id: check_graph_remote_storage.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $
#
# Oreon's plugins are developped with GPL Licence :
# http://www.fsf.org/licenses/gpl.txt
# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier
#
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
#
# tHe Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
# Plugin init
use strict;
use Net::SNMP qw(:snmp);
use FindBin;
use lib "$FindBin::Bin";
use lib "/usr/local/nagios/libexec";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_S $opt_D $opt_s $opt_step $step @test $opt_f);
# Plugin var init
my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed);
my ($AllocationUnits, $Size, $Used);
my ($tot, $used, $pourcent, $return_code);
$PROGNAME = $0;
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"V" => \$opt_V, "version" => \$opt_V,
"v=s" => \$opt_v,
"s" => \$opt_s, "show" => \$opt_s,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"n=s" => \$opt_n, "name=s" => \$opt_n,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
($opt_v) || ($opt_v = shift) || ($opt_v = "2");
my $snmp = $1 if ($opt_v =~ /(\d)/);
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
($opt_c) || ($opt_c = shift) || ($opt_c = 95);
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
($opt_w) || ($opt_w = shift) || ($opt_w = 80);
my $warning = $1 if ($opt_w =~ /([0-9]+)/);
if ($critical <= $warning){
print "(--crit) must be superior to (--warn)";
print_usage();
exit $ERRORS{'OK'};
}
# Plugin snmp requests
my $OID_ExecResult = ".1.3.6.1.4.1.2021.8.1.100";
my $OID_ExecDescr = ".1.3.6.1.4.1.2021.8.1.2";
my $OID_ExecOutput = ".1.3.6.1.4.1.2021.8.1.101";
# create a SNMP session
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
if ( !defined($session) ) {
print("CRITICAL: SNMP Session : $error");
exit $ERRORS{'CRITICAL'};
}
my $scriptname = "";
# getting partition using its name instead of its oid index
if ($opt_n) {
my $result = $session->get_table(Baseoid => $OID_ExecDescr);
if (!defined($result)) {
printf("ERROR: hr Exec Descr Table : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
foreach my $key ( oid_lex_sort(keys %$result)) {
if ($result->{$key} =~ m/^$opt_n$/) {
my @oid_list = split (/\./,$key);
$scriptname = pop (@oid_list) ;
}
}
}
if ($scriptname eq "") {
print "No such process, verify your snmpd configuration\n";
exit(3);
}
my $result = $session->get_request(-varbindlist => [$OID_ExecDescr.".".$scriptname, $OID_ExecOutput.".".$scriptname]);
if (!defined($result)) {
printf("ERROR: %s", $session->error);
if ($opt_n) { print(" - You must specify the disk name when option -n is used");}
print ".\n";
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $ExecResult = $result->{$OID_ExecResult.".".$scriptname };
my $ExecDescr = $result->{$OID_ExecDescr.".".$scriptname };
my $ExecOutput = $result->{$OID_ExecOutput.".".$scriptname };
if ($ExecOutput =~ /cannot\ open/) {
$ExecResult = 3;
}
print $ExecOutput . "\n";
exit($ExecResult);
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -n (--name) Allows to use disk name with option -d instead of disk oid index\n";
print " (ex: -d \"C:\" -n, -d \"E:\" -n, -d \"Swap Memory\" -n, -d \"Real Memory\" -n\n";
print " (choose an unique expression for each disk)\n";
print " -w (--warn) Signal strength at which a warning message will be generated\n";
print " (default 80)\n";
print " -c (--crit) Signal strength at which a critical message will be generated\n";
print " (default 95)\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "##########################################\n";
print "# Copyright (c) 2004-2006 Oreon #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "##########################################\n";
print_usage();
print "\n";
}

View File

@ -1,196 +0,0 @@
#! /usr/bin/perl
#
# $Id: check_graph_remote_storage.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $
#
# Oreon's plugins are developped with GPL Licence :
# http://www.fsf.org/licenses/gpl.txt
# Developped by : Julien Mathis - Mathieu Mettre - Romain Le Merlus - Yohann Lecarpentier
#
# Modified for Oreon Project by : Mathieu Chateau - Christophe Coraboeuf
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
# Plugin init
use strict;
use Net::SNMP qw(:snmp);
use FindBin;
use lib "$FindBin::Bin";
use lib "/usr/local/nagios/libexec";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_V $opt_h $opt_g $opt_v $opt_C $opt_d $opt_n $opt_w $opt_c $opt_H $opt_S $opt_D $opt_s $opt_step $step @test $opt_f);
# Plugin var init
my ($hrStorageDescr, $hrStorageAllocationUnits, $hrStorageSize, $hrStorageUsed);
my ($AllocationUnits, $Size, $Used);
my ($tot, $used, $pourcent, $return_code);
$PROGNAME = "check_snmp_remote_storage";
sub print_help ();
sub print_usage ();
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"V" => \$opt_V, "version" => \$opt_V,
"v=s" => \$opt_v,
"s" => \$opt_s, "show" => \$opt_s,
"C=s" => \$opt_C, "community=s" => \$opt_C,
"n=s" => \$opt_n, "name=s" => \$opt_n,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"c=s" => \$opt_c, "critical=s" => \$opt_c,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_V) {
print_revision($PROGNAME,'$Revision: 1.2 $');
exit $ERRORS{'OK'};
}
if ($opt_h) {
print_help();
exit $ERRORS{'OK'};
}
$opt_H = shift unless ($opt_H);
(print_usage() && exit $ERRORS{'OK'}) unless ($opt_H);
($opt_v) || ($opt_v = shift) || ($opt_v = "2");
my $snmp = $1 if ($opt_v =~ /(\d)/);
($opt_C) || ($opt_C = shift) || ($opt_C = "public");
($opt_c) || ($opt_c = shift) || ($opt_c = 95);
my $critical = $1 if ($opt_c =~ /([0-9]+)/);
($opt_w) || ($opt_w = shift) || ($opt_w = 80);
my $warning = $1 if ($opt_w =~ /([0-9]+)/);
if ($critical <= $warning){
print "(--crit) must be superior to (--warn)";
print_usage();
exit $ERRORS{'OK'};
}
# Plugin snmp requests
my $OID_ExecDescr = ".1.3.6.1.4.1.2021.8.1.2";
my $OID_ExecOutput = ".1.3.6.1.4.1.2021.8.1.101";
# create a SNMP session
my ( $session, $error ) = Net::SNMP->session(-hostname => $opt_H,-community => $opt_C, -version => $snmp);
if ( !defined($session) ) {
print("CRITICAL: SNMP Session : $error");
exit $ERRORS{'CRITICAL'};
}
my $scriptname = "";
# getting partition using its name instead of its oid index
if ($opt_n) {
my $result = $session->get_table(Baseoid => $OID_ExecDescr);
if (!defined($result)) {
printf("ERROR: hr Exec Descr Table : %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
foreach my $key ( oid_lex_sort(keys %$result)) {
if ($result->{$key} =~ m/$opt_n/) {
my @oid_list = split (/\./,$key);
$scriptname = pop (@oid_list) ;
}
}
}
my $result = $session->get_request(-varbindlist => [$OID_ExecDescr.".".$scriptname, $OID_ExecOutput.".".$scriptname]);
if (!defined($result)) {
printf("ERROR: %s", $session->error);
if ($opt_n) { print(" - You must specify the disk name when option -n is used");}
print ".\n";
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $ExecDescr = $result->{$OID_ExecDescr.".".$scriptname };
my $ExecOutput = $result->{$OID_ExecOutput.".".$scriptname };
print "|" . $ExecOutput . "\n";
my $return = 5;
if (!defined($opt_w) && !defined($opt_c)){
$ExecOutput =~ /([0-9]*)/;
if ($1 eq 1){
print "OK : Process runnable \n";
$return = 0;
} else {
print "CRITICAL : Process runnable \n";
$return = 2;
}
} else {
if ($ExecOutput =~ /([0-9]*)/){
if ($1 >= $opt_w && $1 < $opt_c){
print "OK : $1 Process runnable \n";
$return = 1;
} elsif ($1 > $opt_c) {
print "WARNING : $1 Process runnable \n";
$return = 2;
} elsif ($1 < $opt_w) {
print "CRITICAL : Process runnable \n";
$return = 0;
}
}
}
exit($return);
sub print_usage () {
print "\nUsage:\n";
print "$PROGNAME\n";
print " -H (--hostname) Hostname to query - (required)\n";
print " -C (--community) SNMP read community (defaults to public,\n";
print " used with SNMP v1 and v2c\n";
print " -v (--snmp_version) 1 for SNMP v1 (default)\n";
print " 2 for SNMP v2c\n";
print " -n (--name) Allows to use disk name with option -d instead of disk oid index\n";
print " (ex: -d \"C:\" -n, -d \"E:\" -n, -d \"Swap Memory\" -n, -d \"Real Memory\" -n\n";
print " (choose an unique expression for each disk)\n";
print " -w (--warn) Signal strength at which a warning message will be generated\n";
print " (default 80)\n";
print " -c (--crit) Signal strength at which a critical message will be generated\n";
print " (default 95)\n";
print " -V (--version) Plugin version\n";
print " -h (--help) usage help\n";
}
sub print_help () {
print "##########################################\n";
print "# Copyright (c) 2004-2006 Oreon #\n";
print "# Bugs to http://www.oreon-project.org/ #\n";
print "##########################################\n";
print_usage();
print "\n";
}

View File

@ -1,662 +0,0 @@
#!/usr/bin/perl -w
############################## check_snmp_storage ##############
# Version : 1.1.1.4 - DEV
# Date : Aug 2 2005
# Author : Patrick Proy ( patrick at proy.org)
# Help : http://www.manubulon.com/nagios/
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
# TODO : better options in snmpv3
#################################################################
#
# help : ./check_snmp_storage -h
use strict;
use Net::SNMP;
use Getopt::Long;
# Nagios specific
use lib "@NAGIOS_PLUGINS@";
use utils qw(%ERRORS $TIMEOUT);
#my $TIMEOUT = 15;
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
# Oreon specific
#use lib "@NAGIOS_PLUGINS@";
if (eval "require oreon" ) {
use oreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid);
use vars qw($VERSION %oreon);
%oreon=get_parameters();
} else {
print "Unable to load oreon perl module\n";
exit $ERRORS{'UNKNOWN'};
}
my $pathtorrdbase = $oreon{GLOBAL}{DIR_RRDTOOL};
# SNMP Datas
my $storage_table= '1.3.6.1.2.1.25.2.3.1';
my $storagetype_table = '1.3.6.1.2.1.25.2.3.1.2';
my $index_table = '1.3.6.1.2.1.25.2.3.1.1';
my $descr_table = '1.3.6.1.2.1.25.2.3.1.3';
my $size_table = '1.3.6.1.2.1.25.2.3.1.5.';
my $used_table = '1.3.6.1.2.1.25.2.3.1.6.';
my $alloc_units = '1.3.6.1.2.1.25.2.3.1.4.';
#Storage types definition - from /usr/share/snmp/mibs/HOST-RESOURCES-TYPES.txt
my %hrStorage;
$hrStorage{"Other"} = '1.3.6.1.2.1.25.2.1.1';
$hrStorage{"1.3.6.1.2.1.25.2.1.1"} = 'Other';
$hrStorage{"Ram"} = '1.3.6.1.2.1.25.2.1.2';
$hrStorage{"1.3.6.1.2.1.25.2.1.2"} = 'Ram';
$hrStorage{"VirtualMemory"} = '1.3.6.1.2.1.25.2.1.3';
$hrStorage{"1.3.6.1.2.1.25.2.1.3"} = 'VirtualMemory';
$hrStorage{"FixedDisk"} = '1.3.6.1.2.1.25.2.1.4';
$hrStorage{"1.3.6.1.2.1.25.2.1.4"} = 'FixedDisk';
$hrStorage{"RemovableDisk"} = '1.3.6.1.2.1.25.2.1.5';
$hrStorage{"1.3.6.1.2.1.25.2.1.5"} = 'RemovableDisk';
$hrStorage{"FloppyDisk"} = '1.3.6.1.2.1.25.2.1.6';
$hrStorage{"1.3.6.1.2.1.25.2.1.6"} = 'FloppyDisk';
$hrStorage{"CompactDisk"} = '1.3.6.1.2.1.25.2.1.7';
$hrStorage{"1.3.6.1.2.1.25.2.1.7"} = 'CompactDisk';
$hrStorage{"RamDisk"} = '1.3.6.1.2.1.25.2.1.8';
$hrStorage{"1.3.6.1.2.1.25.2.1.8"} = 'RamDisk';
$hrStorage{"FlashMemory"} = '1.3.6.1.2.1.25.2.1.9';
$hrStorage{"1.3.6.1.2.1.25.2.1.9"} = 'FlashMemory';
$hrStorage{"NetworkDisk"} = '1.3.6.1.2.1.25.2.1.10';
$hrStorage{"1.3.6.1.2.1.25.2.1.10"} = 'NetworkDisk';
# Globals
my $Name='check_snmp_storage';
my $Version='1.1.1.3';
my $o_host = undef; # hostname
my $o_community = undef; # community
my $o_port = 161; # port
my $o_version2 = undef; #use snmp v2c
my $o_descr = undef; # description filter
my $o_storagetype = undef; # parse storage type also
my $o_warn = undef; # warning limit
my $o_crit= undef; # critical limit
my $o_help= undef; # wan't some help ?
my $o_type= undef; # pl, pu, mbl, mbu
my @o_typeok= ("pu","pl","bu","bl"); # valid values for o_type
my $o_verb= undef; # verbose mode
my $o_version= undef; # print version
my $o_noreg= undef; # Do not use Regexp for name
my $o_sum= undef; # add all storage before testing
my $o_index= undef; # Parse index instead of description
my $o_negate= undef; # Negate the regexp if set
my $o_timeout= 5; # Default 5s Timeout
my $o_perf= undef; # Output performance data
my $o_short= undef; # Short output parameters
my @o_shortL= undef; # output type,where,cut
# SNMP V3 specific
my $o_login= undef; # snmp v3 login
my $o_passwd= undef; # snmp v3 passwd
# Oreon specific
my $o_step= undef;
my $o_g= undef;
my $o_S= undef;
my $step= undef;
my $rrd= undef;
my $rrd_max= undef;
my $start= undef;
my $ServiceId= undef;
my @rrd_data= undef;
# functions
sub p_version { print "$Name version : $Version\n"; }
sub print_usage {
print "Usage: $Name [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-p <port>] -m <name in desc_oid> [-q storagetype] -w <warn_level> -c <crit_level> [-t <timeout>] [-T pl|pu|bl|bu ] [-r] [-s] [-i] [-e] [-S 0|1[,1,<car>]]\n";
}
sub round ($$) {
sprintf "%.$_[1]f", $_[0];
}
sub is_pattern_valid { # Test for things like "<I\s*[^>" or "+5-i"
my $pat = shift;
if (!defined($pat)) { $pat=" ";} # Just to get rid of compilation time warnings
return eval { "" =~ /$pat/; 1 } || 0;
}
# Get the alarm signal (just in case snmp timout screws up)
$SIG{'ALRM'} = sub {
print ("ERROR: General time-out (Alarm signal)\n");
exit $ERRORS{"UNKNOWN"};
};
sub isnnum { # Return true if arg is not a number
my $num = shift;
if ( $num =~ /^-?(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
return 1;
}
sub help {
print "\nSNMP Disk Monitor for Nagios version ",$Version,"\n";
print "(c)2004 to my cat Ratoune - Author : Patrick Proy\n\n";
print_usage();
print <<EOT;
By default, plugin will monitor %used on drives :
warn if %used > warn and critical if %used > crit
-v, --verbose
print extra debugging information (and lists all storages)
-h, --help
print this help message
-H, --hostname=HOST
name or IP address of host to check
-C, --community=COMMUNITY NAME
community name for the host's SNMP agent (implies SNMP v1)
-2, --v2c
Use snmp v2c
-l, --login=LOGIN
Login for snmpv3 authentication (implies v3 protocol with MD5)
-x, --passwd=PASSWD
Password for snmpv3 authentication
-p, --port=PORT
SNMP port (Default 161)
-m, --name=NAME
Name in description OID (can be mounpoints '/home' or 'Swap Space'...)
This is treated as a regexp : -m /var will match /var , /var/log, /opt/var ...
Test it before, because there are known bugs (ex : trailling /)
No trailing slash for mountpoints !
-q, --storagetype=[Other|Ram|VirtualMemory|FixedDisk|RemovableDisk|FloppyDisk
CompactDisk|RamDisk|FlashMemory|NetworkDisk]
Also check the storage type in addition of the name
It is possible to use regular expressions ( "FixedDisk|FloppyDisk" )
-r, --noregexp
Do not use regexp to match NAME in description OID
-s, --sum
Add all storages that match NAME (used space and total space)
THEN make the tests.
-i, --index
Parse index table instead of description table to select storage
-e, --exclude
Select all storages except the one(s) selected by -m
No action on storage type selection
-T, --type=TYPE
pl : calculate percent left
pu : calculate percent used (Default)
bl : calculate MegaBytes left
bu : calculate MegaBytes used
-w, --warn=INTEGER
percent / MB of disk used to generate WARNING state
you can add the % sign
-c, --critical=INTEGER
percent / MB of disk used to generate CRITICAL state
you can add the % sign
-f, --perfparse
Perfparse compatible output
-S, --short=<type>[,<where>,<cut>]
<type>: Make the output shorter :
0 : only print the global result except the disk in warning or critical
ex: "< 80% : OK"
1 : Don't print all info for every disk
ex : "/ : 66 %used (< 80) : OK"
<where>: (optional) if = 1, put the OK/WARN/CRIT at the beginning
<cut>: take the <n> first caracters or <n> last if n<0
-t, --timeout=INTEGER
timeout for SNMP in seconds (Default: 5)
-V, --version
prints version number
-g (--rrdgraph) Create a rrd base if necessary and add datas into this one
--rrd_step Specifies the base interval in seconds with which data will be fed into the RRD (300 by default)
-S (--ServiceId) Oreon Service Id
Note :
with T=pu or T=bu : OK < warn < crit
with T=pl ot T=bl : crit < warn < OK
If multiple storage are selected, the worse condition will be returned
i.e if one disk is critical, the return is critical
example :
Browse storage list : <script> -C <community> -H <host> -m <anything> -w 1 -c 2 -v
the -m option allows regexp in perl format :
Test drive C,F,G,H,I on Windows : -m ^[CFGHI]:
Test all mounts containing /var : -m /var
Test all mounts under /var : -m ^/var
Test only /var : -m /var -r
Test all swap spaces : -m ^Swap
Test all but swap spaces : -m ^Swap -e
EOT
}
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
sub check_options {
Getopt::Long::Configure ("bundling");
GetOptions(
'v' => \$o_verb, 'verbose' => \$o_verb,
'h' => \$o_help, 'help' => \$o_help,
'H:s' => \$o_host, 'hostname:s' => \$o_host,
'p:i' => \$o_port, 'port:i' => \$o_port,
'C:s' => \$o_community, 'community:s' => \$o_community,
'l:s' => \$o_login, 'login:s' => \$o_login,
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
'c:s' => \$o_crit, 'critical:s' => \$o_crit,
'w:s' => \$o_warn, 'warn:s' => \$o_warn,
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
'm:s' => \$o_descr, 'name:s' => \$o_descr,
'T:s' => \$o_type, 'type:s' => \$o_type,
'r' => \$o_noreg, 'noregexp' => \$o_noreg,
's' => \$o_sum, 'sum' => \$o_sum,
'i' => \$o_index, 'index' => \$o_index,
'e' => \$o_negate, 'exclude' => \$o_negate,
'V' => \$o_version, 'version' => \$o_version,
'q:s' => \$o_storagetype, 'storagetype:s'=> \$o_storagetype,
'2' => \$o_version2, 'v2c' => \$o_version2,
'S:s' => \$o_short, 'short:s' => \$o_short,
'f' => \$o_perf, 'perfparse' => \$o_perf,
# For Oreon rrdtool graph
"rrd_step:s" => \$o_step,
"g" => \$o_g, "rrdgraph" => \$o_g,
# "S=s" => \$o_S,
"ServiceId=s" => \$o_S
);
if (defined($o_help) ) { help(); exit $ERRORS{"UNKNOWN"}};
if (defined($o_version) ) { p_version(); exit $ERRORS{"UNKNOWN"}};
# check mount point regexp
if (!is_pattern_valid($o_descr))
{ print "Bad pattern for mount point !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
# check snmp information
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
# Check types
if ( !defined($o_type) ) { $o_type="pu" ;}
if ( ! grep( /^$o_type$/ ,@o_typeok) ) { print_usage(); exit $ERRORS{"UNKNOWN"}};
# Check compulsory attributes
if ( ! defined($o_descr) || ! defined($o_host) || !defined($o_warn) ||
!defined($o_crit)) { print_usage(); exit $ERRORS{"UNKNOWN"}};
# Check for positive numbers
# check if warn or crit in % and MB is tested
if ( ( ( $o_warn =~ /%/ ) || ($o_crit =~ /%/)) && ( ( $o_type eq 'bu' ) || ( $o_type eq 'bl' ) ) ) {
print "warning or critical cannot be in % when MB are tested\n";
print_usage(); exit $ERRORS{"UNKNOWN"};
}
# Get rid of % sign
$o_warn =~ s/\%//;
$o_crit =~ s/\%//;
if (($o_warn < 0) || ($o_crit < 0)) { print " warn and critical > 0 \n";print_usage(); exit $ERRORS{"UNKNOWN"}};
# Check warning and critical values
if ( ( $o_type eq 'pu' ) || ( $o_type eq 'bu' )) {
if ($o_warn >= $o_crit) { print " warn < crit if type=",$o_type,"\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
}
if ( ( $o_type eq 'pl' ) || ( $o_type eq 'bl' )) {
if ($o_warn <= $o_crit) { print " warn > crit if type=",$o_type,"\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
}
if ( ($o_warn < 0 ) || ($o_crit < 0 )) { print "warn and crit must be > 0\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
if ( ( $o_type eq 'pl' ) || ( $o_type eq 'pu' )) {
if ( ($o_warn > 100 ) || ($o_crit > 100 )) { print "percent must be < 100\n";print_usage(); exit $ERRORS{"UNKNOWN"}};
}
# Check short values
if ( defined ($o_short)) {
@o_shortL=split(/,/,$o_short);
if ((isnnum($o_shortL[0])) || ($o_shortL[0] !=0) && ($o_shortL[0]!=1)) {
print "-S first option must be 0 or 1\n";print_usage(); exit $ERRORS{"UNKNOWN"};
}
if (defined ($o_shortL[1])&& $o_shortL[1] eq "") {$o_shortL[1]=undef};
if (defined ($o_shortL[2]) && isnnum($o_shortL[2]))
{print "-S last option must be an integer\n";print_usage(); exit $ERRORS{"UNKNOWN"};}
}
###### Oreon #######
if (!defined($o_S)) { $o_S="1_1" }
$ServiceId = is_valid_serviceid($o_S);
if (!defined($o_step)) { $o_step="300" }
$step = $1 if ($o_step =~ /(\d+)/);
}
########## MAIN #######
check_options();
$rrd = $pathtorrdbase.$ServiceId.".rrd";
$start=time;
# Check gobal timeout
if (defined($TIMEOUT)) {
verb("Alarm at $TIMEOUT");
alarm($TIMEOUT);
} else {
verb("no timeout defined : $o_timeout + 10");
alarm ($o_timeout+10);
}
# Connect to host
my ($session,$error);
if ( defined($o_login) && defined($o_passwd)) {
# SNMPv3 login
verb("SNMPv3 login");
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => '3',
-username => $o_login,
-authpassword => $o_passwd,
-authprotocol => 'md5',
-privpassword => $o_passwd,
-timeout => $o_timeout
);
} else {
if (defined ($o_version2)) {
# SNMPv2 Login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => 2,
-community => $o_community,
-port => $o_port,
-timeout => $o_timeout
);
} else { # SNMPV1 login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-community => $o_community,
-port => $o_port,
-timeout => $o_timeout
);
}
}
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
exit $ERRORS{"UNKNOWN"};
}
my $resultat=undef;
my $stype=undef;
if (defined ($o_index)){
if (Net::SNMP->VERSION < 4) {
$resultat = $session->get_table($index_table);
} else {
$resultat = $session->get_table(Baseoid => $index_table);
}
} else {
if (Net::SNMP->VERSION < 4) {
$resultat = $session->get_table($descr_table);
} else {
$resultat = $session->get_table(Baseoid => $descr_table);
}
}
#get storage typetable for reference
if (defined($o_storagetype)){
if (Net::SNMP->VERSION < 4) {
$stype = $session->get_table($storagetype_table);
} else {
$stype = $session->get_table(Baseoid => $storagetype_table);
}
}
if (!defined($resultat) | (!defined($stype) && defined($o_storagetype))) {
printf("ERROR: Description/Type table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
my @tindex = undef;
my @oids = undef;
my @descr = undef;
my $num_int = 0;
my $count_oid = 0;
my $test = undef;
my $perf_out= undef;
# Select storage by regexp of exact match
# and put the oid to query in an array
verb("Filter : $o_descr");
foreach my $key ( keys %$resultat) {
verb("OID : $key, Desc : $$resultat{$key}");
# test by regexp or exact match / include or exclude
if (defined($o_negate)) {
$test = defined($o_noreg)
? $$resultat{$key} ne $o_descr
: $$resultat{$key} !~ /$o_descr/;
} else {
$test = defined($o_noreg)
? $$resultat{$key} eq $o_descr
: $$resultat{$key} =~ /$o_descr/;
}
if ($test) {
# get the index number of the interface
my @oid_list = split (/\./,$key);
$tindex[$num_int] = pop (@oid_list);
# Check if storage type is OK
if (defined($o_storagetype)) {
my($skey)=$storagetype_table.".".$tindex[$num_int];
verb(" OID : $skey, Storagetype: $hrStorage{$$stype{$skey}} ?= $o_storagetype");
if ( $hrStorage{$$stype{$skey}} !~ $o_storagetype) {
$test=undef;
}
}
if ($test) {
# get the full description
$descr[$num_int]=$$resultat{$key};
# put the oid in an array
$oids[$count_oid++]=$size_table . $tindex[$num_int];
$oids[$count_oid++]=$used_table . $tindex[$num_int];
$oids[$count_oid++]=$alloc_units . $tindex[$num_int];
verb(" Name : $descr[$num_int], Index : $tindex[$num_int]");
$num_int++;
}
}
}
verb("storages selected : $num_int");
if ( $num_int == 0 ) { print "Unknown storage : $o_descr : ERROR\n" ; exit $ERRORS{"UNKNOWN"};}
my $result=undef;
if (Net::SNMP->VERSION < 4) {
$result = $session->get_request(@oids);
} else {
if ($session->version == 0) {
# snmpv1
$result = $session->get_request(Varbindlist => \@oids);
} else {
# snmp v2c or v3 : get_bulk_request is not really good for this, so do simple get
$result = $session->get_request(Varbindlist => \@oids);
foreach my $key ( keys %$result) { verb("$key : $$result{$key}"); }
}
}
if (!defined($result)) { printf("ERROR: Size table :%s.\n", $session->error); $session->close;
exit $ERRORS{"UNKNOWN"};
}
$session->close;
# Only a few ms left...
alarm(0);
# Sum everything if -s and more than one storage
if ( defined ($o_sum) && ($num_int > 1) ) {
verb("Adding all entries");
$$result{$size_table . $tindex[0]} *= $$result{$alloc_units . $tindex[0]};
$$result{$used_table . $tindex[0]} *= $$result{$alloc_units . $tindex[0]};
$$result{$alloc_units . $tindex[0]} = 1;
for (my $i=1;$i<$num_int;$i++) {
$$result{$size_table . $tindex[0]} += ($$result{$size_table . $tindex[$i]}
* $$result{$alloc_units . $tindex[$i]});
$$result{$used_table . $tindex[0]} += ($$result{$used_table . $tindex[$i]}
* $$result{$alloc_units . $tindex[$i]});
}
$num_int=1;
$descr[0]="Sum of all $o_descr";
}
my $i=undef;
my $warn_state=0;
my $crit_state=0;
my ($p_warn,$p_crit);
my $output=undef;
for ($i=0;$i<$num_int;$i++) {
verb("Descr : $descr[$i]");
verb("Size : $$result{$size_table . $tindex[$i]}");
verb("Used : $$result{$used_table . $tindex[$i]}");
verb("Alloc : $$result{$alloc_units . $tindex[$i]}");
my $to = $$result{$size_table . $tindex[$i]} * $$result{$alloc_units . $tindex[$i]} / 1024**2;
my $pu=undef;
if ( $$result{$used_table . $tindex[$i]} != 0 ) {
$pu = $$result{$used_table . $tindex[$i]}*100 / $$result{$size_table . $tindex[$i]};
}else {
$pu=0;
}
my $bu = $$result{$used_table . $tindex[$i]} * $$result{$alloc_units . $tindex[$i]} / 1024**2;
my $pl = 100 - $pu;
my $bl = ($$result{$size_table . $tindex[$i]}- $$result{$used_table . $tindex[$i]}) * $$result{$alloc_units . $tindex[$i]} / 1024**2;
# add a ' ' if some data exists in $perf_out
$perf_out .= " " if (defined ($perf_out)) ;
##### Ouputs and checks
# Keep complete description fot performance output (in MB)
my $Pdescr=$descr[$i];
$Pdescr =~ s/'/_/g;
##### TODO : subs "," with something
if (defined($o_shortL[2])) {
if ($o_shortL[2] < 0) {$descr[$i]=substr($descr[$i],$o_shortL[2]);}
else {$descr[$i]=substr($descr[$i],0,$o_shortL[2]);}
}
if ($o_type eq "pu") { # Checks % used
my $locstate=0;
$p_warn=$o_warn*$to/100;$p_crit=$o_crit*$to/100;
(($pu >= $o_crit) && ($locstate=$crit_state=1))
|| (($pu >= $o_warn) && ($locstate=$warn_state=1));
if (defined($o_shortL[2])) {}
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
$output.=sprintf ("%s: %.0f%%used(%.0fMB/%.0fMB) ",$descr[$i],$pu,$bu,$to);
} elsif ($o_shortL[0] == 1) {
$output.=sprintf ("%s: %.0f%% ",$descr[$i],$pu);
}
$rrd_max = 100;
if (defined($rrd_data[0])) {
push @rrd_data, $pu;
} else {
$rrd_data[0]= $pu ;
}
}
if ($o_type eq 'bu') { # Checks MBytes used
my $locstate=0;
$p_warn=$o_warn;$p_crit=$o_crit;
( ($bu >= $o_crit) && ($locstate=$crit_state=1) )
|| ( ($bu >= $o_warn) && ($locstate=$warn_state=1) );
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
$output.=sprintf("%s: %.0fMBused/%.0fMB (%.0f%%) ",$descr[$i],$bu,$to,$pu);
} elsif ($o_shortL[0] == 1) {
$output.=sprintf("%s: %.0fMB ",$descr[$i],$bu);
}
$rrd_max = "U";
if (defined($rrd_data[0])) {
push @rrd_data, $bu;
} else {
$rrd_data[0]= $bu ;
}
}
if ($o_type eq 'bl') {
my $locstate=0;
$p_warn=$to-$o_warn;$p_crit=$to-$o_crit;
( ($bl <= $o_crit) && ($locstate=$crit_state=1) )
|| ( ($bl <= $o_warn) && ($locstate=$warn_state=1) );
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
$output.=sprintf ("%s: %.0fMBleft/%.0fMB (%.0f%%) ",$descr[$i],$bl,$to,$pl);
} elsif ($o_shortL[0] == 1) {
$output.=sprintf ("%s: %.0fMB ",$descr[$i],$bl);
}
$rrd_max = "U";
if (defined($rrd_data[0])) {
push @rrd_data, $pl;
} else {
$rrd_data[0]= $pl ;
}
}
if ($o_type eq 'pl') { # Checks % left
my $locstate=0;
$p_warn=(100-$o_warn)*$to/100;$p_crit=(100-$o_crit)*$to/100;
( ($pl <= $o_crit) && ($locstate=$crit_state=1) )
|| ( ($pl <= $o_warn) && ($locstate=$warn_state=1) );
if (!defined($o_shortL[0]) || ($locstate==1)) { # print full output if warn or critical state
$output.=sprintf ("%s: %.0f%%left(%.0fMB/%.0fMB) ",$descr[$i],$pl,$bl,$to);
} elsif ($o_shortL[0] == 1) {
$output.=sprintf ("%s: %.0f%% ",$descr[$i],$pl);
}
$rrd_max = 100;
if (defined($rrd_data[0])) {
push @rrd_data, $pl;
} else {
$rrd_data[0]= $pl ;
}
}
# Performance output (in MB)
$perf_out .= "'".$Pdescr. "'=" . round($bu,0) . "MB;" . round($p_warn,0)
. ";" . round($p_crit,0) . ";0;" . round($to,0);
}
##
## RRD management
##
if ($o_g) {
$start=time;
if (! -e $rrd) {
create_rrd($rrd,$#rrd_data+1,$start,$step,0,$rrd_max,"GAUGE");
}
update_rrd($rrd,$start,@rrd_data);
}
verb ("Perf data : $perf_out");
my $comp_oper=undef;
my $comp_unit=undef;
($o_type eq "pu") && ($comp_oper ="<") && ($comp_unit ="%");
($o_type eq "pl") && ($comp_oper =">") && ($comp_unit ="%");
($o_type eq "bu") && ($comp_oper ="<") && ($comp_unit ="MB");
($o_type eq 'bl') && ($comp_oper =">") && ($comp_unit ="MB");
if (!defined ($output)) { $output="All selected storages "; }
if ( $crit_state == 1) {
$comp_oper = ($comp_oper eq "<") ? ">" : "<"; # Inverse comp operator
if (defined($o_shortL[1])) {
print "CRITICAL : (",$comp_oper,$o_crit,$comp_unit,") ",$output;
} else {
print $output,"(",$comp_oper,$o_crit,$comp_unit,") : CRITICAL";
}
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
exit $ERRORS{"CRITICAL"};
}
if ( $warn_state == 1) {
$comp_oper = ($comp_oper eq "<") ? ">" : "<"; # Inverse comp operator
if (defined($o_shortL[1])) {
print "WARNING : (",$comp_oper,$o_warn,$comp_unit,") ",$output;
} else {
print $output,"(",$comp_oper,$o_warn,$comp_unit,") : WARNING";
}
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
exit $ERRORS{"WARNING"};
}
if (defined($o_shortL[1])) {
print "OK : (",$comp_oper,$o_warn,$comp_unit,") ",$output;
} else {
print $output,"(",$comp_oper,$o_warn,$comp_unit,") : OK";
}
(defined($o_perf)) ? print " | ",$perf_out,"\n" : print "\n";
exit $ERRORS{"OK"};

View File

@ -1,381 +0,0 @@
#!/usr/bin/perl -w
############################## check_snmp_win ##############
# Version : 0.5
# Date : Aug 22 2005
# Author : Patrick Proy (patrick at proy.org)
# Help : http://www.manubulon.com/nagios/
# Licence : GPL - http://www.fsf.org/licenses/gpl.txt
# TODO :
###############################################################
#
# help : ./check_snmp_win.pl -h
use strict;
use Net::SNMP;
use Getopt::Long;
# Nagios specific
use lib "@NAGIOS_PLUGINS@";
use utils qw(%ERRORS $TIMEOUT);
#my $TIMEOUT = 5;
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
# SNMP Datas for processes (MIB II)
my $process_table= '1.3.6.1.2.1.25.4.2.1';
my $index_table = '1.3.6.1.2.1.25.4.2.1.1';
my $run_name_table = '1.3.6.1.2.1.25.4.2.1.2';
my $run_path_table = '1.3.6.1.2.1.25.4.2.1.4';
my $proc_mem_table = '1.3.6.1.2.1.25.5.1.1.2'; # Kbytes
my $proc_cpu_table = '1.3.6.1.2.1.25.5.1.1.1'; # Centi sec of CPU
my $proc_run_state = '1.3.6.1.2.1.25.4.2.1.7';
# Windows SNMP DATA
my $win_serv_table = '1.3.6.1.4.1.77.1.2.3.1'; # Windows services table
my $win_serv_name = '1.3.6.1.4.1.77.1.2.3.1.1'; # Name of the service
# Install state : uninstalled(1), install-pending(2), uninstall-pending(3), installed(4)
my $win_serv_inst = '1.3.6.1.4.1.77.1.2.3.1.2';
# Operating state : active(1), continue-pending(2), pause-pending(3), paused(4)
my $win_serv_state = '1.3.6.1.4.1.77.1.2.3.1.3';
my %win_serv_state_label = ( 1 => 'active', 2=> 'continue-pending', 3=> 'pause-pending', 4=> 'paused');
# Can be uninstalled : cannot-be-uninstalled(1), can-be-uninstalled(2)
my $win_serv_uninst = '1.3.6.1.4.1.77.1.2.3.1.4';
# Globals
my $Version='0.5';
my $Name='check_snmp_win';
my $o_host = undef; # hostname
my $o_community =undef; # community
my $o_port = 161; # port
my $o_version2 = undef; #use snmp v2c
my $o_descr = undef; # description filter
my @o_descrL = undef; # Service descriprion list.
my $o_showall = undef; # Show all services even if OK
my $o_type = "service"; # Check type (service, ...)
my $o_number = undef; # Number of service for warn and crit levels
my $o_help= undef; # wan't some help ?
my $o_verb= undef; # verbose mode
my $o_version= undef; # print version
my $o_noreg= undef; # Do not use Regexp for name
my $o_timeout= 5; # Default 5s Timeout
# SNMP V3 specific
my $o_login= undef; # snmp v3 login
my $o_passwd= undef; # snmp v3 passwd
# functions
sub p_version { print "$Name version : $Version\n"; }
sub print_usage {
print "Usage: $Name [-v] -H <host> -C <snmp_community> [-2] | (-l login -x passwd) [-p <port>] -n <name>[,<name2] [-T=service] [-r] [-s] [-N=<n>] [-t <timeout>] [-V]\n";
}
sub isnotnum { # Return true if arg is not a number
my $num = shift;
if ( $num =~ /^-?(\d+\.?\d*)|(^\.\d+)$/ ) { return 0 ;}
return 1;
}
sub is_pattern_valid { # Test for things like "<I\s*[^>" or "+5-i"
my $pat = shift;
if (!defined($pat)) { $pat=" ";} # Just to get rid of compilation time warnings
return eval { "" =~ /$pat/; 1 } || 0;
}
# Get the alarm signal (just in case snmp timout screws up)
$SIG{'ALRM'} = sub {
print ("ERROR: Alarm signal (Nagios time-out)\n");
exit $ERRORS{"UNKNOWN"};
};
sub help {
print "\nSNMP Windows Monitor for Nagios version ",$Version,"\n";
print "GPL licence, (c)2004-2005 Patrick Proy\n\n";
print_usage();
print <<EOT;
-v, --verbose
print extra debugging information (and lists all services)
-h, --help
print this help message
-H, --hostname=HOST
name or IP address of host to check
-C, --community=COMMUNITY NAME
community name for the host's SNMP agent (implies SNMP v1 or v2c with option)
-2, --v2c
Use snmp v2c
-l, --login=LOGIN
Login for snmpv3 authentication (implies v3 protocol with MD5)
-x, --passwd=PASSWD
Password for snmpv3 authentication
-p, --port=PORT
SNMP port (Default 161)
-T, --type=service
Check type :
- service (default) checks service
-n, --name=NAME[,NAME2...]
Comma separated names of services (perl regular expressions can be used for every one).
By default, it is not case sensitive.
-N, --number=<n>
Compare matching services with <n> instead of the number of names provided.
-s, --showall
Show all services in the output, instead of only the non-active ones.
-r, --noregexp
Do not use regexp to match NAME in service description.
-t, --timeout=INTEGER
timeout for SNMP in seconds (Default: 5)
-V, --version
prints version number
Note :
The script will return
OK if ALL services are in active state,
WARNING if there is more than specified (ex 2 service specified, 3 active services matching),
CRITICAL if at least one of them is non active.
The -n option will allows regexp in perl format
-n "service" will match 'service WINS' 'sevice DNS' etc...
It is not case sensitive by default : WINS = wins
EOT
}
sub verb { my $t=shift; print $t,"\n" if defined($o_verb) ; }
sub decode_utf8 { # just replaces UFT8 caracters by "."
my $utfstr=shift;
if (substr($utfstr,0,2) ne "0x") { return $utfstr; }
my @stringL=split(//,$utfstr);
my $newstring="";
for (my $i=2;$i<$#stringL;$i+=2) {
if ( ($stringL[$i] . $stringL[$i+1]) eq "c3") {
$i+=2;$newstring .= ".";
} else {
$newstring .= chr(hex($stringL[$i] . $stringL[$i+1]));
}
}
return $newstring;
}
sub check_options {
Getopt::Long::Configure ("bundling");
GetOptions(
'v' => \$o_verb, 'verbose' => \$o_verb,
'h' => \$o_help, 'help' => \$o_help,
'H:s' => \$o_host, 'hostname:s' => \$o_host,
'p:i' => \$o_port, 'port:i' => \$o_port,
'C:s' => \$o_community, 'community:s' => \$o_community,
'l:s' => \$o_login, 'login:s' => \$o_login,
'x:s' => \$o_passwd, 'passwd:s' => \$o_passwd,
't:i' => \$o_timeout, 'timeout:i' => \$o_timeout,
'n:s' => \$o_descr, 'name:s' => \$o_descr,
'r' => \$o_noreg, 'noregexp' => \$o_noreg,
'T:s' => \$o_type, 'type:s' => \$o_type,
'N:i' => \$o_number, 'number:i' => \$o_number,
'2' => \$o_version2, 'v2c' => \$o_version2,
's' => \$o_showall, 'showall' => \$o_showall,
'V' => \$o_version, 'version' => \$o_version
);
if (defined ($o_help)) { help(); exit $ERRORS{"UNKNOWN"}};
if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"}};
# check snmp information
if ( !defined($o_community) && (!defined($o_login) || !defined($o_passwd)) )
{ print "Put snmp login info!\n"; print_usage(); exit $ERRORS{"UNKNOWN"}}
# Check compulsory attributes
if ( $o_type ne "service" ) {
print "Invalid check type !\n"; print_usage(); exit $ERRORS{"UNKNOWN"}
}
if ( ! defined($o_descr) || ! defined($o_host) ) { print_usage(); exit $ERRORS{"UNKNOWN"}};
@o_descrL=split(/,/,$o_descr);
foreach my $List (@o_descrL) {
if ( ! is_pattern_valid ($List) ) { print "Invalid pattern ! ";print_usage(); exit $ERRORS{"UNKNOWN"} }
}
if (defined ($o_number)) {
if (isnotnum($o_number) || ($o_number<0) )
{ print "Invalid number of services!\n";print_usage(); exit $ERRORS{"UNKNOWN"}}
}
}
########## MAIN #######
check_options();
# Check gobal timeout if snmp screws up
if (defined($TIMEOUT)) {
verb("Alarm at $TIMEOUT");
alarm($TIMEOUT);
} else {
verb("no timeout defined : $o_timeout + 10");
alarm ($o_timeout+10);
}
# Connect to host
my ($session,$error);
if ( defined($o_login) && defined($o_passwd)) {
# SNMPv3 login
verb("SNMPv3 login");
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => '3',
-username => $o_login,
-authpassword => $o_passwd,
-authprotocol => 'md5',
-privpassword => $o_passwd,
-timeout => $o_timeout
);
} else {
if (defined ($o_version2)) {
# SNMPv2 Login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-version => 2,
-community => $o_community,
-port => $o_port,
-timeout => $o_timeout
);
} else {
# SNMPV1 login
($session, $error) = Net::SNMP->session(
-hostname => $o_host,
-community => $o_community,
-port => $o_port,
-timeout => $o_timeout
);
}
}
$session->max_msg_size(5000);
verb($session->max_msg_size);
#print $session->max_msg_size(),"\n";
if (!defined($session)) {
printf("ERROR: %s.\n", $error);
exit $ERRORS{"UNKNOWN"};
}
# Look for process in name or path name table
my $resultat=undef;
$resultat = (Net::SNMP->VERSION < 4) ?
$session->get_table($win_serv_name)
: $session->get_table(Baseoid => $win_serv_name);
if (!defined($resultat)) {
printf("ERROR: Process name table : %s.\n", $session->error);
$session->close;
exit $ERRORS{"UNKNOWN"};
}
my @tindex = undef;
my @oids = undef;
my @descr = undef;
my $num_int = 0;
my $count_oid = 0;
# Select storage by regexp of exact match
# and put the oid to query in an array
verb("Filter : $o_descr");
foreach my $key ( keys %$resultat) {
my $descr_d=decode_utf8($$resultat{$key});
verb("Desc : $descr_d");
# test by regexp or exact match
my $test=undef;
foreach my $List (@o_descrL) {
if (!($test)) {
$test = defined($o_noreg)
? $descr_d eq $List
: $descr_d =~ /$List/i;
}
}
if ($test) {
# get the full description
$descr[$num_int]=$descr_d;
# get the index number of the process
$key =~ s/$win_serv_name\.//;
$tindex[$num_int] = $key;
# put the oid of running state in an array.
$oids[$count_oid++]=$win_serv_state . "." . $tindex[$num_int];
verb("Name : $descr[$num_int], Index : $tindex[$num_int]");
$num_int++;
}
}
if ( $num_int == 0) {
if (defined ($o_number) && ($o_number ==0)) {
print "No services ",(defined ($o_noreg)) ? "named \"" : "matching \"", $o_descr, "\" found : OK\n";
exit $ERRORS{"OK"};
} else {
print "No services ",(defined ($o_noreg)) ? "named \"" : "matching \"", $o_descr, "\" found : CRITICAL\n";
exit $ERRORS{"CRITICAL"};
}
}
my $result=undef;
my $num_int_ok=0;
$result = (Net::SNMP->VERSION < 4) ?
$session->get_request(@oids)
: $session->get_request(Varbindlist => \@oids);
if (!defined($result)) { printf("ERROR: running table : %s.\n", $session->error); $session->close;
exit $ERRORS{"UNKNOWN"};
}
$session->close;
my $output=undef;
#Check if service are in active state
for (my $i=0; $i< $num_int; $i++) {
my $state=$$result{$win_serv_state . "." . $tindex[$i]};
verb ("Process $tindex[$i] in state $state");
if ($state == 1) {
$num_int_ok++
} else {
$output .= ", " if defined($output);
$output .= $descr[$i] . " : " . $win_serv_state_label{$state};
}
}
my $force_critical=0;
# Show the services that are not present
# Or all of them with -s option
foreach my $List (@o_descrL) {
my $test=0;
for (my $i=0; $i< $num_int; $i++) {
if ( $descr[$i] =~ /$List/i ) { $test++; }
}
if ($test==0) {
$output .= ", " if defined($output);
$output .= "\"" . $List . "\" not active";
# Force a critical state (could otherwise lead to false OK)
$force_critical=1;
} elsif ( defined ($o_showall) ) {
$output .= ", " if defined($output);
$output .= "\"" . $List . "\" active";
if ($test != 1) {
$output .= "(" .$test . " services)";
}
}
}
if (defined ($output) ) {
print $output, " : ";
} else {
print $num_int_ok, " services active (", (defined ($o_noreg)) ? "named \"" : "matching \"", $o_descr, "\") : ";
}
$o_number = $#o_descrL+1 if (!defined($o_number));
if (($num_int_ok < $o_number)||($force_critical == 1)) {
print "CRITICAL\n";
exit $ERRORS{"CRITICAL"};
} elsif ($num_int_ok > $o_number) {
print "WARNING\n";
exit $ERRORS{"WARNING"};
}
print "OK\n";
exit $ERRORS{"OK"};

View File

@ -1,49 +0,0 @@
[GLOBAL]
DIR_OREON=@INSTALL_DIR_OREON@/
DIR_TRAFFICMAP=@INSTALL_DIR_OREON@/include/trafficMap/average/
DIR_NAGIOS=@INSTALL_DIR_NAGIOS@/
DIR_RRDTOOL=@INSTALL_DIR_OREON@/rrd/
NAGIOS_LIBEXEC=@NAGIOS_PLUGINS@/
NAGIOS_ETC=@NAGIOS_ETC@/
[NT]
CPU=.1.3.6.1.2.1.25.3.3.1.2
HD_USED=.1.3.6.1.2.1.25.2.3.1.6
HD_NAME=.1.3.6.1.2.1.25.2.3.1.3
[CISCO]
NB_CONNECT=.1.3.6.1.4.1.9.9.147.1.2.2.2.1.5.40.6
[UNIX]
CPU_USER=.1.3.6.1.4.1.2021.11.50.0
CPU_SYSTEM=.1.3.6.1.4.1.2021.11.52.0
CPU_LOAD_1M =.1.3.6.1.4.1.2021.10.1.3.1
CPU_LOAD_5M =.1.3.6.1.4.1.2021.10.1.3.2
CPU_LOAD_15M =.1.3.6.1.4.1.2021.10.1.3.3
[DELL]
TEMP=.1.3.6.1.4.1.674.10892.1.700.20.1.6.1
[ALTEON]
VIRT=1.3.6.1.4.1.1872.2.1.8.2.7.1.3.1
FRONT=1.3.6.1.4.1.1872.2.1.8.2.5.1.3.1
[MIB2]
SW_RUNNAME=.1.3.6.1.2.1.25.4.2.1.2
SW_RUNINDEX=.1.3.6.1.2.1.25.4.2.1.1
SW_RUNSTATUS=.1.3.6.1.2.1.25.4.2.1.7
HR_STORAGE_DESCR=.1.3.6.1.2.1.25.2.3.1.3
HR_STORAGE_ALLOCATION_UNITS=.1.3.6.1.2.1.25.2.3.1.4
HR_STORAGE_SIZE=.1.3.6.1.2.1.25.2.3.1.5
HR_STORAGE_USED=.1.3.6.1.2.1.25.2.3.1.6
OBJECTID=.1.3.6.1.2.1.1.1.0
UPTIME_WINDOWS=.1.3.6.1.2.1.1.3.0
UPTIME_OTHER=.1.3.6.1.2.1.25.1.1.0
IF_IN_OCTET=.1.3.6.1.2.1.2.2.1.10
IF_OUT_OCTET=.1.3.6.1.2.1.2.2.1.16
IF_SPEED=.1.3.6.1.2.1.2.2.1.5
IF_DESC=.1.3.6.1.2.1.2.2.1.2
IF_IN_ERROR=.1.3.6.1.2.1.2.2.1.14
IF_OUT_ERROR=.1.3.6.1.2.1.2.2.1.20

View File

@ -1,218 +0,0 @@
#
# $Id: check_graph_ping.pl,v 1.2 2005/07/27 22:21:49 wistof Exp $
#
# Oreon's plugins are developped with GPL Licence :
# http://www.fsf.org/licenses/gpl.txt
# Developped by : Mathieu Chateau - Christophe Coraboeuf
#
# The Software is provided to you AS IS and WITH ALL FAULTS.
# OREON makes no representation and gives no warranty whatsoever,
# whether express or implied, and without limitation, with regard to the quality,
# safety, contents, performance, merchantability, non-infringement or suitability for
# any particular or intended purpose of the Software found on the OREON web site.
# In no event will OREON be liable for any direct, indirect, punitive, special,
# incidental or consequential damages however they may arise and even if OREON has
# been previously advised of the possibility of such damages.
package oreon;
use Exporter ();
use FindBin qw($Bin);
use lib "$FindBin::Bin";
use lib "@NAGIOS_PLUGINS@";
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
use utils qw($TIMEOUT %ERRORS &print_revision &support);
if (eval "require Config::IniFiles" ) {
use Config::IniFiles;
} else {
print "Unable to load Config::IniFiles\n";
exit $ERRORS{'UNKNOWN'};
}
### RRDTOOL Module
use lib qw(@RRDTOOL_PERL_LIB@ ../lib/perl);
if (eval "require RRDs" ) {
use RRDs;
} else {
print "Unable to load RRDs perl module\n";
exit $ERRORS{'UNKNOWN'};
}
# On défini une version pour les vérifications
#$VERSION = do { my @r = (q$Revision: XXX $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(get_parameters create_rrd update_rrd fetch_rrd &is_valid_serviceid);
our @EXPORT = @EXPORT_OK;
my $params_file="oreon.conf";
my @ds = ("a","b","c","d","e","f","g","h","i","j","k","l");
###############################################################################
# Get all parameters from the ini file
###############################################################################
sub get_parameters
{
$params_file = "@NAGIOS_PLUGINS@/$params_file";
unless (-e $params_file)
{
print "Unknown - In oreon.pm :: $params_file :: $!\n";
exit $ERRORS{'UNKNOWN'};
}
my %oreon;
tie %oreon, 'Config::IniFiles', ( -file => $params_file );
return %oreon;
}
###############################################################################
# Create RRD file
###############################################################################
sub create_rrd($$$$$$$)
{
my @rrd_arg;
my ($rrd, $nb_ds ,$start, $step, $min, $max, $type) = @_;
$nb_ds = 1 unless($nb_ds);
$start = time unless($start);
$step = 300 unless($step);
$min = "U" unless($min);
$max = "U" unless($max);
$type = "GAUGE" unless($type);
my $ERROR = RRDs::error;
@rrd_arg=($rrd,
"--start",
$start-1,
"--step",
$step);
for ($i = 0; $i < $nb_ds; $i++) {
push(@rrd_arg,"DS:".$ds[$i].":$type:".($step * 2).":".$min.":".$max);
}
push(@rrd_arg,"RRA:AVERAGE:0.5:1:8640",
"RRA:MIN:0.5:12:8640",
"RRA:MAX:0.5:12:8640");
RRDs::create (@rrd_arg);
$ERROR = RRDs::error;
if ($ERROR) {
print "unable to create '$rrd' : $ERROR\n" ;
exit 3;
}
}
###############################################################################
# Update RRD file
###############################################################################
sub update_rrd($$@)
{
my @rrd_arg;
my ($rrd, $start,@values) = @_;
$start = time unless($start);
my $ERROR = RRDs::error;
for (@values) {
s/,/\./ ;
$str_value .= ":" . $_;
}
RRDs::update ($rrd, "$start$str_value");
$ERROR = RRDs::error;
if ($ERROR) {
print "unable to update '$rrd' : $ERROR\n" ;
exit 3;
}
}
###############################################################################
# Fetch RRD file
###############################################################################
sub fetch_rrd($$)
{
my ($line, $val, @valeurs, $update_time, $step, $ds_names, $data, $i) ;
my ($rrd, $CF,@values) = @_;
$start = time unless($start);
my $ERROR = RRDs::error;
($update_time,$step,$ds_names,$data) = RRDs::fetch($rrd, "--resolution=300","--start=now-5min","--end=now",$CF);
$ERROR = RRDs::error;
if ($ERROR) {
print "unable to update '$rrd' : $ERROR\n" ;
exit 3;
}
foreach $line (@$data) {
foreach $val (@$line) {
if ( defined $val ) { $valeur[$i]=$val; } else { $valeur[$i]="undef"; }
$i++;
}
}
return @valeur;
}
###############################################################################
# Is a valid ServiceId
###############################################################################
sub is_valid_serviceid {
my $ServiceId = shift;
if ($ServiceId && $ServiceId =~ m/^([0-9_]+)$/) {
return $ServiceId;
}else{
print "Unknown -S Service ID expected... or it doesn't exist, try another id - number\n";
exit $ERRORS{'UNKNOWN'};
}
}
1;
__END__
=head1 NAME
Oreon - shared module for Oreon plugins
=head1 SYNOPSIS
use oreon;
oreon::get_parameters()
oreon::create_rrd( )
oreon::update_rrd( )
=head1 DESCRIPTION
=head2 Functions
B<oreon::create_rrd> create a rrd database.
create_rrd($rrd, $nb_ds ,$start, $step, $min, $max, $type );
$rrd : RRD filename
$nb_ds : Number of Data Sources to create
$start : Start time of RRD
$step : RRD step
$min : Minimum value in RRD
$max : Maximum value in RRD
$type : GAUGE or COUNTER
update_rrd($rrd, $start,@values);
$rrd : RRD filename to update
$start :
@values : update RRD with list values
=head1 AUTHOR
Mathieu Chateau E<lt>mathieu.chateau@lsafrance.comE<gt>
Christophe Coraboeuf E<lt>ccoraboeuf@oreon-project.orgE<gt>
=cut

View File

@ -1,10 +0,0 @@
# some parameters passed on command line
TIMET=$1
HOSTNAME=$2
SERVICEDESC=$3
OUTPUT=$4
SERVICESTATE=$5
PERFDATA=$6
PERFFILE="@INSTALL_DIR_NAGIOS@var/service-perfdata"
/usr/bin/printf "%b" "$TIMET\t$HOSTNAME\t$SERVICEDESC\t$OUTPUT\t$SERVICESTATE\t$PERFDATA\n" >> $PERFFILE

View File

@ -1,34 +0,0 @@
#!/bin/sh
# Arguments:
# $1 = host_name (Short name of host that the service is
# associated with)
# $2 = state_string (A string representing the status of
# the given service - "UP", "DOWN", "UNREACHABLE"
# $3 = plugin_output (A text string that should be used
# as the plugin output for the service checks)
#
# pipe the service check info into the send_nsca program, which
# in turn transmits the data to the nsca daemon on the central
# monitoring server
return_code=-1
case "$2" in
UP)
return_code=0
;;
DOWN)
return_code=1
;;
UNREACHABLE)
return_code=2
;;
esac
# Test everything works fine
#/usr/bin/printf "%s\t%s\t%s\n" "$1" "$2" "$3" >> /tmp/test
/usr/bin/printf "%s\t%s\t%s\n" "$1" "$return_code" "$3" | /usr/sbin/send_nsca IP -p PORT -c /etc/send_nsca.cfg

View File

@ -1,38 +0,0 @@
#!/bin/sh
# Arguments:
# $1 = host_name (Short name of host that the service is
# associated with)
# $2 = svc_description (Description of the service)
# $3 = state_string (A string representing the status of
# the given service - "OK", "WARNING", "CRITICAL"
# or "UNKNOWN")
# $4 = plugin_output (A text string that should be used
# as the plugin output for the service checks)
#
# pipe the service check info into the send_nsca program, which
# in turn transmits the data to the nsca daemon on the central
# monitoring server
return_code=-1
case "$3" in
OK)
return_code=0
;;
WARNING)
return_code=1
;;
CRITICAL)
return_code=2
;;
UNKNOWN)
return_code=-1
;;
esac
# Test everything works fine
#/usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$3" "$4" >> /tmp/test
/usr/bin/printf "%s\t%s\t%s\t%s\n" "$1" "$2" "$return_code" "$4" | /usr/sbin/send_nsca IP -p PORT -c /etc/send_nsca.cfg

View File

@ -1,76 +0,0 @@
###########################################################################
#
# snmptrapd.conf
#
# - created by the snmpconf configuration program
#
###########################################################################
# SECTION: Trap Handlers
#
# Here we define what programs are run when a trap is
# received by the trap receiver.
# traphandle: When traps are received, a program can be run.
# When traps are received, the list of configured trap
# handles is consulted and any configured program is run.
# If no handler is found, any handler with "default" as the
# traphandle type is run instead. The information contained
# in trap is passed to the program via standard input (see
# the snmptrapd.conf manual page for details).
#
# arguments: oid|"default" program args
traphandle default /usr/sbin/snmptt --ini=@SNMPTT_INI_FILE@
###########################################################################
# SECTION: Runtime options
#
# Runtime options
# donotfork: Do not fork from the shell
# arguments: (1|yes|true|0|no|false)
donotfork 1
# pidfile: Store Process ID in file
# arguments: PID file
pidfile /var/run/snmptrapd.pid
###########################################################################
# SECTION: Logging options
#
# Logging options
# donotlogtraps: Prevent traps from being logged
# Useful when you only want to use traphandles
# arguments: (1|yes|true|0|no|false)
donotlogtraps 0
###########################################################################
# SECTION: Authentication options
#
# Authentication options
# ignoreauthfailure: Ignore authentication failure traps
# arguments: (1|yes|true|0|no|false)
ignoreauthfailure 0
ignoreauthfailure no
#
# Unknown directives read in from other files by snmpconf
#
disableAuthorization yes

File diff suppressed because it is too large Load Diff

View File

@ -1,489 +0,0 @@
#
# SNMPTT v1.0 Configuration File
#
# Linux / Unix
#
[General]
# Set to either 'standalone' or 'daemon'
# standalone: snmptt called from snmptrapd.conf
# daemon: snmptrapd.conf calls snmptthandler
# Ignored by Windows. See documentation
mode = standalone
# Set to 1 to allow multiple trap definitions to be executed for the same trap.
# Set to 0 to have it stop after the first match.
# Note: Wildcard matches are only matched if there are NO exact matches. This takes
# into consideration the NODES list. Therefore, if there is a matching trap, but
# the NODES list prevents it from being considered a match, the wildcard entry will
# only be used if there are no other exact matches.
multiple_event = 1
# SNMPTRAPD passes the IP address of device sending the trap, and the IP address of the
# actual SNMP agent. These addresses could differ if the trap was sent on behalf of another
# device (relay, proxy etc).
# If DNS is enabled, the agent IP address is converted to a host name using a DNS lookup
# (which includes the local hosts file, depending on how the OS is configured). This name
# will be used for: NODES entry matches, hostname field in logged traps (file / database),
# and the $A variable. Host names on the NODES line will be resolved and the IP address
# will then be used for comparing.
# Set to 0 to disable DNS resolution
# Set to 1 to enable DNS resolution
dns_enable = 0
# Set to 0 to enable the use of FQDN (Fully Qualified Domain Names). If a host name is
# passed to SNMPTT that contains a domain name, it will not be altered in any way by
# SNMPTT. This also affects resolve_value_ip_addresses.
# Set to 1 to have SNMPTT strip the domain name from the host name passed to it. For
# example, server01.domain.com would be changed to server01
# Set to 2 to have SNMPTT strip the domain name from the host name passed to it
# based on the list of domains in strip_domain_list
strip_domain = 0
# List of domain names that should be stripped when strip_domain is set to 2.
# List can contain one or more domains. For example, if the FQDN of a host is
# server01.city.domain.com and the list contains domain.com, the 'host' will be
# set as server01.city.
strip_domain_list = <<END
merethis.net
END
# Configures how IP addresses contained in the VALUE of the variable bindings are handled.
# This only applies to the values for $n, $+n, $-n, $vn, $+*, $-*.
# Set to 0 to disable resolving ip address to host names
# Set to 1 to enable resolving ip address to host names
# Note: net_snmp_perl_enable *must* be enabled. The strip_domain settings influence the
# format of the resolved host name. DNS must be enabled (dns_enable)
resolve_value_ip_addresses = 0
# Set to 1 to enable the use of the Perl module from the UCD-SNMP / NET-SNMP package.
# This is required for $v variable substitution to work, and also for some other options
# that are enabled in this .ini file.
# Set to 0 to disable the use of the Perl module from the UCD-SNMP / NET-SNMP package.
# Note: Enabling this with stand-alone mode can cause SNMPTT to run very slowly due to
# the loading of the MIBS at startup.
net_snmp_perl_enable = 1
# This sets the best_guess parameter used by the UCD-SNMP / NET-SNMP Perl module for
# translating symbolic nams to OIDs and vice versa.
# For UCD-SNMP, and Net-SNMP 5.0.8 and previous versions, set this value to 0.
# For Net-SNMP 5.0.9, or any Net-SNMP with patch 722075 applied, set this value to 2.
# A value of 2 is equivalent to -IR on Net-SNMP command line utilities.
# UCD-SNMP and Net-SNMP 5.0.8 and previous may not be able to translate certain formats of
# symbolic names such as RFC1213-MIB::sysDescr. Net-SNMP 5.0.9 or patch 722075 will allow
# all possibilities to be translated. See the FAQ section in the README for more info
net_snmp_perl_best_guess = 0
# Configures how the OID of the received trap is handled when outputting to a log file /
# database. It does NOT apply to the $O variable.
# Set to 0 to use the default of numerical OID
# Set to 1 to translate the trap OID to short text (symbolic form) (eg: linkUp)
# Set to 2 to translate the trap OID to short text with module name (eg: IF-MIB::linkUp)
# Set to 3 to translate the trap OID to long text (eg: iso...snmpTraps.linkUp)
# Set to 4 to translate the trap OID to long text with module name (eg:
# IF-MIB::iso...snmpTraps.linkUp)
# Note: -The output of the long format will vary depending on the version of Net-SNMP you
# are using.
# -net_snmp_perl_enable *must* be enabled
# -If using database logging, ensure the trapoid column is large enough to hold the
# entire line
translate_log_trap_oid = 0
# Configures how OIDs contained in the VALUE of the variable bindings are handled.
# This only applies to the values for $n, $+n, $-n, $vn, $+*, $-*. For substitutions
# that include variable NAMES ($+n etc), only the variable VALUE is affected.
# Set to 0 to disable translating OID values to text (symbolic form)
# Set to 1 to translate OID values to short text (symbolic form) (eg: BuildingAlarm)
# Set to 2 to translate OID values to short text with module name (eg: UPS-MIB::BuildingAlarm)
# Set to 3 to translate OID values to long text (eg: iso...upsAlarm.BuildingAlarm)
# Set to 4 to translate OID values to long text with module name (eg:
# UPS-MIB::iso...upsAlarm.BuildingAlarm)
# For example, if the value contained: 'A UPS Alarm (.1.3.6.1.4.1.534.1.7.12) has cleared.',
# it could be translated to: 'A UPS Alarm (UPS-MIB::BuildingAlarm) has cleared.'
# Note: net_snmp_perl_enable *must* be enabled
translate_value_oids = 1
# Configures how the symbolic enterprise OID will be displayed for $E.
# Set to 1, 2, 3 or 4. See translate_value_oids options 1,2,3 and 4.
# Note: net_snmp_perl_enable *must* be enabled
translate_enterprise_oid_format = 1
# Configures how the symbolic trap OID will be displayed for $O.
# Set to 1, 2, 3 or 4. See translate_value_oids options 1,2,3 and 4.
# Note: net_snmp_perl_enable *must* be enabled
translate_trap_oid_format = 1
# Configures how the symbolic trap OID will be displayed for $v, $-n, $+n, $-* and $+*.
# Set to 1, 2, 3 or 4. See translate_value_oids options 1,2,3 and 4.
# Note: net_snmp_perl_enable *must* be enabled
translate_varname_oid_format = 1
# Set to 0 to disable converting INTEGER values to enumeration tags as defined in the
# MIB files
# Set to 1 to enable converting INTEGER values to enumeration tags as defined in the
# MIB files
# Example: moverDoorState:open instead of moverDoorState:2
# Note: net_snmp_perl_enable *must* be enabled
translate_integers = 1
# Allows you to set the MIBS environment variable used by SNMPTT
# Leave blank or comment out to have the systems enviroment settings used
# To have all MIBS processed, set to ALL
# See the snmp.conf manual page for more info
#mibs_environment = ALL
# Set what is used to separate variables when wildcards are expanded on the FORMAT /
# EXEC line. Defaults to a space. Value MUST be within quotes. Can contain 1 or
# more characters
wildcard_expansion_separator = " "
# Set to 1 to allow unsafe REGEX code to be executed.
# Set to 0 to prevent unsafe REGEX code from being executed (default).
# Enabling unsafe REGEX code will allow variable interopolation and the use of the e
# modifier to allow statements such as substitution with captures such
# as: (one (two) three)(five $1 six)
# which outputs: five two six
# or: (one (two) three)("five ".length($1)." six")e
# which outputs: five 3 six
#
# This is considered unsafe because the contents of the regular expression
# (right) is executed (eval) by Perl which *could contain unsafe code*.
# BE SURE THAT THE SNMPTT CONFIGURATION FILES ARE SECURE!
allow_unsafe_regex = 0
# Set to 1 to have the backslash (escape) removed from quotes passed from
# snmptrapd. For example, \" would be changed to just "
# Set to 0 to disable
remove_backslash_from_quotes = 0
# Set to 1 to have NODES files loaded each time a trap is processed.
# Set to 0 to have all NODES files loaded when the snmptt.conf files are loaded.
# If NODES files are used (files that contain lists of NODES), then setting to 1
# will cause the list to be loaded each time an EVENT is processed that uses
# NODES files. This will allow the NODES file to be modified while SNMPTT is
# running but can result in many file reads depending on the number of traps
# received. Defaults to 0
dynamic_nodes = 0
# This option allows you to use the $D substitution variable to include the
# description text from the SNMPTT.CONF or MIB files.
# Set to 0 to disable the $D substitution variable. If $D is used, nothing
# will be outputted.
# Set to 1 to enable the $D substitution variable and have it use the
# descriptions stored in the SNMPTT .conf files. Enabling this option can
# greatly increase the amount of memory used by SNMPTT.
# Set to 2 to enable the $D substitution variable and have it use the
# description from the MIB files. This enables the UCD-SNMP / NET-SNMP Perl
# module save_descriptions variable. Enabling this option can greatly
# increase the amount of memory used by the Net-SNMP SNMP Perl module, which
# will result in an increase of memory usage by SNMPTT.
description_mode = 0
# Set to 1 to remove any white space at the start of each line from the MIB
# or SNMPTT.CONF description when description_mode is set to 1 or 2.
description_clean = 1
[DaemonMode]
# Set to 1 to have snmptt fork to the background when run in daemon mode
# Ignored by Windows. See documentation
daemon_fork = 1
# Set to the numerical user id (eg: 500) or textual user id (eg: snmptt)
# that snmptt should change to when running in daemon mode. Leave blank
# to disable. The user used should have read/write access to all log
# files, the spool folder, and read access to the configuration files.
daemon_uid = root
# Directory to read received traps from. Ex: /var/spool/snmptt/
# Don't forget the trailing slash!
spool_directory = /var/spool/snmptt/
# Amount of time in seconds to sleep between processing spool files
sleep = 2
# Set to 1 to have SNMPTT use the time that the trap was processed by SNMPTTHANDLER
# Set to 0 to have SNMPTT use the time the trap was processed. Note: Using 0 can
# result in the time being off by the number of seconds used for 'sleep'
use_trap_time = 1
# Set to 0 to have SNMPTT erase the spooled trap file after it attempts to process
# the trap even if it did not successfully log the trap to any of the log systems.
# Set to 1 to have SNMPTT erase the spooled trap file only after it successfully
# logs to at least ONE log system.
# Set to 2 to have SNMPTT erase the spooled trap file only after it successfully
# logs to ALL of the enabled log systems. Warning: If multiple log systems are
# enabled and only one fails, the other log system will continuously be logged to
# until ALL of the log systems function.
# The recommended setting is 1 with only one log system enabled.
keep_unlogged_traps = 1
[Logging]
# Set to 1 to enable messages to be sent to standard output, or 0 to disable.
# Would normally be disabled unless you are piping this program to another
stdout_enable = 0
# Set to 1 to enable text logging. Make sure you specify a logfile location
log_enable = 1
# Log file location. The COMPLETE path and filename. Ex: '/var/log/snmptt.log'
log_file = /var/log/snmptt.log
# Set to 1 to enable logging of unknown traps. This should normally be left off
# as the file could grow large quickly. Used primarily for troubleshooting. If
# you have defined a trap in snmptt.conf, but it is not executing, enable this to
# see if it is being considered an unknown trap due to an incorrect entry or
# simply missing from the snmptt.conf file.
# Unknown traps can be logged either a text file, a SQL table or both.
# See SQL section to define SQL table to log unknown traps to.
unknown_trap_log_enable = 1
# Unknown trap log file location. The COMPLETE path and filename.
# Ex: '/var/log/snmpttunknown.log'
# Leave blank to disable logging to text file if logging to SQL is enabled
# for unknown traps
unknown_trap_log_file = /var/log/snmpttunknown.log
# How often in seconds statistics should be logged to syslog or the event log.
# Set to 0 to disable
# 1 hour = 216000
# 12 hours = 2592000
# 24 hours = 5184000
statistics_interval = 0
# Set to 1 to enable logging of *TRAPS* to syslog. If you do not have the Sys::Syslog
# module then disable this. Windows users should disable this.
syslog_enable = 0
# Syslog facility to use for logging of *TRAPS*. For example: 'local0'
syslog_facility = local0
# Set the syslog level for *TRAPS* based on the severity level of the trap
# as defined in the snmptt.conf file. Values must be one per line between
# the syslog_level_* and END lines, and are not case sensitive. For example:
# Warning
# Critical
# Duplicate definitions will use the definition with the higher severity.
syslog_level_debug = <<END
END
syslog_level_info = <<END
END
syslog_level_notice = <<END
END
syslog_level_warning = <<END
END
syslog_level_err = <<END
END
syslog_level_crit = <<END
END
syslog_level_alert = <<END
END
# Syslog default level to use for logging of *TRAPS*. For example: warning
# Valid values: emerg, alert, crit, err, warning, notice, info, debug
syslog_level = info
# Set to 1 to enable logging of *SNMPTT system errors* to syslog. If you do not have the
# Sys::Syslog module then disable this. Windows users should disable this.
syslog_system_enable = 1
# Syslog facility to use for logging of *SNMPTT system errors*. For example: 'local0'
syslog_system_facility = local0
# Syslog level to use for logging of *SNMPTT system errors*.. For example: 'warning'
# Valid values: emerg, alert, crit, err, warning, notice, info, debug
syslog_system_level = err
[SQL]
# Determines if the enterprise column contains the numeric OID or symbolic OID
# Set to 0 for numeric OID
# Set to 1 for symbolic OID
# Uses translate_enterprise_oid_format to determine format
# Note: net_snmp_perl_enable *must* be enabled
db_translate_enterprise = 0
# FORMAT line to use for unknown traps. If not defined, defaults to $-*.
db_unknown_trap_format = '$-*'
# MySQL: Set to 1 to enable logging to a MySQL database via DBI (Linux / Windows)
# This requires DBI:: and DBD::mysql
mysql_dbi_enable = 0
# MySQL: Hostname of database server (optional - default localhost)
mysql_dbi_host = localhost
# MySQL: Port number of database server (optional - default 3306)
mysql_dbi_port = 3306
# MySQL: Database to use
mysql_dbi_database = snmptt
# MySQL: Table to use
mysql_dbi_table = snmptt
# MySQL: Table to use for unknown traps
# Leave blank to disable logging of unknown traps to MySQL
# Note: unknown_trap_log_enable must be enabled.
mysql_dbi_table_unknown = snmptt_unknown
# MySQL: Username to use
mysql_dbi_username = snmpttuser
# MySQL: Password to use
mysql_dbi_password = password
# MySQL: Whether or not to 'ping' the database before attempting an INSERT
# to ensure the connection is still valid. If *any* error is generate by
# the ping such as 'Unable to connect to database', it will attempt to
# re-create the database connection.
# Set to 0 to disable
# Set to 1 to enable
# Note: This has no effect on mysql_ping_interval.
mysql_ping_on_insert = 1
# MySQL: How often in seconds the database should be 'pinged' to ensure the
# connection is still valid. If *any* error is generate by the ping such as
# 'Unable to connect to database', it will attempt to re-create the database
# connection. Set to 0 to disable pinging.
# Note: This has no effect on mysql_ping_on_insert.
# disabled = 0
# 5 minutes = 300
# 15 minutes = 900
# 30 minutes = 1800
mysql_ping_interval = 300
# PostgreSQL: Set to 1 to enable logging to a PostgreSQL database via DBI (Linux / Windows)
# This requires DBI:: and DBD::PgPP
postgresql_dbi_enable = 0
# Set to 0 to use the DBD::PgPP module
# Set to 1 to use the DBD::Pg module
postgresql_dbi_module = 0
# Set to 0 to disable host and port network support
# Set to 1 to enable host and port network support
# If set to 1, ensure PostgreSQL is configured to allow connections via TCPIP by setting
# tcpip_socket = true in the $PGDATA/postgresql.conf file, and adding the ip address of
# the SNMPTT server to $PGDATApg_hba.conf. The common location for the config files for
# RPM installations of PostgreSQL is /var/lib/pgsql/data.
postgresql_dbi_hostport_enable = 0
# PostgreSQL: Hostname of database server (optional - default localhost)
postgresql_dbi_host = localhost
# PostgreSQL: Port number of database server (optional - default 5432)
postgresql_dbi_port = 5432
# PostgreSQL: Database to use
postgresql_dbi_database = snmptt
# PostgreSQL: Table to use for unknown traps
# Leave blank to disable logging of unknown traps to PostgreSQL
# Note: unknown_trap_log_enable must be enabled.
postgresql_dbi_table_unknown = snmptt_unknown
# PostgreSQL: Table to use
postgresql_dbi_table = snmptt
# PostgreSQL: Username to use
postgresql_dbi_username = snmpttuser
# PostgreSQL: Password to use
postgresql_dbi_password = password
# PostgreSQL: Whether or not to 'ping' the database before attempting an INSERT
# to ensure the connection is still valid. If *any* error is generate by
# the ping such as 'Unable to connect to database', it will attempt to
# re-create the database connection.
# Set to 0 to disable
# Set to 1 to enable
# Note: This has no effect on postgresqll_ping_interval.
postgresql_ping_on_insert = 1
# PostgreSQL: How often in seconds the database should be 'pinged' to ensure the
# connection is still valid. If *any* error is generate by the ping such as
# 'Unable to connect to database', it will attempt to re-create the database
# connection. Set to 0 to disable pinging.
# Note: This has no effect on postgresql_ping_on_insert.
# disabled = 0
# 5 minutes = 300
# 15 minutes = 900
# 30 minutes = 1800
postgresql_ping_interval = 300
# ODBC: Set to 1 to enable logging to a database via ODBC using DBD::ODBC.
# This requires both DBI:: and DBD::ODBC
dbd_odbc_enable = 0
# DBD:ODBC: Database to use
dbd_odbc_dsn = snmptt
# DBD:ODBC: Table to use
dbd_odbc_table = snmptt
# DBD:ODBC: Table to use for unknown traps
# Leave blank to disable logging of unknown traps to DBD:ODBC
# Note: unknown_trap_log_enable must be enabled.
dbd_odbc_table_unknown = snmptt_unknown
# DBD:ODBC: Username to use
dbd_odbc_username = snmptt
# DBD:DBC:: Password to use
dbd_odbc_password = password
# DBD:ODBC: Whether or not to 'ping' the database before attempting an INSERT
# to ensure the connection is still valid. If *any* error is generate by
# the ping such as 'Unable to connect to database', it will attempt to
# re-create the database connection.
# Set to 0 to disable
# Set to 1 to enable
# Note: This has no effect on dbd_odbc_ping_interval.
dbd_odbc_ping_on_insert = 1
# DBD:ODBC:: How often in seconds the database should be 'pinged' to ensure the
# connection is still valid. If *any* error is generate by the ping such as
# 'Unable to connect to database', it will attempt to re-create the database
# connection. Set to 0 to disable pinging.
# Note: This has no effect on dbd_odbc_ping_on_insert.
# disabled = 0
# 5 minutes = 300
# 15 minutes = 900
# 30 minutes = 1800
dbd_odbc_ping_interval = 300
[Exec]
# Set to 1 to allow EXEC statements to execute. Should normally be left on unless you
# want to temporarily disable all EXEC commands
exec_enable = 1
[Debugging]
# 0 - do not output messages
# 1 - output some basic messages
# 2 - out all messages
DEBUGGING = 2
# Debugging file - SNMPTT
# Location of debugging output file. Leave blank to default to STDOUT (good for
# standalone mode, or daemon mode without forking)
#DEBUGGING_FILE =
DEBUGGING_FILE = /etc/snmp/debug.snmptt
# Debugging file - SNMPTTHANDLER
# Location of debugging output file. Leave blank to default to STDOUT
#DEBUGGING_FILE_HANDLER =
DEBUGGING_FILE_HANDLER = /var/log/snmptthandler.debug
[TrapFiles]
# A list of snmptt.conf files (this is NOT the snmptrapd.conf file). The COMPLETE path
# and filename. Ex: '/etc/snmp/snmptt.conf'
snmptt_conf_files = <<END
/etc/snmp/oreon_traps/snmptt-cisco.conf
/etc/snmp/oreon_traps/snmptt-hp.conf
/etc/snmp/oreon_traps/snmptt-3com.conf
/etc/snmp/oreon_traps/snmptt-ciscolinksys.conf
/etc/snmp/oreon_traps/snmptt-dell.conf
/etc/snmp/oreon_traps/snmptt-Generic.conf
/etc/snmp/oreon_traps/snmptt-Zebra.conf
END

View File

@ -1,964 +0,0 @@
#!/usr/bin/perl
#
# SNMPTTCONVERTMIB v1.2beta3
#
# Copyright 2002-2007 Alex Burger
# alex_b@users.sourceforge.net
#
# 8/14/2002
#
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
##############################################################################
#
# http://www.sourceforge.net/projects/snmptt
#
###############################################################################
use strict;
#
# OPTIONS START
#
# Set this to '' to have no default EXEC line added, or modify as needed.
# Can also set on the command line with --exec='string'
my $defaultexec = '';
# Choose what type of quotes (if any) you want around the SUMMARY text pulled from the MIB.
#$defaultexecquote = ''; # no quotes
#$defaultexecquote = "\'"; # single (') quotes
my $defaultexecquote = "\""; # double (") quotes
# Set this to 1 to have the --TYPE string prepended to the --SUMMARY string.
# Set to 0 to disable
my $prepend_type = 1;
#
# OPTIONS END
#
#############################################################################
#
my $snmpttconvertmib_version = "v1.2beta3";
sub showversion
{
print "\nSNMPTTCONVERTMIB $snmpttconvertmib_version\n";
print "(c) 2002-2007 Alex Burger\n";
print "http://snmptt.sourceforge.net\n\n";
}
##############################################################################
# Process command line arguments
$| = 1;
use Getopt::Long;
use File::Basename;
use File::Spec;
my $DEBUGGING = 0;
my $version = 0;
my $debug = 0;
my $help = 0;
my $net_snmp_perl = 0;
my $in = '';
my $out = '';
my $nodes = '';
my $no_description = 0;
my $no_variables = 0;
my $no_format_summary = 0;
my $no_format_desc = 0;
my $format = 0;
my $format_desc = 0;
my $no_desc_wildcard = 0;
my $no_severity = 0;
my $severity = 'Normal';
my $exec = '';
GetOptions ('version' => \$version,
'debug:i' => \$debug,
'help' => \$help,
'in=s' => \$in,
'out=s' => \$out,
'net_snmp_perl' => \$net_snmp_perl,
'nodes=s' => \$nodes,
'no_description' => \$no_description,
'no_variables' => \$no_variables,
'no_format_summary' => \$no_format_summary,
'no_format_desc' => \$no_format_desc,
'no_severity' => \$no_severity,
'severity=s' => \$severity,
'format=n' => \$format,
'format_desc=n' => \$format_desc,
'no_desc_wildcard' => \$no_desc_wildcard,
'exec=s' => \$exec);
if ($version == 1)
{
&showversion;
exit(0);
}
if ($help == 1)
{
&show_help();
exit(0);
}
# Replace any spaces with -'s in severity
$severity =~ s/ /-/g;
if ($debug == 1)
{
$DEBUGGING = 1;
}
if ($debug == 2)
{
$DEBUGGING = 2;
}
if (($in eq "") || ($out eq ""))
{
print "\nMissing arguments!\n";
&show_help();
exit 1;
}
# Get complete path of input file (MIB) in a portable way (needed for -m switch for snmptranslate)
my $dirname = dirname $in;
my $basename = basename $in;
my $input = File::Spec->catfile($dirname, $basename);
# Get complete path of output file (.conf) in a portable way
$dirname = dirname $out;
$basename = basename $out;
my $output = File::Spec->catfile($dirname, $basename);
if ($exec ne '')
{
$defaultexec = $exec;
print "exec: $exec\n";
}
#print "nodes: $nodes\n";
if ($net_snmp_perl == 1)
{
print "\n\n***** UCD-SNMP / NET-SNMP Perl module enabled *****\n\n";
}
print "\n\n***** Processing MIB file *****\n\n";
my $snmptranslate_use_On;
check_snmptranslate_version();
print "severity: $severity\n";
print "\nFile to load is: $input\n";
print "File to APPEND TO: $output\n";
# Set MIBS environment variable to the filename of the MIB file (not the mib name - if a file contains
# multiple MIB definitions in one file, the mib name will not work - at least with 5.0.8 and older)
$ENV{MIBS} = $input;
print "\nMIBS environment var: $ENV{MIBS}\n";
if ($DEBUGGING >= 1)
{
print "\nLoading$input\n";
}
unless (open INPUTFILE, "<$input")
{
die "Cannot open input file: $!";
}
my @mibfile;
while (<INPUTFILE>)
{
chomp; # remove <cr> at end of line
s/\015//; # Remove any DOS carriage returns
push(@mibfile, $_); # add to each line to @trapconf array
}
if ($DEBUGGING >= 1)
{
print "Finished loading $input\n\n";
}
my $currentline=0;
unless (open OUTPUTFILE, ">>$output")
{
die "Cannot open output file: $!";
}
# A mib file can contain multiple BEGIN definitions. This finds the first on
# to make sure we have at least one definition.
# Determine name of MIB file
my $mib_name = '';
while ($currentline <= $#mibfile)
{
my $line = $mibfile[$currentline];
if ($line =~ /(.*)DEFINITIONS\s*::=\s*BEGIN/)
{
$mib_name = $1;
$mib_name =~ s/\s+//g;
last;
}
$currentline++;
}
print "mib name: $mib_name\n";
if ($mib_name eq '')
{
print "\n\nAborting!!!\n";
print "Could not find DEFINITIONS ::= BEGIN statement in MIB file!\n\n";
exit (1);
}
if ($net_snmp_perl == 1)
{
require SNMP;
$SNMP::save_descriptions = 1; # Need them only for looking up variable descriptions.
# Do TRAP definition by hand to be able to pull out
# the SUMMARY lines
&SNMP::initMib();
print "\n\n***** Using UCD-SNMP / NET-SNMP Perl module *****\n\n";
}
my $total_translations = 0;
my $successful_translations = 0;
my $failed_translations = 0;
$currentline=0;
#if ($net_snmp_perl == 0)
if (1)
{
# Process the trap files by hand
while ($currentline <= $#mibfile)
{
my $line = $mibfile[$currentline];
if ($line =~ /(.*)DEFINITIONS\s*::=\s*BEGIN/)
{
$mib_name = $1;
$mib_name =~ s/\s+//g;
print "\n\nProcessing MIB: $mib_name\n";
print OUTPUTFILE "#\n#\n#\n#\n";
print OUTPUTFILE "MIB: $mib_name (file:$input) converted on " . scalar(localtime) . " using snmpttconvertmib $snmpttconvertmib_version\n";
$currentline++; # Increment to the next line
next;
}
# TRAP-TYPE (V1) / NOTIFICATION-TYPE (V2)
#
# eg: 'mngmtAgentTrap-23003 TRAP-TYPE';
# eg: 'ciscoSystemClockChanged NOTIFICATION-TYPE';
if ( $line =~ /(.*)\s*TRAP-TYPE.*/ ||
$line =~ /(.*)\s*(?<!--)NOTIFICATION-TYPE.*/ )
{
my $trapname = $1;
my $trapversion;
if ( $line =~ /TRAP-TYPE/ )
{
$trapversion = 'TRAP';
}
else
{
$trapversion = 'NOTIFICATION';
}
# Make sure it doesn't start with a --. If it does, it's a comment line.. Skip it
if ($line =~/.*--.*TRAP-TYPE/ || $line =~/.*--.*NOTIFICATION-TYPE/)
{
# Comment line
$currentline++; # Increment to the next line
$line = $mibfile[$currentline]; # Get next line
next;
}
my $enterprisefound = 0;
my @variables = ();
# Sometimes the TRAP-TYPE / NOTIFICATION-TYPE will appear on the line following the trap name
# Look for xxx-TYPE with nothing (white space allowed) around it and a previous line with only a single word
# with whitespace around it.
if ( ($currentline > 0 && $line =~ /^\s*TRAP-TYPE\s*$/ && $mibfile[$currentline-1] =~ /^\s*(\w+)\s*$/) ||
($currentline > 0 && $line =~ /^\s*NOTIFICATION-TYPE\s*$/ && $mibfile[$currentline-1] =~ /^\s*(\w+)\s*$/) ) {
# We should have found the trap name
$trapname = $1;
print "split line TRAP-TYPE / NOTIFICATION-TYPE found ($1).\n";
}
# If the TRAP-TYPE / NOTIFICATION-TYPE line starts with white space, it's probably a import line, so ignore
elsif ( $line =~ /^\s+TRAP-TYPE.*/ ||
$line =~ /^\s+NOTIFICATION-TYPE.*/ ||
$line =~ /^.*,.*NOTIFICATION-TYPE.*/ )
{
print "skipping a TRAP-TYPE / NOTIFICATION-TYPE line - probably an import line.\n";
$currentline++; # Increment to the next line
$line = $mibfile[$currentline]; # Get next line
next;
}
# Remove beginning and trailing white space
$trapname =~ /\s*([A-Za-z0-9_-]+)\s*/;
$trapname = $1;
print "#\n";
print "Line: $currentline\n";
if ($trapversion eq 'TRAP')
{
print "TRAP-TYPE: $1\n"; # If trapsummary blank, use trapsummary line for FORMAT and EXEC
}
else
{
print "NOTIFICATION-TYPE: $1\n"; # If trapsummary blank, use trapsummary line for FORMAT and EXEC
}
$currentline++; # Increment to the next line
my $line3 = $mibfile[$currentline];
my $end_of_definition = 0;
my $traptype = "";
my $trapsummary = "";
my @description = ();
my $trap_severity = $severity;
my $enterprise;
my @arguments;
my $formatexec;
while ( ($currentline <= $#mibfile) && !($line3 =~ /\s+END\s+/) && !($line3 =~ /(.*)\s+TRAP-TYPE.*/ )
&& !($line3 =~ /(.*)\s+NOTIFICATION-TYPE.*/) && ($end_of_definition == 0) )
{
# Keep going through the file until the next TRAP-TYPE / NOTIFICATION-TYPE or the end of the mib file
# is reached, or the end of the section (between BEGIN and END)
# Look for DESCRIPTION and anything after (including newline with /s)
# and capture that anything in $1
# If line starts with ENTERPRISE, pull it out
# Only applies to SNMPv1 TRAPs
# (SNMPv2 NOTIFICATIONS have the enterprise in the ::= line)
$traptype = "";
$trapsummary = "";
@description = ();
$trap_severity = $severity;
if ($line3 =~ /ENTERPRISE\s+(.*)/)
{
$enterprise = $1;
$enterprisefound =1;
}
if ( ($line3 =~ /VARIABLES(.*)/s) || ($line3 =~ /OBJECTS(.*)/s) )
{
# If there is more text after the word VARIABLES or OBJECTS, assume it's the start of
# the variable list
my $templine = "";
if ($1 ne "")
{
$templine = $templine . $1;
$templine =~ s/--.*//; # Remove any trailing comments
}
if ($templine =~ /\}/) # Contains a }, so we're done
{
# DONE!
}
else
{
$currentline++; # Increment to the next line
my $line4 = $mibfile[$currentline];
$line4 =~ s/--.*//; # Remove any trailing comments
my $keepdigging = 1;
while (($currentline <= $#mibfile) && ($keepdigging == 1))
{
$templine = $templine . $line4;
if ($line4 =~ /\}/) # Contains a }, so we're done
{
$keepdigging = 0;
}
else
{
$currentline++; # Increment to the next line
$line4 = $mibfile[$currentline];
$line4 =~ s/--.*//; # Remove any trailing comments
}
}
}
$templine =~ s/\s//g; # Remove any white space
$templine =~ /\{(.*)\}/; # Remove brackets
@variables = split /\,/, $1;
print "Variables: @variables\n";
}
if ($line3 =~ /DESCRIPTION(.*)/s)
{
my $temp1 = 0;
# Start of DESCRIPTION
#print "SDESC\n";
# If there is more text after the word DESCRIPTION, assume it's the start of
# the description.
if ($1 ne "")
{
# Pull out text and remove beginning and trailing white space
if ($1 =~ /\s*(.*)\s*/)
{
# Remove any quotes
$_ = $1;
s(\")()g;
# "
push (@description, "$_\n");
}
}
$currentline++; # Increment to the next line
my $line4 = $mibfile[$currentline];
# Assume the rest is the description up until a ::= or end of the file
while (! ($line4 =~ /::=/))
{
# If next line is a --#TYPE, pull out the information and place in $traptype
if ($line4 =~ /--#TYPE(.*)/)
{
# Pull out text and remove beginning and trailing white space and quotes
if ($line4 =~ /\s*--#TYPE\s*(.*)\s*/)
{
# Remove any quotes
$_ = $1;
s(\")()g;
# "
#print ("2\n");
$traptype = $_;
#print "Type: $traptype \n";
}
# Increment to next line and continue with the loop
$currentline++; # Increment to the next line
$line4 = $mibfile[$currentline];
next;
}
# If next line is a --#SUMMARY, pull out the information and place in $summary
if ($line4 =~ /--#SUMMARY(.*)/)
{
# Pull out text and remove beginning and trailing white space and quotes
if ($line4 =~ /\s*--#SUMMARY\s*(.*)\s*/)
{
# Remove any quotes
$_ = $1;
s(\")()g;
# "
#print ("2\n");
$trapsummary .= $_;
#print "Summary: $trapsummary \n";
}
# Increment to next line and continue with the loop
$currentline++; # Increment to the next line
$line4 = $mibfile[$currentline];
next;
}
# If next line is a --#ARGUMENTS, pull out the information and place in $arguments
if ($line4 =~ /--#ARGUMENTS\s*{(.*)}/)
{
@arguments = split /,/, $1;
for(my $i=0;$i <= $#arguments;$i++)
{
# Most ARGUMENTS lines have %n where n is a number starting
# at 0, but some MIBS have an ARGUMENTS line that have $1, $2,
# etc and start at 1. These need to have the $ removed and
# the number downshifted so the FORMAT will be generated
# properly.
if ($arguments[$i] =~ /^\s*\$\d+/) {
$arguments[$i] =~ s/^\s*\$(\d+)/$1/;
$arguments[$i]--;
}
#print "argument $i: $arguments[$i]\n";
}
#for(my $i=0;$i <= $#arguments;$i++)
#{
#print "argument $i: $arguments[$i]\n";
#}
# Increment to next line and continue with the loop
$currentline++; # Increment to the next line
$line4 = $mibfile[$currentline];
next;
}
# If next line is a --#SEVERITY, pull out the information and place in $trap_severity
if ($line4 =~ /--#SEVERITY\s+(.*)/ && ! ($line4 =~ /--#SEVERITYMAP/))
{
# Pull out text and remove beginning and trailing white space and quotes
if ($line4 =~ /\s*--#SEVERITY\s+(.*)\s*/)
{
# Remove any quotes
$_ = $1;
s(\")()g;
# "
#print ("2\n");
if ($no_severity == 0)
{
$trap_severity = $_;
}
#print "Severity: $trap_severity \n";
}
# Increment to next line and continue with the loop
$currentline++; # Increment to the next line
$line4 = $mibfile[$currentline];
next;
}
# If next line starts with a --#, ignore it and continue with the loop
# (we already got the SUMMARY line above)
if ($line4 =~ /--#/)
{
$currentline++; # Increment to the next line
$line4 = $mibfile[$currentline];
next;
}
# If we did not find text after the word DESCRIPTION, then the NEXT
# line must be the first line of description.
# Remove beginning and trailing white space
$line4 =~ (/\s*(.*)\s*/);
if ($1 ne "")
{
# Remove any quotes
$_ = $1;
s(\")()g;
# "
push (@description, "$_\n");
#print "c:$_\n";
}
$currentline++; # Increment to the next line
$line4 = $mibfile[$currentline];
}
#print "EDESC\n";
if ($line4 =~ /::=/)
{
$end_of_definition = 1; # Move on to the next one
if ($enterprisefound == 0)
{
# $line4 should now contain ::= line
# # Pull out enterprise from { }
# # Would only apply to SNMPv2 NOTIFICATIONS
# #print "Line4: $line4\n";
$line4 =~ /{(.*)\s\d.*/;
#print "\$1=$1\n";
$enterprisefound =1;
# Remove any spaces
$_ = $1;
s( )()g;
$enterprise = $_;
print "Enterprise: $enterprise\n";
}
}
}
$currentline++; # Increment to the next line
$line3 = $mibfile[$currentline];
}
# Combine Trap type and summary together to make new summary
if ($traptype ne "" && $prepend_type == 1)
{
$trapsummary = $traptype . ": " . $trapsummary;
}
my $trap_lookup;
if ($mib_name eq '')
{
$trap_lookup = $trapname;
}
else
{
$trap_lookup = "$mib_name\:\:$trapname";
}
print "Looking up via snmptranslate: $trap_lookup\n";
my $trapoid;
if ($snmptranslate_use_On == 1)
{
$trapoid = `snmptranslate -IR -Ts -On $trap_lookup`;
}
else
{
$trapoid = `snmptranslate -IR -Ts $trap_lookup`;
}
chomp $trapoid;
if ($trapoid ne "")
{
print OUTPUTFILE "#\n#\n#\n";
print OUTPUTFILE "EVENT $trapname $trapoid \"Status Events\" $trap_severity\n";
# Loop through trapsummary and replace the %s and %d etc with %1 to %n
#$j = $#arguments; # j is last element number
#print "j is $j\n";
# Change the %s or %d etc into $1 etc (starts at $1)
$_ = $trapsummary;
for (my $j=0; $j<= $#arguments; $j++)
{
my $variable = ($arguments[$j])+1;
s(%[a-zA-Z])(\$$variable);
}
#print "new summary: $_\n";
$trapsummary = $_;
my $descriptionline1 = '';
# Build description line for FORMAT / EXEC
if ($format_desc == 0) # First line of description
{
$descriptionline1 = $description[0];
chomp ($descriptionline1);
}
else # n sentence(s) of description
{
# Build single line copy of description
my $description_temp;
foreach my $a (@description)
{
my $b = $a;
chomp($b);
$description_temp = $description_temp . $b . " ";
}
chop $description_temp;
# Split up based on sentences
my @description_temp2 = split /\./, $description_temp;
# Remove white space around each sentence and add a trailing .
for (my $i=0 ; $i <= $#description_temp2; $i++)
{
$description_temp2[$i] =~ /\s*(.*)\s*/;
$description_temp2[$i] = $1 . ".";
}
# Build description line based on the number of sentences requested.
for (my $i=1 ; $i <= $format_desc; $i++)
{
if ($description_temp2[$i-1] ne '') {
$descriptionline1 = $descriptionline1 . $description_temp2[$i-1] . " " ;
}
}
chop $descriptionline1; # Remove last space
}
if ($descriptionline1 ne "")
{
if ($descriptionline1 =~ /%[a-zA-Z]/)
{
# Sometimes the variables are in the first line of the description
# Change the %s or %d etc into $1 etc (starts at $1)
# There is no list of variables, so just put them in order starting at 1 and
# going up to 20
$_ = $descriptionline1;
for (my $j=1; $j<= 20; $j++)
{
s(%[a-zA-Z])(\$$j);
}
$descriptionline1 = $_;
#$descriptionlinehadvariables = 1;
}
else
{
if ($no_desc_wildcard == 0)
{
$descriptionline1 = "$descriptionline1 \$*";
}
}
}
$formatexec = '';
if ($format == 0) # --#SUMMARY or description
{
if ($trapsummary ne '' && $no_format_summary == 0)
{
$formatexec = $trapsummary;
}
elsif ($descriptionline1 ne '' && $no_format_desc == 0)
{
$formatexec = $descriptionline1;
}
}
elsif ($format == 1) # description or --#SUMMARY
{
if ($descriptionline1 ne '' && $no_format_desc == 0)
{
$formatexec = $descriptionline1;
}
elsif ($trapsummary ne '' && $no_format_summary == 0)
{
$formatexec = $trapsummary;
}
}
elsif ($format == 2) # --#SUMMARY and description
{
if ($trapsummary ne '' && $no_format_summary == 0)
{
$formatexec = $trapsummary;
}
if ($descriptionline1 ne '' && $no_format_desc == 0)
{
if ($formatexec =~ /\.$/) # If it already ends in a .
{
$formatexec = $formatexec . " " . $descriptionline1;
}
else
{
$formatexec = $formatexec . ". " . $descriptionline1;
}
}
}
elsif ($format == 3) # description and --#SUMMARY
{
if ($descriptionline1 ne '' && $no_format_desc == 0)
{
$formatexec = $descriptionline1;
}
if ($trapsummary ne '' && $no_format_summary == 0)
{
$formatexec = $formatexec . " " . $trapsummary;
}
}
if ($formatexec ne '')
{
print OUTPUTFILE "FORMAT $formatexec\n";
if ($defaultexec ne '')
{
print OUTPUTFILE "EXEC $defaultexec $defaultexecquote$formatexec$defaultexecquote\n"
}
}
else
{
print OUTPUTFILE "FORMAT \$*\n";
if ($defaultexec ne '')
{
print OUTPUTFILE "EXEC $defaultexec $defaultexecquote\$*$defaultexecquote\n"
}
#print OUTPUTFILE "EXEC \$*\n";
}
if ($nodes ne '')
{
print OUTPUTFILE "NODES $nodes\n";
}
if ($no_description == 0)
{
print OUTPUTFILE "SDESC\n";
#print OUTPUTFILE "$descriptionline1\n";
for (my $i=0; $i <= $#description; $i++)
{
print OUTPUTFILE "$description[$i]";
}
# If net_snmp_perl is enabled, lookup each variable
if (@variables && $no_variables == 0 && $net_snmp_perl == 1)
{
print OUTPUTFILE "Variables:\n";
for (my $i=0; $i <= $#variables; $i++)
{
printf OUTPUTFILE "%3d: %s\n",$i+1,$variables[$i];
printf OUTPUTFILE " Syntax=\"" . $SNMP::MIB{$variables[$i]}{type} . "\"\n";
if (uc $SNMP::MIB{$variables[$i]}{type} =~ /INTEGER/)
{
my $b = $SNMP::MIB{$variables[$i]}{enums};
my %hash = %$b;
my $i = 1;
# Create a new copy of the hash swapping the key and the value
my %temphash = ();
while ((my $key, my $value) = each %hash)
{
$temphash{$value} = $key;
}
# Print out the entries in the hash
foreach my $c (sort keys %temphash)
{
print OUTPUTFILE " " . $c . ": $temphash{$c}\n";
}
}
if ($SNMP::MIB{$variables[$i]}{description})
{
print OUTPUTFILE " Descr=\"" . $SNMP::MIB{$variables[$i]}{description} . "\"\n";
}
}
}
elsif (@variables ne "" && $no_variables == 0 && $net_snmp_perl == 0)
{
print OUTPUTFILE "Variables:\n";
for (my $i=0; $i <= $#variables; $i++)
{
print OUTPUTFILE " " . ($i+1) . ": " . $variables[$i] . "\n";
}
}
print OUTPUTFILE "EDESC\n";
}
$currentline--;
}
print "OID: $trapoid\n";
$total_translations++;
if ($trapoid eq '')
{
$failed_translations++;
}
else
{
$successful_translations++;
}
#print "\@description is ", $#description,"\n";
#print "going to next trap / notification\n\n";
}
$currentline++; # Increment to the next line
}
sub check_snmptranslate_version
{
$snmptranslate_use_On = 1;
if (open SNMPTRANSLATE, "snmptranslate -V 2>&1|")
{
my $snmptranslatever = <SNMPTRANSLATE>;
close SNMPTRANSLATE;
chomp ($snmptranslatever);
print "snmptranslate version: " . $snmptranslatever. "\n";
if ($snmptranslatever =~ /UCD/i || $snmptranslatever =~ /NET-SNMP version: 5.0.1/i)
{
$snmptranslate_use_On = 0;
if ($DEBUGGING >= 1)
{
print "snmptranslate is either UCD-SNMP, or NET-SNMP v5.0.1, so do not use the -On switch. Version found: $snmptranslatever\n";
}
}
}
}
# End of process the trap files by hand
print "\n\nDone\n\n";
print "Total translations: $total_translations\n";
print "Successful translations: $successful_translations\n";
print "Failed translations: $failed_translations\n";
}
sub show_help
{
my $USAGE = qq/Usage:
snmpttconvertmib --in= --out= [<options>]
Options:
--debug=n Set debug level (1 or 2)
--help Display this message
--version Display author and version information
--net_snmp_perl Enable NET-SNMP Perl integration (see below)
--in=filename Input file
--out=filename Output file
--nodes=name or file If specified, will insert a NODES line after FORMAT or
EXEC. The host name(s) separated by spaces, or the
name of the nodes file. Use quotes for multiple
entries. See NODES section in readme.html for examples
--no_description Do not save the description
--no_variables Do not save the variable list in the description
--no_format_summary Do not use the --#SUMMARY lines for FORMAT \/ EXEC
--no_format_desc Do not use the description line for FORMAT \/ EXEC
--no_severity Do not use the --#SEVERITY line for EVENT line. Default
severity of "Normal" will be used, unless --severity= is
set
--severity=s Severity level for EVENT line. Only used if there is no
--#SEVERITY line, or --no_severity is set. Must NOT
contain any spaces.
Example:
Critical
--format=n FORMAT \/ EXEC order preference
0 = --#SUMMARY or description
1 = description or --#SUMMARY
2 = --#SUMMARY and description
3 = description and --#SUMMARY
--format_desc=n How to convert the description line for FORMAT \/ EXEC
0 = First line of description
n = n sentence(s) of description
--no_desc_wildcard To prevent \$* from being appended to the end of
description text when used on the FORMAT \/ EXEC
lines. A wildcard is only used if the description
line contained no variable definitions (\%n).
--exec=command Command line to use for EXEC line. Use SINGLE quotes
with Unix. Example:
'qpage -f TRAP notifygroup1'
Note: The only benefit in using the --net_snmp_perl switch (which requires the
Net-SNMP Perl module to be installed) is that the Variables: description section
will include:
-variable syntax
-variable description
-variable enums
For example:
2: globalStatus
Syntax="INTEGER"
2: ok
4: failure
Descr="Current status of the entire library system"
/;
&showversion;
print $USAGE . "\n";
}

View File

@ -1,137 +0,0 @@
#! /usr/bin/perl -w
###################################################################
# Oreon is developped with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
# Developped by : Mathavarajan Sugumaran - msugumaran@merethis.com
# Julien Mathis - Romain Le Merlus
#
###################################################################
# 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# For information : contact@merethis.com
####################################################################
#
# Script init
#
use strict;
use Getopt::Long;
use DBI;
use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd);
require "@CENTREON_PATH@/ODS/etc/conf.pm";
#########################################
## TEST IF OID ALREADY EXISTS IN DATABASE
#
sub existsInDB($$) {
my ($dbh, $oid,$manuf) = @_;
my $sth = $dbh->prepare("SELECT traps_id FROM traps WHERE traps_oid = '$oid'");
$sth->execute();
if (defined($sth->fetchrow_array)) {
$sth->finish();
return 1;
}
$sth->finish();
return 0;
}
#####################################
## RETURN ENUM FROM STRING FOR STATUS
#
sub getStatus($$) {
my ($val, $type) = @_;
if ($val =~ /[I|i][N|n][F|f][O|o][R|r][M|m][A|a][T|t][I|i][O|o][N|n][A|a][L|l]|[N|n][O|o][R|r][M|m][A|a][L|l]/) {
return 0;
} elsif ($val =~ /^[W|w][A|a][R|r][N|n][I|i][N|n][G|g]|[M|m][I|i][N|n][O|o][R|r]$/) {
return 1;
} elsif ($val =~ /^[C|c][R|r][I|i][T|t][I|i][C|c][A|a][L|l]|[M|m][A|a][J|j][O|o][R|r]$/) {
return 2;
}
return 3;
}
################
## MAIN FUNCTION
#
sub main($$) {
my $manuf = $_[1];
my $dsn = "dbi:mysql:$mysql_database_oreon";
my $dbh = DBI->connect($dsn, $mysql_user, $mysql_passwd) or die "Echec de la connexion\n";
if (!open(FILE, $_[0])) {
print "Cannot open configuration file : $_[0]\n";
exit;
}
my $last_oid = "";
while (<FILE>) {
if ($_ =~ /^EVENT\ ([a-zA-Z0-9]+)\ ([0-9\.]+)\ (\"[A-Za-z\ ]+\")\ ([a-zA-Z]+)/) {
my ($name,$oid,$type,$val) = ($1,$2,$3,$4);
if (existsInDB($dbh, $oid)) {
print "Trap oid : $name => $oid already exists in database\n";
$last_oid = $oid;
} else {
$val = getStatus($val,$type);
my $sth = $dbh->prepare("INSERT INTO `traps` (traps_name, traps_oid, traps_status, manufacturer_id) values ('$name', '$oid', '$val', '$manuf')");
$sth->execute();
$sth->finish();
$last_oid = $oid;
}
} elsif ($_ =~/^FORMAT\ (.*)/ && $last_oid ne "") {
my $sth = $dbh->prepare("UPDATE `traps` set traps_args='$1' WHERE traps_oid = '$last_oid'");
$sth->execute();
$sth->finish();
} elsif ($_ =~ /^SDESC(.*)/ && $last_oid ne "") {
my $temp_val = $1;
my $desc = "";
if (! ($temp_val =~ /\s+/)){
$temp_val =~ s/\"/\\\"/g;
$temp_val =~ s/\'/\\\'/g;
$desc .= $temp_val;
}
my $found = 0;
while (!$found) {
my $line = <FILE>;
if ($line =~ /^EDESC/) {
$found = 1;
} else {
$line =~ s/\"/\\\"/g;
$line =~ s/\'/\\\'/g;
$desc .= $line;
}
}
if ($desc ne "") {
my $sth = $dbh->prepare("UPDATE `traps` set traps_comments='$desc' where traps_oid='$last_oid'");
$sth->execute();
$sth->finish();
}
}
}
$dbh->disconnect();
}
Getopt::Long::Configure('bundling');
my ($opt_f, $opt_m);
GetOptions("f|file=s" => \$opt_f, "m|man=s" => \$opt_m);
if (!$opt_f || !$opt_m) {
print "fill_trapDB : Usage : ./fill_trapDB -f configuration_file -m manufacturer_id\n";
exit;
}
main($opt_f,$opt_m);
exit();

View File

@ -1,134 +0,0 @@
#! /usr/bin/perl -w
###################################################################
# Oreon is developped with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
# Developped by : Mathavarajan Sugumaran - msugumaran@merethis.com
# Julien Mathis - Romain Le Merlus
#
###################################################################
# 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# For information : contact@merethis.com
####################################################################
#
# Script init
#
use strict;
use Getopt::Long;
use DBI;
use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd);
require "/srv/oreon/ODS/etc/conf.pm";
######################################
## Get snmptt configuration files path
#
sub getPath($) {
my $dbh = shift;
my $sth = $dbh->prepare("Select snmp_trapd_path_conf from general_opt");
$sth->execute();
my $path = $sth->fetchrow_array();
$path .= "/" if (!($path =~ /\/$/));
$path = "/etc/snmp/" if (!$path);
return $path;
}
sub main() {
print "Generating SNMPTT configuration files...\n";
my ($nbMan, $nbTraps) = (0,0);
my $dsn = "dbi:mysql:$mysql_database_oreon";
my $dbh = DBI->connect($dsn, $mysql_user, $mysql_passwd) or die "Echec de la connexion\n";
my $confFiles_path = getPath($dbh);
my $sth = $dbh->prepare("SELECT nagios_path_plugins FROM general_opt LIMIT 1");
$sth->execute();
my @conf = $sth->fetchrow_array();
$sth->finish();
my $NAGIOS_TRAPS = $conf[0]."traps/";
$sth = $dbh->prepare("SELECT id, name from traps_vendor");
$sth->execute();
my $snmpttIni = "";
while (my ($man_id, $man_name) = $sth->fetchrow_array()) {
my $sth2 = $dbh->prepare("SELECT traps_name, traps_oid, traps_status, traps_args, traps_comments FROM traps WHERE manufacturer_id = '$man_id'");
$sth2->execute();
if (!open(FILE, "> ".$confFiles_path."snmptt-".$man_name.".conf")) {
print "Cannot open ".$confFiles_path."snmptt-".$man_name.".conf in write mode - Export aborded\n";
exit;
}
$nbMan++ if ($sth2->rows);
while (my @values = $sth2->fetchrow_array()) {
$nbTraps++;
my $args = "";
print FILE "EVENT ".$values[0]." ".$values[1]." \"Status Event\" ".$values[2]."\n";
if (defined($values[3])) {
print FILE "FORMAT ".$values[3]."\n";
}else {
$values[3] = "no output for trap!";
}
print FILE "EXEC ".$NAGIOS_TRAPS."trapHandler \$aA \$o \"$values[3]\"\n";
if (defined($values[4])) {
print FILE "SDESC\n".$values[4];
if ($values[4] =~ /\n$/) {
print FILE "EDESC\n\n";
} else {
print FILE "\nEDESC\n\n";
}
} else {
print FILE "\n";
}
}
close FILE;
$snmpttIni .= $confFiles_path."snmptt-".$man_name.".conf\n";
$sth2->finish();
}
print "$nbTraps traps for $nbMan manufacturers are defined.\n";
$sth->finish();
$dbh->disconnect();
if (!open(FILE, $confFiles_path."snmptt.ini")) {
print "Cannot open ".$confFiles_path."snmptt.ini - Export Aborded\n";
exit;
}
if (!open(TEMP, "> /tmp/snmptt.ini.tmp")) {
print "Cannot open /tmp/snmptt.ini.tmp in write mode - Export Aborded\n";
exit;
}
my $continue = 1;
while ($continue == 1) {
my $line = <FILE>;
if ($line) {
if (!($line =~ /^snmptt\_conf\_files/)) {
print TEMP $line;
} else {
$continue = 0;
}
} else {
$continue = -1;
}
}
if (!$continue) {
print TEMP "snmptt_conf_files = <<END\n";
print TEMP $snmpttIni."END\n";
my $command = "mv /tmp/snmptt.ini.tmp ".$confFiles_path."snmptt.ini";
my $mv = `$command`;
print "SNMPTT configuration files generated.\n";
} else {
print "Couldn't export ".$confFiles_path."snmptt.ini, please put these lines at the end of file snmptt.ini :\n";
print "snmptt_conf_files = <<END\n".$snmpttIni."END\n";
}
}
main();

View File

@ -1,128 +0,0 @@
#! /usr/bin/perl -w
###################################################################
# Oreon is developped with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
# Developped by : Mathavarajan Sugumaran - msugumaran@merethis.com
# Julien Mathis - Romain Le Merlus
#
###################################################################
# 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# For information : contact@merethis.com
####################################################################
#
# Script init
#
use strict;
use DBI;
use vars qw($mysql_database_oreon $mysql_database_ods $mysql_host $mysql_user $mysql_passwd);
require "/srv/oreon/ODS/etc/conf.pm";
###############################
## GET HOSTNAME FROM IP ADDRESS
#
sub get_hostinfos($$){
my $sth = $_[0]->prepare("SELECT host_name FROM host WHERE host_address='$_[1]' ");
$sth->execute();
my @host;
while (my $temp = $sth->fetchrow_array()) {
$host[scalar(@host)] = $temp;
}
$sth -> finish;
return @host;
}
##########################
## GET SERVICE DESCRIPTION
#
sub get_servicename($$$) {
my $query_host = "SELECT host_id from host WHERE host_name ='$_[2]'";
my $sth = $_[0]->prepare($query_host);
$sth->execute();
my $host_id = $sth -> fetchrow_array();
exit if (!defined $host_id);
$sth->finish();
my $query_trap = "SELECT traps_id, traps_status from traps where traps_oid='$_[1]'";
$sth = $_[0]->prepare($query_trap);
$sth->execute();
my ($trap_id, $trap_status) = $sth->fetchrow_array();
exit if (!defined $trap_id);
my $query_services = "SELECT service_description FROM service s, host_service_relation h, traps_service_relation t";
$query_services .= " where s.service_id = t.service_id and t.traps_id='$trap_id' and s.service_id=h.service_service_id";
$query_services .= " and h.host_host_id='$host_id'";
$sth = $_[0]->prepare($query_services);
$sth->execute();
my @service;
while (my $temp = $sth -> fetchrow_array()) {
$service[scalar(@service)] = $temp;
}
my $query_hostgroup_services = "SELECT service_description FROM hostgroup_relation hgr, traps_service_relation t, service s, host_service_relation hsr";
$query_hostgroup_services .= " WHERE hgr.host_host_id = '".$host_id."' AND hsr.hostgroup_hg_id = hgr.hostgroup_hg_id";
$query_hostgroup_services .= " AND s.service_id = hsr.service_service_id and s.service_id=t.service_id and t.traps_id='$trap_id'";
$sth->finish();
$sth = $_[0]->prepare($query_hostgroup_services);
$sth->execute();
my @new_service;
while (my $temp = $sth->fetchrow_array()){
$new_service[scalar(@new_service)] = $temp;
}
$sth->finish();
return $trap_status, (@service,@new_service);
}
#######################################
## GET HOSTNAME AND SERVICE DESCRIPTION
#
sub getTrapsInfos($$$){
my $ip = shift;
my $oid = shift;
my $arguments_line = shift;
my $dsn = "dbi:mysql:$mysql_database_oreon";
my $dbh = DBI->connect($dsn, $mysql_user, $mysql_passwd) or die "Echec de la connexion\n";
my @host = get_hostinfos($dbh, $ip);
foreach(@host) {
my $this_host = $_;
my ($status, @servicename) = get_servicename($dbh, $oid, $_);
foreach (@servicename) {
my $this_service = $_;
my $datetime=`date +%s`;
chomp($datetime);
my $sth = $dbh->prepare("SELECT command_file FROM cfg_nagios WHERE nagios_activate = '1' LIMIT 1");
$sth->execute();
my @conf = $sth->fetchrow_array();
$sth->finish();
my $submit = `/bin/echo "[$datetime] PROCESS_SERVICE_CHECK_RESULT;$this_host;$this_service;$status;$arguments_line" >> $conf[0]`;
}
}
$dbh->disconnect();
exit;
}
##########################
## PARSE TRAP INFORMATIONS
#
if (scalar(@ARGV)) {
my $ip = $ARGV[0];
my $oid = $ARGV[1];
my $arguments = $ARGV[2];
getTrapsInfos($ip, $oid, $arguments);
}