Example #1
0
 public function addItem($value)
 {
     if (is_object($value) && zbx_strtolower(get_class($value)) != 'carea') {
         return $this->error('Incorrect value for addItem "' . $value . '".');
     }
     return parent::addItem($value);
 }
 public function addItem($item)
 {
     if (is_object($item) && zbx_strtolower(get_class($item)) == 'ccol') {
         parent::addItem($item);
     } elseif (is_array($item)) {
         foreach ($item as $el) {
             if (is_object($el) && zbx_strtolower(get_class($el)) == 'ccol') {
                 parent::addItem($el);
             } elseif (!is_null($el)) {
                 parent::addItem(new CCol($el));
             }
         }
     } elseif (!is_null($item)) {
         parent::addItem(new CCol($item));
     }
 }
Example #3
0
 public function addRow($term, $description = null, $hidden = false, $id = null, $class = null)
 {
     $label = $term;
     if (is_object($description)) {
         $inputClass = zbx_strtolower(get_class($description));
         if (in_array($inputClass, $this->formInputs)) {
             $label = new CLabel($term, $description->getAttribute('id'));
         }
     }
     $defaultClass = $hidden ? 'formrow hidden' : 'formrow';
     if ($class === null) {
         $class = $defaultClass;
     } else {
         $class .= ' ' . $defaultClass;
     }
     if ($description === null) {
         $this->formList->addItem(array(new CDiv(SPACE, 'dt right'), new CDiv($label, 'dd')), $class, $id);
     } else {
         $this->formList->addItem(array(new CDiv($label, 'dt right'), new CDiv($description, 'dd')), $class, $id);
     }
 }
 public function addItem($value, $caption = '', $selected = NULL, $enabled = 'yes')
 {
     //			if($enabled=='no') return;	/* disable item method 1 */
     if (is_object($value) && zbx_strtolower(get_class($value)) == 'ccomboitem') {
         parent::addItem($value);
     } else {
         if (zbx_strlen($caption) > 44) {
             $this->setAttribute('class', 'select selectShorten');
         }
         if (is_null($selected)) {
             $selected = 'no';
             if (is_array($this->value)) {
                 if (str_in_array($value, $this->value)) {
                     $selected = 'yes';
                 }
             } else {
                 if (strcmp($value, $this->value) == 0) {
                     $selected = 'yes';
                 }
             }
         }
         parent::addItem(new CComboItem($value, $caption, $selected, $enabled));
     }
 }
function hide_form_items(&$obj)
{
    if (is_array($obj)) {
        foreach ($obj as $id => $item) {
            hide_form_items($obj[$id]);
            // attention recursion
        }
    } elseif (is_object($obj)) {
        $formObjects = array('cform', 'ccheckbox', 'cselect', 'cbutton', 'csubmit', 'cbuttonqmessage', 'cbuttondelete', 'cbuttoncancel');
        if (is_object($obj) && str_in_array(zbx_strtolower(get_class($obj)), $formObjects)) {
            $obj = SPACE;
        }
        if (isset($obj->items) && !empty($obj->items)) {
            foreach ($obj->items as $id => $item) {
                hide_form_items($obj->items[$id]);
                // attention recursion
            }
        }
    } else {
        foreach (array('<form', '<input', '<select') as $item) {
            if (zbx_strpos($obj, $item) !== false) {
                $obj = SPACE;
            }
        }
    }
}
Example #6
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;
}
 protected function inherit($graph, $hostids = null)
 {
     $graphTemplates = API::Template()->get(array('itemids' => zbx_objectValues($graph['gitems'], 'itemid'), 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => true));
     if (empty($graphTemplates)) {
         return true;
     }
     $graphTemplate = reset($graphTemplates);
     $chdHosts = API::Host()->get(array('templateids' => $graphTemplate['templateid'], 'output' => array('hostid', 'host'), 'preservekeys' => true, 'hostids' => $hostids, 'nopermissions' => true, 'templated_hosts' => true));
     $graph = $this->get(array('graphids' => $graph['graphid'], 'nopermissions' => true, 'filter' => array('flags' => null), 'selectItems' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND));
     $graph = reset($graph);
     foreach ($chdHosts as $chdHost) {
         $tmpGraph = $graph;
         $tmpGraph['templateid'] = $graph['graphid'];
         if (!($tmpGraph['gitems'] = get_same_graphitems_for_host($tmpGraph['gitems'], $chdHost['hostid']))) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" cannot inherit. No required items on "%2$s".', $tmpGraph['name'], $chdHost['host']));
         }
         if ($tmpGraph['ymax_itemid'] > 0) {
             $ymaxItemid = get_same_graphitems_for_host(array(array('itemid' => $tmpGraph['ymax_itemid'])), $chdHost['hostid']);
             if (!$ymaxItemid) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" cannot inherit. No required items on "%2$s" (Ymax value item).', $tmpGraph['name'], $chdHost['host']));
             }
             $ymaxItemid = reset($ymaxItemid);
             $tmpGraph['ymax_itemid'] = $ymaxItemid['itemid'];
         }
         if ($tmpGraph['ymin_itemid'] > 0) {
             $yminItemid = get_same_graphitems_for_host(array(array('itemid' => $tmpGraph['ymin_itemid'])), $chdHost['hostid']);
             if (!$yminItemid) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" cannot inherit. No required items on "%2$s" (Ymin value item).', $tmpGraph['name'], $chdHost['host']));
             }
             $yminItemid = reset($yminItemid);
             $tmpGraph['ymin_itemid'] = $yminItemid['itemid'];
         }
         // check if templated graph exists
         $chdGraphs = $this->get(array('filter' => array('templateid' => $tmpGraph['graphid'], 'flags' => array(ZBX_FLAG_DISCOVERY_CHILD, ZBX_FLAG_DISCOVERY_NORMAL)), 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'hostids' => $chdHost['hostid']));
         if ($chdGraph = reset($chdGraphs)) {
             if (zbx_strtolower($tmpGraph['name']) != zbx_strtolower($chdGraph['name']) && $this->exists(array('name' => $tmpGraph['name'], 'hostids' => $chdHost['hostid']))) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s".', $tmpGraph['name'], $chdHost['host']));
             } elseif ($chdGraph['flags'] != $tmpGraph['flags']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Graph with same name but other type exist.'));
             }
             $tmpGraph['graphid'] = $chdGraph['graphid'];
             $this->updateReal($tmpGraph, $chdGraph);
         } else {
             $chdGraph = $this->get(array('filter' => array('name' => $tmpGraph['name'], 'flags' => null), 'output' => API_OUTPUT_EXTEND, 'selectGraphItems' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'nopermissions' => true, 'hostids' => $chdHost['hostid']));
             if ($chdGraph = reset($chdGraph)) {
                 if ($chdGraph['templateid'] != 0) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s" (inherited from another template).', $tmpGraph['name'], $chdHost['host']));
                 } elseif ($chdGraph['flags'] != $tmpGraph['flags']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('Graph with same name but other type exist.'));
                 }
                 $chdGraphItems = API::GraphItem()->get(array('graphids' => $chdGraph['graphid'], 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'expandData' => true, 'nopermissions' => true));
                 if (count($chdGraphItems) == count($tmpGraph['gitems'])) {
                     foreach ($tmpGraph['gitems'] as $gitem) {
                         foreach ($chdGraphItems as $chdItem) {
                             if ($gitem['key_'] == $chdItem['key_'] && bccomp($chdHost['hostid'], $chdItem['hostid']) == 0) {
                                 continue 2;
                             }
                         }
                         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s" (items are not identical).', $tmpGraph['name'], $chdHost['host']));
                     }
                     $tmpGraph['graphid'] = $chdGraph['graphid'];
                     $this->updateReal($tmpGraph, $chdGraph);
                 } else {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Graph "%1$s" already exists on "%2$s" (items are not identical).', $tmpGraph['name'], $chdHost['host']));
                 }
             } else {
                 $graphid = $this->createReal($tmpGraph);
                 $tmpGraph['graphid'] = $graphid;
             }
         }
         $this->inherit($tmpGraph);
     }
 }
