Imported Upstream version 1.4.10

This commit is contained in:
Jan Wagner 2013-11-26 23:54:42 +01:00
parent 6dd54dd8e2
commit cff68b4c0a
203 changed files with 15026 additions and 8063 deletions

View file

@ -13,7 +13,7 @@ MATHLIBS = @MATHLIBS@
# This is not portable. Run ". tools/devmode" to get development compile flags
#AM_CFLAGS = -Wall
libexec_PROGRAMS = check_apt check_disk check_dummy check_http check_load \
libexec_PROGRAMS = check_apt check_cluster check_disk check_dummy check_http check_load \
check_mrtg check_mrtgtraf check_ntp check_nwstat check_overcr check_ping \
check_real check_smtp check_ssh check_tcp check_time \
check_ups check_users negate \
@ -48,6 +48,7 @@ test:
# the actual targets
check_apt_LDADD = $(BASEOBJS) runcmd.o
check_cluster_LDADD = $(BASEOBJS)
check_dig_LDADD = $(NETLIBS) runcmd.o
check_disk_LDADD = $(BASEOBJS) popen.o
check_dns_LDADD = $(NETLIBS) runcmd.o
@ -86,10 +87,11 @@ check_ups_LDADD = $(NETLIBS)
check_users_LDADD = $(BASEOBJS) popen.o
check_by_ssh_LDADD = $(NETLIBS) runcmd.o
check_ide_smart_LDADD = $(BASEOBJS)
negate_LDADD = $(BASEOBJS) popen.o
negate_LDADD = $(BASEOBJS)
urlize_LDADD = $(BASEOBJS) popen.o
check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS)
check_cluster_DEPENDENCIES = check_cluster.c $(BASEOBJS) $(DEPLIBS)
check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS)
check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS)
check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS)
@ -124,7 +126,7 @@ check_time_DEPENDENCIES = check_time.c $(NETOBJS) $(DEPLIBS)
check_ups_DEPENDENCIES = check_ups.c $(NETOBJS) $(DEPLIBS)
check_users_DEPENDENCIES = check_users.c $(BASEOBJS) popen.o $(DEPLIBS)
check_by_ssh_DEPENDENCIES = check_by_ssh.c $(NETOBJS) runcmd.o $(DEPLIBS)
negate_DEPENDENCIES = negate.c $(BASEOBJS) popen.o $(DEPLIBS)
negate_DEPENDENCIES = negate.c $(BASEOBJS) $(DEPLIBS)
urlize_DEPENDENCIES = urlize.c $(BASEOBJS) popen.o $(DEPLIBS)
##############################################################################

View file

@ -1,4 +1,4 @@
# Makefile.in generated by automake 1.9.6 from Makefile.am.
# Makefile.in generated by automake 1.9.5 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@ -14,6 +14,8 @@
@SET_MAKE@
SOURCES = check_apt.c check_by_ssh.c check_cluster.c check_dig.c check_disk.c check_dns.c check_dummy.c check_fping.c check_game.c check_hpjd.c check_http.c check_ide_smart.c check_ldap.c check_load.c check_mrtg.c check_mrtgtraf.c check_mysql.c check_mysql_query.c check_nagios.c check_nt.c check_ntp.c check_nwstat.c check_overcr.c check_pgsql.c check_ping.c check_procs.c check_radius.c check_real.c check_smtp.c check_snmp.c check_ssh.c check_swap.c check_tcp.c check_time.c check_ups.c check_users.c negate.c urlize.c
srcdir = @srcdir@
top_srcdir = @top_srcdir@
pkgdatadir = $(datadir)/@PACKAGE@
@ -34,9 +36,10 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
libexec_PROGRAMS = check_apt$(EXEEXT) check_disk$(EXEEXT) \
check_dummy$(EXEEXT) check_http$(EXEEXT) check_load$(EXEEXT) \
check_mrtg$(EXEEXT) check_mrtgtraf$(EXEEXT) check_ntp$(EXEEXT) \
libexec_PROGRAMS = check_apt$(EXEEXT) check_cluster$(EXEEXT) \
check_disk$(EXEEXT) check_dummy$(EXEEXT) check_http$(EXEEXT) \
check_load$(EXEEXT) check_mrtg$(EXEEXT) \
check_mrtgtraf$(EXEEXT) check_ntp$(EXEEXT) \
check_nwstat$(EXEEXT) check_overcr$(EXEEXT) \
check_ping$(EXEEXT) check_real$(EXEEXT) check_smtp$(EXEEXT) \
check_ssh$(EXEEXT) check_tcp$(EXEEXT) check_time$(EXEEXT) \
@ -109,7 +112,7 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/np_mysqlclient.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
mkinstalldirs = $(SHELL) $(top_srcdir)/build-aux/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
am__installdirs = "$(DESTDIR)$(libexecdir)"
@ -124,6 +127,8 @@ am__DEPENDENCIES_2 =
am__DEPENDENCIES_3 = netutils.o $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_2)
am__DEPENDENCIES_4 = $(am__DEPENDENCIES_3) $(am__DEPENDENCIES_2)
check_cluster_SOURCES = check_cluster.c
check_cluster_OBJECTS = check_cluster.$(OBJEXT)
check_dig_SOURCES = check_dig.c
check_dig_OBJECTS = check_dig.$(OBJEXT)
check_disk_SOURCES = check_disk.c
@ -207,24 +212,24 @@ LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = check_apt.c check_by_ssh.c check_dig.c check_disk.c \
check_dns.c check_dummy.c check_fping.c check_game.c \
check_hpjd.c check_http.c check_ide_smart.c check_ldap.c \
check_load.c check_mrtg.c check_mrtgtraf.c check_mysql.c \
check_mysql_query.c check_nagios.c check_nt.c check_ntp.c \
check_nwstat.c check_overcr.c check_pgsql.c check_ping.c \
check_procs.c check_radius.c check_real.c check_smtp.c \
check_snmp.c check_ssh.c check_swap.c check_tcp.c check_time.c \
check_ups.c check_users.c negate.c urlize.c
DIST_SOURCES = check_apt.c check_by_ssh.c check_dig.c check_disk.c \
check_dns.c check_dummy.c check_fping.c check_game.c \
check_hpjd.c check_http.c check_ide_smart.c check_ldap.c \
check_load.c check_mrtg.c check_mrtgtraf.c check_mysql.c \
check_mysql_query.c check_nagios.c check_nt.c check_ntp.c \
check_nwstat.c check_overcr.c check_pgsql.c check_ping.c \
check_procs.c check_radius.c check_real.c check_smtp.c \
check_snmp.c check_ssh.c check_swap.c check_tcp.c check_time.c \
check_ups.c check_users.c negate.c urlize.c
SOURCES = check_apt.c check_by_ssh.c check_cluster.c check_dig.c \
check_disk.c check_dns.c check_dummy.c check_fping.c \
check_game.c check_hpjd.c check_http.c check_ide_smart.c \
check_ldap.c check_load.c check_mrtg.c check_mrtgtraf.c \
check_mysql.c check_mysql_query.c check_nagios.c check_nt.c \
check_ntp.c check_nwstat.c check_overcr.c check_pgsql.c \
check_ping.c check_procs.c check_radius.c check_real.c \
check_smtp.c check_snmp.c check_ssh.c check_swap.c check_tcp.c \
check_time.c check_ups.c check_users.c negate.c urlize.c
DIST_SOURCES = check_apt.c check_by_ssh.c check_cluster.c check_dig.c \
check_disk.c check_dns.c check_dummy.c check_fping.c \
check_game.c check_hpjd.c check_http.c check_ide_smart.c \
check_ldap.c check_load.c check_mrtg.c check_mrtgtraf.c \
check_mysql.c check_mysql_query.c check_nagios.c check_nt.c \
check_ntp.c check_nwstat.c check_overcr.c check_pgsql.c \
check_ping.c check_procs.c check_radius.c check_real.c \
check_smtp.c check_snmp.c check_ssh.c check_swap.c check_tcp.c \
check_time.c check_ups.c check_users.c negate.c urlize.c
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -363,6 +368,7 @@ PATH_TO_SWAPINFO = @PATH_TO_SWAPINFO@
PATH_TO_UPTIME = @PATH_TO_UPTIME@
PATH_TO_WHO = @PATH_TO_WHO@
PERL = @PERL@
PERLMODS_DIR = @PERLMODS_DIR@
PGINCLUDE = @PGINCLUDE@
PGLIBS = @PGLIBS@
PKG_ARCH = @PKG_ARCH@
@ -467,6 +473,7 @@ TESTS = @PLUGIN_TEST@
##############################################################################
# the actual targets
check_apt_LDADD = $(BASEOBJS) runcmd.o
check_cluster_LDADD = $(BASEOBJS)
check_dig_LDADD = $(NETLIBS) runcmd.o
check_disk_LDADD = $(BASEOBJS) popen.o
check_dns_LDADD = $(NETLIBS) runcmd.o
@ -505,9 +512,10 @@ check_ups_LDADD = $(NETLIBS)
check_users_LDADD = $(BASEOBJS) popen.o
check_by_ssh_LDADD = $(NETLIBS) runcmd.o
check_ide_smart_LDADD = $(BASEOBJS)
negate_LDADD = $(BASEOBJS) popen.o
negate_LDADD = $(BASEOBJS)
urlize_LDADD = $(BASEOBJS) popen.o
check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS)
check_cluster_DEPENDENCIES = check_cluster.c $(BASEOBJS) $(DEPLIBS)
check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS)
check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS)
check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS)
@ -542,7 +550,7 @@ check_time_DEPENDENCIES = check_time.c $(NETOBJS) $(DEPLIBS)
check_ups_DEPENDENCIES = check_ups.c $(NETOBJS) $(DEPLIBS)
check_users_DEPENDENCIES = check_users.c $(BASEOBJS) popen.o $(DEPLIBS)
check_by_ssh_DEPENDENCIES = check_by_ssh.c $(NETOBJS) runcmd.o $(DEPLIBS)
negate_DEPENDENCIES = negate.c $(BASEOBJS) popen.o $(DEPLIBS)
negate_DEPENDENCIES = negate.c $(BASEOBJS) $(DEPLIBS)
urlize_DEPENDENCIES = urlize.c $(BASEOBJS) popen.o $(DEPLIBS)
all: all-am
@ -611,6 +619,9 @@ check_apt$(EXEEXT): $(check_apt_OBJECTS) $(check_apt_DEPENDENCIES)
check_by_ssh$(EXEEXT): $(check_by_ssh_OBJECTS) $(check_by_ssh_DEPENDENCIES)
@rm -f check_by_ssh$(EXEEXT)
$(LINK) $(check_by_ssh_LDFLAGS) $(check_by_ssh_OBJECTS) $(check_by_ssh_LDADD) $(LIBS)
check_cluster$(EXEEXT): $(check_cluster_OBJECTS) $(check_cluster_DEPENDENCIES)
@rm -f check_cluster$(EXEEXT)
$(LINK) $(check_cluster_LDFLAGS) $(check_cluster_OBJECTS) $(check_cluster_LDADD) $(LIBS)
check_dig$(EXEEXT): $(check_dig_OBJECTS) $(check_dig_DEPENDENCIES)
@rm -f check_dig$(EXEEXT)
$(LINK) $(check_dig_LDFLAGS) $(check_dig_OBJECTS) $(check_dig_LDADD) $(LIBS)
@ -725,6 +736,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_apt.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_by_ssh.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_cluster.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_dig.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_disk.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/check_dns.Po@am__quote@

View file

