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