summaryrefslogtreecommitdiffstats
path: root/plugins/check_nt.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_nt.c')
-rw-r--r--plugins/check_nt.c1179
1 files changed, 567 insertions, 612 deletions
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index 19c050de..7dd23e5c 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -1,336 +1,291 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_nt plugin 3 * Monitoring check_nt plugin
4* 4 *
5* License: GPL 5 * License: GPL
6* Copyright (c) 2000-2002 Yves Rubin (rubiyz@yahoo.com) 6 * Copyright (c) 2000-2002 Yves Rubin (rubiyz@yahoo.com)
7* Copyright (c) 2003-2007 Monitoring Plugins Development Team 7 * Copyright (c) 2003-2024 Monitoring Plugins Development Team
8* 8 *
9* Description: 9 * Description:
10* 10 *
11* This file contains the check_nt plugin 11 * This file contains the check_nt plugin
12* 12 *
13* This plugin collects data from the NSClient service running on a 13 * This plugin collects data from the NSClient service running on a
14* Windows NT/2000/XP/2003 server. 14 * Windows NT/2000/XP/2003 server.
15* This plugin requires NSClient software to run on NT 15 * This plugin requires NSClient software to run on NT
16* (http://nsclient.ready2run.nl/) 16 * (https://nsclient.org/)
17* 17 *
18* 18 *
19* This program is free software: you can redistribute it and/or modify 19 * This program is free software: you can redistribute it and/or modify
20* it under the terms of the GNU General Public License as published by 20 * it under the terms of the GNU General Public License as published by
21* the Free Software Foundation, either version 3 of the License, or 21 * the Free Software Foundation, either version 3 of the License, or
22* (at your option) any later version. 22 * (at your option) any later version.
23* 23 *
24* This program is distributed in the hope that it will be useful, 24 * This program is distributed in the hope that it will be useful,
25* but WITHOUT ANY WARRANTY; without even the implied warranty of 25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27* GNU General Public License for more details. 27 * GNU General Public License for more details.
28* 28 *
29* You should have received a copy of the GNU General Public License 29 * You should have received a copy of the GNU General Public License
30* along with this program. If not, see <http://www.gnu.org/licenses/>. 30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
31* 31 *
32* 32 *
33*****************************************************************************/ 33 *****************************************************************************/
34 34
35const char *progname = "check_nt"; 35const char *progname = "check_nt";
36const char *copyright = "2000-2007"; 36const char *copyright = "2000-2024";
37const char *email = "devel@monitoring-plugins.org"; 37const char *email = "devel@monitoring-plugins.org";
38 38
39#include "common.h" 39#include "common.h"
40#include "netutils.h" 40#include "netutils.h"
41#include "utils.h" 41#include "utils.h"
42 42#include "check_nt.d/config.h"
43enum checkvars {
44 CHECK_NONE,
45 CHECK_CLIENTVERSION,
46 CHECK_CPULOAD,
47 CHECK_UPTIME,
48 CHECK_USEDDISKSPACE,
49 CHECK_SERVICESTATE,
50 CHECK_PROCSTATE,
51 CHECK_MEMUSE,
52 CHECK_COUNTER,
53 CHECK_FILEAGE,
54 CHECK_INSTANCES
55};
56 43
57enum { 44enum {
58 MAX_VALUE_LIST = 30, 45 MAX_VALUE_LIST = 30,
59 PORT = 1248
60}; 46};
61 47
62char *server_address=NULL; 48static char recv_buffer[MAX_INPUT_BUFFER];
63char *volume_name=NULL;
64int server_port=PORT;
65char *value_list=NULL;
66char *req_password=NULL;
67unsigned long lvalue_list[MAX_VALUE_LIST];
68unsigned long warning_value=0L;
69unsigned long critical_value=0L;
70bool check_warning_value=false;
71bool check_critical_value=false;
72enum checkvars vars_to_check = CHECK_NONE;
73bool show_all = false;
74
75char recv_buffer[MAX_INPUT_BUFFER];
76
77void fetch_data (const char* address, int port, const char* sendb);
78int process_arguments(int, char **);
79void preparelist(char *string);
80bool strtoularray(unsigned long *array, char *string, const char *delim);
81void print_help(void);
82void print_usage(void);
83 49
84int main(int argc, char **argv){ 50static void fetch_data(const char *address, int port, const char *sendb);
85 51
86/* should be int result = STATE_UNKNOWN; */ 52typedef struct {
53 int errorcode;
54 check_nt_config config;
55} check_nt_config_wrapper;
56static check_nt_config_wrapper process_arguments(int /*argc*/, char ** /*argv*/);
87 57
88 int return_code = STATE_UNKNOWN; 58static void preparelist(char *string);
89 char *send_buffer=NULL; 59static bool strtoularray(unsigned long *array, char *string, const char *delim);
90 char *output_message=NULL; 60static void print_help(void);
91 char *perfdata=NULL; 61void print_usage(void);
92 char *temp_string=NULL; 62
93 char *temp_string_perf=NULL; 63int main(int argc, char **argv) {
94 char *description=NULL,*counter_unit = NULL; 64 setlocale(LC_ALL, "");
95 char *minval = NULL, *maxval = NULL, *errcvt = NULL; 65 bindtextdomain(PACKAGE, LOCALEDIR);
96 char *fds=NULL, *tds=NULL; 66 textdomain(PACKAGE);
97 char *numstr;
98
99 double total_disk_space=0;
100 double free_disk_space=0;
101 double percent_used_space=0;
102 double warning_used_space=0;
103 double critical_used_space=0;
104 double mem_commitLimit=0;
105 double mem_commitByte=0;
106 double fminval = 0, fmaxval = 0;
107 unsigned long utilization;
108 unsigned long uptime;
109 unsigned long age_in_minutes;
110 double counter_value = 0.0;
111 int offset=0;
112 int updays=0;
113 int uphours=0;
114 int upminutes=0;
115
116 bool isPercent = false;
117 bool allRight = false;
118
119 setlocale (LC_ALL, "");
120 bindtextdomain (PACKAGE, LOCALEDIR);
121 textdomain (PACKAGE);
122 67
123 /* Parse extra opts if any */ 68 /* Parse extra opts if any */
124 argv=np_extra_opts (&argc, argv, progname); 69 argv = np_extra_opts(&argc, argv, progname);
70
71 check_nt_config_wrapper tmp_config = process_arguments(argc, argv);
72 if (tmp_config.errorcode == ERROR) {
73 usage4(_("Could not parse arguments"));
74 }
125 75
126 if(process_arguments(argc,argv) == ERROR) 76 const check_nt_config config = tmp_config.config;
127 usage4 (_("Could not parse arguments"));
128 77
129 /* initialize alarm signal handling */ 78 /* initialize alarm signal handling */
130 signal(SIGALRM,socket_timeout_alarm_handler); 79 signal(SIGALRM, socket_timeout_alarm_handler);
131 80
132 /* set socket timeout */ 81 /* set socket timeout */
133 alarm(socket_timeout); 82 alarm(socket_timeout);
134 83
135 switch (vars_to_check) { 84 int return_code = STATE_UNKNOWN;
136 85 char *send_buffer = NULL;
86 char *output_message = NULL;
87 char *perfdata = NULL;
88 char *temp_string = NULL;
89 char *temp_string_perf = NULL;
90 char *description = NULL;
91 char *counter_unit = NULL;
92 char *errcvt = NULL;
93 unsigned long lvalue_list[MAX_VALUE_LIST];
94 switch (config.vars_to_check) {
137 case CHECK_CLIENTVERSION: 95 case CHECK_CLIENTVERSION:
138 96 xasprintf(&send_buffer, "%s&1", config.req_password);
139 xasprintf(&send_buffer, "%s&1", req_password); 97 fetch_data(config.server_address, config.server_port, send_buffer);
140 fetch_data (server_address, server_port, send_buffer); 98 if (config.value_list != NULL && strcmp(recv_buffer, config.value_list) != 0) {
141 if (value_list != NULL && strcmp(recv_buffer, value_list) != 0) { 99 xasprintf(&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, config.value_list);
142 xasprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list);
143 return_code = STATE_WARNING; 100 return_code = STATE_WARNING;
144 } else { 101 } else {
145 xasprintf (&output_message, "%s", recv_buffer); 102 xasprintf(&output_message, "%s", recv_buffer);
146 return_code = STATE_OK; 103 return_code = STATE_OK;
147 } 104 }
148 break; 105 break;
149
150 case CHECK_CPULOAD: 106 case CHECK_CPULOAD:
151 107 if (config.value_list == NULL) {
152 if (value_list==NULL) 108 output_message = strdup(_("missing -l parameters"));
153 output_message = strdup (_("missing -l parameters")); 109 } else if (!strtoularray(lvalue_list, config.value_list, ",")) {
154 else if (! strtoularray(lvalue_list,value_list,",")) 110 output_message = strdup(_("wrong -l parameter."));
155 output_message = strdup (_("wrong -l parameter.")); 111 } else {
156 else {
157 /* -l parameters is present with only integers */ 112 /* -l parameters is present with only integers */
158 return_code=STATE_OK; 113 return_code = STATE_OK;
159 temp_string = strdup (_("CPU Load")); 114 temp_string = strdup(_("CPU Load"));
160 temp_string_perf = strdup (" "); 115 temp_string_perf = strdup(" ");
161 116
162 /* loop until one of the parameters is wrong or not present */ 117 /* loop until one of the parameters is wrong or not present */
163 while (lvalue_list[0+offset]> (unsigned long)0 && 118 int offset = 0;
164 lvalue_list[0+offset]<=(unsigned long)17280 && 119 while (lvalue_list[0 + offset] > (unsigned long)0 && lvalue_list[0 + offset] <= (unsigned long)17280 &&
165 lvalue_list[1+offset]> (unsigned long)0 && 120 lvalue_list[1 + offset] > (unsigned long)0 && lvalue_list[1 + offset] <= (unsigned long)100 &&
166 lvalue_list[1+offset]<=(unsigned long)100 && 121 lvalue_list[2 + offset] > (unsigned long)0 && lvalue_list[2 + offset] <= (unsigned long)100) {
167 lvalue_list[2+offset]> (unsigned long)0 &&
168 lvalue_list[2+offset]<=(unsigned long)100) {
169 122
170 /* Send request and retrieve data */ 123 /* Send request and retrieve data */
171 xasprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]); 124 xasprintf(&send_buffer, "%s&2&%lu", config.req_password, lvalue_list[0 + offset]);
172 fetch_data (server_address, server_port, send_buffer); 125 fetch_data(config.server_address, config.server_port, send_buffer);
173 126
174 utilization=strtoul(recv_buffer,NULL,10); 127 unsigned long utilization = strtoul(recv_buffer, NULL, 10);
175 128
176 /* Check if any of the request is in a warning or critical state */ 129 /* Check if any of the request is in a warning or critical state */
177 if(utilization >= lvalue_list[2+offset]) 130 if (utilization >= lvalue_list[2 + offset]) {
178 return_code=STATE_CRITICAL; 131 return_code = STATE_CRITICAL;
179 else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING) 132 } else if (utilization >= lvalue_list[1 + offset] && return_code < STATE_WARNING) {
180 return_code=STATE_WARNING; 133 return_code = STATE_WARNING;
181 134 }
182 xasprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]); 135
183 xasprintf(&temp_string,"%s%s",temp_string,output_message); 136 xasprintf(&output_message, _(" %lu%% (%lu min average)"), utilization, lvalue_list[0 + offset]);
184 xasprintf(&perfdata,_(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0+offset], utilization, 137 xasprintf(&temp_string, "%s%s", temp_string, output_message);
185 lvalue_list[1+offset], lvalue_list[2+offset]); 138 xasprintf(&perfdata, _(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0 + offset], utilization,
186 xasprintf(&temp_string_perf,"%s%s",temp_string_perf,perfdata); 139 lvalue_list[1 + offset], lvalue_list[2 + offset]);
187 offset+=3; /* move across the array */ 140 xasprintf(&temp_string_perf, "%s%s", temp_string_perf, perfdata);
141 offset += 3; /* move across the array */
188 } 142 }
189 143
190 if (strlen(temp_string)>10) { /* we had at least one loop */ 144 if (strlen(temp_string) > 10) { /* we had at least one loop */
191 output_message = strdup (temp_string); 145 output_message = strdup(temp_string);
192 perfdata = temp_string_perf; 146 perfdata = temp_string_perf;
193 } else 147 } else {
194 output_message = strdup (_("not enough values for -l parameters")); 148 output_message = strdup(_("not enough values for -l parameters"));
149 }
195 } 150 }
196 break; 151 break;
197 152 case CHECK_UPTIME: {
198 case CHECK_UPTIME: 153 char *tmp_value_list = config.value_list;
199 154 if (config.value_list == NULL) {
200 if (value_list == NULL) { 155 tmp_value_list = "minutes";
201 value_list = "minutes";
202 } 156 }
203 if (strncmp(value_list, "seconds", strlen("seconds") + 1 ) && 157 if (strncmp(tmp_value_list, "seconds", strlen("seconds") + 1) && strncmp(tmp_value_list, "minutes", strlen("minutes") + 1) &&
204 strncmp(value_list, "minutes", strlen("minutes") + 1) && 158 strncmp(config.value_list, "hours", strlen("hours") + 1) && strncmp(tmp_value_list, "days", strlen("days") + 1)) {
205 strncmp(value_list, "hours", strlen("hours") + 1) &&
206 strncmp(value_list, "days", strlen("days") + 1)) {
207 159
208 output_message = strdup (_("wrong -l argument")); 160 output_message = strdup(_("wrong -l argument"));
209 } else { 161 } else {
210 xasprintf(&send_buffer, "%s&3", req_password); 162 xasprintf(&send_buffer, "%s&3", config.req_password);
211 fetch_data (server_address, server_port, send_buffer); 163 fetch_data(config.server_address, config.server_port, send_buffer);
212 uptime=strtoul(recv_buffer,NULL,10); 164 unsigned long uptime = strtoul(recv_buffer, NULL, 10);
213 updays = uptime / 86400; 165 int updays = uptime / 86400;
214 uphours = (uptime % 86400) / 3600; 166 int uphours = (uptime % 86400) / 3600;
215 upminutes = ((uptime % 86400) % 3600) / 60; 167 int upminutes = ((uptime % 86400) % 3600) / 60;
216 168
217 if (!strncmp(value_list, "minutes", strlen("minutes"))) 169 if (!strncmp(tmp_value_list, "minutes", strlen("minutes"))) {
218 uptime = uptime / 60; 170 uptime = uptime / 60;
219 else if (!strncmp(value_list, "hours", strlen("hours"))) 171 } else if (!strncmp(tmp_value_list, "hours", strlen("hours"))) {
220 uptime = uptime / 3600; 172 uptime = uptime / 3600;
221 else if (!strncmp(value_list, "days", strlen("days"))) 173 } else if (!strncmp(tmp_value_list, "days", strlen("days"))) {
222 uptime = uptime / 86400; 174 uptime = uptime / 86400;
175 }
223 /* else uptime in seconds, nothing to do */ 176 /* else uptime in seconds, nothing to do */
224 177
225 xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"),updays, uphours, upminutes, uptime); 178 xasprintf(&output_message, _("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"), updays, uphours, upminutes,
179 uptime);
226 180
227 if (check_critical_value && uptime <= critical_value) 181 if (config.check_critical_value && uptime <= config.critical_value) {
228 return_code=STATE_CRITICAL; 182 return_code = STATE_CRITICAL;
229 else if (check_warning_value && uptime <= warning_value) 183 } else if (config.check_warning_value && uptime <= config.warning_value) {
230 return_code=STATE_WARNING; 184 return_code = STATE_WARNING;
231 else 185 } else {
232 return_code=STATE_OK; 186 return_code = STATE_OK;
187 }
233 } 188 }
234 break; 189 } break;
235
236 case CHECK_USEDDISKSPACE: 190 case CHECK_USEDDISKSPACE:
191 if (config.value_list == NULL) {
192 output_message = strdup(_("missing -l parameters"));
193 } else if (strlen(config.value_list) != 1) {
194 output_message = strdup(_("wrong -l argument"));
195 } else {
196 xasprintf(&send_buffer, "%s&4&%s", config.req_password, config.value_list);
197 fetch_data(config.server_address, config.server_port, send_buffer);
198 char *fds = strtok(recv_buffer, "&");
199 char *tds = strtok(NULL, "&");
200 double total_disk_space = 0;
201 double free_disk_space = 0;
202 if (fds != NULL) {
203 free_disk_space = atof(fds);
204 }
205 if (tds != NULL) {
206 total_disk_space = atof(tds);
207 }
237 208
238 if (value_list==NULL) 209 if (total_disk_space > 0 && free_disk_space >= 0) {
239 output_message = strdup (_("missing -l parameters")); 210 double percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100;
240 else if (strlen(value_list)!=1) 211 double warning_used_space = ((float)config.warning_value / 100) * total_disk_space;
241 output_message = strdup (_("wrong -l argument")); 212 double critical_used_space = ((float)config.critical_value / 100) * total_disk_space;
242 else { 213
243 xasprintf(&send_buffer,"%s&4&%s", req_password, value_list); 214 xasprintf(&temp_string, _("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), config.value_list,
244 fetch_data (server_address, server_port, send_buffer); 215 total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, percent_used_space,
245 fds=strtok(recv_buffer,"&"); 216 free_disk_space / 1073741824, (free_disk_space / total_disk_space) * 100);
246 tds=strtok(NULL,"&"); 217 xasprintf(&temp_string_perf, _("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), config.value_list,
247 if(fds!=NULL) 218 (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
248 free_disk_space=atof(fds); 219 critical_used_space / 1073741824, total_disk_space / 1073741824);
249 if(tds!=NULL) 220
250 total_disk_space=atof(tds); 221 if (config.check_critical_value && percent_used_space >= config.critical_value) {
251 222 return_code = STATE_CRITICAL;
252 if (total_disk_space>0 && free_disk_space>=0) { 223 } else if (config.check_warning_value && percent_used_space >= config.warning_value) {
253 percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100; 224 return_code = STATE_WARNING;
254 warning_used_space = ((float)warning_value / 100) * total_disk_space; 225 } else {
255 critical_used_space = ((float)critical_value / 100) * total_disk_space; 226 return_code = STATE_OK;
256 227 }
257 xasprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), 228
258 value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, 229 output_message = strdup(temp_string);
259 percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100);
260 xasprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list,
261 (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
262 critical_used_space / 1073741824, total_disk_space / 1073741824);
263
264 if(check_critical_value && percent_used_space >= critical_value)
265 return_code=STATE_CRITICAL;
266 else if (check_warning_value && percent_used_space >= warning_value)
267 return_code=STATE_WARNING;
268 else
269 return_code=STATE_OK;
270
271 output_message = strdup (temp_string);
272 perfdata = temp_string_perf; 230 perfdata = temp_string_perf;
273 } else { 231 } else {
274 output_message = strdup (_("Free disk space : Invalid drive")); 232 output_message = strdup(_("Free disk space : Invalid drive"));
275 return_code=STATE_UNKNOWN; 233 return_code = STATE_UNKNOWN;
276 } 234 }
277 } 235 }
278 break; 236 break;
279
280 case CHECK_SERVICESTATE: 237 case CHECK_SERVICESTATE:
281 case CHECK_PROCSTATE: 238 case CHECK_PROCSTATE:
282 239 if (config.value_list == NULL) {
283 if (value_list==NULL) 240 output_message = strdup(_("No service/process specified"));
284 output_message = strdup (_("No service/process specified")); 241 } else {
285 else { 242 preparelist(config.value_list); /* replace , between services with & to send the request */
286 preparelist(value_list); /* replace , between services with & to send the request */ 243 xasprintf(&send_buffer, "%s&%u&%s&%s", config.req_password, (config.vars_to_check == CHECK_SERVICESTATE) ? 5 : 6,
287 xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, 244 (config.show_all) ? "ShowAll" : "ShowFail", config.value_list);
288 (show_all) ? "ShowAll" : "ShowFail",value_list); 245 fetch_data(config.server_address, config.server_port, send_buffer);
289 fetch_data (server_address, server_port, send_buffer); 246 char *numstr = strtok(recv_buffer, "&");
290 numstr = strtok(recv_buffer,"&"); 247 if (numstr == NULL) {
291 if (numstr == NULL)
292 die(STATE_UNKNOWN, _("could not fetch information from server\n")); 248 die(STATE_UNKNOWN, _("could not fetch information from server\n"));
293 return_code=atoi(numstr); 249 }
294 temp_string=strtok(NULL,"&"); 250 return_code = atoi(numstr);
295 output_message = strdup (temp_string); 251 temp_string = strtok(NULL, "&");
252 output_message = strdup(temp_string);
296 } 253 }
297 break; 254 break;
298
299 case CHECK_MEMUSE: 255 case CHECK_MEMUSE:
300 256 xasprintf(&send_buffer, "%s&7", config.req_password);
301 xasprintf(&send_buffer,"%s&7", req_password); 257 fetch_data(config.server_address, config.server_port, send_buffer);
302 fetch_data (server_address, server_port, send_buffer); 258 char *numstr = strtok(recv_buffer, "&");
303 numstr = strtok(recv_buffer,"&"); 259 if (numstr == NULL) {
304 if (numstr == NULL)
305 die(STATE_UNKNOWN, _("could not fetch information from server\n")); 260 die(STATE_UNKNOWN, _("could not fetch information from server\n"));
306 mem_commitLimit=atof(numstr); 261 }
307 numstr = strtok(NULL,"&"); 262 double mem_commitLimit = atof(numstr);
308 if (numstr == NULL) 263 numstr = strtok(NULL, "&");
264 if (numstr == NULL) {
309 die(STATE_UNKNOWN, _("could not fetch information from server\n")); 265 die(STATE_UNKNOWN, _("could not fetch information from server\n"));
310 mem_commitByte=atof(numstr); 266 }
311 percent_used_space = (mem_commitByte / mem_commitLimit) * 100; 267 double mem_commitByte = atof(numstr);
312 warning_used_space = ((float)warning_value / 100) * mem_commitLimit; 268 double percent_used_space = (mem_commitByte / mem_commitLimit) * 100;
313 critical_used_space = ((float)critical_value / 100) * mem_commitLimit; 269 double warning_used_space = ((float)config.warning_value / 100) * mem_commitLimit;
270 double critical_used_space = ((float)config.critical_value / 100) * mem_commitLimit;
314 271
315 /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here, 272 /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here,
316 which equals RAM + Pagefiles. */ 273 which equals RAM + Pagefiles. */
317 xasprintf(&output_message,_("Memory usage: total:%.2f MB - used: %.2f MB (%.0f%%) - free: %.2f MB (%.0f%%)"), 274 xasprintf(&output_message, _("Memory usage: total:%.2f MB - used: %.2f MB (%.0f%%) - free: %.2f MB (%.0f%%)"),
318 mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space, 275 mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space, (mem_commitLimit - mem_commitByte) / 1048567,
319 (mem_commitLimit - mem_commitByte) / 1048567, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100); 276 (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
320 xasprintf(&perfdata,_("'Memory usage'=%.2fMB;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567, 277 xasprintf(&perfdata, _("'Memory usage'=%.2fMB;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567, warning_used_space / 1048567,
321 warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567); 278 critical_used_space / 1048567, mem_commitLimit / 1048567);
322 279
323 return_code=STATE_OK; 280 return_code = STATE_OK;
324 if(check_critical_value && percent_used_space >= critical_value) 281 if (config.check_critical_value && percent_used_space >= config.critical_value) {
325 return_code=STATE_CRITICAL; 282 return_code = STATE_CRITICAL;
326 else if (check_warning_value && percent_used_space >= warning_value) 283 } else if (config.check_warning_value && percent_used_space >= config.warning_value) {
327 return_code=STATE_WARNING; 284 return_code = STATE_WARNING;
285 }
328 286
329 break; 287 break;
330 288 case CHECK_COUNTER: {
331 case CHECK_COUNTER:
332
333
334 /* 289 /*
335 CHECK_COUNTER has been modified to provide extensive perfdata information. 290 CHECK_COUNTER has been modified to provide extensive perfdata information.
336 In order to do this, some modifications have been done to the code 291 In order to do this, some modifications have been done to the code
@@ -352,450 +307,450 @@ int main(int argc, char **argv){
352 strange things will happen when you make graphs of your data. 307 strange things will happen when you make graphs of your data.
353 */ 308 */
354 309
355 if (value_list == NULL) 310 double counter_value = 0.0;
356 output_message = strdup (_("No counter specified")); 311 if (config.value_list == NULL) {
357 else 312 output_message = strdup(_("No counter specified"));
358 { 313 } else {
359 preparelist (value_list); /* replace , between services with & to send the request */ 314 preparelist(config.value_list); /* replace , between services with & to send the request */
360 isPercent = (strchr (value_list, '%') != NULL); 315 bool isPercent = (strchr(config.value_list, '%') != NULL);
361 316
362 strtok (value_list, "&"); /* burn the first parameters */ 317 strtok(config.value_list, "&"); /* burn the first parameters */
363 description = strtok (NULL, "&"); 318 description = strtok(NULL, "&");
364 counter_unit = strtok (NULL, "&"); 319 counter_unit = strtok(NULL, "&");
365 xasprintf (&send_buffer, "%s&8&%s", req_password, value_list); 320 xasprintf(&send_buffer, "%s&8&%s", config.req_password, config.value_list);
366 fetch_data (server_address, server_port, send_buffer); 321 fetch_data(config.server_address, config.server_port, send_buffer);
367 counter_value = atof (recv_buffer); 322 counter_value = atof(recv_buffer);
368 323
369 if (description == NULL) 324 bool allRight = false;
370 xasprintf (&output_message, "%.f", counter_value); 325 if (description == NULL) {
371 else if (isPercent) 326 xasprintf(&output_message, "%.f", counter_value);
372 { 327 } else if (isPercent) {
373 counter_unit = strdup ("%"); 328 counter_unit = strdup("%");
374 allRight = true; 329 allRight = true;
375 } 330 }
376 331
377 if ((counter_unit != NULL) && (!allRight)) 332 char *minval = NULL;
378 { 333 char *maxval = NULL;
379 minval = strtok (NULL, "&"); 334 double fminval = 0;
380 maxval = strtok (NULL, "&"); 335 double fmaxval = 0;
336 if ((counter_unit != NULL) && (!allRight)) {
337 minval = strtok(NULL, "&");
338 maxval = strtok(NULL, "&");
381 339
382 /* All parameters specified. Let's check the numbers */ 340 /* All parameters specified. Let's check the numbers */
383 341
384 fminval = (minval != NULL) ? strtod (minval, &errcvt) : -1; 342 fminval = (minval != NULL) ? strtod(minval, &errcvt) : -1;
385 fmaxval = (minval != NULL) ? strtod (maxval, &errcvt) : -1; 343 fmaxval = (minval != NULL) ? strtod(maxval, &errcvt) : -1;
386
387 if ((fminval == 0) && (minval == errcvt))
388 output_message = strdup (_("Minimum value contains non-numbers"));
389 else
390 {
391 if ((fmaxval == 0) && (maxval == errcvt))
392 output_message = strdup (_("Maximum value contains non-numbers"));
393 else
394 allRight = true; /* Everything is OK. */
395 344
345 if ((fminval == 0) && (minval == errcvt)) {
346 output_message = strdup(_("Minimum value contains non-numbers"));
347 } else {
348 if ((fmaxval == 0) && (maxval == errcvt)) {
349 output_message = strdup(_("Maximum value contains non-numbers"));
350 } else {
351 allRight = true; /* Everything is OK. */
352 }
396 } 353 }
354 } else if ((counter_unit == NULL) && (description != NULL)) {
355 output_message = strdup(_("No unit counter specified"));
397 } 356 }
398 else if ((counter_unit == NULL) && (description != NULL))
399 output_message = strdup (_("No unit counter specified"));
400 357
401 if (allRight) 358 if (allRight) {
402 {
403 /* Let's format the output string, finally... */ 359 /* Let's format the output string, finally... */
404 if (strstr(description, "%") == NULL) { 360 if (strstr(description, "%") == NULL) {
405 xasprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit); 361 xasprintf(&output_message, "%s = %.2f %s", description, counter_value, counter_unit);
406 } else { 362 } else {
407 /* has formatting, will segv if wrong */ 363 /* has formatting, will segv if wrong */
408 xasprintf (&output_message, description, counter_value); 364 xasprintf(&output_message, description, counter_value);
409 } 365 }
410 xasprintf (&output_message, "%s |", output_message); 366 xasprintf(&output_message, "%s |", output_message);
411 xasprintf (&output_message,"%s %s", output_message, 367 xasprintf(&output_message, "%s %s", output_message,
412 fperfdata (description, counter_value, 368 fperfdata(description, counter_value, counter_unit, 1, config.warning_value, 1, config.critical_value,
413 counter_unit, 1, warning_value, 1, critical_value, 369 (!(isPercent) && (minval != NULL)), fminval, (!(isPercent) && (minval != NULL)), fmaxval));
414 (!(isPercent) && (minval != NULL)), fminval,
415 (!(isPercent) && (minval != NULL)), fmaxval));
416 } 370 }
417 } 371 }
418 372
419 if (critical_value > warning_value) 373 if (config.critical_value > config.warning_value) { /* Normal thresholds */
420 { /* Normal thresholds */ 374 if (config.check_critical_value && counter_value >= config.critical_value) {
421 if (check_critical_value && counter_value >= critical_value)
422 return_code = STATE_CRITICAL; 375 return_code = STATE_CRITICAL;
423 else if (check_warning_value && counter_value >= warning_value) 376 } else if (config.check_warning_value && counter_value >= config.warning_value) {
424 return_code = STATE_WARNING; 377 return_code = STATE_WARNING;
425 else 378 } else {
426 return_code = STATE_OK; 379 return_code = STATE_OK;
427 } 380 }
428 else 381 } else { /* inverse thresholds */
429 { /* inverse thresholds */
430 return_code = STATE_OK; 382 return_code = STATE_OK;
431 if (check_critical_value && counter_value <= critical_value) 383 if (config.check_critical_value && counter_value <= config.critical_value) {
432 return_code = STATE_CRITICAL; 384 return_code = STATE_CRITICAL;
433 else if (check_warning_value && counter_value <= warning_value) 385 } else if (config.check_warning_value && counter_value <= config.warning_value) {
434 return_code = STATE_WARNING; 386 return_code = STATE_WARNING;
387 }
435 } 388 }
436 break; 389 } break;
437
438 case CHECK_FILEAGE: 390 case CHECK_FILEAGE:
439 391 if (config.value_list == NULL) {
440 if (value_list==NULL) 392 output_message = strdup(_("No counter specified"));
441 output_message = strdup (_("No counter specified")); 393 } else {
442 else { 394 preparelist(config.value_list); /* replace , between services with & to send the request */
443 preparelist(value_list); /* replace , between services with & to send the request */ 395 xasprintf(&send_buffer, "%s&9&%s", config.req_password, config.value_list);
444 xasprintf(&send_buffer,"%s&9&%s", req_password,value_list); 396 fetch_data(config.server_address, config.server_port, send_buffer);
445 fetch_data (server_address, server_port, send_buffer); 397 unsigned long age_in_minutes = atoi(strtok(recv_buffer, "&"));
446 age_in_minutes = atoi(strtok(recv_buffer,"&")); 398 description = strtok(NULL, "&");
447 description = strtok(NULL,"&"); 399 output_message = strdup(description);
448 output_message = strdup (description); 400
449 401 if (config.critical_value > config.warning_value) { /* Normal thresholds */
450 if (critical_value > warning_value) { /* Normal thresholds */ 402 if (config.check_critical_value && age_in_minutes >= config.critical_value) {
451 if(check_critical_value && age_in_minutes >= critical_value) 403 return_code = STATE_CRITICAL;
452 return_code=STATE_CRITICAL; 404 } else if (config.check_warning_value && age_in_minutes >= config.warning_value) {
453 else if (check_warning_value && age_in_minutes >= warning_value) 405 return_code = STATE_WARNING;
454 return_code=STATE_WARNING; 406 } else {
455 else 407 return_code = STATE_OK;
456 return_code=STATE_OK; 408 }
457 } 409 } else { /* inverse thresholds */
458 else { /* inverse thresholds */ 410 if (config.check_critical_value && age_in_minutes <= config.critical_value) {
459 if(check_critical_value && age_in_minutes <= critical_value) 411 return_code = STATE_CRITICAL;
460 return_code=STATE_CRITICAL; 412 } else if (config.check_warning_value && age_in_minutes <= config.warning_value) {
461 else if (check_warning_value && age_in_minutes <= warning_value) 413 return_code = STATE_WARNING;
462 return_code=STATE_WARNING; 414 } else {
463 else 415 return_code = STATE_OK;
464 return_code=STATE_OK; 416 }
465 } 417 }
466 } 418 }
467 break; 419 break;
468 420
469 case CHECK_INSTANCES: 421 case CHECK_INSTANCES:
470 if (value_list==NULL) 422 if (config.value_list == NULL) {
471 output_message = strdup (_("No counter specified")); 423 output_message = strdup(_("No counter specified"));
472 else { 424 } else {
473 xasprintf(&send_buffer,"%s&10&%s", req_password,value_list); 425 xasprintf(&send_buffer, "%s&10&%s", config.req_password, config.value_list);
474 fetch_data (server_address, server_port, send_buffer); 426 fetch_data(config.server_address, config.server_port, send_buffer);
475 if (!strncmp(recv_buffer,"ERROR",5)) { 427 if (!strncmp(recv_buffer, "ERROR", 5)) {
476 printf("NSClient - %s\n",recv_buffer); 428 printf("NSClient - %s\n", recv_buffer);
477 exit(STATE_UNKNOWN); 429 exit(STATE_UNKNOWN);
478 } 430 }
479 xasprintf(&output_message,"%s",recv_buffer); 431 xasprintf(&output_message, "%s", recv_buffer);
480 return_code=STATE_OK; 432 return_code = STATE_OK;
481 } 433 }
482 break; 434 break;
483 435
484 case CHECK_NONE: 436 case CHECK_NONE:
485 default: 437 default:
486 usage4 (_("Please specify a variable to check")); 438 usage4(_("Please specify a variable to check"));
487 break; 439 break;
488
489 } 440 }
490 441
491 /* reset timeout */ 442 /* reset timeout */
492 alarm(0); 443 alarm(0);
493 444
494 if (perfdata==NULL) 445 if (perfdata == NULL) {
495 printf("%s\n",output_message); 446 printf("%s\n", output_message);
496 else 447 } else {
497 printf("%s | %s\n",output_message,perfdata); 448 printf("%s | %s\n", output_message, perfdata);
449 }
498 return return_code; 450 return return_code;
499} 451}
500 452
501
502
503/* process command-line arguments */ 453/* process command-line arguments */
504int process_arguments(int argc, char **argv){ 454check_nt_config_wrapper process_arguments(int argc, char **argv) {
505 int c; 455 static struct option longopts[] = {{"port", required_argument, 0, 'p'},
506 456 {"timeout", required_argument, 0, 't'},
507 int option = 0; 457 {"critical", required_argument, 0, 'c'},
508 static struct option longopts[] = 458 {"warning", required_argument, 0, 'w'},
509 { 459 {"variable", required_argument, 0, 'v'},
510 {"port", required_argument,0,'p'}, 460 {"hostname", required_argument, 0, 'H'},
511 {"timeout", required_argument,0,'t'}, 461 {"params", required_argument, 0, 'l'},
512 {"critical", required_argument,0,'c'}, 462 {"secret", required_argument, 0, 's'},
513 {"warning", required_argument,0,'w'}, 463 {"display", required_argument, 0, 'd'},
514 {"variable", required_argument,0,'v'}, 464 {"unknown-timeout", no_argument, 0, 'u'},
515 {"hostname", required_argument,0,'H'}, 465 {"version", no_argument, 0, 'V'},
516 {"params", required_argument,0,'l'}, 466 {"help", no_argument, 0, 'h'},
517 {"secret", required_argument,0,'s'}, 467 {0, 0, 0, 0}};
518 {"display", required_argument,0,'d'}, 468
519 {"unknown-timeout", no_argument, 0, 'u'}, 469 check_nt_config_wrapper result = {
520 {"version", no_argument, 0,'V'}, 470 .errorcode = OK,
521 {"help", no_argument, 0,'h'}, 471 .config = check_nt_config_init(),
522 {0,0,0,0}
523 }; 472 };
524 473
525 /* no options were supplied */ 474 /* no options were supplied */
526 if(argc<2) return ERROR; 475 if (argc < 2) {
476 result.errorcode = ERROR;
477 return result;
478 }
527 479
528 /* backwards compatibility */ 480 /* backwards compatibility */
529 if (! is_option(argv[1])) { 481 if (!is_option(argv[1])) {
530 server_address = strdup(argv[1]); 482 result.config.server_address = strdup(argv[1]);
531 argv[1]=argv[0]; 483 argv[1] = argv[0];
532 argv=&argv[1]; 484 argv = &argv[1];
533 argc--; 485 argc--;
534 } 486 }
535 487
536 for (c=1;c<argc;c++) { 488 for (int index = 1; index < argc; index++) {
537 if(strcmp("-to",argv[c])==0) 489 if (strcmp("-to", argv[index]) == 0) {
538 strcpy(argv[c],"-t"); 490 strcpy(argv[index], "-t");
539 else if (strcmp("-wv",argv[c])==0) 491 } else if (strcmp("-wv", argv[index]) == 0) {
540 strcpy(argv[c],"-w"); 492 strcpy(argv[index], "-w");
541 else if (strcmp("-cv",argv[c])==0) 493 } else if (strcmp("-cv", argv[index]) == 0) {
542 strcpy(argv[c],"-c"); 494 strcpy(argv[index], "-c");
495 }
543 } 496 }
544 497
545 while (1) { 498 int option = 0;
546 c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:u",longopts,&option); 499 while (true) {
500 int option_index = getopt_long(argc, argv, "+hVH:t:c:w:p:v:l:s:d:u", longopts, &option);
547 501
548 if (c==-1||c==EOF||c==1) 502 if (option_index == -1 || option_index == EOF || option_index == 1) {
549 break; 503 break;
504 }
550 505
551 switch (c) { 506 switch (option_index) {
552 case '?': /* print short usage statement if args not parsable */ 507 case '?': /* print short usage statement if args not parsable */
553 usage5 (); 508 usage5();
554 case 'h': /* help */ 509 case 'h': /* help */
555 print_help(); 510 print_help();
556 exit(STATE_UNKNOWN); 511 exit(STATE_UNKNOWN);
557 case 'V': /* version */ 512 case 'V': /* version */
558 print_revision(progname, NP_VERSION); 513 print_revision(progname, NP_VERSION);
559 exit(STATE_UNKNOWN); 514 exit(STATE_UNKNOWN);
560 case 'H': /* hostname */ 515 case 'H': /* hostname */
561 server_address = optarg; 516 result.config.server_address = optarg;
562 break; 517 break;
563 case 's': /* password */ 518 case 's': /* password */
564 req_password = optarg; 519 result.config.req_password = optarg;
565 break; 520 break;
566 case 'p': /* port */ 521 case 'p': /* port */
567 if (is_intnonneg(optarg)) 522 if (is_intnonneg(optarg)) {
568 server_port=atoi(optarg); 523 result.config.server_port = atoi(optarg);
569 else 524 } else {
570 die(STATE_UNKNOWN,_("Server port must be an integer\n")); 525 die(STATE_UNKNOWN, _("Server port must be an integer\n"));
571 break;
572 case 'v':
573 if(strlen(optarg)<4)
574 return ERROR;
575 if(!strcmp(optarg,"CLIENTVERSION"))
576 vars_to_check=CHECK_CLIENTVERSION;
577 else if(!strcmp(optarg,"CPULOAD"))
578 vars_to_check=CHECK_CPULOAD;
579 else if(!strcmp(optarg,"UPTIME"))
580 vars_to_check=CHECK_UPTIME;
581 else if(!strcmp(optarg,"USEDDISKSPACE"))
582 vars_to_check=CHECK_USEDDISKSPACE;
583 else if(!strcmp(optarg,"SERVICESTATE"))
584 vars_to_check=CHECK_SERVICESTATE;
585 else if(!strcmp(optarg,"PROCSTATE"))
586 vars_to_check=CHECK_PROCSTATE;
587 else if(!strcmp(optarg,"MEMUSE"))
588 vars_to_check=CHECK_MEMUSE;
589 else if(!strcmp(optarg,"COUNTER"))
590 vars_to_check=CHECK_COUNTER;
591 else if(!strcmp(optarg,"FILEAGE"))
592 vars_to_check=CHECK_FILEAGE;
593 else if(!strcmp(optarg,"INSTANCES"))
594 vars_to_check=CHECK_INSTANCES;
595 else
596 return ERROR;
597 break;
598 case 'l': /* value list */
599 value_list = optarg;
600 break;
601 case 'w': /* warning threshold */
602 warning_value=strtoul(optarg,NULL,10);
603 check_warning_value=true;
604 break;
605 case 'c': /* critical threshold */
606 critical_value=strtoul(optarg,NULL,10);
607 check_critical_value=true;
608 break;
609 case 'd': /* Display select for services */
610 if (!strcmp(optarg,"SHOWALL"))
611 show_all = true;
612 break;
613 case 'u':
614 socket_timeout_state=STATE_UNKNOWN;
615 break;
616 case 't': /* timeout */
617 socket_timeout=atoi(optarg);
618 if(socket_timeout<=0)
619 return ERROR;
620 } 526 }
621 527 break;
528 case 'v':
529 if (strlen(optarg) < 4) {
530 result.errorcode = ERROR;
531 return result;
532 }
533 if (!strcmp(optarg, "CLIENTVERSION")) {
534 result.config.vars_to_check = CHECK_CLIENTVERSION;
535 } else if (!strcmp(optarg, "CPULOAD")) {
536 result.config.vars_to_check = CHECK_CPULOAD;
537 } else if (!strcmp(optarg, "UPTIME")) {
538 result.config.vars_to_check = CHECK_UPTIME;
539 } else if (!strcmp(optarg, "USEDDISKSPACE")) {
540 result.config.vars_to_check = CHECK_USEDDISKSPACE;
541 } else if (!strcmp(optarg, "SERVICESTATE")) {
542 result.config.vars_to_check = CHECK_SERVICESTATE;
543 } else if (!strcmp(optarg, "PROCSTATE")) {
544 result.config.vars_to_check = CHECK_PROCSTATE;
545 } else if (!strcmp(optarg, "MEMUSE")) {
546 result.config.vars_to_check = CHECK_MEMUSE;
547 } else if (!strcmp(optarg, "COUNTER")) {
548 result.config.vars_to_check = CHECK_COUNTER;
549 } else if (!strcmp(optarg, "FILEAGE")) {
550 result.config.vars_to_check = CHECK_FILEAGE;
551 } else if (!strcmp(optarg, "INSTANCES")) {
552 result.config.vars_to_check = CHECK_INSTANCES;
553 } else {
554 result.errorcode = ERROR;
555 return result;
556 }
557 break;
558 case 'l': /* value list */
559 result.config.value_list = optarg;
560 break;
561 case 'w': /* warning threshold */
562 result.config.warning_value = strtoul(optarg, NULL, 10);
563 result.config.check_warning_value = true;
564 break;
565 case 'c': /* critical threshold */
566 result.config.critical_value = strtoul(optarg, NULL, 10);
567 result.config.check_critical_value = true;
568 break;
569 case 'd': /* Display select for services */
570 if (!strcmp(optarg, "SHOWALL")) {
571 result.config.show_all = true;
572 }
573 break;
574 case 'u':
575 socket_timeout_state = STATE_UNKNOWN;
576 break;
577 case 't': /* timeout */
578 socket_timeout = atoi(optarg);
579 if (socket_timeout <= 0) {
580 result.errorcode = ERROR;
581 return result;
582 }
583 }
584 }
585 if (result.config.server_address == NULL) {
586 usage4(_("You must provide a server address or host name"));
622 } 587 }
623 if (server_address == NULL)
624 usage4 (_("You must provide a server address or host name"));
625 588
626 if (vars_to_check==CHECK_NONE) 589 if (result.config.vars_to_check == CHECK_NONE) {
627 return ERROR; 590 result.errorcode = ERROR;
591 return result;
592 }
628 593
629 if (req_password == NULL) 594 if (result.config.req_password == NULL) {
630 req_password = strdup (_("None")); 595 result.config.req_password = strdup(_("None"));
596 }
631 597
632 return OK; 598 return result;
633} 599}
634 600
601void fetch_data(const char *address, int port, const char *sendb) {
602 int result = process_tcp_request(address, port, sendb, recv_buffer, sizeof(recv_buffer));
635 603
604 if (result != STATE_OK) {
605 die(result, _("could not fetch information from server\n"));
606 }
636 607
637void fetch_data (const char *address, int port, const char *sendb) { 608 if (!strncmp(recv_buffer, "ERROR", 5)) {
638 int result; 609 die(STATE_UNKNOWN, "NSClient - %s\n", recv_buffer);
639 610 }
640 result=process_tcp_request(address, port, sendb, recv_buffer,sizeof(recv_buffer));
641
642 if(result!=STATE_OK)
643 die (result, _("could not fetch information from server\n"));
644
645 if (!strncmp(recv_buffer,"ERROR",5))
646 die (STATE_UNKNOWN, "NSClient - %s\n",recv_buffer);
647} 611}
648 612
649bool strtoularray(unsigned long *array, char *string, const char *delim) { 613bool strtoularray(unsigned long *array, char *string, const char *delim) {
650 /* split a <delim> delimited string into a long array */ 614 /* split a <delim> delimited string into a long array */
651 int idx=0; 615 for (int idx = 0; idx < MAX_VALUE_LIST; idx++) {
652 char *t1; 616 array[idx] = 0;
653 617 }
654 for (idx=0;idx<MAX_VALUE_LIST;idx++)
655 array[idx]=0;
656 618
657 idx=0; 619 int idx = 0;
658 for(t1 = strtok(string,delim);t1 != NULL; t1 = strtok(NULL, delim)) { 620 for (char *t1 = strtok(string, delim); t1 != NULL; t1 = strtok(NULL, delim)) {
659 if (is_numeric(t1) && idx<MAX_VALUE_LIST) { 621 if (is_numeric(t1) && idx < MAX_VALUE_LIST) {
660 array[idx]=strtoul(t1,NULL,10); 622 array[idx] = strtoul(t1, NULL, 10);
661 idx++; 623 idx++;
662 } else 624 } else {
663 return false; 625 return false;
626 }
664 } 627 }
665 return true; 628 return true;
666} 629}
667 630
668void preparelist(char *string) { 631void preparelist(char *string) {
669 /* Replace all , with & which is the delimiter for the request */ 632 /* Replace all , with & which is the delimiter for the request */
670 int i; 633 for (int i = 0; (size_t)i < strlen(string); i++) {
671
672 for (i = 0; (size_t)i < strlen(string); i++)
673 if (string[i] == ',') { 634 if (string[i] == ',') {
674 string[i]='&'; 635 string[i] = '&';
675 } 636 }
637 }
676} 638}
677 639
678 640void print_help(void) {
679
680void print_help(void)
681{
682 print_revision(progname, NP_VERSION); 641 print_revision(progname, NP_VERSION);
683 642
684 printf ("Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)\n"); 643 printf("Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)\n");
685 printf (COPYRIGHT, copyright, email); 644 printf(COPYRIGHT, copyright, email);
686 645
687 printf ("%s\n", _("This plugin collects data from the NSClient service running on a")); 646 printf("%s\n", _("This plugin collects data from the NSClient service running on a"));
688 printf ("%s\n", _("Windows NT/2000/XP/2003 server.")); 647 printf("%s\n", _("Windows NT/2000/XP/2003 server."));
689 648
690 printf ("\n\n"); 649 printf("\n\n");
691 650
692 print_usage(); 651 print_usage();
693 652
694 printf (UT_HELP_VRSN); 653 printf(UT_HELP_VRSN);
695 printf (UT_EXTRA_OPTS); 654 printf(UT_EXTRA_OPTS);
696 655
697 printf ("%s\n", _("Options:")); 656 printf("%s\n", _("Options:"));
698 printf (" %s\n", "-H, --hostname=HOST"); 657 printf(" %s\n", "-H, --hostname=HOST");
699 printf (" %s\n", _("Name of the host to check")); 658 printf(" %s\n", _("Name of the host to check"));
700 printf (" %s\n", "-p, --port=INTEGER"); 659 printf(" %s\n", "-p, --port=INTEGER");
701 printf (" %s", _("Optional port number (default: ")); 660 printf(" %s", _("Optional port number (default: "));
702 printf ("%d)\n", PORT); 661 printf("%d)\n", PORT);
703 printf (" %s\n", "-s, --secret=<password>"); 662 printf(" %s\n", "-s, --secret=<password>");
704 printf (" %s\n", _("Password needed for the request")); 663 printf(" %s\n", _("Password needed for the request"));
705 printf (" %s\n", "-w, --warning=INTEGER"); 664 printf(" %s\n", "-w, --warning=INTEGER");
706 printf (" %s\n", _("Threshold which will result in a warning status")); 665 printf(" %s\n", _("Threshold which will result in a warning status"));
707 printf (" %s\n", "-c, --critical=INTEGER"); 666 printf(" %s\n", "-c, --critical=INTEGER");
708 printf (" %s\n", _("Threshold which will result in a critical status")); 667 printf(" %s\n", _("Threshold which will result in a critical status"));
709 printf (" %s\n", "-t, --timeout=INTEGER"); 668 printf(" %s\n", "-t, --timeout=INTEGER");
710 printf (" %s", _("Seconds before connection attempt times out (default: ")); 669 printf(" %s", _("Seconds before connection attempt times out (default: "));
711 printf (" %s\n", "-l, --params=<parameters>"); 670 printf(" %s\n", "-l, --params=<parameters>");
712 printf (" %s", _("Parameters passed to specified check (see below)")); 671 printf(" %s", _("Parameters passed to specified check (see below)"));
713 printf (" %s\n", "-d, --display={SHOWALL}"); 672 printf(" %s\n", "-d, --display={SHOWALL}");
714 printf (" %s", _("Display options (currently only SHOWALL works)")); 673 printf(" %s", _("Display options (currently only SHOWALL works)"));
715 printf (" %s\n", "-u, --unknown-timeout"); 674 printf(" %s\n", "-u, --unknown-timeout");
716 printf (" %s", _("Return UNKNOWN on timeouts")); 675 printf(" %s", _("Return UNKNOWN on timeouts"));
717 printf ("%d)\n", DEFAULT_SOCKET_TIMEOUT); 676 printf("%d)\n", DEFAULT_SOCKET_TIMEOUT);
718 printf (" %s\n", "-h, --help"); 677 printf(" %s\n", "-h, --help");
719 printf (" %s\n", _("Print this help screen")); 678 printf(" %s\n", _("Print this help screen"));
720 printf (" %s\n", "-V, --version"); 679 printf(" %s\n", "-V, --version");
721 printf (" %s\n", _("Print version information")); 680 printf(" %s\n", _("Print version information"));
722 printf (" %s\n", "-v, --variable=STRING"); 681 printf(" %s\n", "-v, --variable=STRING");
723 printf (" %s\n\n", _("Variable to check")); 682 printf(" %s\n\n", _("Variable to check"));
724 printf ("%s\n", _("Valid variables are:")); 683 printf("%s\n", _("Valid variables are:"));
725 printf (" %s", "CLIENTVERSION ="); 684 printf(" %s", "CLIENTVERSION =");
726 printf (" %s\n", _("Get the NSClient version")); 685 printf(" %s\n", _("Get the NSClient version"));
727 printf (" %s\n", _("If -l <version> is specified, will return warning if versions differ.")); 686 printf(" %s\n", _("If -l <version> is specified, will return warning if versions differ."));
728 printf (" %s\n", "CPULOAD ="); 687 printf(" %s\n", "CPULOAD =");
729 printf (" %s\n", _("Average CPU load on last x minutes.")); 688 printf(" %s\n", _("Average CPU load on last x minutes."));
730 printf (" %s\n", _("Request a -l parameter with the following syntax:")); 689 printf(" %s\n", _("Request a -l parameter with the following syntax:"));
731 printf (" %s\n", _("-l <minutes range>,<warning threshold>,<critical threshold>.")); 690 printf(" %s\n", _("-l <minutes range>,<warning threshold>,<critical threshold>."));
732 printf (" %s\n", _("<minute range> should be less than 24*60.")); 691 printf(" %s\n", _("<minute range> should be less than 24*60."));
733 printf (" %s\n", _("Thresholds are percentage and up to 10 requests can be done in one shot.")); 692 printf(" %s\n", _("Thresholds are percentage and up to 10 requests can be done in one shot."));
734 printf (" %s\n", "ie: -l 60,90,95,120,90,95"); 693 printf(" %s\n", "ie: -l 60,90,95,120,90,95");
735 printf (" %s\n", "UPTIME ="); 694 printf(" %s\n", "UPTIME =");
736 printf (" %s\n", _("Get the uptime of the machine.")); 695 printf(" %s\n", _("Get the uptime of the machine."));
737 printf (" %s\n", _("-l <unit> ")); 696 printf(" %s\n", _("-l <unit> "));
738 printf (" %s\n", _("<unit> = seconds, minutes, hours, or days. (default: minutes)")); 697 printf(" %s\n", _("<unit> = seconds, minutes, hours, or days. (default: minutes)"));
739 printf (" %s\n", _("Thresholds will use the unit specified above.")); 698 printf(" %s\n", _("Thresholds will use the unit specified above."));
740 printf (" %s\n", "USEDDISKSPACE ="); 699 printf(" %s\n", "USEDDISKSPACE =");
741 printf (" %s\n", _("Size and percentage of disk use.")); 700 printf(" %s\n", _("Size and percentage of disk use."));
742 printf (" %s\n", _("Request a -l parameter containing the drive letter only.")); 701 printf(" %s\n", _("Request a -l parameter containing the drive letter only."));
743 printf (" %s\n", _("Warning and critical thresholds can be specified with -w and -c.")); 702 printf(" %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
744 printf (" %s\n", "MEMUSE ="); 703 printf(" %s\n", "MEMUSE =");
745 printf (" %s\n", _("Memory use.")); 704 printf(" %s\n", _("Memory use."));
746 printf (" %s\n", _("Warning and critical thresholds can be specified with -w and -c.")); 705 printf(" %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
747 printf (" %s\n", "SERVICESTATE ="); 706 printf(" %s\n", "SERVICESTATE =");
748 printf (" %s\n", _("Check the state of one or several services.")); 707 printf(" %s\n", _("Check the state of one or several services."));
749 printf (" %s\n", _("Request a -l parameters with the following syntax:")); 708 printf(" %s\n", _("Request a -l parameters with the following syntax:"));
750 printf (" %s\n", _("-l <service1>,<service2>,<service3>,...")); 709 printf(" %s\n", _("-l <service1>,<service2>,<service3>,..."));
751 printf (" %s\n", _("You can specify -d SHOWALL in case you want to see working services")); 710 printf(" %s\n", _("You can specify -d SHOWALL in case you want to see working services"));
752 printf (" %s\n", _("in the returned string.")); 711 printf(" %s\n", _("in the returned string."));
753 printf (" %s\n", "PROCSTATE ="); 712 printf(" %s\n", "PROCSTATE =");
754 printf (" %s\n", _("Check if one or several process are running.")); 713 printf(" %s\n", _("Check if one or several process are running."));
755 printf (" %s\n", _("Same syntax as SERVICESTATE.")); 714 printf(" %s\n", _("Same syntax as SERVICESTATE."));
756 printf (" %s\n", "COUNTER ="); 715 printf(" %s\n", "COUNTER =");
757 printf (" %s\n", _("Check any performance counter of Windows NT/2000.")); 716 printf(" %s\n", _("Check any performance counter of Windows NT/2000."));
758 printf (" %s\n", _("Request a -l parameters with the following syntax:")); 717 printf(" %s\n", _("Request a -l parameters with the following syntax:"));
759 printf (" %s\n", _("-l \"\\\\<performance object>\\\\counter\",\"<description>")); 718 printf(" %s\n", _("-l \"\\\\<performance object>\\\\counter\",\"<description>"));
760 printf (" %s\n", _("The <description> parameter is optional and is given to a printf ")); 719 printf(" %s\n", _("The <description> parameter is optional and is given to a printf "));
761 printf (" %s\n", _("output command which requires a float parameter.")); 720 printf(" %s\n", _("output command which requires a float parameter."));
762 printf (" %s\n", _("If <description> does not include \"%%\", it is used as a label.")); 721 printf(" %s\n", _("If <description> does not include \"%%\", it is used as a label."));
763 printf (" %s\n", _("Some examples:")); 722 printf(" %s\n", _("Some examples:"));
764 printf (" %s\n", "\"Paging file usage is %%.2f %%%%\""); 723 printf(" %s\n", "\"Paging file usage is %%.2f %%%%\"");
765 printf (" %s\n", "\"%%.f %%%% paging file used.\""); 724 printf(" %s\n", "\"%%.f %%%% paging file used.\"");
766 printf (" %s\n", "INSTANCES ="); 725 printf(" %s\n", "INSTANCES =");
767 printf (" %s\n", _("Check any performance counter object of Windows NT/2000.")); 726 printf(" %s\n", _("Check any performance counter object of Windows NT/2000."));
768 printf (" %s\n", _("Syntax: check_nt -H <hostname> -p <port> -v INSTANCES -l <counter object>")); 727 printf(" %s\n", _("Syntax: check_nt -H <hostname> -p <port> -v INSTANCES -l <counter object>"));
769 printf (" %s\n", _("<counter object> is a Windows Perfmon Counter object (eg. Process),")); 728 printf(" %s\n", _("<counter object> is a Windows Perfmon Counter object (eg. Process),"));
770 printf (" %s\n", _("if it is two words, it should be enclosed in quotes")); 729 printf(" %s\n", _("if it is two words, it should be enclosed in quotes"));
771 printf (" %s\n", _("The returned results will be a comma-separated list of instances on ")); 730 printf(" %s\n", _("The returned results will be a comma-separated list of instances on "));
772 printf (" %s\n", _(" the selected computer for that object.")); 731 printf(" %s\n", _(" the selected computer for that object."));
773 printf (" %s\n", _("The purpose of this is to be run from command line to determine what instances")); 732 printf(" %s\n", _("The purpose of this is to be run from command line to determine what instances"));
774 printf (" %s\n", _(" are available for monitoring without having to log onto the Windows server")); 733 printf(" %s\n", _(" are available for monitoring without having to log onto the Windows server"));
775 printf (" %s\n", _(" to run Perfmon directly.")); 734 printf(" %s\n", _(" to run Perfmon directly."));
776 printf (" %s\n", _("It can also be used in scripts that automatically create the monitoring service")); 735 printf(" %s\n", _("It can also be used in scripts that automatically create the monitoring service"));
777 printf (" %s\n", _(" configuration files.")); 736 printf(" %s\n", _(" configuration files."));
778 printf (" %s\n", _("Some examples:")); 737 printf(" %s\n", _("Some examples:"));
779 printf (" %s\n\n", _("check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process")); 738 printf(" %s\n\n", _("check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process"));
780 739
781 printf ("%s\n", _("Notes:")); 740 printf("%s\n", _("Notes:"));
782 printf (" %s\n", _("- The NSClient service should be running on the server to get any information")); 741 printf(" %s\n", _("- The NSClient service should be running on the server to get any information"));
783 printf (" %s\n", "(http://nsclient.ready2run.nl)."); 742 printf(" %s\n", "(http://nsclient.ready2run.nl).");
784 printf (" %s\n", _("- Critical thresholds should be lower than warning thresholds")); 743 printf(" %s\n", _("- Critical thresholds should be lower than warning thresholds"));
785 printf (" %s\n", _("- Default port 1248 is sometimes in use by other services. The error")); 744 printf(" %s\n", _("- Default port 1248 is sometimes in use by other services. The error"));
786 printf (" %s\n", _("output when this happens contains \"Cannot map xxxxx to protocol number\".")); 745 printf(" %s\n", _("output when this happens contains \"Cannot map xxxxx to protocol number\"."));
787 printf (" %s\n", _("One fix for this is to change the port to something else on check_nt ")); 746 printf(" %s\n", _("One fix for this is to change the port to something else on check_nt "));
788 printf (" %s\n", _("and on the client service it\'s connecting to.")); 747 printf(" %s\n", _("and on the client service it\'s connecting to."));
789 748
790 printf (UT_SUPPORT); 749 printf(UT_SUPPORT);
791} 750}
792 751
793 752void print_usage(void) {
794 753 printf("%s\n", _("Usage:"));
795void print_usage(void) 754 printf("%s -H host -v variable [-p port] [-w warning] [-c critical]\n", progname);
796{ 755 printf("[-l params] [-d SHOWALL] [-u] [-t timeout]\n");
797 printf ("%s\n", _("Usage:"));
798 printf ("%s -H host -v variable [-p port] [-w warning] [-c critical]\n",progname);
799 printf ("[-l params] [-d SHOWALL] [-u] [-t timeout]\n");
800} 756}
801