예제 #1
0
파일: html.inc.php 프로젝트: rennhak/zabbix
function bfirst($str)
{
    // mark first symbol of string as bold
    $res = bold($str[0]);
    for ($i = 1, $max = strlen($str); $i < $max; $i++) {
        $res .= $str[$i];
    }
    $str = $res;
    return $str;
}
예제 #2
0
function make_decoration($haystack, $needle, $class = null)
{
    $result = $haystack;
    $pos = stripos($haystack, $needle);
    if ($pos !== FALSE) {
        $start = zbx_substring($haystack, 0, $pos);
        //			$middle = substr($haystack, $pos, zbx_strlen($needle));
        $middle = $needle;
        $end = substr($haystack, $pos + zbx_strlen($needle));
        if (is_null($class)) {
            $result = array($start, bold($middle), $end);
        } else {
            $result = array($start, new CSpan($middle, $class), $end);
        }
    }
    return $result;
}
예제 #3
0
    function tablesPrint($tables)
    {
        ?>
<script type="text/javascript">
function tablesFilter(value) {
	var tables = document.getElementById('tables').getElementsByTagName('span');
	for (var i = tables.length; i--; ) {
		var a = tables[i].children[1];
		var text = a.innerText || a.textContent;
		tables[i].className = (text.indexOf(value) == -1 ? 'hidden' : '');
		a.innerHTML = text.replace(value, '<b>' + value + '</b>');
	}
}
</script>
<p class="jsonly"><input onkeyup="tablesFilter(this.value);">
<?php 
        echo "<p id='tables' onmouseover='menuOver(this, event);' onmouseout='menuOut(this);'>\n";
        foreach ($tables as $table => $type) {
            echo '<span><a href="' . h(ME) . 'select=' . urlencode($table) . '"' . bold($_GET["select"] == $table) . ">" . lang('select') . "</a> ";
            echo '<a href="' . h(ME) . 'table=' . urlencode($table) . '"' . bold($_GET["table"] == $table) . ">" . h($table) . "</a><br></span>\n";
        }
        return true;
    }
예제 #4
0
 /** Prints table list in menu
  * @param array result of table_status('', true)
  * @return null
  */
 function tablesPrint($tables)
 {
     echo "<p id='tables' onmouseover='menuOver(this, event);' onmouseout='menuOut(this);'>\n";
     foreach ($tables as $table => $status) {
         echo '<a href="' . h(ME) . 'select=' . urlencode($table) . '"' . bold($_GET["select"] == $table || $_GET["edit"] == $table, "select") . ">" . lang('select') . "</a> ";
         $name = $this->tableName($status);
         echo (support("table") || support("indexes") ? '<a href="' . h(ME) . 'table=' . urlencode($table) . '"' . bold(in_array($table, array($_GET["table"], $_GET["create"], $_GET["indexes"], $_GET["foreign"], $_GET["trigger"])), is_view($status) ? "view" : "", "structure") . " title='" . lang('Show structure') . "'>{$name}</a>" : "<span>{$name}</span>") . "<br>\n";
     }
 }
     $_REQUEST['filter_field'] = CProfile::get('web.hostinventories.filter_field');
     $_REQUEST['filter_field_value'] = CProfile::get('web.hostinventories.filter_field_value');
     $_REQUEST['filter_exact'] = CProfile::get('web.hostinventories.filter_exact');
 }
 $filter_table = new CTable('', 'filter');
 // getting inventory fields to make a drop down
 $inventoryFields = getHostInventories(true);
 // 'true' means list should be ordered by title
 $inventoryFieldsComboBox = new CComboBox('filter_field', $_REQUEST['filter_field']);
 foreach ($inventoryFields as $inventoryField) {
     $inventoryFieldsComboBox->addItem($inventoryField['db_field'], $inventoryField['title']);
 }
 $exactComboBox = new CComboBox('filter_exact', $_REQUEST['filter_exact']);
 $exactComboBox->addItem('0', _('like'));
 $exactComboBox->addItem('1', _('exactly'));
 $filter_table->addRow(array(array(array(bold(_('Field:')), $inventoryFieldsComboBox), array($exactComboBox, new CTextBox('filter_field_value', $_REQUEST['filter_field_value'], 20)))));
 $filter = new CButton('filter', _('Filter'), "javascript: create_var('zbx_filter', 'filter_set', '1', true);");
 $filter->useJQueryStyle('main');
 $reset = new CButton('reset', _('Reset'), "javascript: clearAllForm('zbx_filter');");
 $reset->useJQueryStyle();
 $div_buttons = new CDiv(array($filter, SPACE, $reset));
 $div_buttons->setAttribute('style', 'padding: 4px 0px;');
 $footer_col = new CCol($div_buttons, 'controls');
 $filter_table->addRow($footer_col);
 $filter_form = new CForm('get');
 $filter_form->setAttribute('name', 'zbx_filter');
 $filter_form->setAttribute('id', 'zbx_filter');
 $filter_form->addItem($filter_table);
 $hostinvent_wdgt->addFlicker($filter_form, CProfile::get('web.hostinventories.filter.state', 0));
 $hostinvent_wdgt->addHeaderRowNumber();
 $table = new CTableInfo(_('No hosts defined.'));
예제 #6
0
파일: latest.php 프로젝트: rennhak/zabbix
unset($db_host);
foreach ($db_hosts as $hostid => $db_host) {
    if (!isset($tab_rows[$hostid])) {
        continue;
    }
    $app_rows = $tab_rows[$hostid];
    if (uint_in_array(0, $_REQUEST['applications']) || isset($show_all_apps)) {
        $url = '?close=1&applicationid=0' . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select');
        $link = new CLink(new CImg('images/general/opened.gif'), $url);
        //			$link = new CLink(new CImg('images/general/opened.gif'),$url,null,"javascript: return updater.onetime_update('".ZBX_PAGE_MAIN_HAT."','".$url."');");
    } else {
        $url = '?open=1&applicationid=0' . url_param('groupid') . url_param('hostid') . url_param('applications') . url_param('select');
        $link = new CLink(new CImg('images/general/closed.gif'), $url);
        //			$link = new CLink(new CImg('images/general/closed.gif'),$url,null,"javascript: return updater.onetime_update('".ZBX_PAGE_MAIN_HAT."','".$url."');");
    }
    $col = new CCol(array($link, SPACE, bold(S_MINUS_OTHER_MINUS), SPACE . '(' . $db_host['item_cnt'] . SPACE . S_ITEMS . ')'));
    $col->SetColSpan(5);
    $table->AddRow(array(get_node_name_by_elid($db_host['hostid']), $_REQUEST['hostid'] > 0 ? NULL : $db_host['host'], $col));
    foreach ($app_rows as $row) {
        $table->AddRow($row);
    }
}
$p_elements[] = $table;
/*
// Refresh tab
	$refresh_tab = array(
		array('id'	=> ZBX_PAGE_MAIN_HAT,
				'interval' 	=> $USER_DETAILS['refresh'],
				'url'	=>	zbx_empty($_SERVER['QUERY_STRING'])?'':'?'.$_SERVER['QUERY_STRING'],
			)
	);
예제 #7
0
파일: index.php 프로젝트: unpetitlu/poo
//        $date = new \DateTime('06/01/2014');
$date = \DateTime::createFromFormat('d/m/Y', '06/01/2014');
echo "Date " . $date->format('d/m/Y');
//instanciation : création de 2 objets User
$user1 = new User('Vincent', 'Phillippe');
$user2 = new User('Elodie', 'Perrotton');
//var_dump($user1);
// une constante d'appel depuis un objet de la clase
echo beautiful($user1->getNom()) . "<br />";
echo beautiful($user1::FORMATION) . "<br />";
// un attribut static s'appel depuis la classe
echo beautiful(User::getLangue()) . "<br />";
echo "<h3>Noms: </h3>";
// appel d'un helper bold() comme beautiful() en dessus en affichant le nom de chaque utilisateur
echo bold($user1->getNom()) . "<br />";
echo bold($user2->getNom()) . "<br />";
$user1->setEnabled(0);
echo beautiful("L'utilisateur " . $user1->getNom() . " est inactif");
echo "<h3>Prenoms: </h3>";
echo $user1->getPrenom() . "<br />";
echo $user2->getPrenom() . "<br />";
echo "<h3>Réactions: </h3>";
echo $user1->reagir("François Hollande est un tres bon président !") . "<br />";
echo $user2->reagir("Nicolas Sarkozy est pas mal physiquement...") . "<br />";
//appel d'une méthodes repond() en envoyant l'utilisateur
echo $user1->repond($user2, "Il ne me plait pas beaucoups le nain de jardin!") . "<br />";
echo $user2->repond($user1, "Remarque le tient, il est aussi grand que sa réputation!") . "<br />";
echo $user1->noter(4);
echo "<h2>Moderateur </h2>";
$moderateur1 = new Moderateur("Oussama", "Ben-Laden", 4);
echo beautiful($moderateur1->modererUser($user2));
예제 #8
0
파일: hosts.php 프로젝트: rennhak/zabbix
 $host = new CCol(array(new CCheckBox('hosts[' . $row['hostid'] . ']', NULL, NULL, $row['hostid']), SPACE, $description));
 if ($show_only_tmp) {
     $dns = NULL;
     $ip = NULL;
     $port = NULL;
     $status = NULL;
     $available = NULL;
     $error = NULL;
 } else {
     $dns = empty($row['dns']) ? '-' : $row['dns'];
     $ip = empty($row['ip']) ? '-' : $row['ip'];
     $port = empty($row['port']) ? '-' : $row['port'];
     if (1 == $row['useip']) {
         $ip = bold($ip);
     } else {
         $dns = bold($dns);
     }
     switch ($row['status']) {
         case HOST_STATUS_MONITORED:
             $status = new CLink(S_MONITORED, 'hosts.php?hosts%5B%5D=' . $row['hostid'] . '&disable=1' . url_param('config') . url_param('groupid'), 'off');
             break;
         case HOST_STATUS_NOT_MONITORED:
             $status = new CLink(S_NOT_MONITORED, 'hosts.php?hosts%5B%5D=' . $row['hostid'] . '&activate=1' . url_param('config') . url_param('groupid'), 'on');
             break;
         case HOST_STATUS_TEMPLAT:
             $status = new CCol(S_TEMPLATE, 'unknown');
             break;
         case HOST_STATUS_DELETED:
             $status = new CCol(S_DELETED, 'unknown');
             break;
         default:
예제 #9
0
/**
 * Builds expression html tree
 *
 * @param array $expressionTree output of getExpressionTree() function
 * @param array $next           parameter only for recursive call; should be empty array
 * @param int $letterNum        parameter only for recursive call; should be 0
 * @param int $level            parameter only for recursive call
 * @param string $operand       parameter only for recursive call
 *
 * @return bool                 returns true if element is found, false - otherwise
 */