@ -7,7 +7,7 @@
*
* Original author: sean finney
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -31,12 +31,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_apt.c,v 1.10 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_apt.c 1590 2007-01-28 21:46:41Z hweiss $
*
******************************************************************************/
const char *progname = "check_apt";
const char *revision = "$Revision: 1.10 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-09-23 13:26:03 +0100 (Sun, 23 Sep 2007) $
*
* Description:
*
@ -27,12 +27,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_by_ssh.c,v 1.41 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_by_ssh.c 1792 2007-09-23 12:26:03Z psychotrahe $
*
******************************************************************************/
const char *progname = "check_by_ssh";
const char *revision = "$Revision: 1.41 $";
const char *revision = "$Revision: 1792 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -46,9 +46,10 @@ int validate_arguments (void);
void print_help (void);
void print_usage (void);
int commands = 0;
int services = 0;
int skip = 0;
unsigned int commands = 0;
unsigned int services = 0;
int skip_stdout = 0;
int skip_stderr = 0;
char *remotecmd = NULL;
char *comm = NULL;
char *hostname = NULL;
@ -92,17 +93,28 @@ main (int argc, char **argv)
printf ("%s\n", comm);
result = np_runcmd(comm, &chld_out, &chld_err, 0);
/* UNKNOWN if output found on stderr */
if(chld_err.buflen) {
printf(_("Remote command execution failed: %s\n"),
chld_err.buflen ? chld_err.buf : _("Unknown error"));
if (skip_stdout == -1) /* --skip-stdout specified without argument */
skip_stdout = chld_out.lines;
if (skip_stderr == -1) /* --skip-stderr specified without argument */
skip_stderr = chld_err.lines;
/* UNKNOWN if (non-skipped) output found on stderr */
if(chld_err.lines > skip_stderr) {
printf (_("Remote command execution failed: %s\n"),
chld_err.line[skip_stderr]);
return STATE_UNKNOWN;
}
/* this is simple if we're not supposed to be passive.
* Wrap up quickly and keep the tricks below */
if(!passive) {
printf ("%s\n", skip < chld_out.lines ? chld_out.line[skip] : chld_out.buf);
if (chld_out.lines > skip_stdout)
for (i = skip_stdout; i < chld_out.lines; i++)
puts (chld_out.line[i]);
else
printf (_("%s - check_by_ssh: Remote command '%s' returned status %d\n"),
state_text(result), remotecmd, result);
return result; /* return error status from remote command */
}
@ -119,7 +131,7 @@ main (int argc, char **argv)
local_time = time (NULL);
commands = 0;
for(i = skip; chld_out.line[i]; i++) {
for(i = skip_stdout; i < chld_out.lines; i++) {
status_text = strstr (chld_out.line[i], "STATUS CODE: ");
if (status_text == NULL) {
printf ("%s", chld_out.line[i]);
@ -161,7 +173,9 @@ process_arguments (int argc, char **argv)
{"user", required_argument, 0, 'u'},
{"logname", required_argument, 0, 'l'},
{"command", required_argument, 0, 'C'},
{"skip", required_argument, 0, 'S'},
{"skip", optional_argument, 0, 'S'}, /* backwards compatibility */
{"skip-stdout", optional_argument, 0, 'S'},
{"skip-stderr", optional_argument, 0, 'E'},
{"proto1", no_argument, 0, '1'},
{"proto2", no_argument, 0, '2'},
{"use-ipv4", no_argument, 0, '4'},
@ -179,7 +193,7 @@ process_arguments (int argc, char **argv)
strcpy (argv[c], "-t");
while (1) {
c = getopt_long (argc, argv, "Vvh1246fqt:H:O:p:i:u:l:C:S:n:s:o:", longopts,
c = getopt_long (argc, argv, "Vvh1246fqt:H:O:p:i:u:l:C:S::E::n:s:o:", longopts,
&option);
if (c == -1 || c == EOF)
@ -249,11 +263,21 @@ process_arguments (int argc, char **argv)
asprintf (&remotecmd, "%s;echo STATUS CODE: $?;", remotecmd);
asprintf (&remotecmd, "%s%s", remotecmd, optarg);
break;
case 'S': /* Skip n lines in the output to ignore system banner */
if (!is_integer (optarg))
usage_va(_("skip lines must be an integer"));
case 'S': /* skip n (or all) lines on stdout */
if (optarg == NULL)
skip_stdout = -1; /* skip all output on stdout */
else if (!is_integer (optarg))
usage_va(_("skip-stdout argument must be an integer"));
else
skip = atoi (optarg);
skip_stdout = atoi (optarg);
break;
case 'E': /* skip n (or all) lines on stderr */
if (optarg == NULL)
skip_stderr = -1; /* skip all output on stderr */
else if (!is_integer (optarg))
usage_va(_("skip-stderr argument must be an integer"));
else
skip_stderr = atoi (optarg);
break;
case 'o': /* Extra options for the ssh command */
asprintf (&comm, "%s -%c '%s'", comm, c, optarg);
@ -333,13 +357,15 @@ print_help (void)
printf (_(UT_IPv46));
printf (" %s\n", "-1, --proto1");
printf (" %s\n", _("tell ssh to use Protocol 1"));
printf (" %s\n", _("tell ssh to use Protocol 1 [optional]"));
printf (" %s\n", "-2, --proto2");
printf (" %s\n", _("tell ssh to use Protocol 2"));
printf (" %s\n", "-S, --skiplines=n");
printf (" %s\n", _("Ignore first n lines on STDERR (to suppress a logon banner)"));
printf (" %s\n", _("tell ssh to use Protocol 2 [optional]"));
printf (" %s\n", "-S, --skip-stdout[=n]");
printf (" %s\n", _("Ignore all or (if specified) first n lines on STDOUT [optional]"));
printf (" %s\n", "-E, --skip-stderr[=n]");
printf (" %s\n", _("Ignore all or (if specified) first n lines on STDERR [optional]"));
printf (" %s\n", "-f");
printf (" %s\n", _("tells ssh to fork rather than create a tty"));
printf (" %s\n", _("tells ssh to fork rather than create a tty [optional]"));
printf (" %s\n","-C, --command='COMMAND STRING'");
printf (" %s\n", _("command to execute on the remote machine"));
printf (" %s\n","-l, --logname=USERNAME");
@ -374,6 +400,7 @@ print_help (void)
printf (" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c1;0; up 2 days");
printf (" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c2;0; up 2 days");
printf (" %s\n", "[1080933700] PROCESS_SERVICE_CHECK_RESULT;flint;c3;0; up 2 days");
printf (_(UT_VERBOSE));
printf (_(UT_SUPPORT));
}
@ -383,6 +410,9 @@ void
print_usage (void)
{
printf (_("Usage:"));
printf(" %s [-fq46] [-t timeout] [-i identity] [-l user] -H <host> -C <command>",progname);
printf(" [-n name] [-s servicelist] [-O outputfile] [-p port] [-o ssh-option]\n");
printf (" %s -H <host> -C <command> [-fqv] [-1|-2] [-4|-6]\n"
" [-S [lines]] [-E [lines]] [-t timeout] [-i identity]\n"
" [-l user] [-n name] [-s servicelist] [-O outputfile]\n"
" [-p port] [-o ssh-option]\n",
progname);
}

278
plugins/check_cluster.c Normal file
View file

@ -0,0 +1,278 @@
/*****************************************************************************
*
* CHECK_CLUSTER2.C - Host and Service Cluster Plugin for Nagios 2.x
*
* Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)
* Copyright (c) 2007 nagios-plugins team
* License: GPL
* Last Modified: $Date: 2007-06-20 10:01:07 +0100 (Wed, 20 Jun 2007) $
*
* License Information:
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_cluster.c 1745 2007-06-20 09:01:07Z psychotrahe $
*
******************************************************************************/
const char *progname = "check_cluster";
const char *revision = "$Revision: 1745 $";
const char *copyright = "2007";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
#include "utils.h"
#include "utils_base.h"
#define CHECK_SERVICES 1
#define CHECK_HOSTS 2
void print_help (void);
void print_usage (void);
int total_services_ok=0;
int total_services_warning=0;
int total_services_unknown=0;
int total_services_critical=0;
int total_hosts_up=0;
int total_hosts_down=0;
int total_hosts_unreachable=0;
char *warn_threshold;
char *crit_threshold;
int check_type=CHECK_SERVICES;
char *data_vals=NULL;
char *label=NULL;
int verbose=0;
int process_arguments(int,char **);
int main(int argc, char **argv){
char *ptr;
int data_val;
int return_code=STATE_OK;
thresholds *thresholds = NULL;
if(process_arguments(argc,argv)==ERROR)
usage(_("Could not parse arguments"));
/* Initialize the thresholds */
set_thresholds(&thresholds, warn_threshold, crit_threshold);
if(verbose)
print_thresholds("check_cluster", thresholds);
/* check the data values */
for(ptr=strtok(data_vals,",");ptr!=NULL;ptr=strtok(NULL,",")){
data_val=atoi(ptr);
if(check_type==CHECK_SERVICES){
switch(data_val){
case 0:
total_services_ok++;
break;
case 1:
total_services_warning++;
break;
case 2:
total_services_critical++;
break;
case 3:
total_services_unknown++;
break;
default:
break;
}
}
else{
switch(data_val){
case 0:
total_hosts_up++;
break;
case 1:
total_hosts_down++;
break;
case 2:
total_hosts_unreachable++;
break;
default:
break;
}
}
}
/* return the status of the cluster */
if(check_type==CHECK_SERVICES){
return_code=get_status(total_services_warning+total_services_unknown+total_services_critical, thresholds);
printf("CLUSTER %s: %s: %d ok, %d warning, %d unknown, %d critical\n",
state_text(return_code), (label==NULL)?"Service cluster":label,
total_services_ok,total_services_warning,
total_services_unknown,total_services_critical);
}
else{
return_code=get_status(total_hosts_down+total_hosts_unreachable, thresholds);
printf("CLUSTER %s: %s: %d up, %d down, %d unreachable\n",
state_text(return_code), (label==NULL)?"Host cluster":label,
total_hosts_up,total_hosts_down,total_hosts_unreachable);
}
return return_code;
}
int process_arguments(int argc, char **argv){
int c;
int option=0;
static struct option longopts[]={
{"data", required_argument,0,'d'},
{"warning", required_argument,0,'w'},
{"critical", required_argument,0,'c'},
{"label", required_argument,0,'l'},
{"host", no_argument, 0,'h'},
{"service", no_argument, 0,'s'},
{"verbose", no_argument, 0,'v'},
{"version", no_argument, 0,'V'},
{"help", no_argument, 0,'H'},
{0,0,0,0}
};
/* no options were supplied */
if(argc<2)
return ERROR;
while(1){
c=getopt_long(argc,argv,"hHsvVw:c:d:l:",longopts,&option);
if(c==-1 || c==EOF || c==1)
break;
switch(c){
case 'h': /* host cluster */
check_type=CHECK_HOSTS;
break;
case 's': /* service cluster */
check_type=CHECK_SERVICES;
break;
case 'w': /* warning threshold */
if (strspn (optarg, "0123456789:,") < strlen (optarg))
usage2 (_("Invalid warning threshold: %s\n"), optarg);
warn_threshold = strdup(optarg);
break;
case 'c': /* warning threshold */
if (strspn (optarg, "0123456789:,") < strlen (optarg))
usage2 (_("Invalid critical threshold: %s\n"), optarg);
crit_threshold = strdup(optarg);
break;
case 'd': /* data values */
data_vals=(char *)strdup(optarg);
break;
case 'l': /* text label */
label=(char *)strdup(optarg);
break;
case 'v': /* verbose */
verbose++;
break;
case 'V': /* version */
print_revision (progname, revision);
exit (STATE_OK);
break;
case 'H': /* help */
print_help();
exit(STATE_UNKNOWN);
break;
default:
return ERROR;
break;
}
}
if(data_vals==NULL)
return ERROR;
return OK;
}
void
print_help(void)
{
print_revision(progname, revision);
printf ("Copyright (c) 2000-2004 Ethan Galstad (nagios@nagios.org)\n");
printf(COPYRIGHT, copyright, email);
printf(_("Host/Service Cluster Plugin for Nagios 2"));
printf("\n\n");
print_usage();
printf("\n");
printf("%s\n", _("Options:"));
printf (" %s\n", "-s, --service");
printf (" %s\n", _("Check service cluster status"));
printf (" %s\n", "-h, --host");
printf (" %s\n", _("Check host cluster status"));
printf (" %s\n", "-l, --label=STRING");
printf (" %s\n", _("Optional prepended text output (i.e. \"Host cluster\")"));
printf (" %s\n", "-w, --warning=THRESHOLD");
printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
printf (" %s\n", _("non-OK state in order to return a WARNING status level"));
printf (" %s\n", "-c, --critical=THRESHOLD");
printf (" %s\n", _("Specifies the range of hosts or services in cluster that must be in a"));
printf (" %s\n", _(" non-OK state in order to return a CRITICAL status level"));
printf (" %s\n", "-d, --data=LIST");
printf (" %s\n", _("The status codes of the hosts or services in the cluster, separated by"));
printf (" %s\n", _("commas"));
printf(_(UT_VERBOSE));
printf("\n");
printf("%s\n", _("Notes:"));
printf(" %s\n", _("See:"));
printf(" %s\n", ("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT"));
printf(" %s\n", _("for THRESHOLD format and examples."));
printf(_(UT_SUPPORT));
printf("\n");
}
void
print_usage(void)
{
printf(_("Usage:"));
printf(" %s (-s | -h) -d val1[,val2,...,valn] [-l label]\n", progname);
printf("[-w threshold] [-c threshold] [-v] [--help]\n");
}

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -27,7 +27,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_dig.c,v 1.46 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_dig.c 1590 2007-01-28 21:46:41Z hweiss $
*
*****************************************************************************/
@ -38,7 +38,7 @@
* because on some architectures those strings are in non-writable memory */
const char *progname = "check_dig";
const char *revision = "$Revision: 1.46 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2002-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/03/30 08:56:47 $
* Last Modified: $Date: 2007-09-23 13:29:36 +0100 (Sun, 23 Sep 2007) $
*
* Description:
*
@ -27,13 +27,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_disk.c,v 1.90 2007/03/30 08:56:47 psychotrahe Exp $
* $Id: check_disk.c 1793 2007-09-23 12:29:36Z psychotrahe $
*
*****************************************************************************/
const char *progname = "check_disk";
const char *program_name = "check_disk"; /* Required for coreutils libs */
const char *revision = "$Revision: 1.90 $";
const char *revision = "$Revision: 1793 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -69,6 +69,9 @@ static int show_all_fs = 1;
/* If nonzero, show only local filesystems. */
static int show_local_fs = 0;
/* If nonzero, show only local filesystems but call stat() on remote ones. */
static int stat_remote_fs = 0;
/* If positive, the units to use when printing sizes;
if negative, the human-readable base. */
/* static int output_block_size; */
@ -127,6 +130,7 @@ int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, ch
void print_help (void);
void print_usage (void);
double calculate_percent(uintmax_t, uintmax_t);
void stat_path (struct parameter_list *p);
double w_dfp = -1.0;
double c_dfp = -1.0;
@ -150,8 +154,9 @@ char *warn_usedinodes_percent = NULL;
char *crit_usedinodes_percent = NULL;
char *warn_freeinodes_percent = NULL;
char *crit_freeinodes_percent = NULL;
bool path_selected = false;
int path_selected = FALSE;
char *group = NULL;
struct stat *stat_buf;
int
@ -181,6 +186,7 @@ main (int argc, char **argv)
output = strdup ("");
details = strdup ("");
perf = strdup ("");
stat_buf = malloc(sizeof *stat_buf);
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
@ -194,7 +200,7 @@ main (int argc, char **argv)
/* If a list of paths has not been selected, find entire
mount list and create list of paths
*/
if (path_selected == false) {
if (path_selected == FALSE) {
for (me = mount_list; me; me = me->me_next) {
if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
path = np_add_parameter(&path_select_list, me->me_mountdir);
@ -208,14 +214,15 @@ main (int argc, char **argv)
/* Error if no match found for specified paths */
temp_list = path_select_list;
while (temp_list) {
if (! temp_list->best_match) {
die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
}
temp_list = temp_list->name_next;
}
/* Process for every path in list */
for (path = path_select_list; path; path=path->name_next) {
@ -250,6 +257,7 @@ main (int argc, char **argv)
for (temp_list = path_select_list; temp_list; temp_list=temp_list->name_next) {
if (temp_list->group && ! (strcmp(temp_list->group, path->group))) {
stat_path(path);
get_fs_usage (temp_list->best_match->me_mountdir, temp_list->best_match->me_devname, &tmpfsp);
/* possibly differing blocksizes if disks are grouped. Calculating average */
@ -263,7 +271,7 @@ main (int argc, char **argv)
if (verbose > 3)
printf("Group %s: add %llu blocks (%s) \n", path->group, tmpfsp.fsu_bavail, temp_list->name);
// printf("Group %s: add %u blocks (%s)\n", temp_list->name); // path->group, tmpfsp.fsu_bavail, temp_list->name);
/* printf("Group %s: add %u blocks (%s)\n", temp_list->name); *//* path->group, tmpfsp.fsu_bavail, temp_list->name); */
np_add_name(&seen, temp_list->best_match->me_mountdir);
}
@ -277,6 +285,8 @@ main (int argc, char **argv)
if (path->group == NULL) {
/* Skip remote filesystems if we're not interested in them */
if (me->me_remote && show_local_fs) {
if (stat_remote_fs)
stat_path(path);
continue;
/* Skip pseudo fs's if we haven't asked for all fs's */
} else if (me->me_dummy && !show_all_fs) {
@ -291,6 +301,7 @@ main (int argc, char **argv)
continue;
}
stat_path(path);
get_fs_usage (me->me_mountdir, me->me_devname, &fsp);
}
@ -310,8 +321,8 @@ main (int argc, char **argv)
dfree_inodes_percent = 100 - dused_inodes_percent;
if (verbose >= 3) {
printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g\n",
me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent);
printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n",
me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent, fsp.fsu_blocksize, mult);
}
/* Threshold comparisons */
@ -364,6 +375,7 @@ main (int argc, char **argv)
critical_high_tide = abs( min( (double) critical_high_tide, (double) (1.0 - path->freespace_percent->critical->end/100)*dtotal_units ));
}
/* Nb: *_high_tide are unset when == UINT_MAX */
asprintf (&perf, "%s %s", perf,
perfdata ((!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
dused_units, units,
@ -375,18 +387,16 @@ main (int argc, char **argv)
if (disk_result==STATE_OK && erronly && !verbose)
continue;
if (disk_result!=STATE_OK || verbose>=0) {
asprintf (&output, "%s %s %.0f %s (%.0f%%",
output,
(!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
dfree_units,
units,
dfree_pct);
if (dused_inodes_percent < 0) {
asprintf(&output, "%s inode=-);", output);
} else {
asprintf(&output, "%s inode=%.0f%%);", output, dfree_inodes_percent );
}
asprintf (&output, "%s %s %.0f %s (%.0f%%",
output,
(!strcmp(me->me_mountdir, "none") || display_mntp) ? me->me_devname : me->me_mountdir,
dfree_units,
units,
dfree_pct);
if (dused_inodes_percent < 0) {
asprintf(&output, "%s inode=-);", output);
} else {
asprintf(&output, "%s inode=%.0f%%);", output, dfree_inodes_percent );
}
/* TODO: Need to do a similar debug line
@ -439,16 +449,16 @@ int
process_arguments (int argc, char **argv)
{
int c, err;
struct parameter_list *se, *se2;
struct parameter_list *temp_list;
struct parameter_list *se;
struct parameter_list *temp_list = NULL, *previous = NULL;
struct parameter_list *temp_path_select_list = NULL;
struct mount_entry *me;
struct mount_entry *me, *temp_me;
int result = OK;
struct stat *stat_buf;
regex_t re;
int cflags = REG_NOSUB | REG_EXTENDED;
int default_cflags = cflags;
char errbuf[MAX_INPUT_BUFFER];
bool fnd = false;
int fnd = 0;
int option = 0;
static struct option longopts[] = {
@ -459,6 +469,7 @@ process_arguments (int argc, char **argv)
/* Dang, -C is taken. We might want to reshuffle this. */
{"icritical", required_argument, 0, 'K'},
{"local", required_argument, 0, 'l'},
{"stat-remote-fs", required_argument, 0, 'L'},
{"kilobytes", required_argument, 0, 'k'},
{"megabytes", required_argument, 0, 'm'},
{"units", required_argument, 0, 'u'},
@ -471,9 +482,14 @@ process_arguments (int argc, char **argv)
{"eregi-partition", required_argument, 0, 'R'},
{"ereg-path", required_argument, 0, 'r'},
{"ereg-partition", required_argument, 0, 'r'},
{"ignore-ereg-path", required_argument, 0, 'i'},
{"ignore-ereg-partition", required_argument, 0, 'i'},
{"ignore-eregi-path", required_argument, 0, 'I'},
{"ignore-eregi-partition", required_argument, 0, 'I'},
{"mountpoint", no_argument, 0, 'M'},
{"errors-only", no_argument, 0, 'e'},
{"exact-match", no_argument, 0, 'E'},
{"all", no_argument, 0, 'A'},
{"verbose", no_argument, 0, 'v'},
{"quiet", no_argument, 0, 'q'},
{"clear", no_argument, 0, 'C'},
@ -492,7 +508,7 @@ process_arguments (int argc, char **argv)
strcpy (argv[c], "-t");
while (1) {
c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklg:R:r:ME", longopts, &option);
c = getopt_long (argc, argv, "+?VqhveCt:c:w:K:W:u:p:x:X:mklLg:R:r:i:I:MEA", longopts, &option);
if (c == -1 || c == EOF)
break;
@ -595,6 +611,8 @@ process_arguments (int argc, char **argv)
free(units);
units = strdup ("MB");
break;
case 'L':
stat_remote_fs = 1;
case 'l':
show_local_fs = 1;
break;
@ -606,19 +624,15 @@ process_arguments (int argc, char **argv)
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
}
/* get the real mountdir of the specified path. np_find_parameter won't find an entry if -p is not
* exactly the same string as the mountdir */
se2 = np_add_parameter(&temp_path_select_list, optarg);
np_set_best_match(se2, mount_list, FALSE);
/* add parameter if not found. overwrite thresholds if path has already been added */
if (! (se = np_find_parameter(path_select_list, optarg))) {
se = np_add_parameter(&path_select_list, optarg);
}
se->group = group;
set_all_thresholds(se);
path_selected = true;
np_set_best_match(se, mount_list, exact_match);
stat_path(se);
path_selected = TRUE;
break;
case 'x': /* exclude path or partition */
np_add_name(&dp_exclude_list, optarg);
@ -629,20 +643,64 @@ process_arguments (int argc, char **argv)
case 'v': /* verbose */
verbose++;
break;
case 'q': /* verbose */
verbose--;
case 'q': /* TODO: this function should eventually go away (removed 2007-09-20) */
/* verbose--; **replaced by line below**. -q was only a broken way of implementing -e */
erronly = TRUE;
break;
case 'e':
erronly = TRUE;
break;
case 'E':
if (path_selected)
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting pathes\n"));
exact_match = TRUE;
break;
case 'g':
if (path_selected)
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before using -p\n"));
die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting pathes \n"));
group = optarg;
break;
case 'I':
cflags |= REG_ICASE;
case 'i':
if (!path_selected)
die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Pathes need to be selected before using -i/-I. Use -A to select all pathes explicitly"));
err = regcomp(&re, optarg, cflags);
if (err != 0) {
regerror (err, &re, errbuf, MAX_INPUT_BUFFER);
die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"), _("Could not compile regular expression"), errbuf);
}
temp_list = path_select_list;
previous = NULL;
while (temp_list) {
if (temp_list->best_match) {
if (np_regex_match_mount_entry(temp_list->best_match, &re)) {
if (verbose >=3)
printf("ignoring %s matching regex\n", temp_list->name);
temp_list = np_del_parameter(temp_list, previous);
/* pointer to first element needs to be uüdated if first item gets deleted */
if (previous == NULL)
path_select_list = temp_list;
} else {
previous = temp_list;
temp_list = temp_list->name_next;
}
} else {
previous = temp_list;
temp_list = temp_list->name_next;
}
}
cflags = default_cflags;
break;
case 'A':
optarg = strdup(".*");
case 'R':
cflags |= REG_ICASE;
case 'r':
@ -661,9 +719,9 @@ process_arguments (int argc, char **argv)
for (me = mount_list; me; me = me->me_next) {
if (np_regex_match_mount_entry(me, &re)) {
fnd = true;
fnd = TRUE;
if (verbose > 3)
printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
printf("%s %s matching expression %s\n", me->me_devname, me->me_mountdir, optarg);
/* add parameter if not found. overwrite thresholds if path has already been added */
if (! (se = np_find_parameter(path_select_list, me->me_mountdir))) {
@ -678,15 +736,18 @@ process_arguments (int argc, char **argv)
die (STATE_UNKNOWN, "DISK %s: %s - %s\n",_("UNKNOWN"),
_("Regular expression did not match any path or disk"), optarg);
fnd = false;
path_selected = true;
fnd = FALSE;
path_selected = TRUE;
np_set_best_match(path_select_list, mount_list, exact_match);
cflags = default_cflags;
break;
case 'M': /* display mountpoint */
display_mntp = TRUE;
break;
case 'C':
/* add all mount entries to path_select list if no partitions have been explicitly defined using -p */
if (path_selected == false) {
if (path_selected == FALSE) {
struct mount_entry *me;
struct parameter_list *path;
for (me = mount_list; me; me = me->me_next) {
@ -710,7 +771,7 @@ process_arguments (int argc, char **argv)
warn_freeinodes_percent = NULL;
crit_freeinodes_percent = NULL;
path_selected = false;
path_selected = FALSE;
group = NULL;
break;
case 'V': /* version */
@ -734,6 +795,7 @@ process_arguments (int argc, char **argv)
if (argc > c && path == NULL) {
se = np_add_parameter(&path_select_list, strdup(argv[c++]));
path_selected = TRUE;
set_all_thresholds(se);
}
@ -742,32 +804,7 @@ process_arguments (int argc, char **argv)
mult = (uintmax_t)1024 * 1024;
}
if (path_select_list) {
temp_list = path_select_list;
stat_buf = malloc(sizeof *stat_buf);
while (temp_list) {
/* Stat each entry to check that dir exists */
if (stat (temp_list->name, &stat_buf[0])) {
printf("DISK %s - ", _("CRITICAL"));
die (STATE_CRITICAL, _("%s does not exist\n"), temp_list->name);
}
/* if (validate_arguments (temp_list->w_df,
temp_list->c_df,
temp_list->w_dfp,
temp_list->c_dfp,
temp_list->w_idfp,
temp_list->c_idfp,
temp_list->name) == ERROR)
result = ERROR;
*/
temp_list = temp_list->name_next;
}
free(stat_buf);
return result;
} else {
return TRUE;
/* return validate_arguments (w_df, c_df, w_dfp, c_dfp, w_idfp, c_idfp, NULL); */
}
return TRUE;
}
@ -859,48 +896,62 @@ print_help (void)
printf (" %s\n", _("Exit with WARNING status if less than INTEGER units of disk are free"));
printf (" %s\n", "-w, --warning=PERCENT%");
printf (" %s\n", _("Exit with WARNING status if less than PERCENT of disk space is free"));
printf (" %s\n", "-W, --iwarning=PERCENT%");
printf (" %s\n", _("Exit with WARNING status if less than PERCENT of inode space is free"));
printf (" %s\n", "-K, --icritical=PERCENT%");
printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of inode space is free"));
printf (" %s\n", "-c, --critical=INTEGER");
printf (" %s\n", _("Exit with CRITICAL status if less than INTEGER units of disk are free"));
printf (" %s\n", "-c, --critical=PERCENT%");
printf (" %s\n", _("Exit with CRITCAL status if less than PERCENT of disk space is free"));
printf (" %s\n", "-C, --clear");
printf (" %s\n", _("Clear thresholds"));
printf (" %s\n", "-u, --units=STRING");
printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
printf (" %s\n", "-k, --kilobytes");
printf (" %s\n", _("Same as '--units kB'"));
printf (" %s\n", "-m, --megabytes");
printf (" %s\n", _("Same as '--units MB'"));
printf (" %s\n", "-l, --local");
printf (" %s\n", _("Only check local filesystems"));
printf (" %s\n", "-W, --iwarning=PERCENT%");
printf (" %s\n", _("Exit with WARNING status if less than PERCENT of inode space is free"));
printf (" %s\n", "-K, --icritical=PERCENT%");
printf (" %s\n", _("Exit with CRITICAL status if less than PERCENT of inode space is free"));
printf (" %s\n", "-p, --path=PATH, --partition=PARTITION");
printf (" %s\n", _("Path or partition (may be repeated)"));
printf (" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION");
printf (" %s\n", _("Regular expression for path or partition (may be repeated)"));
printf (" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION");
printf (" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)"));
printf (" %s\n", "-g, --group=NAME");
printf (" %s\n", _("Group pathes. Thresholds apply to (free-)space of all partitions together"));
printf (" %s\n", "-x, --exclude_device=PATH <STRING>");
printf (" %s\n", _("Ignore device (only works if -p unspecified)"));
printf (" %s\n", "-X, --exclude-type=TYPE <STRING>");
printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
printf (" %s\n", "-M, --mountpoint");
printf (" %s\n", _("Display the mountpoint instead of the partition"));
printf (" %s\n", "-C, --clear");
printf (" %s\n", _("Clear thresholds"));
printf (" %s\n", "-E, --exact-match");
printf (" %s\n", _("For paths or partitions specified with -p, only check for exact paths"));
printf (" %s\n", "-e, --errors-only");
printf (" %s\n", _("Display only devices/mountpoints with errors"));
printf (" %s\n", "-g, --group=NAME");
printf (" %s\n", _("Group pathes. Thresholds apply to (free-)space of all partitions together"));
printf (" %s\n", "-k, --kilobytes");
printf (" %s\n", _("Same as '--units kB'"));
printf (" %s\n", "-l, --local");
printf (" %s\n", _("Only check local filesystems"));
printf (" %s\n", "-L, --stat-remote-fs");
printf (" %s\n", _("Only check local filesystems against thresholds. Yet call stat on remote filesystems"));
printf (" %s\n", _("to test if they are accessible (e.g. to detect Stale NFS Handles)"));
printf (" %s\n", "-M, --mountpoint");
printf (" %s\n", _("Display the mountpoint instead of the partition"));
printf (" %s\n", "-m, --megabytes");
printf (" %s\n", _("Same as '--units MB'"));
printf (" %s\n", "-A, --all");
printf (" %s\n", _("Explicitly select all pathes. This is equivalent to -R '.*'"));
printf (" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION");
printf (" %s\n", _("Case insensitive regular expression for path/partition (may be repeated)"));
printf (" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION");
printf (" %s\n", _("Regular expression for path or partition (may be repeated)"));
printf (" %s\n", "-I, --ignore-eregi-path=PATH, --ignore-eregi-partition=PARTITION");
printf (" %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION");
printf (" %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
printf (" %s\n", "-u, --units=STRING");
printf (" %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
printf (_(UT_VERBOSE));
printf (" %s\n", "-X, --exclude-type=TYPE");
printf (" %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
printf ("\n");
printf ("%s\n", _("Examples:"));
printf (" %s\n", "check_disk -w 10% -c 5% -p /tmp -p /var -C -w 100000 -c 50000 -p /");
printf (" %s\n", _("Checks /tmp and /var at 10% and 5%, and / at 100MB and 50MB"));
printf (" %s\n", "check_disk -w 100M -c 50M -C -w 1000M -c 500M -g sidDATA -r '^/oracle/SID/data.*$'");
printf (" %s\n", _("Checks all filesystems not matching -r at 100M and 50M. The fs matching the -r regex"));
printf (" %s\n", _("are grouped which means the freespace thresholds are applied to all disks together"));
printf (" %s\n", "check_disk -w 100M -c 50M -C -w 1000M -c 500M -p /foo -C -w 5% -c 3% -p /bar");
printf (" %s\n", _("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M"));
printf (_(UT_SUPPORT));
}
@ -910,6 +961,21 @@ void
print_usage (void)
{
printf (_("Usage:"));
printf (" %s -w limit -c limit [-p path | -x device] [-t timeout]", progname);
printf ("[-m] [-e] [-W limit] [-K limit] [-v] [-q] [-E]\n");
printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname);
printf ("[-C] [-E] [-e] [-g group ] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
printf ("[-t timeout] [-u unit] [-v] [-X type]\n");
}
void
stat_path (struct parameter_list *p)
{
/* Stat entry to check that dir exists and is accessible */
if (verbose > 3)
printf("calling stat on %s\n", p->name);
if (stat (p->name, &stat_buf[0])) {
if (verbose > 3)
printf("stat failed on %s\n", p->name);
printf("DISK %s - ", _("CRITICAL"));
die (STATE_CRITICAL, _("%s %s: %s\n"), p->name, _("is not accessible"), strerror(errno));
}
}

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -31,12 +31,12 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* $Id: check_dns.c,v 1.55 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_dns.c 1590 2007-01-28 21:46:41Z hweiss $
*
******************************************************************************/
const char *progname = "check_dns";
const char *revision = "$Revision: 1.55 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2006/10/19 00:25:16 $
* Last Modified: $Date: 2007-05-24 09:35:53 +0100 (Thu, 24 May 2007) $
*
* Description:
*
@ -30,12 +30,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_dummy.c,v 1.17 2006/10/19 00:25:16 opensides Exp $
$Id: check_dummy.c 1716 2007-05-24 08:35:53Z tonvoon $
******************************************************************************/
const char *progname = "check_dummy";
const char *revision = "$Revision: 1.17 $";
const char *revision = "$Revision: 1716 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -84,8 +84,10 @@ main (int argc, char **argv)
printf (_("UNKNOWN"));
break;
default:
printf (_("UNKNOWN"));
printf (": ");
printf (_("Status %d is not a supported error state\n"), result);
break;
return STATE_UNKNOWN;
}
if (argc >= 3)

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -30,12 +30,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_fping.c,v 1.28 2007/01/28 21:46:40 hweiss Exp $
$Id: check_fping.c 1590 2007-01-28 21:46:41Z hweiss $
******************************************************************************/
const char *progname = "check_fping";
const char *revision = "$Revision: 1.28 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -30,11 +30,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_game.c,v 1.29 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_game.c 1590 2007-01-28 21:46:41Z hweiss $
*****************************************************************************/
const char *progname = "check_game";
const char *revision = "$Revision: 1.29 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2002-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -31,11 +31,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_hpjd.c,v 1.35 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_hpjd.c 1590 2007-01-28 21:46:41Z hweiss $
*****************************************************************************/
const char *progname = "check_hpjd";
const char *revision = "$Revision: 1.35 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/03/06 22:45:57 $
* Last Modified: $Date: 2007-07-21 17:29:01 +0100 (Sat, 21 Jul 2007) $
*
* Description:
*
@ -33,16 +33,18 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_http.c,v 1.101 2007/03/06 22:45:57 tonvoon Exp $
$Id: check_http.c 1759 2007-07-21 16:29:01Z hweiss $
******************************************************************************/
/* splint -I. -I../../plugins -I../../lib/ -I/usr/kerberos/include/ ../../plugins/check_http.c */
const char *progname = "check_http";
const char *revision = "$Revision: 1.101 $";
const char *revision = "$Revision: 1759 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include <ctype.h>
#include "common.h"
#include "netutils.h"
#include "utils.h"
@ -53,7 +55,8 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
enum {
MAX_IPV4_HOSTLENGTH = 255,
HTTP_PORT = 80,
HTTPS_PORT = 443
HTTPS_PORT = 443,
MAX_PORT = 65535
};
#ifdef HAVE_SSL
@ -148,7 +151,7 @@ main (int argc, char **argv)
if (display_html == TRUE)
printf ("<A HREF=\"%s://%s:%d%s\" target=\"_blank\">",
use_ssl ? "https" : "http", host_name,
use_ssl ? "https" : "http", server_address,
server_port, server_url);
/* initialize alarm signal handling, set socket timeout, start timer */
@ -662,28 +665,28 @@ check_document_dates (const char *headers)
/* Done parsing the body. Now check the dates we (hopefully) parsed. */
if (!server_date || !*server_date) {
die (STATE_UNKNOWN, _("Server date unknown\n"));
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Server date unknown\n"));
} else if (!document_date || !*document_date) {
die (STATE_CRITICAL, _("Document modification date unknown\n"));
die (STATE_CRITICAL, _("HTTP CRITICAL - Document modification date unknown\n"));
} else {
time_t srv_data = parse_time_string (server_date);
time_t doc_data = parse_time_string (document_date);
if (srv_data <= 0) {
die (STATE_CRITICAL, _("CRITICAL - Server date \"%100s\" unparsable"), server_date);
die (STATE_CRITICAL, _("HTTP CRITICAL - Server date \"%100s\" unparsable"), server_date);
} else if (doc_data <= 0) {
die (STATE_CRITICAL, _("CRITICAL - Document date \"%100s\" unparsable"), document_date);
die (STATE_CRITICAL, _("HTTP CRITICAL - Document date \"%100s\" unparsable"), document_date);
} else if (doc_data > srv_data + 30) {
die (STATE_CRITICAL, _("CRITICAL - Document is %d seconds in the future\n"), (int)doc_data - (int)srv_data);
die (STATE_CRITICAL, _("HTTP CRITICAL - Document is %d seconds in the future\n"), (int)doc_data - (int)srv_data);
} else if (doc_data < srv_data - maximum_age) {
int n = (srv_data - doc_data);
if (n > (60 * 60 * 24 * 2))
die (STATE_CRITICAL,
_("CRITICAL - Last modified %.1f days ago\n"),
_("HTTP CRITICAL - Last modified %.1f days ago\n"),
((float) n) / (60 * 60 * 24));
else
die (STATE_CRITICAL,
_("CRITICAL - Last modified %d:%02d:%02d ago\n"),
_("HTTP CRITICAL - Last modified %d:%02d:%02d ago\n"),
n / (60 * 60), (n / 60) % 60, n % 60);
}
@ -764,7 +767,7 @@ check_http (void)
/* try to connect to the host at the given port number */
if (my_tcp_connect (server_address, server_port, &sd) != STATE_OK)
die (STATE_CRITICAL, _("Unable to open TCP socket\n"));
die (STATE_CRITICAL, _("HTTP CRITICAL - Unable to open TCP socket\n"));
#ifdef HAVE_SSL
if (use_ssl == TRUE) {
np_net_ssl_init(sd);
@ -779,6 +782,9 @@ check_http (void)
asprintf (&buf, "%s %s HTTP/1.0\r\n%s\r\n", http_method, server_url, user_agent);
/* tell HTTP/1.1 servers not to keep the connection alive */
asprintf (&buf, "%sConnection: close\r\n", buf);
/* optionally send the host header info */
if (host_name)
asprintf (&buf, "%sHost: %s\r\n", buf, host_name);
@ -836,15 +842,15 @@ check_http (void)
if (use_ssl) {
sslerr=SSL_get_error(ssl, i);
if ( sslerr == SSL_ERROR_SSL ) {
die (STATE_WARNING, _("Client Certificate Required\n"));
die (STATE_WARNING, _("HTTP WARNING - Client Certificate Required\n"));
} else {
die (STATE_CRITICAL, _("Error on receive\n"));
die (STATE_CRITICAL, _("HTTP CRITICAL - Error on receive\n"));
}
}
else {
*/
#endif
die (STATE_CRITICAL, _("Error on receive\n"));
die (STATE_CRITICAL, _("HTTP CRITICAL - Error on receive\n"));
#ifdef HAVE_SSL
/* XXX
}
@ -854,7 +860,7 @@ check_http (void)
/* return a CRITICAL status if we couldn't read any data */
if (pagesize == (size_t) 0)
die (STATE_CRITICAL, _("No data received from host\n"));
die (STATE_CRITICAL, _("HTTP CRITICAL - No data received from host\n"));
/* close the connection */
#ifdef HAVE_SSL
@ -909,7 +915,7 @@ check_http (void)
asprintf (&msg,
_("Invalid HTTP response received from host on port %d\n"),
server_port);
die (STATE_CRITICAL, "%s", msg);
die (STATE_CRITICAL, "HTTP CRITICAL - %s", msg);
}
/* Exit here if server_expect was set by user and not default */
@ -950,13 +956,13 @@ check_http (void)
if (onredirect == STATE_DEPENDENT)
redir (header, status_line);
else if (onredirect == STATE_UNKNOWN)
printf (_("UNKNOWN"));
printf (_("HTTP UNKNOWN"));
else if (onredirect == STATE_OK)
printf (_("OK"));
printf (_("HTTP OK"));
else if (onredirect == STATE_WARNING)
printf (_("WARNING"));
printf (_("HTTP WARNING"));
else if (onredirect == STATE_CRITICAL)
printf (_("CRITICAL"));
printf (_("HTTP CRITICAL"));
microsec = deltime (tv);
elapsed_time = (double)microsec / 1.0e6;
die (onredirect,
@ -997,7 +1003,7 @@ check_http (void)
exit (STATE_OK);
}
else {
printf (_("CRITICAL - string not found%s|%s %s\n"),
printf (_("HTTP CRITICAL - string not found%s|%s %s\n"),
(display_html ? "</A>" : ""),
perfd_time (elapsed_time), perfd_size (pagesize));
exit (STATE_CRITICAL);
@ -1019,7 +1025,7 @@ check_http (void)
else
msg = strdup(_("pattern found"));
printf (("%s - %s%s|%s %s\n"),
_("CRITICAL"),
_("HTTP CRITICAL"),
msg,
(display_html ? "</A>" : ""),
perfd_time (elapsed_time), perfd_size (pagesize));
@ -1027,7 +1033,7 @@ check_http (void)
}
else {
regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER);
printf (_("CRITICAL - Execute Error: %s\n"), errbuf);
printf (_("HTTP CRITICAL - Execute Error: %s\n"), errbuf);
exit (STATE_CRITICAL);
}
}
@ -1057,14 +1063,14 @@ check_http (void)
/* per RFC 2396 */
#define HDR_LOCATION "%*[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]: "
#define URI_HTTP "%[HTPShtps]://"
#define URI_HOST "%[-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
#define URI_PORT ":%[0123456789]"
#define URI_HTTP "%5[HTPShtps]"
#define URI_HOST "%255[-.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
#define URI_PORT "%6d" /* MAX_PORT's width is 5 chars, 6 to detect overflow */
#define URI_PATH "%[-_.!~*'();/?:@&=+$,%#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"
#define HD1 URI_HTTP URI_HOST URI_PORT URI_PATH
#define HD2 URI_HTTP URI_HOST URI_PATH
#define HD3 URI_HTTP URI_HOST URI_PORT
#define HD4 URI_HTTP URI_HOST
#define HD1 URI_HTTP "://" URI_HOST ":" URI_PORT "/" URI_PATH
#define HD2 URI_HTTP "://" URI_HOST "/" URI_PATH
#define HD3 URI_HTTP "://" URI_HOST ":" URI_PORT
#define HD4 URI_HTTP "://" URI_HOST
#define HD5 URI_PATH
void
@ -1075,16 +1081,15 @@ redir (char *pos, char *status_line)
char xx[2];
char type[6];
char *addr;
char port[6];
char *url;
addr = malloc (MAX_IPV4_HOSTLENGTH + 1);
if (addr == NULL)
die (STATE_UNKNOWN, _("Could not allocate addr\n"));
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate addr\n"));
url = malloc (strcspn (pos, "\r\n"));
if (url == NULL)
die (STATE_UNKNOWN, _("Could not allocate url\n"));
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate url\n"));
while (pos) {
sscanf (pos, "%[Ll]%*[Oo]%*[Cc]%*[Aa]%*[Tt]%*[Ii]%*[Oo]%*[Nn]:%n", xx, &i);
@ -1093,23 +1098,33 @@ redir (char *pos, char *status_line)
pos += (size_t) strspn (pos, "\r\n");
if (strlen(pos) == 0)
die (STATE_UNKNOWN,
_("UNKNOWN - Could not find redirect location - %s%s\n"),
_("HTTP UNKNOWN - Could not find redirect location - %s%s\n"),
status_line, (display_html ? "</A>" : ""));
continue;
}
pos += i;
pos += strspn (pos, " \t\r\n");
pos += strspn (pos, " \t");
url = realloc (url, strcspn (pos, "\r\n"));
/*
* RFC 2616 (4.2): ``Header fields can be extended over multiple lines by
* preceding each extra line with at least one SP or HT.''
*/
for (; (i = strspn (pos, "\r\n")); pos += i) {
pos += i;
if (!(i = strspn (pos, " \t"))) {
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Empty redirect location%s\n"),
display_html ? "</A>" : "");
}
}
url = realloc (url, strcspn (pos, "\r\n") + 1);
if (url == NULL)
die (STATE_UNKNOWN, _("could not allocate url\n"));
die (STATE_UNKNOWN, _("HTTP UNKNOWN - could not allocate url\n"));
/* URI_HTTP, URI_HOST, URI_PORT, URI_PATH */
if (sscanf (pos, HD1, type, addr, port, url) == 4) {
if (sscanf (pos, HD1, type, addr, &i, url) == 4)
use_ssl = server_type_check (type);
i = atoi (port);
}
/* URI_HTTP URI_HOST URI_PATH */
else if (sscanf (pos, HD2, type, addr, url) == 3 ) {
@ -1118,10 +1133,9 @@ redir (char *pos, char *status_line)
}
/* URI_HTTP URI_HOST URI_PORT */
else if(sscanf (pos, HD3, type, addr, port) == 3) {
else if(sscanf (pos, HD3, type, addr, &i) == 3) {
strcpy (url, HTTP_URL);
use_ssl = server_type_check (type);
i = atoi (port);
}
/* URI_HTTP URI_HOST */
@ -1141,12 +1155,12 @@ redir (char *pos, char *status_line)
}
i = server_port;
strcpy (type, server_type);
strcpy (addr, host_name);
strcpy (addr, server_address);
}
else {
die (STATE_UNKNOWN,
_("UNKNOWN - Could not parse redirect location - %s%s\n"),
_("HTTP UNKNOWN - Could not parse redirect location - %s%s\n"),
pos, (display_html ? "</A>" : ""));
}
@ -1156,7 +1170,7 @@ redir (char *pos, char *status_line)
if (++redir_depth > max_depth)
die (STATE_WARNING,
_("WARNING - maximum redirection depth %d exceeded - %s://%s:%d%s%s\n"),
_("HTTP WARNING - maximum redirection depth %d exceeded - %s://%s:%d%s%s\n"),
max_depth, type, addr, i, url, (display_html ? "</A>" : ""));
if (server_port==i &&
@ -1164,10 +1178,9 @@ redir (char *pos, char *status_line)
(host_name && !strcmp(host_name, addr)) &&
!strcmp(server_url, url))
die (STATE_WARNING,
_("WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
_("HTTP WARNING - redirection creates an infinite loop - %s://%s:%d%s%s\n"),
type, addr, i, url, (display_html ? "</A>" : ""));
server_port = i;
strcpy (server_type, type);
free (host_name);
@ -1177,7 +1190,22 @@ redir (char *pos, char *status_line)
server_address = strdup (addr);
free (server_url);
server_url = strdup (url);
if ((url[0] == '/'))
server_url = strdup (url);
else if (asprintf(&server_url, "/%s", url) == -1)
die (STATE_UNKNOWN, _("HTTP UNKNOWN - Could not allocate server_url%s\n"),
display_html ? "</A>" : "");
free(url);
if ((server_port = i) > MAX_PORT)
die (STATE_UNKNOWN,
_("HTTP UNKNOWN - Redirection to port above %d - %s://%s:%d%s%s\n"),
MAX_PORT, server_type, server_address, server_port, server_url,
display_html ? "</A>" : "");
if (verbose)
printf (_("Redirection to %s://%s:%d%s\n"), server_type, server_address,
server_port, server_url);
check_http ();
}
@ -1349,5 +1377,6 @@ print_usage (void)
printf (" [-w <warn time>] [-c <critical time>] [-t <timeout>] [-L]\n");
printf (" [-a auth] [-f <ok | warn | critcal | follow>] [-e <expect>]\n");
printf (" [-s string] [-l] [-r <regex> | -R <case-insensitive regex>] [-P string]\n");
printf (" [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string] [-k string]\n");
printf (" [-m <min_pg_size>:<max_pg_size>] [-4|-6] [-N] [-M <age>] [-A string]\n");
printf (" [-k string] [-S] [-C <age>] [-T <content-type>]\n");
}

View file

@ -10,7 +10,7 @@
* Copyright (c) 2000 Robert Dale <rdale@digital-mission.com>
* Copyright (c) 2000-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/02/06 21:03:21 $
* Last Modified: $Date: 2007-06-13 10:43:28 +0100 (Wed, 13 Jun 2007) $
*
* Description:
*
@ -35,11 +35,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_ide_smart.c,v 1.14 2007/02/06 21:03:21 opensides Exp $
* $Id: check_ide_smart.c 1739 2007-06-13 09:43:28Z psychotrahe $
*/
const char *progname = "check_ide_smart";
const char *revision = "$Revision: 1.14 $";
const char *revision = "$Revision: 1739 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -437,23 +437,6 @@ print_values (values_t * p, thresholds_t * t)
}
void
print_thresholds (thresholds_t * p)
{
threshold_t * threshold = p->thresholds;
int i;
printf ("\n");
printf ("SmartRevision=%d\n", p->revision);
for (i = 0; i < NR_ATTRIBUTES; i++) {
if (threshold->id) {
printf ("Id=%3d, Threshold=%3d\n", threshold->id,
threshold->threshold); }
++threshold;
}
printf ("CheckSum=%d\n", p->checksum);
}
int
smart_cmd_simple (int fd, enum SmartCommand command, __u8 val0, char show_error)
{
@ -541,7 +524,7 @@ print_help (void)
void
print_usage (void)
{
printf (_("Usage:");
printf (_("Usage:"));
printf ("%s [-d <device>] [-i <immediate>] [-q quiet] [-1 <auto-on>]",progname);
pritnf (" [-O <auto-off>] [-n <nagios>]\n");
printf (" [-O <auto-off>] [-n <nagios>]\n");
}

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 2000-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-07-07 23:20:40 +0100 (Sat, 07 Jul 2007) $
*
* Description:
*
@ -27,13 +27,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_ldap.c,v 1.35 2007/01/28 21:46:40 hweiss Exp $
$Id: check_ldap.c 1753 2007-07-07 22:20:40Z psychotrahe $
******************************************************************************/
/* progname may be check_ldaps */
char *progname = "check_ldap";
const char *revision = "$Revision: 1.35 $";
const char *revision = "$Revision: 1753 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -70,6 +70,9 @@ int ld_protocol = DEFAULT_PROTOCOL;
double warn_time = UNDEFINED;
double crit_time = UNDEFINED;
struct timeval tv;
int starttls = FALSE;
int ssl_on_connect = FALSE;
int verbose = 0;
/* for ldap tls */
@ -104,6 +107,9 @@ main (int argc, char *argv[])
if (process_arguments (argc, argv) == ERROR)
usage4 (_("Could not parse arguments"));
if (strstr(argv[0],"check_ldaps") && ! starttls && ! ssl_on_connect)
starttls = TRUE;
/* initialize alarm signal handling */
signal (SIGALRM, socket_timeout_alarm_handler);
@ -121,7 +127,8 @@ main (int argc, char *argv[])
}
#else
if (!(ld = ldap_open (ld_host, ld_port))) {
/*ldap_perror(ld, "ldap_open"); */
if (verbose)
ldap_perror(ld, "ldap_open");
printf (_("Could not connect to the server at port %i\n"), ld_port);
return STATE_CRITICAL;
}
@ -136,54 +143,54 @@ main (int argc, char *argv[])
}
#endif
if (strstr(argv[0],"check_ldaps")) {
/* with TLS */
if ( ld_port == LDAPS_PORT ) {
asprintf (&SERVICE, "LDAPS");
if (ld_port == LDAPS_PORT || ssl_on_connect) {
asprintf (&SERVICE, "LDAPS");
#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS)
/* ldaps: set option tls */
tls = LDAP_OPT_X_TLS_HARD;
if (ldap_set_option (ld, LDAP_OPT_X_TLS, &tls) != LDAP_SUCCESS)
{
/*ldap_perror(ld, "ldaps_option"); */
printf (_("Could not init TLS at port %i!\n"), ld_port);
return STATE_CRITICAL;
}
#else
printf (_("TLS not supported by the libraries!\n"), ld_port);
/* ldaps: set option tls */
tls = LDAP_OPT_X_TLS_HARD;
if (ldap_set_option (ld, LDAP_OPT_X_TLS, &tls) != LDAP_SUCCESS)
{
if (verbose)
ldap_perror(ld, "ldaps_option");
printf (_("Could not init TLS at port %i!\n"), ld_port);
return STATE_CRITICAL;
#endif /* LDAP_OPT_X_TLS */
} else {
asprintf (&SERVICE, "LDAP-TLS");
#if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S)
/* ldap with startTLS: set option version */
if (ldap_get_option(ld,LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS )
{
if (version < LDAP_VERSION3)
{
version = LDAP_VERSION3;
ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version);
}
}
/* call start_tls */
if (ldap_start_tls_s(ld, NULL, NULL) != LDAP_SUCCESS)
{
/*ldap_perror(ld, "ldap_start_tls"); */
printf (_("Could not init startTLS at port %i!\n"), ld_port);
return STATE_CRITICAL;
}
#else
printf (_("startTLS not supported by the library, needs LDAPv3!\n"));
return STATE_CRITICAL;
#endif /* HAVE_LDAP_START_TLS_S */
}
#else
printf (_("TLS not supported by the libraries!\n"));
return STATE_CRITICAL;
#endif /* LDAP_OPT_X_TLS */
} else if (starttls) {
asprintf (&SERVICE, "LDAP-TLS");
#if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S)
/* ldap with startTLS: set option version */
if (ldap_get_option(ld,LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS )
{
if (version < LDAP_VERSION3)
{
version = LDAP_VERSION3;
ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version);
}
}
/* call start_tls */
if (ldap_start_tls_s(ld, NULL, NULL) != LDAP_SUCCESS)
{
if (verbose)
ldap_perror(ld, "ldap_start_tls");
printf (_("Could not init startTLS at port %i!\n"), ld_port);
return STATE_CRITICAL;
}
#else
printf (_("startTLS not supported by the library, needs LDAPv3!\n"));
return STATE_CRITICAL;
#endif /* HAVE_LDAP_START_TLS_S */
}
/* bind to the ldap server */
if (ldap_bind_s (ld, ld_binddn, ld_passwd, LDAP_AUTH_SIMPLE) !=
LDAP_SUCCESS) {
/*ldap_perror(ld, "ldap_bind"); */
if (verbose)
ldap_perror(ld, "ldap_bind");
printf (_("Could not bind to the ldap-server\n"));
return STATE_CRITICAL;
}
@ -191,7 +198,8 @@ main (int argc, char *argv[])
/* do a search of all objectclasses in the base dn */
if (ldap_search_s (ld, ld_base, LDAP_SCOPE_BASE, ld_attr, NULL, 0, &result)
!= LDAP_SUCCESS) {
/*ldap_perror(ld, "ldap_search"); */
if (verbose)
ldap_perror(ld, "ldap_search");
printf (_("Could not search/find objectclasses in %s\n"), ld_base);
return STATE_CRITICAL;
}
@ -247,11 +255,14 @@ process_arguments (int argc, char **argv)
{"ver2", no_argument, 0, '2'},
{"ver3", no_argument, 0, '3'},
#endif
{"starttls", no_argument, 0, 'T'},
{"ssl", no_argument, 0, 'S'},
{"use-ipv4", no_argument, 0, '4'},
{"use-ipv6", no_argument, 0, '6'},
{"port", required_argument, 0, 'p'},
{"warn", required_argument, 0, 'w'},
{"crit", required_argument, 0, 'c'},
{"verbose", no_argument, 0, 'v'},
{0, 0, 0, 0}
};
@ -264,7 +275,7 @@ process_arguments (int argc, char **argv)
}
while (1) {
c = getopt_long (argc, argv, "hV2346t:c:w:H:b:p:a:D:P:", longopts, &option);
c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:", longopts, &option);
if (c == -1 || c == EOF)
break;
@ -317,6 +328,22 @@ process_arguments (int argc, char **argv)
case '4':
address_family = AF_INET;
break;
case 'v':
verbose++;
break;
case 'T':
if (! ssl_on_connect)
starttls = TRUE;
else
usage_va(_("%s cannot be combined with %s"), "-T/--starttls", "-S/--ssl");
break;
case 'S':
if (! starttls) {
ssl_on_connect = TRUE;
ld_port = LDAPS_PORT;
} else
usage_va(_("%s cannot be combined with %s"), "-S/--ssl", "-T/--starttls");
break;
case '6':
#ifdef USE_IPV6
address_family = AF_INET6;
@ -382,13 +409,17 @@ print_help (void)
printf (" %s\n", _("ldap bind DN (if required)"));
printf (" %s\n", "-P [--pass]");
printf (" %s\n", _("ldap password (if required)"));
printf (" %s\n", "-T [--starttls]");
printf (" %s\n", _("use starttls mechanism introduced in protocol version 3"));
printf (" %s\n", "-S [--ssl]");
printf (" %s\n", _("use ldaps (ldap v2 ssl method). this also sets the default port to %s"), LDAPS_PORT);
#ifdef HAVE_LDAP_SET_OPTION
printf (" %s\n", "-2 [--ver2]");
printf (" %s\n", _("use ldap protocol version 2"));
printf (" %s\n", "-3 [--ver3]");
printf (" %s\n", _("use ldap protocol version 3"));
printf ("(default protocol version: %d)", DEFAULT_PROTOCOL);
printf (" (default protocol version: %d)\n", DEFAULT_PROTOCOL);
#endif
printf (_(UT_WARN_CRIT));
@ -397,6 +428,13 @@ print_help (void)
printf (_(UT_VERBOSE));
printf ("\n%s\n", _("Note:"));
printf ("%s\n", _("If this plugin is called via 'check_ldaps', method 'STARTTLS' will be"));
printf (_("implied (using default port %i) unless --port=636 is specified. In that case %s"), DEFAULT_PORT, "\n");
printf ("%s\n", _("'SSL on connect' will be used no matter how the plugin was called."));
printf ("%s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags"));
printf ("%s\n", _("to define the behaviour explicitly instead."));
printf (_(UT_SUPPORT));
}

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-04-25 23:10:13 +0100 (Wed, 25 Apr 2007) $
*
* Description:
*
@ -30,12 +30,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_load.c,v 1.33 2007/01/28 21:46:40 hweiss Exp $
$Id: check_load.c 1700 2007-04-25 22:10:13Z tonvoon $
******************************************************************************/
const char *progname = "check_load";
const char *revision = "$Revision: 1.33 $";
const char *revision = "$Revision: 1700 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -71,6 +71,7 @@ double cload[3] = { 0.0, 0.0, 0.0 };
#define la15 la[2]
char *status_line;
int take_into_account_cpus = 0;
static void
get_threshold(char *arg, double *th)
@ -103,6 +104,7 @@ main (int argc, char **argv)
{
int result;
int i;
long numcpus;
double la[3] = { 0.0, 0.0, 0.0 }; /* NetBSD complains about unitialized arrays */
#ifndef HAVE_GETLOADAVG
@ -163,6 +165,13 @@ main (int argc, char **argv)
# endif
#endif
if (take_into_account_cpus == 1) {
if ((numcpus = GET_NUMBER_OF_CPUS()) > 0) {
la[0] = la[0] / numcpus;
la[1] = la[1] / numcpus;
la[2] = la[2] / numcpus;
}
}
if ((la[0] < 0.0) || (la[1] < 0.0) || (la[2] < 0.0)) {
#ifdef HAVE_GETLOADAVG
printf (_("Error in getloadavg()\n"));
@ -208,6 +217,7 @@ process_arguments (int argc, char **argv)
static struct option longopts[] = {
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"percpu", no_argument, 0, 'r'},
{"version", no_argument, 0, 'V'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
@ -217,7 +227,7 @@ process_arguments (int argc, char **argv)
return ERROR;
while (1) {
c = getopt_long (argc, argv, "Vhc:w:", longopts, &option);
c = getopt_long (argc, argv, "Vhrc:w:", longopts, &option);
if (c == -1 || c == EOF)
break;
@ -229,6 +239,9 @@ process_arguments (int argc, char **argv)
case 'c': /* critical time threshold */
get_threshold(optarg, cload);
break;
case 'r': /* Divide load average by number of CPUs */
take_into_account_cpus = 1;
break;
case 'V': /* version */
print_revision (progname, revision);
exit (STATE_OK);
@ -301,6 +314,8 @@ print_help (void)
printf (" %s\n", "-c, --critical=CLOAD1,CLOAD5,CLOAD15");
printf (" %s\n", _("Exit with CRITICAL status if load average exceed CLOADn"));
printf (" %s\n", _("the load average format is the same used by \"uptime\" and \"w\""));
printf (" %s\n", "-r, --percpu");
printf (" %s\n", _("Divide the load averages by the number of CPUs (when possible)"));
printf (_(UT_SUPPORT));
}
@ -309,5 +324,5 @@ void
print_usage (void)
{
printf (_("Usage:"));
printf ("%s -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname);
printf ("%s [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15\n", progname);
}

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/02/06 21:03:21 $
* Last Modified: $Date: 2007-02-06 21:03:21 +0000 (Tue, 06 Feb 2007) $
*
* Description:
*
@ -31,12 +31,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_mrtg.c,v 1.30 2007/02/06 21:03:21 opensides Exp $
$Id: check_mrtg.c 1611 2007-02-06 21:03:21Z opensides $
******************************************************************************/
const char *progname = "check_mrtg";
const char *revision = "$Revision: 1.30 $";
const char *revision = "$Revision: 1611 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2007 nagios-plugins team
*
* Last Modified: $Date: 2007/03/02 01:38:04 $
* Last Modified: $Date: 2007-03-02 01:38:04 +0000 (Fri, 02 Mar 2007) $
*
* Description:
*
@ -31,7 +31,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_mrtgtraf.c,v 1.28 2007/03/02 01:38:04 egalstad Exp $
$Id: check_mrtgtraf.c 1624 2007-03-02 01:38:04Z egalstad $
******************************************************************************/
@ -39,7 +39,7 @@
#include "utils.h"
const char *progname = "check_mrtgtraf";
const char *revision = "$Revision: 1.28 $";
const char *revision = "$Revision: 1624 $";
const char *copyright = "1999-2007";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -7,7 +7,7 @@
* Copyright (c) 1999-2006 nagios-plugins team
* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net)
*
* Last Modified: $Date: 2007/03/29 17:58:28 $
* Last Modified: $Date: 2007-03-29 18:58:28 +0100 (Thu, 29 Mar 2007) $
*
* Description:
*
@ -32,12 +32,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_mysql.c,v 1.35 2007/03/29 17:58:28 hweiss Exp $
* $Id: check_mysql.c 1655 2007-03-29 17:58:28Z hweiss $
*
******************************************************************************/
const char *progname = "check_mysql";
const char *revision = "$Revision: 1.35 $";
const char *revision = "$Revision: 1655 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 2006 nagios-plugins team, after Didi Rieder (check_mysql)
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -30,12 +30,12 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
* CHECK_MYSQL_QUERY.C
*
* $Id: check_mysql_query.c,v 1.6 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_mysql_query.c 1590 2007-01-28 21:46:41Z hweiss $
*
******************************************************************************/
const char *progname = "check_mysql_query";
const char *revision = "$Revision: 1.6 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -33,12 +33,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_nagios.c,v 1.32 2007/01/28 21:46:40 hweiss Exp $
$Id: check_nagios.c 1590 2007-01-28 21:46:41Z hweiss $
******************************************************************************/
const char *progname = "check_nagios";
const char *revision = "$Revision: 1.32 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -6,7 +6,7 @@
* Copyright (c) 2000-2002 Yves Rubin (rubiyz@yahoo.com)
* Copyright (c) 2003-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -32,12 +32,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_nt.c,v 1.46 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_nt.c 1590 2007-01-28 21:46:41Z hweiss $
*
*****************************************************************************/
const char *progname = "check_nt";
const char *revision = "$Revision: 1.46 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2003-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -6,7 +6,7 @@
* Copyright (c) 2006 sean finney <seanius@seanius.net>
* Copyright (c) 2006 nagios-plugins team
*
* Last Modified: $Date: 2007/04/10 07:17:18 $
* Last Modified: $Date: 2007-09-26 05:16:21 +0100 (Wed, 26 Sep 2007) $
*
* Description:
*
@ -32,12 +32,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_ntp.c,v 1.25 2007/04/10 07:17:18 dermoth Exp $
$Id: check_ntp.c 1799 2007-09-26 04:16:21Z dermoth $
*****************************************************************************/
const char *progname = "check_ntp";
const char *revision = "$Revision: 1.25 $";
const char *revision = "$Revision: 1799 $";
const char *copyright = "2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -86,6 +86,7 @@ typedef struct {
double rtdelay; /* converted from the ntp_message */
double rtdisp; /* converted from the ntp_message */
double offset[AVG_NUM]; /* offsets from each response */
uint8_t flags; /* byte with leapindicator,vers,mode. see macros */
} ntp_server_results;
/* this structure holds everything in an ntp control message as per rfc1305 */
@ -302,6 +303,12 @@ int best_offset_server(const ntp_server_results *slist, int nservers){
/* for each server */
for(cserver=0; cserver<nservers; cserver++){
/* sort out servers with error flags */
if ( LI(slist[cserver].flags) != LI_NOWARNING ){
if (verbose) printf("discarding peer id %d: flags=%d\n", cserver, LI(slist[cserver].flags));
break;
}
/* compare it to each of the servers already in the candidate list */
for(i=0; i<csize; i++){
/* does it have an equal or better stratum? */
@ -450,6 +457,7 @@ double offset_request(const char *host, int *status){
servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp);
servers[i].rtdelay=NTP32asDOUBLE(req[i].rtdelay);
servers[i].waiting=0;
servers[i].flags=req[i].flags;
servers_readable--;
one_read = 1;
if(servers[i].num_responses==AVG_NUM) servers_completed++;
@ -720,7 +728,7 @@ int process_arguments(int argc, char **argv){
usage4(_("Critical offset should be larger than warning offset"));
}
if (ocrit < owarn){
if (jcrit < jwarn){
usage4(_("Critical jitter should be larger than warning jitter"));
}
@ -808,6 +816,7 @@ int main(int argc, char *argv[]){
}
if(offset_result==STATE_CRITICAL){
asprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
asprintf(&perfdata_line, "");
} else {
if(offset_result==STATE_WARNING){
asprintf(&result_line, "%s %s", result_line, _("Unable to fully sample sync server"));

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 2000-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -31,12 +31,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_nwstat.c,v 1.35 2007/01/28 21:46:40 hweiss Exp $
$Id: check_nwstat.c 1590 2007-01-28 21:46:41Z hweiss $
******************************************************************************/
const char *progname = "check_nwstat";
const char *revision = "$Revision: 1.35 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 2000-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/02/06 21:03:21 $
* Last Modified: $Date: 2007-02-06 21:03:21 +0000 (Tue, 06 Feb 2007) $
*
* Description:
*
@ -31,12 +31,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_overcr.c,v 1.23 2007/02/06 21:03:21 opensides Exp $
$Id: check_overcr.c 1611 2007-02-06 21:03:21Z opensides $
******************************************************************************/
const char *progname = "check_overcr";
const char *revision = "$Revision: 1.23 $";
const char *revision = "$Revision: 1611 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -30,12 +30,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_pgsql.c,v 1.35 2007/01/28 21:46:40 hweiss Exp $
$Id: check_pgsql.c 1590 2007-01-28 21:46:41Z hweiss $
*****************************************************************************/
const char *progname = "check_pgsql";
const char *revision = "$Revision: 1.35 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 2000-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/03/12 10:51:05 $
* Last Modified: $Date: 2007-04-23 08:30:47 +0100 (Mon, 23 Apr 2007) $
*
* Description:
*
@ -30,12 +30,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: check_ping.c,v 1.60 2007/03/12 10:51:05 tonvoon Exp $
$Id: check_ping.c 1699 2007-04-23 07:30:47Z hweiss $
******************************************************************************/
const char *progname = "check_ping";
const char *revision = "$Revision: 1.60 $";
const char *revision = "$Revision: 1699 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -105,7 +105,7 @@ main (int argc, char **argv)
/* If ./configure finds ping has timeout values, set plugin alarm slightly
* higher so that we can use response from command line ping */
#ifdef PING_PACKETS_FIRST && PING_HAS_TIMEOUT
#if defined(PING_PACKETS_FIRST) && defined(PING_HAS_TIMEOUT)
alarm (timeout_interval + 1);
#else
alarm (timeout_interval);

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/03/06 17:29:15 $
* Last Modified: $Date: 2007-07-15 16:21:51 +0100 (Sun, 15 Jul 2007) $
*
* Description:
*
@ -31,13 +31,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_procs.c,v 1.58 2007/03/06 17:29:15 tonvoon Exp $
* $Id: check_procs.c 1758 2007-07-15 15:21:51Z psychotrahe $
*
******************************************************************************/
const char *progname = "check_procs";
const char *program_name = "check_procs"; /* Required for coreutils libs */
const char *revision = "$Revision: 1.58 $";
const char *revision = "$Revision: 1758 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -185,7 +185,7 @@ main (int argc, char **argv)
cols = sscanf (input_line, PS_FORMAT, PS_VARLIST);
/* Zombie processes do not give a procprog command */
if ( cols == (expected_cols - 1) && strstr(procstat, zombie) ) {
if ( cols < expected_cols && strstr(procstat, zombie) ) {
cols = expected_cols;
}
if ( cols >= expected_cols ) {

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-09-26 11:57:44 +0100 (Wed, 26 Sep 2007) $
*
* Description:
*
@ -30,12 +30,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_radius.c,v 1.25 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_radius.c 1800 2007-09-26 10:57:44Z hweiss $
*
*******************************************************************************/
const char *progname = "check_radius";
const char *revision = "$Revision: 1.25 $";
const char *revision = "$Revision: 1800 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -43,12 +43,35 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "utils.h"
#include "netutils.h"
#ifdef HAVE_LIBRADIUSCLIENT_NG
#include <radiusclient-ng.h>
rc_handle *rch = NULL;
#else
#include <radiusclient.h>
#endif
int process_arguments (int, char **);
void print_help (void);
void print_usage (void);
/* libradiusclient(-ng) wrapper functions */
#ifdef HAVE_LIBRADIUSCLIENT_NG
#define my_rc_conf_str(a) rc_conf_str(rch,a)
#define my_rc_send_server(a,b) rc_send_server(rch,a,b)
#define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(rch,a,b,c,d,e,f)
#define my_rc_own_ipaddress() rc_own_ipaddress(rch)
#define my_rc_avpair_add(a,b,c,d) rc_avpair_add(rch,a,b,c,-1,d)
#define my_rc_read_dictionary(a) rc_read_dictionary(rch, a)
#else
#define my_rc_conf_str(a) rc_conf_str(a)
#define my_rc_send_server(a,b) rc_send_server(a, b)
#define my_rc_buildreq(a,b,c,d,e,f) rc_buildreq(a,b,c,d,e,f)
#define my_rc_own_ipaddress() rc_own_ipaddress()
#define my_rc_avpair_add(a,b,c,d) rc_avpair_add(a, b, c, d)
#define my_rc_read_dictionary(a) rc_read_dictionary(a)
#endif
int my_rc_read_config(char *);
char *server = NULL;
char *username = NULL;
char *password = NULL;
@ -133,33 +156,33 @@ main (int argc, char **argv)
usage4 (_("Could not parse arguments"));
str = strdup ("dictionary");
if ((config_file && rc_read_config (config_file)) ||
rc_read_dictionary (rc_conf_str (str)))
if ((config_file && my_rc_read_config (config_file)) ||
my_rc_read_dictionary (my_rc_conf_str (str)))
die (STATE_UNKNOWN, _("Config file error"));
service = PW_AUTHENTICATE_ONLY;
memset (&data, 0, sizeof(data));
if (!(rc_avpair_add (&data.send_pairs, PW_SERVICE_TYPE, &service, 0) &&
rc_avpair_add (&data.send_pairs, PW_USER_NAME, username, 0) &&
rc_avpair_add (&data.send_pairs, PW_USER_PASSWORD, password, 0) &&
(nasid==NULL || rc_avpair_add (&data.send_pairs, PW_NAS_IDENTIFIER, nasid, 0))))
if (!(my_rc_avpair_add (&data.send_pairs, PW_SERVICE_TYPE, &service, 0) &&
my_rc_avpair_add (&data.send_pairs, PW_USER_NAME, username, 0) &&
my_rc_avpair_add (&data.send_pairs, PW_USER_PASSWORD, password, 0) &&
(nasid==NULL || my_rc_avpair_add (&data.send_pairs, PW_NAS_IDENTIFIER, nasid, 0))))
die (STATE_UNKNOWN, _("Out of Memory?"));
/*
* Fill in NAS-IP-Address
*/
if ((client_id = rc_own_ipaddress ()) == 0)
if ((client_id = my_rc_own_ipaddress ()) == 0)
return (ERROR_RC);
if (rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) ==
if (my_rc_avpair_add (&(data.send_pairs), PW_NAS_IP_ADDRESS, &client_id, 0) ==
NULL) return (ERROR_RC);
rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, (int)timeout_interval,
my_rc_buildreq (&data, PW_ACCESS_REQUEST, server, port, (int)timeout_interval,
retries);
result = rc_send_server (&data, msg);
result = my_rc_send_server (&data, msg);
rc_avpair_free (data.send_pairs);
if (data.receive_pairs)
rc_avpair_free (data.receive_pairs);
@ -202,30 +225,6 @@ process_arguments (int argc, char **argv)
{0, 0, 0, 0}
};
if (argc < 2)
return ERROR;
if (argc == 9) {
config_file = argv[1];
username = argv[2];
password = argv[3];
if (is_intpos (argv[4]))
timeout_interval = atoi (argv[4]);
else
usage2 (_("Timeout interval must be a positive integer"), optarg);
if (is_intpos (argv[5]))
retries = atoi (argv[5]);
else
usage4 (_("Number of retries must be a positive integer"));
server = argv[6];
if (is_intpos (argv[7]))
port = atoi (argv[7]);
else
usage4 (_("Port must be a positive integer"));
expect = argv[8];
return OK;
}
while (1) {
c = getopt_long (argc, argv, "+hVvH:P:F:u:p:n:t:r:e:", longopts,
&option);
@ -286,6 +285,16 @@ process_arguments (int argc, char **argv)
break;
}
}
if (server == NULL)
usage4 (_("Host not specified"));
if (username == NULL)
usage4 (_("User not specified"));
if (password == NULL)
usage4 (_("Password not specified"));
if (config_file == NULL)
usage4 (_("Configuration file not specified"));
return OK;
}
@ -350,3 +359,15 @@ print_usage (void)
printf ("%s -H host -F config_file -u username -p password [-n nas-id] [-P port]\n\
[-t timeout] [-r retries] [-e expect]\n", progname);
}
int my_rc_read_config(char * a)
{
#ifdef HAVE_LIBRADIUSCLIENT_NG
rch = rc_read_config(a);
return (rch == NULL) ? 1 : 0;
#else
return rc_read_config(a);
#endif
}

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -31,12 +31,12 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* $Id: check_real.c,v 1.29 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_real.c 1590 2007-01-28 21:46:41Z hweiss $
*
******************************************************************************/
const char *progname = "check_real";
const char *revision = "$Revision: 1.29 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/03/06 22:29:27 $
* Last Modified: $Date: 2007-09-15 15:25:56 +0100 (Sat, 15 Sep 2007) $
*
* Description:
*
@ -31,15 +31,17 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* $Id: check_smtp.c,v 1.59 2007/03/06 22:29:27 tonvoon Exp $
* $Id: check_smtp.c 1780 2007-09-15 14:25:56Z hweiss $
*
******************************************************************************/
const char *progname = "check_smtp";
const char *revision = "$Revision: 1.59 $";
const char *revision = "$Revision: 1780 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include <ctype.h>
#include "common.h"
#include "netutils.h"
#include "utils.h"
@ -74,6 +76,9 @@ int process_arguments (int, char **);
int validate_arguments (void);
void print_help (void);
void print_usage (void);
void smtp_quit(void);
int recvline(char *, size_t);
int recvlines(char *, size_t);
int my_close(void);
#include "regex.h"
@ -115,7 +120,6 @@ char buffer[MAX_INPUT_BUFFER];
enum {
TCP_PROTOCOL = 1,
UDP_PROTOCOL = 2,
MAXBUF = 1024
};
/* written by lauri alanko */
@ -221,7 +225,7 @@ main (int argc, char **argv)
/* watch for the SMTP connection string and */
/* return a WARNING status if we couldn't read any data */
if (recv (sd, buffer, MAX_INPUT_BUFFER - 1, 0) == -1) {
if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) {
printf (_("recv() failed\n"));
result = STATE_WARNING;
}
@ -245,11 +249,10 @@ main (int argc, char **argv)
send(sd, helocmd, strlen(helocmd), 0);
/* allow for response to helo command to reach us */
if(read (sd, buffer, MAXBUF - 1) < 0){
if (recvlines(buffer, MAX_INPUT_BUFFER) <= 0) {
printf (_("recv() failed\n"));
return STATE_WARNING;
} else if(use_ehlo){
buffer[MAXBUF-1]='\0';
if(strstr(buffer, "250 STARTTLS") != NULL ||
strstr(buffer, "250-STARTTLS") != NULL){
supports_tls=TRUE;
@ -258,7 +261,7 @@ main (int argc, char **argv)
if(use_ssl && ! supports_tls){
printf(_("WARNING - TLS not supported by server\n"));
send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
smtp_quit();
return STATE_WARNING;
}
@ -267,10 +270,10 @@ main (int argc, char **argv)
/* send the STARTTLS command */
send(sd, SMTP_STARTTLS, strlen(SMTP_STARTTLS), 0);
recv(sd,buffer, MAX_INPUT_BUFFER-1, 0); /* wait for it */
recvlines(buffer, MAX_INPUT_BUFFER); /* wait for it */
if (!strstr (buffer, server_expect)) {
printf (_("Server does not support STARTTLS\n"));
send (sd, SMTP_QUIT, strlen (SMTP_QUIT), 0);
smtp_quit();
return STATE_UNKNOWN;
}
result = np_net_ssl_init(sd);
@ -301,13 +304,12 @@ main (int argc, char **argv)
}
if (verbose)
printf(_("sent %s"), helocmd);
if ((n = my_recv(buffer, MAX_INPUT_BUFFER - 1)) <= 0) {
if ((n = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) {
printf("%s\n", _("SMTP UNKNOWN - Cannot read EHLO response via TLS."));
my_close();
return STATE_UNKNOWN;
}
if (verbose) {
buffer[n] = '\0';
printf("%s", buffer);
}
@ -336,16 +338,14 @@ main (int argc, char **argv)
*/
if (smtp_use_dummycmd) {
my_send(cmd_str, strlen(cmd_str));
my_recv(buffer, MAX_INPUT_BUFFER-1);
if (verbose)
if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose)
printf("%s", buffer);
}
while (n < ncommands) {
asprintf (&cmd_str, "%s%s", commands[n], "\r\n");
my_send(cmd_str, strlen(cmd_str));
my_recv(buffer, MAX_INPUT_BUFFER-1);
if (verbose)
if (recvlines(buffer, MAX_INPUT_BUFFER) >= 1 && verbose)
printf("%s", buffer);
strip (buffer);
if (n < nresponses) {
@ -394,12 +394,11 @@ main (int argc, char **argv)
if (verbose)
printf (_("sent %s\n"), "AUTH LOGIN");
if((ret = my_recv(buffer, MAXBUF - 1)) < 0){
if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) {
asprintf(&error_msg, _("recv() failed after AUTH LOGIN, "));
result = STATE_WARNING;
break;
}
buffer[ret] = 0;
if (verbose)
printf (_("received %s\n"), buffer);
@ -416,12 +415,11 @@ main (int argc, char **argv)
if (verbose)
printf (_("sent %s\n"), abuf);
if ((ret = my_recv(buffer, MAX_INPUT_BUFFER-1)) == -1) {
if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) {
result = STATE_CRITICAL;
asprintf(&error_msg, _("recv() failed after sending authuser, "));
break;
}
buffer[ret] = 0;
if (verbose) {
printf (_("received %s\n"), buffer);
}
@ -437,12 +435,11 @@ main (int argc, char **argv)
if (verbose) {
printf (_("sent %s\n"), abuf);
}
if ((ret = my_recv(buffer, MAX_INPUT_BUFFER-1)) == -1) {
if ((ret = recvlines(buffer, MAX_INPUT_BUFFER)) <= 0) {
result = STATE_CRITICAL;
asprintf(&error_msg, _("recv() failed after sending authpass, "));
break;
}
buffer[ret] = 0;
if (verbose) {
printf (_("received %s\n"), buffer);
}
@ -460,7 +457,7 @@ main (int argc, char **argv)
}
/* tell the server we're done */
my_send (SMTP_QUIT, strlen (SMTP_QUIT));
smtp_quit();
/* finally close the connection */
close (sd);
@ -582,22 +579,26 @@ process_arguments (int argc, char **argv)
break;
case 'C': /* commands */
if (ncommands >= command_size) {
commands = realloc (commands, command_size+8);
command_size+=8;
commands = realloc (commands, sizeof(char *) * command_size);
if (commands == NULL)
die (STATE_UNKNOWN,
_("Could not realloc() units [%d]\n"), ncommands);
}
commands[ncommands] = optarg;
commands[ncommands] = (char *) malloc (sizeof(char) * 255);
strncpy (commands[ncommands], optarg, 255);
ncommands++;
break;
case 'R': /* server responses */
if (nresponses >= response_size) {
responses = realloc (responses, response_size+8);
response_size += 8;
responses = realloc (responses, sizeof(char *) * response_size);
if (responses == NULL)
die (STATE_UNKNOWN,
_("Could not realloc() units [%d]\n"), nresponses);
}
responses[nresponses] = optarg;
responses[nresponses] = (char *) malloc (sizeof(char) * 255);
strncpy (responses[nresponses], optarg, 255);
nresponses++;
break;
case 'c': /* critical time threshold */
@ -700,6 +701,88 @@ validate_arguments (void)
}
void
smtp_quit(void)
{
int bytes;
my_send(SMTP_QUIT, strlen(SMTP_QUIT));
if (verbose)
printf(_("sent %s\n"), "QUIT");
/* read the response but don't care about problems */
bytes = recvlines(buffer, MAX_INPUT_BUFFER);
if (verbose) {
if (bytes < 0)
printf(_("recv() failed after QUIT."));
else if (bytes == 0)
printf(_("Connection reset by peer."));
else {
buffer[bytes] = '\0';
printf(_("received %s\n"), buffer);
}
}
}
/*
* Receive one line, copy it into buf and nul-terminate it. Returns the
* number of bytes written to buf (excluding the '\0') or 0 on EOF or <0 on
* error.
*
* TODO: Reading one byte at a time is very inefficient. Replace this by a
* function which buffers the data, move that to netutils.c and change
* check_smtp and other plugins to use that. Also, remove (\r)\n.
*/
int
recvline(char *buf, size_t bufsize)
{
int result;
unsigned i;
for (i = result = 0; i < bufsize - 1; i++) {
if ((result = my_recv(&buf[i], 1)) != 1)
break;
if (buf[i] == '\n') {
buf[++i] = '\0';
return i;
}
}
return (result == 1 || i == 0) ? -2 : result; /* -2 if out of space */
}
/*
* Receive one or more lines, copy them into buf and nul-terminate it. Returns
* the number of bytes written to buf (excluding the '\0') or 0 on EOF or <0 on
* error. Works for all protocols which format multiline replies as follows:
*
* ``The format for multiline replies requires that every line, except the last,
* begin with the reply code, followed immediately by a hyphen, `-' (also known
* as minus), followed by text. The last line will begin with the reply code,
* followed immediately by <SP>, optionally some text, and <CRLF>. As noted
* above, servers SHOULD send the <SP> if subsequent text is not sent, but
* clients MUST be prepared for it to be omitted.'' (RFC 2821, 4.2.1)
*
* TODO: Move this to netutils.c. Also, remove \r and possibly the final \n.
*/
int
recvlines(char *buf, size_t bufsize)
{
int result, i;
for (i = 0; /* forever */; i += result)
if (!((result = recvline(buf + i, bufsize - i)) > 3 &&
isdigit((int)buf[i]) &&
isdigit((int)buf[i + 1]) &&
isdigit((int)buf[i + 2]) &&
buf[i + 3] == '-'))
break;
return (result <= 0) ? result : result + i;
}
int
my_close (void)
{

View file

@ -3,15 +3,15 @@
* Nagios check_snmp plugin
*
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
* Copyright (c) 1999-2007 nagios-plugins team
*
* Last Modified: $Date: 2007/02/02 09:10:22 $
* Last Modified: $Date: 2007-05-29 06:22:32 +0100 (Tue, 29 May 2007) $
*
* Description:
*
* This file contains the check_snmp plugin
*
* Check status of remote machines and obtain sustem information via SNMP
* Check status of remote machines and obtain system information via SNMP
*
*
* License Information:
@ -30,13 +30,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_snmp.c,v 1.69 2007/02/02 09:10:22 dermoth Exp $
* $Id: check_snmp.c 1721 2007-05-29 05:22:32Z dermoth $
*
******************************************************************************/
const char *progname = "check_snmp";
const char *revision = "$Revision: 1.69 $";
const char *copyright = "1999-2006";
const char *revision = "$Revision: 1721 $";
const char *copyright = "1999-2007";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
@ -84,8 +84,8 @@ int process_arguments (int, char **);
int validate_arguments (void);
char *clarify_message (char *);
int check_num (int);
int lu_getll (unsigned long *, char *);
int lu_getul (unsigned long *, char *);
int llu_getll (unsigned long long *, char *);
int llu_getul (unsigned long long *, char *);
char *thisarg (char *str);
char *nextarg (char *str);
void print_usage (void);
@ -124,15 +124,15 @@ size_t nunits = 0;
size_t unitv_size = 8;
int verbose = FALSE;
int usesnmpgetnext = FALSE;
unsigned long lower_warn_lim[MAX_OIDS];
unsigned long upper_warn_lim[MAX_OIDS];
unsigned long lower_crit_lim[MAX_OIDS];
unsigned long upper_crit_lim[MAX_OIDS];
unsigned long response_value[MAX_OIDS];
unsigned long long lower_warn_lim[MAX_OIDS];
unsigned long long upper_warn_lim[MAX_OIDS];
unsigned long long lower_crit_lim[MAX_OIDS];
unsigned long long upper_crit_lim[MAX_OIDS];
unsigned long long response_value[MAX_OIDS];
int check_warning_value = FALSE;
int check_critical_value = FALSE;
int retries = 0;
unsigned long eval_method[MAX_OIDS];
unsigned long long eval_method[MAX_OIDS];
char *delimiter;
char *output_delim;
char *miblist = NULL;
@ -184,13 +184,13 @@ main (int argc, char **argv)
/* create the command line to execute */
if(usesnmpgetnext == TRUE) {
asprintf(&command_line, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
PATH_TO_SNMPGETNEXT, timeout_interval, retries, miblist, proto,
authpriv, server_address, port, oid);
PATH_TO_SNMPGETNEXT, timeout_interval, retries, miblist, proto,
authpriv, server_address, port, oid);
}else{
asprintf (&command_line, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
PATH_TO_SNMPGET, timeout_interval, retries, miblist, proto,
authpriv, server_address, port, oid);
PATH_TO_SNMPGET, timeout_interval, retries, miblist, proto,
authpriv, server_address, port, oid);
}
if (verbose)
@ -204,10 +204,12 @@ main (int argc, char **argv)
exit (STATE_UNKNOWN);
}
#if 0 /* Removed May 29, 2007 */
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
if (child_stderr == NULL) {
printf (_("Could not open stderr for %s\n"), command_line);
}
#endif
while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process))
asprintf (&output, "%s%s", output, input_buffer);
@ -268,6 +270,10 @@ main (int argc, char **argv)
show = strstr (response, "Counter32: ") + 11;
strcpy(type, "c");
}
else if (strstr (response, "Counter64: ")) {
show = strstr (response, "Counter64: ") + 11;
strcpy(type, "c");
}
else if (strstr (response, "INTEGER: "))
show = strstr (response, "INTEGER: ") + 9;
else if (strstr (response, "STRING: "))
@ -296,7 +302,7 @@ main (int argc, char **argv)
die (STATE_UNKNOWN,_("No valid data returned"));
response_value[i] = strtoul (p2, NULL, 10);
iresult = check_num (i);
asprintf (&show, "%lu", response_value[i]);
asprintf (&show, "%llu", response_value[i]);
}
/* Process this block for string matching */
@ -339,11 +345,11 @@ main (int argc, char **argv)
/* Prepend a label for this OID if there is one */
if (nlabels > (size_t)1 && (size_t)i < nlabels && labels[i] != NULL)
asprintf (&outbuff, "%s%s%s %s%s%s", outbuff,
(i == 0) ? " " : output_delim,
labels[i], mark (iresult), show, mark (iresult));
(i == 0) ? " " : output_delim,
labels[i], mark (iresult), show, mark (iresult));
else
asprintf (&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim,
mark (iresult), show, mark (iresult));
mark (iresult), show, mark (iresult));
/* Append a unit string for this OID if there is one */
if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
@ -361,20 +367,25 @@ main (int argc, char **argv)
if (found == 0)
die (STATE_UNKNOWN,
_("%s problem - No data received from host\nCMD: %s\n"),
label,
command_line);
_("%s problem - No data received from host\nCMD: %s\n"),
label,
command_line);
#if 0 /* Removed May 29, 2007 */
/* WARNING if output found on stderr */
if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr))
result = max_state (result, STATE_WARNING);
/* close stderr */
(void) fclose (child_stderr);
#endif
/* close the pipe */
if (spclose (child_process))
result = max_state (result, STATE_WARNING);
if (spclose (child_process)) {
if (result == STATE_OK)
result = STATE_UNKNOWN;
asprintf (&outbuff, "%s (%s)", outbuff, _("snmpget returned an error status"));
}
/* if (nunits == 1 || i == 1) */
/* printf ("%s %s -%s %s\n", label, state_text (result), outbuff, units); */
@ -462,31 +473,31 @@ process_arguments (int argc, char **argv)
case 'H': /* Host or server */
server_address = optarg;
break;
case 'p': /* TCP port number */
case 'p': /* TCP port number */
port = optarg;
break;
case 'm': /* List of MIBS */
case 'm': /* List of MIBS */
miblist = optarg;
break;
case 'n': /* usesnmpgetnext */
case 'n': /* usesnmpgetnext */
usesnmpgetnext = TRUE;
break;
case 'P': /* SNMP protocol version */
case 'P': /* SNMP protocol version */
proto = optarg;
break;
case 'L': /* security level */
case 'L': /* security level */
seclevel = optarg;
break;
case 'U': /* security username */
case 'U': /* security username */
secname = optarg;
break;
case 'a': /* auth protocol */
case 'a': /* auth protocol */
authproto = optarg;
break;
case 'A': /* auth passwd */
case 'A': /* auth passwd */
authpasswd = optarg;
break;
case 'X': /* priv passwd */
case 'X': /* priv passwd */
privpasswd = optarg;
break;
case 't': /* timeout period */
@ -501,9 +512,9 @@ process_arguments (int argc, char **argv)
if (strspn (optarg, "0123456789:,") < strlen (optarg))
usage2 (_("Invalid critical threshold: %s\n"), optarg);
for (ptr = optarg; ptr && jj < MAX_OIDS; jj++) {
if (lu_getll (&lower_crit_lim[jj], ptr) == 1)
if (llu_getll (&lower_crit_lim[jj], ptr) == 1)
eval_method[jj] |= CRIT_LT;
if (lu_getul (&upper_crit_lim[jj], ptr) == 1)
if (llu_getul (&upper_crit_lim[jj], ptr) == 1)
eval_method[jj] |= CRIT_GT;
(ptr = index (ptr, ',')) ? ptr++ : ptr;
}
@ -512,9 +523,9 @@ process_arguments (int argc, char **argv)
if (strspn (optarg, "0123456789:,") < strlen (optarg))
usage2 (_("Invalid warning threshold: %s\n"), optarg);
for (ptr = optarg; ptr && ii < MAX_OIDS; ii++) {
if (lu_getll (&lower_warn_lim[ii], ptr) == 1)
if (llu_getll (&lower_warn_lim[ii], ptr) == 1)
eval_method[ii] |= WARN_LT;
if (lu_getul (&upper_warn_lim[ii], ptr) == 1)
if (llu_getul (&upper_warn_lim[ii], ptr) == 1)
eval_method[ii] |= WARN_GT;
(ptr = index (ptr, ',')) ? ptr++ : ptr;
}
@ -697,14 +708,14 @@ validate_arguments ()
if (proto == NULL || (strcmp(proto,DEFAULT_PROTOCOL) == 0) ) { /* default protocol version */
if (proto == NULL || (strcmp(proto,DEFAULT_PROTOCOL) == 0) ) { /* default protocol version */
asprintf(&proto, DEFAULT_PROTOCOL);
asprintf(&authpriv, "%s%s", "-c ", community);
}
else if ( strcmp (proto, "2c") == 0 ) { /* snmpv2c args */
else if ( strcmp (proto, "2c") == 0 ) { /* snmpv2c args */
asprintf(&authpriv, "%s%s", "-c ", community);
}
else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */
else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */
asprintf(&proto, "%s", "3");
if ( (strcmp(seclevel, "noAuthNoPriv") == 0) || seclevel == NULL ) {
@ -819,14 +830,14 @@ check_num (int i)
int
lu_getll (unsigned long *ll, char *str)
llu_getll (unsigned long long *ll, char *str)
{
char tmp[100];
if (strchr (str, ':') == NULL)
return 0;
if (strchr (str, ',') != NULL && (strchr (str, ',') < strchr (str, ':')))
return 0;
if (sscanf (str, "%lu%[:]", ll, tmp) == 2)
if (sscanf (str, "%llu%[:]", ll, tmp) == 2)
return 1;
return 0;
}
@ -834,14 +845,14 @@ lu_getll (unsigned long *ll, char *str)
int
lu_getul (unsigned long *ul, char *str)
llu_getul (unsigned long long *ul, char *str)
{
char tmp[100];
if (sscanf (str, "%lu%[^,]", ul, tmp) == 1)
if (sscanf (str, "%llu%[^,]", ul, tmp) == 1)
return 1;
if (sscanf (str, ":%lu%[^,]", ul, tmp) == 1)
if (sscanf (str, ":%llu%[^,]", ul, tmp) == 1)
return 1;
if (sscanf (str, "%*u:%lu%[^,]", ul, tmp) == 1)
if (sscanf (str, "%*u:%llu%[^,]", ul, tmp) == 1)
return 1;
return 0;
}

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -31,12 +31,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_ssh.c,v 1.32 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_ssh.c 1590 2007-01-28 21:46:41Z hweiss $
*
******************************************************************************/
const char *progname = "check_ssh";
const char *revision = "$Revision: 1.32 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -221,7 +221,7 @@ ssh_connect (char *haddr, int hport, char *remote_version)
char *ssh_server = NULL;
char rev_no[20];
sscanf ("$Revision: 1.32 $", "$Revision: %[0123456789.]", rev_no);
sscanf ("$Revision: 1590 $", "$Revision: %[0123456789.]", rev_no);
result = my_tcp_connect (haddr, hport, &sd);

View file

@ -6,7 +6,7 @@
* Copyright (c) 2000 Karl DeBisschop (kdebisschop@users.sourceforge.net)
* Copyright (c) 2000-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/02/07 14:06:11 $
* Last Modified: $Date: 2007-02-07 14:06:11 +0000 (Wed, 07 Feb 2007) $
*
* Description:
*
@ -28,12 +28,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_swap.c,v 1.59 2007/02/07 14:06:11 hweiss Exp $
* $Id: check_swap.c 1613 2007-02-07 14:06:11Z hweiss $
*
*****************************************************************************/
const char *progname = "check_swap";
const char *revision = "$Revision: 1.59 $";
const char *revision = "$Revision: 1613 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/02/14 10:11:06 $
* Last Modified: $Date: 2007-06-03 15:40:13 +0100 (Sun, 03 Jun 2007) $
*
* Description:
*
@ -27,19 +27,20 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_tcp.c,v 1.89 2007/02/14 10:11:06 tonvoon Exp $
* $Id: check_tcp.c 1729 2007-06-03 14:40:13Z psychotrahe $
*
*****************************************************************************/
/* progname "check_tcp" changes depending on symlink called */
char *progname;
const char *revision = "$Revision: 1.89 $";
const char *revision = "$Revision: 1729 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#include "common.h"
#include "netutils.h"
#include "utils.h"
#include "utils_tcp.h"
#ifdef HAVE_SSL
static int check_cert = FALSE;
@ -90,6 +91,7 @@ static int expect_mismatch_state = STATE_WARNING;
#define FLAG_TIME_WARN 0x08
#define FLAG_TIME_CRIT 0x10
#define FLAG_HIDE_OUTPUT 0x20
#define FLAG_MATCH_ALL 0x40
static size_t flags = FLAG_EXACT_MATCH;
int
@ -99,7 +101,8 @@ main (int argc, char **argv)
int i;
char *status = NULL;
struct timeval tv;
size_t len, match = -1;
size_t len;
int match = -1;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
@ -298,22 +301,12 @@ main (int argc, char **argv)
(int)len + 1, status);
while(isspace(status[len])) status[len--] = '\0';
for (i = 0; i < server_expect_count; i++) {
match = -2; /* tag it so we know if we tried and failed */
if (flags & FLAG_VERBOSE)
printf ("looking for [%s] %s [%s]\n", server_expect[i],
(flags & FLAG_EXACT_MATCH) ? "in beginning of" : "anywhere in",
status);
/* match it. math first in short-circuit */
if ((flags & FLAG_EXACT_MATCH && !strncmp(status, server_expect[i], strlen(server_expect[i]))) ||
(!(flags & FLAG_EXACT_MATCH) && strstr(status, server_expect[i])))
{
if(flags & FLAG_VERBOSE) puts("found it");
match = i;
break;
}
}
match = np_expect_match(status,
server_expect,
server_expect_count,
(flags & FLAG_MATCH_ALL ? TRUE : FALSE),
(flags & FLAG_EXACT_MATCH ? TRUE : FALSE),
(flags & FLAG_VERBOSE ? TRUE : FALSE));
}
if (server_quit != NULL) {
@ -333,7 +326,7 @@ main (int argc, char **argv)
result = STATE_WARNING;
/* did we get the response we hoped? */
if(match == -2 && result != STATE_CRITICAL)
if(match == FALSE && result != STATE_CRITICAL)
result = expect_mismatch_state;
/* reset the alarm */
@ -344,10 +337,10 @@ main (int argc, char **argv)
* the response we were looking for. if-else */
printf("%s %s - ", SERVICE, state_text(result));
if(match == -2 && len && !(flags & FLAG_HIDE_OUTPUT))
if(match == FALSE && len && !(flags & FLAG_HIDE_OUTPUT))
printf("Unexpected response from host/socket: %s", status);
else {
if(match == -2)
if(match == FALSE)
printf("Unexpected response from host/socket on ");
else
printf("%.3f second response time on ", elapsed_time);
@ -357,25 +350,25 @@ main (int argc, char **argv)
printf("socket %s", server_address);
}
if (match != -2 && !(flags & FLAG_HIDE_OUTPUT) && len)
if (match != FALSE && !(flags & FLAG_HIDE_OUTPUT) && len)
printf (" [%s]", status);
/* perf-data doesn't apply when server doesn't talk properly,
* so print all zeroes on warn and crit. Use fperfdata since
* localisation settings can make different outputs */
if(match == -2)
if(match == FALSE)
printf ("|%s",
fperfdata ("time", elapsed_time, "s",
TRUE, 0,
TRUE, 0,
(flags & FLAG_TIME_WARN ? TRUE : FALSE), 0,
(flags & FLAG_TIME_CRIT ? TRUE : FALSE), 0,
TRUE, 0,
TRUE, socket_timeout)
);
else
printf("|%s",
fperfdata ("time", elapsed_time, "s",
TRUE, warning_time,
TRUE, critical_time,
(flags & FLAG_TIME_WARN ? TRUE : FALSE), warning_time,
(flags & FLAG_TIME_CRIT ? TRUE : FALSE), critical_time,
TRUE, 0,
TRUE, socket_timeout)
);
@ -404,6 +397,7 @@ process_arguments (int argc, char **argv)
{"protocol", required_argument, 0, 'P'},
{"port", required_argument, 0, 'p'},
{"escape", required_argument, 0, 'E'},
{"all", required_argument, 0, 'A'},
{"send", required_argument, 0, 's'},
{"expect", required_argument, 0, 'e'},
{"maxbytes", required_argument, 0, 'm'},
@ -445,7 +439,7 @@ process_arguments (int argc, char **argv)
}
while (1) {
c = getopt_long (argc, argv, "+hVv46EH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
c = getopt_long (argc, argv, "+hVv46EAH:s:e:q:m:c:w:t:p:C:W:d:Sr:jD:M:",
longopts, &option);
if (c == -1 || c == EOF || c == 1)
@ -517,7 +511,6 @@ process_arguments (int argc, char **argv)
asprintf(&server_send, "%s", optarg);
break;
case 'e': /* expect string (may be repeated) */
EXPECT = NULL;
flags &= ~FLAG_EXACT_MATCH;
if (server_expect_count == 0)
server_expect = malloc (sizeof (char *) * (++server_expect_count));
@ -582,6 +575,9 @@ process_arguments (int argc, char **argv)
die (STATE_UNKNOWN, _("Invalid option - SSL is not available"));
#endif
break;
case 'A':
flags |= FLAG_MATCH_ALL;
break;
}
}
@ -619,10 +615,12 @@ print_help (void)
printf (" %s\n", "-s, --send=STRING");
printf (" %s\n", _("String to send to the server"));
printf (" %s\n", "-e, --expect=STRING");
printf (" %s\n", _("String to expect in server response"));
printf (" %s %s\n", _("String to expect in server response"), _("(may be repeated)"));
printf (" %s\n", "-A, --all");
printf (" %s\n", _("All expect strings need to occur in server response. Default is any"));
printf (" %s\n", "-q, --quit=STRING");
printf (" %s\n", _("String to send server to initiate a clean close of the connection"));
printf (" %s\n", "-r, --refuse=ok|warn|crit");
printf (" %s\n", "-r, --refuse=ok|warn|crit");
printf (" %s\n", _("Accept tcp refusals with states ok, warn, crit (default: crit)"));
printf (" %s\n", "-M, --mismatch=ok|warn|crit");
printf (" %s\n", _("Accept expected string mismatches with states ok, warn, crit (default: warn)"));

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:40 $
* Last Modified: $Date: 2007-05-02 06:22:31 +0100 (Wed, 02 May 2007) $
*
* Description:
*
@ -30,12 +30,12 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* $Id: check_time.c,v 1.29 2007/01/28 21:46:40 hweiss Exp $
* $Id: check_time.c 1703 2007-05-02 05:22:31Z dermoth $
*
******************************************************************************/
const char *progname = "check_time";
const char *revision = "$Revision: 1.29 $";
const char *revision = "$Revision: 1703 $";
const char *copyright = "1999-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -49,8 +49,8 @@ enum {
#define UNIX_EPOCH 2208988800UL
uint32_t server_time, raw_server_time;
time_t diff_time;
uint32_t raw_server_time;
unsigned long server_time, diff_time;
int warning_time = 0;
int check_warning_time = FALSE;
int critical_time = 0;
@ -166,9 +166,9 @@ main (int argc, char **argv)
else
diff_time = (unsigned long)end_time - server_time;
if (check_critical_diff == TRUE && diff_time > (time_t)critical_diff)
if (check_critical_diff == TRUE && diff_time > critical_diff)
result = STATE_CRITICAL;
else if (check_warning_diff == TRUE && diff_time > (time_t)warning_diff)
else if (check_warning_diff == TRUE && diff_time > warning_diff)
result = STATE_WARNING;
printf (_("TIME %s - %lu second time difference|%s %s\n"),
@ -177,9 +177,9 @@ main (int argc, char **argv)
check_warning_time, (long)warning_time,
check_critical_time, (long)critical_time,
TRUE, 0, FALSE, 0),
perfdata ("offset", (long)diff_time, "s",
check_warning_diff, (long)warning_diff,
check_critical_diff, (long)critical_diff,
perfdata ("offset", diff_time, "s",
check_warning_diff, warning_diff,
check_critical_diff, critical_diff,
TRUE, 0, FALSE, 0));
return result;
}

View file

@ -8,7 +8,7 @@
* 2004 Arnaud Quette <arnaud.quette@mgeups.com>
* Copyright (c) 2002-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:41 $
* Last Modified: $Date: 2007-05-09 10:16:33 +0100 (Wed, 09 May 2007) $
*
* Description:
*
@ -33,12 +33,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_ups.c,v 1.31 2007/01/28 21:46:41 hweiss Exp $
* $Id: check_ups.c 1709 2007-05-09 09:16:33Z psychotrahe $
*
******************************************************************************/
const char *progname = "check_ups";
const char *revision = "$Revision: 1.31 $";
const char *revision = "$Revision: 1709 $";
const char *copyright = "2002-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
@ -618,12 +618,16 @@ print_help (void)
printf (" %s\n", _("Name of UPS"));
printf (" %s\n", "-T, --temperature");
printf (" %s\n", _("Output of temperatures in Celsius"));
printf (" %s\n", "-v, --variable=STRING");
printf (" %s %s\n", _("Valid values for STRING are"), "LINE, TEMP, BATTPCT or LOADPCT");
printf (_(UT_WARN_CRIT));
printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
printf (_(UT_VERBOSE));
/* TODO: -v clashing with -v/-variable. Commenting out help text since verbose
is unused up to now */
/* printf (_(UT_VERBOSE)); */
printf ("\n");
printf ("%s\n", _("Notes:"));

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 2000-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:41 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -30,12 +30,12 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: check_users.c,v 1.22 2007/01/28 21:46:41 hweiss Exp $
* $Id: check_users.c 1590 2007-01-28 21:46:41Z hweiss $
*
*****************************************************************************/
const char *progname = "check_users";
const char *revision = "$Revision: 1.22 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -28,7 +28,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: common.h,v 1.28 2007/03/22 17:54:16 hweiss Exp $
* $Id: common.h 1700 2007-04-25 22:10:13Z tonvoon $
*
*****************************************************************************/
@ -80,6 +80,18 @@
#include <unistd.h>
#endif
/* GET_NUMBER_OF_CPUS is a macro to return
number of CPUs, if we can get that data.
Use configure.in to test for various OS ways of
getting that data
Will return -1 if cannot get data
*/
#ifdef HAVE_SYSCONF__SC_NPROCESSORS_CONF
#define GET_NUMBER_OF_CPUS() sysconf(_SC_NPROCESSORS_CONF)
#else
#define GET_NUMBER_OF_CPUS() -1
#endif
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>

View file

@ -3,9 +3,9 @@
* Nagios negate plugin
*
* License: GPL
* Copyright (c) 2002-2006 nagios-plugins team
* Copyright (c) 2002-2007 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:41 $
* Last Modified: $Date: 2007-09-23 13:29:36 +0100 (Sun, 23 Sep 2007) $
*
* Description:
*
@ -29,7 +29,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: negate.c,v 1.27 2007/01/28 21:46:41 hweiss Exp $
* $Id: negate.c 1793 2007-09-23 12:29:36Z psychotrahe $
@@-<article>
@ -69,37 +69,44 @@
******************************************************************************/
const char *progname = "negate";
const char *revision = "$Revision: 1.27 $";
const char *copyright = "2002-2006";
const char *revision = "$Revision: 1793 $";
const char *copyright = "2002-2007";
const char *email = "nagiosplug-devel@lists.sourceforge.net";
#define DEFAULT_TIMEOUT 9
#include "common.h"
#include "utils.h"
#include "popen.h"
#include "utils_cmd.h"
char *command_line;
/* char *command_line; */
int process_arguments (int, char **);
int validate_arguments (void);
static const char **process_arguments (int, char **);
int validate_arguments (char **);
void print_help (void);
void print_usage (void);
static int state[4] = {
STATE_OK,
STATE_WARNING,
STATE_CRITICAL,
STATE_UNKNOWN,
};
int
main (int argc, char **argv)
{
int found = 0, result = STATE_UNKNOWN;
char *buf;
char **command_line;
output chld_out, chld_err;
int i;
setlocale (LC_ALL, "");
bindtextdomain (PACKAGE, LOCALEDIR);
textdomain (PACKAGE);
if (process_arguments (argc, argv) == ERROR)
usage4 (_("Could not parse arguments"));
command_line = (char **) process_arguments (argc, argv);
/* Set signal handling and alarm */
if (signal (SIGALRM, timeout_alarm_handler) == SIG_ERR)
@ -107,43 +114,32 @@ main (int argc, char **argv)
(void) alarm ((unsigned) timeout_interval);
child_process = spopen (command_line);
if (child_process == NULL)
die (STATE_UNKNOWN, _("Could not open pipe: %s\n"), command_line);
child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r");
if (child_stderr == NULL) {
printf (_("Could not open stderr for %s\n"), command_line);
/* catch when the command is quoted */
if(command_line[1] == NULL) {
result = cmd_run (command_line[0], &chld_out, &chld_err, 0);
} else {
result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
}
if (chld_err.lines > 0) {
printf ("Error output from command:\n");
for (i = 0; i < chld_err.lines; i++) {
printf ("%s\n", chld_err.line[i]);
}
exit (STATE_WARNING);
}
buf = malloc(MAX_INPUT_BUFFER);
while (fgets (buf, MAX_INPUT_BUFFER - 1, child_process)) {
found++;
printf ("%s", buf);
if (chld_out.lines == 0)
die (STATE_UNKNOWN, _("No data returned from command\n"));
for (i = 0; i < chld_out.lines; i++) {
printf ("%s\n", chld_out.line[i]);
}
if (!found)
die (STATE_UNKNOWN,
_("%s problem - No data received from host\nCMD: %s\n"),\
argv[0], command_line);
/* close the pipe */
result = spclose (child_process);
/* WARNING if output found on stderr */
if (fgets (buf, MAX_INPUT_BUFFER - 1, child_stderr))
result = max_state (result, STATE_WARNING);
/* close stderr */
(void) fclose (child_stderr);
if (result == STATE_OK)
exit (STATE_CRITICAL);
else if (result == STATE_CRITICAL)
exit (EXIT_SUCCESS);
else
if (result >= 0 && result <= 4) {
exit (state[result]);
} else {
exit (result);
}
}
/******************************************************************************
@ -167,22 +163,26 @@ is a only a 'timeout' option.</para>
/* process command-line arguments */
int
static const char **
process_arguments (int argc, char **argv)
{
int c;
int permute = TRUE;
int option = 0;
static struct option longopts[] = {
{"help", no_argument, 0, 'h'},
{"version", no_argument, 0, 'V'},
{"timeout", required_argument, 0, 't'},
{"ok", required_argument, 0, 'o'},
{"warning", required_argument, 0, 'w'},
{"critical", required_argument, 0, 'c'},
{"unknown", required_argument, 0, 'u'},
{0, 0, 0, 0}
};
while (1) {
c = getopt_long (argc, argv, "+hVt:",
longopts, &option);
c = getopt_long (argc, argv, "+hVt:o:w:c:u:", longopts, &option);
if (c == -1 || c == EOF)
break;
@ -204,15 +204,38 @@ process_arguments (int argc, char **argv)
else
timeout_interval = atoi (optarg);
break;
case 'o': /* replacement for OK */
if ((state[STATE_OK] = translate_state(optarg)) == ERROR)
usage4 (_("Ok must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-4)."));
permute = FALSE;
break;
case 'w': /* replacement for WARNING */
if ((state[STATE_WARNING] = translate_state(optarg)) == ERROR)
usage4 (_("Warning must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
permute = FALSE;
break;
case 'c': /* replacement for CRITICAL */
if ((state[STATE_CRITICAL] = translate_state(optarg)) == ERROR)
usage4 (_("Critical must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
permute = FALSE;
break;
case 'u': /* replacement for UNKNOWN */
if ((state[STATE_UNKNOWN] = translate_state(optarg)) == ERROR)
usage4 (_("Unknown must be a valid state name (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)."));
permute = FALSE;
break;
}
}
asprintf (&command_line, "%s", argv[optind]);
for (c = optind+1; c < argc; c++) {
asprintf (&command_line, "%s %s", command_line, argv[c]);
validate_arguments (&argv[optind]);
if (permute) { /* No [owcu] switch specified, default to this */
state[STATE_OK] = STATE_CRITICAL;
state[STATE_CRITICAL] = STATE_OK;
}
return validate_arguments ();
return (const char **) &argv[optind];
}
@ -230,11 +253,13 @@ process_arguments (int argc, char **argv)
int
validate_arguments ()
validate_arguments (char **command_line)
{
if (command_line == NULL)
return ERROR;
return STATE_OK;
if (command_line[0] == NULL)
usage4 (_("Could not parse arguments"));
if (strncmp(command_line[0],"/",1) != 0 && strncmp(command_line[0],"./",2) != 0)
usage4 (_("Require path to command"));
}
/******************************************************************************
@ -245,7 +270,23 @@ validate_arguments ()
-@@
******************************************************************************/
int
translate_state (char *state_text)
{
char *temp_ptr;
for (temp_ptr = state_text; *temp_ptr; temp_ptr++) {
*temp_ptr = toupper(*temp_ptr);
}
if (!strcmp(state_text,"OK") || !strcmp(state_text,"0"))
return STATE_OK;
if (!strcmp(state_text,"WARNING") || !strcmp(state_text,"1"))
return STATE_WARNING;
if (!strcmp(state_text,"CRITICAL") || !strcmp(state_text,"2"))
return STATE_CRITICAL;
if (!strcmp(state_text,"UNKNOWN") || !strcmp(state_text,"3"))
return STATE_UNKNOWN;
return ERROR;
}
void
print_help (void)
@ -254,30 +295,39 @@ print_help (void)
printf (COPYRIGHT, copyright, email);
printf ("%s\n", _("Negates the status of a plugin (returns OK for CRITICAL, and vice-versa)."));
printf ("%s\n", _("Negates the status of a plugin (returns OK for CRITICAL and vice-versa)."));
printf ("%s\n", _("Additional switches can be used to control which state becomes what."));
printf ("\n\n");
printf ("\n\n");
print_usage ();
printf (_(UT_HELP_VRSN));
printf (_(UT_TIMEOUT), DEFAULT_TIMEOUT);
printf (" %s\n", _("Keep timeout lower than the plugin timeout to retain CRITICAL status."));
printf (" %s\n", _("[keep timeout than the plugin timeout to retain CRITICAL status]"));
printf ("\n");
printf ("%s\n", _("Examples:"));
printf (" %s\n", "negate \"/usr/local/nagios/libexec/check_ping -H host\"");
printf (" %s\n", _("Run check_ping and invert result. Must use full path to plugin"));
printf (" %s\n", "negate \"/usr/local/nagios/libexec/check_procs -a 'vi negate.c'\"");
printf (" %s\n", _("Use single quotes if you need to retain spaces"));
printf (_(UT_VERBOSE));
printf ("\n");
printf ("%s\n", _("Notes:"));
printf(" -o,--ok=STATUS\n");
printf(" -w,--warning=STATUS\n");
printf(" -c,--critical=STATUS\n");
printf(" -u,--unknown=STATUS\n");
printf(_(" STATUS can be 'OK', 'WARNING', 'CRITICAL' or 'UNKNOWN' without single\n"));
printf(_(" quotes. Numeric values are accepted. If nothing is specified, permutes\n"));
printf(_(" OK and CRITICAL.\n"));
printf ("\n");
printf ("%s\n", _("Examples:"));
printf (" %s\n", "negate /usr/local/nagios/libexec/check_ping -H host");
printf (" %s\n", _("Run check_ping and invert result. Must use full path to plugin"));
printf (" %s\n", "negate -w OK -c UNKNOWN /usr/local/nagios/libexec/check_procs -a 'vi negate.c'");
printf (" %s\n", _("This will return OK instead of WARNING and UNKNOWN instead of CRITICAL"));
printf ("\n");
printf ("%s\n", _("Notes:"));
printf ("%s\n", _("This plugin is a wrapper to take the output of another plugin and invert it."));
printf ("%s\n", _("If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL."));
printf ("%s\n", _("If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK."));
printf ("%s\n", _("Otherwise, the output state of the wrapped plugin is unchanged."));
printf ("%s\n", _("The full path of the plugin must be provided."));
printf ("%s\n", _("If the wrapped plugin returns STATE_OK, the wrapper will return STATE_CRITICAL."));
printf ("%s\n", _("If the wrapped plugin returns STATE_CRITICAL, the wrapper will return STATE_OK."));
printf ("%s\n", _("Otherwise, the output state of the wrapped plugin is unchanged."));
printf (_(UT_SUPPORT));
}
@ -287,6 +337,6 @@ print_help (void)
void
print_usage (void)
{
printf (_("Usage:"));
printf ("%s [-t timeout] <definition of wrapped plugin>\n",progname);
printf (_("Usage:"));
printf ("%s [-t timeout] [-owcu STATE] <definition of wrapped plugin>\n", progname);
}

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
*
* Last Modified: $Date: 2007/01/20 06:07:48 $
* Last Modified: $Date: 2007-09-24 01:30:14 +0100 (Mon, 24 Sep 2007) $
*
* Description:
*
@ -27,7 +27,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: netutils.c,v 1.33 2007/01/20 06:07:48 dermoth Exp $
* $Id: netutils.c 1794 2007-09-24 00:30:14Z hweiss $
*
****************************************************************************/
@ -39,7 +39,11 @@
unsigned int socket_timeout = DEFAULT_SOCKET_TIMEOUT;
int econn_refuse_state = STATE_CRITICAL;
int was_refused = FALSE;
#if USE_IPV6
int address_family = AF_UNSPEC;
#else
int address_family = AF_INET;
#endif
/* handles socket timeouts */
void

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)
*
* Last Modified: $Date: 2007/01/24 22:47:25 $
* Last Modified: $Date: 2007-01-24 22:47:25 +0000 (Wed, 24 Jan 2007) $
*
* Description:
*
@ -28,7 +28,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: netutils.h,v 1.18 2007/01/24 22:47:25 tonvoon Exp $
* $Id: netutils.h 1580 2007-01-24 22:47:25Z tonvoon $
*
******************************************************************************/

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 2005 nagios-plugins team
*
* Last Modified: $Date: 2006/06/18 19:36:48 $
* Last Modified: $Date: 2007-06-12 08:13:02 +0100 (Tue, 12 Jun 2007) $
*
* Description:
*
@ -40,7 +40,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: popen.c,v 1.15 2006/06/18 19:36:48 opensides Exp $
* $Id: popen.c 1737 2007-06-12 07:13:02Z psychotrahe $
*
******************************************************************************/
@ -104,7 +104,7 @@ spopen (const char *cmdstring)
char *env[2];
char *cmd = NULL;
char **argv = NULL;
char *str;
char *str, *tmp;
int argc;
int i = 0, pfd[2], pfderr[2];
@ -166,7 +166,15 @@ spopen (const char *cmdstring)
cmd = 1 + strstr (str, "'");
str[strcspn (str, "'")] = 0;
}
else {
else if (strcspn(str,"'") < strcspn (str, " \t\r\n")) {
/* handle --option='foo bar' strings */
tmp = str + strcspn(str, "'") + 1;
if (!strstr (tmp, "'"))
return NULL; /* balanced? */
tmp += strcspn(tmp,"'") + 1;
*tmp = 0;
cmd = tmp + 1;
} else {
if (strpbrk (str, " \t\r\n")) {
cmd = 1 + strpbrk (str, " \t\r\n");
str[strcspn (str, " \t\r\n")] = 0;

View file

@ -1,6 +1,6 @@
/******************************************************************************
*
* $Id: popen.h,v 1.4 2005/05/01 20:12:03 seanius Exp $
* $Id: popen.h 1169 2005-05-01 20:12:03Z seanius $
*
******************************************************************************/

View file

@ -4,7 +4,7 @@
* License: GPL
* Copyright (c) 2005 nagios-plugins team
*
* $Id: runcmd.c,v 1.4 2006/06/18 19:36:48 opensides Exp $
* $Id: runcmd.c 1434 2006-06-18 19:36:48Z opensides $
*
* Description :
*

View file

@ -1,5 +1,5 @@
/*
* $Id: runcmd.h,v 1.2 2005/10/24 11:10:29 seanius Exp $
* $Id: runcmd.h 1260 2005-10-24 11:10:29Z seanius $
*
* Author: Andreas Ericsson <ae@op5.se>
*

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 2005 nagios-plugins team
*
* Last Modified: $Date: 2006/06/18 19:36:48 $
* Last Modified: $Date: 2007-06-01 23:57:31 +0100 (Fri, 01 Jun 2007) $
*
* Description:
*
@ -27,7 +27,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: sslutils.c,v 1.3 2006/06/18 19:36:48 opensides Exp $
* $Id: sslutils.c 1726 2007-06-01 22:57:31Z hweiss $
*
****************************************************************************/
@ -38,15 +38,17 @@
#ifdef HAVE_SSL
static SSL_CTX *c=NULL;
static SSL *s=NULL;
static int initialized=0;
int np_net_ssl_init (int sd){
SSL_METHOD *m=NULL;
/* Initialize SSL context */
SSLeay_add_ssl_algorithms ();
m = SSLv23_client_method ();
SSL_load_error_strings ();
OpenSSL_add_all_algorithms();
if ((c = SSL_CTX_new (m)) == NULL) {
if (!initialized) {
/* Initialize SSL context */
SSLeay_add_ssl_algorithms ();
SSL_load_error_strings ();
OpenSSL_add_all_algorithms ();
initialized = 1;
}
if ((c = SSL_CTX_new (SSLv23_client_method ())) == NULL) {
printf ("%s\n", _("CRITICAL - Cannot create SSL context."));
return STATE_CRITICAL;
}
@ -70,7 +72,11 @@ void np_net_ssl_cleanup (){
if(s){
SSL_shutdown (s);
SSL_free (s);
if(c) SSL_CTX_free (c);
if(c) {
SSL_CTX_free (c);
c=NULL;
}
s=NULL;
}
}

View file

@ -1 +0,0 @@
*.tmp

83
plugins/t/check_cluster.t Normal file
View file

@ -0,0 +1,83 @@
#! /usr/bin/perl -w -I ..
#
# check_cluster tests
#
# $Id: check_cluster.t 1702 2007-04-28 21:57:17Z psychotrahe $
#
use strict;
use Test::More tests => 15;
use NPTest;
my $result;
$result = NPTest->testCmd(
"./check_cluster -s -w 0:0 -c 0:0 -d 0,0,0,0"
);
cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok services are inside critical and warning ranges" );
like( $result->output, qr/service/i, "Output contains the word 'service' (case insensitive)");
$result = NPTest->testCmd(
"./check_cluster -l LABEL -s -w 0:0 -c 0:0 -d 0,0,0,0"
);
like( $result->output, qr/LABEL/, "Output contains the defined label 'LABEL' (case sensitive)");
$result = NPTest->testCmd(
"./check_cluster -s -w 0:0 -c 0:1 -d 0,0,0,1"
);
cmp_ok( $result->return_code, '==', 1, "Exit WARNING if non-ok services are inside critical and outside warning ranges" );
$result = NPTest->testCmd(
"./check_cluster -s -w 0:0 -c 0:1 -d 0,0,1,1"
);
cmp_ok( $result->return_code, '==', 2, "Exit CRITICAL if non-ok services are inside critical and outside warning ranges" );
$result = NPTest->testCmd(
"./check_cluster -s -w 0 -c 0 -d 0,0,0,0"
);
cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok services are inside critical and warning (no ranges)" );
$result = NPTest->testCmd(
"./check_cluster -s -w 0 -c 1 -d 0,0,1,0"
);
cmp_ok( $result->return_code, '==', 1, "Exit WARNING if number of non-ok services exceed warning (no ranges)" );
$result = NPTest->testCmd(
"./check_cluster -s -w 0 -c 1 -d 0,0,1,1"
);
cmp_ok( $result->return_code, '==', 2, "Exit Critical if non-ok services exceed critical warning (no ranges)" );
#
# And for hosts..
#
$result = NPTest->testCmd(
"./check_cluster -h -w 0:0 -c 0:0 -d 0,0,0,0"
);
cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok hosts are inside critical and warning ranges" );
like( $result->output, qr/host/i, "Output contains the word 'host' (case insensitive)");
$result = NPTest->testCmd(
"./check_cluster -h -w 0:0 -c 0:1 -d 0,0,0,1"
);
cmp_ok( $result->return_code, '==', 1, "Exit WARNING if non-ok hosts are inside critical and outside warning ranges" );
$result = NPTest->testCmd(
"./check_cluster -h -w 0:0 -c 0:1 -d 0,0,1,1"
);
cmp_ok( $result->return_code, '==', 2, "Exit CRITICAL if non-ok hosts are inside critical and outside warning ranges" );
$result = NPTest->testCmd(
"./check_cluster -h -w 0 -c 0 -d 0,0,0,0"
);
cmp_ok( $result->return_code, '==', 0, "Exit OK if non-ok hosts are inside critical and warning (no ranges)" );
$result = NPTest->testCmd(
"./check_cluster -h -w 0 -c 1 -d 0,0,1,0"
);
cmp_ok( $result->return_code, '==', 1, "Exit WARNING if number of non-ok hosts exceed warning (no ranges)" );
$result = NPTest->testCmd(
"./check_cluster -h -w 0 -c 1 -d 0,0,1,1"
);
cmp_ok( $result->return_code, '==', 2, "Exit Critical if non-ok hosts exceed critical warning (no ranges)" );

View file

@ -2,7 +2,7 @@
#
# Disk Space Tests via check_disk
#
# $Id: check_disk.t,v 1.20 2007/03/30 09:00:06 psychotrahe Exp $
# $Id: check_disk.t 1786 2007-09-22 17:40:35Z psychotrahe $
#
# TODO: Add in tests for perf data. Need to beef up Nagios::Plugin::Performance to cater for max, min, etc
@ -24,7 +24,7 @@ my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to anoth
if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") {
plan skip_all => "Need 2 mountpoints to test";
} else {
plan tests => 68;
plan tests => 78;
}
$result = NPTest->testCmd(
@ -114,10 +114,8 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text");
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" );
cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free");
$_ = $result->output;
print $result->output."\n";
my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+) MB .* (\d+) MB /g);
my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2;
print "$free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2\n";
@ -255,6 +253,7 @@ cmp_ok( $result->return_code, "==", 2, "100 GB empty" );
# Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds
$result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} );
cmp_ok( $result->return_code, "==", 2, "Old syntax: 0% used");
like ( $result->only_output, qr(^[^;]*;[^;]*$), "Select only one path with positional arguments");
$result = NPTest->testCmd( "./check_disk 100 100 $mountpoint_valid" );
cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" );
@ -276,7 +275,7 @@ TODO: {
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /bob" );
cmp_ok( $result->return_code, '==', 2, "Checking /bob - return error because /bob does not exist" );
cmp_ok( $result->output, 'eq', 'DISK CRITICAL - /bob does not exist', 'Output OK');
like( $result->output, '/^DISK CRITICAL - /bob is not accessible:.*$/', 'Output OK');
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /" );
my $root_output = $result->output;
@ -285,9 +284,15 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc" );
cmp_ok( $result->return_code, '==', 0, "Checking /etc - should return info for /" );
cmp_ok( $result->output, 'eq', $root_output, "check_disk /etc gives same as check_disk /");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc -E" );
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -E -p /etc " );
cmp_ok( $result->return_code, '==', 2, "... unless -E/--exact-match is specified");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p /etc -E " );
cmp_ok( $result->return_code, '==', 3, "-E/--exact-match must be specified before -p");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -r /etc -E " );
cmp_ok( $result->return_code, '==', 3, "-E/--exact-match must be specified before -r");
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /bob" );
cmp_ok( $result->return_code, '==', 2, "Checking / and /bob gives critical");
unlike( $result->perf_output, '/\/bob/', "perf data does not have /bob in it");
@ -319,3 +324,24 @@ cmp_ok( $result->return_code, '==', 3, "Invalid options: -p must come after grou
$result = NPTest->testCmd( "./check_disk -w 1 -c 1 -r '('" );
cmp_ok( $result->return_code, '==', 3, "Exit UNKNOWN if regex is not compileable");
# ignore: exit unknown, if all pathes are deselected using -i
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '$mountpoint_valid' -i '$mountpoint2_valid'" );
cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case sensitive)");
# ignore: exit unknown, if all pathes are deselected using -I
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -I '".uc($mountpoint_valid)."' -I '".uc($mountpoint2_valid)."'" );
cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored (case insensitive)");
# ignore: exit unknown, if all pathes are deselected using -i
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '.*'" );
cmp_ok( $result->return_code, '==', 3, "ignore-ereg: Unknown if all fs are ignored using -i '.*'");
# ignore: test if ignored path is actually ignored
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^$mountpoint2_valid\$'");
like( $result->output, qr/$mountpoint_valid/, "output data does have $mountpoint_valid in it");
unlike( $result->output, qr/$mountpoint2_valid/, "output data does not have $mountpoint2_valid in it");
# ignore: test if all pathes are listed when ignore regex doesn't match
$result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p $mountpoint_valid -p $mountpoint2_valid -i '^barbazJodsf\$'");
like( $result->output, qr/$mountpoint_valid/, "ignore: output data does have $mountpoint_valid when regex doesn't match");
like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mountpoint2_valid when regex doesn't match");

View file

@ -2,7 +2,7 @@
#
# Domain Name Server (DNS) Tests via check_dns
#
# $Id: check_dns.t,v 1.7 2006/03/29 08:13:29 tonvoon Exp $
# $Id: check_dns.t 1361 2006-03-29 08:13:29Z tonvoon $
#
use strict;

55
plugins/t/check_dummy.t Normal file
View file

@ -0,0 +1,55 @@
#! /usr/bin/perl -w -I ..
#
# check_dummy tests
#
# $Id: check_dummy.t 1716 2007-05-24 08:35:53Z tonvoon $
#
use strict;
use Test::More;
use NPTest;
plan tests => 20;
my $res;
$res = NPTest->testCmd("./check_dummy");
is( $res->return_code, 3, "No args" );
like( $res->output, "/Could not parse arguments/", "Correct usage message");
$res = NPTest->testCmd("./check_dummy 0");
is( $res->return_code, 0, "OK state returned");
is( $res->output, "OK", "Says 'OK'");
$res = NPTest->testCmd("./check_dummy 0 'some random data'");
is( $res->return_code, 0, "Still OK");
is( $res->output, "OK: some random data", "Sample text okay");
$res = NPTest->testCmd("./check_dummy 1");
is( $res->return_code, 1, "Warning okay");
is( $res->output, "WARNING", "Says 'WARNING'");
$res = NPTest->testCmd("./check_dummy 1 'more stuff'");
is( $res->return_code, 1, "Still warning");
is( $res->output, "WARNING: more stuff", "optional text okay" );
$res = NPTest->testCmd("./check_dummy 2");
is( $res->return_code, 2, "Critical ok" );
is( $res->output, "CRITICAL", "Says 'CRITICAL'");
$res = NPTest->testCmd("./check_dummy 2 'roughly drafted'");
is( $res->return_code, 2, "Still critical");
is( $res->output, "CRITICAL: roughly drafted", "optional text okay" );
$res = NPTest->testCmd("./check_dummy 3");
is( $res->return_code, 3, "Unknown ok" );
is( $res->output, "UNKNOWN", "Says 'UNKNOWN'");
$res = NPTest->testCmd("./check_dummy 3 'daringfireball'");
is( $res->return_code, 3, "Still unknown");
is( $res->output, "UNKNOWN: daringfireball", "optional text okay" );
$res = NPTest->testCmd("./check_dummy 4");
is( $res->return_code, 3, "Invalid error code" );
is( $res->output, "UNKNOWN: Status 4 is not a supported error state", "With appropriate error message");

View file

@ -2,7 +2,7 @@
#
# FPing Tests via check_fping
#
# $Id: check_fping.t,v 1.2 2005/07/25 01:47:14 illumino Exp $
# $Id: check_fping.t 1207 2005-07-25 01:47:15Z illumino $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# File Transfer Protocol (FTP) Test via check_ftp
#
# $Id: check_ftp.t,v 1.3 2005/07/25 01:47:14 illumino Exp $
# $Id: check_ftp.t 1207 2005-07-25 01:47:15Z illumino $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# HP JetDirect Test via check_hpjd
#
# $Id: check_hpjd.t,v 1.3 2006/03/24 16:13:40 tonvoon Exp $
# $Id: check_hpjd.t 1354 2006-03-24 16:13:40Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# HyperText Transfer Protocol (HTTP) Test via check_http
#
# $Id: check_http.t,v 1.14 2007/04/01 14:21:09 psychotrahe Exp $
# $Id: check_http.t 1669 2007-04-01 14:21:09Z psychotrahe $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Internet Mail Access Protocol (IMAP) Server Tests via check_imap
#
# $Id: check_imap.t,v 1.4 2005/11/09 16:40:12 tonvoon Exp $
# $Id: check_imap.t 1279 2005-11-09 16:40:12Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Jabber Server Tests via check_jabber
#
# $Id: check_jabber.t,v 1.3 2007/02/01 06:53:12 dermoth Exp $
# $Id: check_jabber.t 1604 2007-02-01 06:53:12Z dermoth $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Load Average Tests via check_load
#
# $Id: check_load.t,v 1.6 2006/10/02 12:09:18 tonvoon Exp $
# $Id: check_load.t 1700 2007-04-25 22:10:13Z tonvoon $
#
use strict;
@ -14,7 +14,7 @@ my $res;
my $successOutput = '/^OK - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/';
my $failureOutput = '/^CRITICAL - load average: [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+, [0-9]+\.?[0-9]+/';
plan tests => 4;
plan tests => 6;
$res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" );
cmp_ok( $res->return_code, 'eq', 0, "load not over 100");
@ -24,3 +24,7 @@ $res = NPTest->testCmd( "./check_load -w 0,0,0 -c 0,0,0" );
cmp_ok( $res->return_code, 'eq', 2, "Load over 0");
like( $res->output, $failureOutput, "Output OK");
$res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" );
cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division");
like( $res->output, $failureOutput, "Output OK");

View file

@ -2,7 +2,7 @@
#
# MySQL Database Server Tests via check_mysql
#
# $Id: check_mysql.t,v 1.8 2006/03/17 14:07:34 tonvoon Exp $
# $Id: check_mysql.t 1327 2006-03-17 14:07:34Z tonvoon $
#
#
# These are the database permissions required for this test:

View file

@ -2,7 +2,7 @@
#
# MySQL Database Server Tests via check_mysql
#
# $Id: check_mysql_query.t,v 1.2 2006/02/01 13:23:38 tonvoon Exp $
# $Id: check_mysql_query.t 1315 2006-02-01 13:23:38Z tonvoon $
#
#
# These are the database permissions required for this test:

View file

@ -2,7 +2,7 @@
#
# check_nagios tests
#
# $Id: check_nagios.t,v 1.2 2006/04/19 09:33:44 tonvoon Exp $
# $Id: check_nagios.t 1382 2006-04-19 09:33:44Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Testing NTP
#
# $Id: check_ntp.t,v 1.2 2006/08/14 08:42:23 tonvoon Exp $
# $Id: check_ntp.t 1468 2006-08-14 08:42:23Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Ping Response Tests via check_ping
#
# $Id: check_ping.t,v 1.5 2007/03/12 10:51:06 tonvoon Exp $
# $Id: check_ping.t 1639 2007-03-12 10:51:06Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Post Office Protocol (POP) Server Tests via check_pop
#
# $Id: check_pop.t,v 1.3 2006/03/22 15:45:49 tonvoon Exp $
# $Id: check_pop.t 1345 2006-03-22 15:45:49Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Process Tests via check_procs
#
# $Id: check_procs.t,v 1.5 2005/11/03 15:13:13 tonvoon Exp $
# $Id: check_procs.t 1271 2005-11-03 15:13:13Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Simple Mail Transfer Protocol (SMTP) Test via check_smtp
#
# $Id: check_smtp.t,v 1.4 2006/10/19 11:56:34 tonvoon Exp $
# $Id: check_smtp.t 1500 2006-10-19 11:56:34Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Simple Network Management Protocol (SNMP) Test via check_snmp
#
# $Id: check_snmp.t,v 1.3 2006/12/23 18:59:36 dermoth Exp $
# $Id: check_snmp.t 1557 2006-12-23 18:59:36Z dermoth $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Swap Space Tests via check_swap
#
# $Id: check_swap.t,v 1.3 2005/11/09 16:40:12 tonvoon Exp $
# $Id: check_swap.t 1279 2005-11-09 16:40:12Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# TCP Connection Based Tests via check_tcp
#
# $Id: check_tcp.t,v 1.5 2007/02/14 10:11:07 tonvoon Exp $
# $Id: check_tcp.t 1714 2007-05-18 07:17:59Z dermoth $
#
use strict;
@ -34,7 +34,7 @@ $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2
# Need the \r\n to make it more standards compliant with web servers. Need the various quotes
# so that perl doesn't interpret the \r\n and is passed onto command line correctly
$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -E -s ".'"GET /\r\n\r\n"'." -e 'ThisShouldntMatch' -j", 1, $failedExpect );
$t += checkCmd( "./check_tcp $host_tcp_http -p 80 -E -s ".'"GET / HTTP/1.1\r\n\r\n"'." -e 'ThisShouldntMatch' -j", 1, $failedExpect );
exit(0) if defined($Test::Harness::VERSION);
exit($tests - $t);

View file

@ -2,7 +2,7 @@
#
# System Time Tests via check_time
#
# $Id: check_time.t,v 1.3 2005/11/03 15:04:16 tonvoon Exp $
# $Id: check_time.t 1270 2005-11-03 15:04:16Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# UDP Connection Based Tests via check_udp
#
# $Id: check_udp.t,v 1.6 2006/07/28 22:44:11 tonvoon Exp $
# $Id: check_udp.t 1459 2006-07-28 22:44:11Z tonvoon $
#
use strict;

View file

@ -2,7 +2,7 @@
#
# Logged in Users Tests via check_users
#
# $Id: check_users.t,v 1.2 2005/07/25 01:47:15 illumino Exp $
# $Id: check_users.t 1207 2005-07-25 01:47:15Z illumino $
#
use strict;

72
plugins/t/negate.t Normal file
View file

@ -0,0 +1,72 @@
#! /usr/bin/perl -w -I ..
#
# negate checks
# Need check_dummy to work for testing
#
# $Id: negate.pl 1717 2007-05-24 08:53:50Z tonvoon $
#
use strict;
use Test::More;
use NPTest;
# 15 tests in the first part and 32 in the last loop
plan tests => 47;
my $res;
my $PWD = $ENV{PWD};
$res = NPTest->testCmd( "./negate" );
is( $res->return_code, 3, "Not enough parameters");
like( $res->output, "/Could not parse arguments/", "Could not parse arguments");
$res = NPTest->testCmd( "./negate bobthebuilder" );
is( $res->return_code, 3, "Require full path" );
like( $res->output, "/Require path to command/", "Appropriate error message");
$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" );
is( $res->return_code, 2, "OK changed to CRITICAL" );
is( $res->output, "OK: a dummy okay", "Output as expected" );
$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0 redsweaterblog'");
is( $res->return_code, 2, "OK => CRIT with a single quote for command to run" );
is( $res->output, "OK: redsweaterblog", "Output as expected" );
$res = NPTest->testCmd( "./negate $PWD/check_dummy 1 'a warn a day keeps the managers at bay'" );
is( $res->return_code, 1, "WARN stays same" );
$res = NPTest->testCmd( "./negate $PWD/check_dummy 3 mysterious");
is( $res->return_code, 3, "UNKNOWN stays same" );
$res = NPTest->testCmd( "./negate \"$PWD/check_dummy 0 'a dummy okay'\"" );
is( $res->output, "OK: a dummy okay", "Checking slashed quotes - the single quotes are re-evaluated at shell" );
# Output is "OK: a" because check_dummy only returns the first arg
$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 a dummy okay" );
is( $res->output, "OK: a", "Multiple args passed as arrays" );
$res = NPTest->testCmd( "./negate $PWD/check_dummy 0 'a dummy okay'" );
is( $res->output, "OK: a dummy okay", "The quoted string is passed through to subcommand correctly" );
$res = NPTest->testCmd( "./negate '$PWD/check_dummy 0' 'a dummy okay'" );
is( $res->output, "No data returned from command", "Bad command, as expected (trying to execute './check_dummy 0')");
$res = NPTest->testCmd( './negate $PWD/check_dummy 0 \'$$ a dummy okay\'' );
is( $res->output, 'OK: $$ a dummy okay', 'Proves that $$ is not being expanded again' );
my %state = (
ok => 0,
warning => 1,
critical => 2,
unknown => 3,
);
foreach my $current_state (qw(ok warning critical unknown)) {
foreach my $new_state (qw(ok warning critical unknown)) {
$res = NPTest->testCmd( "./negate --$current_state=$new_state ./check_dummy ".$state{$current_state}." 'Fake $new_state'" );
is( $res->return_code, $state{$new_state}, "Got fake $new_state" );
is( $res->output, uc($current_state).": Fake $new_state" );
}
}

View file

@ -5,7 +5,7 @@
* License: GPL
* Copyright (c) 2000-2006 nagios-plugins team
*
* Last Modified: $Date: 2007/01/28 21:46:41 $
* Last Modified: $Date: 2007-01-28 21:46:41 +0000 (Sun, 28 Jan 2007) $
*
* Description:
*
@ -32,12 +32,12 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
$Id: urlize.c,v 1.22 2007/01/28 21:46:41 hweiss Exp $
$Id: urlize.c 1590 2007-01-28 21:46:41Z hweiss $
******************************************************************************/
const char *progname = "urlize";
const char *revision = "$Revision: 1.22 $";
const char *revision = "$Revision: 1590 $";
const char *copyright = "2000-2006";
const char *email = "nagiosplug-devel@lists.sourceforge.net";

View file

@ -8,8 +8,8 @@
* Copyright (c) 2006 Nagios Plugin Development Team
* License: GPL
*
* $Revision: 1.51 $
* $Date: 2007/01/28 21:46:41 $
* $Revision: 1752 $
* $Date: 2007-07-07 13:02:45 +0100 (Sat, 07 Jul 2007) $
****************************************************************************/
#define LOCAL_TIMEOUT_ALARM_HANDLER
@ -105,10 +105,11 @@ char *
clean_revstring (const char *revstring)
{
char plugin_revision[STRLEN];
if (sscanf (revstring,"$Revision: %[0-9.]",plugin_revision) == 1)
plugin_revision[0] = 'v';
if (sscanf (revstring,"$Revision: %[0-9.]", plugin_revision + 1) == 1)
return strscpy (NULL, plugin_revision);
else
return strscpy (NULL, "N/A");
return strscpy (NULL, "N/A");
}
void
@ -116,10 +117,8 @@ print_revision (const char *command_name, const char *revision_string)
{
char plugin_revision[STRLEN];
if (sscanf (revision_string, "$Revision: %[0-9.]", plugin_revision) != 1)
strncpy (plugin_revision, "N/A", STRLEN);
printf ("%s (%s %s) %s\n",
command_name, PACKAGE, VERSION, plugin_revision);
printf ("%s %s (%s %s)\n",
command_name, clean_revstring(revision_string), PACKAGE, VERSION);
}
const char *

View file

@ -18,7 +18,7 @@ suite of plugins. */
/* Standardize version information, termination */
/* $Id: utils.h,v 1.33 2007/01/28 21:46:41 hweiss Exp $ */
/* $Id: utils.h 1590 2007-01-28 21:46:41Z hweiss $ */
void support (void);
char *clean_revstring (const char *);