summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/Makefile.am7
-rw-r--r--plugins/check_disk.c36
-rw-r--r--plugins/check_dns.c1
-rw-r--r--plugins/check_mysql.c1
-rw-r--r--plugins/check_mysql_query.c1
-rw-r--r--plugins/tests/.cvsignore5
-rw-r--r--plugins/tests/Makefile.am28
-rw-r--r--plugins/tests/README5
-rw-r--r--plugins/tests/test_disk.c124
-rwxr-xr-xplugins/tests/test_disk.t6
-rw-r--r--plugins/tests/test_utils.c176
-rwxr-xr-xplugins/tests/test_utils.t6
-rw-r--r--plugins/utils.c191
-rw-r--r--plugins/utils.h25
-rw-r--r--plugins/utils_disk.c141
-rw-r--r--plugins/utils_disk.h30
16 files changed, 25 insertions, 758 deletions
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 28793cd..9dd7184 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,7 +1,5 @@
1## Process this file with automake to produce Makefile.in 1## Process this file with automake to produce Makefile.in
2 2
3SUBDIRS = tests
4
5VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t 3VPATH = $(top_srcdir) $(top_srcdir)/lib $(top_srcdir)/plugins $(top_srcdir)/plugins/t
6 4
7INCLUDES = -I.. -I$(top_srcdir)/lib -I$(top_srcdir)/intl @LDAPINCLUDE@ @PGINCLUDE@ @SSLINCLUDE@ 5INCLUDES = -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)
45TESTS = @PLUGIN_TEST@ 43TESTS = @PLUGIN_TEST@
46 44
47test: 45test:
48 cd tests && make test
49 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl 46 perl -I $(top_builddir) -I $(top_srcdir) ../test.pl
50 47
51AM_INSTALL_PROGRAM_FLAGS = @INSTALL_OPTS@ 48AM_INSTALL_PROGRAM_FLAGS = @INSTALL_OPTS@
@@ -55,7 +52,7 @@ AM_INSTALL_PROGRAM_FLAGS = @INSTALL_OPTS@
55 52
56check_apt_LDADD = $(BASEOBJS) runcmd.o 53check_apt_LDADD = $(BASEOBJS) runcmd.o
57check_dig_LDADD = $(NETLIBS) runcmd.o 54check_dig_LDADD = $(NETLIBS) runcmd.o
58check_disk_LDADD = $(BASEOBJS) popen.o utils_disk.o 55check_disk_LDADD = $(BASEOBJS) popen.o
59check_dns_LDADD = $(NETLIBS) runcmd.o 56check_dns_LDADD = $(NETLIBS) runcmd.o
60check_dummy_LDADD = $(BASEOBJS) 57check_dummy_LDADD = $(BASEOBJS)
61check_fping_LDADD = $(NETLIBS) popen.o 58check_fping_LDADD = $(NETLIBS) popen.o
@@ -98,7 +95,7 @@ urlize_LDADD = $(BASEOBJS) popen.o
98 95
99check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS) 96check_apt_DEPENDENCIES = check_apt.c $(BASEOBJS) runcmd.o $(DEPLIBS)
100check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS) 97check_dig_DEPENDENCIES = check_dig.c $(NETOBJS) runcmd.o $(DEPLIBS)
101check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o utils_disk.o $(DEPLIBS) 98check_disk_DEPENDENCIES = check_disk.c $(BASEOBJS) popen.o $(DEPLIBS)
102check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS) 99check_dns_DEPENDENCIES = check_dns.c $(NETOBJS) runcmd.o $(DEPLIBS)
103check_dummy_DEPENDENCIES = check_dummy.c $(DEPLIBS) 100check_dummy_DEPENDENCIES = check_dummy.c $(DEPLIBS)
104check_fping_DEPENDENCIES = check_fping.c $(NETOBJS) popen.o $(DEPLIBS) 101check_fping_DEPENDENCIES = check_fping.c $(NETOBJS) popen.o $(DEPLIBS)
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index 1423448..6beaf86 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -45,6 +45,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
45#include <assert.h> 45#include <assert.h>
46#include "popen.h" 46#include "popen.h"
47#include "utils.h" 47#include "utils.h"
48#include "utils_disk.h"
48#include <stdarg.h> 49#include <stdarg.h>
49#include "fsusage.h" 50#include "fsusage.h"
50#include "mountlist.h" 51#include "mountlist.h"
@@ -52,7 +53,6 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
52# include <limits.h> 53# include <limits.h>
53#endif 54#endif
54 55
55#include "utils_disk.h"
56 56
57/* If nonzero, show inode information. */ 57/* If nonzero, show inode information. */
58static int inode_format; 58static int inode_format;
@@ -94,7 +94,7 @@ static struct name_list *fs_exclude_list;
94 94
95static struct name_list *dp_exclude_list; 95static struct name_list *dp_exclude_list;
96 96
97static struct parameter_list *path_select_list; 97static struct parameter_list *path_select_list = NULL;
98 98
99/* Linked list of mounted filesystems. */ 99/* Linked list of mounted filesystems. */
100static struct mount_entry *mount_list; 100static struct mount_entry *mount_list;
@@ -296,12 +296,17 @@ process_arguments (int argc, char **argv)
296{ 296{
297 int c; 297 int c;
298 struct parameter_list *se; 298 struct parameter_list *se;
299 struct parameter_list **pathtail = &path_select_list;
300 struct parameter_list *temp_list; 299 struct parameter_list *temp_list;
301 int result = OK; 300 int result = OK;
302 struct stat *stat_buf; 301 struct stat *stat_buf;
302 char *warn_freespace = NULL;
303 char *crit_freespace = NULL;
304 char *warn_freespace_percent = NULL;
305 char *crit_freespace_percent = NULL;
306 char temp_string[MAX_INPUT_BUFFER];
303 307
304 unsigned long l; 308 unsigned long l;
309 double f;
305 310
306 int option = 0; 311 int option = 0;
307 static struct option longopts[] = { 312 static struct option longopts[] = {
@@ -355,6 +360,15 @@ process_arguments (int argc, char **argv)
355 usage2 (_("Timeout interval must be a positive integer"), optarg); 360 usage2 (_("Timeout interval must be a positive integer"), optarg);
356 } 361 }
357 case 'w': /* warning threshold */ 362 case 'w': /* warning threshold */
363 /*
364 if (strstr(optarg, "%")) {
365 printf("Got percent with optarg=%s\n", optarg);
366 warn_freespace_percent = optarg;
367 } else {
368 warn_freespace = optarg;
369 }
370 break;
371 */
358 if (is_intnonneg (optarg)) { 372 if (is_intnonneg (optarg)) {
359 w_df = atoi (optarg); 373 w_df = atoi (optarg);
360 break; 374 break;
@@ -444,19 +458,13 @@ process_arguments (int argc, char **argv)
444 show_local_fs = 1; 458 show_local_fs = 1;
445 break; 459 break;
446 case 'p': /* select path */ 460 case 'p': /* select path */
447 se = (struct parameter_list *) malloc (sizeof (struct parameter_list)); 461 se = np_add_parameter(&path_select_list, optarg);
448 se->name = optarg;
449 se->name_next = NULL;
450 se->w_df = w_df; 462 se->w_df = w_df;
451 se->c_df = c_df; 463 se->c_df = c_df;
452 se->w_dfp = w_dfp; 464 se->w_dfp = w_dfp;
453 se->c_dfp = c_dfp; 465 se->c_dfp = c_dfp;
454 se->w_idfp = w_idfp; 466 se->w_idfp = w_idfp;
455 se->c_idfp = c_idfp; 467 se->c_idfp = c_idfp;
456 se->found = 0;
457 se->found_len = 0;
458 *pathtail = se;
459 pathtail = &se->name_next;
460 break; 468 break;
461 case 'x': /* exclude path or partition */ 469 case 'x': /* exclude path or partition */
462 np_add_name(&dp_exclude_list, optarg); 470 np_add_name(&dp_exclude_list, optarg);
@@ -507,18 +515,13 @@ process_arguments (int argc, char **argv)
507 c_dfp = (100.0 - atof (argv[c++])); 515 c_dfp = (100.0 - atof (argv[c++]));
508 516
509 if (argc > c && path == NULL) { 517 if (argc > c && path == NULL) {
510 se = (struct parameter_list *) malloc (sizeof (struct parameter_list)); 518 se = np_add_parameter(&path_select_list, strdup(argv[c++]));
511 se->name = strdup (argv[c++]);
512 se->name_next = NULL;
513 se->w_df = w_df; 519 se->w_df = w_df;
514 se->c_df = c_df; 520 se->c_df = c_df;
515 se->w_dfp = w_dfp; 521 se->w_dfp = w_dfp;
516 se->c_dfp = c_dfp; 522 se->c_dfp = c_dfp;
517 se->w_idfp = w_idfp; 523 se->w_idfp = w_idfp;
518 se->c_idfp = c_idfp; 524 se->c_idfp = c_idfp;
519 se->found =0;
520 se->found_len = 0;
521 *pathtail = se;
522 } 525 }
523 526
524 if (path_select_list) { 527 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
604 607
605 608
606int 609int
607
608check_disk (double usp, uintmax_t free_disk, double uisp) 610check_disk (double usp, uintmax_t free_disk, double uisp)
609{ 611{
610 int result = STATE_UNKNOWN; 612 int result = STATE_UNKNOWN;
diff --git a/plugins/check_dns.c b/plugins/check_dns.c
index 081741a..6563e10 100644
--- a/plugins/check_dns.c
+++ b/plugins/check_dns.c
@@ -28,6 +28,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
28 28
29#include "common.h" 29#include "common.h"
30#include "utils.h" 30#include "utils.h"
31#include "utils_base.h"
31#include "netutils.h" 32#include "netutils.h"
32#include "runcmd.h" 33#include "runcmd.h"
33 34
diff --git a/plugins/check_mysql.c b/plugins/check_mysql.c
index a47572d..8c7e4ef 100644
--- a/plugins/check_mysql.c
+++ b/plugins/check_mysql.c
@@ -23,6 +23,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
23 23
24#include "common.h" 24#include "common.h"
25#include "utils.h" 25#include "utils.h"
26#include "utils_base.h"
26#include "netutils.h" 27#include "netutils.h"
27 28
28#include <mysql.h> 29#include <mysql.h>
diff --git a/plugins/check_mysql_query.c b/plugins/check_mysql_query.c
index 404ca79..e129366 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";
20 20
21#include "common.h" 21#include "common.h"
22#include "utils.h" 22#include "utils.h"
23#include "utils_base.h"
23#include "netutils.h" 24#include "netutils.h"
24 25
25#include <mysql.h> 26#include <mysql.h>
diff --git a/plugins/tests/.cvsignore b/plugins/tests/.cvsignore
deleted file mode 100644
index 6dc692f..0000000
--- a/plugins/tests/.cvsignore
+++ /dev/null
@@ -1,5 +0,0 @@
1Makefile
2Makefile.in
3test_utils
4test_disk
5.deps
diff --git a/plugins/tests/Makefile.am b/plugins/tests/Makefile.am
deleted file mode 100644
index 741499d..0000000
--- a/plugins/tests/Makefile.am
+++ /dev/null
@@ -1,28 +0,0 @@
1
2noinst_PROGRAMS = @EXTRA_TEST@
3
4# These two lines support "make check", but we use "make test"
5TESTS = @EXTRA_TEST@
6check_PROGRAMS = @EXTRA_TEST@
7
8INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/intl
9
10EXTRA_PROGRAMS = test_utils test_disk
11
12EXTRA_DIST = test_utils.t test_disk.t
13
14LIBS = @LIBINTL@
15
16test_utils_SOURCES = test_utils.c
17test_utils_CFLAGS = -g -I..
18test_utils_LDFLAGS = -L/usr/local/lib -ltap
19test_utils_LDADD = ../utils.o
20
21test_disk_SOURCES = test_disk.c
22test_disk_CFLAGS = -g -I..
23test_disk_LDFLAGS = -L/usr/local/lib -ltap
24test_disk_LDADD = ../utils_disk.o
25
26test: ${noinst_PROGRAMS}
27 perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS)
28
diff --git a/plugins/tests/README b/plugins/tests/README
deleted file mode 100644
index 66935e4..0000000
--- a/plugins/tests/README
+++ /dev/null
@@ -1,5 +0,0 @@
1The tests in here use the libtap library functions
2(http://jc.ngo.org.uk/trac-bin/trac.cgi/wiki/LibTap), so are
3more for unit testing the utils.c library functions.
4
5However, 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 8940236..0000000
--- a/plugins/tests/test_disk.c
+++ /dev/null
@@ -1,124 +0,0 @@
1/******************************************************************************
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
17 $Id$
18
19******************************************************************************/
20
21#include "common.h"
22#include "utils_disk.h"
23#include "tap.h"
24
25int
26main (int argc, char **argv)
27{
28 struct name_list *exclude_filesystem=NULL;
29 struct name_list *exclude_fstype=NULL;
30 struct name_list *dummy_mountlist = NULL;
31 struct name_list *temp_name;
32 struct parameter_list *paths = NULL;
33 struct parameter_list *p;
34
35 struct mount_entry *dummy_mount_list;
36 struct mount_entry *me;
37 struct mount_entry **mtail = &dummy_mount_list;
38
39 plan_tests(17);
40
41 ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list");
42 np_add_name(&exclude_filesystem, "/var/log");
43 ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "is in list now");
44 ok( np_find_name(exclude_filesystem, "/home") == FALSE, "/home not in list");
45 np_add_name(&exclude_filesystem, "/home");
46 ok( np_find_name(exclude_filesystem, "/home") == TRUE, "is in list now");
47 ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "/var/log still in list");
48
49 ok( np_find_name(exclude_fstype, "iso9660") == FALSE, "iso9660 not in list");
50 np_add_name(&exclude_fstype, "iso9660");
51 ok( np_find_name(exclude_fstype, "iso9660") == TRUE, "is in list now");
52
53 ok( np_find_name(exclude_filesystem, "iso9660") == FALSE, "Make sure no clashing in variables");
54
55 /*
56 for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) {
57 printf("Name: %s\n", temp_name->name);
58 }
59 */
60
61 me = (struct mount_entry *) malloc(sizeof *me);
62 me->me_devname = strdup("/dev/c0t0d0s0");
63 me->me_mountdir = strdup("/");
64 *mtail = me;
65 mtail = &me->me_next;
66
67 me = (struct mount_entry *) malloc(sizeof *me);
68 me->me_devname = strdup("/dev/c1t0d1s0");
69 me->me_mountdir = strdup("/var");
70 *mtail = me;
71 mtail = &me->me_next;
72
73 me = (struct mount_entry *) malloc(sizeof *me);
74 me->me_devname = strdup("/dev/c2t0d0s0");
75 me->me_mountdir = strdup("/home");
76 *mtail = me;
77 mtail = &me->me_next;
78
79
80 np_add_parameter(&paths, "/home/groups");
81 np_add_parameter(&paths, "/var");
82 np_add_parameter(&paths, "/tmp");
83 np_add_parameter(&paths, "/home/tonvoon");
84 np_add_parameter(&paths, "/dev/c2t0d0s0");
85
86 np_set_best_match(paths, dummy_mount_list, FALSE);
87 for (p = paths; p; p = p->name_next) {
88 struct mount_entry *temp_me;
89 temp_me = p->best_match;
90 if (! strcmp(p->name, "/home/groups")) {
91 ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/groups got right best match: /home");
92 } else if (! strcmp(p->name, "/var")) {
93 ok( temp_me && !strcmp(temp_me->me_mountdir, "/var"), "/var got right best match: /var");
94 } else if (! strcmp(p->name, "/tmp")) {
95 ok( temp_me && !strcmp(temp_me->me_mountdir, "/"), "/tmp got right best match: /");
96 } else if (! strcmp(p->name, "/home/tonvoon")) {
97 ok( temp_me && !strcmp(temp_me->me_mountdir, "/home"), "/home/tonvoon got right best match: /home");
98 } else if (! strcmp(p->name, "/dev/c2t0d0s0")) {
99 ok( temp_me && !strcmp(temp_me->me_devname, "/dev/c2t0d0s0"), "/dev/c2t0d0s0 got right best match: /dev/c2t0d0s0");
100 }
101 }
102
103 paths = NULL; /* Bad boy - should free, but this is a test suite */
104 np_add_parameter(&paths, "/home/groups");
105 np_add_parameter(&paths, "/var");
106 np_add_parameter(&paths, "/tmp");
107 np_add_parameter(&paths, "/home/tonvoon");
108
109 np_set_best_match(paths, dummy_mount_list, TRUE);
110 for (p = paths; p; p = p->name_next) {
111 if (! strcmp(p->name, "/home/groups")) {
112 ok( p->found == 0, "/home/groups correctly not found");
113 } else if (! strcmp(p->name, "/var")) {
114 ok( p->found == 1, "/var found");
115 } else if (! strcmp(p->name, "/tmp")) {
116 ok( p->found == 0, "/tmp correctly not found");
117 } else if (! strcmp(p->name, "/home/tonvoon")) {
118 ok( p->found == 0, "/home/tonvoon not found");
119 }
120 }
121
122 return exit_status();
123}
124
diff --git a/plugins/tests/test_disk.t b/plugins/tests/test_disk.t
deleted file mode 100755
index d32567a..0000000
--- a/plugins/tests/test_disk.t
+++ /dev/null
@@ -1,6 +0,0 @@
1#!/usr/bin/perl
2use Test::More;
3if (! -e "./test_disk") {
4 plan skip_all => "./test_disk not compiled - please install tap library to test";
5}
6exec "./test_disk";
diff --git a/plugins/tests/test_utils.c b/plugins/tests/test_utils.c
deleted file mode 100644
index 67c304a..0000000
--- a/plugins/tests/test_utils.c
+++ /dev/null
@@ -1,176 +0,0 @@
1/******************************************************************************
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
17 $Id$
18
19******************************************************************************/
20
21const char *progname = "utils";
22
23#include "common.h"
24#include "utils.h"
25#include "popen.h"
26
27#include "tap.h"
28
29int
30main (int argc, char **argv)
31{
32 range *range;
33 double temp;
34 thresholds *thresholds = NULL;
35 int rc;
36
37 plan_tests(74);
38
39 range = parse_range_string("6");
40 ok( range != NULL, "'6' is valid range");
41 ok( range->start == 0, "Start correct");
42 ok( range->start_infinity == FALSE, "Not using negative infinity");
43 ok( range->end == 6, "End correct");
44 ok( range->end_infinity == FALSE, "Not using infinity");
45 free(range);
46
47 range = parse_range_string("-7:23");
48 ok( range != NULL, "'-7:23' is valid range");
49 ok( range->start == -7, "Start correct");
50 ok( range->start_infinity == FALSE, "Not using negative infinity");
51 ok( range->end == 23, "End correct");
52 ok( range->end_infinity == FALSE, "Not using infinity");
53 free(range);
54
55 range = parse_range_string(":5.75");
56 ok( range != NULL, "':5.75' is valid range");
57 ok( range->start == 0, "Start correct");
58 ok( range->start_infinity == FALSE, "Not using negative infinity");
59 ok( range->end == 5.75, "End correct");
60 ok( range->end_infinity == FALSE, "Not using infinity");
61 free(range);
62
63 range = parse_range_string("~:-95.99");
64 ok( range != NULL, "~:-95.99' is valid range");
65 ok( range->start_infinity == TRUE, "Using negative infinity");
66 ok( range->end == -95.99, "End correct (with rounding errors)");
67 ok( range->end_infinity == FALSE, "Not using infinity");
68 free(range);
69
70 range = parse_range_string("12345678901234567890:");
71 temp = atof("12345678901234567890"); /* Can't just use this because number too large */
72 ok( range != NULL, "'12345678901234567890:' is valid range");
73 ok( range->start == temp, "Start correct");
74 ok( range->start_infinity == FALSE, "Not using negative infinity");
75 ok( range->end_infinity == TRUE, "Using infinity");
76 /* Cannot do a "-1" on temp, as it appears to be same value */
77 ok( check_range(temp/1.1, range) == TRUE, "12345678901234567890/1.1 - alert");
78 ok( check_range(temp, range) == FALSE, "12345678901234567890 - no alert");
79 ok( check_range(temp*2, range) == FALSE, "12345678901234567890*2 - no alert");
80 free(range);
81
82 range = parse_range_string("~:0");
83 ok( range != NULL, "'~:0' is valid range");
84 ok( range->start_infinity == TRUE, "Using negative infinity");
85 ok( range->end == 0, "End correct");
86 ok( range->end_infinity == FALSE, "Not using infinity");
87 ok( range->alert_on == OUTSIDE, "Will alert on outside of this range");
88 ok( check_range(0.5, range) == TRUE, "0.5 - alert");
89 ok( check_range(-10, range) == FALSE, "-10 - no alert");
90 ok( check_range(0, range) == FALSE, "0 - no alert");
91 free(range);
92
93 range = parse_range_string("@0:657.8210567");
94 ok( range != 0, "@0:657.8210567' is a valid range");
95 ok( range->start == 0, "Start correct");
96 ok( range->start_infinity == FALSE, "Not using negative infinity");
97 ok( range->end == 657.8210567, "End correct");
98 ok( range->end_infinity == FALSE, "Not using infinity");
99 ok( range->alert_on == INSIDE, "Will alert on inside of this range" );
100 ok( check_range(32.88, range) == TRUE, "32.88 - alert");
101 ok( check_range(-2, range) == FALSE, "-2 - no alert");
102 ok( check_range(657.8210567, range) == TRUE, "657.8210567 - alert");
103 ok( check_range(0, range) == TRUE, "0 - alert");
104 free(range);
105
106 range = parse_range_string("1:1");
107 ok( range != NULL, "'1:1' is a valid range");
108 ok( range->start == 1, "Start correct");
109 ok( range->start_infinity == FALSE, "Not using negative infinity");
110 ok( range->end == 1, "End correct");
111 ok( range->end_infinity == FALSE, "Not using infinity");
112 ok( check_range(0.5, range) == TRUE, "0.5 - alert");
113 ok( check_range(1, range) == FALSE, "1 - no alert");
114 ok( check_range(5.2, range) == TRUE, "5.2 - alert");
115 free(range);
116
117 range = parse_range_string("2:1");
118 ok( range == NULL, "'2:1' rejected");
119
120 rc = _set_thresholds(&thresholds, NULL, "80");
121 ok( rc == 0, "Thresholds (NULL, '80') set");
122 ok( thresholds->warning == NULL, "Warning not set");
123 ok( thresholds->critical->end == 80, "Critical set correctly");
124
125 rc = _set_thresholds(&thresholds, "5:33", NULL);
126 ok( rc == 0, "Thresholds ('5:33', NULL) set");
127 ok( thresholds->warning->start == 5, "Warning start set");
128 ok( thresholds->warning->end == 33, "Warning end set");
129 ok( thresholds->critical == NULL, "Critical not set");
130
131 rc = _set_thresholds(&thresholds, "30", "60");
132 ok( rc == 0, "Thresholds ('30', '60') set");
133 ok( thresholds->warning->end == 30, "Warning set correctly");
134 ok( thresholds->critical->end == 60, "Critical set correctly");
135 ok( get_status(15.3, thresholds) == STATE_OK, "15.3 - ok");
136 ok( get_status(30.0001, thresholds) == STATE_WARNING, "30.0001 - warning");
137 ok( get_status(69, thresholds) == STATE_CRITICAL, "69 - critical");
138
139 char *test;
140 test = np_escaped_string("bob\\n");
141 ok( strcmp(test, "bob\n") == 0, "bob\\n ok");
142 free(test);
143
144 test = np_escaped_string("rhuba\\rb");
145 ok( strcmp(test, "rhuba\rb") == 0, "rhuba\\rb okay");
146 free(test);
147
148 test = np_escaped_string("ba\\nge\\r");
149 ok( strcmp(test, "ba\nge\r") == 0, "ba\\nge\\r okay");
150 free(test);
151
152 test = np_escaped_string("\\rabbi\\t");
153 ok( strcmp(test, "\rabbi\t") == 0, "\\rabbi\\t okay");
154 free(test);
155
156 test = np_escaped_string("and\\\\or");
157 ok( strcmp(test, "and\\or") == 0, "and\\\\or okay");
158 free(test);
159
160 test = np_escaped_string("bo\\gus");
161 ok( strcmp(test, "bogus") == 0, "bo\\gus okay");
162 free(test);
163
164 test = np_escaped_string("everything");
165 ok( strcmp(test, "everything") == 0, "everything okay");
166 free(test);
167
168 test = basename("/here/is/a/path");
169 ok( strcmp(test, "path") == 0, "basename okay");
170
171 return exit_status();
172}
173
174void print_usage() {
175 printf("Dummy");
176}
diff --git a/plugins/tests/test_utils.t b/plugins/tests/test_utils.t
deleted file mode 100755
index 152eb71..0000000
--- a/plugins/tests/test_utils.t
+++ /dev/null
@@ -1,6 +0,0 @@
1#!/usr/bin/perl
2use Test::More;
3if (! -e "./test_utils") {
4 plan skip_all => "./test_utils not compiled - please install tap library to test";
5}
6exec "./test_utils";
diff --git a/plugins/utils.c b/plugins/utils.c
index cb01341..2b3acce 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -16,6 +16,7 @@
16 16
17#include "common.h" 17#include "common.h"
18#include "utils.h" 18#include "utils.h"
19#include "utils_base.h"
19#include <stdarg.h> 20#include <stdarg.h>
20#include <limits.h> 21#include <limits.h>
21 22
@@ -132,16 +133,6 @@ state_text (int result)
132} 133}
133 134
134void 135void
135die (int result, const char *fmt, ...)
136{
137 va_list ap;
138 va_start (ap, fmt);
139 vprintf (fmt, ap);
140 va_end (ap);
141 exit (result);
142}
143
144void
145timeout_alarm_handler (int signo) 136timeout_alarm_handler (int signo)
146{ 137{
147 if (signo == SIGALRM) { 138 if (signo == SIGALRM) {
@@ -266,156 +257,6 @@ is_option (char *str)
266 return FALSE; 257 return FALSE;
267} 258}
268 259
269void set_range_start (range *this, double value) {
270 this->start = value;
271 this->start_infinity = FALSE;
272}
273
274void set_range_end (range *this, double value) {
275 this->end = value;
276 this->end_infinity = FALSE;
277}
278
279range
280*parse_range_string (char *str) {
281 range *temp_range;
282 double start;
283 double end;
284 char *end_str;
285
286 temp_range = (range *) malloc(sizeof(range));
287
288 /* Set defaults */
289 temp_range->start = 0;
290 temp_range->start_infinity = FALSE;
291 temp_range->end = 0;
292 temp_range->end_infinity = TRUE;
293 temp_range->alert_on = OUTSIDE;
294
295 if (str[0] == '@') {
296 temp_range->alert_on = INSIDE;
297 str++;
298 }
299
300 end_str = index(str, ':');
301 if (end_str != NULL) {
302 if (str[0] == '~') {
303 temp_range->start_infinity = TRUE;
304 } else {
305 start = strtod(str, NULL); /* Will stop at the ':' */
306 set_range_start(temp_range, start);
307 }
308 end_str++; /* Move past the ':' */
309 } else {
310 end_str = str;
311 }
312 end = strtod(end_str, NULL);
313 if (strcmp(end_str, "") != 0) {
314 set_range_end(temp_range, end);
315 }
316
317 if (temp_range->start_infinity == TRUE ||
318 temp_range->end_infinity == TRUE ||
319 temp_range->start <= temp_range->end) {
320 return temp_range;
321 }
322 free(temp_range);
323 return NULL;
324}
325
326/* returns 0 if okay, otherwise 1 */
327int
328_set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string)
329{
330 thresholds *temp_thresholds = NULL;
331
332 temp_thresholds = malloc(sizeof(temp_thresholds));
333
334 temp_thresholds->warning = NULL;
335 temp_thresholds->critical = NULL;
336
337 if (warn_string != NULL) {
338 if ((temp_thresholds->warning = parse_range_string(warn_string)) == NULL) {
339 return 1;
340 }
341 }
342 if (critical_string != NULL) {
343 if ((temp_thresholds->critical = parse_range_string(critical_string)) == NULL) {
344 return 1;
345 }
346 }
347
348 if (*my_thresholds != 0) {
349 /* printf("Freeing here: %d\n", *my_thresholds); */
350 free(*my_thresholds);
351 }
352 *my_thresholds = temp_thresholds;
353
354 return 0;
355}
356
357void
358set_thresholds(thresholds **my_thresholds, char *warn_string, char *critical_string)
359{
360 if (_set_thresholds(my_thresholds, warn_string, critical_string) == 0) {
361 return;
362 } else {
363 usage(_("Range format incorrect"));
364 }
365}
366
367/* Returns TRUE if alert should be raised based on the range */
368int
369check_range(double value, range *my_range)
370{
371 int false = FALSE;
372 int true = TRUE;
373
374 if (my_range->alert_on == INSIDE) {
375 false = TRUE;
376 true = FALSE;
377 }
378
379 if (my_range->end_infinity == FALSE && my_range->start_infinity == FALSE) {
380 if ((my_range->start <= value) && (value <= my_range->end)) {
381 return false;
382 } else {
383 return true;
384 }
385 } else if (my_range->start_infinity == FALSE && my_range->end_infinity == TRUE) {
386 if (my_range->start <= value) {
387 return false;
388 } else {
389 return true;
390 }
391 } else if (my_range->start_infinity == TRUE && my_range->end_infinity == FALSE) {
392 if (value <= my_range->end) {
393 return false;
394 } else {
395 return true;
396 }
397 } else {
398 return false;
399 }
400}
401
402/* Returns status */
403int
404get_status(double value, thresholds *my_thresholds)
405{
406 if (my_thresholds->critical != NULL) {
407 if (check_range(value, my_thresholds->critical) == TRUE) {
408 return STATE_CRITICAL;
409 }
410 }
411 if (my_thresholds->warning != NULL) {
412 if (check_range(value, my_thresholds->warning) == TRUE) {
413 return STATE_WARNING;
414 }
415 }
416 return STATE_OK;
417}
418
419#ifdef NEED_GETTIMEOFDAY 260#ifdef NEED_GETTIMEOFDAY
420int 261int
421gettimeofday (struct timeval *tv, struct timezone *tz) 262gettimeofday (struct timeval *tv, struct timezone *tz)
@@ -727,33 +568,3 @@ char *fperfdata (const char *label,
727 568
728 return data; 569 return data;
729} 570}
730
731char *np_escaped_string (const char *string) {
732 char *data;
733 int i, j=0;
734 data = strdup(string);
735 for (i=0; data[i]; i++) {
736 if (data[i] == '\\') {
737 switch(data[++i]) {
738 case 'n':
739 data[j++] = '\n';
740 break;
741 case 'r':
742 data[j++] = '\r';
743 break;
744 case 't':
745 data[j++] = '\t';
746 break;
747 case '\\':
748 data[j++] = '\\';
749 break;
750 default:
751 data[j++] = data[i];
752 }
753 } else {
754 data[j++] = data[i];
755 }
756 }
757 data[j] = '\0';
758 return data;
759}
diff --git a/plugins/utils.h b/plugins/utils.h
index 4bbe33d..1f53aad 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -20,7 +20,6 @@ suite of plugins. */
20void support (void); 20void support (void);
21char *clean_revstring (const char *); 21char *clean_revstring (const char *);
22void print_revision (const char *, const char *); 22void print_revision (const char *, const char *);
23void die (int, const char *, ...) __attribute__((noreturn,format(printf, 2, 3)));
24 23
25/* Handle timeouts */ 24/* Handle timeouts */
26 25
@@ -58,28 +57,6 @@ struct timeval {
58}; 57};
59#endif 58#endif
60 59
61#define OUTSIDE 0
62#define INSIDE 1
63
64typedef struct range_struct {
65 double start;
66 int start_infinity; /* FALSE (default) or TRUE */
67 double end;
68 int end_infinity;
69 int alert_on; /* OUTSIDE (default) or INSIDE */
70 } range;
71
72typedef struct thresholds_struct {
73 range *warning;
74 range *critical;
75 } thresholds;
76
77range *parse_range_string (char *);
78int _set_thresholds(thresholds **, char *, char *);
79void set_thresholds(thresholds **, char *, char *);
80int check_range(double, range *);
81int get_status(double, thresholds *);
82
83#ifndef HAVE_GETTIMEOFDAY 60#ifndef HAVE_GETTIMEOFDAY
84int gettimeofday(struct timeval *, struct timezone *); 61int gettimeofday(struct timeval *, struct timezone *);
85#endif 62#endif
@@ -132,8 +109,6 @@ char *fperfdata (const char *,
132 int, 109 int,
133 double); 110 double);
134 111
135char *np_escaped_string (const char *);
136
137/* The idea here is that, although not every plugin will use all of these, 112/* The idea here is that, although not every plugin will use all of these,
138 most will or should. Therefore, for consistency, these very common 113 most will or should. Therefore, for consistency, these very common
139 options should have only these meanings throughout the overall suite */ 114 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 31284d5..0000000
--- a/plugins/utils_disk.c
+++ /dev/null
@@ -1,141 +0,0 @@
1/****************************************************************************
2* Utils for check_disk
3*
4* License: GPL
5* Copyright (c) 1999-2006 nagios-plugins team
6*
7* Last Modified: $Date$
8*
9* Description:
10*
11* This file contains utilities for check_disk. These are tested by libtap
12*
13* License Information:
14*
15* This program is free software; you can redistribute it and/or modify
16* it under the terms of the GNU General Public License as published by
17* the Free Software Foundation; either version 2 of the License, or
18* (at your option) any later version.
19*
20* This program is distributed in the hope that it will be useful,
21* but WITHOUT ANY WARRANTY; without even the implied warranty of
22* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23* GNU General Public License for more details.
24*
25* You should have received a copy of the GNU General Public License
26* along with this program; if not, write to the Free Software
27* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28*
29* $Id$
30*
31*****************************************************************************/
32
33#include "common.h"
34#include "utils_disk.h"
35
36void
37np_add_name (struct name_list **list, const char *name)
38{
39 struct name_list *new_entry;
40 new_entry = (struct name_list *) malloc (sizeof *new_entry);
41 new_entry->name = (char *) name;
42 new_entry->next = *list;
43 *list = new_entry;
44}
45
46/* Initialises a new parameter at the end of list */
47struct parameter_list *
48np_add_parameter(struct parameter_list **list, const char *name)
49{
50 struct parameter_list *current = *list;
51 struct parameter_list *new_path;
52 new_path = (struct parameter_list *) malloc (sizeof *new_path);
53 new_path->name = (char *) name;
54 new_path->found = 0;
55 new_path->found_len = 0;
56 new_path->w_df = 0;
57 new_path->c_df = 0;
58 new_path->w_dfp = -1.0;
59 new_path->c_dfp = -1.0;
60 new_path->w_idfp = -1.0;
61 new_path->c_idfp = -1.0;
62 new_path->best_match = NULL;
63
64 if (current == NULL) {
65 *list = new_path;
66 } else {
67 while (current->name_next) {
68 current = current->name_next;
69 }
70 current->name_next = new_path;
71 }
72 return new_path;
73}
74
75void
76np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
77{
78 struct parameter_list *d;
79 for (d = desired; d; d= d->name_next) {
80 struct mount_entry *me;
81 size_t name_len = strlen(d->name);
82 size_t best_match_len = 0;
83 struct mount_entry *best_match = NULL;
84
85 for (me = mount_list; me; me = me->me_next) {
86 size_t len = strlen (me->me_mountdir);
87 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
88 (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
89 || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
90 {
91 best_match = me;
92 best_match_len = len;
93 } else {
94 len = strlen (me->me_devname);
95 if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
96 (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
97 || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
98 {
99 best_match = me;
100 best_match_len = len;
101 }
102 }
103 }
104 if (best_match) {
105 d->best_match = best_match;
106 d->found = TRUE;
107 } else {
108 d->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */
109 }
110 }
111}
112
113/* Returns TRUE if name is in list */
114int
115np_find_name (struct name_list *list, const char *name)
116{
117 const struct name_list *n;
118
119 if (list == NULL || name == NULL) {
120 return FALSE;
121 }
122 for (n = list; n; n = n->next) {
123 if (!strcmp(name, n->name)) {
124 return TRUE;
125 }
126 }
127 return FALSE;
128}
129
130int
131np_seen_name(struct name_list *list, const char *name)
132{
133 const struct name_list *s;
134 for (s = list; s; s=s->next) {
135 if (!strcmp(s->name, name)) {
136 return TRUE;
137 }
138 }
139 return FALSE;
140}
141
diff --git a/plugins/utils_disk.h b/plugins/utils_disk.h
deleted file mode 100644
index 676ca09..0000000
--- a/plugins/utils_disk.h
+++ /dev/null
@@ -1,30 +0,0 @@
1/* Header file for utils_disk */
2
3#include "mountlist.h"
4
5struct name_list
6{
7 char *name;
8 struct name_list *next;
9};
10
11struct parameter_list
12{
13 char *name;
14 int found;
15 int found_len;
16 uintmax_t w_df;
17 uintmax_t c_df;
18 double w_dfp;
19 double c_dfp;
20 double w_idfp;
21 double c_idfp;
22 struct mount_entry *best_match;
23 struct parameter_list *name_next;
24};
25
26void np_add_name (struct name_list **list, const char *name);
27int np_find_name (struct name_list *list, const char *name);
28int np_seen_name (struct name_list *list, const char *name);
29struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
30int search_parameter_list (struct parameter_list *list, const char *name);