Beispiel #1
0
// OTHER ITEMS (which doesn't linked to application)
$db_hosts = array();
$db_hostids = array();
$sql = 'SELECT DISTINCT h.host,h.hostid ' . ' FROM hosts h' . $sql_from . ', items i ' . ' LEFT JOIN items_applications ia ON ia.itemid=i.itemid' . ' WHERE ia.itemid is NULL ' . $sql_where . ' AND h.hostid=i.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' ORDER BY h.host';
$db_host_res = DBselect($sql);
while ($db_host = DBfetch($db_host_res)) {
    $db_host['item_cnt'] = 0;
    $db_hosts[$db_host['hostid']] = $db_host;
    $db_hostids[$db_host['hostid']] = $db_host['hostid'];
}
$tab_rows = array();
$sql = 'SELECT DISTINCT h.host,h.hostid,i.* ' . ' FROM hosts h' . $sql_from . ', items i ' . ' LEFT JOIN items_applications ia ON ia.itemid=i.itemid' . ' WHERE ia.itemid is NULL ' . $sql_where . ' AND h.hostid=i.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . DBcondition('h.hostid', $db_hostids) . ' ORDER BY i.description,i.itemid';
$db_items = DBselect($sql);
while ($db_item = DBfetch($db_items)) {
    $description = item_description($db_item);
    if (!empty($_REQUEST['select']) && !zbx_stristr($description, $_REQUEST['select'])) {
        continue;
    }
    $db_host =& $db_hosts[$db_item['hostid']];
    if (!isset($tab_rows[$db_host['hostid']])) {
        $tab_rows[$db_host['hostid']] = array();
    }
    $app_rows =& $tab_rows[$db_host['hostid']];
    $db_host['item_cnt']++;
    if (!uint_in_array(0, $_REQUEST['applications']) && !isset($show_all_apps)) {
        continue;
    }
    if (isset($db_item['lastclock'])) {
        $lastclock = zbx_date2str(S_DATE_FORMAT_YMDHMS, $db_item['lastclock']);
    } else {
        $lastclock = new CCol(' - ');
Beispiel #2
0
function make_latest_data()
{
    global $USER_DETAILS;
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
    while ($db_app = DBfetch($db_applications)) {
        $db_items = DBselect('SELECT DISTINCT i.* ' . ' FROM items i,items_applications ia' . ' WHERE ia.applicationid=' . $db_app['applicationid'] . ' AND i.itemid=ia.itemid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . order_by('i.description,i.itemid,i.lastclock'));
        $app_rows = array();
        $item_cnt = 0;
        while ($db_item = DBfetch($db_items)) {
            $description = item_description($db_item);
            if (!zbx_empty($_REQUEST['select']) && !zbx_stristr($description, $_REQUEST['select'])) {
                continue;
            }
            ++$item_cnt;
            if (!uint_in_array($db_app['applicationid'], $_REQUEST['applications']) && !isset($show_all_apps)) {
                continue;
            }
            if (isset($db_item['lastclock'])) {
                $lastclock = date(S_DATE_FORMAT_YMDHMS, $db_item['lastclock']);
            } else {
                $lastclock = new CCol('-', 'center');
            }
            $lastvalue = format_lastvalue($db_item);
            if (isset($db_item['lastvalue']) && isset($db_item['prevvalue']) && $db_item['value_type'] == 0 && $db_item['lastvalue'] - $db_item['prevvalue'] != 0) {
                if ($db_item['lastvalue'] - $db_item['prevvalue'] < 0) {
                    $change = convert_units($db_item['lastvalue'] - $db_item['prevvalue'], $db_item['units']);
                } else {
                    $change = '+' . convert_units($db_item['lastvalue'] - $db_item['prevvalue'], $db_item['units']);
                }
                $change = nbsp($change);
            } else {
                $change = new CCol('-', 'center');
            }
            if ($db_item['value_type'] == ITEM_VALUE_TYPE_FLOAT || $db_item['value_type'] == ITEM_VALUE_TYPE_UINT64) {
                $actions = new CLink(S_GRAPH, 'history.php?action=showgraph&itemid=' . $db_item['itemid'], 'action');
            } else {
                $actions = new CLink(S_HISTORY, 'history.php?action=showvalues&period=3600&itemid=' . $db_item['itemid'], 'action');
            }
            array_push($app_rows, new CRow(array(is_show_all_nodes() ? SPACE : null, $_REQUEST['hostid'] > 0 ? NULL : SPACE, str_repeat(SPACE, 6) . $description, $lastclock, new CCol($lastvalue, $lastvalue == '-' ? 'center' : null), $change, $actions)));
        }
        if ($item_cnt > 0) {
            if (uint_in_array($db_app['applicationid'], $_REQUEST['applications']) || isset($show_all_apps)) {
                $link = new CLink(new CImg('images/general/opened.gif'), '?close=1&applicationid=' . $db_app['applicationid'] . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select'));
            } else {
                $link = new CLink(new CImg('images/general/closed.gif'), '?open=1&applicationid=' . $db_app['applicationid'] . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select'));
            }
            $col = new CCol(array($link, SPACE, bold($db_app['name']), SPACE . '(' . $item_cnt . SPACE . S_ITEMS . ')'));
            $col->setColSpan(5);
            $table->ShowRow(array(get_node_name_by_elid($db_app['hostid']), $_REQUEST['hostid'] > 0 ? NULL : $db_app['host'], $col));
            $any_app_exist = true;
            foreach ($app_rows as $row) {
                $table->ShowRow($row);
            }
        }
    }
}
Beispiel #3
0
        if (EVENTS_NOFALSEFORB_STATUS_FALSE == $show_events_status && $row_event['value'] != TRIGGER_VALUE_FALSE) {
            continue;
        }
        if (EVENTS_NOFALSEFORB_STATUS_TRUE == $show_events_status && $row_event['value'] != TRIGGER_VALUE_TRUE) {
            continue;
        }
        if ($row_event['value'] == TRIGGER_VALUE_FALSE && !event_initial_time($row_event)) {
            continue;
        }
    }
    $triggers[$row_event['triggerid']]['events'][$row_event['eventid']] = $row_event;
}
foreach ($triggers as $triggerid => $row) {
    $elements = array();
    $description = expand_trigger_description($row['triggerid']);
    if (!zbx_empty($_REQUEST['txt_select']) && (bool) zbx_stristr($description, $_REQUEST['txt_select']) == (bool) $_REQUEST['inverse_select']) {
        continue;
    }
    if (!zbx_empty($row['url'])) {
        $description = new CLink($description, $row['url'], null, null, true);
    }
    if ($_REQUEST['show_details']) {
        $font = new CTag('font', 'yes');
        $font->setAttribute('color', '#000');
        $font->setAttribute('size', '-2');
        $font->addItem(explode_exp($row['expression'], 1));
        $description = array($description, BR(), $font);
    }
    // dependency
    $dependency = false;
    $dep_table = new CTableInfo();
Beispiel #4
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $output = array();
     $stime = zbxDateToTime($this->timeline['stime']);
     $iv_string = array(ITEM_VALUE_TYPE_LOG => 1, ITEM_VALUE_TYPE_TEXT => 1);
     $iv_numeric = array(ITEM_VALUE_TYPE_FLOAT => 1, ITEM_VALUE_TYPE_UINT64 => 1);
     if ($this->action == 'showvalues' || $this->action == 'showlatest') {
         $options = array('history' => $this->item['value_type'], 'itemids' => array_keys($this->items), 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN);
         if ($this->action == 'showlatest') {
             $options['limit'] = 500;
         } elseif ($this->action == 'showvalues') {
             $config = select_config();
             $options['time_from'] = $stime - 10;
             // some seconds to allow script to execute
             $options['time_till'] = $stime + $this->timeline['period'];
             $options['limit'] = $config['search_limit'];
         }
         // text log
         if (isset($iv_string[$this->item['value_type']])) {
             $isManyItems = count($this->items) > 1;
             $useLogItem = $this->item['value_type'] == ITEM_VALUE_TYPE_LOG;
             $useEventLogItem = strpos($this->item['key_'], 'eventlog[') === 0;
             if (empty($this->plaintext)) {
                 $historyTable = new CTableInfo(_('No values found.'));
                 $historyTable->setHeader(array(_('Timestamp'), $isManyItems ? _('Item') : null, $useLogItem ? _('Local time') : null, $useEventLogItem && $useLogItem ? _('Source') : null, $useEventLogItem && $useLogItem ? _('Severity') : null, $useEventLogItem && $useLogItem ? _('Event ID') : null, _('Value')), 'header');
             }
             if (!zbx_empty($this->filter) && in_array($this->filterTask, array(FILTER_TASK_SHOW, FILTER_TASK_HIDE))) {
                 $options['search'] = array('value' => $this->filter);
                 if ($this->filterTask == FILTER_TASK_HIDE) {
                     $options['excludeSearch'] = 1;
                 }
             }
             $options['sortfield'] = 'id';
             $historyData = API::History()->get($options);
             foreach ($historyData as $data) {
                 $data['value'] = encode_log(trim($data['value'], "\r\n"));
                 if (empty($this->plaintext)) {
                     $item = $this->items[$data['itemid']];
                     $host = reset($item['hosts']);
                     $color = null;
                     if (isset($this->filter) && !zbx_empty($this->filter)) {
                         $contain = zbx_stristr($data['value'], $this->filter);
                         if ($contain && $this->filterTask == FILTER_TASK_MARK) {
                             $color = $this->markColor;
                         }
                         if (!$contain && $this->filterTask == FILTER_TASK_INVERT_MARK) {
                             $color = $this->markColor;
                         }
                         switch ($color) {
                             case MARK_COLOR_RED:
                                 $color = 'red';
                                 break;
                             case MARK_COLOR_GREEN:
                                 $color = 'green';
                                 break;
                             case MARK_COLOR_BLUE:
                                 $color = 'blue';
                                 break;
                         }
                     }
                     $row = array(nbsp(zbx_date2str(_('Y.M.d H:i:s'), $data['clock'])));
                     if ($isManyItems) {
                         $row[] = $host['name'] . NAME_DELIMITER . $item['name_expanded'];
                     }
                     if ($useLogItem) {
                         $row[] = $data['timestamp'] == 0 ? '-' : zbx_date2str(HISTORY_LOG_LOCALTIME_DATE_FORMAT, $data['timestamp']);
                         // if this is a eventLog item, showing additional info
                         if ($useEventLogItem) {
                             $row[] = zbx_empty($data['source']) ? '-' : $data['source'];
                             $row[] = $data['severity'] == 0 ? '-' : new CCol(get_item_logtype_description($data['severity']), get_item_logtype_style($data['severity']));
                             $row[] = $data['logeventid'] == 0 ? '-' : $data['logeventid'];
                         }
                     }
                     $row[] = new CCol($data['value'], 'pre');
                     $newRow = new CRow($row);
                     if (!is_null($color)) {
                         $newRow->setAttribute('class', $color);
                     }
                     $historyTable->addRow($newRow);
                 } else {
                     $output[] = zbx_date2str(HISTORY_LOG_ITEM_PLAINTEXT, $data['clock']);
                     $output[] = "\t" . $data['clock'] . "\t" . htmlspecialchars($data['value']) . "\n";
                 }
             }
             if (empty($this->plaintext)) {
                 $output[] = $historyTable;
             }
         } else {
             if (empty($this->plaintext)) {
                 $historyTable = new CTableInfo(_('No values found.'));
                 $historyTable->setHeader(array(_('Timestamp'), _('Value')));
             }
             $options['sortfield'] = array('itemid', 'clock');
             $historyData = API::History()->get($options);
             foreach ($historyData as $data) {
                 $item = $this->items[$data['itemid']];
                 $value = $data['value'];
                 // format the value as float
                 if ($item['value_type'] == ITEM_VALUE_TYPE_FLOAT) {
                     sscanf($data['value'], '%f', $value);
                 }
                 // html table
                 if (empty($this->plaintext)) {
                     if ($item['valuemapid']) {
                         $value = applyValueMap($value, $item['valuemapid']);
                     }
                     $historyTable->addRow(array(zbx_date2str(HISTORY_ITEM_DATE_FORMAT, $data['clock']), zbx_nl2br($value)));
                 } else {
                     $output[] = zbx_date2str(HISTORY_PLAINTEXT_DATE_FORMAT, $data['clock']);
                     $output[] = "\t" . $data['clock'] . "\t" . htmlspecialchars($value) . "\n";
                 }
             }
             if (empty($this->plaintext)) {
                 $output[] = $historyTable;
             }
         }
     }
     if ($this->action == 'showgraph' && !isset($iv_string[$this->item['value_type']])) {
         $this->dataId = 'historyGraph';
         $containerId = 'graph_cont1';
         $src = 'chart.php?itemid=' . $this->item['itemid'] . '&period=' . $this->timeline['period'] . '&stime=' . $this->timeline['stime'] . $this->getProfileUrlParams();
         $output[] = new CDiv(null, 'center', $containerId);
     }
     // time control
     if (!$this->plaintext && str_in_array($this->action, array('showvalues', 'showgraph'))) {
         $graphDims = getGraphDims();
         $this->timeline['starttime'] = date(TIMESTAMP_FORMAT, get_min_itemclock_by_itemid($this->item['itemid']));
         $timeControlData = array('periodFixed' => CProfile::get('web.history.timelinefixed', 1), 'sliderMaximumTimePeriod' => ZBX_MAX_PERIOD);
         if (!empty($this->dataId)) {
             $timeControlData['id'] = $this->getDataId();
             $timeControlData['containerid'] = $containerId;
             $timeControlData['src'] = $src;
             $timeControlData['objDims'] = $graphDims;
             $timeControlData['loadSBox'] = 1;
             $timeControlData['loadImage'] = 1;
             $timeControlData['dynamic'] = 1;
         } else {
             $this->dataId = 'historyGraph';
             $timeControlData['id'] = $this->getDataId();
             $timeControlData['mainObject'] = 1;
         }
         if ($this->mode == SCREEN_MODE_JS) {
             $timeControlData['dynamic'] = 0;
             return 'timeControl.addObject("' . $this->getDataId() . '", ' . zbx_jsvalue($this->timeline) . ', ' . zbx_jsvalue($timeControlData) . ');';
         } else {
             zbx_add_post_js('timeControl.addObject("' . $this->getDataId() . '", ' . zbx_jsvalue($this->timeline) . ', ' . zbx_jsvalue($timeControlData) . ');');
         }
     }
     if (!empty($this->plaintext)) {
         return $output;
     } else {
         if ($this->mode != SCREEN_MODE_JS) {
             $flickerfreeData = array('itemids' => $this->itemids, 'action' => $this->action, 'filter' => $this->filter, 'filterTask' => $this->filterTask, 'markColor' => $this->markColor);
             return $this->getOutput($output, true, $flickerfreeData);
         }
     }
 }
 /**
  * Matches expression as string.
  *
  * @static
  *
  * @param array $expression
  * @param string $string
  *
  * @return bool
  */
 private static function _matchString(array $expression, $string)
 {
     $result = true;
     if ($expression['expression_type'] == EXPRESSION_TYPE_ANY_INCLUDED) {
         $paterns = explode($expression['exp_delimiter'], $expression['expression']);
     } else {
         $paterns = array($expression['expression']);
     }
     $expectedResult = $expression['expression_type'] != EXPRESSION_TYPE_NOT_INCLUDED;
     if ($expression['case_sensitive']) {
         foreach ($paterns as $patern) {
             $result = $result && (zbx_strstr($string, $patern) !== false) == $expectedResult;
         }
     } else {
         foreach ($paterns as $patern) {
             $result = $result && (zbx_stristr($string, $patern) !== false) == $expectedResult;
         }
     }
     return $result;
 }
Beispiel #6
0
function get_regexp_form()
{
    $frm_title = S_REGULAR_EXPRESSION;
    if (isset($_REQUEST['regexpid']) && !isset($_REQUEST["form_refresh"])) {
        $sql = 'SELECT re.* ' . ' FROM regexps re ' . ' WHERE ' . DBin_node('re.regexpid') . ' AND re.regexpid=' . $_REQUEST['regexpid'];
        $regexp = DBfetch(DBSelect($sql));
        $frm_title .= ' [' . $regexp['name'] . ']';
        $rename = $regexp['name'];
        $test_string = $regexp['test_string'];
        $expressions = array();
        $sql = 'SELECT e.* ' . ' FROM expressions e ' . ' WHERE ' . DBin_node('e.expressionid') . ' AND e.regexpid=' . $regexp['regexpid'] . ' ORDER BY e.expression_type';
        $db_exps = DBselect($sql);
        while ($exp = DBfetch($db_exps)) {
            $expressions[] = $exp;
        }
    } else {
        $rename = get_request('rename', '');
        $test_string = get_request('test_string', '');
        $expressions = get_request('expressions', array());
    }
    $tblRE = new CTable('', 'nowrap');
    $tblRE->addStyle('border-left: 1px #AAA solid; border-right: 1px #AAA solid; background-color: #EEE; padding: 2px; padding-left: 6px; padding-right: 6px;');
    $tblRE->addRow(array(S_NAME, new CTextBox('rename', $rename, 60)));
    $tblRE->addRow(array(S_TEST_STRING, new CTextArea('test_string', $test_string, 66, 5)));
    $tabExp = new CTableInfo();
    $td1 = new CCol(S_EXPRESSION);
    $td1->addStyle('background-color: #CCC;');
    $td2 = new CCol(S_EXPECTED_RESULT);
    $td2->addStyle('background-color: #CCC;');
    $td3 = new CCol(S_RESULT);
    $td3->addStyle('background-color: #CCC;');
    $tabExp->setHeader(array($td1, $td2, $td3));
    $final_result = !empty($test_string);
    foreach ($expressions as $id => $expression) {
        $results = array();
        $paterns = array($expression['expression']);
        if (!empty($test_string)) {
            if ($expression['expression_type'] == EXPRESSION_TYPE_ANY_INCLUDED) {
                $paterns = explode($expression['exp_delimiter'], $expression['expression']);
            }
            if (uint_in_array($expression['expression_type'], array(EXPRESSION_TYPE_TRUE, EXPRESSION_TYPE_FALSE))) {
                if ($expression['case_sensitive']) {
                    $results[$id] = ereg($paterns[0], $test_string);
                } else {
                    $results[$id] = eregi($paterns[0], $test_string);
                }
                if ($expression['expression_type'] == EXPRESSION_TYPE_TRUE) {
                    $final_result &= $results[$id];
                } else {
                    $final_result &= !$results[$id];
                }
            } else {
                $results[$id] = true;
                $tmp_result = false;
                if ($expression['case_sensitive']) {
                    foreach ($paterns as $pid => $patern) {
                        $tmp_result |= zbx_stristr($test_string, $patern) !== false;
                    }
                } else {
                    foreach ($paterns as $pid => $patern) {
                        $tmp_result |= zbx_strstr($test_string, $patern) !== false;
                    }
                }
                $results[$id] &= $tmp_result;
                $final_result &= $results[$id];
            }
        }
        if (isset($results[$id]) && $results[$id]) {
            $exp_res = new CSpan(S_TRUE_BIG, 'green bold');
        } else {
            $exp_res = new CSpan(S_FALSE_BIG, 'red bold');
        }
        $expec_result = expression_type2str($expression['expression_type']);
        if (EXPRESSION_TYPE_ANY_INCLUDED == $expression['expression_type']) {
            $expec_result .= ' (' . S_DELIMITER . "='" . $expression['exp_delimiter'] . "')";
        }
        $tabExp->addRow(array($expression['expression'], $expec_result, $exp_res));
    }
    $td = new CCol(S_COMBINED_RESULT, 'bold');
    $td->setColSpan(2);
    if ($final_result) {
        $final_result = new CSpan(S_TRUE_BIG, 'green bold');
    } else {
        $final_result = new CSpan(S_FALSE_BIG, 'red bold');
    }
    $tabExp->addRow(array($td, $final_result));
    $tblRE->addRow(array(S_RESULT, $tabExp));
    $tblFoot = new CTableInfo(null);
    $td = new CCol(array(new CButton('save', S_SAVE)));
    $td->setColSpan(2);
    $td->addStyle('text-align: right;');
    $td->addItem(SPACE);
    $td->addItem(new CButton('test', S_TEST));
    if (isset($_REQUEST['regexpid'])) {
        $td->addItem(SPACE);
        $td->addItem(new CButton('clone', S_CLONE));
        $td->addItem(SPACE);
        $td->addItem(new CButtonDelete(S_DELETE_REGULAR_EXPRESSION_Q, url_param('form') . url_param('config') . url_param('regexpid')));
    }
    $td->addItem(SPACE);
    $td->addItem(new CButtonCancel(url_param("regexpid")));
    $tblFoot->SetFooter($td);
    return array($tblRE, $tblFoot);
}
Beispiel #7
0
 $table = new CTableInfo('...');
 $table->setHeader(array(S_TIMESTAMP, $fewItems ? S_ITEM : null, $logItem ? S_LOCAL_TIME : null, $eventLogItem && $logItem ? S_SOURCE : null, $eventLogItem && $logItem ? S_SEVERITY : null, $eventLogItem && $logItem ? S_EVENT_ID : null, S_VALUE), 'header');
 if (isset($_REQUEST['filter']) && !zbx_empty($_REQUEST['filter']) && in_array($_REQUEST['filter_task'], array(FILTER_TASK_SHOW, FILTER_TASK_HIDE))) {
     $options['search'] = array('value' => $_REQUEST['filter']);
     if ($_REQUEST['filter_task'] == FILTER_TASK_HIDE) {
         $options['excludeSearch'] = 1;
     }
 }
 $options['sortfield'] = 'id';
 $hData = CHistory::get($options);
 foreach ($hData as $hnum => $data) {
     $color_style = null;
     $item = $items[$data['itemid']];
     $host = reset($item['hosts']);
     if (isset($_REQUEST['filter']) && !zbx_empty($_REQUEST['filter'])) {
         $contain = zbx_stristr($data['value'], $_REQUEST['filter']);
         if (!isset($_REQUEST['mark_color'])) {
             $_REQUEST['mark_color'] = MARK_COLOR_RED;
         }
         if ($contain && $_REQUEST['filter_task'] == FILTER_TASK_MARK) {
             $color_style = $_REQUEST['mark_color'];
         }
         if (!$contain && $_REQUEST['filter_task'] == FILTER_TASK_INVERT_MARK) {
             $color_style = $_REQUEST['mark_color'];
         }
         switch ($color_style) {
             case MARK_COLOR_RED:
                 $color_style = 'red';
                 break;
             case MARK_COLOR_GREEN:
                 $color_style = 'green';
Beispiel #8
0
/**
 * Returns the next data set from a DB resource or false if there are no more results.
 *
 * @param resource $cursor
 * @param bool $convertNulls	convert all null values to string zeroes
 *
 * @return array|bool
 */
function DBfetch($cursor, $convertNulls = true)
{
    global $DB;
    $result = false;
    if (!isset($DB['DB']) || empty($DB['DB']) || is_bool($cursor)) {
        return $result;
    }
    switch ($DB['TYPE']) {
        case ZBX_DB_MYSQL:
            $result = mysqli_fetch_assoc($cursor);
            if (!$result) {
                mysqli_free_result($cursor);
            }
            break;
        case ZBX_DB_POSTGRESQL:
            if (!($result = pg_fetch_assoc($cursor))) {
                pg_free_result($cursor);
            }
            break;
        case ZBX_DB_ORACLE:
            if ($row = oci_fetch_assoc($cursor)) {
                $result = array();
                foreach ($row as $key => $value) {
                    $field_type = zbx_strtolower(oci_field_type($cursor, $key));
                    // Oracle does not support NULL values for string fields, so if the string is empty, it will return NULL
                    // convert it to an empty string to be consistent with other databases
                    $value = str_in_array($field_type, array('varchar', 'varchar2', 'blob', 'clob')) && is_null($value) ? '' : $value;
                    if (is_object($value) && zbx_stristr($field_type, 'lob') !== false) {
                        $value = $value->load();
                    }
                    $result[zbx_strtolower($key)] = $value;
                }
            }
            break;
        case ZBX_DB_DB2:
            if (!($result = db2_fetch_assoc($cursor))) {
                db2_free_result($cursor);
            } else {
                // cast all of the values to string to be consistent with other DB drivers: all of them return
                // only strings.
                foreach ($result as &$value) {
                    if ($value !== null) {
                        $value = (string) $value;
                    }
                }
                unset($value);
            }
            break;
        case ZBX_DB_SQLITE3:
            if ($DB['TRANSACTIONS'] == 0) {
                lock_sqlite3_access();
            }
            if (!($result = $cursor->fetchArray(SQLITE3_ASSOC))) {
                unset($cursor);
            } else {
                // cast all of the values to string to be consistent with other DB drivers: all of them return
                // only strings.
                foreach ($result as &$value) {
                    $value = (string) $value;
                }
                unset($value);
            }
            if ($DB['TRANSACTIONS'] == 0) {
                unlock_sqlite3_access();
            }
            break;
    }
    if ($result) {
        if ($convertNulls) {
            foreach ($result as $key => $val) {
                if (is_null($val)) {
                    $result[$key] = '0';
                }
            }
        }
        return $result;
    }
    return false;
}
Beispiel #9
0
 		$sql = 'SELECT DISTINCT th.host as template_host,th.hostid as template_hostid, h.host, h.hostid, hgg.groupid, i.* '.
 				' FROM '.implode(',', $from_tables).
 					' LEFT JOIN hosts_groups hgg ON hgg.hostid=i.hostid '.
 					' LEFT JOIN items ti ON i.templateid=ti.itemid '.
 					' LEFT JOIN hosts th ON ti.hostid=th.hostid '.
 				' WHERE '.implode(' AND ', $where_case).
 				order_by('h.host,i.description,i.key_,i.delay,i.history,i.trends,i.type,i.status','i.itemid');
 //*/
 //*
 $sql = 'SELECT DISTINCT th.host as template_host,th.hostid as template_hostid, h.host, h.hostid, i.* ' . ' FROM ' . implode(',', $from_tables) . ' LEFT JOIN items ti ON i.templateid=ti.itemid ' . ' LEFT JOIN hosts th ON ti.hostid=th.hostid ' . ' WHERE ' . implode(' and ', $where_case) . order_by('h.host,i.description,i.key_,i.delay,i.history,i.trends,i.type,i.status', 'i.itemid');
 //*/
 $db_items = DBselect($sql);
 while ($db_item = DBfetch($db_items)) {
     $description = array();
     $item_description = item_description($db_item);
     if (isset($_REQUEST['filter_description']) && !zbx_stristr($item_description, $_REQUEST['filter_description'])) {
         continue;
     }
     if ($db_item['templateid']) {
         $template_host = get_realhost_by_itemid($db_item['templateid']);
         array_push($description, new CLink($template_host['host'], '?' . 'hostid=' . $template_host['hostid'], 'unknown'), ':');
     }
     array_push($description, new CLink(item_description($db_item), '?form=update&itemid=' . $db_item['itemid'] . '&hostid=' . $db_item['hostid']));
     $status = new CCol(new CLink(item_status2str($db_item['status']), '?group_itemid%5B%5D=' . $db_item['itemid'] . '&go=' . ($db_item['status'] ? 'activate' : 'disable'), item_status2style($db_item['status'])));
     if (!zbx_empty($db_item['error'])) {
         $error = new CDiv(SPACE, 'error_icon');
         $error->setHint($db_item['error'], '', 'on');
     } else {
         $error = new CDiv(SPACE, 'ok_icon');
     }
     $applications = $show_applications ? implode(', ', get_applications_by_itemid($db_item['itemid'], 'name')) : null;
function get_regexp_form()
{
    if (isset($_REQUEST['regexpid']) && !isset($_REQUEST['form_refresh'])) {
        $sql = 'SELECT re.* ' . ' FROM regexps re ' . ' WHERE ' . DBin_node('re.regexpid') . ' AND re.regexpid=' . zbx_dbstr($_REQUEST['regexpid']);
        $regexp = DBfetch(DBSelect($sql));
        $rename = $regexp['name'];
        $test_string = $regexp['test_string'];
        $expressions = array();
        $sql = 'SELECT e.* ' . ' FROM expressions e ' . ' WHERE ' . DBin_node('e.expressionid') . ' AND e.regexpid=' . zbx_dbstr($regexp['regexpid']) . ' ORDER BY e.expression_type';
        $db_exps = DBselect($sql);
        while ($exp = DBfetch($db_exps)) {
            $expressions[] = $exp;
        }
    } else {
        $rename = get_request('rename', '');
        $test_string = get_request('test_string', '');
        $expressions = get_request('expressions', array());
    }
    $tblRE = new CTable('', 'formtable nowrap');
    $tblRE->addRow(array(_('Name'), new CTextBox('rename', $rename, 60, 'no', 128)));
    $tblRE->addRow(array(_('Test string'), new CTextArea('test_string', $test_string)));
    $tabExp = new CTableInfo();
    $td1 = new CCol(_('Expression'));
    $td2 = new CCol(_('Expected result'));
    $td3 = new CCol(_('Result'));
    $tabExp->setHeader(array($td1, $td2, $td3));
    $final_result = !empty($test_string);
    foreach ($expressions as $id => $expression) {
        $results = array();
        $paterns = array($expression['expression']);
        if (!empty($test_string)) {
            if ($expression['expression_type'] == EXPRESSION_TYPE_ANY_INCLUDED) {
                $paterns = explode($expression['exp_delimiter'], $expression['expression']);
            }
            if (uint_in_array($expression['expression_type'], array(EXPRESSION_TYPE_TRUE, EXPRESSION_TYPE_FALSE))) {
                if ($expression['case_sensitive']) {
                    $results[$id] = preg_match('/' . $paterns[0] . '/', $test_string);
                } else {
                    $results[$id] = preg_match('/' . $paterns[0] . '/i', $test_string);
                }
                if ($expression['expression_type'] == EXPRESSION_TYPE_TRUE) {
                    $final_result &= $results[$id];
                } else {
                    $final_result &= !$results[$id];
                }
            } else {
                $results[$id] = true;
                $tmp_result = false;
                if ($expression['case_sensitive']) {
                    foreach ($paterns as $pid => $patern) {
                        $tmp_result |= zbx_strstr($test_string, $patern) !== false;
                    }
                } else {
                    foreach ($paterns as $pid => $patern) {
                        $tmp_result |= zbx_stristr($test_string, $patern) !== false;
                    }
                }
                if (uint_in_array($expression['expression_type'], array(EXPRESSION_TYPE_INCLUDED, EXPRESSION_TYPE_ANY_INCLUDED))) {
                    $results[$id] &= $tmp_result;
                } else {
                    if ($expression['expression_type'] == EXPRESSION_TYPE_NOT_INCLUDED) {
                        $results[$id] &= !$tmp_result;
                    }
                }
                $final_result &= $results[$id];
            }
        }
        if (isset($results[$id]) && $results[$id]) {
            $exp_res = new CSpan(_('TRUE'), 'green bold');
        } else {
            $exp_res = new CSpan(_('FALSE'), 'red bold');
        }
        $expec_result = expression_type2str($expression['expression_type']);
        if (EXPRESSION_TYPE_ANY_INCLUDED == $expression['expression_type']) {
            $expec_result .= ' (' . _('Delimiter') . "='" . $expression['exp_delimiter'] . "')";
        }
        $tabExp->addRow(array($expression['expression'], $expec_result, $exp_res));
    }
    $td = new CCol(_('Combined result'), 'bold');
    $td->setColSpan(2);
    if ($final_result) {
        $final_result = new CSpan(_('TRUE'), 'green bold');
    } else {
        $final_result = new CSpan(_('FALSE'), 'red bold');
    }
    $tabExp->addRow(array($td, $final_result));
    $tblRE->addRow(array(_('Result'), $tabExp));
    $tblFoot = new CTableInfo(null);
    $td = new CCol(array(new CSubmit('save', _('Save'))));
    $td->setColSpan(2);
    $td->addStyle('text-align: right;');
    $td->addItem(SPACE);
    $td->addItem(new CSubmit('test', _('Test')));
    if (isset($_REQUEST['regexpid'])) {
        $td->addItem(SPACE);
        $td->addItem(new CSubmit('clone', _('Clone')));
        $td->addItem(SPACE);
        $td->addItem(new CButtonDelete(_('Delete regular expression?'), url_param('form') . url_param('config') . url_param('regexpid') . url_param('delete', false, 'go')));
    }
    $td->addItem(SPACE);
    $td->addItem(new CButtonCancel(url_param("regexpid")));
    $tblFoot->setFooter($td);
    return array($tblRE, $tblFoot);
}
Beispiel #11
0
 }
 $sql = 'SELECT hst.host,i.itemid,i.key_,i.description,h.clock,h.value,i.valuemapid,h.timestamp,h.source,h.severity' . ' FROM history_log h, items i, hosts hst' . ' WHERE hst.hostid=i.hostid ' . ' AND h.itemid=i.itemid' . $sql_filter . ' AND i.itemid in (' . $itemid_lst . ')' . $cond_clock . ' ORDER BY h.clock desc, h.id desc';
 $result = DBselect($sql, $limit);
 if (!isset($_REQUEST['plaintext'])) {
     $table = new CTableInfo('...', 'log_history_table');
     $table->AddOption('id', 'graph');
     $table->SetHeader(array(S_TIMESTAMP, $item_cout > 1 ? S_ITEM : null, S_LOCAL_TIME, S_SOURCE, S_SEVERITY, S_VALUE), "header");
     $table->ShowStart();
     // to solve memory leak we call 'Show' method by steps
 } else {
     echo "<pre>\n";
 }
 while ($row = DBfetch($result)) {
     $color_style = null;
     if (isset($_REQUEST["filter"]) && $_REQUEST["filter"] != "") {
         $contain = zbx_stristr($row["value"], $_REQUEST["filter"]) ? TRUE : FALSE;
         if (!isset($_REQUEST["mark_color"])) {
             $_REQUEST["mark_color"] = MARK_COLOR_RED;
         }
         if ($contain && $_REQUEST["filter_task"] == FILTER_TAST_MARK) {
             $color_style = $_REQUEST["mark_color"];
         }
         if (!$contain && $_REQUEST["filter_task"] == FILTER_TAST_INVERT_MARK) {
             $color_style = $_REQUEST["mark_color"];
         }
         switch ($color_style) {
             case MARK_COLOR_RED:
                 $color_style = "mark_as_red";
                 break;
             case MARK_COLOR_GREEN:
                 $color_style = "mark_as_green";
Beispiel #12
0
 $sql = 'SELECT hst.host,i.itemid,i.key_,i.description,h.clock,h.value,i.valuemapid,h.timestamp,h.source,' . 'h.severity,h.logeventid ' . ' FROM history_log h, items i, hosts hst ' . ' WHERE hst.hostid=i.hostid ' . ' AND h.itemid=i.itemid' . $sql_filter . ' AND i.itemid in (' . $itemid_lst . ')' . $cond_clock . ' ORDER BY h.clock desc, h.id DESC';
 $result = DBselect($sql, $limit);
 if (!isset($_REQUEST['plaintext'])) {
     $table = new CTableInfo('...', 'log_history_table');
     $table->setAttribute('id', 'graph');
     $table->setHeader(array(S_TIMESTAMP, $item_cout > 1 ? S_ITEM : null, S_LOCAL_TIME, S_SOURCE, S_SEVERITY, S_EVENT_ID, S_VALUE), 'header');
     $table->ShowStart();
     // to solve memory leak we call 'Show' method by steps
 } else {
     echo '<span class="textcolorstyles"><pre>' . "\n";
 }
 while ($row = DBfetch($result)) {
     //				$color_style = null;
     $color_style = 'textcolorstyles';
     if (isset($_REQUEST['filter']) && $_REQUEST['filter'] != '') {
         $contain = zbx_stristr($row['value'], $_REQUEST['filter']) ? TRUE : FALSE;
         if (!isset($_REQUEST['mark_color'])) {
             $_REQUEST['mark_color'] = MARK_COLOR_RED;
         }
         if ($contain && $_REQUEST['filter_task'] == FILTER_TAST_MARK) {
             $color_style = $_REQUEST['mark_color'];
         }
         if (!$contain && $_REQUEST['filter_task'] == FILTER_TAST_INVERT_MARK) {
             $color_style = $_REQUEST['mark_color'];
         }
         switch ($color_style) {
             case MARK_COLOR_RED:
                 $color_style = 'mark_as_red';
                 break;
             case MARK_COLOR_GREEN:
                 $color_style = 'mark_as_green';
Beispiel #13
0
    if (count($hosts) > 1) {
        $sortFields = $sortField === 'host' ? array(array('field' => 'name', 'order' => $sortOrder)) : array('name');
        CArrayHelper::sort($hosts, $sortFields);
    }
}
// get items
if ($hosts) {
    $items = API::Item()->get(array('hostids' => array_keys($hosts), 'output' => array('itemid', 'name', 'type', 'value_type', 'units', 'hostid', 'state', 'valuemapid', 'status', 'error', 'trends', 'history', 'delay', 'key_', 'flags'), 'selectApplications' => array('applicationid'), 'selectItemDiscovery' => array('ts_delete'), 'webitems' => true, 'filter' => array('status' => array(ITEM_STATUS_ACTIVE)), 'preservekeys' => true));
}
if ($items) {
    // macros
    $items = CMacrosResolverHelper::resolveItemKeys($items);
    $items = CMacrosResolverHelper::resolveItemNames($items);
    // filter items by name
    foreach ($items as $key => $item) {
        if (!zbx_empty($filterSelect) && !zbx_stristr($item['name_expanded'], $filterSelect)) {
            unset($items[$key]);
        }
    }
    if ($items) {
        // get history
        $history = Manager::History()->getLast($items, 2, ZBX_HISTORY_PERIOD);
        // filter items without history
        if (!$filterShowWithoutData) {
            foreach ($items as $key => $item) {
                if (!isset($history[$item['itemid']])) {
                    unset($items[$key]);
                }
            }
        }
    }
Beispiel #14
0
    }
    unset($host);
    if (count($hosts) > 1) {
        $sortFields = $sortField == 'h.name' ? array(array('field' => 'name', 'order' => $sortOrder)) : array('name');
        CArrayHelper::sort($hosts, $sortFields);
    }
}
// get items
if ($hosts) {
    $items = API::Item()->get(array('hostids' => array_keys($hosts), 'output' => array('itemid', 'name', 'type', 'value_type', 'units', 'hostid', 'state', 'valuemapid', 'status', 'error', 'trends', 'history', 'delay', 'key_', 'flags'), 'selectApplications' => array('applicationid'), 'selectItemDiscovery' => array('ts_delete'), 'webitems' => true, 'filter' => array('status' => array(ITEM_STATUS_ACTIVE)), 'preservekeys' => true));
}
if ($items) {
    // filter items by name
    foreach ($items as $key => &$item) {
        $item['resolvedName'] = itemName($item);
        if (!zbx_empty($filterSelect) && !zbx_stristr($item['resolvedName'], $filterSelect)) {
            unset($items[$key]);
        }
    }
    unset($item);
    if ($items) {
        // get history
        $history = Manager::History()->getLast($items, 2);
        // filter items without history
        if (!$filterShowWithoutData) {
            foreach ($items as $key => $item) {
                if (!isset($history[$item['itemid']])) {
                    unset($items[$key]);
                }
            }
        }
Beispiel #15
0
function DBfetch(&$cursor)
{
    global $DB;
    $result = false;
    if (isset($DB['DB']) && !empty($DB['DB'])) {
        switch ($DB['TYPE']) {
            case 'MYSQL':
                $result = mysql_fetch_assoc($cursor);
                if (!$result) {
                    mysql_free_result($cursor);
                }
                break;
            case 'POSTGRESQL':
                $result = pg_fetch_assoc($cursor);
                if (!$result) {
                    pg_free_result($cursor);
                }
                break;
            case 'ORACLE':
                if (ocifetchinto($cursor, $row, OCI_ASSOC + OCI_RETURN_NULLS)) {
                    $result = array();
                    foreach ($row as $key => $value) {
                        $field_type = zbx_strtolower(oci_field_type($cursor, $key));
                        $value = str_in_array($field_type, array('varchar', 'varchar2', 'blob', 'clob')) && is_null($value) ? '' : $value;
                        if (is_object($value) && zbx_stristr($field_type, 'lob') !== false) {
                            $value = $value->load();
                        }
                        $result[zbx_strtolower($key)] = $value;
                    }
                }
                break;
            case 'IBM_DB2':
                $result = db2_fetch_assoc($cursor);
                if (!$result) {
                    db2_free_result($cursor);
                }
                break;
            case 'SQLITE3':
                if ($cursor) {
                    $result = array_shift($cursor);
                    if (is_null($result)) {
                        $result = false;
                    }
                }
                break;
        }
    }
    /*
    		if($result === false){
    			switch($DB['TYPE']){
    				case 'MYSQL': mysql_free_result($cursor); break;
    				case 'POSTGRESQL': pg_free_result($cursor); break;
    				case 'ORACLE': oci_free_statement($cursor); break;
    			}
    		}
    //*/
    return $result;
}