Example #8
0
function show_messages($bool = true, $okmsg = null, $errmsg = null)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        return null;
    }
    if (defined('ZBX_API_REQUEST')) {
        return null;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $message = array();
    $width = 0;
    $height = 0;
    if (!$bool && !is_null($errmsg)) {
        $msg = _('ERROR') . ': ' . $errmsg;
    } elseif ($bool && !is_null($okmsg)) {
        $msg = $okmsg;
    }
    if (isset($msg)) {
        switch ($page['type']) {
            case PAGE_TYPE_IMAGE:
                array_push($message, array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68), 'font' => 2));
                $width = max($width, imagefontwidth(2) * zbx_strlen($msg) + 1);
                $height += imagefontheight(2) + 1;
                break;
            case PAGE_TYPE_XML:
                echo htmlspecialchars($msg) . "\n";
                break;
            case PAGE_TYPE_HTML:
            default:
                $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr');
                $msg_tab->setCellPadding(0);
                $msg_tab->setCellSpacing(0);
                $row = array();
                $msg_col = new CCol(bold($msg), 'msg_main msg');
                $msg_col->setAttribute('id', 'page_msg');
                $row[] = $msg_col;
                if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
                    $msg_details = new CDiv(_('Details'), 'blacklink');
                    $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");');
                    $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize'));
                    array_unshift($row, new CCol($msg_details, 'clr'));
                }
                $msg_tab->addRow($row);
                $msg_tab->show();
                break;
        }
    }
    if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
        if ($page['type'] == PAGE_TYPE_IMAGE) {
            $msg_font = 2;
            foreach ($ZBX_MESSAGES as $msg) {
                if ($msg['type'] == 'error') {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55), 'font' => $msg_font));
                } else {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55), 'font' => $msg_font));
                }
                $width = max($width, imagefontwidth($msg_font) * zbx_strlen($msg['message']) + 1);
                $height += imagefontheight($msg_font) + 1;
            }
        } elseif ($page['type'] == PAGE_TYPE_XML) {
            foreach ($ZBX_MESSAGES as $msg) {
                echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n";
            }
        } else {
            $lst_error = new CList(null, 'messages');
            foreach ($ZBX_MESSAGES as $msg) {
                $lst_error->addItem($msg['message'], $msg['type']);
                $bool = $bool && 'error' != zbx_strtolower($msg['type']);
            }
            $msg_show = 6;
            $msg_count = count($ZBX_MESSAGES);
            if ($msg_count > $msg_show) {
                $msg_count = $msg_show * 16;
                $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;');
            }
            $tab = new CTable(null, $bool ? 'msgok' : 'msgerr');
            $tab->setCellPadding(0);
            $tab->setCellSpacing(0);
            $tab->setAttribute('id', 'msg_messages');
            $tab->setAttribute('style', 'width: 100%;');
            if (isset($msg_tab) && $bool) {
                $tab->setAttribute('style', 'display: none;');
            }
            $tab->addRow(new CCol($lst_error, 'msg'));
            $tab->show();
        }
        $ZBX_MESSAGES = null;
    }
    if ($page['type'] == PAGE_TYPE_IMAGE && count($message) > 0) {
        $width += 2;
        $height += 2;
        $canvas = imagecreate($width, $height);
        imagefilledrectangle($canvas, 0, 0, $width, $height, imagecolorallocate($canvas, 255, 255, 255));
        foreach ($message as $id => $msg) {
            $message[$id]['y'] = 1 + (isset($previd) ? $message[$previd]['y'] + $message[$previd]['h'] : 0);
            $message[$id]['h'] = imagefontheight($msg['font']);
            imagestring($canvas, $msg['font'], 1, $message[$id]['y'], $msg['text'], imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']));
            $previd = $id;
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}
 protected static function inherit($graph, $hostids = null)
 {
     $options = array('itemids' => zbx_objectValues($graph['gitems'], 'itemid'), 'output' => API_OUTPUT_SHORTEN, 'nopermissions' => 1);
     $graph_templates = CTemplate::get($options);
     if (empty($graph_templates)) {
         return true;
     }
     //-----
     $graphTemplate = reset($graph_templates);
     $options = array('templateids' => $graphTemplate['templateid'], 'output' => array('hostid', 'host'), 'preservekeys' => 1, 'hostids' => $hostids, 'nopermissions' => 1, 'templated_hosts' => 1);
     $chd_hosts = CHost::get($options);
     $options = array('graphids' => $graph['graphid'], 'nopermissions' => 1, 'select_items' => API_OUTPUT_EXTEND, 'select_graph_items' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND);
     $graph = self::get($options);
     $graph = reset($graph);
     foreach ($chd_hosts as $chd_host) {
         $tmp_graph = $graph;
         $tmp_graph['templateid'] = $graph['graphid'];
         if (!($tmp_graph['gitems'] = get_same_graphitems_for_host($tmp_graph['gitems'], $chd_host['hostid']))) {
             self::exception(ZBX_API_ERROR_PARAMETERS, 'Graph [ ' . $tmp_graph['name'] . ' ]: cannot inherit. No required items on [ ' . $chd_host['host'] . ' ]');
         }
         if ($tmp_graph['ymax_itemid'] > 0) {
             $ymax_itemid = get_same_graphitems_for_host(array(array('itemid' => $tmp_graph['ymax_itemid'])), $chd_host['hostid']);
             if (!$ymax_itemid) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Graph [ ' . $tmp_graph['name'] . ' ]: cannot inherit. No required items on [ ' . $chd_host['host'] . ' ] (Ymax value item)');
             }
             $ymax_itemid = reset($ymax_itemid);
             $tmp_graph['ymax_itemid'] = $ymax_itemid['itemid'];
         }
         if ($tmp_graph['ymin_itemid'] > 0) {
             $ymin_itemid = get_same_graphitems_for_host(array(array('itemid' => $tmp_graph['ymin_itemid'])), $chd_host['hostid']);
             if (!$ymin_itemid) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, 'Graph [ ' . $tmp_graph['name'] . ' ]: cannot inherit. No required items on [ ' . $chd_host['host'] . ' ] (Ymin value item)');
             }
             $ymin_itemid = reset($ymin_itemid);
             $tmp_graph['ymin_itemid'] = $ymin_itemid['itemid'];
         }
         // check if templated graph exists
         $chd_graph = self::get(array('filter' => array('templateid' => $tmp_graph['graphid']), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1, 'hostids' => $chd_host['hostid']));
         if ($chd_graph = reset($chd_graph)) {
             if (zbx_strtolower($tmp_graph['name']) != zbx_strtolower($chd_graph['name']) && self::exists(array('name' => $tmp_graph['name'], 'hostids' => $chd_host['hostid']))) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, sprintf(S_GRAPH_ALREADY_EXISTS_ON, $tmp_graph['name'], $chd_host['host']));
             }
             $tmp_graph['graphid'] = $chd_graph['graphid'];
             self::updateReal($tmp_graph);
         } else {
             $options = array('filter' => array('name' => $tmp_graph['name']), 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1, 'nopermissions' => 1, 'hostids' => $chd_host['hostid']);
             $chd_graph = self::get($options);
             if ($chd_graph = reset($chd_graph)) {
                 if ($chd_graph['templateid'] != 0) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, sprintf(S_GRAPH_ALREADY_EXISTS_ON, $tmp_graph['name'], $chd_host['host']) . SPACE . S_INHERITED_FROM_ANOTHER_TEMPLATE);
                 }
                 $options = array('graphids' => $chd_graph['graphid'], 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1, 'expandData' => 1, 'nopermissions' => 1);
                 $chd_graph_items = CGraphItem::get($options);
                 if (count($chd_graph_items) == count($tmp_graph['gitems'])) {
                     foreach ($tmp_graph['gitems'] as $gitem) {
                         foreach ($chd_graph_items as $chd_item) {
                             if ($gitem['key_'] == $chd_item['key_'] && bccomp($chd_host['hostid'], $chd_item['hostid']) == 0) {
                                 continue 2;
                             }
                         }
                         self::exception(ZBX_API_ERROR_PARAMETERS, sprintf(S_GRAPH_ALREADY_EXISTS_ON, $tmp_graph['name'], $chd_host['host']) . SPACE . S_ITEMS_ARE_NOT_IDENTICAL);
                     }
                     $tmp_graph['graphid'] = $chd_graph['graphid'];
                     self::updateReal($tmp_graph);
                 } else {
                     self::exception(ZBX_API_ERROR_PARAMETERS, sprintf(S_GRAPH_ALREADY_EXISTS_ON, $tmp_graph['name'], $chd_host['host']) . SPACE . S_ITEMS_ARE_NOT_IDENTICAL);
                 }
             } else {
                 $graphid = self::createReal($tmp_graph);
                 $tmp_graph['graphid'] = $graphid;
             }
         }
         self::inherit($tmp_graph);
     }
 }
