diff options
Diffstat (limited to 'plugins/check_users.c')
-rw-r--r-- | plugins/check_users.c | 38 |
1 files changed, 8 insertions, 30 deletions
diff --git a/plugins/check_users.c b/plugins/check_users.c index 8368612..fb8bcca 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c | |||
@@ -35,8 +35,8 @@ const char *copyright = "2000-2007"; | |||
35 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 35 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
36 | 36 | ||
37 | #include "common.h" | 37 | #include "common.h" |
38 | #include "popen.h" | ||
39 | #include "utils.h" | 38 | #include "utils.h" |
39 | #include <utmpx.h> | ||
40 | 40 | ||
41 | #define possibly_set(a,b) ((a) == 0 ? (b) : 0) | 41 | #define possibly_set(a,b) ((a) == 0 ? (b) : 0) |
42 | 42 | ||
@@ -54,6 +54,7 @@ main (int argc, char **argv) | |||
54 | int result = STATE_UNKNOWN; | 54 | int result = STATE_UNKNOWN; |
55 | char input_buffer[MAX_INPUT_BUFFER]; | 55 | char input_buffer[MAX_INPUT_BUFFER]; |
56 | char *perf; | 56 | char *perf; |
57 | struct utmpx *putmpx; | ||
57 | 58 | ||
58 | setlocale (LC_ALL, ""); | 59 | setlocale (LC_ALL, ""); |
59 | bindtextdomain (PACKAGE, LOCALEDIR); | 60 | bindtextdomain (PACKAGE, LOCALEDIR); |
@@ -67,43 +68,20 @@ main (int argc, char **argv) | |||
67 | if (process_arguments (argc, argv) == ERROR) | 68 | if (process_arguments (argc, argv) == ERROR) |
68 | usage4 (_("Could not parse arguments")); | 69 | usage4 (_("Could not parse arguments")); |
69 | 70 | ||
70 | /* run the command */ | ||
71 | child_process = spopen (WHO_COMMAND); | ||
72 | if (child_process == NULL) { | ||
73 | printf (_("Could not open pipe: %s\n"), WHO_COMMAND); | ||
74 | return STATE_UNKNOWN; | ||
75 | } | ||
76 | |||
77 | child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | ||
78 | if (child_stderr == NULL) | ||
79 | printf (_("Could not open stderr for %s\n"), WHO_COMMAND); | ||
80 | |||
81 | users = 0; | 71 | users = 0; |
82 | 72 | ||
83 | while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | 73 | /* get currently logged users from utmpx */ |
74 | setutxent(); | ||
84 | 75 | ||
85 | /* increment 'users' on all lines except total user count */ | 76 | while( (putmpx=getutxent()) ) { |
86 | if (input_buffer[0] != '#') { | 77 | if( (putmpx->ut_type==USER_PROCESS) ) { |
87 | users++; | 78 | users++; |
88 | continue; | ||
89 | } | 79 | } |
90 | |||
91 | /* get total logged in users */ | ||
92 | if (sscanf (input_buffer, _("# users=%d"), &users) == 1) | ||
93 | break; | ||
94 | |||
95 | } | 80 | } |
96 | 81 | ||
97 | /* check STDERR */ | 82 | endutxent(); |
98 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | ||
99 | result = possibly_set (result, STATE_UNKNOWN); | ||
100 | (void) fclose (child_stderr); | ||
101 | |||
102 | /* close the pipe */ | ||
103 | if (spclose (child_process)) | ||
104 | result = possibly_set (result, STATE_UNKNOWN); | ||
105 | 83 | ||
106 | /* else check the user count against warning and critical thresholds */ | 84 | /* check the user count against warning and critical thresholds */ |
107 | if (users > cusers) | 85 | if (users > cusers) |
108 | result = STATE_CRITICAL; | 86 | result = STATE_CRITICAL; |
109 | else if (users > wusers) | 87 | else if (users > wusers) |