diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2006-07-13 12:50:23 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2006-07-13 12:50:23 +0000 |
commit | 548083b2ea865474915fc8a9ddd361e997585a02 (patch) | |
tree | f3766c1f5d8f8ea1b2b721a5792e4fb4daf1cf68 /plugins | |
parent | 6b9cc76d0a27631fbab19a31ab8bd46e143b7580 (diff) | |
download | monitoring-plugins-548083b2ea865474915fc8a9ddd361e997585a02.tar.gz |
Move new util_* functions to lib/
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1451 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Makefile.am | 7 | ||||
-rw-r--r-- | plugins/check_disk.c | 36 | ||||
-rw-r--r-- | plugins/check_dns.c | 1 | ||||
-rw-r--r-- | plugins/check_mysql.c | 1 | ||||
-rw-r--r-- | plugins/check_mysql_query.c | 1 | ||||
-rw-r--r-- | plugins/tests/.cvsignore | 5 | ||||
-rw-r--r-- | plugins/tests/Makefile.am | 28 | ||||
-rw-r--r-- | plugins/tests/README | 5 | ||||
-rw-r--r-- | plugins/tests/test_disk.c | 124 | ||||
-rwxr-xr-x | plugins/tests/test_disk.t | 6 | ||||
-rw-r--r-- | plugins/tests/test_utils.c | 176 | ||||
-rwxr-xr-x | plugins/tests/test_utils.t | 6 | ||||
-rw-r--r-- | plugins/utils.c | 191 | ||||
-rw-r--r-- | plugins/utils.h | 25 | ||||
-rw-r--r-- | plugins/utils_disk.c | 141 | ||||
-rw-r--r-- | plugins/utils_disk.h | 30 |
16 files changed, 25 insertions, 758 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 28793cdc..9dd71845 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,7 +1,5 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS = tests - VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/intl @LDAPINCLUDE@ @PGINCLUDE@ @SSLINCLUDE@ @@ -45,7 +43,6 @@ TESTS_ENVIRONMENT = perl -I $(top_builddir) -I $(top_srcdir) TESTS = @PLUGIN_TEST@ test: - cd tests && make test perl -I $(top_builddir) -I $(top_srcdir) ../test.pl AM_INSTALL_PROGRAM_FLAGS = @INSTALL_OPTS@ @@ -55,7 +52,7 @@ AM_INSTALL_PROGRAM_FLAGS = @INSTALL_OPTS@ check_apt_LDADD = $(BASEOBJS) runcmd.o check_dig_LDADD = $(NETLIBS) runcmd.o -check_disk_LDADD = $(BASEOBJS) popen.o utils_disk.o +check_disk_LDADD = $(BASEOBJS) popen.o check_dns_LDADD = $(NETLIBS) runcmd.o check_dummy_LDADD = $(BASEOBJS) check_fping_LDADD = $(NETLIBS) popen.o @@ -98,7 +95,7 @@ urlize_LDADD = $(BASEOBJS) popen.o check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS) check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS) -check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o utils_disk.o $(DEPLIBS) +check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS) check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS) check_dummy_DEPENDENCIES = check_dummy.c $(DEPLIBS) check_fping_DEPENDENCIES = check_fping.c $(NETOBJS) popen.o $(DEPLIBS) diff --git a/plugins/check_disk.c b/plugins/check_disk.c index 14234483..6beaf861 100644 --- a/plugins/check_disk.c +++ b/plugins/check_disk.c @@ -45,6 +45,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include <assert.h> #include "popen.h" #include "utils.h" +#include "utils_disk.h" #include <stdarg.h> #include "fsusage.h" #include "mountlist.h" @@ -52,7 +53,6 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; # include <limits.h> #endif -#include "utils_disk.h" /* If nonzero, show inode information. */ static int inode_format; @@ -94,7 +94,7 @@ static struct name_list *fs_exclude_list; static struct name_list *dp_exclude_list; -static struct parameter_list *path_select_list; +static struct parameter_list *path_select_list = NULL; /* Linked list of mounted filesystems. */ static struct mount_entry *mount_list; @@ -296,12 +296,17 @@ process_arguments (int argc, char **argv) { int c; struct parameter_list *se; - struct parameter_list **pathtail = &path_select_list; struct parameter_list *temp_list; int result = OK; struct stat *stat_buf; + char *warn_freespace = NULL; + char *crit_freespace = NULL; + char *warn_freespace_percent = NULL; + char *crit_freespace_percent = NULL; + char temp_string[MAX_INPUT_BUFFER]; unsigned long l; + double f; int option = 0; static struct option longopts[] = { @@ -355,6 +360,15 @@ process_arguments (int argc, char **argv) usage2 (_("Timeout interval must be a positive integer"), optarg); } case 'w': /* warning threshold */ + /* + if (strstr(optarg, "%")) { + printf("Got percent with optarg=%s\n", optarg); + warn_freespace_percent = optarg; + } else { + warn_freespace = optarg; + } + break; + */ if (is_intnonneg (optarg)) { w_df = atoi (optarg); break; @@ -444,19 +458,13 @@ process_arguments (int argc, char **argv) show_local_fs = 1; break; case 'p': /* select path */ - se = (struct parameter_list *) malloc (sizeof (struct parameter_list)); - se->name = optarg; - se->name_next = NULL; + se = np_add_parameter(&path_select_list, optarg); se->w_df = w_df; se->c_df = c_df; se->w_dfp = w_dfp; se->c_dfp = c_dfp; se->w_idfp = w_idfp; se->c_idfp = c_idfp; - se->found = 0; - se->found_len = 0; - *pathtail = se; - pathtail = &se->name_next; break; case 'x': /* exclude path or partition */ np_add_name(&dp_exclude_list, optarg); @@ -507,18 +515,13 @@ process_arguments (int argc, char **argv) c_dfp = (100.0 - atof (argv[c++])); if (argc > c && path == NULL) { - se = (struct parameter_list *) malloc (sizeof (struct parameter_list)); - se->name = strdup (argv[c++]); - se->name_next = NULL; + se = np_add_parameter(&path_select_list, strdup(argv[c++])); se->w_df = w_df; se->c_df = c_df; se->w_dfp = w_dfp; se->c_dfp = c_dfp; se->w_idfp = w_idfp; se->c_idfp = c_idfp; - se->found =0; - se->found_len = 0; - *pathtail = se; } if (path_select_list) { @@ -604,7 +607,6 @@ INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greate int - check_disk (double usp, uintmax_t free_disk, double uisp) { int result = STATE_UNKNOWN; diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 081741ab..6563e103 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c @@ -28,6 +28,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" #include "utils.h" +#include "utils_base.h" #include "netutils.h" #include "runcmd.h" diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c index a47572d9..8c7e4ef0 100644 --- a/plugins/check_mysql.c +++ b/plugins/check_mysql.c @@ -23,6 +23,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" #include "utils.h" +#include "utils_base.h" #include "netutils.h" #include <mysql.h> diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c index 404ca79f..e1293666 100644 --- a/plugins/check_mysql_query.c +++ b/plugins/check_mysql_query.c @@ -20,6 +20,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #include "common.h" #include "utils.h" +#include "utils_base.h" #include "netutils.h" #include <mysql.h> diff --git a/plugins/tests/.cvsignore b/plugins/tests/.cvsignore deleted file mode 100644 index 6dc692f5..00000000 --- a/plugins/tests/.cvsignore +++ /dev/null @@ -1,5 +0,0 @@ -Makefile -Makefile.in -test_utils -test_disk -.deps diff --git a/plugins/tests/Makefile.am b/plugins/tests/Makefile.am deleted file mode 100644 index 741499d5..00000000 --- a/plugins/tests/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ - -noinst_PROGRAMS = @EXTRA_TEST@ - -# These two lines support "make check", but we use "make test" -TESTS = @EXTRA_TEST@ -check_PROGRAMS = @EXTRA_TEST@ - -INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/intl - -EXTRA_PROGRAMS = test_utils test_disk - -EXTRA_DIST = test_utils.t test_disk.t - -LIBS = @LIBINTL@ - -test_utils_SOURCES = test_utils.c -test_utils_CFLAGS = -g -I.. -test_utils_LDFLAGS = -L/usr/local/lib -ltap -test_utils_LDADD = ../utils.o - -test_disk_SOURCES = test_disk.c -test_disk_CFLAGS = -g -I.. -test_disk_LDFLAGS = -L/usr/local/lib -ltap -test_disk_LDADD = ../utils_disk.o - -test: ${noinst_PROGRAMS} - perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS) - diff --git a/plugins/tests/README b/plugins/tests/README deleted file mode 100644 index 66935e4d..00000000 --- a/plugins/tests/README +++ /dev/null @@ -1,5 +0,0 @@ -The tests in here use the libtap library functions -(http://jc.ngo.org.uk/trac-bin/trac.cgi/wiki/LibTap), so are -more for unit testing the utils.c library functions. - -However, it probably should be merged into the plugins/t subdirectory. diff --git a/plugins/tests/test_disk.c b/plugins/tests/test_disk.c deleted file mode 100644 index 8940236b..00000000 --- a/plugins/tests/test_disk.c +++ /dev/null @@ -1,124 +0,0 @@ -/****************************************************************************** - - 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$ - -******************************************************************************/ - -#include "common.h" -#include "utils_disk.h" -#include "tap.h" - -int -main (int argc, char **argv) -{ - struct name_list *exclude_filesystem=NULL; - struct name_list *exclude_fstype=NULL; - struct name_list *dummy_mountlist = NULL; - struct name_list *temp_name; - struct parameter_list *paths = NULL; - struct parameter_list *p; - - struct mount_entry *dummy_mount_list; - struct mount_entry *me; - struct mount_entry **mtail = &dummy_mount_list; - - plan_tests(17); - - ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); - np_add_name(&exclude_filesystem, "/var/log"); - ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "is in list now"); - ok( np_find_name(exclude_filesystem, "/home") == FALSE, "/home not in list"); - np_add_name(&exclude_filesystem, "/home"); - ok( np_find_name(exclude_filesystem, "/home") == TRUE, "is in list now"); - ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "/var/log still in list"); - - ok( np_find_name(exclude_fstype, "iso9660") == FALSE, "iso9660 not in list"); - np_add_name(&exclude_fstype, "iso9660"); - ok( np_find_name(exclude_fstype, "iso9660") == TRUE, "is in list now"); - - ok( np_find_name(exclude_filesystem, "iso9660") == FALSE, "Make sure no clashing in variables"); - - /* - for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { - printf("Name: %s\n", temp_name->name); - } - */ - - me = (struct mount_entry *) malloc(sizeof *me); - me->me_devname = strdup("/dev/c0t0d0s0"); - me->me_mountdir = strdup("/"); - *mtail = me; - mtail = &me->me_next; - - me = (struct mount_entry *) malloc(sizeof *me); - me->me_devname = strdup("/dev/c1t0d1s0"); - me->me_mountdir = strdup("/var"); - *mtail = me; - mtail = &me->me_next; - - me = (struct mount_entry *) malloc(sizeof *me); - me->me_devname = strdup("/dev/c2t0d0s0"); - me->me_mountdir = strdup("/home"); - *mtail = me; - mtail = &me->me_next; - - - np_add_parameter(&paths, "/home/groups"); - np_add_parameter(&paths, "/var"); - np_add_parameter(&paths, "/tmp"); - np_add_parameter(&paths, "/home/tonvoon"); - np_add_parameter(&paths, "/dev/c2t0d0s0"); - - np_set_best_match(paths, dummy_mount_list, FALSE); - for (p = paths; p; p = p->name_next) { - struct mount_entry *temp_me; - temp_me = p->best_match; - if (! strcmp(p->name, "/home/groups")) { - ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home"); - } else if (! strcmp(p->name, "/var")) { - ok( temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var"); - } else if (! strcmp(p->name, "/tmp")) { - ok( temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /"); - } else if (! strcmp(p->name, "/home/tonvoon")) { - ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home"); - } else if (! strcmp(p->name, "/dev/c2t0d0s0")) { - ok( temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0"); - } - } - - paths = NULL; /* Bad boy - should free, but this is a test suite */ - np_add_parameter(&paths, "/home/groups"); - np_add_parameter(&paths, "/var"); - np_add_parameter(&paths, "/tmp"); - np_add_parameter(&paths, "/home/tonvoon"); - - np_set_best_match(paths, dummy_mount_list, TRUE); - for (p = paths; p; p = p->name_next) { - if (! strcmp(p->name, "/home/groups")) { - ok( p->found == 0, "/home/groups correctly not found"); - } else if (! strcmp(p->name, "/var")) { - ok( p->found == 1, "/var found"); - } else if (! strcmp(p->name, "/tmp")) { - ok( p->found == 0, "/tmp correctly not found"); - } else if (! strcmp(p->name, "/home/tonvoon")) { - ok( p->found == 0, "/home/tonvoon not found"); - } - } - - return exit_status(); -} - diff --git a/plugins/tests/test_disk.t b/plugins/tests/test_disk.t deleted file mode 100755 index d32567a9..00000000 --- a/plugins/tests/test_disk.t +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/perl -use Test::More; -if (! -e "./test_disk") { - plan skip_all => "./test_disk not compiled - please install tap library to test"; -} -exec "./test_disk"; diff --git a/plugins/tests/test_utils.c b/plugins/tests/test_utils.c deleted file mode 100644 index 67c304a3..00000000 --- a/plugins/tests/test_utils.c +++ /dev/null @@ -1,176 +0,0 @@ -/****************************************************************************** - - 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$ - -******************************************************************************/ - -const char *progname = "utils"; - -#include "common.h" -#include "utils.h" -#include "popen.h" - -#include "tap.h" - -int -main (int argc, char **argv) -{ - range *range; - double temp; - thresholds *thresholds = NULL; - int rc; - - plan_tests(74); - - range = parse_range_string("6"); - ok( range != NULL, "'6' is valid range"); - ok( range->start == 0, "Start correct"); - ok( range->start_infinity == FALSE, "Not using negative infinity"); - ok( range->end == 6, "End correct"); - ok( range->end_infinity == FALSE, "Not using infinity"); - free(range); - - range = parse_range_string("-7:23"); - ok( range != NULL, "'-7:23' is valid range"); - ok( range->start == -7, "Start correct"); - ok( range->start_infinity == FALSE, "Not using negative infinity"); - ok( range->end == 23, "End correct"); - ok( range->end_infinity == FALSE, "Not using infinity"); - free(range); - - range = parse_range_string(":5.75"); - ok( range != NULL, "':5.75' is valid range"); - ok( range->start == 0, "Start correct"); - ok( range->start_infinity == FALSE, "Not using negative infinity"); - ok( range->end == 5.75, "End correct"); - ok( range->end_infinity == FALSE, "Not using infinity"); - free(range); - - range = parse_range_string("~:-95.99"); - ok( range != NULL, "~:-95.99' is valid range"); - ok( range->start_infinity == TRUE, "Using negative infinity"); - ok( range->end == -95.99, "End correct (with rounding errors)"); - ok( range->end_infinity == FALSE, "Not using infinity"); - free(range); - - range = parse_range_string("12345678901234567890:"); - temp = atof("12345678901234567890"); /* Can't just use this because number too large */ - ok( range != NULL, "'12345678901234567890:' is valid range"); - ok( range->start == temp, "Start correct"); - ok( range->start_infinity == FALSE, "Not using negative infinity"); - ok( range->end_infinity == TRUE, "Using infinity"); - /* Cannot do a "-1" on temp, as it appears to be same value */ - ok( check_range(temp/1.1, range) == TRUE, "12345678901234567890/1.1 - alert"); - ok( check_range(temp, range) == FALSE, "12345678901234567890 - no alert"); - ok( check_range(temp*2, range) == FALSE, "12345678901234567890*2 - no alert"); - free(range); - - range = parse_range_string("~:0"); - ok( range != NULL, "'~:0' is valid range"); - ok( range->start_infinity == TRUE, "Using negative infinity"); - ok( range->end == 0, "End correct"); - ok( range->end_infinity == FALSE, "Not using infinity"); - ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); - ok( check_range(0.5, range) == TRUE, "0.5 - alert"); - ok( check_range(-10, range) == FALSE, "-10 - no alert"); - ok( check_range(0, range) == FALSE, "0 - no alert"); - free(range); - - range = parse_range_string("@0:657.8210567"); - ok( range != 0, "@0:657.8210567' is a valid range"); - ok( range->start == 0, "Start correct"); - ok( range->start_infinity == FALSE, "Not using negative infinity"); - ok( range->end == 657.8210567, "End correct"); - ok( range->end_infinity == FALSE, "Not using infinity"); - ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); - ok( check_range(32.88, range) == TRUE, "32.88 - alert"); - ok( check_range(-2, range) == FALSE, "-2 - no alert"); - ok( check_range(657.8210567, range) == TRUE, "657.8210567 - alert"); - ok( check_range(0, range) == TRUE, "0 - alert"); - free(range); - - range = parse_range_string("1:1"); - ok( range != NULL, "'1:1' is a valid range"); - ok( range->start == 1, "Start correct"); - ok( range->start_infinity == FALSE, "Not using negative infinity"); - ok( range->end == 1, "End correct"); - ok( range->end_infinity == FALSE, "Not using infinity"); - ok( check_range(0.5, range) == TRUE, "0.5 - alert"); - ok( check_range(1, range) == FALSE, "1 - no alert"); - ok( check_range(5.2, range) == TRUE, "5.2 - alert"); - free(range); - - range = parse_range_string("2:1"); - ok( range == NULL, "'2:1' rejected"); - - rc = _set_thresholds(&thresholds, NULL, "80"); - ok( rc == 0, "Thresholds (NULL, '80') set"); - ok( thresholds->warning == NULL, "Warning not set"); - ok( thresholds->critical->end == 80, "Critical set correctly"); - - rc = _set_thresholds(&thresholds, "5:33", NULL); - ok( rc == 0, "Thresholds ('5:33', NULL) set"); - ok( thresholds->warning->start == 5, "Warning start set"); - ok( thresholds->warning->end == 33, "Warning end set"); - ok( thresholds->critical == NULL, "Critical not set"); - - rc = _set_thresholds(&thresholds, "30", "60"); - ok( rc == 0, "Thresholds ('30', '60') set"); - ok( thresholds->warning->end == 30, "Warning set correctly"); - ok( thresholds->critical->end == 60, "Critical set correctly"); - ok( get_status(15.3, thresholds) == STATE_OK, "15.3 - ok"); - ok( get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning"); - ok( get_status(69, thresholds) == STATE_CRITICAL, "69 - critical"); - - char *test; - test = np_escaped_string("bob\\n"); - ok( strcmp(test, "bob\n") == 0, "bob\\n ok"); - free(test); - - test = np_escaped_string("rhuba\\rb"); - ok( strcmp(test, "rhuba\rb") == 0, "rhuba\\rb okay"); - free(test); - - test = np_escaped_string("ba\\nge\\r"); - ok( strcmp(test, "ba\nge\r") == 0, "ba\\nge\\r okay"); - free(test); - - test = np_escaped_string("\\rabbi\\t"); - ok( strcmp(test, "\rabbi\t") == 0, "\\rabbi\\t okay"); - free(test); - - test = np_escaped_string("and\\\\or"); - ok( strcmp(test, "and\\or") == 0, "and\\\\or okay"); - free(test); - - test = np_escaped_string("bo\\gus"); - ok( strcmp(test, "bogus") == 0, "bo\\gus okay"); - free(test); - - test = np_escaped_string("everything"); - ok( strcmp(test, "everything") == 0, "everything okay"); - free(test); - - test = basename("/here/is/a/path"); - ok( strcmp(test, "path") == 0, "basename okay"); - - return exit_status(); -} - -void print_usage() { - printf("Dummy"); -} diff --git a/plugins/tests/test_utils.t b/plugins/tests/test_utils.t deleted file mode 100755 index 152eb718..00000000 --- a/plugins/tests/test_utils.t +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/perl -use Test::More; -if (! -e "./test_utils") { - plan skip_all => "./test_utils not compiled - please install tap library to test"; -} -exec "./test_utils"; diff --git a/plugins/utils.c b/plugins/utils.c index cb013412..2b3accea 100644 --- a/plugins/utils.c +++ b/plugins/utils.c @@ -16,6 +16,7 @@ #include "common.h" #include "utils.h" +#include "utils_base.h" #include <stdarg.h> #include <limits.h> @@ -132,16 +133,6 @@ state_text (int result) } void -die (int result, const char *fmt, ...) -{ - va_list ap; - va_start (ap, fmt); - vprintf (fmt, ap); - va_end (ap); - exit (result); -} - -void timeout_alarm_handler (int signo) { if (signo == SIGALRM) { @@ -266,156 +257,6 @@ is_option (char *str) return FALSE; } -void set_range_start (range *this, double value) { - this->start = value; - this->start_infinity = FALSE; -} - -void set_range_end (range *this, double value) { - this->end = value; - this->end_infinity = FALSE; -} - -range -*parse_range_string (char *str) { - range *temp_range; - double start; - double end; - char *end_str; - - temp_range = (range *) malloc(sizeof(range)); - - /* Set defaults */ - temp_range->start = 0; - temp_range->start_infinity = FALSE; - temp_range->end = 0; - temp_range->end_infinity = TRUE; - temp_range->alert_on = OUTSIDE; - - if (str[0] == '@') { - temp_range->alert_on = INSIDE; - str++; - } - - end_str = index(str, ':'); - if (end_str != NULL) { - if (str[0] == '~') { - temp_range->start_infinity = TRUE; - } else { - start = strtod(str, NULL); /* Will stop at the ':' */ - set_range_start(temp_range, start); - } - end_str++; /* Move past the ':' */ - } else { - end_str = str; - } - end = strtod(end_str, NULL); - if (strcmp(end_str, "") != 0) { - set_range_end(temp_range, end); - } - - if (temp_range->start_infinity == TRUE || - temp_range->end_infinity == TRUE || - temp_range->start <= temp_range->end) { - return temp_range; - } - free(temp_range); - return NULL; -} - -/* returns 0 if okay, otherwise 1 */ -int -_set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) -{ - thresholds *temp_thresholds = NULL; - - temp_thresholds = malloc(sizeof(temp_thresholds)); - - temp_thresholds->warning = NULL; - temp_thresholds->critical = NULL; - - if (warn_string != NULL) { - if ((temp_thresholds->warning = parse_range_string(warn_string)) == NULL) { - return 1; - } - } - if (critical_string != NULL) { - if ((temp_thresholds->critical = parse_range_string(critical_string)) == NULL) { - return 1; - } - } - - if (*my_thresholds != 0) { - /* printf("Freeing here: %d\n", *my_thresholds); */ - free(*my_thresholds); - } - *my_thresholds = temp_thresholds; - - return 0; -} - -void -set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string) -{ - if (_set_thresholds(my_thresholds, warn_string, critical_string) == 0) { - return; - } else { - usage(_("Range format incorrect")); - } -} - -/* Returns TRUE if alert should be raised based on the range */ -int -check_range(double value, range *my_range) -{ - int false = FALSE; - int true = TRUE; - - if (my_range->alert_on == INSIDE) { - false = TRUE; - true = FALSE; - } - - if (my_range->end_infinity == FALSE && my_range->start_infinity == FALSE) { - if ((my_range->start <= value) && (value <= my_range->end)) { - return false; - } else { - return true; - } - } else if (my_range->start_infinity == FALSE && my_range->end_infinity == TRUE) { - if (my_range->start <= value) { - return false; - } else { - return true; - } - } else if (my_range->start_infinity == TRUE && my_range->end_infinity == FALSE) { - if (value <= my_range->end) { - return false; - } else { - return true; - } - } else { - return false; - } -} - -/* Returns status */ -int -get_status(double value, thresholds *my_thresholds) -{ - if (my_thresholds->critical != NULL) { - if (check_range(value, my_thresholds->critical) == TRUE) { - return STATE_CRITICAL; - } - } - if (my_thresholds->warning != NULL) { - if (check_range(value, my_thresholds->warning) == TRUE) { - return STATE_WARNING; - } - } - return STATE_OK; -} - #ifdef NEED_GETTIMEOFDAY int gettimeofday (struct timeval *tv, struct timezone *tz) @@ -727,33 +568,3 @@ char *fperfdata (const char *label, return data; } - -char *np_escaped_string (const char *string) { - char *data; - int i, j=0; - data = strdup(string); - for (i=0; data[i]; i++) { - if (data[i] == '\\') { - switch(data[++i]) { - case 'n': - data[j++] = '\n'; - break; - case 'r': - data[j++] = '\r'; - break; - case 't': - data[j++] = '\t'; - break; - case '\\': - data[j++] = '\\'; - break; - default: - data[j++] = data[i]; - } - } else { - data[j++] = data[i]; - } - } - data[j] = '\0'; - return data; -} diff --git a/plugins/utils.h b/plugins/utils.h index 4bbe33d0..1f53aadb 100644 --- a/plugins/utils.h +++ b/plugins/utils.h @@ -20,7 +20,6 @@ suite of plugins. */ void support (void); char *clean_revstring (const char *); void print_revision (const char *, const char *); -void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3))); /* Handle timeouts */ @@ -58,28 +57,6 @@ struct timeval { }; #endif -#define OUTSIDE 0 -#define INSIDE 1 - -typedef struct range_struct { - double start; - int start_infinity; /* FALSE (default) or TRUE */ - double end; - int end_infinity; - int alert_on; /* OUTSIDE (default) or INSIDE */ - } range; - -typedef struct thresholds_struct { - range *warning; - range *critical; - } thresholds; - -range *parse_range_string (char *); -int _set_thresholds(thresholds **, char *, char *); -void set_thresholds(thresholds **, char *, char *); -int check_range(double, range *); -int get_status(double, thresholds *); - #ifndef HAVE_GETTIMEOFDAY int gettimeofday(struct timeval *, struct timezone *); #endif @@ -132,8 +109,6 @@ char *fperfdata (const char *, int, double); -char *np_escaped_string (const char *); - /* The idea here is that, although not every plugin will use all of these, most will or should. Therefore, for consistency, these very common options should have only these meanings throughout the overall suite */ diff --git a/plugins/utils_disk.c b/plugins/utils_disk.c deleted file mode 100644 index 31284d5d..00000000 --- a/plugins/utils_disk.c +++ /dev/null @@ -1,141 +0,0 @@ -/**************************************************************************** -* Utils for check_disk -* -* License: GPL -* Copyright (c) 1999-2006 nagios-plugins team -* -* Last Modified: $Date$ -* -* Description: -* -* This file contains utilities for check_disk. These are tested by libtap -* -* 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$ -* -*****************************************************************************/ - -#include "common.h" -#include "utils_disk.h" - -void -np_add_name (struct name_list **list, const char *name) -{ - struct name_list *new_entry; - new_entry = (struct name_list *) malloc (sizeof *new_entry); - new_entry->name = (char *) name; - new_entry->next = *list; - *list = new_entry; -} - -/* Initialises a new parameter at the end of list */ -struct parameter_list * -np_add_parameter(struct parameter_list **list, const char *name) -{ - struct parameter_list *current = *list; - struct parameter_list *new_path; - new_path = (struct parameter_list *) malloc (sizeof *new_path); - new_path->name = (char *) name; - new_path->found = 0; - new_path->found_len = 0; - new_path->w_df = 0; - new_path->c_df = 0; - new_path->w_dfp = -1.0; - new_path->c_dfp = -1.0; - new_path->w_idfp = -1.0; - new_path->c_idfp = -1.0; - new_path->best_match = NULL; - - if (current == NULL) { - *list = new_path; - } else { - while (current->name_next) { - current = current->name_next; - } - current->name_next = new_path; - } - return new_path; -} - -void -np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact) -{ - struct parameter_list *d; - for (d = desired; d; d= d->name_next) { - struct mount_entry *me; - size_t name_len = strlen(d->name); - size_t best_match_len = 0; - struct mount_entry *best_match = NULL; - - for (me = mount_list; me; me = me->me_next) { - size_t len = strlen (me->me_mountdir); - if ((exact == FALSE && (best_match_len <= len && len <= name_len && - (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) - || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) - { - best_match = me; - best_match_len = len; - } else { - len = strlen (me->me_devname); - if ((exact == FALSE && (best_match_len <= len && len <= name_len && - (len == 1 || strncmp (me->me_devname, d->name, len) == 0))) - || (exact == TRUE && strcmp(me->me_devname, d->name)==0)) - { - best_match = me; - best_match_len = len; - } - } - } - if (best_match) { - d->best_match = best_match; - d->found = TRUE; - } else { - d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ - } - } -} - -/* Returns TRUE if name is in list */ -int -np_find_name (struct name_list *list, const char *name) -{ - const struct name_list *n; - - if (list == NULL || name == NULL) { - return FALSE; - } - for (n = list; n; n = n->next) { - if (!strcmp(name, n->name)) { - return TRUE; - } - } - return FALSE; -} - -int -np_seen_name(struct name_list *list, const char *name) -{ - const struct name_list *s; - for (s = list; s; s=s->next) { - if (!strcmp(s->name, name)) { - return TRUE; - } - } - return FALSE; -} - diff --git a/plugins/utils_disk.h b/plugins/utils_disk.h deleted file mode 100644 index 676ca09a..00000000 --- a/plugins/utils_disk.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Header file for utils_disk */ - -#include "mountlist.h" - -struct name_list -{ - char *name; - struct name_list *next; -}; - -struct parameter_list -{ - char *name; - int found; - int found_len; - uintmax_t w_df; - uintmax_t c_df; - double w_dfp; - double c_dfp; - double w_idfp; - double c_idfp; - struct mount_entry *best_match; - struct parameter_list *name_next; -}; - -void np_add_name (struct name_list **list, const char *name); -int np_find_name (struct name_list *list, const char *name); -int np_seen_name (struct name_list *list, const char *name); -struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); -int search_parameter_list (struct parameter_list *list, const char *name); |