ソースを参照

Merge branch 'maint' into check_disk-inode-perfdata

Sebastian Wolf 6 年 前
コミット
39972e33a3
4 ファイル変更107 行追加16 行削除
  1. 2 0
      NEWS
  2. 54 14
      plugins/check_disk.c
  3. 30 2
      plugins/check_pgsql.c
  4. 21 0
      plugins/utils.c

+ 2 - 0
NEWS

@@ -7,6 +7,7 @@ This file documents the major additions and syntax changes between releases.
 	Added directory plugins-python containing three Python plugins
 	check_apt: Add --only-critical switch
 	check_apt: Add --packages-warning (Marc Sánchez)
+	check_disk: Add --combined-thresholds to alert on a percentage AND raw units. 
 	check_disk: Add --inode-perfdata to get extra performance data from inode statistics
 	check_disk: Add -s option to show status for each path/partition
 	check_disk: Add support for base-10 units kB, MB, GB, TB; rename base-2 units to KiB, MiB, GiB, TiB
@@ -23,6 +24,7 @@ This file documents the major additions and syntax changes between releases.
 	check_ntp_time: Add support for monitoring stratum of timesources
 	check_oracle: Add support for Oracle XE databases (Peter Athaks)
 	check_ping: plugin output will now include hostname and IP address
+	check_pgsql: Add --print-query flag
 	check_procs: Add FreeBSD jail support (Mathieu Arnold)
 	check_procs: Allow process to be excluded from check_procs (Marcel Klein)
 	check_radius: Add calling-station-id (cejkar)

+ 54 - 14
plugins/check_disk.c

@@ -75,6 +75,9 @@ static int stat_remote_fs = 0;
 /* If nonzero, skip "fake" filesystems created by the system */
 static int skip_fake_fs = 0;
 
+/* If nonzero and -w/-c are set on both percentile and raw units, alert when either unit's threshold is crossed */
+static int combined_thresholds = 0;
+
 /* If positive, the units to use when printing sizes;
    if negative, the human-readable base.  */
 /* static int output_block_size; */
@@ -226,6 +229,7 @@ main (int argc, char **argv)
   double warning_high_tide;
   double critical_high_tide;
   int temp_result;
+  int temp_result2;
 
   struct mount_entry *me;
   struct mount_entry *last_me;
@@ -381,31 +385,58 @@ main (int argc, char **argv)
           me->me_mountdir, path->dused_pct, path->dfree_pct, (double)path->dused_units, (double)path->dfree_units, (double)path->dtotal_units, path->dused_inodes_percent, path->dfree_inodes_percent, fsp.fsu_blocksize, mult);
       }
 
-      /* Threshold comparisons */
+      /** Threshold comparisons
+       * If combined_thresholds is set, the "units" and "percent" will
+       * have their minimum state calculated, and the disk_result will be the
+       * maximum of these minima. 
+       * Note that both "units" and "percent" MUST be set, otherwise
+       * the check will always return OK.
+       *
+       * If combined_thresholds is not set, the maximum of all get_status() 
+       * calls will be used.
+       */
+
 
       temp_result = get_status(path->dfree_units, path->freespace_units);
       if (verbose_machine_output) printf("Freespace_units result=%d\n", temp_result);
-      disk_result = max_state( disk_result, temp_result );
+      temp_result2 = get_status(path->dfree_pct, path->freespace_percent);
+      if (verbose_machine_output) printf("Freespace%% result=%d\n", temp_result2);
 
-      temp_result = get_status(path->dfree_pct, path->freespace_percent);
-      if (verbose_machine_output) printf("Freespace%% result=%d\n", temp_result);
-      disk_result = max_state( disk_result, temp_result );
+      printf("dfree_units %d %d\n", temp_result, temp_result2);
+      if (combined_thresholds) {
+        temp_result = min_state(temp_result, temp_result2);
+      }
+      else {
+        temp_result = max_state(temp_result, temp_result2);
+      }
+      disk_result = max_state(disk_result, temp_result);
+      printf("disk_result is %d", disk_result);
 
       temp_result = get_status(path->dused_units, path->usedspace_units);
       if (verbose_machine_output) printf("Usedspace_units result=%d\n", temp_result);
-      disk_result = max_state( disk_result, temp_result );
+      temp_result2 = get_status(path->dused_pct, path->usedspace_percent);
+      if (verbose_machine_output) printf("Usedspace_percent result=%d\n", temp_result2);
 
