Преглед изворни кода

Merge pull request #316 from Absolight/freebsd-jails

Add FreeBSD jail support to check_procs.
Bryan Heden пре 8 година
родитељ
комит
62463ad6df
4 измењених фајлова са 40 додато и 15 уклоњено
  1. 9 9
      README
  2. 10 0
      configure.ac
  3. 1 0
      plugins/check_nagios.c
  4. 20 6
      plugins/check_procs.c

+ 9 - 9
README

@@ -43,7 +43,7 @@ Installation Instructions
 1.  If you are using the Git tree, you will need m4, gettext, automake, and
     autoconf.  To start out, run:
 
-    	./tools/setup
+        ./tools/setup
 
     For more detail, see the developer guidelines at
     <https://www.nagios-plugins.org/doc/guidelines.html>.
@@ -51,7 +51,7 @@ Installation Instructions
 2.  Run the configure script to initialize variables and create a Makefile,
     etc.
 
-    	./configure --prefix=BASEDIRECTORY --with-cgiurl=SOMEURL
+        ./configure --prefix=BASEDIRECTORY --with-cgiurl=SOMEURL
 
     Replace `BASEDIRECTORY` with the path of the directory under which Nagios
     is installed (default is `/usr/local/nagios`), and replace `SOMEURL` with
@@ -60,12 +60,12 @@ Installation Instructions
 
 3.  Compile the plugins with the following command:
 
-    	make
+        make
 
 4.  Install the compiled plugins and plugin scripts with the following
     command:
 
-    	make install
+        make install
 
     The installation procedure will attempt to place the plugins in a
     `libexec/` subdirectory in the base directory you specified with the
@@ -75,7 +75,7 @@ Installation Instructions
     a non-root user, they will not be installed.  To install, switch to root
     and run:
 
-    	make install-root
+        make install-root
 
 That's it!  If you have any problems or questions, feel free to send an
 email to <help@nagios-plugins.org>.
@@ -87,15 +87,15 @@ Testing With libtap
 1.  The nagios-plugins source includes a perl testing suite.  the libtap 
     library and headers are included with the source.  Configure with:
 
-	./configure --enable-libtap
+        ./configure --enable-libtap
 
     Note: "--enable-extra-opts" used to be required as well, but is no 
     longer required as it is a default configure option.
 
 2.  Make and then make test:
 
-	make
-	make test
+        make
+        make test
 
 3.  Testing is pseudo intelligent and will try to autodetect which plugins
     to test.  You may need to look at the REQUIREMENTS doc as to what
@@ -104,7 +104,7 @@ Testing With libtap
     Additionally, default and user supplied (at runtime) testing parameters
     are saved in the file:
 
-	/var/tmp/NPTest.cache
+        /var/tmp/NPTest.cache
 
     If you need to change any testing parameters, edit them in this file
     or just remove the line to force the test to re-prompt you for input.

+ 10 - 0
configure.ac

@@ -786,6 +786,16 @@ then
 	ac_cv_ps_cols=10
 	AC_MSG_RESULT([$ac_cv_ps_command])
 
+dnl jails on FreeBSD:
+elif ps -axwo 'stat comm vsz rss user uid pid ppid jid args' 2>/dev/null | \
+	egrep -i "^ *STAT +COMMAND +VSZ +RSS +USER +UID +PID +PPID +JID +COMMAND" > /dev/null
+then
+	ac_cv_ps_varlist="procstat,&procuid,&procpid,&procppid,&procjid,&procvsz,&procrss,&procpcpu,procprog,&pos"
+	ac_cv_ps_command="$PATH_TO_PS -axwo 'stat uid pid ppid jid vsz rss pcpu comm args'"
+	ac_cv_ps_format="%s %d %d %d %d %d %d %f %s %n"
+	ac_cv_ps_cols=10
+	AC_MSG_RESULT([$ac_cv_ps_command])
+
 dnl Some gnu/linux systems (debian for one) don't like -axwwo and need axwwo.
 dnl so test for this first...
 elif ps axwwo 'stat comm vsz rss user uid pid ppid args' 2>/dev/null | \

+ 1 - 0
plugins/check_nagios.c

@@ -64,6 +64,7 @@ main (int argc, char **argv)
 	int procuid = 0;
 	int procpid = 0;
 	int procppid = 0;
+	int procjid = 0;
 	int procvsz = 0;
 	int procrss = 0;
 	char proc_cgroup_hierarchy[MAX_INPUT_BUFFER];

+ 20 - 6
plugins/check_procs.c

@@ -71,6 +71,7 @@ int options = 0; /* bitmask of filter criteria to test against */
 #define ELAPSED 512
 #define EREG_ARGS 1024
 #define CGROUP_HIERARCHY 2048
