Ejemplo n.º 1
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);
 }