summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_users.c60
-rw-r--r--plugins/utils.c41
-rw-r--r--plugins/utils.h34
3 files changed, 74 insertions, 61 deletions
diff --git a/plugins/check_users.c b/plugins/check_users.c
index 54415a4..a10249c 100644
--- a/plugins/check_users.c
+++ b/plugins/check_users.c
@@ -54,15 +54,15 @@ int process_arguments (int, char **);
54void print_help (void); 54void print_help (void);
55void print_usage (void); 55void print_usage (void);
56 56
57int wusers = -1; 57char *warning_range = NULL;
58int cusers = -1; 58char *critical_range = NULL;
59thresholds *thlds = NULL;
59 60
60int 61int
61main (int argc, char **argv) 62main (int argc, char **argv)
62{ 63{
63 int users = -1; 64 int users = -1;
64 int result = STATE_UNKNOWN; 65 int result = STATE_UNKNOWN;
65 char *perf;
66#if HAVE_WTSAPI32_H 66#if HAVE_WTSAPI32_H
67 WTS_SESSION_INFO *wtsinfo; 67 WTS_SESSION_INFO *wtsinfo;
68 DWORD wtscount; 68 DWORD wtscount;
@@ -77,8 +77,6 @@ main (int argc, char **argv)
77 bindtextdomain (PACKAGE, LOCALEDIR); 77 bindtextdomain (PACKAGE, LOCALEDIR);
78 textdomain (PACKAGE); 78 textdomain (PACKAGE);
79 79
80 perf = strdup ("");
81
82 /* Parse extra opts if any */ 80 /* Parse extra opts if any */
83 argv = np_extra_opts (&argc, argv, progname); 81 argv = np_extra_opts (&argc, argv, progname);
84 82
@@ -160,23 +158,15 @@ main (int argc, char **argv)
160#endif 158#endif
161 159
162 /* check the user count against warning and critical thresholds */ 160 /* check the user count against warning and critical thresholds */
163 if (users > cusers) 161 result = get_status((double)users, thlds);
164 result = STATE_CRITICAL;
165 else if (users > wusers)
166 result = STATE_WARNING;
167 else if (users >= 0)
168 result = STATE_OK;
169 162
170 if (result == STATE_UNKNOWN) 163 if (result == STATE_UNKNOWN)
171 printf ("%s\n", _("Unable to read output")); 164 printf ("%s\n", _("Unable to read output"));
172 else { 165 else {
173 xasprintf (&perf, "%s", perfdata ("users", users, "", 166 printf (_("USERS %s - %d users currently logged in |%s\n"),
174 TRUE, wusers, 167 state_text(result), users,
175 TRUE, cusers, 168 sperfdata_int("users", users, "", warning_range,
176 TRUE, 0, 169 critical_range, TRUE, 0, FALSE, 0));
177 FALSE, 0));
178 printf (_("USERS %s - %d users currently logged in |%s\n"), state_text (result),
179 users, perf);
180 } 170 }
181 171
182 return result; 172 return result;
@@ -215,33 +205,27 @@ process_arguments (int argc, char **argv)
215 print_revision (progname, NP_VERSION); 205 print_revision (progname, NP_VERSION);
216 exit (STATE_UNKNOWN); 206 exit (STATE_UNKNOWN);
217 case 'c': /* critical */ 207 case 'c': /* critical */
218 if (!is_intnonneg (optarg)) 208 critical_range = optarg;
219 usage4 (_("Critical threshold must be a positive integer"));
220 else
221 cusers = atoi (optarg);
222 break; 209 break;
223 case 'w': /* warning */ 210 case 'w': /* warning */
224 if (!is_intnonneg (optarg)) 211 warning_range = optarg;
225 usage4 (_("Warning threshold must be a positive integer"));
226 else
227 wusers = atoi (optarg);
228 break; 212 break;
229 } 213 }
230 } 214 }
231 215
232 c = optind; 216 c = optind;
233 if (wusers == -1 && argc > c) { 217 if (warning_range == NULL && argc > c)
234 if (is_intnonneg (argv[c]) == FALSE) 218 warning_range = argv[c++];
235 usage4 (_("Warning threshold must be a positive integer")); 219 if (critical_range == NULL && argc > c)
236 else 220 critical_range = argv[c++];
237 wusers = atoi (argv[c++]); 221
238 } 222 /* this will abort in case of invalid ranges */
239 if (cusers == -1 && argc > c) { 223 set_thresholds (&thlds, warning_range, critical_range);
240 if (is_intnonneg (argv[c]) == FALSE) 224
241 usage4 (_("Warning threshold must be a positive integer")); 225 if (thlds->warning->end <= 0)
242 else 226 usage4 (_("Warning threshold must be a positive integer"));
243 cusers = atoi (argv[c]); 227 if (thlds->critical->end <= 0)
244 } 228 usage4 (_("Critical threshold must be a positive integer"));
245 229
246 return OK; 230 return OK;
247} 231}
diff --git a/plugins/utils.c b/plugins/utils.c
index a864e4a..231af92 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -668,3 +668,44 @@ char *sperfdata (const char *label,
668 668
669 return data; 669 return data;
670} 670}
671
672char *sperfdata_int (const char *label,
673 int val,
674 const char *uom,
675 char *warn,
676 char *crit,
677 int minp,
678 int minv,
679 int maxp,
680 int maxv)
681{
682 char *data = NULL;
683 if (strpbrk (label, "'= "))
684 xasprintf (&data, "'%s'=", label);
685 else
686 xasprintf (&data, "%s=", label);
687
688 xasprintf (&data, "%s%d", data, val);
689 xasprintf (&data, "%s%s;", data, uom);
690
691 if (warn!=NULL)
692 xasprintf (&data, "%s%s", data, warn);
693
694 xasprintf (&data, "%s;", data);
695
696 if (crit!=NULL)
697 xasprintf (&data, "%s%s", data, crit);
698
699 xasprintf (&data, "%s;", data);
700
701 if (minp)
702 xasprintf (&data, "%s%d", data, minv);
703
704 if (maxp) {
705 xasprintf (&data, "%s;", data);
706 xasprintf (&data, "%s%d", data, maxv);
707 }
708
709 return data;
710}
711
diff --git a/plugins/utils.h b/plugins/utils.h
index 4c4aacc..a436e1c 100644
--- a/plugins/utils.h
+++ b/plugins/utils.h
@@ -94,29 +94,17 @@ const char *state_text (int);
94#define max(a,b) (((a)>(b))?(a):(b)) 94#define max(a,b) (((a)>(b))?(a):(b))
95#define min(a,b) (((a)<(b))?(a):(b)) 95#define min(a,b) (((a)<(b))?(a):(b))
96 96
97char *perfdata (const char *, 97char *perfdata (const char *, long int, const char *, int, long int,
98 long int, 98 int, long int, int, long int, int, long int);
99 const char *, 99
100 int, 100char *fperfdata (const char *, double, const char *, int, double,
101 long int, 101 int, double, int, double, int, double);
102 int, 102
103 long int, 103char *sperfdata (const char *, double, const char *, char *, char *,
104 int, 104 int, double, int, double);
105 long int, 105
106 int, 106char *sperfdata_int (const char *, int, const char *, char *, char *,
107 long int); 107 int, int, int, int);
108
109char *fperfdata (const char *,
110 double,
111 const char *,
112 int,
113 double,
114 int,
115 double,
116 int,
117 double,
118 int,
119 double);
120 108
121/* The idea here is that, although not every plugin will use all of these, 109/* The idea here is that, although not every plugin will use all of these,
122 most will or should. Therefore, for consistency, these very common 110 most will or should. Therefore, for consistency, these very common