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