summaryrefslogtreecommitdiffstats
path: root/web/attachments/67989-multiplier.dif
blob: 99c510c3195b1f8c40c6564cd011c8615cb50d2c (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
diff -Naur nagios-plugins-1.3.0-beta2/plugins/check_mrtgtraf.c nagios-plugins-1.3.0-beta2_swl/plugins/check_mrtgtraf.c
--- nagios-plugins-1.3.0-beta2/plugins/check_mrtgtraf.c	2002-11-15 02:04:51.000000000 +0100
+++ nagios-plugins-1.3.0-beta2_swl/plugins/check_mrtgtraf.c	2003-02-26 14:56:54.000000000 +0100
@@ -56,6 +56,7 @@
 
 int process_arguments (int, char **);
 int validate_arguments (void);
+unsigned long adjust_threshold(unsigned long val, char **c);
 void print_help (void);
 void print_usage (void);
 
@@ -144,9 +145,9 @@
 	if (expire_minutes > 0
 			&& (current_time - timestamp) >
 			(expire_minutes * 60)) terminate (STATE_WARNING,
-																				"MRTG data has expired (%d minutes old)\n",
-																				(int) ((current_time - timestamp) /
-																							 60));
+			"MRTG data has expired (%d minutes old)\n",
+			(int) ((current_time - timestamp) /
+			60));
 
 	/* else check the incoming/outgoing rates */
 	if (use_average == TRUE) {
@@ -160,37 +161,37 @@
 
 	/* report incoming traffic in Bytes/sec */
 	if (incoming_rate < 1024) {
-		strcpy (incoming_speed_rating, "B/s");
+		strcpy (incoming_speed_rating, "b/s");
 		adjusted_incoming_rate = (double) incoming_rate;
 	}
 
 	/* report incoming traffic in KBytes/sec */
 	else if (incoming_rate < (1024 * 1024)) {
-		strcpy (incoming_speed_rating, "KB/s");
+		strcpy (incoming_speed_rating, "Kb/s");
 		adjusted_incoming_rate = (double) (incoming_rate / 1024.0);
 	}
 
 	/* report incoming traffic in MBytes/sec */
 	else {
-		strcpy (incoming_speed_rating, "MB/s");
+		strcpy (incoming_speed_rating, "Mb/s");
 		adjusted_incoming_rate = (double) (incoming_rate / 1024.0 / 1024.0);
 	}
 
 	/* report outgoing traffic in Bytes/sec */
 	if (outgoing_rate < 1024) {
-		strcpy (outgoing_speed_rating, "B/s");
+		strcpy (outgoing_speed_rating, "b/s");
 		adjusted_outgoing_rate = (double) outgoing_rate;
 	}
 
 	/* report outgoing traffic in KBytes/sec */
 	else if (outgoing_rate < (1024 * 1024)) {
-		strcpy (outgoing_speed_rating, "KB/s");
+		strcpy (outgoing_speed_rating, "Kb/s");
 		adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0);
 	}
 
 	/* report outgoing traffic in MBytes/sec */
 	else {
-		strcpy (outgoing_speed_rating, "MB/s");
+		strcpy (outgoing_speed_rating, "Mb/s");
 		adjusted_outgoing_rate = (double) (outgoing_rate / 1024.0 / 1024.0);
 	}
 
@@ -231,6 +232,7 @@
 process_arguments (int argc, char **argv)
 {
 	int c;
+	char* modpos;
 
 #ifdef HAVE_GETOPT_H
 	int option_index = 0;
@@ -283,13 +285,27 @@
 			else
 				use_average = TRUE;
 			break;
-		case 'c':									/* warning threshold */
-			sscanf (optarg, "%lu,%lu", &incoming_critical_threshold,
-							&outgoing_critical_threshold);
+		case 'c':									/* critical threshold */
+			incoming_critical_threshold = strtoul (optarg, &modpos, 10);
+			if(*modpos != ',') 
+				incoming_critical_threshold = adjust_threshold(incoming_critical_threshold,&modpos);
+			
+			modpos++;
+
+			outgoing_critical_threshold = strtoul (modpos, &modpos, 10);
+			outgoing_critical_threshold = adjust_threshold(outgoing_critical_threshold,&modpos);
+	
 			break;
-		case 'w':									/* critical threshold */
-			sscanf (optarg, "%lu,%lu", &incoming_warning_threshold,
-							&outgoing_warning_threshold);
+		case 'w':									/* warning threshold */
+                        incoming_warning_threshold = strtoul (optarg, &modpos, 10);
+                        if(*modpos != ',')
+                                incoming_warning_threshold = adjust_threshold(incoming_warning_threshold,&modpos);
+
+                        modpos++;
+
+                        outgoing_warning_threshold = strtoul (modpos, &modpos, 10);
+                        outgoing_warning_threshold = adjust_threshold(outgoing_warning_threshold,&modpos);
+
 			break;
 		case 'V':									/* version */
 			print_revision (PROGNAME, "$Revision: 1.2 $");
@@ -321,25 +337,48 @@
 	}
 
 	if (argc > c && incoming_warning_threshold == 0) {
-		incoming_warning_threshold = strtoul (argv[c++], NULL, 10);
+		incoming_warning_threshold = strtoul (argv[c++], &modpos, 10);
+		incoming_warning_threshold = adjust_threshold(incoming_warning_threshold,&modpos);
 	}
 
 	if (argc > c && incoming_critical_threshold == 0) {
-		incoming_critical_threshold = strtoul (argv[c++], NULL, 10);
+		incoming_critical_threshold = strtoul (argv[c++], &modpos, 10);
+                incoming_critical_threshold = adjust_threshold(incoming_critical_threshold,&modpos);
 	}
 
 	if (argc > c && outgoing_warning_threshold == 0) {
-		outgoing_warning_threshold = strtoul (argv[c++], NULL, 10);
+		outgoing_warning_threshold = strtoul (argv[c++], &modpos, 10);
+                outgoing_warning_threshold = adjust_threshold(outgoing_warning_threshold,&modpos);
 	}
 	
 	if (argc > c && outgoing_critical_threshold == 0) {
-		outgoing_critical_threshold = strtoul (argv[c++], NULL, 10);
+		outgoing_critical_threshold = strtoul (argv[c++], &modpos, 10);
+                outgoing_critical_threshold = adjust_threshold(outgoing_critical_threshold,&modpos);
 	}
 
 	return validate_arguments ();
 }
 
-
+unsigned long adjust_threshold(unsigned long val, char **pos)
+{
+	switch(**pos)
+	{
+	case 'K':
+       case 'k': 
+		(*pos)++;
+		return (val*1024L);
+	case 'M':
+       case 'm':
+		(*pos)++;
+		return val*1024L*1024L;
+	case 'G':
+       case 'm':
+		(*pos)++;
+		return val*1024L*1024L*1024L;
+	default:
+		return val;
+	}
+}