function buildExpressionHtmlTree(array $expressionTree, array &$next, &$letterNum, $level = 0, $operand = null)
{
    $treeList = array();
    $outline = '';
    end($expressionTree);
    $lastKey = key($expressionTree);
    foreach ($expressionTree as $key => $element) {
        switch ($element['type']) {
            case 'operand':
                $next[$level] = $key != $lastKey;
                $expr = expressionLevelDraw($next, $level);
                $expr[] = SPACE;
                $expr[] = italic($element['operand'] == '&' ? _('AND') : _('OR'));
                $levelDetails = array('list' => $expr, 'id' => $element['id'], 'expression' => array('value' => $element['expression']));
                $levelErrors = expressionHighLevelErrors($element['expression']);
                if (count($levelErrors) > 0) {
                    $levelDetails['expression']['levelErrors'] = $levelErrors;
                }
                $treeList[] = $levelDetails;
                list($subOutline, $subTreeList) = buildExpressionHtmlTree($element['elements'], $next, $letterNum, $level + 1, $element['operand']);
                $treeList = array_merge($treeList, $subTreeList);
                $outline .= $level == 0 ? $subOutline : '(' . $subOutline . ')';
                if ($operand !== null && $next[$level]) {
                    $outline .= ' ' . $operand . ' ';
                }
                break;
            case 'expression':
                $next[$level] = $key != $lastKey;
                $letter = num2letter($letterNum++);
                $outline .= $letter;
                if ($operand !== null && $next[$level]) {
                    $outline .= ' ' . $operand . ' ';
                }
                if (defined('NO_LINK_IN_TESTING')) {
                    $url = new CSpan($element['expression']);
                } else {
                    $expressionId = 'expr_' . $element['id'];
                    $url = new CSpan($element['expression'], 'link');
                    $url->setAttribute('id', $expressionId);
                    $url->setAttribute('onclick', 'javascript: copy_expression("' . $expressionId . '");');
                }
                $expr = expressionLevelDraw($next, $level);
                $expr[] = SPACE;
                $expr[] = bold($letter);
                $expr[] = SPACE;
                $expr[] = $url;
                $levelDetails = array('list' => $expr, 'id' => $element['id'], 'expression' => array('value' => $element['expression']));
                $levelErrors = expressionHighLevelErrors($element['expression']);
                if (count($levelErrors) > 0) {
                    $levelDetails['expression']['levelErrors'] = $levelErrors;
                }
                $treeList[] = $levelDetails;
                break;
        }
    }
    return array($outline, $treeList);
}
예제 #10
0
 if (!empty($trigger['dependencies'])) {
     $dep_table = new CTableInfo();
     $dep_table->setAttribute('style', 'width: 200px;');
     $dep_table->addRow(bold(S_DEPENDS_ON . ':'));
     foreach ($trigger['dependencies'] as $dep) {
         $dep_table->addRow(' - ' . expand_trigger_description($dep['triggerid']));
     }
     $img = new Cimg('images/general/down_icon.png', 'DEP_UP');
     $img->setAttribute('style', 'vertical-align: middle; border: 0px;');
     $img->setHint($dep_table);
     $description = array($img, SPACE, $description);
 }
 $dependency = false;
 $dep_table = new CTableInfo();
 $dep_table->setAttribute('style', 'width: 200px;');
 $dep_table->addRow(bold(S_DEPENDENT . ':'));
 $sql_dep = 'SELECT * FROM trigger_depends WHERE triggerid_up=' . $trigger['triggerid'];
 $dep_res = DBselect($sql_dep);
 while ($dep_row = DBfetch($dep_res)) {
     $dep_table->addRow(SPACE . '-' . SPACE . expand_trigger_description($dep_row['triggerid_down']));
     $dependency = true;
 }
 if ($dependency) {
     $img = new Cimg('images/general/up_icon.png', 'DEP_UP');
     $img->setAttribute('style', 'vertical-align: middle; border: 0px;');
     $img->setHint($dep_table);
     $description = array($img, SPACE, $description);
 }
 unset($img, $dep_table, $dependency);
 // }}} DEPENDENCIES
 $tr_desc = new CSpan($description);
예제 #11
0
         $button_show_tree->setAttribute('id', 'button_show_tree');
         // create node tree
         $node_tree = array();
         $node_tree[0] = array('id' => 0, 'caption' => _('All'), 'combo_select_node' => new CCheckbox('check_all_nodes', null, "javascript : check_all('node_form', this.checked);"), 'parentid' => 0);
         foreach ($available_nodes as $node) {
             $checked = isset($ZBX_VIEWED_NODES['nodeids'][$node['nodeid']]);
             $combo_select_node = new CCheckbox('selected_nodes[' . $node['nodeid'] . ']', $checked, null, $node['nodeid']);
             $combo_select_node->setAttribute('style', 'margin: 1px 4px 2px 4px;');
             // if no parent for node, link it to root (0)
             if (!isset($available_nodes[$node['masterid']])) {
                 $node['masterid'] = 0;
             }
             $node_tree[$node['nodeid']] = array('id' => $node['nodeid'], 'caption' => $node['name'], 'combo_select_node' => $combo_select_node, 'parentid' => $node['masterid']);
         }
         unset($node);
         $node_tree = new CTree('nodes', $node_tree, array('caption' => bold(_('Node')), 'combo_select_node' => SPACE));
         $div_node_tree = new CDiv();
         $div_node_tree->addItem($node_tree->getHTML());
         $div_node_tree->addItem(new CSubmit('select_nodes', _('Select'), "\$('div_node_tree').setStyle({display: 'none'});"));
         $div_node_tree->setAttribute('id', 'div_node_tree');
         $div_node_tree->addStyle('display: none');
         if (!is_null($nodesComboBox)) {
             $node_form->addItem(array(new CSpan(_('Current node') . SPACE, 'textcolorstyles'), $nodesComboBox));
         }
         $node_form->addItem($button_show_tree);
         $node_form->addItem($div_node_tree);
         unset($nodesComboBox);
     }
 }
 if (isset($ZBX_SERVER_NAME) && !zbx_empty($ZBX_SERVER_NAME)) {
     $table = new CTable();
예제 #12
0
            }
        }
    } else {
        if (empty($apps)) {
            $url = '?open=1&applicationid=0';
        } else {
            if (isset($apps[0])) {
                $url = '?close=1' . url_param($tmp_apps, false, 'apps');
            } else {
                $url = '?close=1&applicationid=0' . url_param($tmp_apps, false, 'apps');
            }
        }
    }
    $url .= url_param('groupid') . url_param('hostid') . url_param('fullscreen') . url_param('select');
    $link = new CLink($img, $url);
    $col = new CCol(array(bold('- ' . 'other' . ' -'), SPACE . '(' . _n('%1$s Item', '%1$s Items', $db_host['item_cnt']) . ')'));
    $col->setColSpan(5);
    // host JS menu link
    $hostSpan = null;
    if ($_REQUEST['hostid'] == 0) {
        $hostSpan = new CSpan($host['name'], 'link_menu menu-host');
        $scripts = $hostScripts[$host['hostid']];
        $hostSpan->setAttribute('data-menu', hostMenuData($host, $scripts));
    }
    $table->addRow(array($link, get_node_name_by_elid($db_host['hostid']), $hostSpan, $col));
    foreach ($app_rows as $row) {
        $table->addRow($row);
    }
}
$latest_wdgt->addItem($table);
$latest_wdgt->show();
예제 #13
0
function get_actions_hint_by_eventid($eventid, $status = NULL)
{
    $hostids = array();
    $sql = 'SELECT DISTINCT i.hostid ' . ' FROM events e, functions f, items i ' . ' WHERE e.eventid=' . $eventid . ' AND e.objectid=' . EVENT_SOURCE_TRIGGERS . ' AND f.triggerid=' . $_REQUEST['triggerid'] . ' AND i.itemid=f.itemid';
    if ($host = DBfetch(DBselect($sql, 1))) {
        $hostids[$host['hostid']] = $host['hostid'];
    }
    $available_triggers = get_accessible_triggers(PERM_READ_ONLY, $hostids);
    $tab_hint = new CTableInfo(S_NO_ACTIONS_FOUND);
    $tab_hint->addOption('style', 'width: 300px;');
    $tab_hint->SetHeader(array(is_show_subnodes() ? S_NODES : null, S_USER, S_DETAILS, S_STATUS));
    /*			
    	$sql = 'SELECT DISTINCT a.alertid,mt.description,a.sendto,a.status,u.alias,a.retries '.
    			' FROM events e,users u,alerts a'.
    			' left join media_type mt on mt.mediatypeid=a.mediatypeid'.
    			' WHERE a.eventid='.$eventid.
    				(is_null($status)?'':' AND a.status='.$status).
    				' AND e.eventid = a.eventid'.
    				' AND a.alerttype IN ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')'.
    				' AND '.DBcondition('e.objectid',$available_triggers).
    				' AND '.DBin_node('a.alertid').
    				' AND u.userid=a.userid '.
    			' ORDER BY mt.description';
    //*/
    $sql = 'SELECT DISTINCT a.alertid,mt.description,u.alias,a.subject,a.message,a.sendto,a.status,a.retries,a.alerttype ' . ' FROM events e,alerts a ' . ' LEFT JOIN users u ON u.userid=a.userid ' . ' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid' . ' WHERE a.eventid=' . $eventid . (is_null($status) ? '' : ' AND a.status=' . $status) . ' AND e.eventid = a.eventid' . ' AND a.alerttype IN (' . ALERT_TYPE_MESSAGE . ',' . ALERT_TYPE_COMMAND . ')' . ' AND ' . DBcondition('e.objectid', $available_triggers) . ' AND ' . DBin_node('a.alertid') . ' ORDER BY a.alertid';
    $result = DBselect($sql, 30);
    while ($row = DBfetch($result)) {
        if ($row["status"] == ALERT_STATUS_SENT) {
            $status = new CSpan(S_SENT, "green");
            $retries = new CSpan(SPACE, "green");
        } else {
            if ($row["status"] == ALERT_STATUS_NOT_SENT) {
                $status = new CSpan(S_IN_PROGRESS, "orange");
                $retries = new CSpan(ALERT_MAX_RETRIES - $row["retries"], "orange");
            } else {
                $status = new CSpan(S_NOT_SENT, "red");
                $retries = new CSpan(0, "red");
            }
        }
        switch ($row['alerttype']) {
            case ALERT_TYPE_MESSAGE:
                $message = empty($row['description']) ? '-' : $row['description'];
                break;
            case ALERT_TYPE_COMMAND:
                $message = array(bold(S_COMMAND . ':'));
                $msg = explode("\n", $row['message']);
                foreach ($msg as $m) {
                    array_push($message, BR(), $m);
                }
                break;
            default:
                $message = '-';
        }
        $tab_hint->addRow(array(get_node_name_by_elid($row['alertid']), empty($row['alias']) ? ' - ' : $row['alias'], $message, $status));
    }
    return $tab_hint;
}
예제 #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;
    }
    $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);
    }
}
<?php

