#!/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 ########### check_centreon_snmp_process_detailed ############## # Version : 1.2.2 # Date : Jun 20 2007 # Author : Sugumaran Mathavarajan - msugumaran@merethis.com # Company : Merethis # 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_PLUGIN@"; use utils qw(%ERRORS $TIMEOUT); # centreon specific if (eval "require centreon" ) { use centreon qw(get_parameters create_rrd update_rrd &is_valid_serviceid); use vars qw($VERSION %centreon); %centreon = get_parameters(); } else { print "Unable to load centreon perl module\n"; exit $ERRORS{'UNKNOWN'}; } # 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 :