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

This commit is contained in:
Mat Sugumaran 2007-06-25 08:35:57 +00:00
parent f1fd09b7c6
commit 783ded1450
11 changed files with 2263 additions and 266 deletions

View File

@ -0,0 +1,60 @@
#! /usr/bin/perl -w
###################################################################
# Oreon is developped with GPL Licence 2.0
#
# GPL License: http://www.gnu.org/licenses/gpl.txt
#
# Developped by : 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 lib "/usr/local/nagios/libexec/";
use utils qw($TIMEOUT %ERRORS &print_revision &support);
use vars qw($PROGNAME);
use Getopt::Long;
use vars qw($opt_h $opt_p $opt_H);
$PROGNAME = $0;
Getopt::Long::Configure('bundling');
GetOptions
("h" => \$opt_h, "help" => \$opt_h,
"p=s" => \$opt_p, "port=s" => \$opt_p,
"H=s" => \$opt_H, "hostname=s" => \$opt_H);
if ($opt_h ) {
print "$PROGNAME : Usage : ./check_https.pl -H [hostname/IP address -p port]\n";
exit $ERRORS{'OK'}
}
if (!$opt_H) {
print "$PROGNAME : Usage : ./check_https.pl -H [hostname/IP address]-p port\n";
exit $ERRORS{'OK'}
}
if (!$opt_p) {
$opt_p = 443;
}
my $status = "CRITICAL";
my $msg = "ERROR : couldn't connect to host.";
my $output =`/usr/bin/wget -S --output-document=/tmp/tmp_html https://$opt_H:$opt_p --no-check-certificate 2>&1`;
my @cmd = split /\n/, $output;
my $execute_command = `rm -f /tmp/tmp_html`;
foreach(@cmd) {
if ($_ =~ /[\s]+HTTP\/[0-9]+\.[0-9]+[\s]+[0-9]+[\s]+OK/) {
$msg = $_." - Request done successfully.";
$status = "OK";
}
}
printf $msg."\n";
exit $ERRORS{$status};

View File

@ -0,0 +1,255 @@
#! /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
#
###################################################################
# 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 "/usr/local/nagios/libexec/";
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_a $opt_v $opt_C $opt_p $opt_H $opt_n $opt_k $opt_u $opt_x $result @result $opt_c $opt_w $opt_f %process_list %STATUS);
# Plugin var init
my($proc, $proc_run);
$PROGNAME = "check_graph_process";
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,
"f" => \$opt_f, "full_pathname" => \$opt_f,
"a=s" => \$opt_a, "arguments=s" => \$opt_a,
"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";
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_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'};
}
}
if (!$opt_C) {
$opt_C = "public";
}
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};
if ($opt_f) {
$OID_SW_RunName = $oreon{MIB2}{SW_RUNFULLPATHNAME};
}
my $OID_SW_Runargs = $oreon{MIB2}{SW_RUNARGS};
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);
my $args_index = $oid_list[scalar(@oid_list) - 1];
if (defined($opt_p) && $opt_p ne ""){
if ($$result{$key} eq $opt_p){
my $result2 = $session->get_request(-varbindlist => [$OID_SW_Runargs . "." . $args_index]);
if (!defined($result2)) {
printf("UNKNOWN: %s.\n", $session->error);
$session->close;
exit $ERRORS{'UNKNOWN'};
}
if ($opt_a && $result2->{$OID_SW_Runargs . "." . $args_index} =~ /$opt_a/) {
$proc++ ;
$process_list{$result->{$key}} = pop (@oid_list) ;
}elsif (!$opt_a) {
$process_list{$result->{$key}} = pop (@oid_list) ;
$proc++;
}
}
} 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} };
}
}
if ($opt_n){
if ($proc > 0) {
print "Processes OK - Number of current processes: $proc|nbproc=$proc\n";
exit $ERRORS{'OK'};
}else {
print "Process CRITICAL - $process not in 'running' state\n";
exit $ERRORS{'CRITICAL'};
}
} 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'};
}
}
# Plugin return code
if ( $opt_n) {
if ($proc) {
print "Processes OK - Number of current processes: $proc|nbproc=$proc\n";
exit $ERRORS{'OK'};
}else {
print "Process CRITICAL - $process not in 'running' state\n";
exit $ERRORS{'CRITICAL'};
}
}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 "Usage:\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 " -a (--arguments) arguments of process you want to check\n";
print " -f (--full_pathname) process with its full path\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 " -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

