diff options
Diffstat (limited to 'plugins/check_procs.c')
-rw-r--r-- | plugins/check_procs.c | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index c17c699..1fcbd98 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -14,6 +14,9 @@ | |||
14 | * defaults to number of processes. Search filters can be applied to limit | 14 | * defaults to number of processes. Search filters can be applied to limit |
15 | * the processes to check. | 15 | * the processes to check. |
16 | * | 16 | * |
17 | * The parent process, check_procs itself and any child process of | ||
18 | * check_procs (ps) are excluded from any checks to prevent false positives. | ||
19 | * | ||
17 | * | 20 | * |
18 | * This program is free software: you can redistribute it and/or modify | 21 | * This program is free software: you can redistribute it and/or modify |
19 | * it under the terms of the GNU General Public License as published by | 22 | * it under the terms of the GNU General Public License as published by |
@@ -153,7 +156,7 @@ main (int argc, char **argv) | |||
153 | int expected_cols = PS_COLS - 1; | 156 | int expected_cols = PS_COLS - 1; |
154 | int warn = 0; /* number of processes in warn state */ | 157 | int warn = 0; /* number of processes in warn state */ |
155 | int crit = 0; /* number of processes in crit state */ | 158 | int crit = 0; /* number of processes in crit state */ |
156 | int i = 0, j = 0; | 159 | int i = 0; |
157 | int result = STATE_UNKNOWN; | 160 | int result = STATE_UNKNOWN; |
158 | int ret = 0; | 161 | int ret = 0; |
159 | output chld_out, chld_err; | 162 | output chld_out, chld_err; |
@@ -207,7 +210,7 @@ main (int argc, char **argv) | |||
207 | } | 210 | } |
208 | 211 | ||
209 | /* flush first line: j starts at 1 */ | 212 | /* flush first line: j starts at 1 */ |
210 | for (j = 1; j < chld_out.lines; j++) { | 213 | for (size_t j = 1; j < chld_out.lines; j++) { |
211 | input_line = chld_out.line[j]; | 214 | input_line = chld_out.line[j]; |
212 | 215 | ||
213 | if (verbose >= 3) | 216 | if (verbose >= 3) |
@@ -241,8 +244,9 @@ main (int argc, char **argv) | |||
241 | 244 | ||
242 | /* Ignore self */ | 245 | /* Ignore self */ |
243 | if ((usepid && mypid == procpid) || | 246 | if ((usepid && mypid == procpid) || |
244 | (!usepid && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino) || | 247 | ( ((!usepid) && ((ret = stat_exe(procpid, &statbuf) != -1) && statbuf.st_dev == mydev && statbuf.st_ino == myino)) || |
245 | (ret == -1 && errno == ENOENT))) { | 248 | (ret == -1 && errno == ENOENT)) |
249 | ) { | ||
246 | if (verbose >= 3) | 250 | if (verbose >= 3) |
247 | printf("not considering - is myself or gone\n"); | 251 | printf("not considering - is myself or gone\n"); |
248 | continue; | 252 | continue; |
@@ -254,6 +258,13 @@ main (int argc, char **argv) | |||
254 | continue; | 258 | continue; |
255 | } | 259 | } |
256 | 260 | ||
261 | /* Ignore our own children */ | ||
262 | if (procppid == mypid) { | ||
263 | if (verbose >= 3) | ||
264 | printf("not considering - is our child\n"); | ||
265 | continue; | ||
266 | } | ||
267 | |||
257 | /* Ignore excluded processes by name */ | 268 | /* Ignore excluded processes by name */ |
258 | if(options & EXCLUDE_PROGS) { | 269 | if(options & EXCLUDE_PROGS) { |
259 | int found = 0; | 270 | int found = 0; |
@@ -727,18 +738,23 @@ convert_to_seconds(char *etime) { | |||
727 | void | 738 | void |
728 | print_help (void) | 739 | print_help (void) |
729 | { | 740 | { |
730 | print_revision (progname, NP_VERSION); | 741 | print_revision (progname, NP_VERSION); |
731 | 742 | ||
732 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | 743 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); |
733 | printf (COPYRIGHT, copyright, email); | 744 | printf (COPYRIGHT, copyright, email); |
734 | 745 | ||
735 | printf ("%s\n", _("Checks all processes and generates WARNING or CRITICAL states if the specified")); | 746 | printf ("%s\n", _("Checks all processes and generates WARNING or CRITICAL states if the specified")); |
736 | printf ("%s\n", _("metric is outside the required threshold ranges. The metric defaults to number")); | 747 | printf ("%s\n", _("metric is outside the required threshold ranges. The metric defaults to number")); |
737 | printf ("%s\n", _("of processes. Search filters can be applied to limit the processes to check.")); | 748 | printf ("%s\n", _("of processes. Search filters can be applied to limit the processes to check.")); |
738 | 749 | ||
739 | printf ("\n\n"); | 750 | printf ("\n\n"); |
740 | 751 | ||
741 | print_usage (); | 752 | printf ("%s\n", _("The parent process, check_procs itself and any child process of check_procs (ps)")); |
753 | printf ("%s\n", _("are excluded from any checks to prevent false positives.")); | ||
754 | |||
755 | printf ("\n\n"); | ||
756 | |||
757 | print_usage (); | ||
742 | 758 | ||
743 | printf (UT_HELP_VRSN); | 759 | printf (UT_HELP_VRSN); |
744 | printf (UT_EXTRA_OPTS); | 760 | printf (UT_EXTRA_OPTS); |
@@ -754,11 +770,11 @@ print_help (void) | |||
754 | printf (" %s\n", _("CPU - percentage CPU")); | 770 | printf (" %s\n", _("CPU - percentage CPU")); |
755 | /* only linux etime is support currently */ | 771 | /* only linux etime is support currently */ |
756 | #if defined( __linux__ ) | 772 | #if defined( __linux__ ) |
757 | printf (" %s\n", _("ELAPSED - time elapsed in seconds")); | 773 | printf (" %s\n", _("ELAPSED - time elapsed in seconds")); |
758 | #endif /* defined(__linux__) */ | 774 | #endif /* defined(__linux__) */ |
759 | printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 775 | printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
760 | 776 | ||
761 | printf (" %s\n", "-v, --verbose"); | 777 | printf (" %s\n", "-v, --verbose"); |
762 | printf (" %s\n", _("Extra information. Up to 3 verbosity levels")); | 778 | printf (" %s\n", _("Extra information. Up to 3 verbosity levels")); |
763 | 779 | ||
764 | printf (" %s\n", "-T, --traditional"); | 780 | printf (" %s\n", "-T, --traditional"); |
@@ -776,7 +792,7 @@ print_help (void) | |||
776 | printf (" %s\n", _("Only scan for processes with VSZ higher than indicated.")); | 792 | printf (" %s\n", _("Only scan for processes with VSZ higher than indicated.")); |
777 | printf (" %s\n", "-r, --rss=RSS"); | 793 | printf (" %s\n", "-r, --rss=RSS"); |
778 | printf (" %s\n", _("Only scan for processes with RSS higher than indicated.")); | 794 | printf (" %s\n", _("Only scan for processes with RSS higher than indicated.")); |
779 | printf (" %s\n", "-P, --pcpu=PCPU"); | 795 | printf (" %s\n", "-P, --pcpu=PCPU"); |
780 | printf (" %s\n", _("Only scan for processes with PCPU higher than indicated.")); | 796 | printf (" %s\n", _("Only scan for processes with PCPU higher than indicated.")); |
781 | printf (" %s\n", "-u, --user=USER"); | 797 | printf (" %s\n", "-u, --user=USER"); |
782 | printf (" %s\n", _("Only scan for processes with user name or ID indicated.")); | 798 | printf (" %s\n", _("Only scan for processes with user name or ID indicated.")); |
@@ -791,19 +807,19 @@ print_help (void) | |||
791 | printf (" %s\n", "-k, --no-kthreads"); | 807 | printf (" %s\n", "-k, --no-kthreads"); |
792 | printf (" %s\n", _("Only scan for non kernel threads (works on Linux only).")); | 808 | printf (" %s\n", _("Only scan for non kernel threads (works on Linux only).")); |
793 | 809 | ||
794 | printf(_("\n\ | 810 | printf(_("\n\ |
795 | RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\ | 811 | RANGEs are specified 'min:max' or 'min:' or ':max' (or 'max'). If\n\ |
796 | specified 'max:min', a warning status will be generated if the\n\ | 812 | specified 'max:min', a warning status will be generated if the\n\ |
797 | count is inside the specified range\n\n")); | 813 | count is inside the specified range\n\n")); |
798 | 814 | ||
799 | printf(_("\ | 815 | printf(_("\ |
800 | This plugin checks the number of currently running processes and\n\ | 816 | This plugin checks the number of currently running processes and\n\ |
801 | generates WARNING or CRITICAL states if the process count is outside\n\ | 817 | generates WARNING or CRITICAL states if the process count is outside\n\ |
802 | the specified threshold ranges. The process count can be filtered by\n\ | 818 | the specified threshold ranges. The process count can be filtered by\n\ |
803 | process owner, parent process PID, current state (e.g., 'Z'), or may\n\ | 819 | process owner, parent process PID, current state (e.g., 'Z'), or may\n\ |
804 | be the total number of running processes\n\n")); | 820 | be the total number of running processes\n\n")); |
805 | 821 | ||
806 | printf ("%s\n", _("Examples:")); | 822 | printf ("%s\n", _("Examples:")); |
807 | printf (" %s\n", "check_procs -w 2:2 -c 2:1024 -C portsentry"); | 823 | printf (" %s\n", "check_procs -w 2:2 -c 2:1024 -C portsentry"); |
808 | printf (" %s\n", _("Warning if not two processes with command name portsentry.")); | 824 | printf (" %s\n", _("Warning if not two processes with command name portsentry.")); |
809 | printf (" %s\n\n", _("Critical if < 2 or > 1024 processes")); | 825 | printf (" %s\n\n", _("Critical if < 2 or > 1024 processes")); |
@@ -820,14 +836,14 @@ be the total number of running processes\n\n")); | |||
820 | printf (" %s\n", "check_procs -w 10 -c 20 --metric=CPU"); | 836 | printf (" %s\n", "check_procs -w 10 -c 20 --metric=CPU"); |
821 | printf (" %s\n", _("Alert if CPU of any processes over 10\% or 20\%")); | 837 | printf (" %s\n", _("Alert if CPU of any processes over 10\% or 20\%")); |
822 | 838 | ||
823 | printf (UT_SUPPORT); | 839 | printf (UT_SUPPORT); |
824 | } | 840 | } |
825 | 841 | ||
826 | void | 842 | void |
827 | print_usage (void) | 843 | print_usage (void) |
828 | { | 844 | { |
829 | printf ("%s\n", _("Usage:")); | 845 | printf ("%s\n", _("Usage:")); |
830 | printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname); | 846 | printf ("%s -w <range> -c <range> [-m metric] [-s state] [-p ppid]\n", progname); |
831 | printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n"); | 847 | printf (" [-u user] [-r rss] [-z vsz] [-P %%cpu] [-a argument-array]\n"); |
832 | printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n"); | 848 | printf (" [-C command] [-X process_to_exclude] [-k] [-t timeout] [-v]\n"); |
833 | } | 849 | } |