[Nagiosplug-checkins] nagiosplug/plugins Makefile.am,1.60,1.61 utils.c,1.42,1.43 utils.h,1.24,1.25

Ton Voon tonvoon at users.sourceforge.net
Mon Jan 30 08:12:02 CET 2006


Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19248/plugins

Modified Files:
	Makefile.am utils.c utils.h 
Log Message:
Added libtap tests for utils.c library functions. Removed redundant
test files


Index: Makefile.am
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/Makefile.am,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- Makefile.am	30 Oct 2005 22:45:54 -0000	1.60
+++ Makefile.am	30 Jan 2006 16:10:50 -0000	1.61
@@ -1,5 +1,7 @@
 ## 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@
@@ -41,6 +43,7 @@
 TESTS = @PLUGIN_TEST@
 
 test:
+	cd tests && make test
 	perl -I $(top_builddir) -I $(top_srcdir) ../test.pl
 
 AM_INSTALL_PROGRAM_FLAGS = @INSTALL_OPTS@

Index: utils.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- utils.c	24 Oct 2005 11:10:29 -0000	1.42
+++ utils.c	30 Jan 2006 16:10:50 -0000	1.43
@@ -265,7 +265,62 @@
 		return FALSE;
 }
 
+void set_threshold_start (threshold *this, double value) {
+	this->start = value;
+	this->start_infinity = FALSE;
+}
+
+void set_threshold_end (threshold *this, double value) {
+	this->end = value;
+	this->end_infinity = FALSE;
+}
+
+threshold
+*parse_threshold (char *str) {
+	threshold *temp_threshold;
+	double start;
+	double end;
+	char *end_str;
+
+	temp_threshold = (threshold *) malloc(sizeof(threshold));
+
+	/* Set defaults */
+	temp_threshold->start = 0;
+	temp_threshold->start_infinity = FALSE;
+	temp_threshold->end = 0;
+	temp_threshold->end_infinity = TRUE;
+	temp_threshold->alert_on = OUTSIDE;
 
+	if (str[0] == '@') {
+		temp_threshold->alert_on = INSIDE;
+		str++;
+	}
+
+	end_str = index(str, ':');
+	if (end_str != NULL) {
+		if (str[0] == '~') {
+			temp_threshold->start_infinity = TRUE;
+		} else {
+			start = strtod(str, NULL);	/* Will stop at the ':' */
+			set_threshold_start(temp_threshold, start);
+		}
+		end_str++;		/* Move past the ':' */
+	} else {
+		end_str = str;
+	}
+	end = strtod(end_str, NULL);
+	if (strcmp(end_str, "") != 0) {
+		set_threshold_end(temp_threshold, end);
+	}
+
+	if (temp_threshold->start_infinity == TRUE || 
+		temp_threshold->end_infinity == TRUE ||
+		temp_threshold->start <= temp_threshold->end) {
+		return temp_threshold;
+	}
+	free(temp_threshold);
+	return NULL;
+}
 
 #ifdef NEED_GETTIMEOFDAY
 int

Index: utils.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.h,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- utils.h	25 Oct 2005 10:38:02 -0000	1.24
+++ utils.h	30 Jan 2006 16:10:50 -0000	1.25
@@ -58,6 +58,19 @@
 };
 #endif
 
+#define OUTSIDE 0
+#define INSIDE  1
+
+typedef struct threshold_struct {
+	double	start;
+	int	start_infinity;		/* FALSE (default) or TRUE */
+	double	end;
+	int	end_infinity;
+	int	alert_on;		/* OUTSIDE (default) or INSIDE */
+	} threshold;
+
+threshold *parse_threshold (char *);
+
 #ifndef HAVE_GETTIMEOFDAY
 int gettimeofday(struct timeval *, struct timezone *);
 #endif





More information about the Commits mailing list