@ -0,0 +1,604 @@
#!/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 "/usr/local/nagios/libexec";
use utils qw(%ERRORS $TIMEOUT);
#my $TIMEOUT = 5;
#my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
# Oreon specific
#use lib "/usr/local/nagios/libexec";
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

@ -0,0 +1,453 @@
#! /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
#
###################################################################
# 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 = "check_graph_traffic";
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

@ -0,0 +1,188 @@
#! /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
#
###################################################################
# 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 "/usr/local/nagios/libexec/";
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,
"w=s" => \$opt_w, "warning=s" => \$opt_w,
"ct100" => \$opt_t,
"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");
$opt_o = ".1.3.6.1.4.1.89.35.1.53.0";
if ($opt_t) {
$opt_o = ".1.3.6.1.4.1.89.35.1.92.1.1.1.0";
}
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'};
}
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 ($opt_w && $opt_c && $return_result < $opt_w){
print "CPU load : " . $return_result . "% ( <". $opt_w ." )|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 "CPU load : " . $return_result . "% ( <".$opt_w." )|value=$return_result;".$opt_w.";".$opt_c.";;\n";
exit $ERRORS{'WARNING'};
} elsif ($opt_w && $opt_c && $return_result >= $opt_c){
print "CPU load : " . $return_result."% ( <".$opt_c." )|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 " -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

@ -0,0 +1,180 @@
#! /usr/bin/perl
#
# regarder dans logMatchTable pour recuperer es informations
#
# $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,
"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.16.2.1.2";
my $OID_ExecOutput = ".1.3.6.1.4.1.2021.16.2.1.8";
my $OID_ExecPattern = ".1.3.6.1.4.1.2021.16.2.1.4";
# 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, $OID_ExecPattern.".".$scriptname]);
if (!defined($result)) {
printf("ERROR: %s", $session->error);
if ($opt_n) { print(" - You must specify the right logmatch identifier name");}
print ".\n";
$session->close;
exit $ERRORS{'UNKNOWN'};
}
my $ExecDescr = $result->{$OID_ExecDescr.".".$scriptname };
my $ExecOutput = $result->{$OID_ExecOutput.".".$scriptname };
my $ExecPattern = $result->{$OID_ExecPattern.".".$scriptname };
my $return = 0;
if ($ExecOutput =~ /([0-9]*)/){
if ($1 > 0) {
print "CRITICAL : Matching pattern < $ExecPattern > found : $ExecOutput \n";
exit(2);
}
}
print "OK : matching pattern < $ExecPattern > found : $ExecOutput \n";
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

@ -0,0 +1,177 @@
#! /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

@ -0,0 +1,196 @@
#! /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

@ -0,0 +1,150 @@
#! /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 "/srv/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_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=s" => \$opt_v,
"V" => \$opt_V, "version" => \$opt_V,
"H=s" => \$opt_H, "Hostname=s" => \$opt_H,
"p=s" => \$opt_p, "port=s" => \$opt_p,
"C=s" => \$opt_C, "Community=s" => \$opt_C,
"c=s" => \$opt_c, "w=s" => \$opt_w
);
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)/);
if (!$opt_C){
$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} eq $opt_p || $opt_p eq "all") {
$cpt++;
}
}
if (!defined($opt_w)){$opt_w = 20;}
if (!defined($opt_c)){$opt_c = 30;}
if ($opt_p ne "all" ) {
print "Number of connections on port $opt_p : $cpt |nb_conn=$cpt\n";
}else {
print "Total connections : $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,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 "@INSTALL_DIR_OREON@/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.pl : Usage : ./fill_trapDB.pl -f configuration_file -m manufacturer_id\n";
exit;
}
main($opt_f,$opt_m);
exit();

View File

@ -1,129 +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 "@INSTALL_DIR_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 inventory_manufacturer");
$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++;
print FILE "EVENT ".$values[0]." ".$values[1]." \"Status Event\" ".$values[2]."\n";
print FILE "FORMAT ".$values[3]."\n" if (defined($values[3]));
print FILE "EXEC ".$NAGIOS_TRAPS."/trapHandler.pl \$aA \$o \"\$*\"\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();