diff options
Diffstat (limited to 'web/attachments/418908-0001-check_users-use-utxent-functions-to-get-data.patch')
-rw-r--r-- | web/attachments/418908-0001-check_users-use-utxent-functions-to-get-data.patch | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/web/attachments/418908-0001-check_users-use-utxent-functions-to-get-data.patch b/web/attachments/418908-0001-check_users-use-utxent-functions-to-get-data.patch new file mode 100644 index 0000000..84043bd --- /dev/null +++ b/web/attachments/418908-0001-check_users-use-utxent-functions-to-get-data.patch | |||
@@ -0,0 +1,98 @@ | |||
1 | From 10d9e2aadb3f7db0ab784a1843abcea570adf9ec Mon Sep 17 00:00:00 2001 | ||
2 | From: Marc Remy <mremy@gmx.ch> | ||
3 | Date: Wed, 20 Jul 2011 21:18:42 +0200 | ||
4 | Subject: [PATCH] check_users: use utxent functions to get data | ||
5 | |||
6 | --- | ||
7 | plugins/Makefile.am | 2 +- | ||
8 | plugins/check_users.c | 38 ++++++++------------------------------ | ||
9 | 2 files changed, 9 insertions(+), 31 deletions(-) | ||
10 | |||
11 | diff --git a/plugins/Makefile.am b/plugins/Makefile.am | ||
12 | index 36a28b0..3a2afc1 100644 | ||
13 | --- a/plugins/Makefile.am | ||
14 | +++ b/plugins/Makefile.am | ||
15 | @@ -101,7 +101,7 @@ check_tcp_LDADD = $(SSLOBJS) $(NETLIBS) $(SSLLIBS) | ||
16 | check_time_LDADD = $(NETLIBS) | ||
17 | check_ntp_time_LDADD = $(NETLIBS) $(MATHLIBS) | ||
18 | check_ups_LDADD = $(NETLIBS) | ||
19 | -check_users_LDADD = $(BASEOBJS) popen.o | ||
20 | +check_users_LDADD = $(BASEOBJS) | ||
21 | check_by_ssh_LDADD = $(NETLIBS) | ||
22 | check_ide_smart_LDADD = $(BASEOBJS) | ||
23 | negate_LDADD = $(BASEOBJS) | ||
24 | diff --git a/plugins/check_users.c b/plugins/check_users.c | ||
25 | index 8368612..fb8bcca 100644 | ||
26 | --- a/plugins/check_users.c | ||
27 | +++ b/plugins/check_users.c | ||
28 | @@ -35,8 +35,8 @@ const char *copyright = "2000-2007"; | ||
29 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
30 | |||
31 | #include "common.h" | ||
32 | -#include "popen.h" | ||
33 | #include "utils.h" | ||
34 | +#include <utmpx.h> | ||
35 | |||
36 | #define possibly_set(a,b) ((a) == 0 ? (b) : 0) | ||
37 | |||
38 | @@ -54,6 +54,7 @@ main (int argc, char **argv) | ||
39 | int result = STATE_UNKNOWN; | ||
40 | char input_buffer[MAX_INPUT_BUFFER]; | ||
41 | char *perf; | ||
42 | + struct utmpx *putmpx; | ||
43 | |||
44 | setlocale (LC_ALL, ""); | ||
45 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
46 | @@ -67,43 +68,20 @@ main (int argc, char **argv) | ||
47 | if (process_arguments (argc, argv) == ERROR) | ||
48 | usage4 (_("Could not parse arguments")); | ||
49 | |||
50 | - /* run the command */ | ||
51 | - child_process = spopen (WHO_COMMAND); | ||
52 | - if (child_process == NULL) { | ||
53 | - printf (_("Could not open pipe: %s\n"), WHO_COMMAND); | ||
54 | - return STATE_UNKNOWN; | ||
55 | - } | ||
56 | - | ||
57 | - child_stderr = fdopen (child_stderr_array[fileno (child_process)], "r"); | ||
58 | - if (child_stderr == NULL) | ||
59 | - printf (_("Could not open stderr for %s\n"), WHO_COMMAND); | ||
60 | - | ||
61 | users = 0; | ||
62 | |||
63 | - while (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_process)) { | ||
64 | + /* get currently logged users from utmpx */ | ||
65 | + setutxent(); | ||
66 | |||
67 | - /* increment 'users' on all lines except total user count */ | ||
68 | - if (input_buffer[0] != '#') { | ||
69 | + while( (putmpx=getutxent()) ) { | ||
70 | + if( (putmpx->ut_type==USER_PROCESS) ) { | ||
71 | users++; | ||
72 | - continue; | ||
73 | } | ||
74 | - | ||
75 | - /* get total logged in users */ | ||
76 | - if (sscanf (input_buffer, _("# users=%d"), &users) == 1) | ||
77 | - break; | ||
78 | - | ||
79 | } | ||
80 | |||
81 | - /* check STDERR */ | ||
82 | - if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | ||
83 | - result = possibly_set (result, STATE_UNKNOWN); | ||
84 | - (void) fclose (child_stderr); | ||
85 | - | ||
86 | - /* close the pipe */ | ||
87 | - if (spclose (child_process)) | ||
88 | - result = possibly_set (result, STATE_UNKNOWN); | ||
89 | + endutxent(); | ||
90 | |||
91 | - /* else check the user count against warning and critical thresholds */ | ||
92 | + /* check the user count against warning and critical thresholds */ | ||
93 | if (users > cusers) | ||
94 | result = STATE_CRITICAL; | ||
95 | else if (users > wusers) | ||
96 | -- | ||
97 | 1.7.2.5 | ||
98 | |||