Пример #1
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     if ($grp->gid < 0) {
         if (!strcmp($grp->gid, VIRTUALReader::COMPLEX_ID)) {
             throw new ADEIException(translate("Data could not be retrieved from complex groups"));
         } else {
             if (!strcmp($grp->gid, VIRTUALReader::MISSING_ID)) {
                 throw new ADEIException(translate("The source tree is empty, please, select something"));
             } else {
                 if (!strcmp($grp->gid, VIRTUALReader::SRCTREE_ID)) {
                     throw new ADEIException(translate("Data could not be retrieved from source tree"));
                 }
             }
         }
     }
     if ($filter) {
         $mask = $filter->GetItemMask();
         $rate = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
     } else {
         $mask = NULL;
         $rate = false;
         $limit = 0;
     }
     $req = $this->srctree->GetGroupRequest($grp, $mask);
     $rdr = $this->CreateReader($req);
     $group = $rdr->CreateGroup();
     $mask = $rdr->CreateMask();
     $super_filter = $this->CreateDataFilter($group, $mask, $rate, $limit, $filter);
     return $rdr->GetRawData($group, $from, $to, $super_filter, $filter_data);
 }
Пример #2
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     $res = $this->db->Query("SELECT {$this->req_cols} FROM adt WHERE ID=" . $grp->gid);
     $row = $res->fetch();
     if ($row['writable'] > 0) {
         $writable = 1;
     } else {
         $writable = 0;
     }
     if (!$from || !$to) {
         $ivl = $this->CreateInterval($grp);
         $ivl->Limit($from, $to);
         $from = $ivl->GetWindowStart();
         $to = $ivl->GetWindowEnd();
     }
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     if (!$mask || !is_array($ids = $mask->GetIDs())) {
         $ids = array(0, 1);
     }
     $data_request = "";
     if (in_array(0, $ids)) {
         if ($writable) {
             $data_request .= "{$this->db->col_quote}{$this->rw_cols[0]}{$this->db->col_quote}, ";
         } else {
             $data_request .= "{$this->db->col_quote}{$this->ro_cols[0]}{$this->db->col_quote}, ";
         }
     }
     if ($writable && in_array(1, $ids)) {
         $data_request .= "{$this->db->col_quote}{$this->rw_cols[1]}{$this->db->col_quote}, ";
     }
     $data_request .= "time";
     $selopts = array("condition" => "{$this->db->col_quote}time{$this->db->col_quote} BETWEEN " . $this->db->SQLTime($from) . " and " . $this->db->SQLTime($to));
     if ($this->data_cond) {
         $selopts['condition'] .= " AND " . $this->SubstituteGroup($this->data_cond, $grp);
     }
     if ($resample) {
         $selopts['sampling'] = array("slicer" => $this->time_module->GetTimeSlicingFunction("{$this->db->col_quote}time{$this->db->col_quote}", $resample), "selector" => "{$this->db->col_quote}time{$this->db->col_quote}");
     }
     if ($limit) {
         $selopts['limit'] = abs($limit);
         if ($limit > 0) {
             $selopts['order'] = "{$this->db->col_quote}time{$this->db->col_quote} ASC";
         } else {
             $selopts['order'] = "{$this->db->col_quote}time{$this->db->col_quote} DESC";
         }
     } else {
         $selopts['order'] = "{$this->db->col_quote}time{$this->db->col_quote} ASC";
     }
     $table = $this->SubstituteGroup($this->data_table, $grp);
     $query = $this->db->SelectRequest($table, $data_request, $selopts);
     #    echo $query . "\n";
     $stmt = $this->db->Prepare($query);
     return new DATABASEData($this, $stmt, DATABASEData::EMPTY_ON_ERROR);
 }
Пример #3
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     $postfix = $this->cache->GetCachePostfix($grp->gid);
     $ivl = $this->CreateInterval($grp);
     $ivl->Limit($from, $to);
     if ($filter) {
         $limit = $filter->GetVectorsLimit();
         $resample = $filter->GetSamplingRate();
         $mask = $filter->GetItemMask();
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     if (!$mask) {
         $minfo = array("db_mask" => "");
         $mask = $this->cache->CreateCacheMask($postfix, $minfo);
     }
     return $this->cache->GetCachePoints($postfix, $mask, $ivl, CACHEDB::TYPE_ALL, $limit, $resample);
 }