Example #10
0
 public function setHeader($value = null, $class = 'header')
 {
     if (is_null($class)) {
         $class = $this->headerClass;
     }
     if (is_object($value) && zbx_strtolower(get_class($value)) == 'crow') {
         if (!is_null($class)) {
             $value->setAttribute('class', $class);
         }
     } else {
         $value = new CRow($value, $class);
     }
     $this->colnum = $value->itemsCount();
     $this->header = $value->toString();
 }
Example #11
0
function str2mem($val)
{
    $val = trim($val);
    $last = zbx_strtolower(zbx_substr($val, -1, 1));
    switch ($last) {
        // The 'G' modifier is available since PHP 5.1.0
        case 'g':
            $val *= 1024;
        case 'm':
            $val *= 1024;
        case 'k':
            $val *= 1024;
    }
    return $val;
}
Example #12
0
            if ($data['pageFilter']->groupid > 0) {
                $options['groupids'] = $data['pageFilter']->groupid;
            }
            $data['hosts'] = API::Host()->get($options);
            // copy some inventory fields to the uppers array level for sorting
            // and filter out hosts if we are using filter
            foreach ($data['hosts'] as $num => $host) {
                $data['hosts'][$num]['pr_name'] = $host['inventory']['name'];
                $data['hosts'][$num]['pr_type'] = $host['inventory']['type'];
                $data['hosts'][$num]['pr_os'] = $host['inventory']['os'];
                $data['hosts'][$num]['pr_serialno_a'] = $host['inventory']['serialno_a'];
                $data['hosts'][$num]['pr_tag'] = $host['inventory']['tag'];
                $data['hosts'][$num]['pr_macaddress_a'] = $host['inventory']['macaddress_a'];
                // if we are filtering by inventory field
                if (!empty($data['filterField']) && !empty($data['filterFieldValue'])) {
                    // must we filter exactly or using a substring (both are case insensitive)
                    $match = $data['filterExact'] ? zbx_strtolower($data['hosts'][$num]['inventory'][$data['filterField']]) === zbx_strtolower($data['filterFieldValue']) : zbx_strpos(zbx_strtolower($data['hosts'][$num]['inventory'][$data['filterField']]), zbx_strtolower($data['filterFieldValue'])) !== false;
                    if (!$match) {
                        unset($data['hosts'][$num]);
                    }
                }
            }
            order_result($data['hosts'], getPageSortField('name'), getPageSortOrder());
        }
    }
    $data['paging'] = getPagingLine($data['hosts']);
    $hostinventoriesView = new CView('inventory.host.list', $data);
    $hostinventoriesView->render();
    $hostinventoriesView->show();
}
require_once dirname(__FILE__) . '/include/page_footer.php';
Example #13
0
function get_items_data_overview($hostids, $view_style = null)
{
    global $USER_DETAILS;
    if (is_null($view_style)) {
        $view_style = CProfile::get('web.overview.view.style', STYLE_TOP);
    }
    $table = new CTableInfo(S_NO_ITEMS_DEFINED);
    // COpt::profiling_start('prepare_data');
    $result = DBselect('SELECT DISTINCT h.hostid, h.host,i.itemid, i.key_, i.value_type, i.lastvalue, i.units, ' . ' i.description, t.priority, i.valuemapid, t.value as tr_value, t.triggerid ' . ' FROM hosts h, items i ' . ' LEFT JOIN functions f on f.itemid=i.itemid ' . ' LEFT JOIN triggers t on t.triggerid=f.triggerid and t.status=' . TRIGGER_STATUS_ENABLED . ' WHERE ' . DBcondition('h.hostid', $hostids) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' ORDER BY i.description,i.itemid');
    unset($items);
    unset($hosts);
    // get rid of warnings about $triggers undefined
    $items = array();
    while ($row = DBfetch($result)) {
        $descr = item_description($row);
        $row['host'] = get_node_name_by_elid($row['hostid'], null, ': ') . $row['host'];
        $hosts[zbx_strtolower($row['host'])] = $row['host'];
        // A little tricky check for attempt to overwrite active trigger (value=1) with
        // inactive or active trigger with lower priority.
        if (!isset($items[$descr][$row['host']]) || ($items[$descr][$row['host']]['tr_value'] == TRIGGER_VALUE_FALSE && $row['tr_value'] == TRIGGER_VALUE_TRUE || ($items[$descr][$row['host']]['tr_value'] == TRIGGER_VALUE_FALSE || $row['tr_value'] == TRIGGER_VALUE_TRUE) && $row['priority'] > $items[$descr][$row['host']]['severity'])) {
            $items[$descr][$row['host']] = array('itemid' => $row['itemid'], 'value_type' => $row['value_type'], 'lastvalue' => $row['lastvalue'], 'units' => $row['units'], 'description' => $row['description'], 'valuemapid' => $row['valuemapid'], 'severity' => $row['priority'], 'tr_value' => $row['tr_value'], 'triggerid' => $row['triggerid']);
        }
    }
    if (!isset($hosts)) {
        return $table;
    }
    ksort($hosts, SORT_STRING);
    // COpt::profiling_stop('prepare_data');
    // COpt::profiling_start('prepare_table');
    $css = getUserTheme($USER_DETAILS);
    $vTextColor = $css == 'css_od.css' ? '&color=white' : '';
    if ($view_style == STYLE_TOP) {
        $header = array(new CCol(S_ITEMS, 'center'));
        foreach ($hosts as $hostname) {
            $header = array_merge($header, array(new CImg('vtext.php?text=' . $hostname . $vTextColor)));
        }
        $table->SetHeader($header, 'vertical_header');
        $curr_rime = time();
        foreach ($items as $descr => $ithosts) {
            $table_row = array(nbsp($descr));
            foreach ($hosts as $hostname) {
                $table_row = get_item_data_overview_cells($table_row, $ithosts, $hostname);
            }
            $table->AddRow($table_row);
        }
    } else {
        $header = array(new CCol(S_HOSTS, 'center'));
        foreach ($items as $descr => $ithosts) {
            $header = array_merge($header, array(new CImg('vtext.php?text=' . $descr . $vTextColor)));
        }
        $table->SetHeader($header, 'vertical_header');
        $curr_rime = time();
        foreach ($hosts as $hostname) {
            $table_row = array(nbsp($hostname));
            foreach ($items as $descr => $ithosts) {
                $table_row = get_item_data_overview_cells($table_row, $ithosts, $hostname);
            }
            $table->AddRow($table_row);
        }
    }
    // COpt::profiling_stop('prepare_table');
    return $table;
}
Example #14
0
function show_messages($bool = true, $okmsg = null, $errmsg = null)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        return null;
    }
    if (defined('ZBX_API_REQUEST')) {
        return null;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $imageMessages = array();
    if (!$bool && !is_null($errmsg)) {
        $msg = _('ERROR') . ': ' . $errmsg;
    } elseif ($bool && !is_null($okmsg)) {
        $msg = $okmsg;
    }
    if (isset($msg)) {
        switch ($page['type']) {
            case PAGE_TYPE_IMAGE:
                // save all of the messages in an array to display them later in an image
                $imageMessages[] = array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68));
                break;
            case PAGE_TYPE_XML:
                echo htmlspecialchars($msg) . "\n";
                break;
            case PAGE_TYPE_HTML:
            default:
                $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr');
                $msg_tab->setCellPadding(0);
                $msg_tab->setCellSpacing(0);
                $row = array();
                $msg_col = new CCol(bold($msg), 'msg_main msg');
                $msg_col->setAttribute('id', 'page_msg');
                $row[] = $msg_col;
                if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
                    $msg_details = new CDiv(_('Details'), 'blacklink');
                    $msg_details->setAttribute('onclick', 'javascript: showHide("msg_messages", IE ? "block" : "table");');
                    $msg_details->setAttribute('title', _('Maximize') . '/' . _('Minimize'));
                    array_unshift($row, new CCol($msg_details, 'clr'));
                }
                $msg_tab->addRow($row);
                $msg_tab->show();
                break;
        }
    }
    if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
        if ($page['type'] == PAGE_TYPE_IMAGE) {
            foreach ($ZBX_MESSAGES as $msg) {
                // save all of the messages in an array to display them later in an image
                if ($msg['type'] == 'error') {
                    $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55));
                } else {
                    $imageMessages[] = array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55));
                }
            }
        } elseif ($page['type'] == PAGE_TYPE_XML) {
            foreach ($ZBX_MESSAGES as $msg) {
                echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n";
            }
        } else {
            $lst_error = new CList(null, 'messages');
            foreach ($ZBX_MESSAGES as $msg) {
                $lst_error->addItem($msg['message'], $msg['type']);
                $bool = $bool && 'error' != zbx_strtolower($msg['type']);
            }
            $msg_show = 6;
            $msg_count = count($ZBX_MESSAGES);
            if ($msg_count > $msg_show) {
                $msg_count = $msg_show * 16;
                $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;');
            }
            $tab = new CTable(null, $bool ? 'msgok' : 'msgerr');
            $tab->setCellPadding(0);
            $tab->setCellSpacing(0);
            $tab->setAttribute('id', 'msg_messages');
            $tab->setAttribute('style', 'width: 100%;');
            if (isset($msg_tab) && $bool) {
                $tab->setAttribute('style', 'display: none;');
            }
            $tab->addRow(new CCol($lst_error, 'msg'));
            $tab->show();
        }
        $ZBX_MESSAGES = null;
    }
    // draw an image with the messages
    if ($page['type'] == PAGE_TYPE_IMAGE && count($imageMessages) > 0) {
        $imageFontSize = 8;
        // calculate the size of the text
        $imageWidth = 0;
        $imageHeight = 0;
        foreach ($imageMessages as &$msg) {
            $size = imageTextSize($imageFontSize, 0, $msg['text']);
            $msg['height'] = $size['height'] - $size['baseline'];
            // calculate the total size of the image
            $imageWidth = max($imageWidth, $size['width']);
            $imageHeight += $size['height'] + 1;
        }
        unset($msg);
        // additional padding
        $imageWidth += 2;
        $imageHeight += 2;
        // create the image
        $canvas = imagecreate($imageWidth, $imageHeight);
        imagefilledrectangle($canvas, 0, 0, $imageWidth, $imageHeight, imagecolorallocate($canvas, 255, 255, 255));
        // draw each message
        $y = 1;
        foreach ($imageMessages as $msg) {
            $y += $msg['height'];
            imageText($canvas, $imageFontSize, 0, 1, $y, imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']), $msg['text']);
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}
 public function addRow($item1, $item2 = null, $class = null, $id = null)
 {
     if (is_object($item1) && zbx_strtolower(get_class($item1)) == 'crow') {
     } elseif (is_object($item1) && zbx_strtolower(get_class($item1)) == 'ctable') {
         $td = new CCol($item1, 'form_row_c');
         $td->setColSpan(2);
         $item1 = new CRow($td);
     } else {
         if (is_string($item1)) {
             $item1 = nbsp($item1);
         }
         if (empty($item1)) {
             $item1 = SPACE;
         }
         if (empty($item2)) {
             $item2 = SPACE;
         }
         $item1 = new CRow(array(new CCol($item1, 'form_row_l'), new CCol($item2, 'form_row_r')), $class);
     }
     if (!is_null($id)) {
         $item1->attr('id', zbx_formatDomId($id));
     }
     array_push($this->center_items, $item1);
     return $item1;
 }
 public function addRow($item1, $item2 = NULL, $class = NULL)
 {
     if (is_object($item1) && zbx_strtolower(get_class($item1)) == 'crow') {
     } else {
         if (is_object($item1) && zbx_strtolower(get_class($item1)) == 'ctable') {
             $td = new CCol($item1, 'form_row_c');
             $td->setColSpan(2);
             $item1 = new CRow($td);
         } else {
             $tmp = $item1;
             if (is_string($item1)) {
                 $item1 = nbsp($item1);
             }
             if (empty($item1)) {
                 $item1 = SPACE;
             }
             if (empty($item2)) {
                 $item2 = SPACE;
             }
             $item1 = new CRow(array(new CCol($item1, 'form_row_l'), new CCol($item2, 'form_row_r')), $class);
         }
     }
     array_push($this->center_items, $item1);
     return $item1;
 }
Example #17
0
 /**
  * Decodes a JSON string into appropriate variable.
  *
  * Note: several changes were made in translating this method from
  * Services_JSON, particularly related to how strings are handled. According
  * to JSON_checker test suite from <http://www.json.org/JSON_checker/>,
  * a JSON payload should be an object or an array, not a string.
  *
  * Therefore, returning bool(true) for 'true' is invalid JSON decoding
  * behavior, unless nested inside of an array or object.
  *
  * Similarly, a string of '1' should return null, not int(1), unless
  * nested inside of an array or object.
  *
  * @param string $str String encoded in JSON format
  * @param bool $asArray Optional argument to decode as an array.
  * @return mixed decoded value
  * @todo Rewrite this based off of method used in Solar_Json_Checker
  */
 protected function _json_decode($str, $asArray = false)
 {
     $str = $this->_reduce_string($str);
     switch (zbx_strtolower($str)) {
         case 'true':
             // JSON_checker test suite claims
             // "A JSON payload should be an object or array, not a string."
             // Thus, returning bool(true) is invalid parsing, unless
             // we're nested inside an array or object.
             if (in_array($this->_level, array(self::IN_ARR, self::IN_OBJ))) {
                 return true;
             } else {
                 return null;
             }
             break;
         case 'false':
             // JSON_checker test suite claims
             // "A JSON payload should be an object or array, not a string."
             // Thus, returning bool(false) is invalid parsing, unless
             // we're nested inside an array or object.
             if (in_array($this->_level, array(self::IN_ARR, self::IN_OBJ))) {
                 return false;
             } else {
                 return null;
             }
             break;
         case 'null':
             return null;
         default:
             $m = array();
             if (is_numeric($str) || ctype_digit($str) || ctype_xdigit($str)) {
                 // return float or int, or null as appropriate
                 if (in_array($this->_level, array(self::IN_ARR, self::IN_OBJ))) {
                     return (double) $str == (int) $str ? (int) $str : (double) $str;
                 } else {
                     return null;
                 }
                 break;
             } elseif (preg_match('/^("|\').*(\\1)$/s', $str, $m) && $m[1] == $m[2]) {
                 // strings returned in UTF-8 format
                 $delim = substr($str, 0, 1);
                 $chrs = substr($str, 1, -1);
                 $utf8 = '';
                 $strlen_chrs = zbx_strlen($chrs);
                 for ($c = 0; $c < $strlen_chrs; ++$c) {
                     $substr_chrs_c_2 = substr($chrs, $c, 2);
                     $ord_chrs_c = ord($chrs[$c]);
                     switch (true) {
                         case $substr_chrs_c_2 == '\\b':
                             $utf8 .= chr(0x8);
                             ++$c;
                             break;
                         case $substr_chrs_c_2 == '\\t':
                             $utf8 .= chr(0x9);
                             ++$c;
                             break;
                         case $substr_chrs_c_2 == '\\n':
                             $utf8 .= chr(0xa);
                             ++$c;
                             break;
                         case $substr_chrs_c_2 == '\\f':
                             $utf8 .= chr(0xc);
                             ++$c;
                             break;
                         case $substr_chrs_c_2 == '\\r':
                             $utf8 .= chr(0xd);
                             ++$c;
                             break;
                         case $substr_chrs_c_2 == '\\"':
                         case $substr_chrs_c_2 == '\\\'':
                         case $substr_chrs_c_2 == '\\\\':
                         case $substr_chrs_c_2 == '\\/':
                             if ($delim == '"' && $substr_chrs_c_2 != '\\\'' || $delim == "'" && $substr_chrs_c_2 != '\\"') {
                                 $utf8 .= $chrs[++$c];
                             }
                             break;
                         case preg_match('/\\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
                             // single, escaped unicode character
                             $utf16 = chr(hexdec(substr($chrs, $c + 2, 2))) . chr(hexdec(substr($chrs, $c + 4, 2)));
                             $utf8 .= $this->_utf162utf8($utf16);
                             $c += 5;
                             break;
                         case $ord_chrs_c >= 0x20 && $ord_chrs_c <= 0x7f:
                             $utf8 .= $chrs[$c];
                             break;
                         case ($ord_chrs_c & 0xe0) == 0xc0:
                             // characters U-00000080 - U-000007FF, mask 110XXXXX
                             //see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                             $utf8 .= substr($chrs, $c, 2);
                             ++$c;
                             break;
                         case ($ord_chrs_c & 0xf0) == 0xe0:
                             // characters U-00000800 - U-0000FFFF, mask 1110XXXX
                             // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                             $utf8 .= substr($chrs, $c, 3);
                             $c += 2;
                             break;
                         case ($ord_chrs_c & 0xf8) == 0xf0:
                             // characters U-00010000 - U-001FFFFF, mask 11110XXX
                             // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                             $utf8 .= substr($chrs, $c, 4);
                             $c += 3;
                             break;
                         case ($ord_chrs_c & 0xfc) == 0xf8:
                             // characters U-00200000 - U-03FFFFFF, mask 111110XX
                             // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                             $utf8 .= substr($chrs, $c, 5);
                             $c += 4;
                             break;
                         case ($ord_chrs_c & 0xfe) == 0xfc:
                             // characters U-04000000 - U-7FFFFFFF, mask 1111110X
                             // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
                             $utf8 .= substr($chrs, $c, 6);
                             $c += 5;
                             break;
                     }
                 }
                 if (in_array($this->_level, array(self::IN_ARR, self::IN_OBJ))) {
                     return $utf8;
                 } else {
                     return null;
                 }
             } elseif (preg_match('/^\\[.*\\]$/s', $str) || preg_match('/^\\{.*\\}$/s', $str)) {
                 // array, or object notation
                 if ($str[0] == '[') {
                     $stk = array(self::IN_ARR);
                     $this->_level = self::IN_ARR;
                     $arr = array();
                 } else {
                     if ($asArray) {
                         $stk = array(self::IN_OBJ);
                         $obj = array();
                     } else {
                         $stk = array(self::IN_OBJ);
                         $obj = new stdClass();
                     }
                     $this->_level = self::IN_OBJ;
                 }
                 array_push($stk, array('what' => self::SLICE, 'where' => 0, 'delim' => false));
                 $chrs = substr($str, 1, -1);
                 $chrs = $this->_reduce_string($chrs);
                 if ($chrs == '') {
                     if (reset($stk) == self::IN_ARR) {
                         return $arr;
                     } else {
                         return $obj;
                     }
                 }
                 $strlen_chrs = zbx_strlen($chrs);
                 for ($c = 0; $c <= $strlen_chrs; ++$c) {
                     $top = end($stk);
                     $substr_chrs_c_2 = substr($chrs, $c, 2);
                     if ($c == $strlen_chrs || $chrs[$c] == ',' && $top['what'] == self::SLICE) {
                         // found a comma that is not inside a string, array, etc.,
                         // OR we've reached the end of the character list
                         $slice = substr($chrs, $top['where'], $c - $top['where']);
                         array_push($stk, array('what' => self::SLICE, 'where' => $c + 1, 'delim' => false));
                         if (reset($stk) == self::IN_ARR) {
                             $this->_level = self::IN_ARR;
                             // we are in an array, so just push an element onto the stack
                             array_push($arr, $this->_json_decode($slice, $asArray));
                         } elseif (reset($stk) == self::IN_OBJ) {
                             $this->_level = self::IN_OBJ;
                             // we are in an object, so figure
                             // out the property name and set an
                             // element in an associative array,
                             // for now
                             $parts = array();
                             if (preg_match('/^\\s*(["\'].*[^\\\\]["\'])\\s*:\\s*(\\S.*),?$/Uis', $slice, $parts)) {
                                 // "name":value pair
                                 $key = $this->_json_decode($parts[1], $asArray);
                                 $val = $this->_json_decode($parts[2], $asArray);
                                 if ($asArray) {
                                     $obj[$key] = $val;
                                 } else {
                                     $obj->{$key} = $val;
                                 }
                             } elseif (preg_match('/^\\s*(\\w+)\\s*:\\s*(\\S.*),?$/Uis', $slice, $parts)) {
                                 // name:value pair, where name is unquoted
                                 $key = $parts[1];
                                 $val = $this->_json_decode($parts[2], $asArray);
                                 if ($asArray) {
                                     $obj[$key] = $val;
                                 } else {
                                     $obj->{$key} = $val;
                                 }
                             } elseif (preg_match('/^\\s*(["\']["\'])\\s*:\\s*(\\S.*),?$/Uis', $slice, $parts)) {
                                 // "":value pair
                                 //$key = $this->_json_decode($parts[1]);
                                 // use string that matches ext/json
                                 $key = '_empty_';
                                 $val = $this->_json_decode($parts[2], $asArray);
                                 if ($asArray) {
                                     $obj[$key] = $val;
                                 } else {
                                     $obj->{$key} = $val;
                                 }
                             }
                         }
                     } elseif (($chrs[$c] == '"' || $chrs[$c] == "'") && $top['what'] != self::IN_STR) {
                         // found a quote, and we are not inside a string
                         array_push($stk, array('what' => self::IN_STR, 'where' => $c, 'delim' => $chrs[$c]));
                     } elseif ($chrs[$c] == $top['delim'] && $top['what'] == self::IN_STR && (zbx_strlen(substr($chrs, 0, $c)) - zbx_strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1) {
                         // found a quote, we're in a string, and it's not escaped
                         // we know that it's not escaped becase there is _not_ an
                         // odd number of backslashes at the end of the string so far
                         array_pop($stk);
                     } elseif ($chrs[$c] == '[' && in_array($top['what'], array(self::SLICE, self::IN_ARR, self::IN_OBJ))) {
                         // found a left-bracket, and we are in an array, object, or slice
                         array_push($stk, array('what' => self::IN_ARR, 'where' => $c, 'delim' => false));
                     } elseif ($chrs[$c] == ']' && $top['what'] == self::IN_ARR) {
                         // found a right-bracket, and we're in an array
                         $this->_level = null;
                         array_pop($stk);
                     } elseif ($chrs[$c] == '{' && in_array($top['what'], array(self::SLICE, self::IN_ARR, self::IN_OBJ))) {
                         // found a left-brace, and we are in an array, object, or slice
                         array_push($stk, array('what' => self::IN_OBJ, 'where' => $c, 'delim' => false));
                     } elseif ($chrs[$c] == '}' && $top['what'] == self::IN_OBJ) {
                         // found a right-brace, and we're in an object
                         $this->_level = null;
                         array_pop($stk);
                     } elseif ($substr_chrs_c_2 == '/*' && in_array($top['what'], array(self::SLICE, self::IN_ARR, self::IN_OBJ))) {
                         // found a comment start, and we are in an array, object, or slice
                         array_push($stk, array('what' => self::IN_CMT, 'where' => $c, 'delim' => false));
                         $c++;
                     } elseif ($substr_chrs_c_2 == '*/' && $top['what'] == self::IN_CMT) {
                         // found a comment end, and we're in one now
                         array_pop($stk);
                         $c++;
                         for ($i = $top['where']; $i <= $c; ++$i) {
                             $chrs = substr_replace($chrs, ' ', $i, 1);
                         }
                     }
                 }
                 if (reset($stk) == self::IN_ARR) {
                     return $arr;
                 } elseif (reset($stk) == self::IN_OBJ) {
                     return $obj;
                 }
             }
     }
 }
Example #18
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;
}
     $options['groupids'] = $pageFilter->groupid;
 }
 $hosts = API::Host()->get($options);
 // copy some inventory fields to the uppers array level for sorting
 // and filter out hosts if we are using filter
 foreach ($hosts as $num => $host) {
     $hosts[$num]['pr_name'] = $host['inventory']['name'];
     $hosts[$num]['pr_type'] = $host['inventory']['type'];
     $hosts[$num]['pr_os'] = $host['inventory']['os'];
     $hosts[$num]['pr_serialno_a'] = $host['inventory']['serialno_a'];
     $hosts[$num]['pr_tag'] = $host['inventory']['tag'];
     $hosts[$num]['pr_macaddress_a'] = $host['inventory']['macaddress_a'];
     // if we are filtering by inventory field
     if (!empty($_REQUEST['filter_field']) && !empty($_REQUEST['filter_field_value'])) {
         // must we filter exactly or using a substring (both are case insensitive)
         $match = $_REQUEST['filter_exact'] ? zbx_strtolower($hosts[$num]['inventory'][$_REQUEST['filter_field']]) === zbx_strtolower($_REQUEST['filter_field_value']) : zbx_strpos(zbx_strtolower($hosts[$num]['inventory'][$_REQUEST['filter_field']]), zbx_strtolower($_REQUEST['filter_field_value'])) !== false;
         if (!$match) {
             unset($hosts[$num]);
         }
     }
 }
 order_result($hosts, getPageSortField('name'), getPageSortOrder());
 $paging = getPagingLine($hosts);
 foreach ($hosts as $host) {
     $host_groups = array();
     foreach ($host['groups'] as $group) {
         $host_groups[] = $group['name'];
     }
     natsort($host_groups);
     $host_groups = implode(', ', $host_groups);
     $row = array(get_node_name_by_elid($host['hostid']), new CLink($host['name'], '?hostid=' . $host['hostid'] . url_param('groupid')), $host_groups, zbx_str2links($host['inventory']['name']), zbx_str2links($host['inventory']['type']), zbx_str2links($host['inventory']['os']), zbx_str2links($host['inventory']['serialno_a']), zbx_str2links($host['inventory']['tag']), zbx_str2links($host['inventory']['macaddress_a']));
Example #20
0
function show_messages($bool = TRUE, $okmsg = NULL, $errmsg = NULL)
{
    global $page, $ZBX_MESSAGES;
    if (!defined('PAGE_HEADER_LOADED')) {
        return;
    }
    if (defined('ZBX_API_REQUEST')) {
        return;
    }
    if (!isset($page['type'])) {
        $page['type'] = PAGE_TYPE_HTML;
    }
    $message = array();
    $width = 0;
    $height = 0;
    $img_space = null;
    if (!$bool && !is_null($errmsg)) {
        $msg = S_CONFIG_ERROR_HEAD . ': ' . $errmsg;
    } else {
        if ($bool && !is_null($okmsg)) {
            $msg = $okmsg;
        }
    }
    $api_errors = CZBXAPI::resetErrors();
    if (!empty($api_errors)) {
        error($api_errors);
    }
    if (isset($msg)) {
        switch ($page['type']) {
            case PAGE_TYPE_IMAGE:
                array_push($message, array('text' => $msg, 'color' => !$bool ? array('R' => 255, 'G' => 0, 'B' => 0) : array('R' => 34, 'G' => 51, 'B' => 68), 'font' => 2));
                $width = max($width, ImageFontWidth(2) * zbx_strlen($msg) + 1);
                $height += imagefontheight(2) + 1;
                break;
            case PAGE_TYPE_XML:
                echo htmlspecialchars($msg) . "\n";
                break;
                //				case PAGE_TYPE_JS: break;
            //				case PAGE_TYPE_JS: break;
            case PAGE_TYPE_HTML:
            default:
                $msg_tab = new CTable($msg, $bool ? 'msgok' : 'msgerr');
                $msg_tab->setCellPadding(0);
                $msg_tab->setCellSpacing(0);
                $row = array();
                $msg_col = new CCol(bold($msg), 'msg_main msg');
                $msg_col->setAttribute('id', 'page_msg');
                $row[] = $msg_col;
                if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
                    $msg_details = new CDiv(S_DETAILS, 'blacklink');
                    $msg_details->setAttribute('onclick', "javascript: ShowHide('msg_messages', IE?'block':'table');");
                    $msg_details->setAttribute('title', S_MAXIMIZE . '/' . S_MINIMIZE);
                    array_unshift($row, new CCol($msg_details, 'clr'));
                }
                $msg_tab->addRow($row);
                $msg_tab->show();
                $img_space = new CImg('images/general/tree/zero.gif', 'space', '100', '2');
                break;
        }
    }
    if (isset($ZBX_MESSAGES) && !empty($ZBX_MESSAGES)) {
        if ($page['type'] == PAGE_TYPE_IMAGE) {
            $msg_font = 2;
            foreach ($ZBX_MESSAGES as $msg) {
                if ($msg['type'] == 'error') {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 255, 'G' => 55, 'B' => 55), 'font' => $msg_font));
                } else {
                    array_push($message, array('text' => $msg['message'], 'color' => array('R' => 155, 'G' => 155, 'B' => 55), 'font' => $msg_font));
                }
                $width = max($width, imagefontwidth($msg_font) * zbx_strlen($msg['message']) + 1);
                $height += imagefontheight($msg_font) + 1;
            }
        } else {
            if ($page['type'] == PAGE_TYPE_XML) {
                foreach ($ZBX_MESSAGES as $msg) {
                    echo '[' . $msg['type'] . '] ' . $msg['message'] . "\n";
                }
            } else {
                $lst_error = new CList(null, 'messages');
                foreach ($ZBX_MESSAGES as $msg) {
                    $lst_error->addItem($msg['message'], $msg['type']);
                    $bool = $bool && 'error' != zbx_strtolower($msg['type']);
                }
                //message scroll if needed
                $msg_show = 6;
                $msg_count = count($ZBX_MESSAGES);
                if ($msg_count > $msg_show) {
                    $msg_count = $msg_show;
                    $msg_count = $msg_count * 16;
                    $lst_error->setAttribute('style', 'height: ' . $msg_count . 'px;');
                }
                $tab = new CTable(null, $bool ? 'msgok' : 'msgerr');
                $tab->setCellPadding(0);
                $tab->setCellSpacing(0);
                $tab->setAttribute('id', 'msg_messages');
                $tab->setAttribute('style', 'width: 100%;');
                if (isset($msg_tab) && $bool) {
                    $tab->setAttribute('style', 'display: none;');
                }
                $tab->addRow(new CCol($lst_error, 'msg'));
                $tab->Show();
                //---
            }
        }
        $ZBX_MESSAGES = null;
    }
    if (!is_null($img_space)) {
        print unpack_object($img_space);
    }
    if ($page['type'] == PAGE_TYPE_IMAGE && count($message) > 0) {
        $width += 2;
        $height += 2;
        $canvas = imagecreate($width, $height);
        imagefilledrectangle($canvas, 0, 0, $width, $height, imagecolorallocate($canvas, 255, 255, 255));
        foreach ($message as $id => $msg) {
            $message[$id]['y'] = 1 + (isset($previd) ? $message[$previd]['y'] + $message[$previd]['h'] : 0);
            $message[$id]['h'] = imagefontheight($msg['font']);
            imagestring($canvas, $msg['font'], 1, $message[$id]['y'], $msg['text'], imagecolorallocate($canvas, $msg['color']['R'], $msg['color']['G'], $msg['color']['B']));
            $previd = $id;
        }
        imageOut($canvas);
        imagedestroy($canvas);
    }
}
Example #21
0
function construct_expression($itemid, $expressions)
{
    $complite_expr = '';
    $item = get_item_by_itemid($itemid);
    $host = get_host_by_itemid($itemid);
    $prefix = $host['host'] . ':' . $item['key_'] . '.';
    if (empty($expressions)) {
        error(_('Expression cannot be empty'));
        return false;
    }
    $ZBX_PREG_EXPESSION_FUNC_FORMAT = '^([' . ZBX_PREG_PRINT . ']*)([&|]{1})[(]*(([a-zA-Z_.\\$]{6,7})(\\(([' . ZBX_PREG_PRINT . ']+?){0,1}\\)))([' . ZBX_PREG_PRINT . ']*)$';
    $functions = array('regexp' => 1, 'iregexp' => 1);
    $expr_array = array();
    $cexpor = 0;
    $startpos = -1;
    foreach ($expressions as $expression) {
        $expression['value'] = preg_replace('/\\s+(AND){1,2}\\s+/U', '&', $expression['value']);
        $expression['value'] = preg_replace('/\\s+(OR){1,2}\\s+/U', '|', $expression['value']);
        if ($expression['type'] == REGEXP_INCLUDE) {
            if (!empty($complite_expr)) {
                $complite_expr .= ' | ';
            }
            if ($cexpor == 0) {
                $startpos = zbx_strlen($complite_expr);
            }
            $cexpor++;
            $eq_global = '#0';
        } else {
            if ($cexpor > 1 & $startpos >= 0) {
                $head = substr($complite_expr, 0, $startpos);
                $tail = substr($complite_expr, $startpos);
                $complite_expr = $head . '(' . $tail . ')';
            }
            $cexpor = 0;
            $eq_global = '=0';
            if (!empty($complite_expr)) {
                $complite_expr .= ' & ';
            }
        }
        $expr = '&' . $expression['value'];
        $expr = preg_replace('/\\s+(\\&|\\|){1,2}\\s+/U', '$1', $expr);
        $expr_array = array();
        $sub_expr_count = 0;
        $sub_expr = '';
        $multi = preg_match('/.+(&|\\|).+/', $expr);
        while (preg_match('/' . $ZBX_PREG_EXPESSION_FUNC_FORMAT . '/i', $expr, $arr)) {
            $arr[4] = zbx_strtolower($arr[4]);
            if (!isset($functions[$arr[4]])) {
                error(_('Incorrect function is used') . '. [' . $expression['value'] . ']');
                return false;
            }
            $expr_array[$sub_expr_count]['eq'] = trim($arr[2]);
            $expr_array[$sub_expr_count]['regexp'] = zbx_strtolower($arr[4]) . $arr[5];
            $sub_expr_count++;
            $expr = $arr[1];
        }
        if (empty($expr_array)) {
            error(_('Incorrect trigger expression') . '. [' . $expression['value'] . ']');
            return false;
        }
        $expr_array[$sub_expr_count - 1]['eq'] = '';
        $sub_eq = '';
        if ($multi > 0) {
            $sub_eq = $eq_global;
        }
        foreach ($expr_array as $id => $expr) {
            if ($multi > 0) {
                $sub_expr = $expr['eq'] . '({' . $prefix . $expr['regexp'] . '})' . $sub_eq . $sub_expr;
            } else {
                $sub_expr = $expr['eq'] . '{' . $prefix . $expr['regexp'] . '}' . $sub_eq . $sub_expr;
            }
        }
        if ($multi > 0) {
            $complite_expr .= '(' . $sub_expr . ')';
        } else {
            $complite_expr .= '((' . $sub_expr . ')' . $eq_global . ')';
        }
    }
    if ($cexpor > 1 & $startpos >= 0) {
        $head = substr($complite_expr, 0, $startpos);
        $tail = substr($complite_expr, $startpos);
        $complite_expr = $head . '(' . $tail . ')';
    }
    return $complite_expr;
}
Example #22
0
 public function __construct($url = null)
 {
     $this->url = null;
     $this->port = null;
     $this->host = null;
     $this->protocol = null;
     $this->username = null;
     $this->password = null;
     $this->file = null;
     $this->reference = null;
     $this->path = null;
     $this->query = null;
     $this->arguments = array();
     if (empty($url)) {
         $this->formatGetArguments();
         // $protocol = (zbx_strpos(zbx_strtolower($_SERVER['SERVER_PROTOCOL']), 'shttp') !== false)?'shttp':'http';
         $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || $_SERVER['SERVER_PORT'] == 443 ? 'https' : 'http';
         $this->url = $url = $protocol . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['SCRIPT_NAME'] . '?' . $this->getQuery();
     } else {
         $this->url = $url;
         $tmp_pos = zbx_strpos($this->url, '?');
         $this->query = $tmp_pos !== false ? substr($this->url, $tmp_pos + 1) : '';
         $tmp_pos = zbx_strpos($this->query, '#');
         if ($tmp_pos !== false) {
             $this->query = zbx_substring($this->query, 0, $tmp_pos);
         }
         $this->formatArguments($this->query);
     }
     $protocolSepIndex = zbx_strpos($this->url, '://');
     if ($protocolSepIndex !== false) {
         $this->protocol = zbx_strtolower(zbx_substring($this->url, 0, $protocolSepIndex));
         $this->host = substr($this->url, $protocolSepIndex + 3);
         $tmp_pos = zbx_strpos($this->host, '/');
         if ($tmp_pos !== false) {
             $this->host = zbx_substring($this->host, 0, $tmp_pos);
         }
         $atIndex = zbx_strpos($this->host, '@');
         if ($atIndex !== false) {
             $credentials = zbx_substring($this->host, 0, $atIndex);
             $colonIndex = zbx_strpos(credentials, ':');
             if ($colonIndex !== false) {
                 $this->username = zbx_substring($credentials, 0, $colonIndex);
                 $this->password = substr($credentials, $colonIndex);
             } else {
                 $this->username = $credentials;
             }
             $this->host = substr($this->host, $atIndex + 1);
         }
         $host_ipv6 = zbx_strpos($this->host, ']');
         if ($host_ipv6 !== false) {
             if ($host_ipv6 < zbx_strlen($this->host) - 1) {
                 $host_ipv6++;
                 $host_less = substr($this->host, $host_ipv6);
                 $portColonIndex = zbx_strpos($host_less, ':');
                 if ($portColonIndex !== false) {
                     $this->host = zbx_substring($this->host, 0, $host_ipv6);
                     $this->port = substr($host_less, $portColonIndex + 1);
                 }
             }
         } else {
             $portColonIndex = zbx_strpos($this->host, ':');
             if ($portColonIndex !== false) {
                 $this->port = substr($this->host, $portColonIndex + 1);
                 $this->host = zbx_substring($this->host, 0, $portColonIndex);
             }
         }
         $this->file = substr($this->url, $protocolSepIndex + 3);
         $this->file = substr($this->file, zbx_strpos($this->file, '/'));
         if ($this->file == $this->host) {
             $this->file = '';
         }
     } else {
         $this->file = $this->url;
     }
     $tmp_pos = zbx_strpos($this->file, '?');
     if ($tmp_pos !== false) {
         $this->file = zbx_substring($this->file, 0, $tmp_pos);
     }
     $refSepIndex = zbx_strpos($url, '#');
     if ($refSepIndex !== false) {
         $this->file = zbx_substring($this->file, 0, $refSepIndex);
         $this->reference = substr($url, zbx_strpos($url, '#') + 1);
     }
     $this->path = $this->file;
     if (zbx_strlen($this->query) > 0) {
         $this->file .= '?' . $this->query;
     }
     if (zbx_strlen($this->reference) > 0) {
         $this->file .= '#' . $this->reference;
     }
     if (isset($_COOKIE['zbx_sessionid'])) {
         $this->setArgument('sid', substr($_COOKIE['zbx_sessionid'], 16, 16));
     }
 }
