diff options
Diffstat (limited to 'plugins/check_nt.c')
-rw-r--r-- | plugins/check_nt.c | 115 |
1 files changed, 74 insertions, 41 deletions
diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 7dd23e5c..35ca92cd 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c | |||
@@ -96,7 +96,8 @@ int main(int argc, char **argv) { | |||
96 | xasprintf(&send_buffer, "%s&1", config.req_password); | 96 | xasprintf(&send_buffer, "%s&1", config.req_password); |
97 | fetch_data(config.server_address, config.server_port, send_buffer); | 97 | fetch_data(config.server_address, config.server_port, send_buffer); |
98 | if (config.value_list != NULL && strcmp(recv_buffer, config.value_list) != 0) { | 98 | if (config.value_list != NULL && strcmp(recv_buffer, config.value_list) != 0) { |
99 | xasprintf(&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, config.value_list); | 99 | xasprintf(&output_message, _("Wrong client version - running: %s, required: %s"), |
100 | recv_buffer, config.value_list); | ||
100 | return_code = STATE_WARNING; | 101 | return_code = STATE_WARNING; |
101 | } else { | 102 | } else { |
102 | xasprintf(&output_message, "%s", recv_buffer); | 103 | xasprintf(&output_message, "%s", recv_buffer); |
@@ -116,9 +117,12 @@ int main(int argc, char **argv) { | |||
116 | 117 | ||
117 | /* loop until one of the parameters is wrong or not present */ | 118 | /* loop until one of the parameters is wrong or not present */ |
118 | int offset = 0; | 119 | int offset = 0; |
119 | while (lvalue_list[0 + offset] > (unsigned long)0 && lvalue_list[0 + offset] <= (unsigned long)17280 && | 120 | while (lvalue_list[0 + offset] > (unsigned long)0 && |
120 | lvalue_list[1 + offset] > (unsigned long)0 && lvalue_list[1 + offset] <= (unsigned long)100 && | 121 | lvalue_list[0 + offset] <= (unsigned long)17280 && |
121 | lvalue_list[2 + offset] > (unsigned long)0 && lvalue_list[2 + offset] <= (unsigned long)100) { | 122 | lvalue_list[1 + offset] > (unsigned long)0 && |
123 | lvalue_list[1 + offset] <= (unsigned long)100 && | ||
124 | lvalue_list[2 + offset] > (unsigned long)0 && | ||
125 | lvalue_list[2 + offset] <= (unsigned long)100) { | ||
122 | 126 | ||
123 | /* Send request and retrieve data */ | 127 | /* Send request and retrieve data */ |
124 | xasprintf(&send_buffer, "%s&2&%lu", config.req_password, lvalue_list[0 + offset]); | 128 | xasprintf(&send_buffer, "%s&2&%lu", config.req_password, lvalue_list[0 + offset]); |
@@ -133,10 +137,12 @@ int main(int argc, char **argv) { | |||
133 | return_code = STATE_WARNING; | 137 | return_code = STATE_WARNING; |
134 | } | 138 | } |
135 | 139 | ||
136 | xasprintf(&output_message, _(" %lu%% (%lu min average)"), utilization, lvalue_list[0 + offset]); | 140 | xasprintf(&output_message, _(" %lu%% (%lu min average)"), utilization, |
141 | lvalue_list[0 + offset]); | ||
137 | xasprintf(&temp_string, "%s%s", temp_string, output_message); | 142 | xasprintf(&temp_string, "%s%s", temp_string, output_message); |
138 | xasprintf(&perfdata, _(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0 + offset], utilization, | 143 | xasprintf(&perfdata, _(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), |
139 | lvalue_list[1 + offset], lvalue_list[2 + offset]); | 144 | lvalue_list[0 + offset], utilization, lvalue_list[1 + offset], |
145 | lvalue_list[2 + offset]); | ||
140 | xasprintf(&temp_string_perf, "%s%s", temp_string_perf, perfdata); | 146 | xasprintf(&temp_string_perf, "%s%s", temp_string_perf, perfdata); |
141 | offset += 3; /* move across the array */ | 147 | offset += 3; /* move across the array */ |
142 | } | 148 | } |
@@ -154,8 +160,10 @@ int main(int argc, char **argv) { | |||
154 | if (config.value_list == NULL) { | 160 | if (config.value_list == NULL) { |
155 | tmp_value_list = "minutes"; | 161 | tmp_value_list = "minutes"; |
156 | } | 162 | } |
157 | if (strncmp(tmp_value_list, "seconds", strlen("seconds") + 1) && strncmp(tmp_value_list, "minutes", strlen("minutes") + 1) && | 163 | if (strncmp(tmp_value_list, "seconds", strlen("seconds") + 1) && |
158 | strncmp(config.value_list, "hours", strlen("hours") + 1) && strncmp(tmp_value_list, "days", strlen("days") + 1)) { | 164 | strncmp(tmp_value_list, "minutes", strlen("minutes") + 1) && |
165 | strncmp(config.value_list, "hours", strlen("hours") + 1) && | ||
166 | strncmp(tmp_value_list, "days", strlen("days") + 1)) { | ||
159 | 167 | ||
160 | output_message = strdup(_("wrong -l argument")); | 168 | output_message = strdup(_("wrong -l argument")); |
161 | } else { | 169 | } else { |
@@ -175,8 +183,9 @@ int main(int argc, char **argv) { | |||
175 | } | 183 | } |
176 | /* else uptime in seconds, nothing to do */ | 184 | /* else uptime in seconds, nothing to do */ |
177 | 185 | ||
178 | xasprintf(&output_message, _("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"), updays, uphours, upminutes, | 186 | xasprintf(&output_message, |
179 | uptime); | 187 | _("System Uptime - %u day(s) %u hour(s) %u minute(s) |uptime=%lu"), updays, |
188 | uphours, upminutes, uptime); | ||
180 | 189 | ||
181 | if (config.check_critical_value && uptime <= config.critical_value) { | 190 | if (config.check_critical_value && uptime <= config.critical_value) { |
182 | return_code = STATE_CRITICAL; | 191 | return_code = STATE_CRITICAL; |
@@ -207,20 +216,27 @@ int main(int argc, char **argv) { | |||
207 | } | 216 | } |
208 | 217 | ||
209 | if (total_disk_space > 0 && free_disk_space >= 0) { | 218 | if (total_disk_space > 0 && free_disk_space >= 0) { |
210 | double percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100; | 219 | double percent_used_space = |
220 | ((total_disk_space - free_disk_space) / total_disk_space) * 100; | ||
211 | double warning_used_space = ((float)config.warning_value / 100) * total_disk_space; | 221 | double warning_used_space = ((float)config.warning_value / 100) * total_disk_space; |
212 | double critical_used_space = ((float)config.critical_value / 100) * total_disk_space; | 222 | double critical_used_space = |
213 | 223 | ((float)config.critical_value / 100) * total_disk_space; | |
214 | xasprintf(&temp_string, _("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), config.value_list, | 224 | |
215 | total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, percent_used_space, | 225 | xasprintf( |
216 | free_disk_space / 1073741824, (free_disk_space / total_disk_space) * 100); | 226 | &temp_string, |
217 | xasprintf(&temp_string_perf, _("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), config.value_list, | 227 | _("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), |
218 | (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824, | 228 | config.value_list, total_disk_space / 1073741824, |
219 | critical_used_space / 1073741824, total_disk_space / 1073741824); | 229 | (total_disk_space - free_disk_space) / 1073741824, percent_used_space, |
230 | free_disk_space / 1073741824, (free_disk_space / total_disk_space) * 100); | ||
231 | xasprintf(&temp_string_perf, _("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), | ||
232 | config.value_list, (total_disk_space - free_disk_space) / 1073741824, | ||
233 | warning_used_space / 1073741824, critical_used_space / 1073741824, | ||
234 | total_disk_space / 1073741824); | ||
220 | 235 | ||
221 | if (config.check_critical_value && percent_used_space >= config.critical_value) { | 236 | if (config.check_critical_value && percent_used_space >= config.critical_value) { |
222 | return_code = STATE_CRITICAL; | 237 | return_code = STATE_CRITICAL; |
223 | } else if (config.check_warning_value && percent_used_space >= config.warning_value) { | 238 | } else if (config.check_warning_value && |
239 | percent_used_space >= config.warning_value) { | ||
224 | return_code = STATE_WARNING; | 240 | return_code = STATE_WARNING; |
225 | } else { | 241 | } else { |
226 | return_code = STATE_OK; | 242 | return_code = STATE_OK; |
@@ -239,8 +255,10 @@ int main(int argc, char **argv) { | |||
239 | if (config.value_list == NULL) { | 255 | if (config.value_list == NULL) { |
240 | output_message = strdup(_("No service/process specified")); | 256 | output_message = strdup(_("No service/process specified")); |
241 | } else { | 257 | } else { |
242 | preparelist(config.value_list); /* replace , between services with & to send the request */ | 258 | preparelist( |
243 | xasprintf(&send_buffer, "%s&%u&%s&%s", config.req_password, (config.vars_to_check == CHECK_SERVICESTATE) ? 5 : 6, | 259 | config.value_list); /* replace , between services with & to send the request */ |
260 | xasprintf(&send_buffer, "%s&%u&%s&%s", config.req_password, | ||
261 | (config.vars_to_check == CHECK_SERVICESTATE) ? 5 : 6, | ||
244 | (config.show_all) ? "ShowAll" : "ShowFail", config.value_list); | 262 | (config.show_all) ? "ShowAll" : "ShowFail", config.value_list); |
245 | fetch_data(config.server_address, config.server_port, send_buffer); | 263 | fetch_data(config.server_address, config.server_port, send_buffer); |
246 | char *numstr = strtok(recv_buffer, "&"); | 264 | char *numstr = strtok(recv_buffer, "&"); |
@@ -271,10 +289,14 @@ int main(int argc, char **argv) { | |||
271 | 289 | ||
272 | /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here, | 290 | /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here, |
273 | which equals RAM + Pagefiles. */ | 291 | which equals RAM + Pagefiles. */ |
274 | xasprintf(&output_message, _("Memory usage: total:%.2f MB - used: %.2f MB (%.0f%%) - free: %.2f MB (%.0f%%)"), | 292 | xasprintf( |
275 | mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space, (mem_commitLimit - mem_commitByte) / 1048567, | 293 | &output_message, |
276 | (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100); | 294 | _("Memory usage: total:%.2f MB - used: %.2f MB (%.0f%%) - free: %.2f MB (%.0f%%)"), |
277 | xasprintf(&perfdata, _("'Memory usage'=%.2fMB;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567, warning_used_space / 1048567, | 295 | mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space, |
296 | (mem_commitLimit - mem_commitByte) / 1048567, | ||
297 | (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100); | ||
298 | xasprintf(&perfdata, _("'Memory usage'=%.2fMB;%.2f;%.2f;0.00;%.2f"), | ||
299 | mem_commitByte / 1048567, warning_used_space / 1048567, | ||
278 | critical_used_space / 1048567, mem_commitLimit / 1048567); | 300 | critical_used_space / 1048567, mem_commitLimit / 1048567); |
279 | 301 | ||
280 | return_code = STATE_OK; | 302 | return_code = STATE_OK; |
@@ -302,16 +324,17 @@ int main(int argc, char **argv) { | |||
302 | the counter unit - that is, the dimensions of the counter you're getting. Examples: | 324 | the counter unit - that is, the dimensions of the counter you're getting. Examples: |
303 | pages/s, packets transferred, etc. | 325 | pages/s, packets transferred, etc. |
304 | 326 | ||
305 | 4) If you want, you may provide the minimum and maximum values to expect. They aren't mandatory, | 327 | 4) If you want, you may provide the minimum and maximum values to expect. They aren't |
306 | but once specified they MUST have the same order of magnitude and units of -w and -c; otherwise. | 328 | mandatory, but once specified they MUST have the same order of magnitude and units of -w and |
307 | strange things will happen when you make graphs of your data. | 329 | -c; otherwise. strange things will happen when you make graphs of your data. |
308 | */ | 330 | */ |
309 | 331 | ||
310 | double counter_value = 0.0; | 332 | double counter_value = 0.0; |
311 | if (config.value_list == NULL) { | 333 | if (config.value_list == NULL) { |
312 | output_message = strdup(_("No counter specified")); | 334 | output_message = strdup(_("No counter specified")); |
313 | } else { | 335 | } else { |
314 | preparelist(config.value_list); /* replace , between services with & to send the request */ | 336 | preparelist( |
337 | config.value_list); /* replace , between services with & to send the request */ | ||
315 | bool isPercent = (strchr(config.value_list, '%') != NULL); | 338 | bool isPercent = (strchr(config.value_list, '%') != NULL); |
316 | 339 | ||
317 | strtok(config.value_list, "&"); /* burn the first parameters */ | 340 | strtok(config.value_list, "&"); /* burn the first parameters */ |
@@ -358,15 +381,18 @@ int main(int argc, char **argv) { | |||
358 | if (allRight) { | 381 | if (allRight) { |
359 | /* Let's format the output string, finally... */ | 382 | /* Let's format the output string, finally... */ |
360 | if (strstr(description, "%") == NULL) { | 383 | if (strstr(description, "%") == NULL) { |
361 | xasprintf(&output_message, "%s = %.2f %s", description, counter_value, counter_unit); | 384 | xasprintf(&output_message, "%s = %.2f %s", description, counter_value, |
385 | counter_unit); | ||
362 | } else { | 386 | } else { |
363 | /* has formatting, will segv if wrong */ | 387 | /* has formatting, will segv if wrong */ |
364 | xasprintf(&output_message, description, counter_value); | 388 | xasprintf(&output_message, description, counter_value); |
365 | } | 389 | } |
366 | xasprintf(&output_message, "%s |", output_message); | 390 | xasprintf(&output_message, "%s |", output_message); |
367 | xasprintf(&output_message, "%s %s", output_message, | 391 | xasprintf(&output_message, "%s %s", output_message, |
368 | fperfdata(description, counter_value, counter_unit, 1, config.warning_value, 1, config.critical_value, | 392 | fperfdata(description, counter_value, counter_unit, 1, |
369 | (!(isPercent) && (minval != NULL)), fminval, (!(isPercent) && (minval != NULL)), fmaxval)); | 393 | config.warning_value, 1, config.critical_value, |
394 | (!(isPercent) && (minval != NULL)), fminval, | ||
395 | (!(isPercent) && (minval != NULL)), fmaxval)); | ||
370 | } | 396 | } |
371 | } | 397 | } |
372 | 398 | ||
@@ -391,7 +417,8 @@ int main(int argc, char **argv) { | |||
391 | if (config.value_list == NULL) { | 417 | if (config.value_list == NULL) { |
392 | output_message = strdup(_("No counter specified")); | 418 | output_message = strdup(_("No counter specified")); |
393 | } else { | 419 | } else { |
394 | preparelist(config.value_list); /* replace , between services with & to send the request */ | 420 | preparelist( |
421 | config.value_list); /* replace , between services with & to send the request */ | ||
395 | xasprintf(&send_buffer, "%s&9&%s", config.req_password, config.value_list); | 422 | xasprintf(&send_buffer, "%s&9&%s", config.req_password, config.value_list); |
396 | fetch_data(config.server_address, config.server_port, send_buffer); | 423 | fetch_data(config.server_address, config.server_port, send_buffer); |
397 | unsigned long age_in_minutes = atoi(strtok(recv_buffer, "&")); | 424 | unsigned long age_in_minutes = atoi(strtok(recv_buffer, "&")); |
@@ -724,25 +751,31 @@ void print_help(void) { | |||
724 | printf(" %s\n", "\"%%.f %%%% paging file used.\""); | 751 | printf(" %s\n", "\"%%.f %%%% paging file used.\""); |
725 | printf(" %s\n", "INSTANCES ="); | 752 | printf(" %s\n", "INSTANCES ="); |
726 | printf(" %s\n", _("Check any performance counter object of Windows NT/2000.")); | 753 | printf(" %s\n", _("Check any performance counter object of Windows NT/2000.")); |
727 | printf(" %s\n", _("Syntax: check_nt -H <hostname> -p <port> -v INSTANCES -l <counter object>")); | 754 | printf(" %s\n", |
755 | _("Syntax: check_nt -H <hostname> -p <port> -v INSTANCES -l <counter object>")); | ||
728 | printf(" %s\n", _("<counter object> is a Windows Perfmon Counter object (eg. Process),")); | 756 | printf(" %s\n", _("<counter object> is a Windows Perfmon Counter object (eg. Process),")); |
729 | printf(" %s\n", _("if it is two words, it should be enclosed in quotes")); | 757 | printf(" %s\n", _("if it is two words, it should be enclosed in quotes")); |
730 | printf(" %s\n", _("The returned results will be a comma-separated list of instances on ")); | 758 | printf(" %s\n", _("The returned results will be a comma-separated list of instances on ")); |
731 | printf(" %s\n", _(" the selected computer for that object.")); | 759 | printf(" %s\n", _(" the selected computer for that object.")); |
732 | printf(" %s\n", _("The purpose of this is to be run from command line to determine what instances")); | 760 | printf(" %s\n", |
733 | printf(" %s\n", _(" are available for monitoring without having to log onto the Windows server")); | 761 | _("The purpose of this is to be run from command line to determine what instances")); |
762 | printf(" %s\n", | ||
763 | _(" are available for monitoring without having to log onto the Windows server")); | ||
734 | printf(" %s\n", _(" to run Perfmon directly.")); | 764 | printf(" %s\n", _(" to run Perfmon directly.")); |
735 | printf(" %s\n", _("It can also be used in scripts that automatically create the monitoring service")); | 765 | printf(" %s\n", |
766 | _("It can also be used in scripts that automatically create the monitoring service")); | ||
736 | printf(" %s\n", _(" configuration files.")); | 767 | printf(" %s\n", _(" configuration files.")); |
737 | printf(" %s\n", _("Some examples:")); | 768 | printf(" %s\n", _("Some examples:")); |
738 | printf(" %s\n\n", _("check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process")); | 769 | printf(" %s\n\n", _("check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process")); |
739 | 770 | ||
740 | printf("%s\n", _("Notes:")); | 771 | printf("%s\n", _("Notes:")); |
741 | printf(" %s\n", _("- The NSClient service should be running on the server to get any information")); | 772 | printf(" %s\n", |
773 | _("- The NSClient service should be running on the server to get any information")); | ||
742 | printf(" %s\n", "(http://nsclient.ready2run.nl)."); | 774 | printf(" %s\n", "(http://nsclient.ready2run.nl)."); |
743 | printf(" %s\n", _("- Critical thresholds should be lower than warning thresholds")); | 775 | printf(" %s\n", _("- Critical thresholds should be lower than warning thresholds")); |
744 | printf(" %s\n", _("- Default port 1248 is sometimes in use by other services. The error")); | 776 | printf(" %s\n", _("- Default port 1248 is sometimes in use by other services. The error")); |
745 | printf(" %s\n", _("output when this happens contains \"Cannot map xxxxx to protocol number\".")); | 777 | printf(" %s\n", |
778 | _("output when this happens contains \"Cannot map xxxxx to protocol number\".")); | ||
746 | printf(" %s\n", _("One fix for this is to change the port to something else on check_nt ")); | 779 | printf(" %s\n", _("One fix for this is to change the port to something else on check_nt ")); |
747 | printf(" %s\n", _("and on the client service it\'s connecting to.")); | 780 | printf(" %s\n", _("and on the client service it\'s connecting to.")); |
748 | 781 | ||