From 69e1b0fe391b611fed0dd57422dbff76d5ea9546 Mon Sep 17 00:00:00 2001 From: "M. Sean Finney" Date: Sun, 26 Jun 2005 16:27:05 +0000 Subject: spring cleaning of contrib directory from andreas git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1192 f882894a-f735-0410-b71e-b25c423dba1c diff --git a/contrib/check_dl_size.pl b/contrib/check_dl_size.pl deleted file mode 100644 index e6cbda8..0000000 --- a/contrib/check_dl_size.pl +++ /dev/null @@ -1,148 +0,0 @@ -#! /usr/bin/perl -wT - -# (c)2001 Patrick Greenwell, Stealthgeeks, LLC. (patrick@stealthgeeks.net) -# Licensed under the GNU GPL -# http://www.gnu.org/licenses/gpl.html -# -# check_dl_size: Attempts to download a specified file via FTP and verify -# it is a specified size. -# Requires Net::FTP - -# Version 1.0 -# Last Updated: 8/31/01 - - -BEGIN { - if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { - $runtimedir = $1; - $PROGNAME = $2; - } -} - -require 5.004; -use strict; -use Getopt::Long; -use vars qw($opt_H $opt_f $opt_s $opt_t $verbose $PROGNAME); -use lib $main::runtimedir; -use utils qw($TIMEOUT %ERRORS &print_revision &usage &support &is_error); -use Net::FTP; - -sub help (); -sub print_help (); -sub print_usage (); -sub version (); -sub display_res($$); -my ($ftpfile, $ftpdir, $filesize, $answer) = (); -my $state = $ERRORS{'UNKNOWN'}; - -# Directory to place file. If your machine is not secure DO NOT USE /tmp. -my $dir = "/usr/local/netsaint/etc/tmp"; - -# Username for login -my $user = "anonymous"; - -# Password (PLEASE TAKE APPROPRIATE PRECAUTIONS TO SECURE THIS) -my $pass = "guest\@example.com"; - - -delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; - -Getopt::Long::Configure('bundling', 'no_ignore_case'); -GetOptions - ("V|version" => \&version, - "h|help" => \&help, - "v|verbose" => \$verbose, - "H|hostname=s" => \$opt_H, - "f|filename=s" => \$opt_f, - "s|filesize=s" => \$opt_s, - "t|timeout=s" => \$opt_t, - ); - -($opt_H) || ($opt_H = shift) || usage("Host address or name not specified\n"); -my $host = $1 - if ($opt_H =~ m/^(([0-9]{1,3}\.){3}[0-9]{1,3}|(([a-z0-9]+(\-+[a-z0-9]+)*|\.))+[a-z])$/i); - usage("Please provide a valid IP address or host name\n") unless ($host); - -($opt_f) || ($opt_f = shift) || usage("File name not specified\n"); - -if ($opt_f =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { - $ftpdir = $1; - $ftpfile = $2; -} - -($opt_s) || ($opt_s = shift) || usage("File size not specified\n"); -usage("File size must be numeric value") unless ($opt_s =~ m/^[0-9]+$/); - -(($opt_t) && ($TIMEOUT = $opt_t)) || ($TIMEOUT = 120); -usage("TIMEOUT must be numeric value") unless ($TIMEOUT =~ m/^[0-9]+$/); - -# Don't hang if there are timeout issues -$SIG{'ALRM'} = sub { - print ("ERROR: No response from ftp server (alarm)\n"); - exit $ERRORS{'UNKNOWN'}; -}; -alarm($TIMEOUT); - -# Make certain temporary directory exists - -if ( ! -e "$dir" ) { - display_res("Temporary directory $dir does not exist.\n", "CRITICAL"); - -} - -# Remove existing file if any - -if ( -e "$dir/$ftpfile") { - unlink "$dir/$ftpfile" or - display_res("Can't remove existing file $dir/$ftpfile.\n", "CRITICAL"); -} - -# Snarf file - -my $ftp = Net::FTP->new("$host", Passive => 1, Timeout => $TIMEOUT) or - display_res("Can't connect to $host.\n", "CRITICAL"); - $ftp->login("$user","$pass") or - display_res("Login to $host failed", "CRITICAL"); - $ftp->cwd("$ftpdir") or - display_res("Can't change to directory $ftpdir.\n", "CRITICAL"); - $ftp->get($ftpfile, "$dir/$ftpfile") or - display_res("Can't retrieve file $ftpfile.\n", "CRITICAL"); - $ftp->quit; - -# If file exists and is correct size we are happy. - -if (( -e "$dir/$ftpfile" ) && (($filesize = -s "/tmp/$ftpfile") eq $opt_s)) { - display_res("File $ftpfile size OK: $filesize bytes.\n", "OK"); - } else { -# Otherwise we are not happy. - display_res("File $ftpfile size incorrect: $filesize bytes", "CRITICAL"); -} - -exit; - -sub print_usage () { - print "Usage: $PROGNAME -H -f -s -t \n"; -} - -sub print_help () { - print_revision($PROGNAME,'$ Revision: 1.0 $ '); - print "Copyright (c) 2001 Patrick Greenwell, Stealthgeeks, LLC.\n\n"; - print_usage(); - support(); -} - -sub version () { - print_revision($PROGNAME,'$ Revision: 1.0 $ '); - exit $ERRORS{'OK'}; -} - -sub help () { - print_help(); - exit $ERRORS{'OK'}; -} - -sub display_res ($$) { - my ($answer, $state) = @_; - print $answer; - exit $ERRORS{$state}; -} diff --git a/contrib/check_ftpget.pl b/contrib/check_ftpget.pl deleted file mode 100755 index de7e824..0000000 --- a/contrib/check_ftpget.pl +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/perl -w -## Written 12/5/00 Jeremy Hanmer -# $Id$ - -use strict; -use Net::FTP; -use Getopt::Std; - -use vars qw($opt_H $opt_u $opt_p $opt_f); -getopts("H:u:p:f:"); - -my $host = $opt_H || - die "usage: check_ftp.pl -h host [<-u user> <-p pass> <-f file>]\n"; - -my $username = $opt_u || 'anonymous'; -my $pass = $opt_p || "$ENV{'LOGNAME'}\@$ENV{'HOSTNAME'}" ; - -my $file = $opt_f; - -my $status = 0; -my $problem; -my $output = "ftp ok"; - -my $ftp = Net::FTP->new("$host") || - &crit("connect"); - -$ftp->login("$username", "$pass") || - &crit("login"); - -$ftp->get($file) || - &crit("get") if $file; - -sub crit() -{ - $problem = $_[0]; - $status = 2; - if ( $problem eq 'connect' ) { - $output = "can't connect"; - } elsif ( $problem eq 'login' ) { - $output = "can't log in"; - } elsif ( $problem eq 'get' ) { - $output = "cant get $file"; - } -} - -print "$output\n"; -exit $status; - diff --git a/contrib/check_logins.c b/contrib/check_logins.c deleted file mode 100644 index fa3ed17..0000000 --- a/contrib/check_logins.c +++ /dev/null @@ -1,351 +0,0 @@ -/*================================= - * check_logins - Nagios plugin - * Copyright (C) 2003 Dag Robøle - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Authors email: drobole@broadpark.no - */ -//================================= -#include -#include -#include -#include -#include -#include -#include - -#include "config.h" -#include "common.h" -#include "utils.h" -#include "popen.h" -//================================= -#define REVISION "$Revision$" -#define COPYRIGHT "2003" -#define AUTHOR "Dag Robole" -#define EMAIL "drobole@broadpark.no" -#define SUMMARY "Check for multiple user logins" - -#define check(func, errmsg) { if((func) == -1) die(STATE_UNKNOWN, errmsg); } -#define checkz(func, errmsg) { if(!(func)) die(STATE_UNKNOWN, errmsg); } -//================================= -typedef struct USERNODE_TYP { - char *name; - char *host; - struct USERNODE_TYP* next; -} USERNODE; -//================================= -char *progname = NULL; -USERNODE *userlist = NULL, *adminlist = NULL; -int warning_limit = 0, critical_limit = 0; - -void print_usage(); -void print_help(); -void process_arguments(int argc, char* *argv); -void parse_wholine(const char *line, char *name, char *host); -void node_create(USERNODE* *node, const char *name, const char *host); -void node_free(USERNODE* *node); -USERNODE* list_insert_sort_uniq(USERNODE* *list, USERNODE* *node); -void list_free(USERNODE* *list); -void cleanup(); -//================================= -int main(int argc, char* *argv) -{ - FILE *who; - USERNODE *newnode, *nptra, *nptrb; - char buffer[BUFSIZ], username[BUFSIZ], hostname[BUFSIZ], *cptra, *cptrb; - char max_login_name[BUFSIZ], currname[BUFSIZ]; - int max_login_count = 0, counter = 0, skip; - void (*old_sig_alrm)(); - - progname = argv[0]; - if(atexit(cleanup)) - die(STATE_UNKNOWN, "atexit failed\n"); - - if((old_sig_alrm = signal((int)SIGALRM, timeout_alarm_handler)) == SIG_ERR) - die(STATE_UNKNOWN, "signal failed\n"); - alarm(timeout_interval); - - process_arguments(argc, argv); - - checkz(who = spopen(PATH_TO_WHO), "spopen failed\n"); - - while(fgets(buffer, sizeof(buffer), who) != NULL) { - parse_wholine(buffer, username, hostname); - skip = 0; - nptra = adminlist; - - while(nptra != NULL) { - if(!strcmp(nptra->name, username)) { - skip = 1; - break; - } - nptra = nptra->next; - } - if(!skip) { - node_create(&newnode, username, hostname); - if(!list_insert_sort_uniq(&userlist, &newnode)) - node_free(&newnode); - } - } - - check(spclose(who), "spclose failed\n"); - - if(userlist != NULL) { - nptra = userlist; - strcpy(currname, nptra->name); - strcpy(max_login_name, nptra->name); - max_login_count = 1; - while(nptra != NULL) { - if(!strcmp(currname, nptra->name)) - ++counter; - else { - if(counter > max_login_count) { - max_login_count = counter; - strcpy(max_login_name, currname); - } - strcpy(currname, nptra->name); - counter = 1; - } - nptra = nptra->next; - } - - if(counter > max_login_count) { - max_login_count = counter; - strcpy(max_login_name, currname); - } - } - - if(signal((int)SIGALRM, old_sig_alrm) == SIG_ERR) - die(STATE_UNKNOWN, "signal failed\n"); - - if(max_login_count) { - if(critical_limit && max_login_count >= critical_limit) { - printf("CRITICAL - User %s has logged in from %d different hosts\n", max_login_name, max_login_count); - return STATE_CRITICAL; - } - else if(warning_limit && max_login_count >= warning_limit) { - printf("WARNING - User %s has logged in from %d different hosts\n", max_login_name, max_login_count); - return STATE_WARNING; - } - } - - printf("OK - No users has exceeded the login limits\n"); - return STATE_OK; -} -//================================= -void print_usage() -{ - fprintf(stderr, "Usage: %s [ -hV ] [ -w limit ] [ -c limit ] [ -u username1, ... ,usernameN ]\n", progname); -} -//================================= -void print_help() -{ - print_revision(progname, REVISION); - printf("Copyright (c) %s %s <%s>\n\n%s\n\n", COPYRIGHT, AUTHOR, EMAIL, SUMMARY); - print_usage(); - printf("\nDescription:\n" - "\tThis plugin supports the w (warning) and c (critical) options indicating the upper limits\n" - "\tof logins allowed before a warning is given.\n" - "\tThe output from %s is the username and number of login sessions for the user\n" - "\twho has the most login sessions (from different hosts) running at a given point in time.\n" - "\tThe u (users) option takes a comma separated list of usernames that will be ignored\n" - "\twhile scannig users.\n" - "\nOptions:\n" - "\t-h | --help\n\t\tShow this help message and exit\n" - "\t-V | --version\n\t\tShow version description\n" - "\t-w | --warning=INTEGER\n\t\tSet warning limit for logins (minimum value is 2)\n" - "\t-c | --critical=INTEGER\n\t\tSet critical limit for logins (minimum value is 2)\n" - "\t-u | --users=STRING\n\t\tSet usernames to be ignored\n" - "\nExamples:\n\t%s -w 3 -c 5\n" - "\t%s -w 3 -c 5 -u root,guest,jcarmack\n\n", progname, progname, progname); -} -//================================= -void process_arguments(int argc, char* *argv) -{ - USERNODE *newnode; - int optch; - char buffer[BUFSIZ], *cptra; - static struct option long_opts[] = { - {"help", no_argument, 0, 'h'}, - {"version", no_argument, 0, 'V'}, - {"warning", required_argument, 0, 'w'}, - {"critical", required_argument, 0, 'c'}, - {"users", required_argument, 0, 'u'}, - {0, 0, 0, 0}, - }; - - while((optch = getopt_long(argc, argv, "hVw:c:u:", long_opts, NULL)) != -1) { - switch(optch) { - case 'h': - print_help(); - exit(STATE_OK); - break; - case 'V': - print_revision(progname, REVISION); - exit(STATE_OK); - break; - case 'w': - if(!is_numeric(optarg)) { - print_usage(); - die(STATE_UNKNOWN, "invalid options\n"); - } - warning_limit = atoi(optarg) > 2 ? atoi(optarg) : 2; - break; - case 'c': - if(!is_numeric(optarg)) { - print_usage(); - die(STATE_UNKNOWN, "invalid options\n"); - } - critical_limit = atoi(optarg) > 2 ? atoi(optarg) : 2; - break; - case 'u': - strcpy(buffer, optarg); - cptra = strtok(buffer, ","); - while(cptra != NULL) { - node_create(&newnode, cptra, "(adminhost)"); - list_insert_sort_uniq(&adminlist, &newnode); - cptra = strtok(NULL, ","); - } - break; - default: - print_usage(); - exit(STATE_UNKNOWN); - break; - } - } - - if(argc > optind) { - print_usage(); - die(STATE_UNKNOWN, "invalid options\n"); - } - - if(!warning_limit && !critical_limit) { - print_usage(); - die(STATE_UNKNOWN, "you must provide a limit for this plugin\n"); - } - - if(critical_limit && warning_limit > critical_limit) { - print_usage(); - die(STATE_UNKNOWN, "warning limit must be less or equal critical limit\n"); - } -} -//================================= -void parse_wholine(const char *line, char *name, char *host) -{ - char buffer[BUFSIZ], *cptra, *cptrb, *display; - strcpy(buffer, line); - - cptra = buffer; - checkz(cptrb = (char*)strchr(buffer, ' '), "strchr failed\n"); - strncpy(name, cptra, cptrb-cptra); - name[cptrb-cptra] = '\0'; - - if((cptra = strchr(buffer, '(')) != NULL) // hostname found in source arg... - { - if(cptra[1] == ':') // local host - strcpy(host, "(localhost)"); - else // extern host - { - checkz(cptrb = strchr(cptra, ')'), "strchr failed\n"); - cptrb++; - strncpy(host, cptra, cptrb-cptra); - host[cptrb-cptra] = '\0'; - } - } - else // no hostname in source arg, look in line arg... - { - checkz(cptra = strtok(buffer, " \t\r\n"), "strtok failed\n"); - checkz(cptra = strtok(NULL, " \t\r\n"), "strtok failed\n"); - if(cptra[0] == ':') // local host - strcpy(host, "(localhost)"); - else // extern host - sprintf(host, "(%s)", cptra); - } - - if((cptra = strchr(host, ':')) != NULL) // remove display if any... - strcpy(cptra, ")"); -} -//================================= -void node_create(USERNODE* *node, const char *name, const char *host) -{ - checkz(*node = (USERNODE*)malloc(sizeof(USERNODE)), "malloc failed\n"); - checkz((*node)->name = (char*)malloc(strlen(name)+1), "malloc failed\n"); - checkz((*node)->host = (char*)malloc(strlen(host)+1), "malloc failed\n"); - (*node)->next = NULL; - strcpy((*node)->name, name); - strcpy((*node)->host, host); -} -//================================= -void node_free(USERNODE* *node) -{ - free((*node)->name); - free((*node)->host); - free(*node); - *node = NULL; -} -//================================= -USERNODE* list_insert_sort_uniq(USERNODE* *list, USERNODE* *node) -{ - char n1[BUFSIZ], n2[BUFSIZ]; - USERNODE *last_nptr = NULL, *nptr = *list; - - if(*list == NULL) - return(*list = *node); - else { - sprintf(n1, "%s %s", (*node)->name, (*node)->host); - while(nptr != NULL) { - sprintf(n2, "%s %s", nptr->name, nptr->host); - if(!strcmp(n1, n2)) - return NULL; - else if(strcmp(n1, n2) < 0) { - if(last_nptr) { - last_nptr->next = *node; - (*node)->next = nptr; - } - else { - (*node)->next = *list; - *list = *node; - } - break; - } - else { - last_nptr = nptr; - nptr = nptr->next; - } - } - if(nptr == NULL) - last_nptr->next = *node; - } - return *node; -} -//================================= -void list_free(USERNODE* *list) -{ - USERNODE *doe, *nptr = *list; - while(nptr != NULL) { - doe = nptr; - nptr = nptr->next; - node_free(&doe); - } - *list = NULL; -} -//================================= -void cleanup() -{ - list_free(&userlist); - list_free(&adminlist); -} -//================================= diff --git a/contrib/check_mysql.c b/contrib/check_mysql.c deleted file mode 100644 index 56725dc..0000000 --- a/contrib/check_mysql.c +++ /dev/null @@ -1,75 +0,0 @@ -/***************************************************************** - * - * Program: check_mysql.c - * License: GPL - * - * Written by Tim Weippert - * (based on plugins by Ethan Galstad and MySQL example code) - * - * Command line: check_mysql [user] [passwd] - * can be the FQDN or the IP-Adress - * [user] and [passwd] are optional - * - * Description: - * - * This plugin attempts to connect to an MySQL Server - * with the optional specified parameters user and passwd. - * Normaly the host and a user HAVE to assigned. - * - * The plugin returns - * STATE_OK and the Version Number of the Server when all is fine - * STATE_CRITICAL if the Connection can't be esablished - * STATE_WARNING if the connection was established but the - * program can't get the Versoin Number - * STATE_UNKNOWN if to many parameters are given - * - * Copyright (c) 1999 by Tim Weippert - * - * Changes: - * 16.12.1999: Changed the return codes from numbers to statements - * - *******************************************************************/ - -#include "config.h" -#include "common.h" -#include "mysql.h" - -MYSQL mysql; - -int main(int argc, char **argv) -{ - uint i = 0; - char *host; - char *user; - char *passwd; - - char *status; - char *version; - - if ( argc > 4 ) { - printf("Too many Arguments supplied - %i .\n", argc); - printf("Usage: %s [user] [passwd]\n", argv[0]); - return STATE_UNKNOWN; - } - - (host = argv[1]) || (host = NULL); - (user = argv[2]) || (user = NULL); - (passwd = argv[3]) || (passwd = NULL); - - if (!(mysql_connect(&mysql,host,user,passwd))) { - printf("Can't connect to Mysql on Host: %s\n", host); - return STATE_CRITICAL; - } - - if ( !(version = mysql_get_server_info(&mysql)) ) { - printf("Connect OK, but can't get Serverinfo ... something wrong !\n"); - return STATE_WARNING; - } - - printf("Mysql ok - Running Version: %s\n", version); - - mysql_close(&mysql); - return STATE_OK; -} - - diff --git a/contrib/check_mysql.pl b/contrib/check_mysql.pl deleted file mode 100644 index 143d5a5..0000000 --- a/contrib/check_mysql.pl +++ /dev/null @@ -1,73 +0,0 @@ -#!/nyet/bin/perl -# -# (c)1999 Mitch Wright, NetLine Corporation -# Read the GNU copyright stuff for all the legalese -# -# Check to see that our MySQL server(s) are up and running. -# This plugin requires that mysqladmin(1) is installed on the system. -# Since it is part of the MySQL distribution, that should be a problem. -# -# If no parameters are giving, a usage statement is output. -# -# Exit 0 on success, providing some informational output -# Exit 2 on failure, provide what we can... -# - -require 5.004; - -sub usage; - -my $TIMEOUT = 15; -my $MYSQLADMIN = "/usr/local/bin/mysqladmin"; - -my %ERRORS = ('UNKNOWN' , '-1', - 'OK' , '0', - 'WARNING', '1', - 'CRITICAL', '2'); - -my $host = shift || &usage(%ERRORS); -my $user = shift || &usage(%ERRORS); -my $pass = shift || ""; -my $warn = shift || 60; -my $crit = shift || 100; - -my $state = "OK"; - -# Just in case of problems, let's not hang Nagios -$SIG{'ALRM'} = sub { - print ("ERROR: No response from MySQL server (alarm)\n"); - exit $ERRORS{"UNKNOWN"}; -}; -alarm($TIMEOUT); - -open (OUTPUT, - "$MYSQLADMIN -h $host -u $user --password=\"$pass\" version 2>&1 - |"); - -while () { - if (/failed/) { $state="CRITICAL"; s/.*://; $status=$_; last; } - next if /^\s*$/; - if (/^Server version\s+(\d+.*)/) { $version = $1; next; } - if (/^Uptime:\s+(\d.*)/) { $uptime = $1; next; } - if (/^Threads:\s+(\d+)\s+/) { $threads = $1; next; } -} - -$status = "Version $version -- $threads Threads
Uptime $uptime" if -$state ne "CRITICAL"; - -if ($threads >= $warn) { $state = "WARNING"; } -if ($threads >= $crit) { $state = "CRITICAL"; } - -print $status; -exit $ERRORS{$state}; - -sub usage { - print "Required arguments not given!\n\n"; - print "MySQL status checker plugin for Nagios, V1.01\n"; - print "Copyright (c) 1999-2000 Mitch Wright \n\n"; - print "Usage: check_mysql.pl [ [ - []]]\n\n"; print " = password to use for at - \n"; print " = number of threads to warn us - about\n"; print " = number of threads to scream at us - about\n"; exit $ERRORS{"UNKNOWN"}; -} diff --git a/contrib/check_mysqlslave.pl b/contrib/check_mysqlslave.pl deleted file mode 100644 index ab7af89..0000000 --- a/contrib/check_mysqlslave.pl +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/perl -w -# -# check_mysqlslave.pl - nagios plugin -# -# -# Copyright 2002 Mario Witte -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -# -# Credits: -# - Thanks to Christoph Kron for check_ifstatus.pl -# I used check_ifstatus.pl as a layout when writing this -# -# Report bugs to: chengfu@users.sourceforge.net -# -# 20.09.2002 Version 0.1 - - -use strict; -use lib "/usr/local/nagios/libexec"; -use utils qw($TIMEOUT %ERRORS &print_revision &support); - -use DBI; -use DBD::mysql; -use Getopt::Long; -Getopt::Long::Configure('bundling'); - -# Predeclare some variables -my $PROGNAME = 'check_mysqlslave'; -my $REVISION = '0.1'; -my $status; -my $state = 'UNKNOWN'; -my $opt_V; -my $opt_h; -my $port = 3306; -my $hostname; -my $user = 'root'; -my $pass = ''; -my $driver; -my $dbh; -my $query; -my $result; -my $data; - -# Just in case of problems, let's not hang Nagios -$SIG{'ALRM'} = sub { - print ("ERROR: No response from $hostname (alarm timeout)\n"); - exit $ERRORS{"UNKNOWN"}; -}; -alarm($TIMEOUT); - -$status = GetOptions( - "V" => \$opt_V, "version" => \$opt_V, - "h" => \$opt_h, "help" => \$opt_h, - "p=i" => \$port, "port=i" => \$port, - "H=s" => \$hostname, "hostname=s" => \$hostname, - "u=s" => \$user, "user=s" => \$user, - "P=s" => \$pass, "pass=s" => \$pass, - ); - - -if ($status == 0) { - print_help() ; - exit $ERRORS{'OK'}; -} - -if ($opt_V) { - print_revision($PROGNAME,'$Revision$REVISION .' $ '); - exit $ERRORS{'OK'}; -} - -if ($opt_h) { - print_help(); - exit $ERRORS{'OK'}; -} - -if (! utils::is_hostname($hostname)){ - usage(); - exit $ERRORS{"UNKNOWN"}; -} - - -$driver = 'DBI:mysql::'. $hostname; - -eval { - $dbh = DBI->connect($driver, $user, $pass, { RaiseError => 1, PrintError => 0}); -}; -if ($@) { - $status = $@; - if ($status =~ /^.*failed:\ (.+)\ at\ $0/i) { $status = $1; } - $state='CRITICAL'; - print $state .': Connect failed: '."$status\n"; - exit ($ERRORS{$state}); -} - -eval { - $query = 'SHOW SLAVE STATUS'; - $result = $dbh->prepare($query); - $result->execute; - $data = $result->fetchrow_hashref(); - $result->finish(); - $dbh->disconnect(); -}; -if ($@) { - $status = $@; - $status =~ s/\n/ /g; - if ($status =~ /^DB[ID].*(failed|prepare):\ (.+)\ at\ $0/i) { $status = $2; } - $state = 'CRITICAL'; - print $state .': Couldn\'t check slave: '."$status\n"; - exit($ERRORS{$state}); -} - -if ($data->{'Slave_Running'} eq 'Yes') { - $status = 'Replicating from '. $data->{'Master_Host'}; - $state = 'OK'; - print $state .': '. $status ."\n"; - exit($ERRORS{$state}); -} elsif ($data->{'Slave_Running'} eq 'No') { - if (length($data->{'Last_error'}) > 0) { - $status = 'Slave stopped with error message'; - $state = 'CRITICAL'; - print $state .': '. $status ."\n"; - exit($ERRORS{$state}); - } else { - $status = 'Slave stopped without errors'; - $state = 'WARNING'; - print $state .': '. $status ."\n"; - exit($ERRORS{$state}); - } -} else { - $status = 'Unknown slave status: (Running: '. $data->{'Slave_Running'} .')'; - $state = 'UNKNOWN'; - print $state .': '. $status ."\n"; - exit($ERRORS{$state}); -} - -sub usage { - printf "\nMissing arguments!\n"; - printf "\n"; - printf "check_mysqlslave -H [-p -u -P ]\n"; - printf "Copyright 2002 Mario Witte\n"; - printf "\n\n"; - support(); - exit $ERRORS{"UNKNOWN"}; -} - -sub print_help { - printf "check_mysqlslave plugin for Nagios checks \n"; - printf "if the replication on a backup mysql-server\n"; - printf "is up and running\n"; - printf "\nUsage:\n"; - printf " -H (--hostname) Hostname to query\n"; - printf " -p (--port) mysql port (default: 3306)\n"; - printf " -u (--user) username for accessing mysql host\n"; - printf " (default: root)\n"; - printf " -P (--pass) password for accessing mysql host\n"; - printf " (default: '')\n"; - printf " -V (--version) Plugin version\n"; - printf " -h (--help) usage help \n\n"; - print_revision($PROGNAME, '$Revision$REVISION .' $'); - -} diff --git a/contrib/check_nwstat.pl b/contrib/check_nwstat.pl deleted file mode 100644 index 2194640..0000000 --- a/contrib/check_nwstat.pl +++ /dev/null @@ -1,188 +0,0 @@ -#!/usr/bin/perl -# -# check_nwstat.pl: Nagios plugin that uses Jim Drews' nwstat.pl for -# MRTG instead of emulating it. For use particularly with Cliff -# Woolley's mrtgext.pl Unix companion to Drews' MRTGEXT.NLM, where -# mrtgext.pl can contain custom commands that check_nwstat won't recognize, -# though this also does its best to perfectly emulate the C version -# of check_nwstat. -# - - -###################################################################### -# Configuration -###################################################################### - -$nwstatcmd = "/apps/mrtg/helpers/nwstat.pl"; - -use Getopt::Long; - -$::host = shift || &usage(%ERROR); -$::opt_v = undef; -$::opt_wv = undef; -$::opt_cv = undef; -$::opt_to = 10; -$::opt_url = undef; - -GetOptions (qw(v=s wv=i cv=i to=i url=s)) || &usage(%ERROR); - -my $cmd1 = ""; -my $cmd2 = "ZERO"; -my $backward = 0; -my $desc = ""; -my $okstr = "OK"; -my $probstr = "Problem"; -my $result = ""; -my @CMD; -my %ERROR = ("UNKNOWN" => -1, - "OK" => 0, - "WARNING" => 1, - "CRITICAL" => 2); -my $status = $ERROR{"OK"}; - - -###################################################################### -# Main program -###################################################################### - -$SIG{'ALRM'} = sub { - print "Connection timed out\n"; - exit $ERROR{"CRITICAL"}; -}; - -# translate table for compatability with -# check_nwstat (C version) -SWITCH: for ($::opt_v) { - /^LOAD(1|5|15)$/ - && do { $desc = "Load - Up , ". - "$1-min load average = %"; - $cmd1 = "UTIL$1"; last; }; - /^CONNS$/ && do { $desc = "Conns : ". - " current connections"; - $cmd1 = "CONNECT"; last; }; - /^CDBUFF$/ && do { $desc = "Dirty cache buffers = "; - $cmd1 = "S3"; last; }; - /^LTCH$/ && do { $desc = "Long term cache hits = %"; - $cmd1 = "S1"; - $backward = 1; last; }; - /^CBUFF$/ && do { $desc = "Total cache buffers = "; - $cmd1 = "S2"; - $backward = 1; last; }; - /^LRUM$/ && do { $desc = "LRU sitting time = minutes"; - $cmd1 = "S5"; - $backward = 1; last; }; - /^VPF(.*)$/ && do { $desc = " MB ". - "(%) free on volume $1"; - $okstr = ""; $probstr = "Only "; - $cmd1 = "VKF$1"; - $cmd2 = "VKS$1"; - $backward = 1; last; }; - /^VKF/ && do { $desc = " KB free on volume $1"; - $okstr = ""; $probstr = "Only "; - $cmd1 = "$::opt_v"; - $backward = 1; last; }; - /^$/ && die "Nothing to check!"; - $desc = ": "; - $cmd1 = "$::opt_v"; - } - - -# begin timeout period, run the check -alarm($::opt_to); -open ( CMD, "$nwstatcmd $host $cmd1 $cmd2|" ) || die "Couldn't execute nwstat"; -@CMD = ; -close ( CMD ); -alarm(0); - -for (@CMD) { chomp; } - -# for any variables that manipulate the results instead of -# just using directly, do that manipulation here into -SWITCH: for ($::opt_v) { - /^VPF/ && do { $result=int(("$CMD[0]"/"$CMD[1]")*100); last; }; - $result = "$CMD[0]"; - } - -if ("$result" == -1) { - $status = $ERROR{"UNKNOWN"}; - $desc = "Server returned \"variable unknown\""; -} elsif ("$result" == -2) { - $status = $ERROR{"CRITICAL"}; - $desc = "Connection failed"; -} - -if (defined($::opt_cv) && $status == $ERROR{"OK"}) { - if ($backward) { - ("$result" <= "$::opt_cv") && ( $status = $ERROR{"CRITICAL"} ); - } else { - ("$result" >= "$::opt_cv") && ( $status = $ERROR{"CRITICAL"} ); - } -} -if (defined($::opt_wv) && $status == $ERROR{"OK"}) { - if ($backward) { - ("$result" <= "$::opt_wv") && ( $status = $ERROR{"WARNING"} ); - } else { - ("$result" >= "$::opt_wv") && ( $status = $ERROR{"WARNING"} ); - } -} - -$desc =~ s//($status == $ERROR{"OK"})?"$okstr":"$probstr"/eg; -$desc =~ s/<([^>]*)cmd([0-3])([^>]*)>/eval("$1\"$CMD[$2]\"$3")/eg; -$desc =~ s//"$result"/eg; - -if (defined($::opt_url)) { - print "$desc\n"; -} else { - print "$desc\n"; -} -exit $status; - - -###################################################################### -# Subroutines -###################################################################### - -sub usage { - - %ERROR = shift; - - print < [-v variable] [-wv warn_value] [-cv crit_value] [-to to_sec] [-url url_value] - -Options: - [variable] = Variable to check. Valid variables include: - LOAD1 = 1 minute average CPU load - LOAD5 = 5 minute average CPU load - LOAD15 = 15 minute average CPU load - CONNS = number of currently licensed connections - VPF = percent free space on volume - VKF = KB of free space on volume - LTCH = percent long term cache hits - CBUFF = current number of cache buffers - CDBUFF = current number of dirty cache buffers - LRUM = LRU sitting time in minutes - [warn_value] = Threshold for value necessary to result in a warning status - [crit_value] = Threshold for value necessary to result in a critical status - [to_sec] = Number of secs before connection times out - default is 10 sec - [url_value] = URL to use in output as a hyperlink. Useful to link to a page - with more details or history for this variable (ie an MRTG page) - -This plugin attempts to contact the MRTGEXT NLM running on a Novell server -to gather the requested system information. - -Notes: - - This plugin requres that the MRTGEXT.NLM file distributed with - James Drews' MRTG extension for NetWare (available from - http://www.engr.wisc.edu/~drews/mrtg/) be loaded on the Novell - servers you wish to check. - - Critical thresholds should be lower than warning thresholds when - the following variables are checked: VPF, VKF, LTCH, CBUFF, and LRUM. -EOF -; - - exit $ERROR{"UNKNOWN"}; -} - diff --git a/contrib/check_pop3.pl b/contrib/check_pop3.pl deleted file mode 100644 index 37f2ce0..0000000 --- a/contrib/check_pop3.pl +++ /dev/null @@ -1,148 +0,0 @@ -#!/usr/bin/perl -# ------------------------------------------------------------------------------ -# File Name: check_pop3.pl -# Author: Richard Mayhew - South Africa -# Date: 2000/01/21 -# Version: 1.0 -# Description: This script will check to see if an POP3 is running -# and whether authentication can take place. -# Email: netsaint@splash.co.za -# ------------------------------------------------------------------------------ -# Copyright 1999 (c) Richard Mayhew -# Credits go to Ethan Galstad for coding Nagios -# If any changes are made to this script, please mail me a copy of the -# changes :) -# License GPL -# ------------------------------------------------------------------------------ -# Date Author Reason -# ---- ------ ------ -# 1999/09/20 RM Creation -# 1999/09/20 TP Changed script to use strict, more secure by -# specifying $ENV variables. The bind command is -# still insecure through. Did most of my work -# with perl -wT and 'use strict' -# 2000/01/20 RM Corrected POP3 Exit State. -# 2000/01/21 RM Fix Exit Codes Again!! -# 2003/12/30 CZ Proper CRLF in communication w/server -# Fixed infinite loop -# Error checking on welcome banner, USER, PASS commands -# Better error condition handling - -# ------------------------------------------------------------------------------ - -# -----------------------------------------------------------------[ Require ]-- -require 5.004; - -# --------------------------------------------------------------------[ Uses ]-- -use Socket; -use strict; - -# --------------------------------------------------------------[ Enviroment ]-- -$ENV{PATH} = "/bin"; -$ENV{BASH_ENV} = ""; -$|=1; -# ------------------------------------------------------------------[ Global ]-- -my $TIMEOUT = 60; - -# -------------------------------------------------------------------[ usage ]-- -sub usage -{ - print "Minimum arguments not supplied!\n"; - print "\n"; - print "Perl Check POP3 plugin for Nagios\n"; - print "Copyright (c) 2000 Richard Mayhew\n"; - print "\n"; - print "Usage: check_pop3.pl [port]\n"; - print "\n"; - print " = Port that the pop3 daemon is running on . Defaults to 110.\n"; - exit -1; - -} - -# --------------------------------------------------------------[ bindRemote ]-- -sub bindRemote -{ - my ($in_remotehost, $in_remoteport, $in_hostname) = @_; - my $proto; - my $sockaddr; - my $this; - my $thisaddr; - my $that; - my ($name, $aliases,$type,$len,$thataddr) = gethostbyname($in_remotehost); - - if (!socket(ClientSocket,AF_INET, SOCK_STREAM, $proto)) { die $!; } - $sockaddr = 'S n a4 x8'; - $this = pack($sockaddr, AF_INET, 0, $thisaddr); - $that = pack($sockaddr, AF_INET, $in_remoteport, $thataddr); - if (!bind(ClientSocket, $this)) { print "Connection Refused\n"; exit 2; } - if (!connect(ClientSocket, $that)) { print "Connection Refused\n"; exit 2; } - select(ClientSocket); $| = 1; select(STDOUT); - return \*ClientSocket; -} - -# ====================================================================[ MAIN ]== -MAIN: -{ - my $hostname; - my $remotehost = shift || &usage; - my $username = shift || &usage; - my $password = shift || &usage; - my $remoteport = shift || 110; - - # Just in case of problems, let's not hang Nagios - $SIG{'ALRM'} = sub { - print "Something is Taking a Long Time, Increase Your TIMEOUT (Currently Set At $TIMEOUT Seconds)\n"; - exit -1; - }; - - alarm($TIMEOUT); - - chop($hostname = `hostname`); - my ($name, $alias, $proto) = getprotobyname('tcp'); - my $ClientSocket = &bindRemote($remotehost,$remoteport,$hostname); - - - &err("no welcome banner\n") unless $_ = ; - &err("bad welcome banner: " . $_) unless $_ =~ /^\+OK/; - - print ClientSocket "USER $username\r\n"; - - &err("no response to USER command\n") unless $_ = ; - &err("bad response to USER: " . $_) unless $_ =~ /^\+OK/; - - print ClientSocket "PASS $password\r\n"; - - &err("no response to PASS command\n") unless $_ = ; - &err("bad response to PASS: " . $_) unless $_ =~ /^\+OK/; - - print ClientSocket "LIST\r\n"; - - my $bad = 1; - my $msgs = 0; - while () { - &err(($1||' UNKNOWN')."\n") if (m/\-ERR(.*)/); - $bad = 0 if /^\+OK/; - $msgs = $1 if /^(\d+)\s+/; - last if /^\./; - } - &message("$msgs\n") unless $bad; - &err("missing +OK to LIST command\n"); -} - -sub message -{ - my $msg = shift; - alarm(0); - print ClientSocket "QUIT\r\n"; - print "POP3 OK - Total Messages On Server: $msg"; - exit 0; -} - -sub err -{ - my $msg = shift; - alarm(0); - print ClientSocket "QUIT\r\n"; - print "POP3 Error: $msg"; - exit 2; -} diff --git a/contrib/check_procl.sh b/contrib/check_procl.sh deleted file mode 100644 index b1793ad..0000000 --- a/contrib/check_procl.sh +++ /dev/null @@ -1,400 +0,0 @@ -#!/bin/bash - -# -# Check_procl.sh -# -# Program: Process load check plugin for Nagios -# License : GPL -# Copyright (c) 2002 Jerome Tytgat (j.tytgat@sioban.net) -# -# check_procl.sh,v 1.1 2002/07/04 09:35 -# -# Description : -# -# This plugin is for check the %cpu, %mem or cputime of one or more process -# -# Usage : -# -# check_procl.sh -p process1,process2,... -w a.b -c c.d --cpu -# check_procl.sh -p process1,process2,... -w a.b -c c.d --mem -# check_procl.sh -p process1,process2,... -w a:b:c -c d:e:f --cputime -# -# check_procl.sh -p %all% -e process1,process2,... -w -c <--cpu | --mem | --cputime> -# check_procl.sh -p %max% -e process1,process2,... -w -c <--cpu | --mem | --cputime> -# -# Example : -# -# To know the memory eaten by HTTPD processes, be warned when it reach 50% and be critical when it reach 75% -# check_procl.sh -p httpd -w 50.0 -c 75.0 --mem -# > OK - total %MEM for process httpd : 46.1 -# -# To know the process which eat the more cpu time, but as we are under linux and are using kapm we do : -# check_procl.sh -p %max% -e kapmd-idle,kapmd -w 0:1:0 -c 0:2:0 --cputime -# > CRITICAL - total CPUTIME for process named : 02:32:10 -# -# Tested on solaris 7/8, Linux Redhat 7.3 and Linux Suse 7.1 -# -# BUGS : problems with handling time on solaris... - - -help_usage() { - echo "Usage:" - echo " $0 -p " - echo " [-e ] -w warning -c critical < --cpu | --mem | --cputime>" - echo " $0 (-v | --version)" - echo " $0 (-h | --help)" -} - -help_version() { - echo "check_procl.sh (nagios-plugins) 1.1" - echo "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute" - echo "copies of the plugins under the terms of the GNU General Public License." - echo "For more information about these matters, see the file named COPYING." - echo "Copyright (c) 2002 Jerome Tytgat - j.tytgat@sioban.net" - echo "Greetings goes to Websurg which kindly let me took time to develop this" - echo " Manu Feig and Jacques Kern who were my beta testers, thanks to them !" -} - -verify_dep() { - needed="bash cut egrep expr grep let ps sed sort tail test tr wc" - for i in `echo $needed` - do - type $i > /dev/null 2>&1 /dev/null - if [ $? -eq 1 ] - then - echo "I am missing an important component : $i" - echo "Cannot continue, sorry, try to find the missing one..." - exit 3 - fi - done -} - -myself=$0 - -verify_dep - -if [ "$1" = "-h" -o "$1" = "--help" ] -then - help_version - echo "" - echo "This plugin will check either the cumulutative %cpu, %mem or cputime" - echo "of a process." - echo "" - help_usage - echo "" - echo "Required Arguments:" - echo " -p, --process STRING1,STRING2,..." - echo " names of the processes we want to monitor," - echo " you can add as much as process as you want, separated by comma," - echo " hey will be cumulated" - echo " -p, --process %all%" - echo " The special keyword %all% will check the cumulative cpu/mem/time of all process" - echo " WARNING : Can be very slow on heavy loaded servers, watch your timeout !" - echo " -p, --process %max%" - echo " The special keyword %max% will check the process which eat the most" - echo " WARNING : only select the process which eat the more, not the cumulative," - echo " but return the cumulative" - echo " -w, --warning INTEGER.INTEGER or INTERGER:INTEGER:INTEGER" - echo " generate warning state if process count is outside this range" - echo " -c, --critical INTEGER.INTEGER or INTERGER:INTEGER:INTEGER" - echo " generate critical state if process count is outside this range" - echo " --cpu" - echo " return the current cpu usage for the given process" - echo " --mem" - echo " return the current memory usage for the given process" - echo " --cputime" - echo " return the total cputime usage for the given process" - echo "" - echo "Optional Argument:" - echo " -e, --exclude-process STRING1,STRING2,..." - echo " names of the processes we want don't want to monitor" - echo " only useful when associated with %all% or %max% keywords, else ignored" - echo " ex : kapm-idled on linux is a process which eat memory / cputime but not really... ;-)" - echo "" - exit 3 -fi - -if [ "$1" = "-v" -o "$1" = "--version" ] -then - help_version - exit 3 -fi - -if [ `echo $@|tr "=" " "|wc -w` -lt 7 ] -then - echo "Bad arguments number (need at least 7)!" - help_usage - exit 3 -fi - -tt=0 -process_name="" -exclude_process_name="" -wt="" -ct="" - -# Test of the command lines arguments -while test $# -gt 0 -do - - case "$1" in - -p|--process) - if [ -n "$process_name" ] - then - echo "Only one --process argument is useful..." - help_usage - exit 3 - fi - shift - process_name="`echo $1|tr \",\" \"|\"`" - ;; - -e|--exclude-process) - if [ -n "$exclude_process_name" ] - then - echo "Only one --exclude-process argument is useful..." - help_usage - exit 3 - fi - shift - exclude_process_name="`echo $1|tr \",\" \"|\"`" - ;; - -w|--warning) - if [ -n "$wt" ] - then - echo "Only one --warning argument needed... Trying to test bad things ? :-)" - help_usage - exit 3 - fi - shift - wt=$1 - ;; - -c|--critical) - if [ -n "$ct" ] - then - echo "Only one --critical argument needed... Trying to test bad things ? :-)" - help_usage - exit 3 - fi - shift - ct=$1 - ;; - --cpu) - if [ $tt -eq 0 ] - then - tt=1 - else - echo "Only one of the arguments --cpu/--mem/--cputime can be used at a time !" - help_usage - exit 3 - fi - type_arg_aff="%CPU" - type_arg="pcpu" - delim="." - ;; - --mem) - if [ $tt -eq 0 ] - then - tt=2 - else - echo "Only one of the arguments --cpu/--mem/--cputime can be used at a time !" - help_usage - exit 3 - fi - type_arg_aff="%MEM" - type_arg="pmem" - delim="." - ;; - --cputime) - if [ $tt -eq 0 ] - then - tt=3 - else - echo "Only one of the arguments --cpu/--mem/--cputime can be used at a time !" - help_usage - exit 3 - fi - type_arg_aff="TIME" - type_arg="time" - delim=":" - ;; - *) - echo "Unknown argument $1" - help_usage - exit 3 - ;; - esac - shift -done - -# Is the process running ? -if [ -z "`ps -e | egrep \"$process_name?\"`" -a "$process_name" != "%all%" -a "$process_name" != "%max%" ] -then - echo "WARNING: process $process_name not running !" - exit 3 -fi - -# Cut of warning and critical values -wt_value1=`echo $wt|cut -d"$delim" -f1` -wt_value2=`echo $wt|cut -d"$delim" -f2` -ct_value1=`echo $ct|cut -d"$delim" -f1` -ct_value2=`echo $ct|cut -d"$delim" -f2` - -if [ $tt -eq 3 ] -then - wt_value3=`echo $wt|cut -d"$delim" -f3` - ct_value3=`echo $ct|cut -d"$delim" -f3` -else - wt_value3=0 - ct_value3=0 -fi - -# Integrity check of warning and critical values -if [ -z "$wt_value1" -o -z "$wt_value2" -o -z "$wt_value3" ] -then - echo "Bad expression in the WARNING field : $wt" - help_usage - exit 3 -fi - -if [ "`echo $wt_value1|tr -d \"[:digit:]\"`" != "" -o "`echo $wt_value2|tr -d \"[:digit:]\"`" != "" -o "`echo $wt_value3|tr -d \"[:digit:]\"`" != "" ] -then - echo "Bad expression in the WARNING field : $wt" - help_usage - exit 3 -fi - -if [ -z "$ct_value1" -o -z "$ct_value2" -o -z "$ct_value3" ] -then - echo "Bad expression in the CRITICAL field : $ct" - help_usage - exit 3 -fi - - -if [ "`echo $ct_value1|tr -d \"[:digit:]\"`" != "" -o "`echo $ct_value2|tr -d \"[:digit:]\"`" != "" -o "`echo $ct_value3|tr -d \"[:digit:]\"`" != "" ] -then - echo "Bad expression in the CRITICAL field : $ct" - help_usage - exit 3 -fi - -# ps line construction set... -case "$process_name" in - %all%) - if [ -z "$exclude_process_name" ] - then - psline=`ps -eo $type_arg,comm|egrep -v "$myself|$type_arg_aff?"|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f1` - else - psline=`ps -eo $type_arg,comm|egrep -v "$myself|$type_arg_aff|$exclude_process_name?"|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f1` - fi - ;; - %max%) - if [ -z "$exclude_process_name" ] - then - pstmp=`ps -eo $type_arg,comm|egrep -v "$myself|$type_arg_aff?"|sort|tail -1|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f2` - else - pstmp=`ps -eo $type_arg,comm|egrep -v "$myself|$type_arg_aff|$exclude_process_name?"|sort|tail -1|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f2` - fi - psline=`ps -eo $type_arg,comm|grep $pstmp|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f1` - process_name=$pstmp - ;; - *) - psline=`ps -eo $type_arg,comm|egrep "$process_name?"|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f1` - ;; -esac - -total1=0 -total2=0 -total3=0 - - -# fetching the values -for i in $psline -do - # Special case for solaris - several format exist for the time function... - if [ ${#i} -le 6 -a "$tt" -eq 3 ] - then - i="00:$i" - fi - value1=`echo $i|cut -d$delim -f1` - value2=`echo $i|cut -d$delim -f2` - value3=`echo $i|cut -d$delim -f3` - value3=`test -z "$value3" && echo 0 || echo $value3` - total1=`expr $total1 + $value1` - total2=`expr $total2 + $value2` - total3=`expr $total3 + $value3` - if [ $tt -eq 3 ] - then - if [ $total3 -ge 60 ] - then - let total2+=1 - let total3-=60 - fi - if [ $total2 -ge 60 ] - then - let total1+=1 - let total2-=60 - fi - else - if [ $total2 -ge 10 ] - then - let total1+=1 - let total2=total2-10 - fi - fi -done - -warn=0 -crit=0 - -# evaluation of the cumulative values vs warning and critical values -case "$tt" in - 1) - return_total="$total1.$total2" - test $total1 -gt $ct_value1 && crit=1 - test $total1 -eq $ct_value1 -a $total2 -ge $ct_value2 && crit=1 - test $total1 -gt $wt_value1 && warn=1 - test $total1 -eq $wt_value1 -a $total2 -ge $wt_value2 && warn=1 - ;; - 2) - return_total="$total1.$total2" - test $total1 -gt $ct_value1 && crit=1 - test $total1 -eq $ct_value1 -a $total2 -ge $ct_value2 && crit=1 - test $total1 -gt $wt_value1 && warn=1 - test $total1 -eq $wt_value1 -a $total2 -ge $wt_value2 && warn=1 - ;; - 3) - return_total="`test ${#total1} -eq 1 && echo 0`$total1:`test ${#total2} -eq 1 && echo 0`$total2:`test ${#total3} -eq 1 && echo 0`$total3" - test $total1 -gt $ct_value1 && crit=1 - test $total1 -eq $ct_value1 -a $total2 -gt $ct_value2 && crit=1 - test $total1 -eq $ct_value1 -a $total2 -eq $ct_value2 -a $total3 -ge $ct_value3 && crit=1 - test $total1 -gt $wt_value1 && warn=1 - test $total1 -eq $wt_value1 -a $total2 -gt $wt_value2 && warn=1 - test $total1 -eq $wt_value1 -a $total2 -eq $wt_value2 -a $total3 -ge $wt_value3 && warn=1 - ;; -esac - -# last check ... -if [ $crit -eq 1 -a $warn -eq 0 ] -then - echo "Critical value must be greater than warning value !" - help_usage - exit 3 -fi - -# Finally Inform Nagios of what we found... -if [ $crit -eq 1 ] -then - echo "CRITICAL - total $type_arg_aff for process `echo $process_name|tr \"|\" \",\"` : $return_total" - exit 2 -elif [ $warn -eq 1 ] -then - echo "WARNING - total $type_arg_aff for process `echo $process_name|tr \"|\" \",\"` : $return_total" - exit 1 -else - echo "OK - total $type_arg_aff for process `echo $process_name|tr \"|\" \",\"` : $return_total" - exit 0 -fi - -# Hey what are we doing here ??? -exit 3 \ No newline at end of file diff --git a/contrib/check_procr.sh b/contrib/check_procr.sh deleted file mode 100644 index c99a17e..0000000 --- a/contrib/check_procr.sh +++ /dev/null @@ -1,147 +0,0 @@ -#!/bin/bash - -# -# Check_procr.sh -# -# Program: Process running check plugin for Nagios -# License : GPL -# Copyright (c) 2002 Jerome Tytgat (j.tytgat@sioban.net) -# -# check_procr.sh,v 1.0 2002/09/18 15:28 -# -# Description : -# -# This plugin check if at least one process is running -# -# Usage : -# -# check_procr.sh -p process_name -# -# Example : -# -# To know if snort is running -# check_procr.sh -p snort -# > OK - total snort running : PID=23441 -# -# Linux Redhat 7.3 -# - -help_usage() { - echo "Usage:" - echo " $0 -p " - echo " $0 (-v | --version)" - echo " $0 (-h | --help)" -} - -help_version() { - echo "check_procr.sh (nagios-plugins) 1.0" - echo "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute" - echo "copies of the plugins under the terms of the GNU General Public License." - echo "For more information about these matters, see the file named COPYING." - echo "Copyright (c) 2002 Jerome Tytgat - j.tytgat@sioban.net" - echo "Greetings goes to Websurg which kindly let me took time to develop this" - echo " Manu Feig and Jacques Kern who were my beta testers, thanks to them !" -} - -verify_dep() { - needed="bash cut egrep expr grep let ps sed sort tail test tr wc" - for i in `echo $needed` - do - type $i > /dev/null 2>&1 /dev/null - if [ $? -eq 1 ] - then - echo "I am missing an important component : $i" - echo "Cannot continue, sorry, try to find the missing one..." - exit 3 - fi - done -} - -myself=$0 - -verify_dep - -if [ "$1" = "-h" -o "$1" = "--help" ] -then - help_version - echo "" - echo "This plugin will check if a process is running." - echo "" - help_usage - echo "" - echo "Required Arguments:" - echo " -p, --process STRING" - echo " process name we want to verify" - echo "" - exit 3 -fi - -if [ "$1" = "-v" -o "$1" = "--version" ] -then - help_version - exit 3 -fi - -if [ `echo $@|tr "=" " "|wc -w` -lt 2 ] -then - echo "Bad arguments number (need two)!" - help_usage - exit 3 -fi - -tt=0 -process_name="" -exclude_process_name="" -wt="" -ct="" - -# Test of the command lines arguments -while test $# -gt 0 -do - - case "$1" in - -p|--process) - if [ -n "$process_name" ] - then - echo "Only one --process argument is useful..." - help_usage - exit 3 - fi - shift - process_name="`echo $1|tr \",\" \"|\"`" - ;; - *) - echo "Unknown argument $1" - help_usage - exit 3 - ;; - esac - shift -done - -# ps line construction set... -for i in `ps ho pid -C $process_name` -do - pid_list="$pid_list $i" -done - -if [ -z "$pid_list" ] -then - crit=1 -else - crit=0 -fi - -# Finally Inform Nagios of what we found... -if [ $crit -eq 1 ] -then - echo "CRITICAL - process $process_name is not running !" - exit 2 -else - echo "OK - process $process_name is running : PID=$pid_list " - exit 0 -fi - -# Hey what are we doing here ??? -exit 3 - -- cgit v0.10-9-g596f