- }
- read_tag(&ptr,"lastupdate","%lu",&(rrd->live_head->last_up));
-
- /* Data Source Definition Part */
- ptr2 = ptr;
- while (eat_tag(&ptr2,"ds") == 1){
- rrd->stat_head->ds_cnt++;
- if((rrd->ds_def = rrd_realloc(rrd->ds_def,rrd->stat_head->ds_cnt*sizeof(ds_def_t)))==NULL){
- rrd_set_error("allocating rrd.ds_def");
- return -1;
- };
- /* clean out memory to make sure no data gets stored from previous tasks */
- memset(&(rrd->ds_def[rrd->stat_head->ds_cnt-1]), 0, sizeof(ds_def_t));
- if((rrd->pdp_prep = rrd_realloc(rrd->pdp_prep,rrd->stat_head->ds_cnt
- *sizeof(pdp_prep_t)))==NULL){
- rrd_set_error("allocating pdp_prep");
- return(-1);
- }
- /* clean out memory to make sure no data gets stored from previous tasks */
- memset(&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1]), 0, sizeof(pdp_prep_t));
-
- read_tag(&ptr2,"name",DS_NAM_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].ds_nam);
-
- read_tag(&ptr2,"type",DST_FMT,rrd->ds_def[rrd->stat_head->ds_cnt-1].dst);
- /* test for valid type */
- if(dst_conv(rrd->ds_def[rrd->stat_head->ds_cnt-1].dst) == -1) return -1;
-
- read_tag(&ptr2,"minimal_heartbeat","%lu",
- &(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_mrhb_cnt].u_cnt));
- read_tag(&ptr2,"min","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_min_val].u_val));
- read_tag(&ptr2,"max","%lf",&(rrd->ds_def[rrd->stat_head->ds_cnt-1].par[DS_max_val].u_val));
-
- read_tag(&ptr2,"last_ds","%30s",rrd->pdp_prep[rrd->stat_head->ds_cnt-1].last_ds);
- read_tag(&ptr2,"value","%lf",&(rrd->pdp_prep[rrd->stat_head->ds_cnt-1].scratch[PDP_val].u_val));
- read_tag(&ptr2,"unknown_sec","%lu",&(rrd->pdp_prep[i].scratch[PDP_unkn_sec_cnt].u_cnt));
- eat_tag(&ptr2,"/ds");
- ptr=ptr2;
- }
-
- ptr2 = ptr;
- while (eat_tag(&ptr2,"rra") == 1){
- rrd->stat_head->rra_cnt++;
-
- /* alocate and reset rra definition areas */
- if((rrd->rra_def = rrd_realloc(rrd->rra_def,rrd->stat_head->rra_cnt*sizeof(rra_def_t)))==NULL){
- rrd_set_error("allocating rra_def"); return -1; }
- memset(&(rrd->rra_def[rrd->stat_head->rra_cnt-1]), 0, sizeof(rra_def_t));
-
- /* alocate and reset consolidation point areas */
- if((rrd->cdp_prep = rrd_realloc(rrd->cdp_prep,
- rrd->stat_head->rra_cnt
- *rrd->stat_head->ds_cnt*sizeof(cdp_prep_t)))==NULL){
- rrd_set_error("allocating cdp_prep"); return -1; }
-
- memset(&(rrd->cdp_prep[rrd->stat_head->ds_cnt*(rrd->stat_head->rra_cnt-1)]),
- 0, rrd->stat_head->ds_cnt*sizeof(cdp_prep_t));
-
-
- read_tag(&ptr2,"cf",CF_NAM_FMT,rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam);
- /* test for valid type */
- if(cf_conv(rrd->rra_def[rrd->stat_head->rra_cnt-1].cf_nam) == -1) return -1;
-
- read_tag(&ptr2,"pdp_per_row","%lu",&(rrd->rra_def[rrd->stat_head->rra_cnt-1].pdp_cnt));
- read_tag(&ptr2,"xff","%lf",&(rrd->rra_def[rrd->stat_head->rra_cnt-1].par[RRA_cdp_xff_val].u_val));
- if(rrd->rra_def[rrd->stat_head->rra_cnt-1].par[RRA_cdp_xff_val].u_val > 1 ||
- rrd->rra_def[rrd->stat_head->rra_cnt-1].par[RRA_cdp_xff_val].u_val < 0)
- return -1;
-
- eat_tag(&ptr2,"cdp_prep");
- for(i=0;i<rrd->stat_head->ds_cnt;i++){
- eat_tag(&ptr2,"ds");
- read_tag(&ptr2,"value","%lf",&(rrd->cdp_prep[rrd->stat_head->ds_cnt*
- (rrd->stat_head->rra_cnt-1)
- +i].scratch[CDP_val].u_val));
- read_tag(&ptr2,"unknown_datapoints","%lu",&(rrd->cdp_prep[rrd->stat_head->ds_cnt
- *(rrd->stat_head->rra_cnt-1)
- +i].scratch[CDP_unkn_pdp_cnt].u_cnt));
- eat_tag(&ptr2,"/ds");
- }
- eat_tag(&ptr2,"/cdp_prep");
- rrd->rra_def[rrd->stat_head->rra_cnt-1].row_cnt=0;
- eat_tag(&ptr2,"database");
- ptr3 = ptr2;
- while (eat_tag(&ptr3,"row") == 1){
-
- if(mempool==0){
- mempool = 1000;
- if((rrd->rrd_value = rrd_realloc(rrd->rrd_value,
- (rows+mempool)*(rrd->stat_head->ds_cnt)
- *sizeof(rrd_value_t)))==NULL) {
- rrd_set_error("allocating rrd_values"); return -1; }
- }
- rows++;
- mempool--;
- rrd->rra_def[rrd->stat_head->rra_cnt-1].row_cnt++;
- for(i=0;i<rrd->stat_head->ds_cnt;i++){
-
- rrd_value_t * value = &(rrd->rrd_value[(rows-1)*rrd->stat_head->ds_cnt+i]);
-
- read_tag(&ptr3,"v","%lf", value);
-
- if (
- (rc == 1) /* do we have to check for the ranges */
- &&
- (!isnan(*value)) /* not a NAN value */
- &&
- ( /* min defined and in the range ? */
- (!isnan(rrd->ds_def[i].par[DS_min_val].u_val)
- && (*value < rrd->ds_def[i].par[DS_min_val].u_val))
- || /* max defined and in the range ? */
- (!isnan(rrd->ds_def[i].par[DS_max_val].u_val)
- && (*value > rrd->ds_def[i].par[DS_max_val].u_val))
- )
- ) {
- fprintf (stderr, "out of range found [ds: %lu], [value : %0.10e]\n", i, *value);
- *value = DNAN;
- }
- }
- eat_tag(&ptr3,"/row");
- ptr2=ptr3;
- }
- eat_tag(&ptr2,"/database");
- eat_tag(&ptr2,"/rra");
- ptr=ptr2;
- }
- eat_tag(&ptr,"/rrd");
-
- if((rrd->rra_ptr = calloc(1,sizeof(rra_ptr_t)*rrd->stat_head->rra_cnt)) == NULL) {
- rrd_set_error("allocating rra_ptr");
- return(-1);
- }
-
- for(i=0; i <rrd->stat_head->rra_cnt; i++) {
- rrd->rra_ptr[i].cur_row = rrd->rra_def[i].row_cnt-1;
- }
- if (ptr==NULL)
- return -1;
- return 1;
-}
-
+} /* int parse_tag_rra_cdp_prep_ds_history */
+
+static int parse_tag_rra_cdp_prep_ds(
+ xmlTextReaderPtr reader,
+ rrd_t *rrd,
+ cdp_prep_t *cdp_prep)
+{
+ int status;
+ xmlChar *element;
+ memset(cdp_prep, '\0', sizeof(cdp_prep_t));
+
+ status = -1;
+
+ if (atoi(rrd->stat_head->version) == 1) {
+ cdp_prep->scratch[CDP_primary_val].u_val = 0.0;
+ cdp_prep->scratch[CDP_secondary_val].u_val = 0.0;
+ }
+
+ while ((element = get_xml_element(reader)) != NULL){
+ if (xmlStrcasecmp(element, (const xmlChar *) "primary_value") == 0)
+ status =
+ get_xml_double(reader,&cdp_prep->scratch[CDP_primary_val].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "secondary_value") == 0)
+ status =
+ get_xml_double(reader,&cdp_prep->scratch[CDP_secondary_val].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "intercept") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->
+ scratch[CDP_hw_intercept].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "last_intercept") ==
+ 0)
+ status =
+ get_xml_double(reader,
+ &cdp_prep->
+ scratch[CDP_hw_last_intercept].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "slope") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->scratch[CDP_hw_slope].
+ u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "last_slope") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->
+ scratch[CDP_hw_last_slope].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "nan_count") == 0)
+ status = get_xml_ulong(reader,
+ &cdp_prep->
+ scratch[CDP_null_count].u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "last_nan_count") ==
+ 0)
+ status =
+ get_xml_ulong(reader,
+ &cdp_prep->
+ scratch[CDP_last_null_count].u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "seasonal") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->scratch[CDP_hw_seasonal].
+ u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "last_seasonal") ==
+ 0)
+ status =
+ get_xml_double(reader,
+ &cdp_prep->scratch[CDP_hw_last_seasonal].
+ u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "init_flag") == 0)
+ status = get_xml_ulong(reader,
+ &cdp_prep->
+ scratch[CDP_init_seasonal].u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "history") == 0)
+ status = parse_tag_rra_cdp_prep_ds_history(reader, cdp_prep);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "value") == 0)
+ status = get_xml_double(reader,
+ &cdp_prep->scratch[CDP_val].u_val);
+ else if (xmlStrcasecmp(element,
+ (const xmlChar *) "unknown_datapoints") == 0)
+ status = get_xml_ulong(reader,
+ &cdp_prep->
+ scratch[CDP_unkn_pdp_cnt].u_cnt);
+ else if (xmlStrcasecmp(element,
+ (const xmlChar *) "/ds") == 0){
+ xmlFree(element);
+ break;
+ }
+ else {
+ rrd_set_error("parse_tag_rra_cdp_prep: Unknown tag: %s",
+ element);
+ status = -1;
+ xmlFree(element);
+ break;
+ }
+ if (status != 0){
+ xmlFree(element);
+ break;
+ }
+ status = expect_element_end(reader,(char *)element);
+ xmlFree(element);
+ if (status != 0)
+ break;
+ }
+ return (status);
+} /* int parse_tag_rra_cdp_prep_ds */
+
+static int parse_tag_rra_cdp_prep(
+ xmlTextReaderPtr reader,
+ rrd_t *rrd,
+ cdp_prep_t *cdp_prep)
+{
+ int status;
+
+ unsigned int ds_count;
+
+ status = 0;
+ for ( ds_count = 0; ds_count < rrd->stat_head->ds_cnt;ds_count++){
+ if (expect_element(reader,"ds") == 0) {
+ status = parse_tag_rra_cdp_prep_ds(reader, rrd,
+ cdp_prep + ds_count);
+ if (status != 0)
+ break;
+ } else {
+ status = -1;
+ break;
+ }
+ }
+ if (status == 0)
+ status = expect_element(reader,"/cdp_prep");
+ return (status);
+} /* int parse_tag_rra_cdp_prep */
+
+/*
+ * Parse the <params> block within an RRA definition
+ */
+static int parse_tag_rra_params(
+ xmlTextReaderPtr reader,
+ rra_def_t *rra_def)
+{
+ xmlChar *element;
+ int status;
+
+ status = -1;
+ while ((element = get_xml_element(reader)) != NULL){
+ /*
+ * Parameters for CF_HWPREDICT
+ */
+ if (xmlStrcasecmp(element, (const xmlChar *) "hw_alpha") == 0)
+ status = get_xml_double(reader,
+ &rra_def->par[RRA_hw_alpha].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "hw_beta") == 0)
+ status = get_xml_double(reader,
+ &rra_def->par[RRA_hw_beta].u_val);
+ else if (xmlStrcasecmp(element,
+ (const xmlChar *) "dependent_rra_idx") == 0)
+ status = get_xml_ulong(reader,
+ &rra_def->
+ par[RRA_dependent_rra_idx].u_cnt);
+ /*
+ * Parameters for CF_SEASONAL and CF_DEVSEASONAL
+ */
+ else if (xmlStrcasecmp(element, (const xmlChar *) "seasonal_gamma") ==
+ 0)
+ status =
+ get_xml_double(reader,
+ &rra_def->par[RRA_seasonal_gamma].u_val);
+ else if (xmlStrcasecmp
+ (element, (const xmlChar *) "seasonal_smooth_idx") == 0)
+ status =
+ get_xml_ulong(reader,
+ &rra_def->
+ par[RRA_seasonal_smooth_idx].u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "smoothing_window")
+ == 0)
+ status =
+ get_xml_double(reader,
+ &rra_def->
+ par[RRA_seasonal_smoothing_window].
+ u_val);
+ /* else if (dependent_rra_idx) ...; */
+ /*
+ * Parameters for CF_FAILURES
+ */
+ else if (xmlStrcasecmp(element, (const xmlChar *) "delta_pos") == 0)
+ status = get_xml_double(reader,
+ &rra_def->par[RRA_delta_pos].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "delta_neg") == 0)
+ status = get_xml_double(reader,
+ &rra_def->par[RRA_delta_neg].u_val);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "window_len") == 0)
+ status = get_xml_ulong(reader,
+ &rra_def->par[RRA_window_len].
+ u_cnt);
+ else if (xmlStrcasecmp(element, (const xmlChar *) "failure_threshold")
+ == 0)
+ status =
+ get_xml_ulong(reader,
+ &rra_def->
+ par[RRA_failure_threshold].u_cnt);
+ /*
+ * Parameters for CF_AVERAGE, CF_MAXIMUM, CF_MINIMUM, and CF_LAST
+ */
+ else if (xmlStrcasecmp(element, (const xmlChar *) "xff") == 0)
+ status = get_xml_double(reader,
+ &rra_def->par[RRA_cdp_xff_val].
+ u_val);
+ /*
+ * Compatibility code for 1.0.49
+ */
+ else if (xmlStrcasecmp(element, (const xmlChar *) "value") == 0) { /* {{{ */
+ unsigned int i = 0;
+
+ for (i=0;i<ARRAY_LENGTH(rra_def->par);i++){
+ if ((i == RRA_dependent_rra_idx)
+ || (i == RRA_seasonal_smooth_idx)
+ || (i == RRA_failure_threshold))
+ status = get_xml_ulong(reader,
+ &rra_def->par[i].
+ u_cnt);
+ else
+ status = get_xml_double(reader,
+ &rra_def->par[i].u_val);
+
+ if (status != 0)
+ break;
+ if ( i-1 < ARRAY_LENGTH(rra_def->par)){
+ status = expect_element(reader,"/value");
+ if (status == 0){
+ status = expect_element(reader,"value");
+ }
+ }
+ if (status != 0){
+ break;
+ }
+ }
+ } /* }}} */
+ else if (xmlStrcasecmp(element,(const xmlChar *) "/params") == 0){
+ xmlFree(element);
+ return status;
+ } /* }}} */
+ else {
+ rrd_set_error("line %d: parse_tag_rra_params: Unknown tag: %s",
+ xmlTextReaderGetParserLineNumber(reader),element);
+ status = -1;
+ }
+ status = expect_element_end(reader,(char *)element);
+ xmlFree(element);
+ if (status != 0)
+ break;
+ }
+ return (status);
+} /* int parse_tag_rra_params */
+
+/*
+ * Parse an RRA definition
+ */
+static int parse_tag_rra_cf(
+ xmlTextReaderPtr reader,
+ rra_def_t *rra_def)
+{
+ int status;
+
+ status = get_xml_string(reader,
+ rra_def->cf_nam, sizeof(rra_def->cf_nam));
+ if (status != 0)
+ return status;
+
+ status = cf_conv(rra_def->cf_nam);
+ if (status == -1) {
+ rrd_set_error("parse_tag_rra_cf: Unknown consolidation function: %s",
+ rra_def->cf_nam);
+ return -1;
+ }
+
+ return 0;
+} /* int parse_tag_rra_cf */
+
+static int parse_tag_rra(
+ xmlTextReaderPtr reader,
+ rrd_t *rrd)
+{
+ int status;
+ xmlChar *element;