diff options
| -rw-r--r-- | plugins/check_overcr.c | 425 |
1 files changed, 201 insertions, 224 deletions
diff --git a/plugins/check_overcr.c b/plugins/check_overcr.c index 4c3b957f..4ee47a51 100644 --- a/plugins/check_overcr.c +++ b/plugins/check_overcr.c | |||
| @@ -1,64 +1,44 @@ | |||
| 1 | /****************************************************************************** | 1 | /****************************************************************************** |
| 2 | * | ||
| 3 | * CHECK_OVERCR.C | ||
| 4 | * | ||
| 5 | * Program: Over-CR collector plugin for Nagios | ||
| 6 | * License: GPL | ||
| 7 | * Copyright (c) 1999 Ethan Galstad (nagios@nagios.org) | ||
| 8 | * | ||
| 9 | * $Id$ | ||
| 10 | * | ||
| 11 | * Description: | ||
| 12 | * | ||
| 13 | * Notes: | ||
| 14 | * - This plugin requires that Eric Molitors' Over-CR collector daemon | ||
| 15 | * be running on any UNIX boxes you want to monitor. Over-CR | ||
| 16 | * is available from * http://www.molitor.org/overcr/ | ||
| 17 | * | ||
| 18 | * Modifications: | ||
| 19 | * | ||
| 20 | * 08-11-999 Jacob Lundqvist <jaclu@grm.se> | ||
| 21 | * Load was presented as a one digit percentage - changed to two digit | ||
| 22 | * value * before load of 11.2 was presented as "1.2%" (not very | ||
| 23 | * high). Warning and Critical params were int's, not very good | ||
| 24 | * for load, changed to doubles, so we can trap loadlimits like | ||
| 25 | * 1.5. Also added more informative LOAD error messages. | ||
| 26 | * | ||
| 27 | * License Information: | ||
| 28 | * | ||
| 29 | * This program is free software; you can redistribute it and/or modify | ||
| 30 | * it under the terms of the GNU General Public License as published by | ||
| 31 | * the Free Software Foundation; either version 2 of the License, or | ||
| 32 | * (at your option) any later version. | ||
| 33 | * | ||
| 34 | * This program is distributed in the hope that it will be useful, | ||
| 35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 36 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 37 | * GNU General Public License for more details. | ||
| 38 | * | ||
| 39 | * You should have received a copy of the GNU General Public License | ||
| 40 | * along with this program; if not, write to the Free Software | ||
| 41 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 42 | * | ||
| 43 | *****************************************************************************/ | ||
| 44 | |||
| 45 | #include "config.h" | ||
| 46 | #include "common.h" | ||
| 47 | #include "netutils.h" | ||
| 48 | #include "utils.h" | ||
| 49 | 2 | ||
| 50 | #define CHECK_NONE 0 | 3 | This program is free software; you can redistribute it and/or modify |
| 51 | #define CHECK_LOAD1 1 | 4 | it under the terms of the GNU General Public License as published by |
| 52 | #define CHECK_LOAD5 2 | 5 | the Free Software Foundation; either version 2 of the License, or |
| 53 | #define CHECK_LOAD15 4 | 6 | (at your option) any later version. |
| 54 | #define CHECK_DPU 8 | 7 | |
| 55 | #define CHECK_PROCS 16 | 8 | This program is distributed in the hope that it will be useful, |
| 56 | #define CHECK_NETSTAT 32 | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 57 | #define CHECK_UPTIME 64 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. | ||
| 58 | 12 | ||
| 59 | #define PORT 2000 | 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program; if not, write to the Free Software | ||
| 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
| 16 | |||
| 17 | ******************************************************************************/ | ||
| 60 | 18 | ||
| 61 | const char *progname = "check_overcr"; | 19 | const char *progname = "check_overcr"; |
| 20 | const char *revision = "$Revision$"; | ||
| 21 | const char *copyright = "2000-2003"; | ||
| 22 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | ||
| 23 | |||
| 24 | #include "common.h" | ||
| 25 | #include "netutils.h" | ||
| 26 | #include "utils.h" | ||
| 27 | |||
| 28 | enum checkvar { | ||
| 29 | NONE, | ||
| 30 | LOAD1, | ||
| 31 | LOAD5, | ||
| 32 | LOAD15, | ||
| 33 | DPU, | ||
| 34 | PROCS, | ||
| 35 | NETSTAT, | ||
| 36 | UPTIME | ||
| 37 | }; | ||
| 38 | |||
| 39 | enum { | ||
| 40 | PORT = 2000 | ||
| 41 | }; | ||
| 62 | 42 | ||
| 63 | char *server_address = NULL; | 43 | char *server_address = NULL; |
| 64 | int server_port = PORT; | 44 | int server_port = PORT; |
| @@ -66,12 +46,13 @@ double warning_value = 0L; | |||
| 66 | double critical_value = 0L; | 46 | double critical_value = 0L; |
| 67 | int check_warning_value = FALSE; | 47 | int check_warning_value = FALSE; |
| 68 | int check_critical_value = FALSE; | 48 | int check_critical_value = FALSE; |
| 69 | int vars_to_check = CHECK_NONE; | 49 | enum checkvar vars_to_check = NONE; |
| 70 | int cmd_timeout = 1; | 50 | int cmd_timeout = 1; |
| 71 | 51 | ||
| 72 | int netstat_port = 0; | 52 | int netstat_port = 0; |
| 73 | char *disk_name = NULL; | 53 | char *disk_name = NULL; |
| 74 | char *process_name = NULL; | 54 | char *process_name = NULL; |
| 55 | char send_buffer[MAX_INPUT_BUFFER]; | ||
| 75 | 56 | ||
| 76 | int process_arguments (int, char **); | 57 | int process_arguments (int, char **); |
| 77 | void print_usage (void); | 58 | void print_usage (void); |
| @@ -81,9 +62,7 @@ int | |||
| 81 | main (int argc, char **argv) | 62 | main (int argc, char **argv) |
| 82 | { | 63 | { |
| 83 | int result; | 64 | int result; |
| 84 | char send_buffer[MAX_INPUT_BUFFER]; | ||
| 85 | char recv_buffer[MAX_INPUT_BUFFER]; | 65 | char recv_buffer[MAX_INPUT_BUFFER]; |
| 86 | char output_message[MAX_INPUT_BUFFER]; | ||
| 87 | char temp_buffer[MAX_INPUT_BUFFER]; | 66 | char temp_buffer[MAX_INPUT_BUFFER]; |
| 88 | char *temp_ptr = NULL; | 67 | char *temp_ptr = NULL; |
| 89 | int found_disk = FALSE; | 68 | int found_disk = FALSE; |
| @@ -109,44 +88,42 @@ main (int argc, char **argv) | |||
| 109 | /* set socket timeout */ | 88 | /* set socket timeout */ |
| 110 | alarm (socket_timeout); | 89 | alarm (socket_timeout); |
| 111 | 90 | ||
| 112 | result = STATE_OK; | 91 | result = process_tcp_request2 (server_address, |
| 92 | server_port, | ||
| 93 | send_buffer, | ||
| 94 | recv_buffer, | ||
| 95 | sizeof (recv_buffer)); | ||
| 113 | 96 | ||
| 114 | if (vars_to_check == CHECK_LOAD1 || vars_to_check == CHECK_LOAD5 | 97 | switch (vars_to_check) { |
| 115 | || vars_to_check == CHECK_LOAD15) { | ||
| 116 | 98 | ||
| 117 | strcpy (send_buffer, "LOAD\r\nQUIT\r\n"); | 99 | case LOAD1: |
| 118 | result = | 100 | case LOAD5: |
| 119 | process_tcp_request2 (server_address, server_port, send_buffer, | 101 | case LOAD15: |
| 120 | recv_buffer, sizeof (recv_buffer)); | 102 | |
| 121 | if (result != STATE_OK) | 103 | if (result != STATE_OK) |
| 122 | return result; | 104 | terminate (result, _("Unknown error fetching load data\n")); |
| 123 | 105 | ||
| 124 | temp_ptr = (char *) strtok (recv_buffer, "\r\n"); | 106 | temp_ptr = (char *) strtok (recv_buffer, "\r\n"); |
| 125 | if (temp_ptr == NULL) { | 107 | if (temp_ptr == NULL) |
| 126 | printf ("Invalid response from server - no load information\n"); | 108 | terminate (STATE_CRITICAL, _("Invalid response from server - no load information\n")); |
| 127 | return STATE_CRITICAL; | ||
| 128 | } | ||
| 129 | load_1min = strtod (temp_ptr, NULL); | 109 | load_1min = strtod (temp_ptr, NULL); |
| 110 | |||
| 130 | temp_ptr = (char *) strtok (NULL, "\r\n"); | 111 | temp_ptr = (char *) strtok (NULL, "\r\n"); |
| 131 | if (temp_ptr == NULL) { | 112 | if (temp_ptr == NULL) |
| 132 | printf ("Invalid response from server after load 1\n"); | 113 | terminate (STATE_CRITICAL, _("Invalid response from server after load 1\n")); |
| 133 | return STATE_CRITICAL; | ||
| 134 | } | ||
| 135 | load_5min = strtod (temp_ptr, NULL); | 114 | load_5min = strtod (temp_ptr, NULL); |
| 115 | |||
| 136 | temp_ptr = (char *) strtok (NULL, "\r\n"); | 116 | temp_ptr = (char *) strtok (NULL, "\r\n"); |
| 137 | if (temp_ptr == NULL) { | 117 | if (temp_ptr == NULL) |
| 138 | printf ("Invalid response from server after load 5\n"); | 118 | terminate (STATE_CRITICAL, _("Invalid response from server after load 5\n")); |
| 139 | return STATE_CRITICAL; | ||
| 140 | } | ||
| 141 | load_15min = strtod (temp_ptr, NULL); | 119 | load_15min = strtod (temp_ptr, NULL); |
| 142 | 120 | ||
| 143 | |||
| 144 | switch (vars_to_check) { | 121 | switch (vars_to_check) { |
| 145 | case CHECK_LOAD1: | 122 | case LOAD1: |
| 146 | strcpy (temp_buffer, "1"); | 123 | strcpy (temp_buffer, "1"); |
| 147 | load = load_1min; | 124 | load = load_1min; |
| 148 | break; | 125 | break; |
| 149 | case CHECK_LOAD5: | 126 | case LOAD5: |
| 150 | strcpy (temp_buffer, "5"); | 127 | strcpy (temp_buffer, "5"); |
| 151 | load = load_5min; | 128 | load = load_5min; |
| 152 | break; | 129 | break; |
| @@ -160,30 +137,29 @@ main (int argc, char **argv) | |||
| 160 | result = STATE_CRITICAL; | 137 | result = STATE_CRITICAL; |
| 161 | else if (check_warning_value == TRUE && (load >= warning_value)) | 138 | else if (check_warning_value == TRUE && (load >= warning_value)) |
| 162 | result = STATE_WARNING; | 139 | result = STATE_WARNING; |
| 163 | sprintf (output_message, "Load %s - %s-min load average = %0.2f", | ||
| 164 | (result == STATE_OK) ? "ok" : "problem", temp_buffer, load); | ||
| 165 | } | ||
| 166 | 140 | ||
| 141 | terminate (result, | ||
| 142 | _("Load %s - %s-min load average = %0.2f"), | ||
| 143 | state_text(result), | ||
| 144 | temp_buffer, | ||
| 145 | load); | ||
| 146 | |||
| 147 | break; | ||
| 167 | 148 | ||
| 168 | else if (vars_to_check == CHECK_DPU) { | 149 | case DPU: |
| 169 | 150 | ||
| 170 | sprintf (send_buffer, "DISKSPACE\r\n"); | ||
| 171 | result = | ||
| 172 | process_tcp_request2 (server_address, server_port, send_buffer, | ||
| 173 | recv_buffer, sizeof (recv_buffer)); | ||
| 174 | if (result != STATE_OK) | 151 | if (result != STATE_OK) |
| 175 | return result; | 152 | terminate (result, _("Unknown error fetching disk data\n")); |
| 176 | 153 | ||
| 177 | for (temp_ptr = (char *) strtok (recv_buffer, " "); temp_ptr != NULL; | 154 | for (temp_ptr = (char *) strtok (recv_buffer, " "); |
| 178 | temp_ptr = (char *) strtok (NULL, " ")) { | 155 | temp_ptr != NULL; |
| 156 | temp_ptr = (char *) strtok (NULL, " ")) { | ||
| 179 | 157 | ||
| 180 | if (!strcmp (temp_ptr, disk_name)) { | 158 | if (!strcmp (temp_ptr, disk_name)) { |
| 181 | found_disk = TRUE; | 159 | found_disk = TRUE; |
| 182 | temp_ptr = (char *) strtok (NULL, "%"); | 160 | temp_ptr = (char *) strtok (NULL, "%"); |
| 183 | if (temp_ptr == NULL) { | 161 | if (temp_ptr == NULL) |
| 184 | printf ("Invalid response from server\n"); | 162 | terminate (STATE_CRITICAL, _("Invalid response from server\n")); |
| 185 | return STATE_CRITICAL; | ||
| 186 | } | ||
| 187 | percent_used_disk_space = strtoul (temp_ptr, NULL, 10); | 163 | percent_used_disk_space = strtoul (temp_ptr, NULL, 10); |
| 188 | break; | 164 | break; |
| 189 | } | 165 | } |
| @@ -192,68 +168,54 @@ main (int argc, char **argv) | |||
| 192 | } | 168 | } |
| 193 | 169 | ||
| 194 | /* error if we couldn't find the info for the disk */ | 170 | /* error if we couldn't find the info for the disk */ |
| 195 | if (found_disk == FALSE) { | 171 | if (found_disk == FALSE) |
| 196 | sprintf (output_message, "Error: Disk '%s' non-existent or not mounted", | 172 | terminate (STATE_CRITICAL, |
| 197 | disk_name); | 173 | "Error: Disk '%s' non-existent or not mounted", |
| 198 | result = STATE_CRITICAL; | 174 | disk_name); |
| 199 | } | ||
| 200 | 175 | ||
| 201 | /* else check the disk space used */ | 176 | if (check_critical_value == TRUE && (percent_used_disk_space >= critical_value)) |
| 202 | else { | 177 | result = STATE_CRITICAL; |
| 178 | else if (check_warning_value == TRUE && (percent_used_disk_space >= warning_value)) | ||
| 179 | result = STATE_WARNING; | ||
| 203 | 180 | ||
| 204 | if (check_critical_value == TRUE | 181 | terminate (result, "Disk %s - %lu%% used on %s", state_text(result), percent_used_disk_space, disk_name); |
| 205 | && (percent_used_disk_space >= critical_value)) result = | ||
| 206 | STATE_CRITICAL; | ||
| 207 | else if (check_warning_value == TRUE | ||
| 208 | && (percent_used_disk_space >= warning_value)) result = | ||
| 209 | STATE_WARNING; | ||
| 210 | 182 | ||
| 211 | sprintf (output_message, "Disk %s - %lu%% used on %s", | 183 | break; |
| 212 | (result == STATE_OK) ? "ok" : "problem", | ||
| 213 | percent_used_disk_space, disk_name); | ||
| 214 | } | ||
| 215 | } | ||
| 216 | 184 | ||
| 217 | else if (vars_to_check == CHECK_NETSTAT) { | 185 | case NETSTAT: |
| 218 | 186 | ||
| 219 | sprintf (send_buffer, "NETSTAT %d\r\n", netstat_port); | ||
| 220 | result = | ||
| 221 | process_tcp_request2 (server_address, server_port, send_buffer, | ||
| 222 | recv_buffer, sizeof (recv_buffer)); | ||
| 223 | if (result != STATE_OK) | 187 | if (result != STATE_OK) |
| 224 | return result; | 188 | terminate (result, _("Unknown error fetching network status\n")); |
| 225 | 189 | ||
| 226 | port_connections = strtod (recv_buffer, NULL); | 190 | port_connections = strtod (recv_buffer, NULL); |
| 227 | 191 | ||
| 228 | if (check_critical_value == TRUE && (port_connections >= critical_value)) | 192 | if (check_critical_value == TRUE && (port_connections >= critical_value)) |
| 229 | result = STATE_CRITICAL; | 193 | result = STATE_CRITICAL; |
| 230 | else if (check_warning_value == TRUE | 194 | else if (check_warning_value == TRUE && (port_connections >= warning_value)) |
| 231 | && (port_connections >= warning_value)) result = STATE_WARNING; | 195 | result = STATE_WARNING; |
| 232 | 196 | ||
| 233 | sprintf (output_message, "Net %s - %d connection%s on port %d", | 197 | terminate (result, |
| 234 | (result == STATE_OK) ? "ok" : "problem", port_connections, | 198 | _("Net %s - %d connection%s on port %d"), |
| 235 | (port_connections == 1) ? "" : "s", netstat_port); | 199 | state_text(result), |
| 236 | } | 200 | port_connections, |
| 201 | (port_connections == 1) ? "" : "s", | ||
| 202 | netstat_port); | ||
| 203 | |||
| 204 | break; | ||
| 237 | 205 | ||
| 238 | else if (vars_to_check == CHECK_PROCS) { | 206 | case PROCS: |
| 239 | 207 | ||
| 240 | sprintf (send_buffer, "PROCESS %s\r\n", process_name); | ||
| 241 | result = | ||
| 242 | process_tcp_request2 (server_address, server_port, send_buffer, | ||
| 243 | recv_buffer, sizeof (recv_buffer)); | ||
| 244 | if (result != STATE_OK) | 208 | if (result != STATE_OK) |
| 245 | return result; | 209 | terminate (result, _("Unknown error fetching process status\n")); |
| 246 | 210 | ||
| 247 | temp_ptr = (char *) strtok (recv_buffer, "("); | 211 | temp_ptr = (char *) strtok (recv_buffer, "("); |
| 248 | if (temp_ptr == NULL) { | 212 | if (temp_ptr == NULL) |
| 249 | printf ("Invalid response from server\n"); | 213 | terminate (STATE_CRITICAL, _("Invalid response from server\n")); |
| 250 | return STATE_CRITICAL; | 214 | |
| 251 | } | ||
| 252 | temp_ptr = (char *) strtok (NULL, ")"); | 215 | temp_ptr = (char *) strtok (NULL, ")"); |
| 253 | if (temp_ptr == NULL) { | 216 | if (temp_ptr == NULL) |
| 254 | printf ("Invalid response from server\n"); | 217 | terminate (STATE_CRITICAL, _("Invalid response from server\n")); |
| 255 | return STATE_CRITICAL; | 218 | |
| 256 | } | ||
| 257 | processes = strtod (temp_ptr, NULL); | 219 | processes = strtod (temp_ptr, NULL); |
| 258 | 220 | ||
| 259 | if (check_critical_value == TRUE && (processes >= critical_value)) | 221 | if (check_critical_value == TRUE && (processes >= critical_value)) |
| @@ -261,27 +223,26 @@ main (int argc, char **argv) | |||
| 261 | else if (check_warning_value == TRUE && (processes >= warning_value)) | 223 | else if (check_warning_value == TRUE && (processes >= warning_value)) |
| 262 | result = STATE_WARNING; | 224 | result = STATE_WARNING; |
| 263 | 225 | ||
| 264 | sprintf (output_message, "Process %s - %d instance%s of %s running", | 226 | terminate (result, |
| 265 | (result == STATE_OK) ? "ok" : "problem", processes, | 227 | _("Process %s - %d instance%s of %s running"), |
| 266 | (processes == 1) ? "" : "s", process_name); | 228 | state_text(result), |
| 267 | } | 229 | processes, |
| 230 | (processes == 1) ? "" : "s", | ||
| 231 | process_name); | ||
| 232 | break; | ||
| 268 | 233 | ||
| 269 | else if (vars_to_check == CHECK_UPTIME) { | 234 | case UPTIME: |
| 270 | 235 | ||
| 271 | sprintf (send_buffer, "UPTIME\r\n"); | ||
| 272 | result = | ||
| 273 | process_tcp_request2 (server_address, server_port, send_buffer, | ||
| 274 | recv_buffer, sizeof (recv_buffer)); | ||
| 275 | if (result != STATE_OK) | 236 | if (result != STATE_OK) |
| 276 | return result; | 237 | return result; |
| 277 | 238 | ||
| 278 | uptime_raw_hours = strtod (recv_buffer, NULL); | 239 | uptime_raw_hours = strtod (recv_buffer, NULL); |
| 279 | uptime_raw_minutes = (unsigned long) (uptime_raw_hours * 60.0); | 240 | uptime_raw_minutes = (unsigned long) (uptime_raw_hours * 60.0); |
| 280 | 241 | ||
| 281 | if (check_critical_value == TRUE | 242 | if (check_critical_value == TRUE && (uptime_raw_minutes <= critical_value)) |
| 282 | && (uptime_raw_minutes <= critical_value)) result = STATE_CRITICAL; | 243 | result = STATE_CRITICAL; |
| 283 | else if (check_warning_value == TRUE | 244 | else if (check_warning_value == TRUE && (uptime_raw_minutes <= warning_value)) |
| 284 | && (uptime_raw_minutes <= warning_value)) result = STATE_WARNING; | 245 | result = STATE_WARNING; |
| 285 | 246 | ||
| 286 | uptime_days = uptime_raw_minutes / 1440; | 247 | uptime_days = uptime_raw_minutes / 1440; |
| 287 | uptime_raw_minutes %= 1440; | 248 | uptime_raw_minutes %= 1440; |
| @@ -289,20 +250,23 @@ main (int argc, char **argv) | |||
| 289 | uptime_raw_minutes %= 60; | 250 | uptime_raw_minutes %= 60; |
| 290 | uptime_minutes = uptime_raw_minutes; | 251 | uptime_minutes = uptime_raw_minutes; |
| 291 | 252 | ||
| 292 | sprintf (output_message, "Uptime %s - Up %d days %d hours %d minutes", | 253 | terminate (result, |
| 293 | (result == STATE_OK) ? "ok" : "problem", uptime_days, | 254 | _("Uptime %s - Up %d days %d hours %d minutes"), |
| 294 | uptime_hours, uptime_minutes); | 255 | state_text(result), |
| 295 | } | 256 | uptime_days, |
| 296 | 257 | uptime_hours, | |
| 297 | else { | 258 | uptime_minutes); |
| 298 | strcpy (output_message, "Nothing to check!\n"); | 259 | break; |
| 299 | result = STATE_UNKNOWN; | 260 | |
| 261 | default: | ||
| 262 | terminate (STATE_UNKNOWN, _("Nothing to check!\n")); | ||
| 263 | break; | ||
| 300 | } | 264 | } |
| 301 | 265 | ||
| 302 | /* reset timeout */ | 266 | /* reset timeout */ |
| 303 | alarm (0); | 267 | alarm (0); |
| 304 | 268 | ||
| 305 | printf ("%s\n", output_message); | 269 | printf (_("Reached end of program with no data returned\n")); |
| 306 | 270 | ||
| 307 | return result; | 271 | return result; |
| 308 | } | 272 | } |
| @@ -360,7 +324,7 @@ process_arguments (int argc, char **argv) | |||
| 360 | 324 | ||
| 361 | switch (c) { | 325 | switch (c) { |
| 362 | case '?': /* print short usage statement if args not parsable */ | 326 | case '?': /* print short usage statement if args not parsable */ |
| 363 | printf ("%s: Unknown argument: %s\n\n", progname, optarg); | 327 | printf (_("%s: Unknown argument: %s\n\n"), progname, optarg); |
| 364 | print_usage (); | 328 | print_usage (); |
| 365 | exit (STATE_UNKNOWN); | 329 | exit (STATE_UNKNOWN); |
| 366 | case 'h': /* help */ | 330 | case 'h': /* help */ |
| @@ -377,28 +341,36 @@ process_arguments (int argc, char **argv) | |||
| 377 | server_port = atoi (optarg); | 341 | server_port = atoi (optarg); |
| 378 | else | 342 | else |
| 379 | terminate (STATE_UNKNOWN, | 343 | terminate (STATE_UNKNOWN, |
| 380 | "Server port an integer (seconds)\nType '%s -h' for additional help\n", | 344 | _("Server port an integer (seconds)\nType '%s -h' for additional help\n"), |
| 381 | progname); | 345 | progname); |
| 382 | break; | 346 | break; |
| 383 | case 'v': /* variable */ | 347 | case 'v': /* variable */ |
| 384 | if (strcmp (optarg, "LOAD1") == 0) | 348 | if (strcmp (optarg, "LOAD") == 0) { |
| 385 | vars_to_check = CHECK_LOAD1; | 349 | strcpy (send_buffer, "LOAD\r\nQUIT\r\n"); |
| 386 | else if (strcmp (optarg, "LOAD5") == 0) | 350 | if (strcmp (optarg, "LOAD1") == 0) |
| 387 | vars_to_check = CHECK_LOAD5; | 351 | vars_to_check = LOAD1; |
| 388 | else if (strcmp (optarg, "LOAD15") == 0) | 352 | else if (strcmp (optarg, "LOAD5") == 0) |
| 389 | vars_to_check = CHECK_LOAD15; | 353 | vars_to_check = LOAD5; |
| 390 | else if (strcmp (optarg, "UPTIME") == 0) | 354 | else if (strcmp (optarg, "LOAD15") == 0) |
| 391 | vars_to_check = CHECK_UPTIME; | 355 | vars_to_check = LOAD15; |
| 356 | } | ||
| 357 | else if (strcmp (optarg, "UPTIME") == 0) { | ||
| 358 | vars_to_check = UPTIME; | ||
| 359 | strcpy (send_buffer, "UPTIME\r\n"); | ||
| 360 | } | ||
| 392 | else if (strstr (optarg, "PROC") == optarg) { | 361 | else if (strstr (optarg, "PROC") == optarg) { |
| 393 | vars_to_check = CHECK_PROCS; | 362 | vars_to_check = PROCS; |
| 394 | process_name = strscpy (process_name, optarg + 4); | 363 | process_name = strscpy (process_name, optarg + 4); |
| 364 | sprintf (send_buffer, "PROCESS %s\r\n", process_name); | ||
| 395 | } | 365 | } |
| 396 | else if (strstr (optarg, "NET") == optarg) { | 366 | else if (strstr (optarg, "NET") == optarg) { |
| 397 | vars_to_check = CHECK_NETSTAT; | 367 | vars_to_check = NETSTAT; |
| 398 | netstat_port = atoi (optarg + 3); | 368 | netstat_port = atoi (optarg + 3); |
| 369 | sprintf (send_buffer, "NETSTAT %d\r\n", netstat_port); | ||
| 399 | } | 370 | } |
| 400 | else if (strstr (optarg, "DPU") == optarg) { | 371 | else if (strstr (optarg, "DPU") == optarg) { |
| 401 | vars_to_check = CHECK_DPU; | 372 | vars_to_check = DPU; |
| 373 | strcpy (send_buffer, "DISKSPACE\r\n"); | ||
| 402 | disk_name = strscpy (disk_name, optarg + 3); | 374 | disk_name = strscpy (disk_name, optarg + 3); |
| 403 | } | 375 | } |
| 404 | else | 376 | else |
| @@ -421,62 +393,67 @@ process_arguments (int argc, char **argv) | |||
| 421 | } | 393 | } |
| 422 | return OK; | 394 | return OK; |
| 423 | } | 395 | } |
| 424 | 396 | ||
| 425 | |||
| 426 | |||
| 427 | |||
| 428 | |||
| 429 | void | 397 | void |
| 430 | print_usage (void) | 398 | print_usage (void) |
| 431 | { | 399 | { |
| 432 | printf | 400 | printf (_("\ |
| 433 | ("Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical] [-t timeout]\n", | 401 | Usage: %s -H host [-p port] [-v variable] [-w warning] [-c critical]\n\ |
| 434 | progname); | 402 | [-t timeout]\n"), |
| 403 | progname); | ||
| 404 | printf (_(UT_HLP_VRS), progname, progname); | ||
| 435 | } | 405 | } |
| 436 | 406 | ||
| 407 | void | ||
| 408 | print_help (void) | ||
| 409 | { | ||
| 410 | char *myport; | ||
| 411 | asprintf (&myport, "%d", PORT); | ||
| 437 | 412 | ||
| 413 | print_revision (progname, revision); | ||
| 438 | 414 | ||
| 415 | printf (_("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n")); | ||
| 416 | printf (_(COPYRIGHT), copyright, email); | ||
| 439 | 417 | ||
| 418 | printf (_("\ | ||
| 419 | This plugin attempts to contact the Over-CR collector daemon running on the\n\ | ||
| 420 | remote UNIX server in order to gather the requested system information.\n\n")); | ||
| 440 | 421 | ||
| 441 | void | ||
| 442 | print_help (void) | ||
| 443 | { | ||
| 444 | print_revision (progname, "$Revision$"); | ||
| 445 | printf | ||
| 446 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" | ||
| 447 | "This plugin attempts to contact the Over-CR collector daemon running on the\n" | ||
| 448 | "remote UNIX server in order to gather the requested system information. This\n" | ||
| 449 | "plugin requres that Eric Molitors' Over-CR collector daemon be running on the\n" | ||
| 450 | "remote server. Over-CR can be downloaded from http://www.molitor.org/overcr\n" | ||
| 451 | "(This plugin was tested with version 0.99.53 of the Over-CR collector)\n\n"); | ||
| 452 | print_usage (); | 422 | print_usage (); |
| 453 | printf | 423 | |
| 454 | ("\nOptions:\n" | 424 | printf (_(UT_HELP_VRSN)); |
| 455 | "-H, --hostname=HOST\n" | 425 | |
| 456 | " Name of the host to check\n" | 426 | printf (_(UT_HOST_PORT), 'p', myport); |
| 457 | "-p, --port=INTEGER\n" | 427 | |
| 458 | " Optional port number (default: %d)\n" | 428 | printf (_("\ |
| 459 | "-v, --variable=STRING\n" | 429 | -v, --variable=STRING\n\ |
| 460 | " Variable to check. Valid variables include:\n" | 430 | Variable to check. Valid variables include:\n\ |
| 461 | " LOAD1 = 1 minute average CPU load\n" | 431 | LOAD1 = 1 minute average CPU load\n\ |
| 462 | " LOAD5 = 5 minute average CPU load\n" | 432 | LOAD5 = 5 minute average CPU load\n\ |
| 463 | " LOAD15 = 15 minute average CPU load\n" | 433 | LOAD15 = 15 minute average CPU load\n\ |
| 464 | " DPU<filesys> = percent used disk space on filesystem <filesys>\n" | 434 | DPU<filesys> = percent used disk space on filesystem <filesys>\n\ |
| 465 | " PROC<process> = number of running processes with name <process>\n" | 435 | PROC<process> = number of running processes with name <process>\n\ |
| 466 | " NET<port> = number of active connections on TCP port <port>\n" | 436 | NET<port> = number of active connections on TCP port <port>\n\ |
| 467 | " UPTIME = system uptime in seconds\n" | 437 | UPTIME = system uptime in seconds\n")); |
| 468 | " -w, --warning=INTEGER\n" | 438 | |
| 469 | " Threshold which will result in a warning status\n" | 439 | printf (_("\ |
| 470 | " -c, --critical=INTEGER\n" | 440 | -w, --warning=INTEGER\n\ |
| 471 | " Threshold which will result in a critical status\n" | 441 | Threshold which will result in a warning status\n\ |
| 472 | " -t, --timeout=INTEGER\n" | 442 | -c, --critical=INTEGER\n\ |
| 473 | " Seconds before connection attempt times out (default: %d)\n" | 443 | Threshold which will result in a critical status\n")); |
| 474 | "-h, --help\n" | 444 | |
| 475 | " Print this help screen\n" | 445 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); |
| 476 | "-V, --version\n" | 446 | |
| 477 | " Print version information\n\n" | 447 | printf (_("\ |
| 478 | "Notes:\n" | 448 | Notes:\n\ |
| 479 | " - For the available options, the critical threshold value should always be\n" | 449 | - For the available options, the critical threshold value should always be\n\ |
| 480 | " higher than the warning threshold value, EXCEPT with the uptime variable\n" | 450 | higher than the warning threshold value, EXCEPT with the uptime variable\n\n")); |
| 481 | " (i.e. lower uptimes are worse).\n", PORT, DEFAULT_SOCKET_TIMEOUT); | 451 | |
| 452 | printf (_("\ | ||
| 453 | - This plugin requres that Eric Molitors' Over-CR collector daemon be\n\ | ||
| 454 | running on the remote server. Over-CR can be downloaded from\n\ | ||
| 455 | http://www.molitor.org/overcr (This plugin was tested with version\n\ | ||
| 456 | 0.99.53 of the Over-CR collector)\n\n")); | ||
| 457 | |||
| 458 | printf (_(UT_SUPPORT)); | ||
| 482 | } | 459 | } |