-      temp_result = get_status(path->dused_pct, path->usedspace_percent);
-      if (verbose_machine_output) printf("Usedspace_percent result=%d\n", temp_result);
-      disk_result = max_state( disk_result, temp_result );
+      if (combined_thresholds) {
+        temp_result = min_state(temp_result, temp_result2);
+      }
+      else {
+        temp_result = max_state(temp_result, temp_result2);
+      }
+      disk_result = max_state(disk_result, temp_result);
 
       temp_result = get_status(path->dused_inodes_percent, path->usedinodes_percent);
       if (verbose_machine_output) printf("Usedinodes_percent result=%d\n", temp_result);
-      disk_result = max_state( disk_result, temp_result );
+      temp_result2 = get_status(path->dfree_inodes_percent, path->freeinodes_percent);
+      if (verbose_machine_output) printf("Freeinodes_percent result=%d\n", temp_result2);
 
-      temp_result = get_status(path->dfree_inodes_percent, path->freeinodes_percent);
-      if (verbose_machine_output) printf("Freeinodes_percent result=%d\n", temp_result);
-      disk_result = max_state( disk_result, temp_result );
+      if (combined_thresholds) {
+        temp_result = min_state(temp_result, temp_result2);
+      }
+      else {
+        temp_result = max_state(temp_result, temp_result2);
+      }
+      disk_result = max_state(disk_result, temp_result);
 
       result = max_state(result, disk_result);
 
@@ -608,6 +639,7 @@ process_arguments (int argc, char **argv)
   enum {
     SKIP_FAKE_FS = CHAR_MAX + 1,
     INODE_PERFDATA_ENABLED,
+    COMBINED_THRESHOLDS,
   };
 
   int option = 0;
@@ -615,6 +647,7 @@ process_arguments (int argc, char **argv)
     {"timeout", required_argument, 0, 't'},
     {"warning", required_argument, 0, 'w'},
     {"critical", required_argument, 0, 'c'},
+    {"combined-thresholds", no_argument, 0, COMBINED_THRESHOLDS},
     {"iwarning", required_argument, 0, 'W'},
     /* Dang, -C is taken. We might want to reshuffle this. */
     {"icritical", required_argument, 0, 'K'},
@@ -712,6 +745,10 @@ process_arguments (int argc, char **argv)
       }
       break;
 
+    case COMBINED_THRESHOLDS:
+      combined_thresholds = 1;
+      break;
+
     case 'W':			/* warning inode threshold */
       if (*optarg == '@') {
         warn_freeinodes_percent = optarg;
@@ -1096,6 +1133,9 @@ print_help (void)
   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 CRITICAL status if less than PERCENT of disk space is free"));
+  printf (" %s\n", "    --combined-thresholds");
+  printf ("    %s\n", _("Do not alert at a given level unless \"PERCENT\" AND \"INTEGER units\""));
+  printf ("    %s\n", _("thresholds are met. For an OR condition, don't use this flag."));
   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%");
@@ -1173,7 +1213,7 @@ print_usage (void)
   printf ("%s\n", _("Usage:"));
   printf (" %s -w limit -c limit [-W limit] [-K limit] {-p path | -x device}\n", progname);
   printf ("[-C] [-E] [-e] [-f] [-g group ] [-H] [-k] [-l] [-M] [-m] [-R path ] [-r path ]\n");
-  printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type] [-n] \n");
+  printf ("[-t timeout] [-u unit] [-v] [-X type] [-N type] [-n] [--combined-thresholds ]\n");
 }
 
 void

+ 30 - 2
plugins/check_pgsql.c

@@ -86,6 +86,7 @@ double tcrit = (double)DEFAULT_CRIT;
 char *pgquery = NULL;
 char *query_warning = NULL;
 char *query_critical = NULL;
+static int print_query = 0;
 thresholds *qthresholds = NULL;
 int verbose = 0;
 
@@ -286,6 +287,7 @@ process_arguments (int argc, char **argv)
 		{"query", required_argument, 0, 'q'},
 		{"query_critical", required_argument, 0, 'C'},
 		{"query_warning", required_argument, 0, 'W'},
+		{"print-query", no_argument, 0, 'r'},
 		{"verbose", no_argument, 0, 'v'},
 		{0, 0, 0, 0}
 	};