Пример #4
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     $ivl = $this->CreateInterval($grp);
     $ivl->Limit($from, $to);
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if ($limit) {
             $ivl->SetItemLimit($limit);
         }
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     $opts = $this->req->GetGroupOptions($grp);
     $items = $opts->Get('items', $this->items);
     if ($mask && is_array($ids = $mask->GetIDs())) {
         $tmp = array();
         foreach ($ids as $id) {
             if ($id >= sizeof($items)) {
                 throw new ADEIException(translate("Invalid item mask is supplied. The ID:%d refers non-existing item.", $id));
             }
             array_push($tmp, $items[$id]);
         }
         $items = $tmp;
     }
     return new TESTData($this, $this->req->GetGroupOptions($grp), $items, $ivl, $resample);
 }
Пример #5
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     if (!$from || !$to) {
         $ivl = $this->CreateInterval($grp);
         $ivl->Limit($from, $to);
         $from = $ivl->GetWindowStart();
         $to = $ivl->GetWindowEnd();
     }
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     $data_columns = $this->FindColumns($grp, $mask);
     if ($this->emit_delays) {
         log_message("Sleeping");
         usleep($this->emit_delays);
     }
     $selopts = array("condition" => $this->db->col_quote . $this->columns['time'] . "{$this->db->col_quote} BETWEEN " . $this->ImportUnixTime($from) . " and " . $this->ImportUnixTime($to));
     if ($resample) {
         $slicer_col = $this->slicer_column[$grp->gid];
         $selopts['sampling'] = array("slicer" => $this->time_module->GetTimeSlicingFunction("{$slicer_col}", $resample), "selector" => "{$this->db->col_quote}{$this->columns['time']}{$this->db->col_quote}");
     }
     if ($limit) {
         $selopts['limit'] = abs($limit);
         if ($limit > 0) {
             $selopts['order'] = $this->time_sort;
         } else {
             if (!$this->inverse_sort) {
                 throw new ADEIException(translate("The inverse_timesort should be specified in order to select items from the end"));
             }
             $selopts['order'] = $this->inverse_sort;
             if ($limit < -1) {
                 throw new ADEIException(translate("Current version supports only selecting a single item from the end"));
             }
         }
     } else {
         $selopts['order'] = $this->time_sort;
     }
     $query = $this->db->SelectRequest($grp->table, $data_columns, $selopts);
     #    echo $query . "\n";
     $stmt = $this->db->Prepare($query);
     return new DATABASEData($this, $stmt);
 }
