summaryrefslogtreecommitdiffstats
path: root/web/attachments/297946-patch-plugins__check_nt.c.txt
blob: a004ad40e1cefccc7f060758a1de99abf4abae44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
--- plugins/check_nt.c.orig     2008-10-19 14:39:43.000000000 +0200
+++ plugins/check_nt.c  2008-10-19 14:47:19.000000000 +0200
@@ -97,6 +97,8 @@
        char *temp_string_perf=NULL;
        char *description=NULL,*counter_unit = NULL;
        char *minval = NULL, *maxval = NULL, *errcvt = NULL;
+       char *fds=NULL;
+       char *tds=NULL;

        double total_disk_space=0;
        double free_disk_space=0;
@@ -218,33 +220,41 @@
                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;
-
-                       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);
-                               asprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list,
-                                 (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
-                                 critical_used_space / 1073741824, total_disk_space / 1073741824);
+                       fds=strtok(recv_buffer,"&");
+                       tds=strtok(NULL,"&");

-                               if(check_critical_value==TRUE && percent_used_space >= critical_value)
-                                       return_code=STATE_CRITICAL;
-                               else if (check_warning_value==TRUE && percent_used_space >= warning_value)
-                                       return_code=STATE_WARNING;
-                               else
-                                       return_code=STATE_OK;
-
-                               output_message = strdup (temp_string);
-                               perfdata = temp_string_perf;
+                       if (fds != NULL)
+                               free_disk_space=atof(fds);
+                       if (tds != NULL)
+                               total_disk_space=atof(tds);
+
+                       if (total_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);
+                                       asprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list,
+                                         (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
+                                         critical_used_space / 1073741824, total_disk_space / 1073741824);
+
+                                       if(check_critical_value==TRUE && percent_used_space >= critical_value)
+                                               return_code=STATE_CRITICAL;
+                                       else if (check_warning_value==TRUE && percent_used_space >= warning_value)
+                                               return_code=STATE_WARNING;
+                                       else
+                                               return_code=STATE_OK;
+
+                                       output_message = strdup (temp_string);
+                                       perfdata = temp_string_perf;
+                               }
                        } else {
-                               output_message = strdup (_("Free disk space : Invalid drive "));
-                               return_code=STATE_UNKNOWN;
-                       }
+                                       output_message = strdup (_("Free disk space : Invalid drive "));
+                                       return_code=STATE_UNKNOWN;
+                               }
                }
                break;