diff options
author | Ton Voon <tonvoon@macbook.local> | 2009-02-19 23:43:15 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@macbook.local> | 2009-02-19 23:43:15 +0000 |
commit | 31efea1b490a12a64ce0359c2d847a381d2efb7b (patch) | |
tree | 6aa46c2ca01a830fdeaff19e545ec3fcbdf436c8 /plugins/check_nt.c | |
parent | b99afc69bf36131f70a7cd312577118c65300ba6 (diff) | |
download | monitoring-plugins-31efea1b490a12a64ce0359c2d847a381d2efb7b.tar.gz |
Fixed coredump from check_nt when drive not found (Olli Hauer - SF 2179754)
Diffstat (limited to 'plugins/check_nt.c')
-rw-r--r-- | plugins/check_nt.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/plugins/check_nt.c b/plugins/check_nt.c index 4d9157a6..ee5e2a63 100644 --- a/plugins/check_nt.c +++ b/plugins/check_nt.c @@ -93,6 +93,7 @@ int main(int argc, char **argv){ char *temp_string_perf=NULL; char *description=NULL,*counter_unit = NULL; char *minval = NULL, *maxval = NULL, *errcvt = NULL; + char *fds=NULL, *tds=NULL; double total_disk_space=0; double free_disk_space=0; @@ -214,13 +215,18 @@ int main(int argc, char **argv){ else { asprintf(&send_buffer,"%s&4&%s", req_password, value_list); fetch_data (server_address, server_port, send_buffer); - free_disk_space=atof(strtok(recv_buffer,"&")); - total_disk_space=atof(strtok(NULL,"&")); - percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100; - warning_used_space = ((float)warning_value / 100) * total_disk_space; - critical_used_space = ((float)critical_value / 100) * total_disk_space; + fds=strtok(recv_buffer,"&"); + tds=strtok(NULL,"&"); + if(fds!=NULL) + free_disk_space=atof(fds); + if(tds!=NULL) + total_disk_space=atof(tds); + + if (total_disk_space>0 && free_disk_space>=0) { + percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100; + warning_used_space = ((float)warning_value / 100) * total_disk_space; + critical_used_space = ((float)critical_value / 100) * total_disk_space; - if (free_disk_space>=0) { asprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"), value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824, percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100); @@ -238,7 +244,7 @@ int main(int argc, char **argv){ output_message = strdup (temp_string); perfdata = temp_string_perf; } else { - output_message = strdup (_("Free disk space : Invalid drive ")); + output_message = strdup (_("Free disk space : Invalid drive")); return_code=STATE_UNKNOWN; } } |