Пример #6
0
 function GetRawData(LOGGROUP $grp = NULL, $from = false, $to = false, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     $grp = $this->CheckGroup($grp);
     $ivl = $this->CreateInterval($grp);
     $ivl->Limit($from, $to);
     if ($grp) {
         $groups = array();
         $options = $this->opts;
         # Get Groups
         $groups = $options->Get('groups', false);
         foreach ($groups as $gid => &$group) {
             if ($grp && strcmp($grp->gid, $gid)) {
                 continue;
             }
             $design_view = $groups[$gid]['design_view'];
             $this->view_url = str_replace("%design_view%", $design_view, $this->base_view_url);
         }
     }
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if ($limit) {
             $ivl->SetItemLimit($limit);
         }
         if (isset($filter_data)) {
             #if ($mask) $filter_data['masked'] = true;
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     foreach ($this->itemList as $key => $value) {
         if (strcmp($grp->gid, $key)) {
             continue;
         }
         $itemList = $value;
     }
     $items = array();
     if ($mask && is_array($ids = $mask->GetIDs())) {
         $tmp = array();
         foreach ($ids as $id) {
             if ($id >= sizeof($itemList)) {
                 throw new ADEIException(translate("Invalid item mask is supplied. The ID:%d refers non-existing item.", $id));
             }
             array_push($tmp, $itemList[$id]);
         }
         $items = $tmp;
     }
     return new COUCHData($this->view_url, $this->alldata_view, $this->req->GetGroupOptions($grp), $items, $ivl);
 }
Пример #7
0
 function GetRawAlarms(LOGGROUP $grp = NULL, $from = false, $to = false, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     if ($this->server['driver'] == "mysql" || $this->sqldrv['driver'] == "mysql") {
         // the subrequest should be formulated differently.
         //throw new ADEIException(translate("Alarms are not supported in MySQL version yet"));
     }
     // If interval is not specified we are looking for the alarms in the
     // interval where the data of current group is present
     //The group is optional and not needed in this reader
     /*
         try {
     	$grp = $this->CheckGroup($grp);
         } catch (ADEIException $ae) {
     	$grp = false;
         }
     */
     if (!$from || !$to) {
         if ($grp) {
             $ivl = $this->CreateInterval($grp);
         } else {
             $ivl = new INTERVAL($this->req->props);
         }
         $ivl->Limit($from, $to);
         $from = $ivl->GetWindowStart(false);
         $to = $ivl->GetWindowEnd(false);
     }
     if ($filter) {
         $limit = $filter->GetVectorsLimit();
         $mode = $filter->GetProperty("alarm_list_mode");
         $severity = $filter->GetProperty("alarm_severity");
         $mask = $filter->GetItemMask();
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $limit = 0;
         $mode = 0;
         $severity = 0;
         $mask = NULL;
     }
     $masktest = "";
     if ($mask) {
         $ids = $mask->GetIDs();
         if ($ids) {
             $lastid = array_pop($ids);
             foreach ($ids as $id) {
                 $masktest .= "(messageid = {$id}) OR ";
             }
             $masktest .= "(messageid = {$lastid})";
         }
     }
     switch ($mode) {
         case READER::ALARM_MODE_ACTIVE_LIST:
             $cond = "mtype >= {$severity} AND go = 0";
             if ($masktest) {
                 $cond .= " AND ({$masktest})";
             }
             $columns = array("messageid", "mtype", "name", "cond", "come");
             $selopts = array("condition" => $cond, "order" => "mtype DESC, come DESC");
             $query = $this->db->SelectRequest("messagelog", $columns, $selopts);
             break;
         case READER::ALARM_MODE_FULL_LIST:
             if ($from !== false) {
                 $from = $this->ImportUnixTime($from);
             }
             if ($to !== false) {
                 $to = $this->ImportUnixTime($to);
             }
             if ($from === false && $to === false) {
                 $test = false;
             } else {
                 if ($from === false) {
                     $test = "(come < {$to})";
                 } else {
                     if ($to === false) {
                         $test = "((go = 0) OR (go > {$from}))";
                     } else {
                         $test = "(come BETWEEN {$from} and {$to}) OR ((come < {$from}) AND ((go = 0) OR (go > {$from})))";
                     }
                 }
             }
             if ($test) {
                 $cond = "(mtype >= {$severity}) AND ({$test})";
             } else {
                 $cond = "(mtype >= {$severity})";
             }
             if ($masktest) {
                 $cond .= " AND ({$masktest})";
             }
             $columns = array("messageid", "mtype", "name", "cond", "come", "go");
             $selopts = array("condition" => $cond, "order" => "mtype DESC, come DESC");
             if ($limit) {
                 $selopts['limit'] = abs($limit);
                 if ($limit > 0) {
                     $selopts['order'] = "come ASC";
                 } else {
                     $selopts['order'] = "come DESC";
                 }
             } else {
                 $selopts['order'] = "come ASC";
             }
             $query = $this->db->SelectRequest("messagelog", $columns, $selopts);
             break;
         default:
             if ($from !== false) {
                 $from = $this->ImportUnixTime($from);
             }
             if ($to !== false) {
                 $to = $this->ImportUnixTime($to);
             }
             if ($from === false && $to === false) {
                 $test = false;
             } else {
                 if ($from === false) {
                     $test = "(come < {$to})";
                 } else {
                     if ($to === false) {
                         $test = "((go = 0) OR (go > {$from}))";
                     } else {
                         $test = "(come BETWEEN {$from} and {$to}) OR ((come < {$from}) AND ((go = 0) OR (go > {$from})))";
                     }
                 }
             }
             if ($test) {
                 $cond = "(mtype >= {$severity}) AND ({$test})";
             } else {
                 $cond = "(mtype >= {$severity})";
             }
             if ($masktest) {
                 $cond .= " AND ({$masktest})";
             }
             $columns = "messageid, MAX(mtype) AS mtype, MIN(come) AS come, MAX(go) AS go, COUNT(lid) AS count, MIN(go) AS notactive";
             $selopts = array("condition" => $cond, "group" => "messageid");
             $subquery = $this->db->SelectRequest("messagelog", $columns, $selopts);
             $columns = "result.*, messages.name";
             $selopts = array("condition" => "messages.messageid = result.messageid", "order" => "mtype DESC, come ASC");
             $query = $this->db->SelectRequest("({$subquery}) AS result, messages", $columns, $selopts);
     }
     //    echo $query . "\n\n\n";
     //    exit;
     $stmt = $this->db->Prepare($query);
     return new ZEUSAlarms($this, $stmt);
 }
Пример #8
0
 function GetRawData(LOGGROUP $grp = NULL, $from = 0, $to = 0, DATAFilter $filter = NULL, &$filter_data = NULL)
 {
     //get iterator for raw data of rrd:s archives
     $grp = $this->CheckGroup($grp);
     //checks if the group is valid
     $ivl = $this->CreateInterval($grp);
     //creates a data interval for the group
     if ($filter) {
         $mask = $filter->GetItemMask();
         $resample = $filter->GetSamplingRate();
         $limit = $filter->GetVectorsLimit();
         if ($limit) {
             $ivl->SetItemLimit($limit);
         }
         //if item limit was specified for the filter, then set item limit for interval
         if (isset($filter_data)) {
             if ($mask) {
                 $filter_data['masked'] = true;
             }
             if ($resample) {
                 $filter_data['resampled'] = true;
             }
             if ($limit) {
                 $filter_data['limited'] = true;
             }
         }
     } else {
         $mask = NULL;
         $resample = 0;
         $limit = 0;
     }
     $ivl->Limit($from, $to);
     //set interval timelimit
     $opts = $this->req->GetGroupOptions($grp);
     //get options for group
     $null_mask = new MASK($mreq = array());
     $items = $this::GetItemList($grp, $null_mask);
     //get list of items for current group
     if ($mask && is_array($ids = $mask->GetIDs())) {
         $tmp = array();
         foreach ($ids as $id) {
             if ($id >= sizeof($items)) {
                 throw new ADEIException(translate("Invalid item mask is supplied. The ID:%d refers non-existing item.", $id));
             }
             array_push($tmp, $items[$id]);
             // create a new items array that contains just the items specified by the mask
         }
         $items = $tmp;
     }
     if ($this->munin_datafile) {
         return new MUNINData($this, $opts, $items, $ivl, $resample);
     } else {
         $gid = $grp->gid;
         $info = $this::GetRRDInfo($gid, $this);
         //get rrd info for the current rrd-file
         $step = $info["info"]["step"];
         //get the minimum and maximum interval between two archive datapoints in seconds
         $min_itv = 0;
         $max_itv = 0;
         $max_itv_index = -1;
         foreach ($info["rra"] as $key => $rra) {
             if ($mask) {
                 if (!$mask->Check($key)) {
                     continue;
                 }
             }
             $itv = $info["info"]["step"] * $rra["pdp_per_row"];
             if ($itv > $max_itv) {
                 $max_itv = $itv;
                 $max_itv_index = $key;
             }
             if ($min_itv === 0) {
                 $min_itv = $itv;
             } else {
                 if ($itv < $min_itv) {
                     $min_itv = $itv;
                 }
             }
         }
         //passing a few parameters in options to RRDData
         $opts->options[count($opts->options)]['step'] = $min_itv;
         $opts->options[count($opts->options)]['file'] = $gid;
         $opts->options[count($opts->options)]['data_start'] = time() - $max_itv * $info["rra"][$max_itv_index]["rows"];
         return new RRDData($this, $opts, $items, $ivl, $resample);
         // return raw data
     }
 }