summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_users.c38
1 files changed, 14 insertions, 24 deletions
diff --git a/plugins/check_users.c b/plugins/check_users.c
index fb8bcca..3766292 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -3,7 +3,7 @@
3* Nagios check_users plugin 3* Nagios check_users plugin
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2000-2007 Nagios Plugins Development Team 6* Copyright (c) 2000-2012 Nagios Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
@@ -52,7 +52,6 @@ main (int argc, char **argv)
52{ 52{
53 int users = -1; 53 int users = -1;
54 int result = STATE_UNKNOWN; 54 int result = STATE_UNKNOWN;
55 char input_buffer[MAX_INPUT_BUFFER];
56 char *perf; 55 char *perf;
57 struct utmpx *putmpx; 56 struct utmpx *putmpx;
58 57
@@ -60,10 +59,10 @@ main (int argc, char **argv)
60 bindtextdomain (PACKAGE, LOCALEDIR); 59 bindtextdomain (PACKAGE, LOCALEDIR);
61 textdomain (PACKAGE); 60 textdomain (PACKAGE);
62 61
63 perf = strdup(""); 62 perf = strdup ("");
64 63
65 /* Parse extra opts if any */ 64 /* Parse extra opts if any */
66 argv=np_extra_opts (&argc, argv, progname); 65 argv = np_extra_opts (&argc, argv, progname);
67 66
68 if (process_arguments (argc, argv) == ERROR) 67 if (process_arguments (argc, argv) == ERROR)
69 usage4 (_("Could not parse arguments")); 68 usage4 (_("Could not parse arguments"));
@@ -71,15 +70,13 @@ main (int argc, char **argv)
71 users = 0; 70 users = 0;
72 71
73 /* get currently logged users from utmpx */ 72 /* get currently logged users from utmpx */
74 setutxent(); 73 setutxent ();
75 74
76 while( (putmpx=getutxent()) ) { 75 while ((putmpx = getutxent ()) != NULL)
77 if( (putmpx->ut_type==USER_PROCESS) ) { 76 if (putmpx->ut_type == USER_PROCESS)
78 users++; 77 users++;
79 }
80 }
81 78
82 endutxent(); 79 endutxent ();
83 80
84 /* check the user count against warning and critical thresholds */ 81 /* check the user count against warning and critical thresholds */
85 if (users > cusers) 82 if (users > cusers)
@@ -92,7 +89,7 @@ main (int argc, char **argv)
92 if (result == STATE_UNKNOWN) 89 if (result == STATE_UNKNOWN)
93 printf ("%s\n", _("Unable to read output")); 90 printf ("%s\n", _("Unable to read output"));
94 else { 91 else {
95 asprintf(&perf, "%s", perfdata ("users", users, "", 92 asprintf (&perf, "%s", perfdata ("users", users, "",
96 TRUE, wusers, 93 TRUE, wusers,
97 TRUE, cusers, 94 TRUE, cusers,
98 TRUE, 0, 95 TRUE, 0,
@@ -104,14 +101,11 @@ main (int argc, char **argv)
104 return result; 101 return result;
105} 102}
106 103
107
108
109/* process command-line arguments */ 104/* process command-line arguments */
110int 105int
111process_arguments (int argc, char **argv) 106process_arguments (int argc, char **argv)
112{ 107{
113 int c; 108 int c;
114
115 int option = 0; 109 int option = 0;
116 static struct option longopts[] = { 110 static struct option longopts[] = {
117 {"critical", required_argument, 0, 'c'}, 111 {"critical", required_argument, 0, 'c'},
@@ -161,7 +155,6 @@ process_arguments (int argc, char **argv)
161 else 155 else
162 wusers = atoi (argv[c++]); 156 wusers = atoi (argv[c++]);
163 } 157 }
164
165 if (cusers == -1 && argc > c) { 158 if (cusers == -1 && argc > c) {
166 if (is_intnonneg (argv[c]) == FALSE) 159 if (is_intnonneg (argv[c]) == FALSE)
167 usage4 (_("Warning threshold must be a positive integer")); 160 usage4 (_("Warning threshold must be a positive integer"));
@@ -172,8 +165,6 @@ process_arguments (int argc, char **argv)
172 return OK; 165 return OK;
173} 166}
174 167
175
176
177void 168void
178print_help (void) 169print_help (void)
179{ 170{
@@ -183,9 +174,9 @@ print_help (void)
183 printf (COPYRIGHT, copyright, email); 174 printf (COPYRIGHT, copyright, email);
184 175
185 printf ("%s\n", _("This plugin checks the number of users currently logged in on the local")); 176 printf ("%s\n", _("This plugin checks the number of users currently logged in on the local"));
186 printf ("%s\n", _("system and generates an error if the number exceeds the thresholds specified.")); 177 printf ("%s\n", _("system and generates an error if the number exceeds the thresholds specified."));
187 178
188 printf ("\n\n"); 179 printf ("\n\n");
189 180
190 print_usage (); 181 print_usage ();
191 182
@@ -193,17 +184,16 @@ print_help (void)
193 printf (UT_EXTRA_OPTS); 184 printf (UT_EXTRA_OPTS);
194 185
195 printf (" %s\n", "-w, --warning=INTEGER"); 186 printf (" %s\n", "-w, --warning=INTEGER");
196 printf (" %s\n", _("Set WARNING status if more than INTEGER users are logged in")); 187 printf (" %s\n", _("Set WARNING status if more than INTEGER users are logged in"));
197 printf (" %s\n", "-c, --critical=INTEGER"); 188 printf (" %s\n", "-c, --critical=INTEGER");
198 printf (" %s\n", _("Set CRITICAL status if more than INTEGER users are logged in")); 189 printf (" %s\n", _("Set CRITICAL status if more than INTEGER users are logged in"));
199 190
200 printf (UT_SUPPORT); 191 printf (UT_SUPPORT);
201} 192}
202 193
203
204void 194void
205print_usage (void) 195print_usage (void)
206{ 196{
207 printf ("%s\n", _("Usage:")); 197 printf ("%s\n", _("Usage:"));
208 printf ("%s -w <users> -c <users>\n", progname); 198 printf ("%s -w <users> -c <users>\n", progname);
209} 199}