Пример #1
0
 public function buildDataStruct($host = FALSE, $service = FALSE, $view = NULL, $source = NULL)
 {
     if ($host === FALSE && $service === FALSE) {
         return FALSE;
     }
     $conf = $this->config->conf;
     /*
      * Special templates without Host/Service
      */
     if ($host == '__special') {
         // $service contains the template name
         $this->includeTemplate($service, 'special');
     } else {
         if ($this->readXML($host, $service) == FALSE) {
             throw new Kohana_Exception('error.xml-not-found', "Undefined error");
             return false;
         }
         $this->includeTemplate($this->DS[0]['TEMPLATE']);
     }
     if (isset($this->TIMERANGE['type']) && $this->TIMERANGE['type'] == "start-end") {
         $view = intval($view);
         $i = 0;
         foreach ($this->RRD['def'] as $key => $val) {
             if (!is_null($source) && $source != $key) {
                 continue;
             }
             $tmp_struct = array();
             $tmp_struct['LEVEL'] = $i;
             $tmp_struct['VIEW'] = $view;
             $tmp_struct['TEMPLATE_FILE'] = $this->TEMPLATE_FILE;
             $tmp_struct['SOURCE'] = $key;
             $tmp_struct['RRD_CALL'] = $this->TIMERANGE['cmd'] . " " . $this->RRD['opt'][$key] . " " . $this->RRD['def'][$key];
             $tmp_struct['TIMERANGE'] = $this->TIMERANGE;
             $tmp_struct['GRAPH_WIDTH'] = $this->getGraphDimensions('width', $tmp_struct['RRD_CALL']);
             $tmp_struct['GRAPH_HEIGHT'] = $this->getGraphDimensions('height', $tmp_struct['RRD_CALL']);
             if (isset($this->RRD['ds_name'][$key])) {
                 $tmp_struct['ds_name'] = $this->RRD['ds_name'][$key];
             } elseif (array_key_exists($i, $this->DS)) {
                 $tmp_struct['ds_name'] = $this->DS[$i]['NAME'];
             } else {
                 $tmp_struct['ds_name'] = "UNDEF";
             }
             $tmp_struct['MACRO'] = $this->MACRO;
             if (isset($this->XML->XML->VERSION)) {
                 $tmp_struct['VERSION'] = pnp::xml_version_check((string) $this->XML->XML->VERSION);
             } else {
                 $tmp_struct['VERSION'] = pnp::xml_version_check("0");
             }
             $this->addToDataStruct($tmp_struct);
             $i++;
         }
         return;
     }
     if ($view === "") {
         $v = 0;
         foreach ($this->config->views as $view_key => $view_val) {
             $i = 0;
             foreach ($this->RRD['def'] as $key => $val) {
                 if (!is_null($source) && $source != $key) {
                     continue;
                 }
                 $tmp_struct = array();
                 $tmp_struct['LEVEL'] = $i;
                 $tmp_struct['VIEW'] = $view_key;
                 $tmp_struct['TEMPLATE_FILE'] = $this->TEMPLATE_FILE;
                 $tmp_struct['SOURCE'] = $key;
                 $tmp_struct['RRD_CALL'] = $this->TIMERANGE[$v]['cmd'] . " " . $this->RRD['opt'][$key] . " " . $this->RRD['def'][$key];
                 $tmp_struct['GRAPH_WIDTH'] = $this->getGraphDimensions('width', $tmp_struct['RRD_CALL']);
                 $tmp_struct['GRAPH_HEIGHT'] = $this->getGraphDimensions('height', $tmp_struct['RRD_CALL']);
                 if (isset($this->RRD['ds_name'][$key])) {
                     $tmp_struct['ds_name'] = $this->RRD['ds_name'][$key];
                 } elseif (array_key_exists($i, $this->DS)) {
                     $tmp_struct['ds_name'] = $this->DS[$i]['NAME'];
                 } else {
                     $tmp_struct['ds_name'] = "UNDEF";
                 }
                 $tmp_struct['TIMERANGE'] = $this->TIMERANGE[$v];
                 $tmp_struct['MACRO'] = $this->MACRO;
                 if (isset($this->XML->XML->VERSION)) {
                     $tmp_struct['VERSION'] = pnp::xml_version_check((string) $this->XML->XML->VERSION);
                 } else {
                     $tmp_struct['VERSION'] = pnp::xml_version_check("0");
                 }
                 $this->addToDataStruct($tmp_struct);
                 $i++;
             }
             $v++;
         }
     } else {
         $view = intval($view);
         $i = 0;
         foreach ($this->RRD['def'] as $key => $val) {
             if (!is_null($source) && $source != $key) {
                 continue;
             }
             $tmp_struct = array();
             $tmp_struct['LEVEL'] = $i;
             $tmp_struct['VIEW'] = $view;
             $tmp_struct['TEMPLATE_FILE'] = $this->TEMPLATE_FILE;
             $tmp_struct['SOURCE'] = $key;
             $tmp_struct['RRD_CALL'] = $this->TIMERANGE[$view]['cmd'] . " " . $this->RRD['opt'][$key] . " " . $this->RRD['def'][$key];
             $tmp_struct['TIMERANGE'] = $this->TIMERANGE[$view];
             $tmp_struct['GRAPH_WIDTH'] = $this->getGraphDimensions('width', $tmp_struct['RRD_CALL']);
             $tmp_struct['GRAPH_HEIGHT'] = $this->getGraphDimensions('height', $tmp_struct['RRD_CALL']);
             if (isset($this->RRD['ds_name'][$key])) {
                 $tmp_struct['ds_name'] = $this->RRD['ds_name'][$key];
             } elseif (array_key_exists($i, $this->DS)) {
                 $tmp_struct['ds_name'] = $this->DS[$i]['NAME'];
             } else {
                 $tmp_struct['ds_name'] = "UNDEF";
             }
             $tmp_struct['MACRO'] = $this->MACRO;
             if (isset($this->XML->XML->VERSION)) {
                 $tmp_struct['VERSION'] = pnp::xml_version_check((string) $this->XML->XML->VERSION);
             } else {
                 $tmp_struct['VERSION'] = pnp::xml_version_check("0");
             }
             $this->addToDataStruct($tmp_struct);
             $i++;
         }
     }
 }