Code

aded missing fcntl.h
[rrdtool-all.git] / program / src / rrd_restore.c
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;
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) != 2)
126   {
127     rrd_set_error("Incompatible file version, detected version %s, required version %s\n",
128                   rrd -> stat_head -> version, RRD_VERSION);
129     free(rrd -> stat_head);
130     return -1;
131   }
132   rrd->stat_head->float_cookie = FLOAT_COOKIE;
133   rrd->stat_head->ds_cnt = 0;
134   rrd->stat_head->rra_cnt = 0;
135   read_tag(&ptr,"step","%lu",&(rrd->stat_head->pdp_step));
137   /* allocate live head */
138   if((rrd->live_head = calloc(1,sizeof(live_head_t)))==NULL){
139     rrd_set_error("allocating rrd.live_head");
140     return -1;    
141   }
142   read_tag(&ptr,"lastupdate","%lu",&(rrd->live_head->last_up));
144   /* Data Source Definition Part */
145   ptr2 = ptr;
146   while (eat_tag(&ptr2,"ds") == 1){
147       rrd->stat_head->ds_cnt++;
148       if((rrd->ds_def = rrd_realloc(rrd->ds_def,rrd->stat_head->ds_cnt*sizeof(ds_def_t)))==NULL){
149           rrd_set_error("allocating rrd.ds_def");
150           return -1;
151       };
152       /* clean out memory to make sure no data gets stored from previous tasks */
153       memset(&(rrd->ds_def[rrd->stat_head->ds_cnt-1]), 0, sizeof(ds_def_t));
154       if((rrd->pdp_prep = rrd_realloc(rrd->pdp_prep,rrd->stat_head->ds_cnt
155                                   *sizeof(pdp_prep_t)))==NULL){
156         rrd_set_error("allocating pdp_prep");
157         return(-1);
158       }
159       /* clean out memory to make sure no data gets stored from previous tasks */
160       memset(&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1]), 0, sizeof(pdp_prep_t));
162       read_tag(&ptr2,"name",DS_NAM_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].ds_nam);
164       read_tag(&ptr2,"type",DST_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].dst);
165       /* test for valid type */
166       if(dst_conv(rrd->ds_def[rrd->stat_head->ds_cnt-1].dst) == -1) return -1;      
168           if (dst_conv(rrd->ds_def[rrd->stat_head->ds_cnt-1].dst) != DST_CDEF)
169           {
170       read_tag(&ptr2,"minimal_heartbeat","%lu",
171                &(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_mrhb_cnt].u_cnt));
172       read_tag(&ptr2,"min","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_min_val].u_val));
173       read_tag(&ptr2,"max","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_max_val].u_val));
174           } else { /* DST_CDEF */
175                  char buffer[1024];
176              read_tag(&ptr2,"cdef","%s",buffer);
177                  parseCDEF_DS(buffer,rrd,rrd -> stat_head -> ds_cnt - 1);
178           }
180       read_tag(&ptr2,"last_ds","%30s",rrd->pdp_prep[rrd->stat_head->ds_cnt-1].last_ds);
181       read_tag(&ptr2,"value","%lf",&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1].scratch[PDP_val].u_val));
182       read_tag(&ptr2,"unknown_sec","%lu",&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1].scratch[PDP_unkn_sec_cnt].u_cnt));      
183       eat_tag(&ptr2,"/ds");
184       ptr=ptr2;
185   }
186   
187   ptr2 = ptr;
188   while (eat_tag(&ptr2,"rra") == 1){
189       rrd->stat_head->rra_cnt++;
191       /* alocate and reset rra definition areas */
192       if((rrd->rra_def = rrd_realloc(rrd->rra_def,rrd->stat_head->rra_cnt*sizeof(rra_def_t)))==NULL){
193           rrd_set_error("allocating rra_def"); return -1; }      
194       memset(&(rrd->rra_def[rrd->stat_head->rra_cnt-1]), 0, sizeof(rra_def_t));
196       /* alocate and reset consolidation point areas */
197       if((rrd->cdp_prep = rrd_realloc(rrd->cdp_prep,
198                                   rrd->stat_head->rra_cnt
199                                   *rrd->stat_head->ds_cnt*sizeof(cdp_prep_t)))==NULL){
200           rrd_set_error("allocating cdp_prep"); return -1; }
202       memset(&(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rrd->stat_head->rra_cnt-1)]), 
203              0, rrd->stat_head->ds_cnt*sizeof(cdp_prep_t));
205       
206       read_tag(&ptr2,"cf",CF_NAM_FMT,rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam);
207       /* test for valid type */
208       if(cf_conv(rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam) == -1) return -1;
210       read_tag(&ptr2,"pdp_per_row","%lu",&(rrd->rra_def[rrd->stat_head->rra_cnt-1].pdp_cnt));
211       /* support to read RRA parameters */
212       eat_tag(&ptr2, "params");
213       skip(&ptr2);
214       rra_index = rrd->stat_head->rra_cnt - 1;
215       /* backwards compatibility w/ old patch */
216       if (strncmp(ptr2, "<value>",7) == 0) {
217          parse_patch1028_RRA_params(&ptr2,rrd,rra_index); 
218       } else {
219       switch(cf_conv(rrd -> rra_def[rra_index].cf_nam)) {
220       case CF_HWPREDICT:
221          read_tag(&ptr2, "hw_alpha", "%lf", 
222             &(rrd->rra_def[rra_index].par[RRA_hw_alpha].u_val));
223          read_tag(&ptr2, "hw_beta", "%lf", 
224             &(rrd->rra_def[rra_index].par[RRA_hw_beta].u_val));
225          read_tag(&ptr2, "dependent_rra_idx", "%lu", 
226             &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
227          break;
228       case CF_SEASONAL:
229       case CF_DEVSEASONAL:
230          read_tag(&ptr2, "seasonal_gamma", "%lf", 
231             &(rrd->rra_def[rra_index].par[RRA_seasonal_gamma].u_val));
232          read_tag(&ptr2, "seasonal_smooth_idx", "%lu", 
233             &(rrd->rra_def[rra_index].par[RRA_seasonal_smooth_idx].u_cnt));
234          read_tag(&ptr2, "dependent_rra_idx", "%lu", 
235             &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
236          break;
237       case CF_FAILURES:
238          read_tag(&ptr2, "delta_pos", "%lf", 
239             &(rrd->rra_def[rra_index].par[RRA_delta_pos].u_val));
240          read_tag(&ptr2, "delta_neg", "%lf", 
241             &(rrd->rra_def[rra_index].par[RRA_delta_neg].u_val));
242          read_tag(&ptr2, "window_len", "%lu", 
243             &(rrd->rra_def[rra_index].par[RRA_window_len].u_cnt));
244          read_tag(&ptr2, "failure_threshold", "%lu", 
245             &(rrd->rra_def[rra_index].par[RRA_failure_threshold].u_cnt));
246          /* fall thru */
247       case CF_DEVPREDICT:
248          read_tag(&ptr2, "dependent_rra_idx", "%lu", 
249             &(rrd->rra_def[rra_index].par[RRA_dependent_rra_idx].u_cnt));
250          break;
251       case CF_AVERAGE:
252       case CF_MAXIMUM:
253       case CF_MINIMUM:
254       case CF_LAST:
255       default:
256          read_tag(&ptr2, "xff","%lf",
257             &(rrd->rra_def[rra_index].par[RRA_cdp_xff_val].u_val));
258       }
259       }
260       eat_tag(&ptr2, "/params");
261       eat_tag(&ptr2,"cdp_prep");
262       for(i=0;i<rrd->stat_head->ds_cnt;i++)
263       {
264       eat_tag(&ptr2,"ds");
265       /* support to read CDP parameters */
266       rra_index = rrd->stat_head->rra_cnt-1; 
267       skip(&ptr2);
268       if (strncmp(ptr2, "<value>",7) == 0) {
269          parse_patch1028_CDP_params(&ptr2,rrd,rra_index,i);
270       } else {
271          read_tag(&ptr2, "primary_value","%lf",
272                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
273                +i].scratch[CDP_primary_val].u_val));
274          read_tag(&ptr2, "secondary_value","%lf",
275                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
276                +i].scratch[CDP_secondary_val].u_val));
277          switch(cf_conv(rrd->rra_def[rra_index].cf_nam)) {
278          case CF_HWPREDICT:
279             read_tag(&ptr2,"intercept","%lf", 
280                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
281                +i].scratch[CDP_hw_intercept].u_val));
282             read_tag(&ptr2,"last_intercept","%lf", 
283                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
284                +i].scratch[CDP_hw_last_intercept].u_val));
285             read_tag(&ptr2,"slope","%lf", 
286                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
287                +i].scratch[CDP_hw_slope].u_val));
288             read_tag(&ptr2,"last_slope","%lf", 
289                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
290                +i].scratch[CDP_hw_last_slope].u_val));
291             read_tag(&ptr2,"nan_count","%lu", 
292                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
293                +i].scratch[CDP_null_count].u_cnt));
294             read_tag(&ptr2,"last_nan_count","%lu", 
295                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
296                +i].scratch[CDP_last_null_count].u_cnt));
297             break;
298          case CF_SEASONAL:
299          case CF_DEVSEASONAL:
300             read_tag(&ptr2,"seasonal","%lf", 
301                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
302                +i].scratch[CDP_hw_seasonal].u_val));
303             read_tag(&ptr2,"last_seasonal","%lf", 
304                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
305                +i].scratch[CDP_hw_last_seasonal].u_val));
306             read_tag(&ptr2,"init_flag","%lu", 
307                &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
308                +i].scratch[CDP_init_seasonal].u_cnt));
309             break;
310          case CF_DEVPREDICT:
311             break;
312          case CF_FAILURES:
313             parse_FAILURES_history(&ptr2,rrd,rra_index,i); 
314             break;
315          case CF_AVERAGE:
316          case CF_MAXIMUM:
317          case CF_MINIMUM:
318          case CF_LAST:
319          default:
320             read_tag(&ptr2,"value","%lf",&(rrd->cdp_prep[rrd->stat_head->ds_cnt
321                *(rra_index) +i].scratch[CDP_val].u_val));
322             read_tag(&ptr2,"unknown_datapoints","%lu",&(rrd->cdp_prep[rrd->stat_head->ds_cnt
323                *(rra_index) +i].scratch[CDP_unkn_pdp_cnt].u_cnt));
324             break;
325          }
326       }
327       eat_tag(&ptr2,"/ds");
328       }
329       eat_tag(&ptr2,"/cdp_prep");
330       rrd->rra_def[rrd->stat_head->rra_cnt-1].row_cnt=0;
331       eat_tag(&ptr2,"database");
332       ptr3 = ptr2;      
333       while (eat_tag(&ptr3,"row") == 1){
334         
335           if(mempool==0){
336             mempool = 1000;
337             if((rrd->rrd_value = rrd_realloc(rrd->rrd_value,
338                                          (rows+mempool)*(rrd->stat_head->ds_cnt)
339                                          *sizeof(rrd_value_t)))==NULL) {
340               rrd_set_error("allocating rrd_values"); return -1; }
341           }
342           rows++;
343           mempool--;
344           rrd->rra_def[rrd->stat_head->rra_cnt-1].row_cnt++;
345           for(i=0;i<rrd->stat_head->ds_cnt;i++){
347                   rrd_value_t  * value = &(rrd->rrd_value[(rows-1)*rrd->stat_head->ds_cnt+i]);
349                   read_tag(&ptr3,"v","%lf", value);
350                   
351                   if (
352                           (rc == 1)                     /* do we have to check for the ranges */
353                           &&
354                       (!isnan(*value))  /* not a NAN value */
355                       &&
356                           (dst_conv(rrd->ds_def[i].dst) != DST_CDEF)
357                           &&
358                       (                                 /* min defined and in the range ? */
359                           (!isnan(rrd->ds_def[i].par[DS_min_val].u_val) 
360                                 && (*value < rrd->ds_def[i].par[DS_min_val].u_val)) 
361                           ||                            /* max defined and in the range ? */
362                           (!isnan(rrd->ds_def[i].par[DS_max_val].u_val) 
363                                 && (*value > rrd->ds_def[i].par[DS_max_val].u_val))
364                       )
365                   ) {
366                       fprintf (stderr, "out of range found [ds: %lu], [value : %0.10e]\n", i, *value);
367                       *value = DNAN;
368                   }
369           }
370           eat_tag(&ptr3,"/row");                  
371           ptr2=ptr3;
372       }
373       eat_tag(&ptr2,"/database");
374       eat_tag(&ptr2,"/rra");                  
375       ptr=ptr2;
376   }  
377   eat_tag(&ptr,"/rrd");
379   if((rrd->rra_ptr = calloc(1,sizeof(rra_ptr_t)*rrd->stat_head->rra_cnt)) == NULL) {
380       rrd_set_error("allocating rra_ptr");
381       return(-1);
382   }
384   for(i=0; i <rrd->stat_head->rra_cnt; i++) {
385           /* last row in the xml file is the most recent; as
386            * rrd_update increments the current row pointer, set cur_row
387            * here to the last row. */
388       rrd->rra_ptr[i].cur_row = rrd->rra_def[i].row_cnt-1;
389   }
390   if (ptr==NULL)
391       return -1;
392   return 1;
394   
395     
399 /* create and empty rrd file according to the specs given */
401 int
402 rrd_write(char *file_name, rrd_t *rrd)
404     unsigned long    i,ii,val_cnt;
405     FILE             *rrd_file=NULL;
407     if (strcmp("-",file_name)==0){
408       *rrd_file= *stdout;
409     } else {
410       int fd = open(file_name,O_RDWR|O_CREAT|O_EXCL);
411       if (fd == -1 || (rrd_file = fdopen(fd,"wb")) == NULL) {
412         rrd_set_error("creating '%s': %s",file_name,strerror(errno));
413         rrd_free(rrd);
414         if (fd != -1)
415           close(fd);
416         return(-1);
417       }
418     }
419     fwrite(rrd->stat_head,
420            sizeof(stat_head_t), 1, rrd_file);
422     fwrite(rrd->ds_def,
423            sizeof(ds_def_t), rrd->stat_head->ds_cnt, rrd_file);
425     fwrite(rrd->rra_def,
426            sizeof(rra_def_t), rrd->stat_head->rra_cnt, rrd_file);
427     
428     fwrite(rrd->live_head, sizeof(live_head_t),1, rrd_file);
430     fwrite( rrd->pdp_prep, sizeof(pdp_prep_t),rrd->stat_head->ds_cnt,rrd_file);
431     
432     fwrite( rrd->cdp_prep, sizeof(cdp_prep_t),rrd->stat_head->rra_cnt*
433             rrd->stat_head->ds_cnt,rrd_file);
434     fwrite( rrd->rra_ptr, sizeof(rra_ptr_t), rrd->stat_head->rra_cnt,rrd_file);
438     /* calculate the number of rrd_values to dump */
439     val_cnt=0;
440     for(i=0; i <  rrd->stat_head->rra_cnt; i++)
441         for(ii=0; ii <  rrd->rra_def[i].row_cnt * rrd->stat_head->ds_cnt;ii++)
442             val_cnt++;
443     fwrite( rrd->rrd_value, sizeof(rrd_value_t),val_cnt,rrd_file);
445     /* lets see if we had an error */
446     if(ferror(rrd_file)){
447         rrd_set_error("a file error occurred while creating '%s'",file_name);
448         fclose(rrd_file);       
449         return(-1);
450     }
451     
452     fclose(rrd_file);    
453     return 0;
457 int
458 rrd_restore(int argc, char **argv) 
460     rrd_t          rrd;
461     char          *buf;
462         char                    rc = 0;
464     /* init rrd clean */
465     rrd_init(&rrd);
466     if (argc<3) {
467                 rrd_set_error("usage rrdtool %s [--range-check/-r] file.xml file.rrd",argv[0]);
468                 return -1;
469     }
470         
471         while (1) {
472                 static struct option long_options[] =
473                 {
474                         {"range-check",      required_argument, 0,  'r'},
475                         {0,0,0,0}
476                 };
477                 int option_index = 0;
478                 int opt;
479                 
480                 
481                 opt = getopt_long(argc, argv, "r", long_options, &option_index);
482                 
483                 if (opt == EOF)
484                         break;
485                 
486                 switch(opt) {
487                 case 'r':
488                         rc=1;
489                         break;
490                 default:
491                         rrd_set_error("usage rrdtool %s [--range-check|-r] file.xml file.rrd",argv[0]);
492         return -1;
493                         break;
494                 }
495     }
496         
497     if (readfile(argv[optind],&buf,0)==-1){
498       return -1;
499     }
500     if (xml2rrd(buf,&rrd,rc)==-1) {
501         rrd_free(&rrd);
502         free(buf);
503         return -1;
504     }
505     free(buf);
506     if(rrd_write(argv[optind+1],&rrd)==-1){
507         rrd_free(&rrd); 
508         return -1;      
509     };
510     rrd_free(&rrd);    
511     return 0;
514 /* a backwards compatibility routine that will parse the RRA params section
515  * generated by the aberrant patch to 1.0.28. */
516 void
517 parse_patch1028_RRA_params(char **buf, rrd_t *rrd, int rra_index)
519    int i;
520    for (i = 0; i < MAX_RRA_PAR_EN; i++)
521    {
522    if (i == RRA_dependent_rra_idx ||
523        i == RRA_seasonal_smooth_idx ||
524        i == RRA_failure_threshold)
525       read_tag(buf, "value","%lu",
526          &(rrd->rra_def[rra_index].par[i].u_cnt));
527    else
528       read_tag(buf, "value","%lf",
529          &(rrd->rra_def[rra_index].par[i].u_val));
530    }
533 /* a backwards compatibility routine that will parse the CDP params section
534  * generated by the aberrant patch to 1.0.28. */
535 void
536 parse_patch1028_CDP_params(char **buf, rrd_t *rrd, int rra_index, int ds_index)
538    int ii;
539    for (ii = 0; ii < MAX_CDP_PAR_EN; ii++)
540    {
541    if (cf_conv(rrd->rra_def[rra_index].cf_nam) == CF_FAILURES ||
542        ii == CDP_unkn_pdp_cnt ||
543        ii == CDP_null_count ||
544        ii == CDP_last_null_count)
545    {
546       read_tag(buf,"value","%lu",
547        &(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rra_index) + ds_index].scratch[ii].u_cnt));
548    } else {
549       read_tag(buf,"value","%lf",&(rrd->cdp_prep[rrd->stat_head->ds_cnt*
550        (rra_index) + ds_index].scratch[ii].u_val));
551    }
552    }
555 void
556 parse_FAILURES_history(char **buf, rrd_t *rrd, int rra_index, int ds_index)
558    char history[MAX_FAILURES_WINDOW_LEN + 1];
559    char *violations_array;
560    short i;
562    /* 28 = MAX_FAILURES_WINDOW_LEN */ 
563    read_tag(buf, "history", "%28[0-1]", history);
564    violations_array = (char*) rrd -> cdp_prep[rrd->stat_head->ds_cnt*(rra_index)
565       + ds_index].scratch;
566    
567    for (i = 0; i < rrd -> rra_def[rra_index].par[RRA_window_len].u_cnt; ++i)
568       violations_array[i] = (history[i] == '1') ? 1 : 0;