summaryrefslogtreecommitdiffstats
path: root/plugins/check_nt.c
diff options
context:
space:
mode:
authorAnders Kaseorg <andersk@mit.edu>2012-06-29 04:57:48 (GMT)
committerHolger Weiss <holger@zedat.fu-berlin.de>2012-06-29 11:39:11 (GMT)
commit028d50d6f99e647a325a0a68303016382c4bbdc9 (patch)
tree1d9a14635602169d137409becfa108cd6bdb371c /plugins/check_nt.c
parent9976876584e5a1df6e1c9315212c3d274df7a12e (diff)
downloadmonitoring-plugins-028d50d6f99e647a325a0a68303016382c4bbdc9.tar.gz
Die when asprintf fails
Fixes many instances of warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result] Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Diffstat (limited to 'plugins/check_nt.c')
-rw-r--r--plugins/check_nt.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/plugins/check_nt.c b/plugins/check_nt.c
index 60806bb..89c4d8d 100644
--- a/plugins/check_nt.c
+++ b/plugins/check_nt.c
@@ -135,13 +135,13 @@ int main(int argc, char **argv){
135 135
136 case CHECK_CLIENTVERSION: 136 case CHECK_CLIENTVERSION:
137 137
138 asprintf(&send_buffer, "%s&1", req_password); 138 xasprintf(&send_buffer, "%s&1", req_password);
139 fetch_data (server_address, server_port, send_buffer); 139 fetch_data (server_address, server_port, send_buffer);
140 if (value_list != NULL && strcmp(recv_buffer, value_list) != 0) { 140 if (value_list != NULL && strcmp(recv_buffer, value_list) != 0) {
141 asprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list); 141 xasprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list);
142 return_code = STATE_WARNING; 142 return_code = STATE_WARNING;
143 } else { 143 } else {
144 asprintf (&output_message, "%s", recv_buffer); 144 xasprintf (&output_message, "%s", recv_buffer);
145 return_code = STATE_OK; 145 return_code = STATE_OK;
146 } 146 }
147 break; 147 break;
@@ -167,7 +167,7 @@ int main(int argc, char **argv){
167 lvalue_list[2+offset]<=(unsigned long)100) { 167 lvalue_list[2+offset]<=(unsigned long)100) {
168 168
169 /* Send request and retrieve data */ 169 /* Send request and retrieve data */
170 asprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]); 170 xasprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]);
171 fetch_data (server_address, server_port, send_buffer); 171 fetch_data (server_address, server_port, send_buffer);
172 172
173 utilization=strtoul(recv_buffer,NULL,10); 173 utilization=strtoul(recv_buffer,NULL,10);
@@ -178,11 +178,11 @@ int main(int argc, char **argv){
178 else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING) 178 else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING)
179 return_code=STATE_WARNING; 179 return_code=STATE_WARNING;
180 180
181 asprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]); 181 xasprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]);
182 asprintf(&temp_string,"%s%s",temp_string,output_message); 182 xasprintf(&temp_string,"%s%s",temp_string,output_message);
183 asprintf(&perfdata,_(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0+offset], utilization, 183 xasprintf(&perfdata,_(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0+offset], utilization,
184 lvalue_list[1+offset], lvalue_list[2+offset]); 184 lvalue_list[1+offset], lvalue_list[2+offset]);
185 asprintf(&temp_string_perf,"%s%s",temp_string_perf,perfdata); 185 xasprintf(&temp_string_perf,"%s%s",temp_string_perf,perfdata);
186 offset+=3; /* move across the array */ 186 offset+=3; /* move across the array */
187 } 187 }
188 188
@@ -196,13 +196,13 @@ int main(int argc, char **argv){
196 196
197 case CHECK_UPTIME: 197 case CHECK_UPTIME:
198 198
199 asprintf(&send_buffer, "%s&3", req_password); 199 xasprintf(&send_buffer, "%s&3", req_password);
200 fetch_data (server_address, server_port, send_buffer); 200 fetch_data (server_address, server_port, send_buffer);
201 uptime=strtoul(recv_buffer,NULL,10); 201 uptime=strtoul(recv_buffer,NULL,10);
202 updays = uptime / 86400; 202 updays = uptime / 86400;
203 uphours = (uptime % 86400) / 3600; 203 uphours = (uptime % 86400) / 3600;
204 upminutes = ((uptime % 86400) % 3600) / 60; 204 upminutes = ((uptime % 86400) % 3600) / 60;
205 asprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s)"),updays,uphours, upminutes); 205 xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s)"),updays,uphours, upminutes);
206 if (check_critical_value==TRUE && uptime <= critical_value) 206 if (check_critical_value==TRUE && uptime <= critical_value)
207 return_code=STATE_CRITICAL; 207 return_code=STATE_CRITICAL;
208 else if (check_warning_value==TRUE && uptime <= warning_value) 208 else if (check_warning_value==TRUE && uptime <= warning_value)
@@ -218,7 +218,7 @@ int main(int argc, char **argv){
218 else if (strlen(value_list)!=1) 218 else if (strlen(value_list)!=1)
219 output_message = strdup (_("wrong -l argument")); 219 output_message = strdup (_("wrong -l argument"));
220 else { 220 else {
221 asprintf(&send_buffer,"%s&4&%s", req_password, value_list); 221 xasprintf(&send_buffer,"%s&4&%s", req_password, value_list);
222 fetch_data (server_address, server_port, send_buffer); 222 fetch_data (server_address, server_port, send_buffer);
223 fds=strtok(recv_buffer,"&"); 223 fds=strtok(recv_buffer,"&");
224 tds=strtok(NULL,"&"); 224 tds=strtok(NULL,"&");
@@ -232,10 +232,10 @@ int main(int argc, char **argv){
232 warning_used_space = ((float)warning_value / 100) * total_disk_space; 232 warning_used_space = ((float)warning_value / 100) * total_disk_space;
233 critical_used_space = ((float)critical_value / 100) * total_disk_space; 233 critical_used_space = ((float)critical_value / 100) * total_disk_space;
234 234
235 asprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), 235 xasprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"),
236 value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, 236 value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824,
237 percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100); 237 percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100);
238 asprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list, 238 xasprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list,
239 (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824, 239 (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
240 critical_used_space / 1073741824, total_disk_space / 1073741824); 240 critical_used_space / 1073741824, total_disk_space / 1073741824);
241 241
@@ -262,7 +262,7 @@ int main(int argc, char **argv){
262 output_message = strdup (_("No service/process specified")); 262 output_message = strdup (_("No service/process specified"));
263 else { 263 else {
264 preparelist(value_list); /* replace , between services with & to send the request */ 264 preparelist(value_list); /* replace , between services with & to send the request */
265 asprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6, 265 xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6,
266 (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list); 266 (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list);
267 fetch_data (server_address, server_port, send_buffer); 267 fetch_data (server_address, server_port, send_buffer);
268 return_code=atoi(strtok(recv_buffer,"&")); 268 return_code=atoi(strtok(recv_buffer,"&"));
@@ -273,7 +273,7 @@ int main(int argc, char **argv){
273 273
274 case CHECK_MEMUSE: 274 case CHECK_MEMUSE:
275 275
276 asprintf(&send_buffer,"%s&7", req_password); 276 xasprintf(&send_buffer,"%s&7", req_password);
277 fetch_data (server_address, server_port, send_buffer); 277 fetch_data (server_address, server_port, send_buffer);
278 mem_commitLimit=atof(strtok(recv_buffer,"&")); 278 mem_commitLimit=atof(strtok(recv_buffer,"&"));
279 mem_commitByte=atof(strtok(NULL,"&")); 279 mem_commitByte=atof(strtok(NULL,"&"));
@@ -283,10 +283,10 @@ int main(int argc, char **argv){
283 283
284 /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here, 284 /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here,
285 which equals RAM + Pagefiles. */ 285 which equals RAM + Pagefiles. */
286 asprintf(&output_message,_("Memory usage: total:%.2f Mb - used: %.2f Mb (%.0f%%) - free: %.2f Mb (%.0f%%)"), 286 xasprintf(&output_message,_("Memory usage: total:%.2f Mb - used: %.2f Mb (%.0f%%) - free: %.2f Mb (%.0f%%)"),
287 mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space, 287 mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space,
288 (mem_commitLimit - mem_commitByte) / 1048567, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100); 288 (mem_commitLimit - mem_commitByte) / 1048567, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
289 asprintf(&perfdata,_("'Memory usage'=%.2fMb;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567, 289 xasprintf(&perfdata,_("'Memory usage'=%.2fMb;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567,
290 warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567); 290 warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567);
291 291
292 return_code=STATE_OK; 292 return_code=STATE_OK;
@@ -331,12 +331,12 @@ int main(int argc, char **argv){
331 strtok (value_list, "&"); /* burn the first parameters */ 331 strtok (value_list, "&"); /* burn the first parameters */
332 description = strtok (NULL, "&"); 332 description = strtok (NULL, "&");
333 counter_unit = strtok (NULL, "&"); 333 counter_unit = strtok (NULL, "&");
334 asprintf (&send_buffer, "%s&8&%s", req_password, value_list); 334 xasprintf (&send_buffer, "%s&8&%s", req_password, value_list);
335 fetch_data (server_address, server_port, send_buffer); 335 fetch_data (server_address, server_port, send_buffer);
336 counter_value = atof (recv_buffer); 336 counter_value = atof (recv_buffer);
337 337
338 if (description == NULL) 338 if (description == NULL)
339 asprintf (&output_message, "%.f", counter_value); 339 xasprintf (&output_message, "%.f", counter_value);
340 else if (isPercent) 340 else if (isPercent)
341 { 341 {
342 counter_unit = strdup ("%"); 342 counter_unit = strdup ("%");
@@ -371,13 +371,13 @@ int main(int argc, char **argv){
371 { 371 {
372 /* Let's format the output string, finally... */ 372 /* Let's format the output string, finally... */
373 if (strstr(description, "%") == NULL) { 373 if (strstr(description, "%") == NULL) {
374 asprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit); 374 xasprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit);
375 } else { 375 } else {
376 /* has formatting, will segv if wrong */ 376 /* has formatting, will segv if wrong */
377 asprintf (&output_message, description, counter_value); 377 xasprintf (&output_message, description, counter_value);
378 } 378 }
379 asprintf (&output_message, "%s |", output_message); 379 xasprintf (&output_message, "%s |", output_message);
380 asprintf (&output_message,"%s %s", output_message, 380 xasprintf (&output_message,"%s %s", output_message,
381 fperfdata (description, counter_value, 381 fperfdata (description, counter_value,
382 counter_unit, 1, warning_value, 1, critical_value, 382 counter_unit, 1, warning_value, 1, critical_value,
383 (!(isPercent) && (minval != NULL)), fminval, 383 (!(isPercent) && (minval != NULL)), fminval,
@@ -410,7 +410,7 @@ int main(int argc, char **argv){
410 output_message = strdup (_("No counter specified")); 410 output_message = strdup (_("No counter specified"));
411 else { 411 else {
412 preparelist(value_list); /* replace , between services with & to send the request */ 412 preparelist(value_list); /* replace , between services with & to send the request */
413 asprintf(&send_buffer,"%s&9&%s", req_password,value_list); 413 xasprintf(&send_buffer,"%s&9&%s", req_password,value_list);
414 fetch_data (server_address, server_port, send_buffer); 414 fetch_data (server_address, server_port, send_buffer);
415 age_in_minutes = atoi(strtok(recv_buffer,"&")); 415 age_in_minutes = atoi(strtok(recv_buffer,"&"));
416 description = strtok(NULL,"&"); 416 description = strtok(NULL,"&");
@@ -439,13 +439,13 @@ int main(int argc, char **argv){
439 if (value_list==NULL) 439 if (value_list==NULL)
440 output_message = strdup (_("No counter specified")); 440 output_message = strdup (_("No counter specified"));
441 else { 441 else {
442 asprintf(&send_buffer,"%s&10&%s", req_password,value_list); 442 xasprintf(&send_buffer,"%s&10&%s", req_password,value_list);
443 fetch_data (server_address, server_port, send_buffer); 443 fetch_data (server_address, server_port, send_buffer);
444 if (!strncmp(recv_buffer,"ERROR",5)) { 444 if (!strncmp(recv_buffer,"ERROR",5)) {
445 printf("NSClient - %s\n",recv_buffer); 445 printf("NSClient - %s\n",recv_buffer);
446 exit(STATE_UNKNOWN); 446 exit(STATE_UNKNOWN);
447 } 447 }
448 asprintf(&output_message,"%s",recv_buffer); 448 xasprintf(&output_message,"%s",recv_buffer);
449 return_code=STATE_OK; 449 return_code=STATE_OK;
450 } 450 }
451 break; 451 break;