diff options
Diffstat (limited to 'web/attachments/67989-multiplier.dif')
-rw-r--r-- | web/attachments/67989-multiplier.dif | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/web/attachments/67989-multiplier.dif b/web/attachments/67989-multiplier.dif new file mode 100644 index 0000000..99c510c --- /dev/null +++ b/web/attachments/67989-multiplier.dif | |||
@@ -0,0 +1,164 @@ | |||
1 | diff -Naur nagios-plugins-1.3.0-beta2/plugins/check_mrtgtraf.c nagios-plugins-1.3.0-beta2_swl/plugins/check_mrtgtraf.c | ||
2 | --- nagios-plugins-1.3.0-beta2/plugins/check_mrtgtraf.c 2002-11-15 02:04:51.000000000 +0100 | ||
3 | +++ nagios-plugins-1.3.0-beta2_swl/plugins/check_mrtgtraf.c 2003-02-26 14:56:54.000000000 +0100 | ||
4 | @@ -56,6 +56,7 @@ | ||
5 | |||
6 | int process_arguments (int, char **); | ||
7 | int validate_arguments (void); | ||
8 | +unsigned long adjust_threshold(unsigned long val, char **c); | ||
9 | void print_help (void); | ||
10 | void print_usage (void); | ||
11 | |||
12 | @@ -144,9 +145,9 @@ | ||
13 | if (expire_minutes > 0 | ||
14 | && (current_time - timestamp) > | ||
15 | (expire_minutes * 60)) terminate (STATE_WARNING, | ||
16 | - "MRTG data has expired (%d minutes old)\n", | ||
17 | - (int) ((current_time - timestamp) / | ||
18 | - 60)); | ||
19 | + "MRTG data has expired (%d minutes old)\n", | ||
20 | + (int) ((current_time - timestamp) / | ||
21 | + 60)); | ||
22 | |||
23 | /* else check the incoming/outgoing rates */ | ||
24 | if (use_average == TRUE) { | ||
25 | @@ -160,37 +161,37 @@ | ||
26 | |||
27 | /* report incoming traffic in Bytes/sec */ | ||
28 | if (incoming_rate < 1024) { | ||
29 | - strcpy (incoming_speed_rating, "B/s"); | ||
30 | + strcpy (incoming_speed_rating, "b/s"); | ||
31 | adjusted_incoming_rate = (double) incoming_rate; | ||
32 | } | ||
33 | |||
34 | /* report incoming traffic in KBytes/sec */ | ||
35 | else if (incoming_rate < (1024 * 1024)) { | ||
36 | - strcpy (incoming_speed_rating, "KB/s"); | ||
37 | + strcpy (incoming_speed_rating, "Kb/s"); | ||
38 | adjusted_incoming_rate = (double) (incoming_rate / 1024.0); | ||
39 | } | ||
40 | |||
41 | /* report incoming traffic in MBytes/sec */ | ||
42 | else { | ||
43 | - strcpy (incoming_speed_rating, "MB/s"); | ||
44 | + strcpy (incoming_speed_rating, "Mb/s"); | ||
45 | adjusted_incoming_rate = (double) (incoming_rate / 1024.0 / 1024.0); | ||
46 | } | ||
47 | |||
48 | /* report outgoing traffic in Bytes/sec */ | ||
49 | if (outgoing_rate < 1024) { | ||
50 | - strcpy (outgoing_speed_rating, "B/s"); | ||
51 | + strcpy (outgoing_speed_rating, "b/s"); | ||
52 | adjusted_outgoing_rate = (double) outgoing_rate; | ||
53 | } | ||
54 | |||
55 | /* report outgoing traffic in KBytes/sec */ | ||
56 | else if (outgoing_rate < (1024 * 1024)) { | ||
57 | - strcpy (outgoing_speed_rating, "KB/s"); | ||
58 | + strcpy (outgoing_speed_rating, "Kb/s"); | ||
59 | adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0); | ||
60 | } | ||
61 | |||
62 | /* report outgoing traffic in MBytes/sec */ | ||
63 | else { | ||
64 | - strcpy (outgoing_speed_rating, "MB/s"); | ||
65 | + strcpy (outgoing_speed_rating, "Mb/s"); | ||
66 | adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0 / 1024.0); | ||
67 | } | ||
68 | |||
69 | @@ -231,6 +232,7 @@ | ||
70 | process_arguments (int argc, char **argv) | ||
71 | { | ||
72 | int c; | ||
73 | + char* modpos; | ||
74 | |||
75 | #ifdef HAVE_GETOPT_H | ||
76 | int option_index = 0; | ||
77 | @@ -283,13 +285,27 @@ | ||
78 | else | ||
79 | use_average = TRUE; | ||
80 | break; | ||
81 | - case 'c': /* warning threshold */ | ||
82 | - sscanf (optarg, "%lu,%lu", &incoming_critical_threshold, | ||
83 | - &outgoing_critical_threshold); | ||
84 | + case 'c': /* critical threshold */ | ||
85 | + incoming_critical_threshold = strtoul (optarg, &modpos, 10); | ||
86 | + if(*modpos != ',') | ||
87 | + incoming_critical_threshold = adjust_threshold(incoming_critical_threshold,&modpos); | ||
88 | + | ||
89 | + modpos++; | ||
90 | + | ||
91 | + outgoing_critical_threshold = strtoul (modpos, &modpos, 10); | ||
92 | + outgoing_critical_threshold = adjust_threshold(outgoing_critical_threshold,&modpos); | ||
93 | + | ||
94 | break; | ||
95 | - case 'w': /* critical threshold */ | ||
96 | - sscanf (optarg, "%lu,%lu", &incoming_warning_threshold, | ||
97 | - &outgoing_warning_threshold); | ||
98 | + case 'w': /* warning threshold */ | ||
99 | + incoming_warning_threshold = strtoul (optarg, &modpos, 10); | ||
100 | + if(*modpos != ',') | ||
101 | + incoming_warning_threshold = adjust_threshold(incoming_warning_threshold,&modpos); | ||
102 | + | ||
103 | + modpos++; | ||
104 | + | ||
105 | + outgoing_warning_threshold = strtoul (modpos, &modpos, 10); | ||
106 | + outgoing_warning_threshold = adjust_threshold(outgoing_warning_threshold,&modpos); | ||
107 | + | ||
108 | break; | ||
109 | case 'V': /* version */ | ||
110 | print_revision (PROGNAME, "$Revision: 1.2 $"); | ||
111 | @@ -321,25 +337,48 @@ | ||
112 | } | ||
113 | |||
114 | if (argc > c && incoming_warning_threshold == 0) { | ||
115 | - incoming_warning_threshold = strtoul (argv[c++], NULL, 10); | ||
116 | + incoming_warning_threshold = strtoul (argv[c++], &modpos, 10); | ||
117 | + incoming_warning_threshold = adjust_threshold(incoming_warning_threshold,&modpos); | ||
118 | } | ||
119 | |||
120 | if (argc > c && incoming_critical_threshold == 0) { | ||
121 | - incoming_critical_threshold = strtoul (argv[c++], NULL, 10); | ||
122 | + incoming_critical_threshold = strtoul (argv[c++], &modpos, 10); | ||
123 | + incoming_critical_threshold = adjust_threshold(incoming_critical_threshold,&modpos); | ||
124 | } | ||
125 | |||
126 | if (argc > c && outgoing_warning_threshold == 0) { | ||
127 | - outgoing_warning_threshold = strtoul (argv[c++], NULL, 10); | ||
128 | + outgoing_warning_threshold = strtoul (argv[c++], &modpos, 10); | ||
129 | + outgoing_warning_threshold = adjust_threshold(outgoing_warning_threshold,&modpos); | ||
130 | } | ||
131 | |||
132 | if (argc > c && outgoing_critical_threshold == 0) { | ||
133 | - outgoing_critical_threshold = strtoul (argv[c++], NULL, 10); | ||
134 | + outgoing_critical_threshold = strtoul (argv[c++], &modpos, 10); | ||
135 | + outgoing_critical_threshold = adjust_threshold(outgoing_critical_threshold,&modpos); | ||
136 | } | ||
137 | |||
138 | return validate_arguments (); | ||
139 | } | ||
140 | |||
141 | - | ||
142 | +unsigned long adjust_threshold(unsigned long val, char **pos) | ||
143 | +{ | ||
144 | + switch(**pos) | ||
145 | + { | ||
146 | + case 'K': | ||
147 | + case 'k': | ||
148 | + (*pos)++; | ||
149 | + return (val*1024L); | ||
150 | + case 'M': | ||
151 | + case 'm': | ||
152 | + (*pos)++; | ||
153 | + return val*1024L*1024L; | ||
154 | + case 'G': | ||
155 | + case 'm': | ||
156 | + (*pos)++; | ||
157 | + return val*1024L*1024L*1024L; | ||
158 | + default: | ||
159 | + return val; | ||
160 | + } | ||
161 | +} | ||
162 | |||
163 | |||
164 | |||