diff options
Diffstat (limited to 'plugins/check_overcr.c')
| -rw-r--r-- | plugins/check_overcr.c | 469 |
1 files changed, 0 insertions, 469 deletions
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c deleted file mode 100644 index 5165c828..00000000 --- a/plugins/check_overcr.c +++ /dev/null | |||
| @@ -1,469 +0,0 @@ | |||
| 1 | /***************************************************************************** | ||
| 2 | * | ||
| 3 | * Monitoring check_overcr plugin | ||
| 4 | * | ||
| 5 | * License: GPL | ||
| 6 | * Copyright (c) 2000-2007 Monitoring Plugins Development Team | ||
| 7 | * | ||
| 8 | * Description: | ||
| 9 | * | ||
| 10 | * This file contains the check_overcr plugin | ||
| 11 | * | ||
| 12 | * This plugin attempts to contact the Over-CR collector daemon running on the | ||
| 13 | * remote UNIX server in order to gather the requested system information. | ||
| 14 | * | ||
| 15 | * | ||
| 16 | * This program is free software: you can redistribute it and/or modify | ||
| 17 | * it under the terms of the GNU General Public License as published by | ||
| 18 | * the Free Software Foundation, either version 3 of the License, or | ||
| 19 | * (at your option) any later version. | ||
| 20 | * | ||
| 21 | * This program is distributed in the hope that it will be useful, | ||
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 24 | * GNU General Public License for more details. | ||
| 25 | * | ||
| 26 | * You should have received a copy of the GNU General Public License | ||
| 27 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| 28 | * | ||
| 29 | * | ||
| 30 | *****************************************************************************/ | ||
| 31 | |||
| 32 | const char *progname = "check_overcr"; | ||
| 33 | const char *copyright = "2000-2007"; | ||
| 34 | const char *email = "devel@monitoring-plugins.org"; | ||
| 35 | |||
| 36 | #include "common.h" | ||
| 37 | #include "netutils.h" | ||
| 38 | #include "utils.h" | ||
| 39 | |||
| 40 | enum checkvar { | ||
| 41 | NONE, | ||
| 42 | LOAD1, | ||
| 43 | LOAD5, | ||
| 44 | LOAD15, | ||
| 45 | DPU, | ||
| 46 | PROCS, | ||
| 47 | NETSTAT, | ||
| 48 | UPTIME | ||
| 49 | }; | ||
| 50 | |||
| 51 | enum { | ||
| 52 | PORT = 2000 | ||
| 53 | }; | ||
| 54 | |||
| 55 | char *server_address = NULL; | ||
| 56 | int server_port = PORT; | ||
| 57 | double warning_value = 0L; | ||
| 58 | double critical_value = 0L; | ||
| 59 | bool check_warning_value = false; | ||
| 60 | bool check_critical_value = false; | ||
| 61 | enum checkvar vars_to_check = NONE; | ||
| 62 | int cmd_timeout = 1; | ||
| 63 | |||
| 64 | int netstat_port = 0; | ||
| 65 | char *disk_name = NULL; | ||
| 66 | char *process_name = NULL; | ||
| 67 | char send_buffer[MAX_INPUT_BUFFER]; | ||
| 68 | |||
| 69 | int process_arguments (int, char **); | ||
| 70 | void print_usage (void); | ||
| 71 | void print_help (void); | ||
| 72 | |||
| 73 | int | ||
| 74 | main (int argc, char **argv) | ||
| 75 | { | ||
| 76 | int result = STATE_UNKNOWN; | ||
| 77 | char recv_buffer[MAX_INPUT_BUFFER]; | ||
| 78 | char temp_buffer[MAX_INPUT_BUFFER]; | ||
| 79 | char *temp_ptr = NULL; | ||
| 80 | bool found_disk = false; | ||
| 81 | unsigned long percent_used_disk_space = 100; | ||
| 82 | double load; | ||
| 83 | double load_1min; | ||
| 84 | double load_5min; | ||
| 85 | double load_15min; | ||
| 86 | int port_connections = 0; | ||
| 87 | int processes = 0; | ||
| 88 | double uptime_raw_hours; | ||
| 89 | int uptime_raw_minutes = 0; | ||
| 90 | int uptime_days = 0; | ||
| 91 | int uptime_hours = 0; | ||
| 92 | int uptime_minutes = 0; | ||
| 93 | |||
| 94 | setlocale (LC_ALL, ""); | ||
| 95 | bindtextdomain (PACKAGE, LOCALEDIR); | ||
| 96 | textdomain (PACKAGE); | ||
| 97 | |||
| 98 | /* Parse extra opts if any */ | ||
| 99 | argv=np_extra_opts (&argc, argv, progname); | ||
| 100 | |||
| 101 | if (process_arguments (argc, argv) == ERROR) | ||
| 102 | usage4 (_("Could not parse arguments")); | ||
| 103 | |||
| 104 | /* initialize alarm signal handling */ | ||
| 105 | signal (SIGALRM, socket_timeout_alarm_handler); | ||
| 106 | |||
| 107 | /* set socket timeout */ | ||
| 108 | alarm (socket_timeout); | ||
| 109 | |||
| 110 | result = process_tcp_request2 (server_address, | ||
| 111 | server_port, | ||
| 112 | send_buffer, | ||
| 113 | recv_buffer, | ||
| 114 | sizeof (recv_buffer)); | ||
| 115 | |||
| 116 | switch (vars_to_check) { | ||
| 117 | |||
| 118 | case LOAD1: | ||
| 119 | case LOAD5: | ||
| 120 | case LOAD15: | ||
| 121 | |||
| 122 | if (result != STATE_OK) | ||
| 123 | die (result, _("Unknown error fetching load data\n")); | ||
| 124 | |||
| 125 | temp_ptr = (char *) strtok (recv_buffer, "\r\n"); | ||
| 126 | if (temp_ptr == NULL) | ||
| 127 | die (STATE_CRITICAL, _("Invalid response from server - no load information\n")); | ||
| 128 | else | ||
| 129 | load_1min = strtod (temp_ptr, NULL); | ||
| 130 | |||
| 131 | temp_ptr = (char *) strtok (NULL, "\r\n"); | ||
| 132 | if (temp_ptr == NULL) | ||
| 133 | die (STATE_CRITICAL, _("Invalid response from server after load 1\n")); | ||
| 134 | else | ||
| 135 | load_5min = strtod (temp_ptr, NULL); | ||
| 136 | |||
| 137 | temp_ptr = (char *) strtok (NULL, "\r\n"); | ||
| 138 | if (temp_ptr == NULL) | ||
| 139 | die (STATE_CRITICAL, _("Invalid response from server after load 5\n")); | ||
| 140 | else | ||
| 141 | load_15min = strtod (temp_ptr, NULL); | ||
| 142 | |||
| 143 | switch (vars_to_check) { | ||
| 144 | case LOAD1: | ||
| 145 | strcpy (temp_buffer, "1"); | ||
| 146 | load = load_1min; | ||
| 147 | break; | ||
| 148 | case LOAD5: | ||
| 149 | strcpy (temp_buffer, "5"); | ||
| 150 | load = load_5min; | ||
| 151 | break; | ||
| 152 | default: | ||
| 153 | strcpy (temp_buffer, "15"); | ||
| 154 | load = load_15min; | ||
| 155 | break; | ||
| 156 | } | ||
| 157 | |||
| 158 | if (check_critical_value && (load >= critical_value)) | ||
| 159 | result = STATE_CRITICAL; | ||
| 160 | else if (check_warning_value && (load >= warning_value)) | ||
| 161 | result = STATE_WARNING; | ||
| 162 | |||
| 163 | die (result, | ||
| 164 | _("Load %s - %s-min load average = %0.2f"), | ||
| 165 | state_text(result), | ||
| 166 | temp_buffer, | ||
| 167 | load); | ||
| 168 | |||
| 169 | break; | ||
| 170 | |||
| 171 | case DPU: | ||
| 172 | |||
| 173 | if (result != STATE_OK) | ||
| 174 | die (result, _("Unknown error fetching disk data\n")); | ||
| 175 | |||
| 176 | for (temp_ptr = (char *) strtok (recv_buffer, " "); | ||
| 177 | temp_ptr != NULL; | ||
| 178 | temp_ptr = (char *) strtok (NULL, " ")) { | ||
| 179 | |||
| 180 | if (!strcmp (temp_ptr, disk_name)) { | ||
| 181 | found_disk = true; | ||
| 182 | temp_ptr = (char *) strtok (NULL, "%"); | ||
| 183 | if (temp_ptr == NULL) | ||
| 184 | die (STATE_CRITICAL, _("Invalid response from server\n")); | ||
| 185 | else | ||
| 186 | percent_used_disk_space = strtoul (temp_ptr, NULL, 10); | ||
| 187 | break; | ||
| 188 | } | ||
| 189 | |||
| 190 | temp_ptr = (char *) strtok (NULL, "\r\n"); | ||
| 191 | } | ||
| 192 | |||
| 193 | /* error if we couldn't find the info for the disk */ | ||
| 194 | if (!found_disk) | ||
| 195 | die (STATE_CRITICAL, | ||
| 196 | "CRITICAL - Disk '%s' non-existent or not mounted", | ||
| 197 | disk_name); | ||
| 198 | |||
| 199 | if (check_critical_value && (percent_used_disk_space >= critical_value)) | ||
| 200 | result = STATE_CRITICAL; | ||
| 201 | else if (check_warning_value && (percent_used_disk_space >= warning_value)) | ||
| 202 | result = STATE_WARNING; | ||
| 203 | |||
| 204 | die (result, "Disk %s - %lu%% used on %s", state_text(result), percent_used_disk_space, disk_name); | ||
| 205 | |||
| 206 | break; | ||
| 207 | |||
| 208 | case NETSTAT: | ||
| 209 | |||
| 210 | if (result != STATE_OK) | ||
| 211 | die (result, _("Unknown error fetching network status\n")); | ||
| 212 | else | ||
| 213 | port_connections = strtod (recv_buffer, NULL); | ||
| 214 | |||
| 215 | if (check_critical_value && (port_connections >= critical_value)) | ||
| 216 | result = STATE_CRITICAL; | ||
| 217 | else if (check_warning_value && (port_connections >= warning_value)) | ||
| 218 | result = STATE_WARNING; | ||
| 219 | |||
| 220 | die (result, | ||
| 221 | _("Net %s - %d connection%s on port %d"), | ||
| 222 | state_text(result), | ||
| 223 | port_connections, | ||
| 224 | (port_connections == 1) ? "" : "s", | ||
| 225 | netstat_port); | ||
| 226 | |||
| 227 | break; | ||
| 228 | |||
| 229 | case PROCS: | ||
| 230 | |||
| 231 | if (result != STATE_OK) | ||
| 232 | die (result, _("Unknown error fetching process status\n")); | ||
| 233 | |||
| 234 | temp_ptr = (char *) strtok (recv_buffer, "("); | ||
| 235 | if (temp_ptr == NULL) | ||
| 236 | die (STATE_CRITICAL, _("Invalid response from server\n")); | ||
| 237 | |||
| 238 | temp_ptr = (char *) strtok (NULL, ")"); | ||
| 239 | if (temp_ptr == NULL) | ||
| 240 | die (STATE_CRITICAL, _("Invalid response from server\n")); | ||
| 241 | else | ||
| 242 | processes = strtod (temp_ptr, NULL); | ||
| 243 | |||
| 244 | if (check_critical_value && (processes >= critical_value)) | ||
| 245 | result = STATE_CRITICAL; | ||
| 246 | else if (check_warning_value && (processes >= warning_value)) | ||
| 247 | result = STATE_WARNING; | ||
| 248 | |||
| 249 | die (result, | ||
| 250 | _("Process %s - %d instance%s of %s running"), | ||
| 251 | state_text(result), | ||
| 252 | processes, | ||
| 253 | (processes == 1) ? "" : "s", | ||
| 254 | process_name); | ||
| 255 | break; | ||
| 256 | |||
| 257 | case UPTIME: | ||
| 258 | |||
| 259 | if (result != STATE_OK) | ||
| 260 | return result; | ||
| 261 | |||
| 262 | uptime_raw_hours = strtod (recv_buffer, NULL); | ||
| 263 | uptime_raw_minutes = (unsigned long) (uptime_raw_hours * 60.0); | ||
| 264 | |||
| 265 | if (check_critical_value && (uptime_raw_minutes <= critical_value)) | ||
| 266 | result = STATE_CRITICAL; | ||
| 267 | else if (check_warning_value && (uptime_raw_minutes <= warning_value)) | ||
| 268 | result = STATE_WARNING; | ||
| 269 | |||
| 270 | uptime_days = uptime_raw_minutes / 1440; | ||
| 271 | uptime_raw_minutes %= 1440; | ||
| 272 | uptime_hours = uptime_raw_minutes / 60; | ||
| 273 | uptime_raw_minutes %= 60; | ||
| 274 | uptime_minutes = uptime_raw_minutes; | ||
| 275 | |||
| 276 | die (result, | ||
| 277 | _("Uptime %s - Up %d days %d hours %d minutes"), | ||
| 278 | state_text(result), | ||
| 279 | uptime_days, | ||
| 280 | uptime_hours, | ||
| 281 | uptime_minutes); | ||
| 282 | break; | ||
| 283 | |||
| 284 | default: | ||
| 285 | die (STATE_UNKNOWN, _("Nothing to check!\n")); | ||
| 286 | break; | ||
| 287 | } | ||
| 288 | } | ||
| 289 | |||
| 290 | |||
| 291 | /* process command-line arguments */ | ||
| 292 | int | ||
| 293 | process_arguments (int argc, char **argv) | ||
| 294 | { | ||
| 295 | int c; | ||
| 296 | |||
| 297 | int option = 0; | ||
| 298 | static struct option longopts[] = { | ||
| 299 | {"port", required_argument, 0, 'p'}, | ||
| 300 | {"timeout", required_argument, 0, 't'}, | ||
| 301 | {"critical", required_argument, 0, 'c'}, | ||
| 302 | {"warning", required_argument, 0, 'w'}, | ||
| 303 | {"variable", required_argument, 0, 'v'}, | ||
| 304 | {"hostname", required_argument, 0, 'H'}, | ||
| 305 | {"version", no_argument, 0, 'V'}, | ||
| 306 | {"help", no_argument, 0, 'h'}, | ||
| 307 | {0, 0, 0, 0} | ||
| 308 | }; | ||
| 309 | |||
| 310 | /* no options were supplied */ | ||
| 311 | if (argc < 2) | ||
| 312 | return ERROR; | ||
| 313 | |||
| 314 | /* backwards compatibility */ | ||
| 315 | if (!is_option (argv[1])) { | ||
| 316 | server_address = argv[1]; | ||
| 317 | argv[1] = argv[0]; | ||
| 318 | argv = &argv[1]; | ||
| 319 | argc--; | ||
| 320 | } | ||
| 321 | |||
| 322 | for (c = 1; c < argc; c++) { | ||
| 323 | if (strcmp ("-to", argv[c]) == 0) | ||
| 324 | strcpy (argv[c], "-t"); | ||
| 325 | else if (strcmp ("-wv", argv[c]) == 0) | ||
| 326 | strcpy (argv[c], "-w"); | ||
| 327 | else if (strcmp ("-cv", argv[c]) == 0) | ||
| 328 | strcpy (argv[c], "-c"); | ||
| 329 | } | ||
| 330 | |||
| 331 | while (1) { | ||
| 332 | c = getopt_long (argc, argv, "+hVH:t:c:w:p:v:", longopts, | ||
| 333 | &option); | ||
| 334 | |||
| 335 | if (c == -1 || c == EOF || c == 1) | ||
| 336 | break; | ||
| 337 | |||
| 338 | switch (c) { | ||
| 339 | case '?': /* print short usage statement if args not parsable */ | ||
| 340 | usage5 (); | ||
| 341 | case 'h': /* help */ | ||
| 342 | print_help (); | ||
| 343 | exit (STATE_UNKNOWN); | ||
| 344 | case 'V': /* version */ | ||
| 345 | print_revision (progname, NP_VERSION); | ||
| 346 | exit (STATE_UNKNOWN); | ||
| 347 | case 'H': /* hostname */ | ||
| 348 | server_address = optarg; | ||
| 349 | break; | ||
| 350 | case 'p': /* port */ | ||
| 351 | if (is_intnonneg (optarg)) | ||
| 352 | server_port = atoi (optarg); | ||
| 353 | else | ||
| 354 | die (STATE_UNKNOWN, | ||
| 355 | _("Server port an integer\n")); | ||
| 356 | break; | ||
| 357 | case 'v': /* variable */ | ||
| 358 | if (strcmp (optarg, "LOAD") == 0) { | ||
| 359 | strcpy (send_buffer, "LOAD\r\nQUIT\r\n"); | ||
| 360 | if (strcmp (optarg, "LOAD1") == 0) | ||
| 361 | vars_to_check = LOAD1; | ||
| 362 | else if (strcmp (optarg, "LOAD5") == 0) | ||
| 363 | vars_to_check = LOAD5; | ||
| 364 | else if (strcmp (optarg, "LOAD15") == 0) | ||
| 365 | vars_to_check = LOAD15; | ||
| 366 | } | ||
| 367 | else if (strcmp (optarg, "UPTIME") == 0) { | ||
| 368 | vars_to_check = UPTIME; | ||
| 369 | strcpy (send_buffer, "UPTIME\r\n"); | ||
| 370 | } | ||
| 371 | else if (strstr (optarg, "PROC") == optarg) { | ||
| 372 | vars_to_check = PROCS; | ||
| 373 | process_name = strscpy (process_name, optarg + 4); | ||
| 374 | sprintf (send_buffer, "PROCESS %s\r\n", process_name); | ||
| 375 | } | ||
| 376 | else if (strstr (optarg, "NET") == optarg) { | ||
| 377 | vars_to_check = NETSTAT; | ||
| 378 | netstat_port = atoi (optarg + 3); | ||
| 379 | sprintf (send_buffer, "NETSTAT %d\r\n", netstat_port); | ||
| 380 | } | ||
| 381 | else if (strstr (optarg, "DPU") == optarg) { | ||
| 382 | vars_to_check = DPU; | ||
| 383 | strcpy (send_buffer, "DISKSPACE\r\n"); | ||
| 384 | disk_name = strscpy (disk_name, optarg + 3); | ||
| 385 | } | ||
| 386 | else | ||
| 387 | return ERROR; | ||
| 388 | break; | ||
| 389 | case 'w': /* warning threshold */ | ||
| 390 | warning_value = strtoul (optarg, NULL, 10); | ||
| 391 | check_warning_value = true; | ||
| 392 | break; | ||
| 393 | case 'c': /* critical threshold */ | ||
| 394 | critical_value = strtoul (optarg, NULL, 10); | ||
| 395 | check_critical_value = true; | ||
| 396 | break; | ||
| 397 | case 't': /* timeout */ | ||
| 398 | socket_timeout = atoi (optarg); | ||
| 399 | if (socket_timeout <= 0) | ||
| 400 | return ERROR; | ||
| 401 | } | ||
| 402 | |||
| 403 | } | ||
| 404 | return OK; | ||
| 405 | } | ||
| 406 | |||
| 407 | |||
| 408 | void | ||
| 409 | print_help (void) | ||
| 410 | { | ||
| 411 | char *myport; | ||
| 412 | xasprintf (&myport, "%d", PORT); | ||
| 413 | |||
| 414 | print_revision (progname, NP_VERSION); | ||
| 415 | |||
| 416 | printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n"); | ||
| 417 | printf (COPYRIGHT, copyright, email); | ||
| 418 | |||
| 419 | printf ("%s\n", _("This plugin attempts to contact the Over-CR collector daemon running on the")); | ||
| 420 | printf ("%s\n", _("remote UNIX server in order to gather the requested system information.")); | ||
| 421 | |||
| 422 | printf ("\n\n"); | ||
| 423 | |||
| 424 | print_usage (); | ||
| 425 | |||
| 426 | printf (UT_HELP_VRSN); | ||
| 427 | printf (UT_EXTRA_OPTS); | ||
| 428 | |||
| 429 | printf (UT_HOST_PORT, 'p', myport); | ||
| 430 | |||
| 431 | printf (" %s\n", "-w, --warning=INTEGER"); | ||
| 432 | printf (" %s\n", _("Threshold which will result in a warning status")); | ||
| 433 | printf (" %s\n", "-c, --critical=INTEGER"); | ||
| 434 | printf (" %s\n", _("Threshold which will result in a critical status")); | ||
| 435 | printf (" %s\n", "-v, --variable=STRING"); | ||
| 436 | printf (" %s\n", _("Variable to check. Valid variables include:")); | ||
| 437 | printf (" %s\n", _("LOAD1 = 1 minute average CPU load")); | ||
| 438 | printf (" %s\n", _("LOAD5 = 5 minute average CPU load")); | ||
| 439 | printf (" %s\n", _("LOAD15 = 15 minute average CPU load")); | ||
| 440 | printf (" %s\n", _("DPU<filesys> = percent used disk space on filesystem <filesys>")); | ||
| 441 | printf (" %s\n", _("PROC<process> = number of running processes with name <process>")); | ||
| 442 | printf (" %s\n", _("NET<port> = number of active connections on TCP port <port>")); | ||
| 443 | printf (" %s\n", _("UPTIME = system uptime in seconds")); | ||
| 444 | |||
| 445 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | ||
| 446 | |||
| 447 | printf (UT_VERBOSE); | ||
| 448 | |||
| 449 | printf ("\n"); | ||
| 450 | printf ("%s\n", _("This plugin requires that Eric Molitors' Over-CR collector daemon be")); | ||
| 451 | printf ("%s\n", _("running on the remote server.")); | ||
| 452 | printf ("%s\n", _("Over-CR can be downloaded from http://www.molitor.org/overcr")); | ||
| 453 | printf ("%s\n", _("This plugin was tested with version 0.99.53 of the Over-CR collector")); | ||
| 454 | |||
| 455 | printf ("\n"); | ||
| 456 | printf ("%s\n", _("Notes:")); | ||
| 457 | printf (" %s\n", _("For the available options, the critical threshold value should always be")); | ||
| 458 | printf (" %s\n", _("higher than the warning threshold value, EXCEPT with the uptime variable")); | ||
| 459 | |||
| 460 | printf (UT_SUPPORT); | ||
| 461 | } | ||
| 462 | |||
| 463 | |||
| 464 | void | ||
| 465 | print_usage (void) | ||
| 466 | { | ||
| 467 | printf ("%s\n", _("Usage:")); | ||
| 468 | printf ("%s -H host [-p port] [-v variable] [-w warning] [-c critical] [-t timeout]\n", progname); | ||
| 469 | } | ||
