1 /*****************************************************************************
2 * RRDtool 1.1.x Copyright Tobias Oetiker, 1997 - 2002
3 *****************************************************************************
4 * rrd_restore.c creates new rrd from data dumped by rrd_dump.c
5 *****************************************************************************/
7 #include "rrd_tool.h"
8 #include "rrd_rpncalc.h"
9 #include <fcntl.h>
11 /* Prototypes */
13 void xml_lc(char*);
14 int skip(char **);
15 int eat_tag(char **, char *);
16 int read_tag(char **, char *, char *, void *);
17 int xml2rrd(char*, rrd_t*, char);
18 int rrd_write(char *, rrd_t *);
19 void parse_patch1028_RRA_params(char **buf, rrd_t *rrd, int rra_index);
20 void parse_patch1028_CDP_params(char **buf, rrd_t *rrd, int rra_index, int ds_index);
21 void parse_FAILURES_history(char **buf, rrd_t *rrd, int rra_index, int ds_index);
23 /* convert all ocurances of <BlaBlaBla> to <blablabla> */
25 void xml_lc(char* buf){
26 int intag=0;
27 while((*buf)){
28 if (intag ==0 && (*buf) == '<') {
29 intag = 1;
30 }
31 else if (intag ==1 && (*buf) == '>') {
32 intag = 0;
33 continue;
34 } else if (intag ==1) {
35 *buf = tolower(*buf);
36 }
37 buf++;
38 }
39 }
41 int skip(char **buf){
42 char *ptr;
43 ptr=(*buf);
44 do {
45 (*buf)=ptr;
46 while((*(ptr+1)) && ((*ptr)==' ' || (*ptr)=='\r' || (*ptr)=='\n' || (*ptr)=='\t')) ptr++;
47 if (strncmp(ptr,"<!--",4) == 0) {
48 ptr= strstr(ptr,"-->");
49 if (ptr) ptr+=3; else {
50 rrd_set_error("Dangling Comment");
51 (*buf) = NULL;
52 return -1;
53 }
54 }
55 } while ((*buf)!=ptr);
56 return 1;
57 }
59 int eat_tag(char **buf, char *tag){
60 if ((*buf)==NULL) return -1; /* fall though clause */
62 rrd_clear_error();
63 skip(buf);
64 if ((**buf)=='<'
65 && strncmp((*buf)+1,tag,strlen(tag)) == 0
66 && *((*buf)+strlen(tag)+1)=='>') {
67 (*buf) += strlen(tag)+2;
68 }
69 else {
70 rrd_set_error("No <%s> tag found",tag);
71 (*buf) = NULL;
72 return -1;
73 }
74 skip(buf);
75 return 1;
76 }
78 int read_tag(char **buf, char *tag, char *format, void *value){
79 char *end_tag;
80 int matches;
81 if ((*buf)==NULL) return -1; /* fall though clause */
82 rrd_clear_error();
83 if (eat_tag(buf,tag)==1){
84 char *temp;
85 temp = (*buf);
86 while(*((*buf)+1) && (*(*buf) != '<')) (*buf)++; /*find start of endtag*/
87 *(*buf) = '\0';
88 matches =sscanf(temp,format,value);
89 *(*buf) = '<';
90 end_tag = malloc((strlen(tag)+2)*sizeof(char));
91 sprintf(end_tag,"/%s",tag);
92 eat_tag(buf,end_tag);
93 free(end_tag);
94 if (matches == 0 && strcmp(format,"%lf") == 0)
95 (*((double* )(value))) = DNAN;
96 if (matches != 1) return 0;
97 return 1;
98 }
99 return -1;
100 }
103 /* parse the data stored in buf and return a filled rrd structure */
104 int xml2rrd(char* buf, rrd_t* rrd, char rc){
105 /* pass 1 identify number of RRAs */
106 char *ptr,*ptr2,*ptr3; /* walks thought the buffer */
107 long rows=0,mempool=0,i=0;
108 int rra_index;
109 xml_lc(buf); /* lets lowercase all active parts of the xml */
110 ptr=buf;
111 ptr2=buf;
112 ptr3=buf;
113 /* start with an RRD tag */
115 eat_tag(&ptr,"rrd");
116 /* allocate static header */
117 if((rrd->stat_head = calloc(1,sizeof(stat_head_t)))==NULL){
118 rrd_set_error("allocating rrd.stat_head");
119 return -1;
120 };
122 strcpy(rrd->stat_head->cookie,RRD_COOKIE);
123 read_tag(&ptr,"version","%4[0-9]",rrd->stat_head->version);
124 /* added primitive version checking */
125 if (atoi(rrd -> stat_head -> version) > atoi(RRD_VERSION) )
126 {
127 rrd_set_error("Incompatible file version, detected version %s is bigger than supported version %s\n",
128 rrd -> stat_head -> version, RRD_VERSION );
129 free(rrd -> stat_head);
130 return -1;
131 }
132 if (atoi(rrd -> stat_head -> version) < 2)
133 {
134 rrd_set_error("Can only restore version >= 2 (Not %s). Dump your rrd using a current rrdtool dump.", rrd -> stat_head -> version );
135 free(rrd -> stat_head);
136 return -1;
137 }
138 rrd->stat_head->float_cookie = FLOAT_COOKIE;
139 rrd->stat_head->ds_cnt = 0;
140 rrd->stat_head->rra_cnt = 0;
141 read_tag(&ptr,"step","%lu",&(rrd->stat_head->pdp_step));
143 /* allocate live head */
144 if((rrd->live_head = calloc(1,sizeof(live_head_t)))==NULL){
145 rrd_set_error("allocating rrd.live_head");
146 return -1;
147 }
148 read_tag(&ptr,"lastupdate","%lu",&(rrd->live_head->last_up));
150 /* Data Source Definition Part */
151 ptr2 = ptr;
152 while (eat_tag(&ptr2,"ds") == 1){
153 rrd->stat_head->ds_cnt++;
154 if((rrd->ds_def = rrd_realloc(rrd->ds_def,rrd->stat_head->ds_cnt*sizeof(ds_def_t)))==NULL){
155 rrd_set_error("allocating rrd.ds_def");
156 return -1;
157 };
158 /* clean out memory to make sure no data gets stored from previous tasks */
159 memset(&(rrd->ds_def[rrd->stat_head->ds_cnt-1]), 0, sizeof(ds_def_t));
160 if((rrd->pdp_prep = rrd_realloc(rrd->pdp_prep,rrd->stat_head->ds_cnt
161 *sizeof(pdp_prep_t)))==NULL){
162 rrd_set_error("allocating pdp_prep");
163 return(-1);
164 }
165 /* clean out memory to make sure no data gets stored from previous tasks */
166 memset(&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1]), 0, sizeof(pdp_prep_t));
168 read_tag(&ptr2,"name",DS_NAM_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].ds_nam);
170 read_tag(&ptr2,"type",DST_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].dst);
171 /* test for valid type */
172 if(dst_conv(rrd->ds_def[rrd->stat_head->ds_cnt-1].dst) == -1) return -1;
174 if (dst_conv(rrd->ds_def[rrd->stat_head->ds_cnt-1].dst) != DST_CDEF)
175 {
176 read_tag(&ptr2,"minimal_heartbeat","%lu",
177 &(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_mrhb_cnt].u_cnt));
178 read_tag(&ptr2,"min","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_min_val].u_val));
179 read_tag(&ptr2,"max","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_max_val].u_val));
180 } else { /* DST_CDEF */
181 char buffer[1024];
182 read_tag(&ptr2,"cdef","%s",buffer);
183 parseCDEF_DS(buffer,rrd,rrd -> stat_head -> ds_cnt - 1);
184 }
186 read_tag(&ptr2,"last_ds","%30s",rrd->pdp_prep[rrd->stat_head->ds_cnt-1].last_ds);
187 read_tag(&ptr2,"value","%lf",&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1].scratch[PDP_val].u_val));
188 read_tag(&ptr2,"unknown_sec","%lu",&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1].scratch[PDP_unkn_sec_cnt].u_cnt));
189 eat_tag(&ptr2,"/ds");
190 ptr=ptr2;
191 }
193 ptr2 = ptr;
194 while (eat_tag(&ptr2,"rra") == 1){
195 rrd->stat_head->rra_cnt++;
197 /* alocate and reset rra definition areas */
198 if((rrd->rra_def = rrd_realloc(rrd->rra_def,rrd->stat_head->rra_cnt*sizeof(rra_def_t)))==NULL){
199 rrd_set_error("allocating rra_def"); return -1; }
200 memset(&(rrd->rra_def[rrd->stat_head->rra_cnt-1]), 0, sizeof(rra_def_t));
202 /* alocate and reset consolidation point areas */
203 if((rrd->cdp_prep = rrd_realloc(rrd->cdp_prep,
204 rrd->stat_head->rra_cnt
205 *rrd->stat_head->ds_cnt*sizeof(cdp_prep_t)))==NULL){
206 rrd_set_error("allocating cdp_prep"); return -1; }
208 memset(&(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rrd->stat_head->rra_cnt-1)]),
209 0, rrd->stat_head->ds_cnt*sizeof(cdp_prep_t));
212 read_tag(&ptr2,"cf",CF_NAM_FMT,rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam);
213 /* test for valid type */
214 if(cf_conv(rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam) == -1) return -1;
216 read_tag(&ptr2,"pdp_per_row","%lu",&(rrd->rra_def[rrd->stat_head->rra_cnt-1].pdp_cnt));
217 /* support to read RRA parameters */
218 eat_tag(&ptr2, "params");
219 skip(&ptr2);
220 rra_index = rrd->stat_head->rra_cnt - 1;
221 /* backwards compatibility w/ old patch */
222 if (strncmp(ptr2, "<value>",7) == 0) {
223 parse_patch1028_RRA_params(&ptr2,rrd,rra_index);
224 } else {
225 switch(cf_conv(rrd -> rra_def[rra_index].cf_nam)) {
226 case CF_HWPREDICT:
227 read_tag(&ptr2, "hw_alpha", "%lf",
228 &(rrd->rra_def[rra_index].par[RRA_hw_alpha].u_val));
229 read_tag(&ptr2, "hw_beta", "%lf",
230 &(rrd->rra_def[rra_index].par[RRA_hw_beta].u_val));
231 read_tag(&ptr2, "dependent_rra_idx", "%lu",
232 &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
233 break;
234 case CF_SEASONAL:
235 case CF_DEVSEASONAL:
236 read_tag(&ptr2, "seasonal_gamma", "%lf",
237 &(rrd->rra_def[rra_index].par[RRA_seasonal_gamma].u_val));
238 read_tag(&ptr2, "seasonal_smooth_idx", "%lu",
239 &(rrd->rra_def[rra_index].par[RRA_seasonal_smooth_idx].u_cnt));
240 read_tag(&ptr2, "dependent_rra_idx", "%lu",
241 &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
242 break;
243 case CF_FAILURES:
244 read_tag(&ptr2, "delta_pos", "%lf",
245 &(rrd->rra_def[rra_index].par[RRA_delta_pos].u_val));
246 read_tag(&ptr2, "delta_neg", "%lf",
247 &(rrd->rra_def[rra_index].par[RRA_delta_neg].u_val));
248 read_tag(&ptr2, "window_len", "%lu",
249 &(rrd->rra_def[rra_index].par[RRA_window_len].u_cnt));
250 read_tag(&ptr2, "failure_threshold", "%lu",
251 &(rrd->rra_def[rra_index].par[RRA_failure_threshold].u_cnt));
252 /* fall thru */
253 case CF_DEVPREDICT:
254 read_tag(&ptr2, "dependent_rra_idx", "%lu",
255 &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
256 break;
257 case CF_AVERAGE:
258 case CF_MAXIMUM:
259 case CF_MINIMUM:
260 case CF_LAST:
261 default:
262 read_tag(&ptr2, "xff","%lf",
263 &(rrd->rra_def[rra_index].par[RRA_cdp_xff_val].u_val));
264 }
265 }
266 eat_tag(&ptr2, "/params");
267 eat_tag(&ptr2,"cdp_prep");
268 for(i=0;i<rrd->stat_head->ds_cnt;i++)
269 {
270 eat_tag(&ptr2,"ds");
271 /* support to read CDP parameters */
272 rra_index = rrd->stat_head->rra_cnt-1;
273 skip(&ptr2);
274 if (strncmp(ptr2, "<value>",7) == 0) {
275 parse_patch1028_CDP_params(&ptr2,rrd,rra_index,i);
276 } else {
277 read_tag(&ptr2, "primary_value","%lf",
278 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
279 +i].scratch[CDP_primary_val].u_val));
280 read_tag(&ptr2, "secondary_value","%lf",
281 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
282 +i].scratch[CDP_secondary_val].u_val));
283 switch(cf_conv(rrd->rra_def[rra_index].cf_nam)) {
284 case CF_HWPREDICT:
285 read_tag(&ptr2,"intercept","%lf",
286 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
287 +i].scratch[CDP_hw_intercept].u_val));
288 read_tag(&ptr2,"last_intercept","%lf",
289 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
290 +i].scratch[CDP_hw_last_intercept].u_val));
291 read_tag(&ptr2,"slope","%lf",
292 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
293 +i].scratch[CDP_hw_slope].u_val));
294 read_tag(&ptr2,"last_slope","%lf",
295 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
296 +i].scratch[CDP_hw_last_slope].u_val));
297 read_tag(&ptr2,"nan_count","%lu",
298 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
299 +i].scratch[CDP_null_count].u_cnt));
300 read_tag(&ptr2,"last_nan_count","%lu",
301 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
302 +i].scratch[CDP_last_null_count].u_cnt));
303 break;
304 case CF_SEASONAL:
305 case CF_DEVSEASONAL:
306 read_tag(&ptr2,"seasonal","%lf",
307 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
308 +i].scratch[CDP_hw_seasonal].u_val));
309 read_tag(&ptr2,"last_seasonal","%lf",
310 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
311 +i].scratch[CDP_hw_last_seasonal].u_val));
312 read_tag(&ptr2,"init_flag","%lu",
313 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
314 +i].scratch[CDP_init_seasonal].u_cnt));
315 break;
316 case CF_DEVPREDICT:
317 break;
318 case CF_FAILURES:
319 parse_FAILURES_history(&ptr2,rrd,rra_index,i);
320 break;
321 case CF_AVERAGE:
322 case CF_MAXIMUM:
323 case CF_MINIMUM:
324 case CF_LAST:
325 default:
326 read_tag(&ptr2,"value","%lf",&(rrd->cdp_prep[rrd->stat_head->ds_cnt
327 *(rra_index) +i].scratch[CDP_val].u_val));
328 read_tag(&ptr2,"unknown_datapoints","%lu",&(rrd->cdp_prep[rrd->stat_head->ds_cnt
329 *(rra_index) +i].scratch[CDP_unkn_pdp_cnt].u_cnt));
330 break;
331 }
332 }
333 eat_tag(&ptr2,"/ds");
334 }
335 eat_tag(&ptr2,"/cdp_prep");
336 rrd->rra_def[rrd->stat_head->rra_cnt-1].row_cnt=0;
337 eat_tag(&ptr2,"database");
338 ptr3 = ptr2;
339 while (eat_tag(&ptr3,"row") == 1){
341 if(mempool==0){
342 mempool = 1000;
343 if((rrd->rrd_value = rrd_realloc(rrd->rrd_value,
344 (rows+mempool)*(rrd->stat_head->ds_cnt)
345 *sizeof(rrd_value_t)))==NULL) {
346 rrd_set_error("allocating rrd_values"); return -1; }
347 }
348 rows++;
349 mempool--;
350 rrd->rra_def[rrd->stat_head->rra_cnt-1].row_cnt++;
351 for(i=0;i<rrd->stat_head->ds_cnt;i++){
353 rrd_value_t * value = &(rrd->rrd_value[(rows-1)*rrd->stat_head->ds_cnt+i]);
355 read_tag(&ptr3,"v","%lf", value);
357 if (
358 (rc == 1) /* do we have to check for the ranges */
359 &&
360 (!isnan(*value)) /* not a NAN value */
361 &&
362 (dst_conv(rrd->ds_def[i].dst) != DST_CDEF)
363 &&
364 ( /* min defined and in the range ? */
365 (!isnan(rrd->ds_def[i].par[DS_min_val].u_val)
366 && (*value < rrd->ds_def[i].par[DS_min_val].u_val))
367 || /* max defined and in the range ? */
368 (!isnan(rrd->ds_def[i].par[DS_max_val].u_val)
369 && (*value > rrd->ds_def[i].par[DS_max_val].u_val))
370 )
371 ) {
372 fprintf (stderr, "out of range found [ds: %lu], [value : %0.10e]\n", i, *value);
373 *value = DNAN;
374 }
375 }
376 eat_tag(&ptr3,"/row");
377 ptr2=ptr3;
378 }
379 eat_tag(&ptr2,"/database");
380 eat_tag(&ptr2,"/rra");
381 ptr=ptr2;
382 }
383 eat_tag(&ptr,"/rrd");
385 if((rrd->rra_ptr = calloc(1,sizeof(rra_ptr_t)*rrd->stat_head->rra_cnt)) == NULL) {
386 rrd_set_error("allocating rra_ptr");
387 return(-1);
388 }
390 for(i=0; i <rrd->stat_head->rra_cnt; i++) {
391 /* last row in the xml file is the most recent; as
392 * rrd_update increments the current row pointer, set cur_row
393 * here to the last row. */
394 rrd->rra_ptr[i].cur_row = rrd->rra_def[i].row_cnt-1;
395 }
396 if (ptr==NULL)
397 return -1;
398 return 1;
399 }
405 /* create and empty rrd file according to the specs given */
407 int
408 rrd_write(char *file_name, rrd_t *rrd)
409 {
410 unsigned long i,ii,val_cnt;
411 FILE *rrd_file=NULL;
413 if (strcmp("-",file_name)==0){
414 rrd_file= stdout;
415 } else {
416 int fd = open(file_name,O_RDWR|O_CREAT|O_EXCL,0666);
417 if (fd == -1 || (rrd_file = fdopen(fd,"wb")) == NULL) {
418 rrd_set_error("creating '%s': %s",file_name,rrd_strerror(errno));
419 if (fd != -1)
420 close(fd);
421 return(-1);
422 }
423 }
424 fwrite(rrd->stat_head,
425 sizeof(stat_head_t), 1, rrd_file);
427 fwrite(rrd->ds_def,
428 sizeof(ds_def_t), rrd->stat_head->ds_cnt, rrd_file);
430 fwrite(rrd->rra_def,
431 sizeof(rra_def_t), rrd->stat_head->rra_cnt, rrd_file);
433 /* maybe the xml hold an old formatted rrd */
434 if (atoi(rrd->stat_head->version) < 3)
435 fwrite(&(rrd->live_head->last_up), sizeof(long),1, rrd_file);
436 else
437 fwrite(rrd->live_head, sizeof(live_head_t),1, rrd_file);
439 fwrite( rrd->pdp_prep, sizeof(pdp_prep_t),rrd->stat_head->ds_cnt,rrd_file);
441 fwrite( rrd->cdp_prep, sizeof(cdp_prep_t),rrd->stat_head->rra_cnt*
442 rrd->stat_head->ds_cnt,rrd_file);
443 fwrite( rrd->rra_ptr, sizeof(rra_ptr_t), rrd->stat_head->rra_cnt,rrd_file);
447 /* calculate the number of rrd_values to dump */
448 val_cnt=0;
449 for(i=0; i < rrd->stat_head->rra_cnt; i++)
450 for(ii=0; ii < rrd->rra_def[i].row_cnt * rrd->stat_head->ds_cnt;ii++)
451 val_cnt++;
452 fwrite( rrd->rrd_value, sizeof(rrd_value_t),val_cnt,rrd_file);
454 /* lets see if we had an error */
455 if(ferror(rrd_file)){
456 rrd_set_error("a file error occurred while creating '%s'",file_name);
457 fclose(rrd_file);
458 return(-1);
459 }
461 fclose(rrd_file);
462 return 0;
463 }
466 int
467 rrd_restore(int argc, char **argv)
468 {
469 rrd_t rrd;
470 char *buf;
471 char rc = 0;
473 /* init rrd clean */
474 rrd_init(&rrd);
475 if (argc<3) {
476 rrd_set_error("usage rrdtool %s [--range-check/-r] file.xml file.rrd",argv[0]);
477 return -1;
478 }
480 while (1) {
481 static struct option long_options[] =
482 {
483 {"range-check", required_argument, 0, 'r'},
484 {0,0,0,0}
485 };
486 int option_index = 0;
487 int opt;
490 opt = getopt_long(argc, argv, "r", long_options, &option_index);
492 if (opt == EOF)
493 break;
495 switch(opt) {
496 case 'r':
497 rc=1;
498 break;
499 default:
500 rrd_set_error("usage rrdtool %s [--range-check|-r] file.xml file.rrd",argv[0]);
501 return -1;
502 break;
503 }
504 }
506 if (readfile(argv[optind],&buf,0)==-1){
507 return -1;
508 }
509 if (xml2rrd(buf,&rrd,rc)==-1) {
510 rrd_free(&rrd);
511 free(buf);
512 return -1;
513 }
514 free(buf);
515 if(rrd_write(argv[optind+1],&rrd)==-1){
516 rrd_free(&rrd);
517 return -1;
518 };
519 rrd_free(&rrd);
520 return 0;
521 }
523 /* a backwards compatibility routine that will parse the RRA params section
524 * generated by the aberrant patch to 1.0.28. */
526 void
527 parse_patch1028_RRA_params(char **buf, rrd_t *rrd, int rra_index)
528 {
529 int i;
530 for (i = 0; i < MAX_RRA_PAR_EN; i++)
531 {
532 if (i == RRA_dependent_rra_idx ||
533 i == RRA_seasonal_smooth_idx ||
534 i == RRA_failure_threshold)
535 read_tag(buf, "value","%lu",
536 &(rrd->rra_def[rra_index].par[i].u_cnt));
537 else
538 read_tag(buf, "value","%lf",
539 &(rrd->rra_def[rra_index].par[i].u_val));
540 }
541 }
543 /* a backwards compatibility routine that will parse the CDP params section
544 * generated by the aberrant patch to 1.0.28. */
545 void
546 parse_patch1028_CDP_params(char **buf, rrd_t *rrd, int rra_index, int ds_index)
547 {
548 int ii;
549 for (ii = 0; ii < MAX_CDP_PAR_EN; ii++)
550 {
551 if (cf_conv(rrd->rra_def[rra_index].cf_nam) == CF_FAILURES ||
552 ii == CDP_unkn_pdp_cnt ||
553 ii == CDP_null_count ||
554 ii == CDP_last_null_count)
555 {
556 read_tag(buf,"value","%lu",
557 &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index) + ds_index].scratch[ii].u_cnt));
558 } else {
559 read_tag(buf,"value","%lf",&(rrd->cdp_prep[rrd->stat_head->ds_cnt*
560 (rra_index) + ds_index].scratch[ii].u_val));
561 }
562 }
563 }
565 void
566 parse_FAILURES_history(char **buf, rrd_t *rrd, int rra_index, int ds_index)
567 {
568 char history[MAX_FAILURES_WINDOW_LEN + 1];
569 char *violations_array;
570 unsigned short i;
572 /* 28 = MAX_FAILURES_WINDOW_LEN */
573 read_tag(buf, "history", "%28[0-1]", history);
574 violations_array = (char*) rrd -> cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
575 + ds_index].scratch;
577 for (i = 0; i < rrd -> rra_def[rra_index].par[RRA_window_len].u_cnt; ++i)
578 violations_array[i] = (history[i] == '1') ? 1 : 0;
580 }