function __construct(READER $rdr, LOGGROUP $grp, DATAFilter $filter, &$opts = NULL) { if ($rdr instanceof CACHEReader) { $this->skip = true; } else { $this->skip = false; $this->filters = array(); foreach ($opts['extractors'] as $ext => &$items) { $config =& $opts['config'][$ext]; $filter_class = $config['filter']; ADEI::RequireClass("extractors/{$filter_class}", true); $this->filters[$ext] = array(); foreach ($items as $item => $mask) { $this->filters[$ext][$item] = new $filter_class($mask, $config); } } $this->mappings = $opts['mappings']; $mask = $filter->GetItemMask(); if ($mask && !$mask->IsFull()) { $this->check_masked = true; $this->cur_indexes = array(); $i = 0; foreach ($mask->ids as $id) { $this->cur_indexes[$id] = $i++; } } else { $this->check_masked = false; $this->cur_indexes = range(0, $rdr->GetGroupSize($grp) - 1); } if ($opts['mask'] && !$opts['mask']->IsFull()) { $this->real_indexes = array(); $i = 0; foreach ($opts['mask']->ids as $id) { $this->real_indexes[$id] = $i++; } } else { $this->real_indexes = range(0, $rdr->GetGroupSize($grp) - 1); } $this->remove = sizeof($this->cur_mask) - sizeof($this->real_mask); if ($this->remove < 0) { $this->remove = 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); }
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); }
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); }
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); }
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); }
function __construct(READER $rdr, LOGGROUP $grp, DATAFilter $filter, &$opts = NULL) { if ($rdr instanceof CACHEReader) { $this->skip = true; } else { $this->skip = false; $filter_class = $opts['filter']; if (!(include_once "item/" . strtolower($filter_class) . ".php")) { if (!isset($opts['filter'])) { throw new ADEIException(translate("No item filter is configured")); } else { throw new ADEIException(translate("Unsupported item filter is configured: \"%s\"", $filter_class)); } } $this->filter = new $filter_class($opts); $mask = $filter->GetItemMask(); if ($mask && !$mask->IsFull()) { $this->check_masked = true; } else { $this->check_masked = false; } if (isset($opts['item_mask'])) { $this->indexes = array(); $key = array(); $re = array(); if (is_array($opts['item_mask'])) { if (is_array($opts['item_mask'][0])) { $checks = $opts['item_mask']; } else { $checks = array($opts['item_mask']); } } else { $re = $opts['item_mask']; if ($mask) { $checks = false; $i = 0; foreach ($mask->ids as $id) { if (preg_match($re, $id)) { $this->indexes[$i] = $id; } $i++; } } else { $checks = array(array("key" => id, "items" => $re)); } } if ($checks) { $items = $rdr->GetItemList($grp, $mask ? $mask : new MASK()); $i = 0; foreach ($items as &$item) { $matched = true; foreach ($checks as $check) { if (!preg_match($check['items'], $item[$check['key']])) { $matched = false; break; } } if ($matched) { $this->indexes[$i] = $item["id"]; } $i++; } } } else { if ($mask && !$mask->IsFull()) { $this->indexes = $mask->ids; } else { $this->indexes = range(0, $rdr->GetGroupSize($grp) - 1); } } } }
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); }
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); }
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 } }