diff --git a/src/check_https.pl b/src/check_https.pl new file mode 100644 index 000000000..b5a33caef --- /dev/null +++ b/src/check_https.pl @@ -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}; diff --git a/src/check_oreon_snmp_process.pl b/src/check_oreon_snmp_process.pl new file mode 100644 index 000000000..9ce8c071f --- /dev/null +++ b/src/check_oreon_snmp_process.pl @@ -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"; +} + diff --git a/src/check_oreon_snmp_process_detailed.pl b/src/check_oreon_snmp_process_detailed.pl new file mode 100644 index 000000000..b801d0c00 --- /dev/null +++ b/src/check_oreon_snmp_process_detailed.pl @@ -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 -C | (-l login -x passwd) [-p ] -n [-w [,] -c [,max_proc] ] [-m, -a -u, ] [-t ] [-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 = ) + { + 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 < 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 :