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