/*
** Zabbix
** Copyright (C) 2001-2016 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
return (new CWidget())->setTitle($data['name'])->addItem((new CForm())->addItem((new CTabView())->addTab('scriptTab', null, new CPre(new CList([bold($data['command']), SPACE, $data['message']])))));
    $hostsWidget->setRootClass($rootClass);
} else {
    $displayNodes = is_array(get_current_nodeid()) && $pageFilter->groupid == 0;
    $frmForm = new CForm();
    $frmForm->cleanItems();
    $frmForm->addItem(new CDiv(array(new CSubmit('form', _('Create host')), new CButton('form', _('Import'), 'redirect("conf.import.php?rules_preset=host")'))));
    $frmForm->addItem(new CVar('groupid', $_REQUEST['groupid'], 'filter_groupid_id'));
    $hostsWidget->addPageHeader(_('CONFIGURATION OF HOSTS'), $frmForm);
    $frmGroup = new CForm('get');
    $frmGroup->addItem(array(_('Group') . SPACE, $pageFilter->getGroupsCB(true)));
    $hostsWidget->addHeader(_('Hosts'), $frmGroup);
    $hostsWidget->addHeaderRowNumber();
    $hostsWidget->setRootClass('host-list');
    // filter
    $filterTable = new CTable('', 'filter');
    $filterTable->addRow(array(array(array(bold(_('Name')), SPACE . _('like') . NAME_DELIMITER), new CTextBox('filter_host', $_REQUEST['filter_host'], 20)), array(array(bold(_('DNS')), SPACE . _('like') . NAME_DELIMITER), new CTextBox('filter_dns', $_REQUEST['filter_dns'], 20)), array(array(bold(_('IP')), SPACE . _('like') . NAME_DELIMITER), new CTextBox('filter_ip', $_REQUEST['filter_ip'], 20)), array(bold(_('Port') . NAME_DELIMITER), new CTextBox('filter_port', $_REQUEST['filter_port'], 20))));
    $filter = new CButton('filter', _('Filter'), "javascript: create_var('zbx_filter', 'filter_set', '1', true); chkbxRange.clearSelectedOnFilterChange();");
    $filter->useJQueryStyle('main');
    $reset = new CButton('reset', _('Reset'), "javascript: clearAllForm('zbx_filter');");
    $reset->useJQueryStyle();
    $divButtons = new CDiv(array($filter, SPACE, $reset));
    $divButtons->setAttribute('style', 'padding: 4px 0;');
    $filterTable->addRow(new CCol($divButtons, 'center', 4));
    $filterForm = new CForm('get');
    $filterForm->setAttribute('name', 'zbx_filter');
    $filterForm->setAttribute('id', 'zbx_filter');
    $filterForm->addItem($filterTable);
    $hostsWidget->addFlicker($filterForm, CProfile::get('web.hosts.filter.state', 0));
    // table hosts
    $form = new CForm();
    $form->setName('hosts');
예제 #17
0
function get_actions_hint_by_eventid($eventid, $status = null)
{
    $tab_hint = new CTableInfo(_('No actions found.'));
    $tab_hint->setAttribute('style', 'width: 300px;');
    $tab_hint->setHeader(array(is_show_all_nodes() ? _('Nodes') : null, _('User'), _('Details'), _('Status')));
    $sql = 'SELECT a.alertid,mt.description,u.alias,u.name,u.surname,a.subject,a.message,a.sendto,a.status,a.retries,a.alerttype' . ' FROM events e,alerts a' . ' LEFT JOIN users u ON u.userid=a.userid' . ' LEFT JOIN media_type mt ON mt.mediatypeid=a.mediatypeid' . ' WHERE a.eventid=' . zbx_dbstr($eventid) . (is_null($status) ? '' : ' AND a.status=' . $status) . ' AND e.eventid=a.eventid' . ' AND a.alerttype IN (' . ALERT_TYPE_MESSAGE . ',' . ALERT_TYPE_COMMAND . ')' . andDbNode('a.alertid') . ' ORDER BY a.alertid';
    $result = DBselect($sql, 30);
    while ($row = DBfetch($result)) {
        if ($row['status'] == ALERT_STATUS_SENT) {
            $status = new CSpan(_('Sent'), 'green');
        } elseif ($row['status'] == ALERT_STATUS_NOT_SENT) {
            $status = new CSpan(_('In progress'), 'orange');
        } else {
            $status = new CSpan(_('not sent'), 'red');
        }
        switch ($row['alerttype']) {
            case ALERT_TYPE_MESSAGE:
                $message = empty($row['description']) ? '-' : $row['description'];
                break;
            case ALERT_TYPE_COMMAND:
                $message = array(bold(_('Command') . NAME_DELIMITER));
                $msg = explode("\n", $row['message']);
                foreach ($msg as $m) {
                    array_push($message, BR(), $m);
                }
                break;
            default:
                $message = '-';
        }
        if (!$row['alias']) {
            $row['alias'] = ' - ';
        } else {
            $fullname = '';
            if ($row['name']) {
                $fullname = $row['name'];
            }
            if ($row['surname']) {
                $fullname .= $fullname ? ' ' . $row['surname'] : $row['surname'];
            }
            if ($fullname) {
                $row['alias'] .= ' (' . $fullname . ')';
            }
        }
        $tab_hint->addRow(array(get_node_name_by_elid($row['alertid']), $row['alias'], $message, $status));
    }
    return $tab_hint;
}
예제 #18
0
function get_trigger_overview_cells(&$table_row, &$trhosts, &$hostname)
{
    $css_class = NULL;
    unset($tr_ov_menu);
    $ack = null;
    if (isset($trhosts[$hostname])) {
        unset($ack_menu);
        switch ($trhosts[$hostname]['value']) {
            case TRIGGER_VALUE_TRUE:
                $css_class = get_severity_style($trhosts[$hostname]['priority']);
                if ($ack = get_last_event_by_triggerid($trhosts[$hostname]['triggerid'])) {
                    $ack_menu = array(S_ACKNOWLEDGE, 'acknow.php?eventid=' . $ack['eventid'], array('tw' => '_blank'));
                }
                if (1 == $ack['acknowledged']) {
                    $ack = new CImg('images/general/tick.png', 'ack');
                } else {
                    $ack = null;
                }
                break;
            case TRIGGER_VALUE_FALSE:
                $css_class = 'normal';
                break;
            default:
                $css_class = 'unknown_trigger';
        }
        $style = 'cursor: pointer; ';
        if (time(NULL) - $trhosts[$hostname]['lastchange'] < 300) {
            $style .= 'background-image: url(images/gradients/blink1.gif); ' . 'background-position: top left; ' . 'background-repeat: repeat;';
        } else {
            if (time(NULL) - $trhosts[$hostname]['lastchange'] < 900) {
                $style .= 'background-image: url(images/gradients/blink2.gif); ' . 'background-position: top left; ' . 'background-repeat: repeat;';
            }
        }
        unset($item_menu);
        $tr_ov_menu = array(array(S_TRIGGER, null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))), array(S_EVENTS, 'events.php?triggerid=' . $trhosts[$hostname]['triggerid'], array('tw' => '_blank')));
        if (isset($ack_menu)) {
            $tr_ov_menu[] = $ack_menu;
        }
        $db_items = DBselect('select distinct i.itemid, i.description, i.key_, i.value_type ' . ' from items i, functions f ' . ' where f.itemid=i.itemid and f.triggerid=' . $trhosts[$hostname]['triggerid']);
        while ($item_data = DBfetch($db_items)) {
            $description = item_description($item_data);
            switch ($item_data['value_type']) {
                case ITEM_VALUE_TYPE_UINT64:
                case ITEM_VALUE_TYPE_FLOAT:
                    $action = 'showgraph';
                    $status_bar = S_SHOW_GRAPH_OF_ITEM . ' \'' . $description . '\'';
                    break;
                case ITEM_VALUE_TYPE_LOG:
                case ITEM_VALUE_TYPE_STR:
                case ITEM_VALUE_TYPE_TEXT:
                default:
                    $action = 'showlatest';
                    $status_bar = S_SHOW_VALUES_OF_ITEM . ' \'' . $description . '\'';
                    break;
            }
            if (strlen($description) > 25) {
                $description = substr($description, 0, 22) . '...';
            }
            $item_menu[$action][] = array($description, 'history.php?action=' . $action . '&itemid=' . $item_data['itemid'] . '&period=3600', array('tw' => '', 'sb' => $status_bar));
        }
        if (isset($item_menu['showgraph'])) {
            $tr_ov_menu[] = array(S_GRAPHS, null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader')));
            $tr_ov_menu = array_merge($tr_ov_menu, $item_menu['showgraph']);
        }
        if (isset($item_menu['showlatest'])) {
            $tr_ov_menu[] = array(S_VALUES, null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader')));
            $tr_ov_menu = array_merge($tr_ov_menu, $item_menu['showlatest']);
        }
        unset($item_menu);
    }
    // dependency
    // TRIGGERS ON WHICH DEPENDS THIS
    $desc = array();
    if (isset($trhosts[$hostname])) {
        $triggerid = $trhosts[$hostname]['triggerid'];
        $dependency = false;
        $dep_table = new CTableInfo();
        $dep_table->AddOption('style', 'width: 200px;');
        $dep_table->addRow(bold(S_DEPENDS_ON . ':'));
        $sql_dep = 'SELECT * FROM trigger_depends WHERE triggerid_down=' . $triggerid;
        $dep_res = DBselect($sql_dep);
        while ($dep_row = DBfetch($dep_res)) {
            $dep_table->addRow(SPACE . '-' . SPACE . expand_trigger_description($dep_row['triggerid_up']));
            $dependency = true;
        }
        if ($dependency) {
            $img = new Cimg('images/general/down_icon.png', 'DEP_DOWN');
            $img->AddOption('style', 'vertical-align: middle; border: 0px;');
            $img->SetHint($dep_table);
            array_push($desc, $img);
        }
        unset($img, $dep_table, $dependency);
        // TRIGGERS THAT DEPEND ON THIS
        $dependency = false;
        $dep_table = new CTableInfo();
        $dep_table->AddOption('style', 'width: 200px;');
        $dep_table->addRow(bold(S_DEPENDENT . ':'));
        $sql_dep = 'SELECT * FROM trigger_depends WHERE triggerid_up=' . $triggerid;
        $dep_res = DBselect($sql_dep);
        while ($dep_row = DBfetch($dep_res)) {
            $dep_table->addRow(SPACE . '-' . SPACE . expand_trigger_description($dep_row['triggerid_down']));
            $dependency = true;
        }
        if ($dependency) {
            $img = new Cimg('images/general/up_icon.png', 'DEP_UP');
            $img->AddOption('style', 'vertical-align: middle; border: 0px;');
            $img->SetHint($dep_table);
            array_push($desc, $img);
        }
        unset($img, $dep_table, $dependency);
    }
    //------------------------
    $status_col = new CCol(array($desc, $ack), $css_class);
    if (isset($style)) {
        $status_col->AddOption('style', $style);
    }
    if (isset($tr_ov_menu)) {
        $tr_ov_menu = new CPUMenu($tr_ov_menu, 170);
        $status_col->OnClick($tr_ov_menu->GetOnActionJS());
        $status_col->AddAction('onmouseover', 'this.old_border=this.style.border; this.style.border=\'1px dotted #0C0CF0\'');
        $status_col->AddAction('onmouseout', 'this.style.border=this.old_border;');
    }
    array_push($table_row, $status_col);
    return $table_row;
}
예제 #19
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);
            }
        }
    }
}
예제 #20
0
파일: search.php 프로젝트: phedders/zabbix
                break;
        }
    }
}
if (PAGE_TYPE_JS == $page['type'] || PAGE_TYPE_HTML_BLOCK == $page['type']) {
    exit;
}
$admin = uint_in_array($USER_DETAILS['type'], array(USER_TYPE_ZABBIX_ADMIN, USER_TYPE_SUPER_ADMIN));
$rows_per_page = $USER_DETAILS['rows_per_page'];
$search_wdgt = new CWidget('search_wdgt');
$search = get_request('search', '');
// Header
if (zbx_empty($search)) {
    $search = 'Search pattern is empty';
}
$search_wdgt->addHeader(array(S_SEARCH_BIG . ': ', bold($search)), SPACE);
//-------------
$left_tab = new CTable();
$left_tab->setCellPadding(3);
$left_tab->setCellSpacing(3);
$left_tab->setAttribute('border', 0);
$right_tab = new CTable();
$right_tab->setCellPadding(3);
$right_tab->setCellSpacing(3);
$right_tab->setAttribute('border', 0);
// FIND Hosts
$params = array('nodeids' => get_current_nodeid(), 'extendoutput' => true, 'pattern' => $search, 'extend_pattern' => true, 'limit' => $rows_per_page, 'order' => 'host');
$db_hosts = CHost::get($params);
$hosts = selectByPattern($db_hosts, 'host', $search, $rows_per_page);
$hostids = array_keys($hosts);
$hostsgroups = array();
예제 #21
0
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $this->dataId = 'discovery';
     $sort_field = $this->data['sort'];
     $sort_order = $this->data['sortorder'];
     $druleid = $this->data['druleid'];
     // discovery rules
     $options = ['output' => ['druleid', 'name'], 'selectDHosts' => ['dhostid', 'status', 'lastup', 'lastdown'], 'filter' => ['status' => DRULE_STATUS_ACTIVE]];
     if ($druleid > 0) {
         $options['druleids'] = $druleid;
         // set selected discovery rule id
     }
     $drules = API::DRule()->get($options);
     if ($drules) {
         order_result($drules, 'name');
     }
     // discovery services
     $options = ['selectHosts' => ['hostid', 'name', 'status'], 'output' => ['dserviceid', 'type', 'key_', 'port', 'status', 'lastup', 'lastdown', 'ip', 'dns'], 'sortfield' => $sort_field, 'sortorder' => $sort_order, 'limitSelects' => 1];
     if ($druleid > 0) {
         $options['druleids'] = $druleid;
     } else {
         $options['druleids'] = zbx_objectValues($drules, 'druleid');
     }
     $dservices = API::DService()->get($options);
     // user macros
     $macros = API::UserMacro()->get(['output' => ['macro', 'value'], 'globalmacro' => true]);
     $macros = zbx_toHash($macros, 'macro');
     // services
     $services = [];
     foreach ($dservices as $dservice) {
         $key_ = $dservice['key_'];
         if ($key_ !== '') {
             if (array_key_exists($key_, $macros)) {
                 $key_ = $macros[$key_]['value'];
             }
             $key_ = ': ' . $key_;
         }
         $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
         $services[$service_name] = 1;
     }
     ksort($services);
     // discovery services to hash
     $dservices = zbx_toHash($dservices, 'dserviceid');
     // discovery hosts
     $dhosts = API::DHost()->get(['druleids' => zbx_objectValues($drules, 'druleid'), 'selectDServices' => ['dserviceid', 'ip', 'dns', 'type', 'status', 'key_'], 'output' => ['dhostid', 'lastdown', 'lastup', 'druleid']]);
     $dhosts = zbx_toHash($dhosts, 'dhostid');
     $header = [make_sorting_header(_('Discovered device'), 'ip', $sort_field, $sort_order, 'zabbix.php?action=discovery.view'), _('Monitored host'), _('Uptime') . '/' . _('Downtime')];
     foreach ($services as $name => $foo) {
         $header[] = (new CColHeader($name))->addClass('vertical_rotation');
     }
     // create table
     $table = (new CTableInfo())->makeVerticalRotation()->setHeader($header);
     foreach ($drules as $drule) {
         $discovery_info = [];
         foreach ($drule['dhosts'] as $dhost) {
             if ($dhost['status'] == DHOST_STATUS_DISABLED) {
                 $hclass = 'disabled';
                 $htime = $dhost['lastdown'];
             } else {
                 $hclass = 'enabled';
                 $htime = $dhost['lastup'];
             }
             // $primary_ip stores the primary host ip of the dhost
             $primary_ip = '';
             foreach ($dhosts[$dhost['dhostid']]['dservices'] as $dservice) {
                 $dservice = $dservices[$dservice['dserviceid']];
                 $hostName = '';
                 $host = reset($dservices[$dservice['dserviceid']]['hosts']);
                 if (!is_null($host)) {
                     $hostName = $host['name'];
                 }
                 if ($primary_ip !== '') {
                     if ($primary_ip === $dservice['ip']) {
                         $htype = 'primary';
                     } else {
                         $htype = 'slave';
                     }
                 } else {
                     $primary_ip = $dservice['ip'];
                     $htype = 'primary';
                 }
                 if (!array_key_exists($dservice['ip'], $discovery_info)) {
                     $discovery_info[$dservice['ip']] = ['ip' => $dservice['ip'], 'dns' => $dservice['dns'], 'type' => $htype, 'class' => $hclass, 'host' => $hostName, 'time' => $htime];
                 }
                 if ($dservice['status'] == DSVC_STATUS_DISABLED) {
                     $class = ZBX_STYLE_INACTIVE_BG;
                     $time = 'lastdown';
                 } else {
                     $class = ZBX_STYLE_ACTIVE_BG;
                     $time = 'lastup';
                 }
                 $key_ = $dservice['key_'];
                 if ($key_ !== '') {
                     if (array_key_exists($key_, $macros)) {
                         $key_ = $macros[$key_]['value'];
                     }
                     $key_ = NAME_DELIMITER . $key_;
                 }
                 $service_name = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
                 $discovery_info[$dservice['ip']]['services'][$service_name] = ['class' => $class, 'time' => $dservice[$time]];
             }
         }
         if ($druleid == 0 && $discovery_info) {
             $col = new CCol([bold($drule['name']), SPACE . '(' . _n('%d device', '%d devices', count($discovery_info)) . ')']);
             $col->setColSpan(count($services) + 3);
             $table->addRow($col);
         }
         order_result($discovery_info, $sort_field, $sort_order);
         foreach ($discovery_info as $ip => $h_data) {
             $dns = $h_data['dns'] == '' ? '' : ' (' . $h_data['dns'] . ')';
             $row = [$h_data['type'] == 'primary' ? (new CSpan($ip . $dns))->addClass($h_data['class']) : new CSpan(SPACE . SPACE . $ip . $dns), new CSpan(array_key_exists('host', $h_data) ? $h_data['host'] : ''), (new CSpan($h_data['time'] == 0 || $h_data['type'] === 'slave' ? '' : convert_units(['value' => time() - $h_data['time'], 'units' => 'uptime'])))->addClass($h_data['class'])];
             foreach ($services as $name => $foo) {
                 $class = null;
                 $time = SPACE;
                 $hint = (new CDiv(SPACE))->addClass($class);
                 $hint_table = null;
                 if (array_key_exists($name, $h_data['services'])) {
                     $class = $h_data['services'][$name]['class'];
                     $time = $h_data['services'][$name]['time'];
                     $hint_table = (new CTableInfo())->setAttribute('style', 'width: auto;');
                     if ($class == ZBX_STYLE_ACTIVE_BG) {
                         $hint_table->setHeader(_('Uptime'));
                     } else {
                         $hint_table->setHeader(_('Downtime'));
                     }
                     $hint_table->addRow((new CCol(zbx_date2age($h_data['services'][$name]['time'])))->addClass($class));
                 }
                 $column = (new CCol($hint))->addClass($class);
                 if (!is_null($hint_table)) {
                     $column->setHint($hint_table);
                 }
                 $row[] = $column;
             }
             $table->addRow($row);
         }
     }
     return $this->getOutput($table, true, $this->data);
 }
예제 #22
0
        if (isset($services[$row['serviceid']])) {
            $services[$row['serviceid']] = array_merge($services[$row['serviceid']], $row);
        } else {
            $services[$row['serviceid']] = $row;
        }
        if (isset($row['serviceupid'])) {
            $services[$row['serviceupid']]['childs'][] = array('id' => $row['serviceid'], 'soft' => 0, 'linkid' => 0);
        }
        if (isset($row['servicedownid'])) {
            $services[$row['serviceid']]['childs'][] = array('id' => $row['servicedownid'], 'soft' => 1, 'linkid' => $row['linkid']);
        }
    }
    $treeServ = array();
    createShowServiceTree($services, $treeServ);
    //return into $treeServ parametr
    //permission issue
    $treeServ = del_empty_nodes($treeServ);
    $tree = new CTree($treeServ, array('caption' => bold(S_SERVICE), 'status' => bold(S_STATUS), 'reason' => bold(S_REASON), 'sla' => bold(S_SLA_LAST_7_DAYS), 'sla2' => bold(nbsp(S_SLA)), 'graph' => bold(S_GRAPH)));
    if ($tree) {
        $url = '?fullscreen=' . ($_REQUEST['fullscreen'] ? '0' : '1');
        $fs_icon = new CDiv(SPACE, 'fullscreen');
        $fs_icon->AddOption('title', $_REQUEST['fullscreen'] ? S_NORMAL . ' ' . S_VIEW : S_FULLSCREEN);
        $fs_icon->AddAction('onclick', new CScript("javascript: document.location = '" . $url . "';"));
        $tab = create_hat(S_IT_SERVICES_BIG, $tree->getHTML(), null, 'hat_services', get_profile('web.srv_status.hats.hat_services.state', 1));
        $tab->Show();
        unset($tab);
    } else {
        error('Can not format Tree. Check logik structure in service links');
    }
}
include_once "include/page_footer.php";
            if (count($evtnames) > 0) {
                echoEventRows($evtnames);
            }
            echo "<tr><td colspan='2'><div class='split' style='margin:10px 0;'></div></td></tr>";
            echo "<tr><td colspan='2'><b>" . $services[$srv - 1] . "</b></td></tr>";
        }
        // display group name
        if ($grp != $row['groupname']) {
            $grp = $row['groupname'];
            if (count($evtnames) > 0) {
                echoEventRows($evtnames);
            }
            echo "<tr><td colspan='2'><div class='split' style='margin:10px 0;'></div></td></tr>";
            echo "<tr><td colspan='2'><b>" . $row['groupname'] . "</b></td></tr>";
        }
        $evtnames[] = '<input name="sysevents[]" id="' . $row['name'] . '" type="checkbox"' . (in_array($row['id'], $evts) ? " checked='checked' " : "") . 'class="inputBox" value="' . $row['id'] . '" /><label for="' . $row['name'] . '"' . bold(in_array($row[id], $evts)) . '>' . $row['name'] . '</label>' . "\n";
        if (count($evtnames) == 2) {
            echoEventRows($evtnames);
        }
    }
}
if (count($evtnames) > 0) {
    echoEventRows($evtnames);
}
function echoEventRows(&$evtnames)
{
    echo "<tr><td>" . implode("</td><td>", $evtnames) . "</td></tr>";
    $evtnames = array();
}
?>
    </table>
$rForm = new CForm('get');
$rForm->addItem(array(_('Group'), SPACE, $this->data['pageFilter']->getGroupsCB()));
$hostInventoryWidget->addPageHeader(_('HOST INVENTORY'), SPACE);
$hostInventoryWidget->addHeader(_('Hosts'), $rForm);
$filterTable = new CTable('', 'filter filter-center');
// getting inventory fields to make a drop down
$inventoryFields = getHostInventories(true);
// 'true' means list should be ordered by title
$inventoryFieldsComboBox = new CComboBox('filter_field', $this->data['filterField']);
foreach ($inventoryFields as $inventoryField) {
    $inventoryFieldsComboBox->addItem($inventoryField['db_field'], $inventoryField['title']);
}
$exactComboBox = new CComboBox('filter_exact', $this->data['filterExact']);
$exactComboBox->addItem('0', _('like'));
$exactComboBox->addItem('1', _('exactly'));
$filterTable->addRow(array(array(array(bold(_('Field')), SPACE, $inventoryFieldsComboBox), array($exactComboBox, new CTextBox('filter_field_value', $this->data['filterFieldValue'], 20)))), 'host-inventories');
$filter = new CSubmit('filter_set', _('Filter'));
$filter->useJQueryStyle('main');
$reset = new CSubmit('filter_rst', _('Reset'));
$reset->useJQueryStyle();
$divButtons = new CDiv(array($filter, SPACE, $reset));
$divButtons->setAttribute('style', 'padding: 4px 0px;');
$footerCol = new CCol($divButtons, 'controls');
$filterTable->addRow($footerCol);
$filterForm = new CForm('get');
$filterForm->setAttribute('name', 'zbx_filter');
$filterForm->setAttribute('id', 'zbx_filter');
$filterForm->addItem($filterTable);
$hostInventoryWidget->addFlicker($filterForm, CProfile::get('web.hostinventories.filter.state', 0));
$hostInventoryWidget->addHeaderRowNumber();
$table = new CTableInfo(_('No hosts found.'));
예제 #25
0
/**
 * Create CDiv with host/template information and references to it's elements
 *
 * @param string $currentElement
 * @param int $hostid
 * @param int $discoveryid
 *
 * @return object
 */