$hostinvent_wdgt->addHeader(_('Hosts'), $r_form);
$hostinvent_wdgt->addItem(BR());
$table = new CTableInfo(_('No hosts defined.'));
$table->setHeader(array(make_sorting_header($groupFieldTitle === '' ? _('Field') : $groupFieldTitle, 'inventory_field'), make_sorting_header(_('Host count'), 'host_count')));
// to show a report, we will need a host group and a field to aggregate
if ($pageFilter->groupsSelected && $groupFieldTitle !== '') {
    $options = array('output' => array('hostid', 'name'), 'selectInventory' => array($_REQUEST['groupby']), 'withInventory' => true);
    if ($pageFilter->groupid > 0) {
        $options['groupids'] = $pageFilter->groupid;
    }
    $hosts = API::Host()->get($options);
    // aggregating data by chosen field value
    $report = array();
    foreach ($hosts as $host) {
        if ($host['inventory'][$_REQUEST['groupby']] !== '') {
            $lowerValue = zbx_strtolower($host['inventory'][$_REQUEST['groupby']]);
            if (!isset($report[$lowerValue])) {
                $report[$lowerValue] = array('inventory_field' => $host['inventory'][$_REQUEST['groupby']], 'host_count' => 1);
            } else {
                $report[$lowerValue]['host_count'] += 1;
            }
        }
    }
    order_result($report, getPageSortField('host_count'), getPageSortOrder());
    foreach ($report as $rep) {
        $row = array(new CSpan($rep['inventory_field'], 'pre'), new CLink($rep['host_count'], 'hostinventories.php?filter_field=' . $_REQUEST['groupby'] . '&filter_field_value=' . urlencode($rep['inventory_field']) . '&filter_set=1&filter_exact=1' . url_param('groupid')));
        $table->addRow($row);
    }
}
$hostinvent_wdgt->addItem($table);
$hostinvent_wdgt->show();
Example #24
0
function get_triggers_overview($hostids, $view_style = null)
{
    global $USER_DETAILS;
    if (is_null($view_style)) {
        $view_style = CProfile::get('web.overview.view.style', STYLE_TOP);
    }
    $table = new CTableInfo(S_NO_TRIGGERS_DEFINED);
    $options = array('hostids' => $hostids, 'monitored' => 1, 'expandData' => 1, 'skipDependent' => 1, 'output' => API_OUTPUT_EXTEND, 'sortfield' => 'description');
    $db_triggers = CTrigger::get($options);
    unset($triggers);
    unset($hosts);
    $triggers = array();
    foreach ($db_triggers as $tnum => $row) {
        $row['host'] = get_node_name_by_elid($row['hostid'], null, ': ') . $row['host'];
        $row['description'] = expand_trigger_description_constants($row['description'], $row);
        $hosts[zbx_strtolower($row['host'])] = $row['host'];
        // A little tricky check for attempt to overwrite active trigger (value=1) with
        // inactive or active trigger with lower priority.
        if (!isset($triggers[$row['description']][$row['host']]) || ($triggers[$row['description']][$row['host']]['value'] == TRIGGER_VALUE_FALSE && $row['value'] == TRIGGER_VALUE_TRUE || ($triggers[$row['description']][$row['host']]['value'] == TRIGGER_VALUE_FALSE || $row['value'] == TRIGGER_VALUE_TRUE) && $row['priority'] > $triggers[$row['description']][$row['host']]['priority'])) {
            $triggers[$row['description']][$row['host']] = array('hostid' => $row['hostid'], 'triggerid' => $row['triggerid'], 'value' => $row['value'], 'lastchange' => $row['lastchange'], 'priority' => $row['priority']);
        }
    }
    if (!isset($hosts)) {
        return $table;
    }
    ksort($hosts);
    $css = getUserTheme($USER_DETAILS);
    $vTextColor = $css == 'css_od.css' ? '&color=white' : '';
    if ($view_style == STYLE_TOP) {
        $header = array(new CCol(S_TRIGGERS, 'center'));
        foreach ($hosts as $hostname) {
            $header = array_merge($header, array(new CCol(array(new CImg('vtext.php?text=' . $hostname . $vTextColor)), 'hosts')));
        }
        $table->setHeader($header, 'vertical_header');
        foreach ($triggers as $descr => $trhosts) {
            $table_row = array(nbsp($descr));
            foreach ($hosts as $hostname) {
                $table_row = get_trigger_overview_cells($table_row, $trhosts, $hostname);
            }
            $table->addRow($table_row);
        }
    } else {
        $header = array(new CCol(S_HOSTS, 'center'));
        foreach ($triggers as $descr => $trhosts) {
            $descr = array(new CImg('vtext.php?text=' . $descr . $vTextColor));
            array_push($header, $descr);
        }
        $table->setHeader($header, 'vertical_header');
        foreach ($hosts as $hostname) {
            $table_row = array(nbsp($hostname));
            foreach ($triggers as $descr => $trhosts) {
                $table_row = get_trigger_overview_cells($table_row, $trhosts, $hostname);
            }
            $table->addRow($table_row);
        }
    }
    return $table;
}