@@ -327,6 +329,9 @@ process_arguments (int argc, char **argv)
 		case 'W':     /* warning query threshold */
 			query_warning = optarg;
 			break;
+		case 'r':
+			print_query = 1;
+			break;
 		case 'H':     /* host */
 			if ((*optarg != '/') && (!is_host (optarg)))
 				usage2 (_("Invalid hostname/address"), optarg);
@@ -515,7 +520,8 @@ print_help (void)
 	printf (" %s\n", "-l, --logname = STRING");
 	printf ("    %s\n", _("Login name of user"));
 	printf (" %s\n", "-p, --password = STRING");
-	printf ("    %s\n", _("Password (BIG SECURITY ISSUE)"));
+	printf ("    %s\n", _("The user's password. To avoid security issues, define this option using"));
+	printf ("    %s\n", _("--extra-opts when possible."));
 	printf (" %s\n", "-o, --option = STRING");
 	printf ("    %s\n", _("Connection parameters (keyword = value), see below"));
 
@@ -529,6 +535,8 @@ print_help (void)
 	printf ("    %s\n", _("SQL query value to result in warning status (double)"));
 	printf (" %s\n", "-C, --query-critical=RANGE");
 	printf ("    %s\n", _("SQL query value to result in critical status (double)"));
+	printf (" %s\n", "-r,  --print-query");
+	printf ("    %s\n", _("Print the output of the entire query to extended plugin output."));
 
 	printf (UT_VERBOSE);
 
@@ -575,7 +583,7 @@ print_usage (void)
 	printf ("%s\n", _("Usage:"));
 	printf ("%s [-H <host>] [-P <port>] [-c <critical time>] [-w <warning time>]\n", progname);
 	printf (" [-t <timeout>] [-d <database>] [-l <logname>] [-p <password>]\n"
-			"[-q <query>] [-C <critical query range>] [-W <warning query range>]\n");
+			"[-q <query>] [-C <critical query range>] [-W <warning query range>] [-r]\n");
 }
 
 int
@@ -590,6 +598,9 @@ do_query (PGconn *conn, char *query)
 
 	int my_status = STATE_UNKNOWN;
 
+	// Only used for print_query block at the end of this function
+	PQprintOpt po;
+
 	if (verbose)
 		printf ("Executing SQL query \"%s\".\n", query);
 	res = PQexec (conn, query);
@@ -642,6 +653,23 @@ do_query (PGconn *conn, char *query)
 	printf ("|query=%f;%s;%s;;\n", value,
 			query_warning ? query_warning : "",
 			query_critical ? query_critical : "");
+
+	if (print_query) {
+		printf("\n");
+		po.header = 1;
+		po.align = 1;
+		po.standard = 1;
+		po.html3 = 0;
+		po.expanded = 0;
+		po.pager = 0;
+		po.fieldSep = "|";
+		po.tableOpt = NULL;
+		po.caption = NULL;
+		po.fieldName = NULL;
+
+		PQprint(stdout, res, &po);
+	}
+
 	return my_status;
 }
 

+ 21 - 0
plugins/utils.c

@@ -67,6 +67,27 @@ max_state (int a, int b)
 		return max (a, b);
 }
 
+/* **************************************************************************
+ * min_state(STATE_x, STATE_y)
+ * does the opposite of max_state(): returns the minimum of both states using
+ * the ordder STATE_UNKNOWN < STATE_OK < STATE_WARNING < STATE_CRITICAL
+ ****************************************************************************/
+int min_state (int a, int b)
+{
+	if (a == STATE_UNKNOWN || b == STATE_UNKNOWN)
+		return STATE_UNKNOWN;
+	else if (a == STATE_OK || b == STATE_OK)
+		return STATE_OK;
+	else if (a == STATE_WARNING || b == STATE_WARNING)
+		return STATE_WARNING;
+	else if (a == STATE_CRITICAL || b == STATE_CRITICAL)
+		return STATE_CRITICAL;
+	else if (a == STATE_DEPENDENT || b == STATE_DEPENDENT)
+		return STATE_DEPENDENT;
+	else
+		return min(a, b);
+}
+
 /* **************************************************************************
  * max_state_alt(STATE_x, STATE_y)
  * compares STATE_x to  STATE_y and returns result based on the following