[Nagiosplug-checkins] nagiosplug/plugins Makefile.am, 1.68, 1.69 check_disk.c, 1.71, 1.72 check_dns.c, 1.52, 1.53 check_mysql.c, 1.31, 1.32 check_mysql_query.c, 1.3, 1.4 utils.c, 1.49, 1.50 utils.h, 1.30, 1.31 utils_disk.c, 1.3, NONE utils_disk.h, 1.3, NONE

Ton Voon tonvoon at users.sourceforge.net
Thu Jul 13 14:50:25 CEST 2006


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

Modified Files:
	Makefile.am check_disk.c check_dns.c check_mysql.c 
	check_mysql_query.c utils.c utils.h 
Removed Files:
	utils_disk.c utils_disk.h 
Log Message:
Move new util_* functions to lib/


--- utils_disk.h DELETED ---

Index: utils.h
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.h,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- utils.h	13 Jul 2006 08:54:57 -0000	1.30
+++ utils.h	13 Jul 2006 12:50:21 -0000	1.31
@@ -20,7 +20,6 @@
 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 @@
 };
 #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 @@
  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 */

Index: check_mysql.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_mysql.c,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- check_mysql.c	15 Jun 2006 12:52:25 -0000	1.31
+++ check_mysql.c	13 Jul 2006 12:50:21 -0000	1.32
@@ -23,6 +23,7 @@
 
 #include "common.h"
 #include "utils.h"
+#include "utils_base.h"
 #include "netutils.h"
 
 #include <mysql.h>

--- utils_disk.c DELETED ---

Index: utils.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/utils.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -d -r1.49 -r1.50
--- utils.c	13 Jul 2006 08:54:57 -0000	1.49
+++ utils.c	13 Jul 2006 12:50:21 -0000	1.50
@@ -16,6 +16,7 @@
 
 #include "common.h"
 #include "utils.h"
+#include "utils_base.h"
 #include <stdarg.h>
 #include <limits.h>
 
@@ -132,16 +133,6 @@
 }
 
 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 @@
 		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 @@
 
 	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;
-}

Index: check_disk.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_disk.c,v
retrieving revision 1.71
retrieving revision 1.72
diff -u -d -r1.71 -r1.72
--- check_disk.c	12 Jul 2006 22:53:27 -0000	1.71
+++ check_disk.c	13 Jul 2006 12:50:21 -0000	1.72
@@ -45,6 +45,7 @@
 #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 @@
 # 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 *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 @@
 {
   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 @@
         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 @@
       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 @@
     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 @@
 
 
 int
-
 check_disk (double usp, uintmax_t free_disk, double uisp)
 {
        int result = STATE_UNKNOWN;

Index: Makefile.am
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/Makefile.am,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- Makefile.am	12 Jul 2006 12:15:42 -0000	1.68
+++ Makefile.am	13 Jul 2006 12:50:21 -0000	1.69
@@ -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 = @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 @@
 
 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 @@
 
 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)

Index: check_mysql_query.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_mysql_query.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- check_mysql_query.c	15 Jun 2006 12:52:25 -0000	1.3
+++ check_mysql_query.c	13 Jul 2006 12:50:21 -0000	1.4
@@ -20,6 +20,7 @@
 
 #include "common.h"
 #include "utils.h"
+#include "utils_base.h"
 #include "netutils.h"
 
 #include <mysql.h>

Index: check_dns.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_dns.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- check_dns.c	14 Jun 2006 21:27:38 -0000	1.52
+++ check_dns.c	13 Jul 2006 12:50:21 -0000	1.53
@@ -28,6 +28,7 @@
 
 #include "common.h"
 #include "utils.h"
+#include "utils_base.h"
 #include "netutils.h"
 #include "runcmd.h"
 





More information about the Commits mailing list