function get_header_host_table($currentElement, $hostid, $discoveryid = null)
{
    $elements = array('items' => 'items', 'triggers' => 'triggers', 'graphs' => 'graphs', 'applications' => 'applications', 'screens' => 'screens', 'discoveries' => 'discoveries');
    if (!empty($discoveryid)) {
        unset($elements['applications'], $elements['screens'], $elements['discoveries']);
    }
    $options = array('hostids' => $hostid, 'output' => API_OUTPUT_EXTEND, 'templated_hosts' => true);
    if (isset($elements['items'])) {
        $options['selectItems'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['triggers'])) {
        $options['selectTriggers'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['graphs'])) {
        $options['selectGraphs'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['applications'])) {
        $options['selectApplications'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['screens'])) {
        $options['selectScreens'] = API_OUTPUT_COUNT;
    }
    if (isset($elements['discoveries'])) {
        $options['selectDiscoveries'] = API_OUTPUT_COUNT;
    }
    // get hosts
    $dbHost = API::Host()->get($options);
    $dbHost = reset($dbHost);
    // get discoveries
    if (!empty($discoveryid)) {
        $options['itemids'] = $discoveryid;
        $options['output'] = array('name');
        unset($options['hostids'], $options['templated_hosts']);
        $dbDiscovery = API::DiscoveryRule()->get($options);
        $dbDiscovery = reset($dbDiscovery);
    }
    /*
     * Back
     */
    $list = new CList(null, 'objectlist');
    if ($dbHost['status'] == HOST_STATUS_TEMPLATE) {
        $list->addItem(array('&laquo; ', new CLink(_('Template list'), 'templates.php?templateid=' . $dbHost['hostid'] . url_param('groupid'))));
    } else {
        $list->addItem(array('&laquo; ', new CLink(_('Host list'), 'hosts.php?hostid=' . $dbHost['hostid'] . url_param('groupid'))));
    }
    /*
     * Name
     */
    $description = '';
    if ($dbHost['proxy_hostid']) {
        $proxy = get_host_by_hostid($dbHost['proxy_hostid']);
        $description .= $proxy['host'] . ': ';
    }
    $description .= $dbHost['name'];
    if ($dbHost['status'] == HOST_STATUS_TEMPLATE) {
        $list->addItem(array(bold(_('Template') . ': '), new CLink($description, 'templates.php?form=update&templateid=' . $dbHost['hostid'])));
    } else {
        switch ($dbHost['status']) {
            case HOST_STATUS_MONITORED:
                $status = new CSpan(_('Monitored'), 'off');
                break;
            case HOST_STATUS_NOT_MONITORED:
                $status = new CSpan(_('Not monitored'), 'on');
                break;
            default:
                $status = _('Unknown');
                break;
        }
        $list->addItem(array(bold(_('Host') . ': '), new CLink($description, 'hosts.php?form=update&hostid=' . $dbHost['hostid'])));
        $list->addItem($status);
        $list->addItem(getAvailabilityTable($dbHost));
    }
    if (!empty($dbDiscovery)) {
        $list->addItem(array('&laquo; ', new CLink(_('Discovery list'), 'host_discovery.php?hostid=' . $dbHost['hostid'] . url_param('groupid'))));
        $list->addItem(array(bold(_('Discovery') . ': '), new CLink($dbDiscovery['name'], 'host_discovery.php?form=update&itemid=' . $dbDiscovery['itemid'])));
    }
    /*
     * Rowcount
     */
    if (isset($elements['applications'])) {
        if ($currentElement == 'applications') {
            $list->addItem(_('Applications') . ' (' . $dbHost['applications'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Applications'), 'applications.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['applications'] . ')'));
        }
    }
    if (isset($elements['items'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'items') {
                $list->addItem(_('Item prototypes') . ' (' . $dbDiscovery['items'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Item prototypes'), 'disc_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['items'] . ')'));
            }
        } else {
            if ($currentElement == 'items') {
                $list->addItem(_('Items') . ' (' . $dbHost['items'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Items'), 'items.php?filter_set=1&hostid=' . $dbHost['hostid']), ' (' . $dbHost['items'] . ')'));
            }
        }
    }
    if (isset($elements['triggers'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'triggers') {
                $list->addItem(_('Trigger prototypes') . ' (' . $dbDiscovery['triggers'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Trigger prototypes'), 'trigger_prototypes.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['triggers'] . ')'));
            }
        } else {
            if ($currentElement == 'triggers') {
                $list->addItem(_('Triggers') . ' (' . $dbHost['triggers'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Triggers'), 'triggers.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['triggers'] . ')'));
            }
        }
    }
    if (isset($elements['graphs'])) {
        if (!empty($dbDiscovery)) {
            if ($currentElement == 'graphs') {
                $list->addItem(_('Graph prototypes') . ' (' . $dbDiscovery['graphs'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Graph prototypes'), 'graphs.php?hostid=' . $dbHost['hostid'] . '&parent_discoveryid=' . $dbDiscovery['itemid']), ' (' . $dbDiscovery['graphs'] . ')'));
            }
        } else {
            if ($currentElement == 'graphs') {
                $list->addItem(_('Graphs') . ' (' . $dbHost['graphs'] . ')');
            } else {
                $list->addItem(array(new CLink(_('Graphs'), 'graphs.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['graphs'] . ')'));
            }
        }
    }
    if (isset($elements['screens']) && $dbHost['status'] == HOST_STATUS_TEMPLATE) {
        if ($currentElement == 'screens') {
            $list->addItem(_('Screens') . ' (' . $dbHost['screens'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Screens'), 'screenconf.php?templateid=' . $dbHost['hostid']), ' (' . $dbHost['screens'] . ')'));
        }
    }
    if (isset($elements['discoveries'])) {
        if ($currentElement == 'discoveries') {
            $list->addItem(_('Discovery rules') . ' (' . $dbHost['discoveries'] . ')');
        } else {
            $list->addItem(array(new CLink(_('Discovery rules'), 'host_discovery.php?hostid=' . $dbHost['hostid']), ' (' . $dbHost['discoveries'] . ')'));
        }
    }
    return new CDiv($list, 'objectgroup top ui-widget-content ui-corner-all');
}
예제 #26
0
    if (isset($row['serviceupid'])) {
        $services[$row['serviceupid']]['childs'][] = array('id' => $row['serviceid'], 'soft' => 0, 'linkid' => 0);
    }
    if (isset($row['servicedownid'])) {
        $services[$row['serviceid']]['childs'][] = array('id' => $row['servicedownid'], 'soft' => 1, 'linkid' => $row['linkid']);
    }
}
$treeServ = array();
createServiceTree($services, $treeServ);
//return into $treeServ parametr
//permission issue
$treeServ = del_empty_nodes($treeServ);
//----
if (isset($_REQUEST['msg']) && !empty($_REQUEST['msg'])) {
    show_messages(true, $_REQUEST['msg']);
}
//show_table_header(S_IT_SERVICES_BIG);
$tree = new CTree('service_conf_tree', $treeServ, array('caption' => bold(S_SERVICE), 'algorithm' => bold(S_STATUS_CALCULATION), 'description' => bold(S_TRIGGER)));
if ($tree) {
    $serv_wdgt = new CWidget();
    $serv_wdgt->addHeader(S_IT_SERVICES_BIG, SPACE);
    $serv_wdgt->addItem($tree->getHTML());
    $serv_wdgt->show();
} else {
    error(S_CANT_FORMAT_TREE);
}
$tr_ov_menu[] = array('test1', null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader')));
$tr_ov_menu[] = array('test2', null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader')));
$jsmenu = new CPUMenu($tr_ov_menu, 170);
$jsmenu->InsertJavaScript();
include_once "include/page_footer.php";
예제 #27
0
             $class = 'inactive';
             $time = 'lastdown';
         }
         $key_ = $dservice['key_'];
         if (!zbx_empty($key_)) {
             if (isset($this->data['macros'][$key_])) {
                 $key_ = $this->data['macros'][$key_]['value'];
             }
             $key_ = NAME_DELIMITER . $key_;
         }
         $serviceName = discovery_check_type2str($dservice['type']) . discovery_port2str($dservice['type'], $dservice['port']) . $key_;
         $discovery_info[$dservice['ip']]['services'][$serviceName] = array('class' => $class, 'time' => $dservice[$time]);
     }
 }
 if (empty($this->data['druleid']) && !empty($discovery_info)) {
     $col = new CCol(array(bold($drule['name']), SPACE . '(' . _n('%d device', '%d devices', count($discovery_info)) . ')'));
     $col->setColSpan(count($this->data['services']) + 3);
     $discoveryTable->addRow($col);
 }
 order_result($discovery_info, $this->data['sort'], $this->data['sortorder']);
 foreach ($discovery_info as $ip => $h_data) {
     $dns = $h_data['dns'] == '' ? '' : ' (' . $h_data['dns'] . ')';
     $row = array($h_data['type'] == 'primary' ? new CSpan($ip . $dns, $h_data['class']) : new CSpan(SPACE . SPACE . $ip . $dns), new CSpan(empty($h_data['host']) ? '-' : $h_data['host']), new CSpan($h_data['time'] == 0 || $h_data['type'] === 'slave' ? '' : convert_units(array('value' => time() - $h_data['time'], 'units' => 'uptime')), $h_data['class']));
     foreach ($this->data['services'] as $name => $foo) {
         $class = null;
         $time = SPACE;
         $hint = new CDiv(SPACE, $class);
         $hintTable = null;
         if (isset($h_data['services'][$name])) {
             $class = $h_data['services'][$name]['class'];
             $time = $h_data['services'][$name]['time'];
예제 #28
0
         $button_show_tree->setAttribute('id', 'button_show_tree');
         // +++ Create node tree +++
         $combo_check_all = new CCheckbox('check_all_nodes', null, "javascript : check_all('node_form', this.checked);");
         $node_tree = array();
         $node_tree[0] = array('id' => 0, 'caption' => S_ALL_S, 'combo_select_node' => $combo_check_all, 'parentid' => 0);
         //root
         foreach ($available_nodes as $num => $node) {
             $checked = uint_in_array($node['nodeid'], $ZBX_VIEWED_NODES['nodeids']);
             $combo_select_node = new CCheckbox('selected_nodes[' . $node['nodeid'] . ']', $checked, null, $node['nodeid']);
             // If not exist parent for node, link it to root (0)
             if (!isset($available_nodes[$node['masterid']])) {
                 $node['masterid'] = 0;
             }
             $node_tree[$node['nodeid']] = array('id' => $node['nodeid'], 'caption' => $node['name'], 'combo_select_node' => $combo_select_node, 'parentid' => $node['masterid']);
         }
         $node_tree_captions = array('caption' => bold(S_NODE), 'combo_select_node' => SPACE);
         $node_tree = new CTree('nodes', $node_tree, $node_tree_captions);
         // --- ---
         $div_node_tree = new CDiv();
         $div_node_tree->additem($node_tree->getHTML());
         $div_node_tree->additem(new CButton('select_nodes', S_SELECT, "javascript: " . " hidePopupDiv('select_iframe');" . " \$('div_node_tree').setStyle({display:'none'});"));
         $div_node_tree->setAttribute('id', 'div_node_tree');
         $div_node_tree->addStyle('display: none');
         if (!is_null($combo_node_list)) {
             $node_form->addItem(array(new CSpan(S_CURRENT_NODE, 'textcolorstyles'), $combo_node_list));
         }
         $node_form->addItem($button_show_tree);
         $node_form->addItem($div_node_tree);
         unset($combo_node_list);
     }
 }
예제 #29
0
function getItemFilterForm(&$items)
{
    $filter_groupId = $_REQUEST['filter_groupid'];
    $filter_hostId = $_REQUEST['filter_hostid'];
    $filter_application = $_REQUEST['filter_application'];
    $filter_name = $_REQUEST['filter_name'];
    $filter_type = $_REQUEST['filter_type'];
    $filter_key = $_REQUEST['filter_key'];
    $filter_snmp_community = $_REQUEST['filter_snmp_community'];
    $filter_snmpv3_securityname = $_REQUEST['filter_snmpv3_securityname'];
    $filter_snmp_oid = $_REQUEST['filter_snmp_oid'];
    $filter_port = $_REQUEST['filter_port'];
    $filter_value_type = $_REQUEST['filter_value_type'];
    $filter_data_type = $_REQUEST['filter_data_type'];
    $filter_delay = $_REQUEST['filter_delay'];
    $filter_history = $_REQUEST['filter_history'];
    $filter_trends = $_REQUEST['filter_trends'];
    $filter_status = $_REQUEST['filter_status'];
    $filter_state = $_REQUEST['filter_state'];
    $filter_templated_items = $_REQUEST['filter_templated_items'];
    $filter_with_triggers = $_REQUEST['filter_with_triggers'];
    $subfilter_hosts = $_REQUEST['subfilter_hosts'];
    $subfilter_apps = $_REQUEST['subfilter_apps'];
    $subfilter_types = $_REQUEST['subfilter_types'];
    $subfilter_value_types = $_REQUEST['subfilter_value_types'];
    $subfilter_status = $_REQUEST['subfilter_status'];
    $subfilter_state = $_REQUEST['subfilter_state'];
    $subfilter_templated_items = $_REQUEST['subfilter_templated_items'];
    $subfilter_with_triggers = $_REQUEST['subfilter_with_triggers'];
    $subfilter_history = $_REQUEST['subfilter_history'];
    $subfilter_trends = $_REQUEST['subfilter_trends'];
    $subfilter_interval = $_REQUEST['subfilter_interval'];
    $form = new CForm('get');
    $form->setAttribute('name', 'zbx_filter');
    $form->setAttribute('id', 'zbx_filter');
    $form->addVar('subfilter_hosts', $subfilter_hosts);
    $form->addVar('subfilter_apps', $subfilter_apps);
    $form->addVar('subfilter_types', $subfilter_types);
    $form->addVar('subfilter_value_types', $subfilter_value_types);
    $form->addVar('subfilter_status', $subfilter_status);
    $form->addVar('subfilter_state', $subfilter_state);
    $form->addVar('subfilter_templated_items', $subfilter_templated_items);
    $form->addVar('subfilter_with_triggers', $subfilter_with_triggers);
    $form->addVar('subfilter_history', $subfilter_history);
    $form->addVar('subfilter_trends', $subfilter_trends);
    $form->addVar('subfilter_interval', $subfilter_interval);
    // type select
    $fTypeVisibility = array();
    $cmbType = new CComboBox('filter_type', $filter_type);
    $cmbType->setAttribute('id', 'filter_type');
    $cmbType->addItem(-1, _('all'));
    foreach (array('filter_delay_label', 'filter_delay') as $vItem) {
        zbx_subarray_push($fTypeVisibility, -1, $vItem);
    }
    $itemTypes = item_type2str();
    unset($itemTypes[ITEM_TYPE_HTTPTEST]);
    // httptest items are only for internal zabbix logic
    $cmbType->addItems($itemTypes);
    foreach ($itemTypes as $typeNum => $typeLabel) {
        if ($typeNum != ITEM_TYPE_TRAPPER) {
            zbx_subarray_push($fTypeVisibility, $typeNum, 'filter_delay_label');
            zbx_subarray_push($fTypeVisibility, $typeNum, 'filter_delay');
        }
        switch ($typeNum) {
            case ITEM_TYPE_SNMPV1:
            case ITEM_TYPE_SNMPV2C:
                $snmp_types = array('filter_snmp_community_label', 'filter_snmp_community', 'filter_snmp_oid_label', 'filter_snmp_oid', 'filter_port_label', 'filter_port');
                foreach ($snmp_types as $vItem) {
                    zbx_subarray_push($fTypeVisibility, $typeNum, $vItem);
                }
                break;
            case ITEM_TYPE_SNMPV3:
                foreach (array('filter_snmpv3_securityname_label', 'filter_snmpv3_securityname', 'filter_snmp_oid_label', 'filter_snmp_oid', 'filter_port_label', 'filter_port') as $vItem) {
                    zbx_subarray_push($fTypeVisibility, $typeNum, $vItem);
                }
                break;
        }
    }
    zbx_add_post_js("var filterTypeSwitcher = new CViewSwitcher('filter_type', 'change', " . zbx_jsvalue($fTypeVisibility, true) . ');');
    // type of information select
    $fVTypeVisibility = array();
    $cmbValType = new CComboBox('filter_value_type', $filter_value_type);
    $cmbValType->addItem(-1, _('all'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_UINT64, _('Numeric (unsigned)'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_FLOAT, _('Numeric (float)'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_STR, _('Character'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_LOG, _('Log'));
    $cmbValType->addItem(ITEM_VALUE_TYPE_TEXT, _('Text'));
    foreach (array('filter_data_type_label', 'filter_data_type') as $vItem) {
        zbx_subarray_push($fVTypeVisibility, ITEM_VALUE_TYPE_UINT64, $vItem);
    }
    zbx_add_post_js("var filterValueTypeSwitcher = new CViewSwitcher('filter_value_type', 'change', " . zbx_jsvalue($fVTypeVisibility, true) . ');');
    // status select
    $cmbStatus = new CComboBox('filter_status', $filter_status);
    $cmbStatus->addItem(-1, _('all'));
    foreach (array(ITEM_STATUS_ACTIVE, ITEM_STATUS_DISABLED) as $status) {
        $cmbStatus->addItem($status, item_status2str($status));
    }
    // state select
    $cmbState = new CComboBox('filter_state', $filter_state);
    $cmbState->addItem(-1, _('all'));
    foreach (array(ITEM_STATE_NORMAL, ITEM_STATE_NOTSUPPORTED) as $state) {
        $cmbState->addItem($state, itemState($state));
    }
    // update interval
    $updateIntervalLabel = new CSpan(array(bold(_('Update interval')), SPACE . _('(in sec)') . NAME_DELIMITER));
    $updateIntervalLabel->setAttribute('id', 'filter_delay_label');
    $updateIntervalInput = new CNumericBox('filter_delay', $filter_delay, 5, false, true);
    $updateIntervalInput->setEnabled('no');
    // data type
    $dataTypeLabel = new CSpan(bold(_('Data type') . NAME_DELIMITER));
    $dataTypeLabel->setAttribute('id', 'filter_data_type_label');
    $dataTypeInput = new CComboBox('filter_data_type', $filter_data_type);
    $dataTypeInput->addItem(-1, _('all'));
    $dataTypeInput->addItems(item_data_type2str());
    $dataTypeInput->setEnabled('no');
    // filter table
    $table = new CTable('', 'filter');
    $table->setCellPadding(0);
    $table->setCellSpacing(0);
    // SNMP community
    $snmpCommunityLabel = new CSpan(array(bold(_('SNMP community')), SPACE . _('like') . NAME_DELIMITER));
    $snmpCommunityLabel->setAttribute('id', 'filter_snmp_community_label');
    $snmpCommunityField = new CTextBox('filter_snmp_community', $filter_snmp_community, ZBX_TEXTBOX_FILTER_SIZE);
    $snmpCommunityField->setEnabled('no');
    // SNMPv3 security name
    $snmpSecurityLabel = new CSpan(array(bold(_('Security name')), SPACE . _('like') . NAME_DELIMITER));
    $snmpSecurityLabel->setAttribute('id', 'filter_snmpv3_securityname_label');
    $snmpSecurityField = new CTextBox('filter_snmpv3_securityname', $filter_snmpv3_securityname, ZBX_TEXTBOX_FILTER_SIZE);
    $snmpSecurityField->setEnabled('no');
    // SNMP OID
    $snmpOidLabel = new CSpan(array(bold(_('SNMP OID')), SPACE . _('like') . NAME_DELIMITER));
    $snmpOidLabel->setAttribute('id', 'filter_snmp_oid_label');
    $snmpOidField = new CTextBox('filter_snmp_oid', $filter_snmp_oid, ZBX_TEXTBOX_FILTER_SIZE);
    $snmpOidField->setEnabled('no');
    // port
    $portLabel = new CSpan(array(bold(_('Port')), SPACE . _('like') . NAME_DELIMITER));
    $portLabel->setAttribute('id', 'filter_port_label');
    $portField = new CNumericBox('filter_port', $filter_port, 5, false, true);
    $portField->setEnabled('no');
    // row 1
    $groupFilter = null;
    if (!empty($filter_groupId)) {
        $getHostInfo = API::HostGroup()->get(array('groupids' => $filter_groupId, 'output' => array('name')));
        $getHostInfo = reset($getHostInfo);
        if (!empty($getHostInfo)) {
            $groupFilter[] = array('id' => $getHostInfo['groupid'], 'name' => $getHostInfo['name']);
        }
    }
    $table->addRow(array(new CCol(bold(_('Host group') . NAME_DELIMITER), 'label col1'), new CCol(array(new CMultiSelect(array('name' => 'filter_groupid', 'selectedLimit' => 1, 'objectName' => 'hostGroup', 'objectOptions' => array('editable' => true), 'data' => $groupFilter, 'popup' => array('parameters' => 'srctbl=host_groups&dstfrm=' . $form->getName() . '&dstfld1=filter_groupid' . '&srcfld1=groupid&writeonly=1', 'width' => 450, 'height' => 450, 'buttonClass' => 'input filter-multiselect-select-button')))), 'col1'), new CCol(bold(_('Type') . NAME_DELIMITER), 'label col2'), new CCol($cmbType, 'col2'), new CCol(bold(_('Type of information') . NAME_DELIMITER), 'label col3'), new CCol($cmbValType, 'col3'), new CCol(bold(_('State') . NAME_DELIMITER), 'label'), new CCol($cmbState, 'col4')), 'item-list-row');
    // row 2
    $hostFilterData = null;
    if (!empty($filter_hostId)) {
        $getHostInfo = API::Host()->get(array('hostids' => $filter_hostId, 'templated_hosts' => true, 'output' => array('name')));
        $getHostInfo = reset($getHostInfo);
        if (!empty($getHostInfo)) {
            $hostFilterData[] = array('id' => $getHostInfo['hostid'], 'name' => $getHostInfo['name']);
        }
    }
    $table->addRow(array(new CCol(bold(_('Host') . NAME_DELIMITER), 'label'), new CCol(array(new CMultiSelect(array('name' => 'filter_hostid', 'selectedLimit' => 1, 'objectName' => 'hosts', 'objectOptions' => array('editable' => true, 'templated_hosts' => true), 'data' => $hostFilterData, 'popup' => array('parameters' => 'srctbl=host_templates&dstfrm=' . $form->getName() . '&dstfld1=filter_hostid' . '&srcfld1=hostid&writeonly=1', 'width' => 450, 'height' => 450, 'buttonClass' => 'input filter-multiselect-select-button')))), 'col1'), new CCol($updateIntervalLabel, 'label'), new CCol($updateIntervalInput), new CCol($dataTypeLabel, 'label'), new CCol($dataTypeInput), new CCol(bold(_('Status') . NAME_DELIMITER), 'label col4'), new CCol($cmbStatus, 'col4')), 'item-list-row');
    // row 3
    $table->addRow(array(new CCol(bold(_('Application') . NAME_DELIMITER), 'label'), new CCol(array(new CTextBox('filter_application', $filter_application, ZBX_TEXTBOX_FILTER_SIZE), new CButton('btn_app', _('Select'), 'return PopUp("popup.php?srctbl=applications&srcfld1=name' . '&dstfrm=' . $form->getName() . '&dstfld1=filter_application' . '&with_applications=1' . '" + (jQuery("input[name=\'filter_hostid\']").length > 0 ? "&hostid="+jQuery("input[name=\'filter_hostid\']").val() : "")' . ', 550, 450, "application");', 'filter-select-button')), 'col1'), new CCol(array($snmpCommunityLabel, $snmpSecurityLabel), 'label'), new CCol(array($snmpCommunityField, $snmpSecurityField)), new CCol(array(bold(_('History')), SPACE . _('(in days)') . NAME_DELIMITER), 'label'), new CCol(new CNumericBox('filter_history', $filter_history, 8, false, true)), new CCol(bold(_('Triggers') . NAME_DELIMITER), 'label'), new CCol(new CComboBox('filter_with_triggers', $filter_with_triggers, null, array(-1 => _('all'), 1 => _('With triggers'), 0 => _('Without triggers'))))), 'item-list-row');
    // row 4
    $table->addRow(array(new CCol(array(bold(_('Name')), SPACE . _('like') . NAME_DELIMITER), 'label'), new CCol(new CTextBox('filter_name', $filter_name, ZBX_TEXTBOX_FILTER_SIZE), 'col1'), new CCol($snmpOidLabel, 'label'), new CCol($snmpOidField), new CCol(array(bold(_('Trends')), SPACE . _('(in days)') . NAME_DELIMITER), 'label'), new CCol(new CNumericBox('filter_trends', $filter_trends, 8, false, true)), new CCol(bold(_('Template') . NAME_DELIMITER), 'label'), new CCol(new CComboBox('filter_templated_items', $filter_templated_items, null, array(-1 => _('all'), 1 => _('Templated items'), 0 => _('Not Templated items'))))), 'item-list-row');
    // row 5
    $table->addRow(array(new CCol(array(bold(_('Key')), SPACE . _('like') . NAME_DELIMITER), 'label'), new CCol(new CTextBox('filter_key', $filter_key, ZBX_TEXTBOX_FILTER_SIZE), 'col1'), new CCol($portLabel, 'label'), new CCol($portField), new CCol(null, 'label'), new CCol(), new CCol(null, 'label'), new CCol()), 'item-list-row');
    $filter = new CSubmit('filter_set', _('Filter'), 'chkbxRange.clearSelectedOnFilterChange();');
    $filter->useJQueryStyle('main');
    $reset = new CSubmit('filter_rst', _('Reset'), 'chkbxRange.clearSelectedOnFilterChange();');
    $reset->useJQueryStyle();
    $div_buttons = new CDiv(array($filter, SPACE, $reset));
    $div_buttons->setAttribute('style', 'padding: 4px 0px;');
    $footer = new CCol($div_buttons, 'controls', 8);
    $table->addRow($footer);
    $form->addItem($table);
    // subfilters
    $table_subfilter = new CTable(null, 'filter sub-filter');
    // array contains subfilters and number of items in each
    $item_params = array('hosts' => array(), 'applications' => array(), 'types' => array(), 'value_types' => array(), 'status' => array(), 'state' => array(), 'templated_items' => array(), 'with_triggers' => array(), 'history' => array(), 'trends' => array(), 'interval' => array());
    // generate array with values for subfilters of selected items
    foreach ($items as $item) {
        // hosts
        if (zbx_empty($filter_hostId)) {
            $host = reset($item['hosts']);
            if (!isset($item_params['hosts'][$host['hostid']])) {
                $item_params['hosts'][$host['hostid']] = array('name' => $host['name'], 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_hosts') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $host = reset($item['hosts']);
                $item_params['hosts'][$host['hostid']]['count']++;
            }
        }
        // applications
        if (!empty($item['applications'])) {
            foreach ($item['applications'] as $application) {
                if (!isset($item_params['applications'][$application['name']])) {
                    $item_params['applications'][$application['name']] = array('name' => $application['name'], 'count' => 0);
                }
            }
        }
        $show_item = true;
        foreach ($item['subfilters'] as $name => $value) {
            if ($name == 'subfilter_apps') {
                continue;
            }
            $show_item &= $value;
        }
        $sel_app = false;
        if ($show_item) {
            // if any of item applications are selected
            foreach ($item['applications'] as $app) {
                if (str_in_array($app['name'], $subfilter_apps)) {
                    $sel_app = true;
                    break;
                }
            }
            foreach ($item['applications'] as $app) {
                if (str_in_array($app['name'], $subfilter_apps) || !$sel_app) {
                    $item_params['applications'][$app['name']]['count']++;
                }
            }
        }
        // types
        if ($filter_type == -1) {
            if (!isset($item_params['types'][$item['type']])) {
                $item_params['types'][$item['type']] = array('name' => item_type2str($item['type']), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_types') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['types'][$item['type']]['count']++;
            }
        }
        // value types
        if ($filter_value_type == -1) {
            if (!isset($item_params['value_types'][$item['value_type']])) {
                $item_params['value_types'][$item['value_type']] = array('name' => itemValueTypeString($item['value_type']), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_value_types') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['value_types'][$item['value_type']]['count']++;
            }
        }
        // status
        if ($filter_status == -1) {
            if (!isset($item_params['status'][$item['status']])) {
                $item_params['status'][$item['status']] = array('name' => item_status2str($item['status']), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_status') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['status'][$item['status']]['count']++;
            }
        }
        // state
        if ($filter_state == -1) {
            if (!isset($item_params['state'][$item['state']])) {
                $item_params['state'][$item['state']] = array('name' => itemState($item['state']), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_state') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['state'][$item['state']]['count']++;
            }
        }
        // template
        if ($filter_templated_items == -1) {
            if ($item['templateid'] == 0 && !isset($item_params['templated_items'][0])) {
                $item_params['templated_items'][0] = array('name' => _('Not Templated items'), 'count' => 0);
            } elseif ($item['templateid'] > 0 && !isset($item_params['templated_items'][1])) {
                $item_params['templated_items'][1] = array('name' => _('Templated items'), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_templated_items') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                if ($item['templateid'] == 0) {
                    $item_params['templated_items'][0]['count']++;
                } else {
                    $item_params['templated_items'][1]['count']++;
                }
            }
        }
        // with triggers
        if ($filter_with_triggers == -1) {
            if (count($item['triggers']) == 0 && !isset($item_params['with_triggers'][0])) {
                $item_params['with_triggers'][0] = array('name' => _('Without triggers'), 'count' => 0);
            } elseif (count($item['triggers']) > 0 && !isset($item_params['with_triggers'][1])) {
                $item_params['with_triggers'][1] = array('name' => _('With triggers'), 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_with_triggers') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                if (count($item['triggers']) == 0) {
                    $item_params['with_triggers'][0]['count']++;
                } else {
                    $item_params['with_triggers'][1]['count']++;
                }
            }
        }
        // trends
        if (zbx_empty($filter_trends)) {
            if (!isset($item_params['trends'][$item['trends']])) {
                $item_params['trends'][$item['trends']] = array('name' => $item['trends'], 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_trends') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['trends'][$item['trends']]['count']++;
            }
        }
        // history
        if (zbx_empty($filter_history)) {
            if (!isset($item_params['history'][$item['history']])) {
                $item_params['history'][$item['history']] = array('name' => $item['history'], 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_history') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['history'][$item['history']]['count']++;
            }
        }
        // interval
        if (zbx_empty($filter_delay) && $filter_type != ITEM_TYPE_TRAPPER) {
            if (!isset($item_params['interval'][$item['delay']])) {
                $item_params['interval'][$item['delay']] = array('name' => $item['delay'], 'count' => 0);
            }
            $show_item = true;
            foreach ($item['subfilters'] as $name => $value) {
                if ($name == 'subfilter_interval') {
                    continue;
                }
                $show_item &= $value;
            }
            if ($show_item) {
                $item_params['interval'][$item['delay']]['count']++;
            }
        }
    }
    // output
    if (zbx_empty($filter_hostId) && count($item_params['hosts']) > 1) {
        $hosts_output = prepareSubfilterOutput($item_params['hosts'], $subfilter_hosts, 'subfilter_hosts');
        $table_subfilter->addRow(array(_('Hosts'), $hosts_output));
    }
    if (!empty($item_params['applications']) && count($item_params['applications']) > 1) {
        $application_output = prepareSubfilterOutput($item_params['applications'], $subfilter_apps, 'subfilter_apps');
        $table_subfilter->addRow(array(_('Applications'), $application_output));
    }
    if ($filter_type == -1 && count($item_params['types']) > 1) {
        $type_output = prepareSubfilterOutput($item_params['types'], $subfilter_types, 'subfilter_types');
        $table_subfilter->addRow(array(_('Types'), $type_output));
    }
    if ($filter_value_type == -1 && count($item_params['value_types']) > 1) {
        $value_types_output = prepareSubfilterOutput($item_params['value_types'], $subfilter_value_types, 'subfilter_value_types');
        $table_subfilter->addRow(array(_('Type of information'), $value_types_output));
    }
    if ($filter_status == -1 && count($item_params['status']) > 1) {
        $status_output = prepareSubfilterOutput($item_params['status'], $subfilter_status, 'subfilter_status');
        $table_subfilter->addRow(array(_('Status'), $status_output));
    }
    if ($filter_state == -1 && count($item_params['state']) > 1) {
        $state_output = prepareSubfilterOutput($item_params['state'], $subfilter_state, 'subfilter_state');
        $table_subfilter->addRow(array(_('State'), $state_output));
    }
    if ($filter_templated_items == -1 && count($item_params['templated_items']) > 1) {
        $templated_items_output = prepareSubfilterOutput($item_params['templated_items'], $subfilter_templated_items, 'subfilter_templated_items');
        $table_subfilter->addRow(array(_('Template'), $templated_items_output));
    }
    if ($filter_with_triggers == -1 && count($item_params['with_triggers']) > 1) {
        $with_triggers_output = prepareSubfilterOutput($item_params['with_triggers'], $subfilter_with_triggers, 'subfilter_with_triggers');
        $table_subfilter->addRow(array(_('With triggers'), $with_triggers_output));
    }
    if (zbx_empty($filter_history) && count($item_params['history']) > 1) {
        $history_output = prepareSubfilterOutput($item_params['history'], $subfilter_history, 'subfilter_history');
        $table_subfilter->addRow(array(_('History'), $history_output));
    }
    if (zbx_empty($filter_trends) && count($item_params['trends']) > 1) {
        $trends_output = prepareSubfilterOutput($item_params['trends'], $subfilter_trends, 'subfilter_trends');
        $table_subfilter->addRow(array(_('Trends'), $trends_output));
    }
    if (zbx_empty($filter_delay) && $filter_type != ITEM_TYPE_TRAPPER && count($item_params['interval']) > 1) {
        $interval_output = prepareSubfilterOutput($item_params['interval'], $subfilter_interval, 'subfilter_interval');
        $table_subfilter->addRow(array(_('Interval'), $interval_output));
    }
    $form->addItem(new CDiv(_('Subfilter [affects only filtered data!]'), 'thin_header'));
    $form->addItem($table_subfilter);
    return $form;
}
예제 #30
-1
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' !== 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);
    }
}