+#define JID 4096
 
 #define KTHREAD_PARENT "kthreadd" /* the parent process of kernel threads:
 							ppid of procs are compared to pid of this proc*/
@@ -103,6 +104,7 @@ char *fails;
 char tmp[MAX_INPUT_BUFFER];
 int kthread_filter = 0;
 int usepid = 0; /* whether to test for pid or /proc/pid/exe */
+int jid;
 
 FILE *ps_input = NULL;
 
@@ -133,6 +135,7 @@ main (int argc, char **argv)
 	int procuid = 0;
 	pid_t procpid = 0;
 	pid_t procppid = 0;
+	int procjid = 0;
 	pid_t kthread_ppid = 0;
 	int procvsz = 0;
 	int procrss = 0;
@@ -236,9 +239,9 @@ main (int argc, char **argv)
 			procseconds = convert_to_seconds(procetime);
 
 			if (verbose >= 3) {
-				printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s",
++				printf ("proc#=%d uid=%d vsz=%d rss=%d pid=%d ppid=%d jid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n",
 					procs, procuid, procvsz, procrss,
-					procpid, procppid, procpcpu, procstat,
+					procpid, procppid, procjid, procpcpu, procstat,
 					procetime, procprog, procargs);
 				if (strstr(PS_COMMAND, "cgroup") != NULL) {
 					printf(" proc_cgroup_hierarchy=%s\n", proc_cgroup_hierarchy);
@@ -287,6 +290,8 @@ main (int argc, char **argv)
 				resultsum |= PROG;
 			if ((options & PPID) && (procppid == ppid))
 				resultsum |= PPID;
+			if ((options & JID) && (procjid == jid))
+				resultsum |= JID;
 			if ((options & USER) && (procuid == uid))
 				resultsum |= USER;
 			if ((options & VSZ)  && (procvsz >= vsz))
@@ -315,9 +320,9 @@ main (int argc, char **argv)
 
 			procs++;
 			if (verbose >= 2) {
-				printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s",
++				printf ("Matched: uid=%d vsz=%d rss=%d pid=%d ppid=%d jid=%d pcpu=%.2f stat=%s etime=%s prog=%s args=%s\n",
 					procuid, procvsz, procrss,
-					procpid, procppid, procpcpu, procstat, 
+					procpid, procppid, procjid, procpcpu, procstat,
 					procetime, procprog, procargs);
 				if (strstr(PS_COMMAND, "cgroup") != NULL) {
 					printf(" cgroup_hierarchy=%s\n", cgroup_hierarchy);
@@ -438,6 +443,7 @@ process_arguments (int argc, char **argv)
 		{"no-kthreads", required_argument, 0, 'k'},
 		{"traditional-filter", no_argument, 0, 'T'},
 		{"cgroup-hierarchy", required_argument, 0, 'g'},
+		{"jid", required_argument, 0, 'j'},
 		{0, 0, 0, 0}
 	};
 
@@ -446,7 +452,7 @@ process_arguments (int argc, char **argv)
 			strcpy (argv[c], "-t");
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:Tg:",
+		c = getopt_long (argc, argv, "Vvhkt:c:w:p:s:u:C:a:z:r:m:P:Tg:j:",
 			longopts, &option);
 
 		if (c == -1 || c == EOF)
@@ -477,6 +483,12 @@ process_arguments (int argc, char **argv)
 				break;
 			}
 			usage4 (_("Parent Process ID must be an integer!"));
+		case 'j':                                   /* jail id */
+			if (sscanf (optarg, "%d%[^0-9]", &jid, tmp) == 1) {
+				xasprintf (&fmt, "%s%sJID = %d", (fmt ? fmt : "") , (options ? ", " : ""), jid);
+				options |= JID;
+				break;
+			}
 		case 's':									/* status */
 			if (statopts)
 				break;
@@ -766,6 +778,8 @@ print_help (void)
   printf ("   %s\n", _("RSZDT, plus others based on the output of your 'ps' command)."));
   printf (" %s\n", "-p, --ppid=PPID");
   printf ("   %s\n", _("Only scan for children of the parent process ID indicated."));
+  printf (" %s\n", "-j, --jid=JID");
+  printf ("   %s\n", _("Only scan for process running in jail which ID is JID."));
   printf (" %s\n", "-z, --vsz=VSZ");
   printf ("   %s\n", _("Only scan for processes with VSZ higher than indicated."));
   printf (" %s\n", "-r, --rss=RSS");
@@ -818,7 +832,7 @@ void
 print_usage (void)
 {
   printf ("%s\n", _("Usage:"));
-	printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname);
+	printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid] [-j jid]\n", progname);
   printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n");
   printf (" [-C command] [-k] [-t timeout] [-v]\n");
 }