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