summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--contrib/check_dl_size.pl148
-rwxr-xr-xcontrib/check_ftpget.pl48
-rw-r--r--contrib/check_logins.c351
-rw-r--r--contrib/check_mysql.c75
-rw-r--r--contrib/check_mysql.pl73
-rw-r--r--contrib/check_mysqlslave.pl174
-rw-r--r--contrib/check_nwstat.pl188
-rw-r--r--contrib/check_pop3.pl148
-rw-r--r--contrib/check_procl.sh400
-rw-r--r--contrib/check_procr.sh147
10 files changed, 0 insertions, 1752 deletions
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 @@
1#! /usr/bin/perl -wT
2
3# (c)2001 Patrick Greenwell, Stealthgeeks, LLC. (patrick@stealthgeeks.net)
4# Licensed under the GNU GPL
5# http://www.gnu.org/licenses/gpl.html
6#
7# check_dl_size: Attempts to download a specified file via FTP and verify
8# it is a specified size.
9# Requires Net::FTP
10
11# Version 1.0
12# Last Updated: 8/31/01
13
14
15BEGIN {
16 if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
17 $runtimedir = $1;
18 $PROGNAME = $2;
19 }
20}
21
22require 5.004;
23use strict;
24use Getopt::Long;
25use vars qw($opt_H $opt_f $opt_s $opt_t $verbose $PROGNAME);
26use lib $main::runtimedir;
27use utils qw($TIMEOUT %ERRORS &print_revision &usage &support &is_error);
28use Net::FTP;
29
30sub help ();
31sub print_help ();
32sub print_usage ();
33sub version ();
34sub display_res($$);
35my ($ftpfile, $ftpdir, $filesize, $answer) = ();
36my $state = $ERRORS{'UNKNOWN'};
37
38# Directory to place file. If your machine is not secure DO NOT USE /tmp.
39my $dir = "/usr/local/netsaint/etc/tmp";
40
41# Username for login
42my $user = "anonymous";
43
44# Password (PLEASE TAKE APPROPRIATE PRECAUTIONS TO SECURE THIS)
45my $pass = "guest\@example.com";
46
47
48delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
49
50Getopt::Long::Configure('bundling', 'no_ignore_case');
51GetOptions
52 ("V|version" => \&version,
53 "h|help" => \&help,
54 "v|verbose" => \$verbose,
55 "H|hostname=s" => \$opt_H,
56 "f|filename=s" => \$opt_f,
57 "s|filesize=s" => \$opt_s,
58 "t|timeout=s" => \$opt_t,
59 );
60
61($opt_H) || ($opt_H = shift) || usage("Host address or name not specified\n");
62my $host = $1
63 if ($opt_H =~ m/^(([0-9]{1,3}\.){3}[0-9]{1,3}|(([a-z0-9]+(\-+[a-z0-9]+)*|\.))+[a-z])$/i);
64 usage("Please provide a valid IP address or host name\n") unless ($host);
65
66($opt_f) || ($opt_f = shift) || usage("File name not specified\n");
67
68if ($opt_f =~ m/^(.*?)[\/\\]([^\/\\]+)$/) {
69 $ftpdir = $1;
70 $ftpfile = $2;
71}
72
73($opt_s) || ($opt_s = shift) || usage("File size not specified\n");
74usage("File size must be numeric value") unless ($opt_s =~ m/^[0-9]+$/);
75
76(($opt_t) && ($TIMEOUT = $opt_t)) || ($TIMEOUT = 120);
77usage("TIMEOUT must be numeric value") unless ($TIMEOUT =~ m/^[0-9]+$/);
78
79# Don't hang if there are timeout issues
80$SIG{'ALRM'} = sub {
81 print ("ERROR: No response from ftp server (alarm)\n");
82 exit $ERRORS{'UNKNOWN'};
83};
84alarm($TIMEOUT);
85
86# Make certain temporary directory exists
87
88if ( ! -e "$dir" ) {
89 display_res("Temporary directory $dir does not exist.\n", "CRITICAL");
90
91}
92
93# Remove existing file if any
94
95if ( -e "$dir/$ftpfile") {
96 unlink "$dir/$ftpfile" or
97 display_res("Can't remove existing file $dir/$ftpfile.\n", "CRITICAL");
98}
99
100# Snarf file
101
102my $ftp = Net::FTP->new("$host", Passive => 1, Timeout => $TIMEOUT) or
103 display_res("Can't connect to $host.\n", "CRITICAL");
104 $ftp->login("$user","$pass") or
105 display_res("Login to $host failed", "CRITICAL");
106 $ftp->cwd("$ftpdir") or
107 display_res("Can't change to directory $ftpdir.\n", "CRITICAL");
108 $ftp->get($ftpfile, "$dir/$ftpfile") or
109 display_res("Can't retrieve file $ftpfile.\n", "CRITICAL");
110 $ftp->quit;
111
112# If file exists and is correct size we are happy.
113
114if (( -e "$dir/$ftpfile" ) && (($filesize = -s "/tmp/$ftpfile") eq $opt_s)) {
115 display_res("File $ftpfile size OK: $filesize bytes.\n", "OK");
116 } else {
117# Otherwise we are not happy.
118 display_res("File $ftpfile size incorrect: $filesize bytes", "CRITICAL");
119}
120
121exit;
122
123sub print_usage () {
124 print "Usage: $PROGNAME -H <host> -f <filename> -s <file size in bytes> -t <timeout> \n";
125}
126
127sub print_help () {
128 print_revision($PROGNAME,'$ Revision: 1.0 $ ');
129 print "Copyright (c) 2001 Patrick Greenwell, Stealthgeeks, LLC.\n\n";
130 print_usage();
131 support();
132}
133
134sub version () {
135 print_revision($PROGNAME,'$ Revision: 1.0 $ ');
136 exit $ERRORS{'OK'};
137}
138
139sub help () {
140 print_help();
141 exit $ERRORS{'OK'};
142}
143
144sub display_res ($$) {
145 my ($answer, $state) = @_;
146 print $answer;
147 exit $ERRORS{$state};
148}
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 @@
1#!/usr/bin/perl -w
2## Written 12/5/00 Jeremy Hanmer
3# $Id$
4
5use strict;
6use Net::FTP;
7use Getopt::Std;
8
9use vars qw($opt_H $opt_u $opt_p $opt_f);
10getopts("H:u:p:f:");
11
12my $host = $opt_H ||
13 die "usage: check_ftp.pl -h host [<-u user> <-p pass> <-f file>]\n";
14
15my $username = $opt_u || 'anonymous';
16my $pass = $opt_p || "$ENV{'LOGNAME'}\@$ENV{'HOSTNAME'}" ;
17
18my $file = $opt_f;
19
20my $status = 0;
21my $problem;
22my $output = "ftp ok";
23
24my $ftp = Net::FTP->new("$host") ||
25 &crit("connect");
26
27$ftp->login("$username", "$pass") ||
28 &crit("login");
29
30$ftp->get($file) ||
31 &crit("get") if $file;
32
33sub crit()
34{
35 $problem = $_[0];
36 $status = 2;
37 if ( $problem eq 'connect' ) {
38 $output = "can't connect";
39 } elsif ( $problem eq 'login' ) {
40 $output = "can't log in";
41 } elsif ( $problem eq 'get' ) {
42 $output = "cant get $file";
43 }
44}
45
46print "$output\n";
47exit $status;
48
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 @@
1/*=================================
2 * check_logins - Nagios plugin
3 * Copyright (C) 2003 Dag Robøle
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * Authors email: drobole@broadpark.no
20 */
21//=================================
22#include <sys/types.h>
23#include <signal.h>
24#include <errno.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <unistd.h>
28#include <string.h>
29
30#include "config.h"
31#include "common.h"
32#include "utils.h"
33#include "popen.h"
34//=================================
35#define REVISION "$Revision$"
36#define COPYRIGHT "2003"
37#define AUTHOR "Dag Robole"
38#define EMAIL "drobole@broadpark.no"
39#define SUMMARY "Check for multiple user logins"
40
41#define check(func, errmsg) { if((func) == -1) die(STATE_UNKNOWN, errmsg); }
42#define checkz(func, errmsg) { if(!(func)) die(STATE_UNKNOWN, errmsg); }
43//=================================
44typedef struct USERNODE_TYP {
45 char *name;
46 char *host;
47 struct USERNODE_TYP* next;
48} USERNODE;
49//=================================
50char *progname = NULL;
51USERNODE *userlist = NULL, *adminlist = NULL;
52int warning_limit = 0, critical_limit = 0;
53
54void print_usage();
55void print_help();
56void process_arguments(int argc, char* *argv);
57void parse_wholine(const char *line, char *name, char *host);
58void node_create(USERNODE* *node, const char *name, const char *host);
59void node_free(USERNODE* *node);
60USERNODE* list_insert_sort_uniq(USERNODE* *list, USERNODE* *node);
61void list_free(USERNODE* *list);
62void cleanup();
63//=================================
64int main(int argc, char* *argv)
65{
66 FILE *who;
67 USERNODE *newnode, *nptra, *nptrb;
68 char buffer[BUFSIZ], username[BUFSIZ], hostname[BUFSIZ], *cptra, *cptrb;
69 char max_login_name[BUFSIZ], currname[BUFSIZ];
70 int max_login_count = 0, counter = 0, skip;
71 void (*old_sig_alrm)();
72
73 progname = argv[0];
74 if(atexit(cleanup))
75 die(STATE_UNKNOWN, "atexit failed\n");
76
77 if((old_sig_alrm = signal((int)SIGALRM, timeout_alarm_handler)) == SIG_ERR)
78 die(STATE_UNKNOWN, "signal failed\n");
79 alarm(timeout_interval);
80
81 process_arguments(argc, argv);
82
83 checkz(who = spopen(PATH_TO_WHO), "spopen failed\n");
84
85 while(fgets(buffer, sizeof(buffer), who) != NULL) {
86 parse_wholine(buffer, username, hostname);
87 skip = 0;
88 nptra = adminlist;
89
90 while(nptra != NULL) {
91 if(!strcmp(nptra->name, username)) {
92 skip = 1;
93 break;
94 }
95 nptra = nptra->next;
96 }
97 if(!skip) {
98 node_create(&newnode, username, hostname);
99 if(!list_insert_sort_uniq(&userlist, &newnode))
100 node_free(&newnode);
101 }
102 }
103
104 check(spclose(who), "spclose failed\n");
105
106 if(userlist != NULL) {
107 nptra = userlist;
108 strcpy(currname, nptra->name);
109 strcpy(max_login_name, nptra->name);
110 max_login_count = 1;
111 while(nptra != NULL) {
112 if(!strcmp(currname, nptra->name))
113 ++counter;
114 else {
115 if(counter > max_login_count) {
116 max_login_count = counter;
117 strcpy(max_login_name, currname);
118 }
119 strcpy(currname, nptra->name);
120 counter = 1;
121 }
122 nptra = nptra->next;
123 }
124
125 if(counter > max_login_count) {
126 max_login_count = counter;
127 strcpy(max_login_name, currname);
128 }
129 }
130
131 if(signal((int)SIGALRM, old_sig_alrm) == SIG_ERR)
132 die(STATE_UNKNOWN, "signal failed\n");
133
134 if(max_login_count) {
135 if(critical_limit && max_login_count >= critical_limit) {
136 printf("CRITICAL - User %s has logged in from %d different hosts\n", max_login_name, max_login_count);
137 return STATE_CRITICAL;
138 }
139 else if(warning_limit && max_login_count >= warning_limit) {
140 printf("WARNING - User %s has logged in from %d different hosts\n", max_login_name, max_login_count);
141 return STATE_WARNING;
142 }
143 }
144
145 printf("OK - No users has exceeded the login limits\n");
146 return STATE_OK;
147}
148//=================================
149void print_usage()
150{
151 fprintf(stderr, "Usage: %s [ -hV ] [ -w limit ] [ -c limit ] [ -u username1, ... ,usernameN ]\n", progname);
152}
153//=================================
154void print_help()
155{
156 print_revision(progname, REVISION);
157 printf("Copyright (c) %s %s <%s>\n\n%s\n\n", COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
158 print_usage();
159 printf("\nDescription:\n"
160 "\tThis plugin supports the w (warning) and c (critical) options indicating the upper limits\n"
161 "\tof logins allowed before a warning is given.\n"
162 "\tThe output from %s is the username and number of login sessions for the user\n"
163 "\twho has the most login sessions (from different hosts) running at a given point in time.\n"
164 "\tThe u (users) option takes a comma separated list of usernames that will be ignored\n"
165 "\twhile scannig users.\n"
166 "\nOptions:\n"
167 "\t-h | --help\n\t\tShow this help message and exit\n"
168 "\t-V | --version\n\t\tShow version description\n"
169 "\t-w | --warning=INTEGER\n\t\tSet warning limit for logins (minimum value is 2)\n"
170 "\t-c | --critical=INTEGER\n\t\tSet critical limit for logins (minimum value is 2)\n"
171 "\t-u | --users=STRING\n\t\tSet usernames to be ignored\n"
172 "\nExamples:\n\t%s -w 3 -c 5\n"
173 "\t%s -w 3 -c 5 -u root,guest,jcarmack\n\n", progname, progname, progname);
174}
175//=================================
176void process_arguments(int argc, char* *argv)
177{
178 USERNODE *newnode;
179 int optch;
180 char buffer[BUFSIZ], *cptra;
181 static struct option long_opts[] = {
182 {"help", no_argument, 0, 'h'},
183 {"version", no_argument, 0, 'V'},
184 {"warning", required_argument, 0, 'w'},
185 {"critical", required_argument, 0, 'c'},
186 {"users", required_argument, 0, 'u'},
187 {0, 0, 0, 0},
188 };
189
190 while((optch = getopt_long(argc, argv, "hVw:c:u:", long_opts, NULL)) != -1) {
191 switch(optch) {
192 case 'h':
193 print_help();
194 exit(STATE_OK);
195 break;
196 case 'V':
197 print_revision(progname, REVISION);
198 exit(STATE_OK);
199 break;
200 case 'w':
201 if(!is_numeric(optarg)) {
202 print_usage();
203 die(STATE_UNKNOWN, "invalid options\n");
204 }
205 warning_limit = atoi(optarg) > 2 ? atoi(optarg) : 2;
206 break;
207 case 'c':
208 if(!is_numeric(optarg)) {
209 print_usage();
210 die(STATE_UNKNOWN, "invalid options\n");
211 }
212 critical_limit = atoi(optarg) > 2 ? atoi(optarg) : 2;
213 break;
214 case 'u':
215 strcpy(buffer, optarg);
216 cptra = strtok(buffer, ",");
217 while(cptra != NULL) {
218 node_create(&newnode, cptra, "(adminhost)");
219 list_insert_sort_uniq(&adminlist, &newnode);
220 cptra = strtok(NULL, ",");
221 }
222 break;
223 default:
224 print_usage();
225 exit(STATE_UNKNOWN);
226 break;
227 }
228 }
229
230 if(argc > optind) {
231 print_usage();
232 die(STATE_UNKNOWN, "invalid options\n");
233 }
234
235 if(!warning_limit && !critical_limit) {
236 print_usage();
237 die(STATE_UNKNOWN, "you must provide a limit for this plugin\n");
238 }
239
240 if(critical_limit && warning_limit > critical_limit) {
241 print_usage();
242 die(STATE_UNKNOWN, "warning limit must be less or equal critical limit\n");
243 }
244}
245//=================================
246void parse_wholine(const char *line, char *name, char *host)
247{
248 char buffer[BUFSIZ], *cptra, *cptrb, *display;
249 strcpy(buffer, line);
250
251 cptra = buffer;
252 checkz(cptrb = (char*)strchr(buffer, ' '), "strchr failed\n");
253 strncpy(name, cptra, cptrb-cptra);
254 name[cptrb-cptra] = '\0';
255
256 if((cptra = strchr(buffer, '(')) != NULL) // hostname found in source arg...
257 {
258 if(cptra[1] == ':') // local host
259 strcpy(host, "(localhost)");
260 else // extern host
261 {
262 checkz(cptrb = strchr(cptra, ')'), "strchr failed\n");
263 cptrb++;
264 strncpy(host, cptra, cptrb-cptra);
265 host[cptrb-cptra] = '\0';
266 }
267 }
268 else // no hostname in source arg, look in line arg...
269 {
270 checkz(cptra = strtok(buffer, " \t\r\n"), "strtok failed\n");
271 checkz(cptra = strtok(NULL, " \t\r\n"), "strtok failed\n");
272 if(cptra[0] == ':') // local host
273 strcpy(host, "(localhost)");
274 else // extern host
275 sprintf(host, "(%s)", cptra);
276 }
277
278 if((cptra = strchr(host, ':')) != NULL) // remove display if any...
279 strcpy(cptra, ")");
280}
281//=================================
282void node_create(USERNODE* *node, const char *name, const char *host)
283{
284 checkz(*node = (USERNODE*)malloc(sizeof(USERNODE)), "malloc failed\n");
285 checkz((*node)->name = (char*)malloc(strlen(name)+1), "malloc failed\n");
286 checkz((*node)->host = (char*)malloc(strlen(host)+1), "malloc failed\n");
287 (*node)->next = NULL;
288 strcpy((*node)->name, name);
289 strcpy((*node)->host, host);
290}
291//=================================
292void node_free(USERNODE* *node)
293{
294 free((*node)->name);
295 free((*node)->host);
296 free(*node);
297 *node = NULL;
298}
299//=================================
300USERNODE* list_insert_sort_uniq(USERNODE* *list, USERNODE* *node)
301{
302 char n1[BUFSIZ], n2[BUFSIZ];
303 USERNODE *last_nptr = NULL, *nptr = *list;
304
305 if(*list == NULL)
306 return(*list = *node);
307 else {
308 sprintf(n1, "%s %s", (*node)->name, (*node)->host);
309 while(nptr != NULL) {
310 sprintf(n2, "%s %s", nptr->name, nptr->host);
311 if(!strcmp(n1, n2))
312 return NULL;
313 else if(strcmp(n1, n2) < 0) {
314 if(last_nptr) {
315 last_nptr->next = *node;
316 (*node)->next = nptr;
317 }
318 else {
319 (*node)->next = *list;
320 *list = *node;
321 }
322 break;
323 }
324 else {
325 last_nptr = nptr;
326 nptr = nptr->next;
327 }
328 }
329 if(nptr == NULL)
330 last_nptr->next = *node;
331 }
332 return *node;
333}
334//=================================
335void list_free(USERNODE* *list)
336{
337 USERNODE *doe, *nptr = *list;
338 while(nptr != NULL) {
339 doe = nptr;
340 nptr = nptr->next;
341 node_free(&doe);
342 }
343 *list = NULL;
344}
345//=================================
346void cleanup()
347{
348 list_free(&userlist);
349 list_free(&adminlist);
350}
351//=================================
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 @@
1/*****************************************************************
2 *
3 * Program: check_mysql.c
4 * License: GPL
5 *
6 * Written by Tim Weippert
7 * (based on plugins by Ethan Galstad and MySQL example code)
8 *
9 * Command line: check_mysql <host> [user] [passwd]
10 * <host> can be the FQDN or the IP-Adress
11 * [user] and [passwd] are optional
12 *
13 * Description:
14 *
15 * This plugin attempts to connect to an MySQL Server
16 * with the optional specified parameters user and passwd.
17 * Normaly the host and a user HAVE to assigned.
18 *
19 * The plugin returns
20 * STATE_OK and the Version Number of the Server when all is fine
21 * STATE_CRITICAL if the Connection can't be esablished
22 * STATE_WARNING if the connection was established but the
23 * program can't get the Versoin Number
24 * STATE_UNKNOWN if to many parameters are given
25 *
26 * Copyright (c) 1999 by Tim Weippert
27 *
28 * Changes:
29 * 16.12.1999: Changed the return codes from numbers to statements
30 *
31 *******************************************************************/
32
33#include "config.h"
34#include "common.h"
35#include "mysql.h"
36
37MYSQL mysql;
38
39int main(int argc, char **argv)
40{
41 uint i = 0;
42 char *host;
43 char *user;
44 char *passwd;
45
46 char *status;
47 char *version;
48
49 if ( argc > 4 ) {
50 printf("Too many Arguments supplied - %i .\n", argc);
51 printf("Usage: %s <host> [user] [passwd]\n", argv[0]);
52 return STATE_UNKNOWN;
53 }
54
55 (host = argv[1]) || (host = NULL);
56 (user = argv[2]) || (user = NULL);
57 (passwd = argv[3]) || (passwd = NULL);
58
59 if (!(mysql_connect(&mysql,host,user,passwd))) {
60 printf("Can't connect to Mysql on Host: %s\n", host);
61 return STATE_CRITICAL;
62 }
63
64 if ( !(version = mysql_get_server_info(&mysql)) ) {
65 printf("Connect OK, but can't get Serverinfo ... something wrong !\n");
66 return STATE_WARNING;
67 }
68
69 printf("Mysql ok - Running Version: %s\n", version);
70
71 mysql_close(&mysql);
72 return STATE_OK;
73}
74
75
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 @@
1#!/nyet/bin/perl
2#
3# (c)1999 Mitch Wright, NetLine Corporation
4# Read the GNU copyright stuff for all the legalese
5#
6# Check to see that our MySQL server(s) are up and running.
7# This plugin requires that mysqladmin(1) is installed on the system.
8# Since it is part of the MySQL distribution, that should be a problem.
9#
10# If no parameters are giving, a usage statement is output.
11#
12# Exit 0 on success, providing some informational output
13# Exit 2 on failure, provide what we can...
14#
15
16require 5.004;
17
18sub usage;
19
20my $TIMEOUT = 15;
21my $MYSQLADMIN = "/usr/local/bin/mysqladmin";
22
23my %ERRORS = ('UNKNOWN' , '-1',
24 'OK' , '0',
25 'WARNING', '1',
26 'CRITICAL', '2');
27
28my $host = shift || &usage(%ERRORS);
29my $user = shift || &usage(%ERRORS);
30my $pass = shift || "";
31my $warn = shift || 60;
32my $crit = shift || 100;
33
34my $state = "OK";
35
36# Just in case of problems, let's not hang Nagios
37$SIG{'ALRM'} = sub {
38 print ("ERROR: No response from MySQL server (alarm)\n");
39 exit $ERRORS{"UNKNOWN"};
40};
41alarm($TIMEOUT);
42
43open (OUTPUT,
44 "$MYSQLADMIN -h $host -u $user --password=\"$pass\" version 2>&1
45 |");
46
47while (<OUTPUT>) {
48 if (/failed/) { $state="CRITICAL"; s/.*://; $status=$_; last; }
49 next if /^\s*$/;
50 if (/^Server version\s+(\d+.*)/) { $version = $1; next; }
51 if (/^Uptime:\s+(\d.*)/) { $uptime = $1; next; }
52 if (/^Threads:\s+(\d+)\s+/) { $threads = $1; next; }
53}
54
55$status = "Version $version -- $threads Threads <br>Uptime $uptime" if
56$state ne "CRITICAL";
57
58if ($threads >= $warn) { $state = "WARNING"; }
59if ($threads >= $crit) { $state = "CRITICAL"; }
60
61print $status;
62exit $ERRORS{$state};
63
64sub usage {
65 print "Required arguments not given!\n\n";
66 print "MySQL status checker plugin for Nagios, V1.01\n";
67 print "Copyright (c) 1999-2000 Mitch Wright \n\n";
68 print "Usage: check_mysql.pl <host> <user> [<pass> [<warn>
69 [<crit>]]]\n\n"; print " <pass> = password to use for <user> at
70 <host>\n"; print " <warn> = number of threads to warn us
71 about\n"; print " <crit> = number of threads to scream at us
72 about\n"; exit $ERRORS{"UNKNOWN"};
73}
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 @@
1#!/usr/bin/perl -w
2#
3# check_mysqlslave.pl - nagios plugin
4#
5#
6# Copyright 2002 Mario Witte
7#
8# This program is free software; you can redistribute it and/or
9# modify it under the terms of the GNU General Public License
10# as published by the Free Software Foundation; either version 2
11# of the License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21#
22# Credits:
23# - Thanks to Christoph Kron <ck@zet.net> for check_ifstatus.pl
24# I used check_ifstatus.pl as a layout when writing this
25#
26# Report bugs to: chengfu@users.sourceforge.net
27#
28# 20.09.2002 Version 0.1
29
30
31use strict;
32use lib "/usr/local/nagios/libexec";
33use utils qw($TIMEOUT %ERRORS &print_revision &support);
34
35use DBI;
36use DBD::mysql;
37use Getopt::Long;
38Getopt::Long::Configure('bundling');
39
40# Predeclare some variables
41my $PROGNAME = 'check_mysqlslave';
42my $REVISION = '0.1';
43my $status;
44my $state = 'UNKNOWN';
45my $opt_V;
46my $opt_h;
47my $port = 3306;
48my $hostname;
49my $user = 'root';
50my $pass = '';
51my $driver;
52my $dbh;
53my $query;
54my $result;
55my $data;
56
57# Just in case of problems, let's not hang Nagios
58$SIG{'ALRM'} = sub {
59 print ("ERROR: No response from $hostname (alarm timeout)\n");
60 exit $ERRORS{"UNKNOWN"};
61};
62alarm($TIMEOUT);
63
64$status = GetOptions(
65 "V" => \$opt_V, "version" => \$opt_V,
66 "h" => \$opt_h, "help" => \$opt_h,
67 "p=i" => \$port, "port=i" => \$port,
68 "H=s" => \$hostname, "hostname=s" => \$hostname,
69 "u=s" => \$user, "user=s" => \$user,
70 "P=s" => \$pass, "pass=s" => \$pass,
71 );
72
73
74if ($status == 0) {
75 print_help() ;
76 exit $ERRORS{'OK'};
77}
78
79if ($opt_V) {
80 print_revision($PROGNAME,'$Revision$REVISION .' $ ');
81 exit $ERRORS{'OK'};
82}
83
84if ($opt_h) {
85 print_help();
86 exit $ERRORS{'OK'};
87}
88
89if (! utils::is_hostname($hostname)){
90 usage();
91 exit $ERRORS{"UNKNOWN"};
92}
93
94
95$driver = 'DBI:mysql::'. $hostname;
96
97eval {
98 $dbh = DBI->connect($driver, $user, $pass, { RaiseError => 1, PrintError => 0});
99};
100if ($@) {
101 $status = $@;
102 if ($status =~ /^.*failed:\ (.+)\ at\ $0/i) { $status = $1; }
103 $state='CRITICAL';
104 print $state .': Connect failed: '."$status\n";
105 exit ($ERRORS{$state});
106}
107
108eval {
109 $query = 'SHOW SLAVE STATUS';
110 $result = $dbh->prepare($query);
111 $result->execute;
112 $data = $result->fetchrow_hashref();
113 $result->finish();
114 $dbh->disconnect();
115};
116if ($@) {
117 $status = $@;
118 $status =~ s/\n/ /g;
119 if ($status =~ /^DB[ID].*(failed|prepare):\ (.+)\ at\ $0/i) { $status = $2; }
120 $state = 'CRITICAL';
121 print $state .': Couldn\'t check slave: '."$status\n";
122 exit($ERRORS{$state});
123}
124
125if ($data->{'Slave_Running'} eq 'Yes') {
126 $status = 'Replicating from '. $data->{'Master_Host'};
127 $state = 'OK';
128 print $state .': '. $status ."\n";
129 exit($ERRORS{$state});
130} elsif ($data->{'Slave_Running'} eq 'No') {
131 if (length($data->{'Last_error'}) > 0) {
132 $status = 'Slave stopped with error message';
133 $state = 'CRITICAL';
134 print $state .': '. $status ."\n";
135 exit($ERRORS{$state});
136 } else {
137 $status = 'Slave stopped without errors';
138 $state = 'WARNING';
139 print $state .': '. $status ."\n";
140 exit($ERRORS{$state});
141 }
142} else {
143 $status = 'Unknown slave status: (Running: '. $data->{'Slave_Running'} .')';
144 $state = 'UNKNOWN';
145 print $state .': '. $status ."\n";
146 exit($ERRORS{$state});
147}
148
149sub usage {
150 printf "\nMissing arguments!\n";
151 printf "\n";
152 printf "check_mysqlslave -H <hostname> [-p <port> -u <username> -P <password>]\n";
153 printf "Copyright 2002 Mario Witte\n";
154 printf "\n\n";
155 support();
156 exit $ERRORS{"UNKNOWN"};
157}
158
159sub print_help {
160 printf "check_mysqlslave plugin for Nagios checks \n";
161 printf "if the replication on a backup mysql-server\n";
162 printf "is up and running\n";
163 printf "\nUsage:\n";
164 printf " -H (--hostname) Hostname to query\n";
165 printf " -p (--port) mysql port (default: 3306)\n";
166 printf " -u (--user) username for accessing mysql host\n";
167 printf " (default: root)\n";
168 printf " -P (--pass) password for accessing mysql host\n";
169 printf " (default: '')\n";
170 printf " -V (--version) Plugin version\n";
171 printf " -h (--help) usage help \n\n";
172 print_revision($PROGNAME, '$Revision$REVISION .' $');
173
174}
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 @@
1#!/usr/bin/perl
2#
3# check_nwstat.pl: Nagios plugin that uses Jim Drews' nwstat.pl for
4# MRTG instead of emulating it. For use particularly with Cliff
5# Woolley's mrtgext.pl Unix companion to Drews' MRTGEXT.NLM, where
6# mrtgext.pl can contain custom commands that check_nwstat won't recognize,
7# though this also does its best to perfectly emulate the C version
8# of check_nwstat.
9#
10
11
12######################################################################
13# Configuration
14######################################################################
15
16$nwstatcmd = "/apps/mrtg/helpers/nwstat.pl";
17
18use Getopt::Long;
19
20$::host = shift || &usage(%ERROR);
21$::opt_v = undef;
22$::opt_wv = undef;
23$::opt_cv = undef;
24$::opt_to = 10;
25$::opt_url = undef;
26
27GetOptions (qw(v=s wv=i cv=i to=i url=s)) || &usage(%ERROR);
28
29my $cmd1 = "";
30my $cmd2 = "ZERO";
31my $backward = 0;
32my $desc = "";
33my $okstr = "OK";
34my $probstr = "Problem";
35my $result = "";
36my @CMD;
37my %ERROR = ("UNKNOWN" => -1,
38 "OK" => 0,
39 "WARNING" => 1,
40 "CRITICAL" => 2);
41my $status = $ERROR{"OK"};
42
43
44######################################################################
45# Main program
46######################################################################
47
48$SIG{'ALRM'} = sub {
49 print "Connection timed out\n";
50 exit $ERROR{"CRITICAL"};
51};
52
53# translate table for compatability with
54# check_nwstat (C version)
55SWITCH: for ($::opt_v) {
56 /^LOAD(1|5|15)$/
57 && do { $desc = "Load <status> - Up <cmd2>, ".
58 "$1-min load average = <cmd0>%";
59 $cmd1 = "UTIL$1"; last; };
60 /^CONNS$/ && do { $desc = "Conns <status>: ".
61 "<cmd0> current connections";
62 $cmd1 = "CONNECT"; last; };
63 /^CDBUFF$/ && do { $desc = "Dirty cache buffers = <cmd0>";
64 $cmd1 = "S3"; last; };
65 /^LTCH$/ && do { $desc = "Long term cache hits = <cmd0>%";
66 $cmd1 = "S1";
67 $backward = 1; last; };
68 /^CBUFF$/ && do { $desc = "Total cache buffers = <cmd0>";
69 $cmd1 = "S2";
70 $backward = 1; last; };
71 /^LRUM$/ && do { $desc = "LRU sitting time = <cmd0> minutes";
72 $cmd1 = "S5";
73 $backward = 1; last; };
74 /^VPF(.*)$/ && do { $desc = "<status><int(cmd0/1024)> MB ".
75 "(<result>%) free on volume $1";
76 $okstr = ""; $probstr = "Only ";
77 $cmd1 = "VKF$1";
78 $cmd2 = "VKS$1";
79 $backward = 1; last; };
80 /^VKF/ && do { $desc = "<status><cmd0> KB free on volume $1";
81 $okstr = ""; $probstr = "Only ";
82 $cmd1 = "$::opt_v";
83 $backward = 1; last; };
84 /^$/ && die "Nothing to check!";
85 $desc = "<status>: <cmd0>";
86 $cmd1 = "$::opt_v";
87 }
88
89
90# begin timeout period, run the check
91alarm($::opt_to);
92open ( CMD, "$nwstatcmd $host $cmd1 $cmd2|" ) || die "Couldn't execute nwstat";
93@CMD = <CMD>;
94close ( CMD );
95alarm(0);
96
97for (@CMD) { chomp; }
98
99# for any variables that manipulate the results instead of
100# just using <cmd0> directly, do that manipulation here into <result>
101SWITCH: for ($::opt_v) {
102 /^VPF/ && do { $result=int(("$CMD[0]"/"$CMD[1]")*100); last; };
103 $result = "$CMD[0]";
104 }
105
106if ("$result" == -1) {
107 $status = $ERROR{"UNKNOWN"};
108 $desc = "Server returned \"variable unknown\"";
109} elsif ("$result" == -2) {
110 $status = $ERROR{"CRITICAL"};
111 $desc = "Connection failed";
112}
113
114if (defined($::opt_cv) && $status == $ERROR{"OK"}) {
115 if ($backward) {
116 ("$result" <= "$::opt_cv") && ( $status = $ERROR{"CRITICAL"} );
117 } else {
118 ("$result" >= "$::opt_cv") && ( $status = $ERROR{"CRITICAL"} );
119 }
120}
121if (defined($::opt_wv) && $status == $ERROR{"OK"}) {
122 if ($backward) {
123 ("$result" <= "$::opt_wv") && ( $status = $ERROR{"WARNING"} );
124 } else {
125 ("$result" >= "$::opt_wv") && ( $status = $ERROR{"WARNING"} );
126 }
127}
128
129$desc =~ s/<status>/($status == $ERROR{"OK"})?"$okstr":"$probstr"/eg;
130$desc =~ s/<([^>]*)cmd([0-3])([^>]*)>/eval("$1\"$CMD[$2]\"$3")/eg;
131$desc =~ s/<result>/"$result"/eg;
132
133if (defined($::opt_url)) {
134 print "<A HREF=\"$::opt_url\">$desc</A>\n";
135} else {
136 print "$desc\n";
137}
138exit $status;
139
140
141######################################################################
142# Subroutines
143######################################################################
144
145sub usage {
146
147 %ERROR = shift;
148
149 print <<EOF
150check_nwstat.pl plugin for Nagios
151by Cliff Woolley, (c) 2000
152
153Usage: ./check_nwstat.pl <host_address> [-v variable] [-wv warn_value] [-cv crit_value] [-to to_sec] [-url url_value]
154
155Options:
156 [variable] = Variable to check. Valid variables include:
157 LOAD1 = 1 minute average CPU load
158 LOAD5 = 5 minute average CPU load
159 LOAD15 = 15 minute average CPU load
160 CONNS = number of currently licensed connections
161 VPF<vol> = percent free space on volume <vol>
162 VKF<vol> = KB of free space on volume <vol>
163 LTCH = percent long term cache hits
164 CBUFF = current number of cache buffers
165 CDBUFF = current number of dirty cache buffers
166 LRUM = LRU sitting time in minutes
167 [warn_value] = Threshold for value necessary to result in a warning status
168 [crit_value] = Threshold for value necessary to result in a critical status
169 [to_sec] = Number of secs before connection times out - default is 10 sec
170 [url_value] = URL to use in output as a hyperlink. Useful to link to a page
171 with more details or history for this variable (ie an MRTG page)
172
173This plugin attempts to contact the MRTGEXT NLM running on a Novell server
174to gather the requested system information.
175
176Notes:
177 - This plugin requres that the MRTGEXT.NLM file distributed with
178 James Drews' MRTG extension for NetWare (available from
179 http://www.engr.wisc.edu/~drews/mrtg/) be loaded on the Novell
180 servers you wish to check.
181 - Critical thresholds should be lower than warning thresholds when
182 the following variables are checked: VPF, VKF, LTCH, CBUFF, and LRUM.
183EOF
184;
185
186 exit $ERROR{"UNKNOWN"};
187}
188
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 @@
1#!/usr/bin/perl
2# ------------------------------------------------------------------------------
3# File Name: check_pop3.pl
4# Author: Richard Mayhew - South Africa
5# Date: 2000/01/21
6# Version: 1.0
7# Description: This script will check to see if an POP3 is running
8# and whether authentication can take place.
9# Email: netsaint@splash.co.za
10# ------------------------------------------------------------------------------
11# Copyright 1999 (c) Richard Mayhew
12# Credits go to Ethan Galstad for coding Nagios
13# If any changes are made to this script, please mail me a copy of the
14# changes :)
15# License GPL
16# ------------------------------------------------------------------------------
17# Date Author Reason
18# ---- ------ ------
19# 1999/09/20 RM Creation
20# 1999/09/20 TP Changed script to use strict, more secure by
21# specifying $ENV variables. The bind command is
22# still insecure through. Did most of my work
23# with perl -wT and 'use strict'
24# 2000/01/20 RM Corrected POP3 Exit State.
25# 2000/01/21 RM Fix Exit Codes Again!!
26# 2003/12/30 CZ Proper CRLF in communication w/server
27# Fixed infinite loop
28# Error checking on welcome banner, USER, PASS commands
29# Better error condition handling
30
31# ------------------------------------------------------------------------------
32
33# -----------------------------------------------------------------[ Require ]--
34require 5.004;
35
36# --------------------------------------------------------------------[ Uses ]--
37use Socket;
38use strict;
39
40# --------------------------------------------------------------[ Enviroment ]--
41$ENV{PATH} = "/bin";
42$ENV{BASH_ENV} = "";
43$|=1;
44# ------------------------------------------------------------------[ Global ]--
45my $TIMEOUT = 60;
46
47# -------------------------------------------------------------------[ usage ]--
48sub usage
49{
50 print "Minimum arguments not supplied!\n";
51 print "\n";
52 print "Perl Check POP3 plugin for Nagios\n";
53 print "Copyright (c) 2000 Richard Mayhew\n";
54 print "\n";
55 print "Usage: check_pop3.pl <host> <username> <password> [port]\n";
56 print "\n";
57 print "<port> = Port that the pop3 daemon is running on <host>. Defaults to 110.\n";
58 exit -1;
59
60}
61
62# --------------------------------------------------------------[ bindRemote ]--
63sub bindRemote
64{
65 my ($in_remotehost, $in_remoteport, $in_hostname) = @_;
66 my $proto;
67 my $sockaddr;
68 my $this;
69 my $thisaddr;
70 my $that;
71 my ($name, $aliases,$type,$len,$thataddr) = gethostbyname($in_remotehost);
72
73 if (!socket(ClientSocket,AF_INET, SOCK_STREAM, $proto)) { die $!; }
74 $sockaddr = 'S n a4 x8';
75 $this = pack($sockaddr, AF_INET, 0, $thisaddr);
76 $that = pack($sockaddr, AF_INET, $in_remoteport, $thataddr);
77 if (!bind(ClientSocket, $this)) { print "Connection Refused\n"; exit 2; }
78 if (!connect(ClientSocket, $that)) { print "Connection Refused\n"; exit 2; }
79 select(ClientSocket); $| = 1; select(STDOUT);
80 return \*ClientSocket;
81}
82
83# ====================================================================[ MAIN ]==
84MAIN:
85{
86 my $hostname;
87 my $remotehost = shift || &usage;
88 my $username = shift || &usage;
89 my $password = shift || &usage;
90 my $remoteport = shift || 110;
91
92 # Just in case of problems, let's not hang Nagios
93 $SIG{'ALRM'} = sub {
94 print "Something is Taking a Long Time, Increase Your TIMEOUT (Currently Set At $TIMEOUT Seconds)\n";
95 exit -1;
96 };
97
98 alarm($TIMEOUT);
99
100 chop($hostname = `hostname`);
101 my ($name, $alias, $proto) = getprotobyname('tcp');
102 my $ClientSocket = &bindRemote($remotehost,$remoteport,$hostname);
103
104
105 &err("no welcome banner\n") unless $_ = <ClientSocket>;
106 &err("bad welcome banner: " . $_) unless $_ =~ /^\+OK/;
107
108 print ClientSocket "USER $username\r\n";
109
110 &err("no response to USER command\n") unless $_ = <ClientSocket>;
111 &err("bad response to USER: " . $_) unless $_ =~ /^\+OK/;
112
113 print ClientSocket "PASS $password\r\n";
114
115 &err("no response to PASS command\n") unless $_ = <ClientSocket>;
116 &err("bad response to PASS: " . $_) unless $_ =~ /^\+OK/;
117
118 print ClientSocket "LIST\r\n";
119
120 my $bad = 1;
121 my $msgs = 0;
122 while (<ClientSocket>) {
123 &err(($1||' UNKNOWN')."\n") if (m/\-ERR(.*)/);
124 $bad = 0 if /^\+OK/;
125 $msgs = $1 if /^(\d+)\s+/;
126 last if /^\./;
127 }
128 &message("$msgs\n") unless $bad;
129 &err("missing +OK to LIST command\n");
130}
131
132sub message
133{
134 my $msg = shift;
135 alarm(0);
136 print ClientSocket "QUIT\r\n";
137 print "POP3 OK - Total Messages On Server: $msg";
138 exit 0;
139}
140
141sub err
142{
143 my $msg = shift;
144 alarm(0);
145 print ClientSocket "QUIT\r\n";
146 print "POP3 Error: $msg";
147 exit 2;
148}
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 @@
1#!/bin/bash
2
3#
4# Check_procl.sh
5#
6# Program: Process load check plugin for Nagios
7# License : GPL
8# Copyright (c) 2002 Jerome Tytgat (j.tytgat@sioban.net)
9#
10# check_procl.sh,v 1.1 2002/07/04 09:35
11#
12# Description :
13#
14# This plugin is for check the %cpu, %mem or cputime of one or more process
15#
16# Usage :
17#
18# check_procl.sh -p process1,process2,... -w a.b -c c.d --cpu
19# check_procl.sh -p process1,process2,... -w a.b -c c.d --mem
20# check_procl.sh -p process1,process2,... -w a:b:c -c d:e:f --cputime
21#
22# check_procl.sh -p %all% -e process1,process2,... -w <a.b | a:b:c> -c <c.d | d:e:f> <--cpu | --mem | --cputime>
23# check_procl.sh -p %max% -e process1,process2,... -w <a.b | a:b:c> -c <c.d | d:e:f> <--cpu | --mem | --cputime>
24#
25# Example :
26#
27# To know the memory eaten by HTTPD processes, be warned when it reach 50% and be critical when it reach 75%
28# check_procl.sh -p httpd -w 50.0 -c 75.0 --mem
29# > OK - total %MEM for process httpd : 46.1
30#
31# To know the process which eat the more cpu time, but as we are under linux and are using kapm we do :
32# check_procl.sh -p %max% -e kapmd-idle,kapmd -w 0:1:0 -c 0:2:0 --cputime
33# > CRITICAL - total CPUTIME for process named : 02:32:10
34#
35# Tested on solaris 7/8, Linux Redhat 7.3 and Linux Suse 7.1
36#
37# BUGS : problems with handling time on solaris...
38
39
40help_usage() {
41 echo "Usage:"
42 echo " $0 -p <process_name1,process_name2,... | %all% | %max%>"
43 echo " [-e <process_name1,process_name2,...>] -w warning -c critical < --cpu | --mem | --cputime>"
44 echo " $0 (-v | --version)"
45 echo " $0 (-h | --help)"
46}
47
48help_version() {
49 echo "check_procl.sh (nagios-plugins) 1.1"
50 echo "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute"
51 echo "copies of the plugins under the terms of the GNU General Public License."
52 echo "For more information about these matters, see the file named COPYING."
53 echo "Copyright (c) 2002 Jerome Tytgat - j.tytgat@sioban.net"
54 echo "Greetings goes to Websurg which kindly let me took time to develop this"
55 echo " Manu Feig and Jacques Kern who were my beta testers, thanks to them !"
56}
57
58verify_dep() {
59 needed="bash cut egrep expr grep let ps sed sort tail test tr wc"
60 for i in `echo $needed`
61 do
62 type $i > /dev/null 2>&1 /dev/null
63 if [ $? -eq 1 ]
64 then
65 echo "I am missing an important component : $i"
66 echo "Cannot continue, sorry, try to find the missing one..."
67 exit 3
68 fi
69 done
70}
71
72myself=$0
73
74verify_dep
75
76if [ "$1" = "-h" -o "$1" = "--help" ]
77then
78 help_version
79 echo ""
80 echo "This plugin will check either the cumulutative %cpu, %mem or cputime"
81 echo "of a process."
82 echo ""
83 help_usage
84 echo ""
85 echo "Required Arguments:"
86 echo " -p, --process STRING1,STRING2,..."
87 echo " names of the processes we want to monitor,"
88 echo " you can add as much as process as you want, separated by comma,"
89 echo " hey will be cumulated"
90 echo " -p, --process %all%"
91 echo " The special keyword %all% will check the cumulative cpu/mem/time of all process"
92 echo " WARNING : Can be very slow on heavy loaded servers, watch your timeout !"
93 echo " -p, --process %max%"
94 echo " The special keyword %max% will check the process which eat the most"
95 echo " WARNING : only select the process which eat the more, not the cumulative,"
96 echo " but return the cumulative"
97 echo " -w, --warning INTEGER.INTEGER or INTERGER:INTEGER:INTEGER"
98 echo " generate warning state if process count is outside this range"
99 echo " -c, --critical INTEGER.INTEGER or INTERGER:INTEGER:INTEGER"
100 echo " generate critical state if process count is outside this range"
101 echo " --cpu"
102 echo " return the current cpu usage for the given process"
103 echo " --mem"
104 echo " return the current memory usage for the given process"
105 echo " --cputime"
106 echo " return the total cputime usage for the given process"
107 echo ""
108 echo "Optional Argument:"
109 echo " -e, --exclude-process STRING1,STRING2,..."
110 echo " names of the processes we want don't want to monitor"
111 echo " only useful when associated with %all% or %max% keywords, else ignored"
112 echo " ex : kapm-idled on linux is a process which eat memory / cputime but not really... ;-)"
113 echo ""
114 exit 3
115fi
116
117if [ "$1" = "-v" -o "$1" = "--version" ]
118then
119 help_version
120 exit 3
121fi
122
123if [ `echo $@|tr "=" " "|wc -w` -lt 7 ]
124then
125 echo "Bad arguments number (need at least 7)!"
126 help_usage
127 exit 3
128fi
129
130tt=0
131process_name=""
132exclude_process_name=""
133wt=""
134ct=""
135
136# Test of the command lines arguments
137while test $# -gt 0
138do
139
140 case "$1" in
141 -p|--process)
142 if [ -n "$process_name" ]
143 then
144 echo "Only one --process argument is useful..."
145 help_usage
146 exit 3
147 fi
148 shift
149 process_name="`echo $1|tr \",\" \"|\"`"
150 ;;
151 -e|--exclude-process)
152 if [ -n "$exclude_process_name" ]
153 then
154 echo "Only one --exclude-process argument is useful..."
155 help_usage
156 exit 3
157 fi
158 shift
159 exclude_process_name="`echo $1|tr \",\" \"|\"`"
160 ;;
161 -w|--warning)
162 if [ -n "$wt" ]
163 then
164 echo "Only one --warning argument needed... Trying to test bad things ? :-)"
165 help_usage
166 exit 3
167 fi
168 shift
169 wt=$1
170 ;;
171 -c|--critical)
172 if [ -n "$ct" ]
173 then
174 echo "Only one --critical argument needed... Trying to test bad things ? :-)"
175 help_usage
176 exit 3
177 fi
178 shift
179 ct=$1
180 ;;
181 --cpu)
182 if [ $tt -eq 0 ]
183 then
184 tt=1
185 else
186 echo "Only one of the arguments --cpu/--mem/--cputime can be used at a time !"
187 help_usage
188 exit 3
189 fi
190 type_arg_aff="%CPU"
191 type_arg="pcpu"
192 delim="."
193 ;;
194 --mem)
195 if [ $tt -eq 0 ]
196 then
197 tt=2
198 else
199 echo "Only one of the arguments --cpu/--mem/--cputime can be used at a time !"
200 help_usage
201 exit 3
202 fi
203 type_arg_aff="%MEM"
204 type_arg="pmem"
205 delim="."
206 ;;
207 --cputime)
208 if [ $tt -eq 0 ]
209 then
210 tt=3
211 else
212 echo "Only one of the arguments --cpu/--mem/--cputime can be used at a time !"
213 help_usage
214 exit 3
215 fi
216 type_arg_aff="TIME"
217 type_arg="time"
218 delim=":"
219 ;;
220 *)
221 echo "Unknown argument $1"
222 help_usage
223 exit 3
224 ;;
225 esac
226 shift
227done
228
229# Is the process running ?
230if [ -z "`ps -e | egrep \"$process_name?\"`" -a "$process_name" != "%all%" -a "$process_name" != "%max%" ]
231then
232 echo "WARNING: process $process_name not running !"
233 exit 3
234fi
235
236# Cut of warning and critical values
237wt_value1=`echo $wt|cut -d"$delim" -f1`
238wt_value2=`echo $wt|cut -d"$delim" -f2`
239ct_value1=`echo $ct|cut -d"$delim" -f1`
240ct_value2=`echo $ct|cut -d"$delim" -f2`
241
242if [ $tt -eq 3 ]
243then
244 wt_value3=`echo $wt|cut -d"$delim" -f3`
245 ct_value3=`echo $ct|cut -d"$delim" -f3`
246else
247 wt_value3=0
248 ct_value3=0
249fi
250
251# Integrity check of warning and critical values
252if [ -z "$wt_value1" -o -z "$wt_value2" -o -z "$wt_value3" ]
253then
254 echo "Bad expression in the WARNING field : $wt"
255 help_usage
256 exit 3
257fi
258
259if [ "`echo $wt_value1|tr -d \"[:digit:]\"`" != "" -o "`echo $wt_value2|tr -d \"[:digit:]\"`" != "" -o "`echo $wt_value3|tr -d \"[:digit:]\"`" != "" ]
260then
261 echo "Bad expression in the WARNING field : $wt"
262 help_usage
263 exit 3
264fi
265
266if [ -z "$ct_value1" -o -z "$ct_value2" -o -z "$ct_value3" ]
267then
268 echo "Bad expression in the CRITICAL field : $ct"
269 help_usage
270 exit 3
271fi
272
273
274if [ "`echo $ct_value1|tr -d \"[:digit:]\"`" != "" -o "`echo $ct_value2|tr -d \"[:digit:]\"`" != "" -o "`echo $ct_value3|tr -d \"[:digit:]\"`" != "" ]
275then
276 echo "Bad expression in the CRITICAL field : $ct"
277 help_usage
278 exit 3
279fi
280
281# ps line construction set...
282case "$process_name" in
283 %all%)
284 if [ -z "$exclude_process_name" ]
285 then
286 psline=`ps -eo $type_arg,comm|egrep -v "$myself|$type_arg_aff?"|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f1`
287 else
288 psline=`ps -eo $type_arg,comm|egrep -v "$myself|$type_arg_aff|$exclude_process_name?"|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f1`
289 fi
290 ;;
291 %max%)
292 if [ -z "$exclude_process_name" ]
293 then
294 pstmp=`ps -eo $type_arg,comm|egrep -v "$myself|$type_arg_aff?"|sort|tail -1|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f2`
295 else
296 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`
297 fi
298 psline=`ps -eo $type_arg,comm|grep $pstmp|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f1`
299 process_name=$pstmp
300 ;;
301 *)
302 psline=`ps -eo $type_arg,comm|egrep "$process_name?"|sed "s/^ *\([0-9]\)/\1/"|cut -d" " -f1`
303 ;;
304esac
305
306total1=0
307total2=0
308total3=0
309
310
311# fetching the values
312for i in $psline
313do
314 # Special case for solaris - several format exist for the time function...
315 if [ ${#i} -le 6 -a "$tt" -eq 3 ]
316 then
317 i="00:$i"
318 fi
319 value1=`echo $i|cut -d$delim -f1`
320 value2=`echo $i|cut -d$delim -f2`
321 value3=`echo $i|cut -d$delim -f3`
322 value3=`test -z "$value3" && echo 0 || echo $value3`
323 total1=`expr $total1 + $value1`
324 total2=`expr $total2 + $value2`
325 total3=`expr $total3 + $value3`
326 if [ $tt -eq 3 ]
327 then
328 if [ $total3 -ge 60 ]
329 then
330 let total2+=1
331 let total3-=60
332 fi
333 if [ $total2 -ge 60 ]
334 then
335 let total1+=1
336 let total2-=60
337 fi
338 else
339 if [ $total2 -ge 10 ]
340 then
341 let total1+=1
342 let total2=total2-10
343 fi
344 fi
345done
346
347warn=0
348crit=0
349
350# evaluation of the cumulative values vs warning and critical values
351case "$tt" in
352 1)
353 return_total="$total1.$total2"
354 test $total1 -gt $ct_value1 && crit=1
355 test $total1 -eq $ct_value1 -a $total2 -ge $ct_value2 && crit=1
356 test $total1 -gt $wt_value1 && warn=1
357 test $total1 -eq $wt_value1 -a $total2 -ge $wt_value2 && warn=1
358 ;;
359 2)
360 return_total="$total1.$total2"
361 test $total1 -gt $ct_value1 && crit=1
362 test $total1 -eq $ct_value1 -a $total2 -ge $ct_value2 && crit=1
363 test $total1 -gt $wt_value1 && warn=1
364 test $total1 -eq $wt_value1 -a $total2 -ge $wt_value2 && warn=1
365 ;;
366 3)
367 return_total="`test ${#total1} -eq 1 && echo 0`$total1:`test ${#total2} -eq 1 && echo 0`$total2:`test ${#total3} -eq 1 && echo 0`$total3"
368 test $total1 -gt $ct_value1 && crit=1
369 test $total1 -eq $ct_value1 -a $total2 -gt $ct_value2 && crit=1
370 test $total1 -eq $ct_value1 -a $total2 -eq $ct_value2 -a $total3 -ge $ct_value3 && crit=1
371 test $total1 -gt $wt_value1 && warn=1
372 test $total1 -eq $wt_value1 -a $total2 -gt $wt_value2 && warn=1
373 test $total1 -eq $wt_value1 -a $total2 -eq $wt_value2 -a $total3 -ge $wt_value3 && warn=1
374 ;;
375esac
376
377# last check ...
378if [ $crit -eq 1 -a $warn -eq 0 ]
379then
380 echo "Critical value must be greater than warning value !"
381 help_usage
382 exit 3
383fi
384
385# Finally Inform Nagios of what we found...
386if [ $crit -eq 1 ]
387then
388 echo "CRITICAL - total $type_arg_aff for process `echo $process_name|tr \"|\" \",\"` : $return_total"
389 exit 2
390elif [ $warn -eq 1 ]
391then
392 echo "WARNING - total $type_arg_aff for process `echo $process_name|tr \"|\" \",\"` : $return_total"
393 exit 1
394else
395 echo "OK - total $type_arg_aff for process `echo $process_name|tr \"|\" \",\"` : $return_total"
396 exit 0
397fi
398
399# Hey what are we doing here ???
400exit 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 @@
1#!/bin/bash
2
3#
4# Check_procr.sh
5#
6# Program: Process running check plugin for Nagios
7# License : GPL
8# Copyright (c) 2002 Jerome Tytgat (j.tytgat@sioban.net)
9#
10# check_procr.sh,v 1.0 2002/09/18 15:28
11#
12# Description :
13#
14# This plugin check if at least one process is running
15#
16# Usage :
17#
18# check_procr.sh -p process_name
19#
20# Example :
21#
22# To know if snort is running
23# check_procr.sh -p snort
24# > OK - total snort running : PID=23441
25#
26# Linux Redhat 7.3
27#
28
29help_usage() {
30 echo "Usage:"
31 echo " $0 -p <process_name>"
32 echo " $0 (-v | --version)"
33 echo " $0 (-h | --help)"
34}
35
36help_version() {
37 echo "check_procr.sh (nagios-plugins) 1.0"
38 echo "The nagios plugins come with ABSOLUTELY NO WARRANTY. You may redistribute"
39 echo "copies of the plugins under the terms of the GNU General Public License."
40 echo "For more information about these matters, see the file named COPYING."
41 echo "Copyright (c) 2002 Jerome Tytgat - j.tytgat@sioban.net"
42 echo "Greetings goes to Websurg which kindly let me took time to develop this"
43 echo " Manu Feig and Jacques Kern who were my beta testers, thanks to them !"
44}
45
46verify_dep() {
47 needed="bash cut egrep expr grep let ps sed sort tail test tr wc"
48 for i in `echo $needed`
49 do
50 type $i > /dev/null 2>&1 /dev/null
51 if [ $? -eq 1 ]
52 then
53 echo "I am missing an important component : $i"
54 echo "Cannot continue, sorry, try to find the missing one..."
55 exit 3
56 fi
57 done
58}
59
60myself=$0
61
62verify_dep
63
64if [ "$1" = "-h" -o "$1" = "--help" ]
65then
66 help_version
67 echo ""
68 echo "This plugin will check if a process is running."
69 echo ""
70 help_usage
71 echo ""
72 echo "Required Arguments:"
73 echo " -p, --process STRING"
74 echo " process name we want to verify"
75 echo ""
76 exit 3
77fi
78
79if [ "$1" = "-v" -o "$1" = "--version" ]
80then
81 help_version
82 exit 3
83fi
84
85if [ `echo $@|tr "=" " "|wc -w` -lt 2 ]
86then
87 echo "Bad arguments number (need two)!"
88 help_usage
89 exit 3
90fi
91
92tt=0
93process_name=""
94exclude_process_name=""
95wt=""
96ct=""
97
98# Test of the command lines arguments
99while test $# -gt 0
100do
101
102 case "$1" in
103 -p|--process)
104 if [ -n "$process_name" ]
105 then
106 echo "Only one --process argument is useful..."
107 help_usage
108 exit 3
109 fi
110 shift
111 process_name="`echo $1|tr \",\" \"|\"`"
112 ;;
113 *)
114 echo "Unknown argument $1"
115 help_usage
116 exit 3
117 ;;
118 esac
119 shift
120done
121
122# ps line construction set...
123for i in `ps ho pid -C $process_name`
124do
125 pid_list="$pid_list $i"
126done
127
128if [ -z "$pid_list" ]
129then
130 crit=1
131else
132 crit=0
133fi
134
135# Finally Inform Nagios of what we found...
136if [ $crit -eq 1 ]
137then
138 echo "CRITICAL - process $process_name is not running !"
139 exit 2
140else
141 echo "OK - process $process_name is running : PID=$pid_list "
142 exit 0
143fi
144
145# Hey what are we doing here ???
146exit 3
147