91 | | /* HERE Put in RRD FILE */ |
92 | | for (j=0; j<strlen(name); j++) {name[j] = '\0';} |
93 | | for (j=0; j<strlen(createstr); j++) {createstr[j] = '\0';} |
94 | | for (j=0; j<strlen(ipStr); j++) {ipStr[j] = '\0';} |
95 | | for (j=0; j<strlen(buf); j++) {buf[j] = '\0';} |
96 | | strcat(name, RRD_LOCATION); |
97 | | sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu", |
98 | | shmForAgg->prefixV4Tab[index][i].beginning>>24, |
99 | | shmForAgg->prefixV4Tab[index][i].beginning<<8>>24, |
100 | | shmForAgg->prefixV4Tab[index][i].beginning<<16>>24, |
101 | | shmForAgg->prefixV4Tab[index][i].beginning<<24>>24, |
102 | | shmForAgg->prefixV4Tab[index][i].mask, |
103 | | shmForAgg->prefixV4Tab[index][i].sampling |
104 | | ); |
105 | | strcat(name, ipStr); |
106 | | strcat(name, RRD_EXTENSION); |
107 | | if ( (fp=fopen(name,"r")) == NULL ){ |
108 | | opt[0]= (char *) malloc((strlen(RRD_PARAM_0) + 1) * sizeof(char)); |
109 | | strcpy(opt[0], RRD_PARAM_0); |
110 | | opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
111 | | strcpy(opt[1], name); |
112 | | opt[2]= (char *) malloc((strlen(RRD_PARAM_1) + 1) * sizeof(char)); |
113 | | strcpy(opt[2], RRD_PARAM_1); |
114 | | opt[3]= (char *) malloc((strlen(RRD_PARAM_2) + 1) * sizeof(char)); |
115 | | strcpy(opt[3], RRD_PARAM_2); |
116 | | opt[4]= (char *) malloc((strlen(RRD_PARAM_3) + 1) * sizeof(char)); |
117 | | strcpy(opt[4], RRD_PARAM_3); |
118 | | opt[5]= (char *) malloc((strlen(RRD_PARAM_4) + 1) * sizeof(char)); |
119 | | strcpy(opt[5], RRD_PARAM_4); |
120 | | opt[6]= (char *) malloc((strlen(RRD_PARAM_5) + 1) * sizeof(char)); |
121 | | strcpy(opt[6], RRD_PARAM_5); |
122 | | opt[7]= (char *) malloc((strlen(RRD_PARAM_6) + 1) * sizeof(char)); |
123 | | strcpy(opt[7], RRD_PARAM_6); |
124 | | opt[8]= (char *) malloc((strlen(RRD_PARAM_7) + 1) * sizeof(char)); |
125 | | strcpy(opt[8], RRD_PARAM_7); |
126 | | opt[9]= (char *) malloc((strlen(RRD_PARAM_8) + 1) * sizeof(char)); |
127 | | strcpy(opt[9], RRD_PARAM_8); |
128 | | opt[10]= (char *) malloc((strlen(RRD_PARAM_9) + 1) * sizeof(char)); |
129 | | strcpy(opt[10], RRD_PARAM_9); |
130 | | opt[11]= (char *) malloc((strlen(RRD_PARAM_10) + 1) * sizeof(char)); |
131 | | strcpy(opt[11], RRD_PARAM_10); |
132 | | opt[12]= (char *) malloc((strlen(RRD_PARAM_11) + 1) * sizeof(char)); |
133 | | strcpy(opt[12], RRD_PARAM_11); |
134 | | opt[13]= (char *) malloc((strlen(RRD_PARAM_12) + 1) * sizeof(char)); |
135 | | strcpy(opt[13], RRD_PARAM_12); |
136 | | opt[14]= (char *) malloc((strlen(RRD_PARAM_13) + 1) * sizeof(char)); |
137 | | strcpy(opt[14], RRD_PARAM_13); |
138 | | opt[15]= (char *) malloc((strlen(RRD_PARAM_14) + 1) * sizeof(char)); |
139 | | strcpy(opt[15], RRD_PARAM_14); |
140 | | opt[16]= (char *) malloc((strlen(RRD_PARAM_15) + 1) * sizeof(char)); |
141 | | strcpy(opt[16], RRD_PARAM_15); |
142 | | opt[17]= (char *) malloc((strlen(RRD_PARAM_16) + 1) * sizeof(char)); |
143 | | strcpy(opt[17], RRD_PARAM_16); |
144 | | opt[18]= (char *) malloc((strlen(RRD_PARAM_17) + 1) * sizeof(char)); |
145 | | strcpy(opt[18], RRD_PARAM_17); |
146 | | opt[19]= (char *) malloc((strlen(RRD_PARAM_18) + 1) * sizeof(char)); |
147 | | strcpy(opt[19], RRD_PARAM_18); |
148 | | opt[20]= (char *) malloc((strlen(RRD_PARAM_19) + 1) * sizeof(char)); |
149 | | strcpy(opt[20], RRD_PARAM_19); |
150 | | opt[21]= (char *) malloc((strlen(RRD_PARAM_20) + 1) * sizeof(char)); |
151 | | strcpy(opt[21], RRD_PARAM_20); |
152 | | opt[22]= (char *) malloc((strlen(RRD_PARAM_21) + 1) * sizeof(char)); |
153 | | strcpy(opt[22], RRD_PARAM_21); |
154 | | opt[23]= (char *) malloc((strlen(RRD_PARAM_22) + 1) * sizeof(char)); |
155 | | strcpy(opt[23], RRD_PARAM_22); |
156 | | opt[24]= (char *) malloc((strlen(RRD_PARAM_23) + 1) * sizeof(char)); |
157 | | strcpy(opt[24], RRD_PARAM_23); |
158 | | opt[25]= (char *) malloc((strlen(RRD_PARAM_24) + 1) * sizeof(char)); |
159 | | strcpy(opt[25], RRD_PARAM_24); |
160 | | opt[26]= (char *) malloc((strlen(RRD_PARAM_25) + 1) * sizeof(char)); |
161 | | strcpy(opt[26], RRD_PARAM_25); |
162 | | optind = opterr = 0; |
163 | | rrd_clear_error(); |
164 | | if ( rrd_create(27,opt) < 0) { |
165 | | syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); |
166 | | rrd_create_er_ct++; |
167 | | } else { |
168 | | rrd_create_ok_ct++; |
| 91 | /* HERE create or update RRD FILE */ |
| 92 | if (shmForAgg->prefixV4Tab[index][i].sampling != 0) { |
| 93 | for (j=0; j<strlen(name); j++) {name[j] = '\0';} |
| 94 | for (j=0; j<strlen(createstr); j++) {createstr[j] = '\0';} |
| 95 | for (j=0; j<strlen(ipStr); j++) {ipStr[j] = '\0';} |
| 96 | for (j=0; j<strlen(buf); j++) {buf[j] = '\0';} |
| 97 | strcat(name, RRD_LOCATION); |
| 98 | sprintf(ipStr, "%lu_%lu_%lu_%lu_%hu_%lu", |
| 99 | shmForAgg->prefixV4Tab[index][i].beginning>>24, |
| 100 | shmForAgg->prefixV4Tab[index][i].beginning<<8>>24, |
| 101 | shmForAgg->prefixV4Tab[index][i].beginning<<16>>24, |
| 102 | shmForAgg->prefixV4Tab[index][i].beginning<<24>>24, |
| 103 | shmForAgg->prefixV4Tab[index][i].mask, |
| 104 | shmForAgg->prefixV4Tab[index][i].sampling |
| 105 | ); |
| 106 | strcat(name, ipStr); |
| 107 | strcat(name, RRD_EXTENSION); |
| 108 | if ( (fp=fopen(name,"r")) == NULL ){ |
| 109 | opt[0]= (char *) malloc((strlen(RRD_PARAM_0) + 1) * sizeof(char)); |
| 110 | strcpy(opt[0], RRD_PARAM_0); |
| 111 | opt[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
| 112 | strcpy(opt[1], name); |
| 113 | opt[2]= (char *) malloc((strlen(RRD_PARAM_1) + 1) * sizeof(char)); |
| 114 | strcpy(opt[2], RRD_PARAM_1); |
| 115 | opt[3]= (char *) malloc((strlen(RRD_PARAM_2) + 1) * sizeof(char)); |
| 116 | strcpy(opt[3], RRD_PARAM_2); |
| 117 | opt[4]= (char *) malloc((strlen(RRD_PARAM_3) + 1) * sizeof(char)); |
| 118 | strcpy(opt[4], RRD_PARAM_3); |
| 119 | opt[5]= (char *) malloc((strlen(RRD_PARAM_4) + 1) * sizeof(char)); |
| 120 | strcpy(opt[5], RRD_PARAM_4); |
| 121 | opt[6]= (char *) malloc((strlen(RRD_PARAM_5) + 1) * sizeof(char)); |
| 122 | strcpy(opt[6], RRD_PARAM_5); |
| 123 | opt[7]= (char *) malloc((strlen(RRD_PARAM_6) + 1) * sizeof(char)); |
| 124 | strcpy(opt[7], RRD_PARAM_6); |
| 125 | opt[8]= (char *) malloc((strlen(RRD_PARAM_7) + 1) * sizeof(char)); |
| 126 | strcpy(opt[8], RRD_PARAM_7); |
| 127 | opt[9]= (char *) malloc((strlen(RRD_PARAM_8) + 1) * sizeof(char)); |
| 128 | strcpy(opt[9], RRD_PARAM_8); |
| 129 | opt[10]= (char *) malloc((strlen(RRD_PARAM_9) + 1) * sizeof(char)); |
| 130 | strcpy(opt[10], RRD_PARAM_9); |
| 131 | opt[11]= (char *) malloc((strlen(RRD_PARAM_10) + 1) * sizeof(char)); |
| 132 | strcpy(opt[11], RRD_PARAM_10); |
| 133 | opt[12]= (char *) malloc((strlen(RRD_PARAM_11) + 1) * sizeof(char)); |
| 134 | strcpy(opt[12], RRD_PARAM_11); |
| 135 | opt[13]= (char *) malloc((strlen(RRD_PARAM_12) + 1) * sizeof(char)); |
| 136 | strcpy(opt[13], RRD_PARAM_12); |
| 137 | opt[14]= (char *) malloc((strlen(RRD_PARAM_13) + 1) * sizeof(char)); |
| 138 | strcpy(opt[14], RRD_PARAM_13); |
| 139 | opt[15]= (char *) malloc((strlen(RRD_PARAM_14) + 1) * sizeof(char)); |
| 140 | strcpy(opt[15], RRD_PARAM_14); |
| 141 | opt[16]= (char *) malloc((strlen(RRD_PARAM_15) + 1) * sizeof(char)); |
| 142 | strcpy(opt[16], RRD_PARAM_15); |
| 143 | opt[17]= (char *) malloc((strlen(RRD_PARAM_16) + 1) * sizeof(char)); |
| 144 | strcpy(opt[17], RRD_PARAM_16); |
| 145 | opt[18]= (char *) malloc((strlen(RRD_PARAM_17) + 1) * sizeof(char)); |
| 146 | strcpy(opt[18], RRD_PARAM_17); |
| 147 | opt[19]= (char *) malloc((strlen(RRD_PARAM_18) + 1) * sizeof(char)); |
| 148 | strcpy(opt[19], RRD_PARAM_18); |
| 149 | opt[20]= (char *) malloc((strlen(RRD_PARAM_19) + 1) * sizeof(char)); |
| 150 | strcpy(opt[20], RRD_PARAM_19); |
| 151 | opt[21]= (char *) malloc((strlen(RRD_PARAM_20) + 1) * sizeof(char)); |
| 152 | strcpy(opt[21], RRD_PARAM_20); |
| 153 | opt[22]= (char *) malloc((strlen(RRD_PARAM_21) + 1) * sizeof(char)); |
| 154 | strcpy(opt[22], RRD_PARAM_21); |
| 155 | opt[23]= (char *) malloc((strlen(RRD_PARAM_22) + 1) * sizeof(char)); |
| 156 | strcpy(opt[23], RRD_PARAM_22); |
| 157 | opt[24]= (char *) malloc((strlen(RRD_PARAM_23) + 1) * sizeof(char)); |
| 158 | strcpy(opt[24], RRD_PARAM_23); |
| 159 | opt[25]= (char *) malloc((strlen(RRD_PARAM_24) + 1) * sizeof(char)); |
| 160 | strcpy(opt[25], RRD_PARAM_24); |
| 161 | opt[26]= (char *) malloc((strlen(RRD_PARAM_25) + 1) * sizeof(char)); |
| 162 | strcpy(opt[26], RRD_PARAM_25); |
| 163 | optind = opterr = 0; |
| 164 | rrd_clear_error(); |
| 165 | if ( rrd_create(27,opt) < 0) { |
| 166 | syslog(LOG_ERR, "RRD create file %s, error: %s\n", name, rrd_get_error()); |
| 167 | rrd_create_er_ct++; |
| 168 | } else { |
| 169 | rrd_create_ok_ct++; |
| 170 | } |
| 171 | for ( j=0; j<27; j++) { |
| 172 | free(opt[j]); |
| 173 | opt[j] = NULL; |
| 174 | } |
| 175 | }else{ |
| 176 | fclose(fp); |
| 177 | rrd_already_created_ct++; |
| 178 | snprintf(buf, |
| 179 | 2048, |
| 180 | "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu", |
| 181 | now-300, /* or ctime(&now) with %s */ |
| 182 | shmForAgg->prefixV4Tab[index][i].flowNbIN, /* 1 */ |
| 183 | shmForAgg->prefixV4Tab[index][i].flowNbOUT, |
| 184 | shmForAgg->prefixV4Tab[index][i].bytesNbIN, |
| 185 | shmForAgg->prefixV4Tab[index][i].bytesNbOUT, |
| 186 | shmForAgg->prefixV4Tab[index][i].pktsNbIN, /* 5 */ |
| 187 | shmForAgg->prefixV4Tab[index][i].pktsNbOUT, |
| 188 | shmForAgg->prefixV4Tab[index][i].firstCoSIN, |
| 189 | shmForAgg->prefixV4Tab[index][i].firstCoSOUT, |
| 190 | shmForAgg->prefixV4Tab[index][i].secondCoSIN, |
| 191 | shmForAgg->prefixV4Tab[index][i].secondCoSOUT, |
| 192 | shmForAgg->prefixV4Tab[index][i].thirdCoSIN, |
| 193 | shmForAgg->prefixV4Tab[index][i].thirdCoSOUT, |
| 194 | shmForAgg->prefixV4Tab[index][i].fourthCoSIN, |
| 195 | shmForAgg->prefixV4Tab[index][i].fourthCoSOUT |
| 196 | ); |
| 197 | optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); |
| 198 | strcpy(optUpdate[0], RRD_UPDATE_0); |
| 199 | optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
| 200 | strcpy(optUpdate[1], name); |
| 201 | optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); |
| 202 | strcpy(optUpdate[2], buf); |
| 203 | optind = opterr = 0; |
| 204 | rrd_clear_error(); |
| 205 | if ( rrd_update(3, optUpdate) < 0 ) { |
| 206 | syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); |
| 207 | rrd_update_er_ct++; |
| 208 | } else { |
| 209 | rrd_update_ok_ct++; |
| 210 | } |
| 211 | for ( j=0; j<3; j++) { |
| 212 | free(optUpdate[j]); |
| 213 | optUpdate[j] = NULL; |
| 214 | } |
170 | | for ( j=0; j<27; j++) { |
171 | | free(opt[j]); |
172 | | opt[j] = NULL; |
173 | | } |
174 | | }else{ |
175 | | fclose(fp); |
176 | | rrd_already_created_ct++; |
177 | | snprintf(buf, |
178 | | 2048, |
179 | | "%lu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu:%llu", |
180 | | now-300, /* or ctime(&now) with %s */ |
181 | | shmForAgg->prefixV4Tab[index][i].flowNbIN, /* 1 */ |
182 | | shmForAgg->prefixV4Tab[index][i].flowNbOUT, |
183 | | shmForAgg->prefixV4Tab[index][i].bytesNbIN, |
184 | | shmForAgg->prefixV4Tab[index][i].bytesNbOUT, |
185 | | shmForAgg->prefixV4Tab[index][i].pktsNbIN, /* 5 */ |
186 | | shmForAgg->prefixV4Tab[index][i].pktsNbOUT, |
187 | | shmForAgg->prefixV4Tab[index][i].firstCoSIN, |
188 | | shmForAgg->prefixV4Tab[index][i].firstCoSOUT, |
189 | | shmForAgg->prefixV4Tab[index][i].secondCoSIN, |
190 | | shmForAgg->prefixV4Tab[index][i].secondCoSOUT, |
191 | | shmForAgg->prefixV4Tab[index][i].thirdCoSIN, |
192 | | shmForAgg->prefixV4Tab[index][i].thirdCoSOUT, |
193 | | shmForAgg->prefixV4Tab[index][i].fourthCoSIN, |
194 | | shmForAgg->prefixV4Tab[index][i].fourthCoSOUT |
195 | | ); |
196 | | optUpdate[0]= (char *) malloc((strlen(RRD_UPDATE_0) + 1) * sizeof(char)); |
197 | | strcpy(optUpdate[0], RRD_UPDATE_0); |
198 | | optUpdate[1]= (char *) malloc((strlen(name) + 1) * sizeof(char)); |
199 | | strcpy(optUpdate[1], name); |
200 | | optUpdate[2]= (char *) malloc((strlen(buf) + 1) * sizeof(char)); |
201 | | strcpy(optUpdate[2], buf); |
202 | | optind = opterr = 0; |
203 | | rrd_clear_error(); |
204 | | if ( rrd_update(3, optUpdate) < 0 ) { |
205 | | syslog(LOG_ERR, "RRD update file %s, error: %s\n", name, rrd_get_error()); |
206 | | rrd_update_er_ct++; |
207 | | } else { |
208 | | rrd_update_ok_ct++; |
209 | | } |
210 | | for ( j=0; j<3; j++) { |
211 | | free(optUpdate[j]); |
212 | | optUpdate[j] = NULL; |
213 | | } |
| 216 | /* Reinit the shared table */ |
| 217 | shmForAgg->prefixV4Tab[index][i].flowNbIN = 0; |
| 218 | shmForAgg->prefixV4Tab[index][i].bytesNbIN = 0; |
| 219 | shmForAgg->prefixV4Tab[index][i].pktsNbIN = 0; |
| 220 | shmForAgg->prefixV4Tab[index][i].flowNbOUT = 0; |
| 221 | shmForAgg->prefixV4Tab[index][i].bytesNbOUT = 0; |
| 222 | shmForAgg->prefixV4Tab[index][i].pktsNbOUT = 0; |
| 223 | shmForAgg->prefixV4Tab[index][i].firstCoSIN = 0; |
| 224 | shmForAgg->prefixV4Tab[index][i].secondCoSIN = 0; |
| 225 | shmForAgg->prefixV4Tab[index][i].thirdCoSIN = 0; |
| 226 | shmForAgg->prefixV4Tab[index][i].fourthCoSIN = 0; |
| 227 | shmForAgg->prefixV4Tab[index][i].firstCoSOUT = 0; |
| 228 | shmForAgg->prefixV4Tab[index][i].secondCoSOUT = 0; |
| 229 | shmForAgg->prefixV4Tab[index][i].thirdCoSOUT = 0; |
| 230 | shmForAgg->prefixV4Tab[index][i].fourthCoSOUT = 0; |