public function addItem($itemid, $calc_fnc = CALC_FNC_AVG, $color = null, $type = null)
 {
     $this->items[$this->num] = get_item_by_itemid($itemid);
     $this->items[$this->num]['name'] = itemName($this->items[$this->num]);
     $host = get_host_by_hostid($this->items[$this->num]['hostid']);
     $this->items[$this->num]['host'] = $host['name'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
     $this->num++;
 }
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     // if screen is defined in template, then 'real_resourceid' is defined and should be used
     if (!empty($this->screenitem['real_resourceid'])) {
         $this->screenitem['resourceid'] = $this->screenitem['real_resourceid'];
     }
     if ($this->screenitem['dynamic'] == SCREEN_DYNAMIC_ITEM && !empty($this->hostid)) {
         $newitemid = get_same_item_for_host($this->screenitem['resourceid'], $this->hostid);
         $this->screenitem['resourceid'] = !empty($newitemid) ? $newitemid : 0;
     }
     if ($this->screenitem['resourceid'] == 0) {
         $table = new CTableInfo(_('No data defined.'));
         $table->setHeader(array(_('Timestamp'), _('Item')));
         return $this->getOutput($table);
     }
     $item = get_item_by_itemid($this->screenitem['resourceid']);
     switch ($item['value_type']) {
         case ITEM_VALUE_TYPE_TEXT:
         case ITEM_VALUE_TYPE_LOG:
             $orderField = 'id';
             break;
         case ITEM_VALUE_TYPE_FLOAT:
         case ITEM_VALUE_TYPE_UINT64:
         default:
             $orderField = array('itemid', 'clock');
     }
     $host = get_host_by_itemid($this->screenitem['resourceid']);
     $table = new CTableInfo(_('No data defined.'));
     $table->setHeader(array(_('Timestamp'), $host['name'] . ': ' . itemName($item)));
     $stime = zbxDateToTime($this->timeline['stime']);
     $histories = API::History()->get(array('history' => $item['value_type'], 'itemids' => $this->screenitem['resourceid'], 'output' => API_OUTPUT_EXTEND, 'sortorder' => ZBX_SORT_DOWN, 'sortfield' => $orderField, 'limit' => $this->screenitem['elements'], 'time_from' => $stime, 'time_till' => $stime + $this->timeline['period']));
     foreach ($histories as $history) {
         switch ($item['value_type']) {
             case ITEM_VALUE_TYPE_FLOAT:
                 sscanf($history['value'], '%f', $value);
                 break;
             case ITEM_VALUE_TYPE_TEXT:
             case ITEM_VALUE_TYPE_STR:
             case ITEM_VALUE_TYPE_LOG:
                 $value = $this->screenitem['style'] ? new CJSscript($history['value']) : $history['value'];
                 break;
             default:
                 $value = $history['value'];
                 break;
         }
         if ($item['valuemapid'] > 0) {
             $value = applyValueMap($value, $item['valuemapid']);
         }
         $table->addRow(array(zbx_date2str(_('d M Y H:i:s'), $history['clock']), new CCol($value, 'pre')));
     }
     return $this->getOutput($table);
 }
     $type = get_request('type', 0);
     $priority = get_request('priority', 0);
     $comments = get_request('comments', '');
     $url = get_request('url', '');
     $status = get_request('status', 0);
 }
 $keys = get_request('keys', array());
 $frmTRLog->addRow(_('Description'), new CTextBox('description', $description, 80));
 $item = '';
 $db_items = DBselect('SELECT DISTINCT * FROM items WHERE itemid=' . $itemid);
 while ($db_item = DBfetch($db_items)) {
     if ($db_item['templateid']) {
         $template_host = get_realhost_by_itemid($db_item['templateid']);
         $item = $template_host['host'] . ':';
     }
     $item .= itemName($db_item, $db_item['key_']);
 }
 $ctb = new CTextBox('item', $item, 80);
 $ctb->setAttribute('id', 'item');
 $ctb->setAttribute('disabled', 'disabled');
 $script = "javascript: return PopUp('popup.php?dstfrm=" . $frmTRLog->getName() . "&dstfld1=itemid&dstfld2=item&srctbl=items&srcfld1=itemid&srcfld2=name',800,450);";
 $cbtn = new CSubmit('select_item', _('Select'), $script);
 $frmTRLog->addRow(_('Item'), array($ctb, $cbtn));
 $frmTRLog->addVar('itemid', $itemid);
 $exp_select = new CComboBox('expr_type');
 $exp_select->setAttribute('id', 'expr_type');
 $exp_select->addItem(REGEXP_INCLUDE, _('Include'));
 $exp_select->addItem(REGEXP_EXCLUDE, _('Exclude'));
 $ctb = new CTextBox('expression', '', 80);
 $ctb->setAttribute('id', 'logexpr');
 $cb = new CButton('add_exp', _('Add'), 'javascript: add_logexpr();');
예제 #4
0
 }
 // set values for subfilters, if any of subfilters = false then item shouldnt be shown
 if (!empty($data['items'])) {
     // fill template host
     fillItemsWithChildTemplates($data['items']);
     $dbHostItems = DBselect('SELECT i.itemid,h.name,h.hostid' . ' FROM hosts h,items i' . ' WHERE i.hostid=h.hostid' . ' AND ' . dbConditionInt('i.itemid', zbx_objectValues($data['items'], 'templateid')));
     while ($dbHostItem = DBfetch($dbHostItems)) {
         foreach ($data['items'] as $itemid => $item) {
             if ($item['templateid'] == $dbHostItem['itemid']) {
                 $data['items'][$itemid]['template_host'] = $dbHostItem;
             }
         }
     }
     foreach ($data['items'] as &$item) {
         $item['hostids'] = zbx_objectValues($item['hosts'], 'hostid');
         $item['name_expanded'] = itemName($item);
         if (empty($data['filter_hostname'])) {
             $host = reset($item['hosts']);
             $item['host'] = $host['name'];
         }
         $item['subfilters'] = array('subfilter_hosts' => empty($_REQUEST['subfilter_hosts']) || (bool) array_intersect($_REQUEST['subfilter_hosts'], $item['hostids']), 'subfilter_types' => empty($_REQUEST['subfilter_types']) || uint_in_array($item['type'], $_REQUEST['subfilter_types']), 'subfilter_value_types' => empty($_REQUEST['subfilter_value_types']) || uint_in_array($item['value_type'], $_REQUEST['subfilter_value_types']), 'subfilter_status' => empty($_REQUEST['subfilter_status']) || uint_in_array($item['status'], $_REQUEST['subfilter_status']), 'subfilter_templated_items' => empty($_REQUEST['subfilter_templated_items']) || ($item['templateid'] == 0 && uint_in_array(0, $_REQUEST['subfilter_templated_items']) || $item['templateid'] > 0 && uint_in_array(1, $_REQUEST['subfilter_templated_items'])), 'subfilter_with_triggers' => empty($_REQUEST['subfilter_with_triggers']) || count($item['triggers']) == 0 && uint_in_array(0, $_REQUEST['subfilter_with_triggers']) || count($item['triggers']) > 0 && uint_in_array(1, $_REQUEST['subfilter_with_triggers']), 'subfilter_history' => empty($_REQUEST['subfilter_history']) || uint_in_array($item['history'], $_REQUEST['subfilter_history']), 'subfilter_trends' => empty($_REQUEST['subfilter_trends']) || uint_in_array($item['trends'], $_REQUEST['subfilter_trends']), 'subfilter_interval' => empty($_REQUEST['subfilter_interval']) || uint_in_array($item['delay'], $_REQUEST['subfilter_interval']), 'subfilter_apps' => empty($_REQUEST['subfilter_apps']));
         if (!empty($_REQUEST['subfilter_apps'])) {
             foreach ($item['applications'] as $application) {
                 if (str_in_array($application['name'], $_REQUEST['subfilter_apps'])) {
                     $item['subfilters']['subfilter_apps'] = true;
                     break;
                 }
             }
         }
         if (!empty($item['applications'])) {
             order_result($item['applications'], 'name');
 }
 if ($hostInventoryTable['fields'][$inventoryInfo['db_field']]['type'] == DB::FIELD_TYPE_TEXT) {
     $input = new CTextArea('host_inventory[' . $inventoryInfo['db_field'] . ']', $host_inventory[$inventoryInfo['db_field']]);
     $input->addStyle('width: 64em;');
 } else {
     $fieldLength = $hostInventoryTable['fields'][$inventoryInfo['db_field']]['length'];
     $input = new CTextBox('host_inventory[' . $inventoryInfo['db_field'] . ']', $host_inventory[$inventoryInfo['db_field']]);
     $input->setAttribute('maxlength', $fieldLength);
     $input->addStyle('width: ' . ($fieldLength > 64 ? 64 : $fieldLength) . 'em;');
 }
 if ($inventory_mode == HOST_INVENTORY_DISABLED) {
     $input->setAttribute('disabled', 'disabled');
 }
 // link to populating item at the right side (if any)
 if (isset($hostItemsToInventory[$inventoryNo])) {
     $itemName = itemName($hostItemsToInventory[$inventoryNo]);
     $populatingLink = new CLink($itemName, 'items.php?form=update&itemid=' . $hostItemsToInventory[$inventoryNo]['itemid']);
     $populatingLink->setAttribute('title', _s('This field is automatically populated by item "%s".', $itemName));
     $populatingItemCell = array(' ← ', $populatingLink);
     $input->addClass('linked_to_item');
     // this will be used for disabling fields via jquery
     if ($inventory_mode == HOST_INVENTORY_AUTOMATIC) {
         $input->setAttribute('disabled', 'disabled');
     }
 } else {
     $populatingItemCell = '';
 }
 $input->addStyle('float: left;');
 $populatingItem = new CSpan($populatingItemCell, 'populating_item');
 if ($inventory_mode != HOST_INVENTORY_AUTOMATIC) {
     // those links are visible only in automatic mode
/**
 * Retrieve overview table object for items.
 *
 * @param $hostids
 * @param null $view_style
 *
 * @return CTableInfo
 */
function get_items_data_overview($hostids, $view_style)
{
    global $USER_DETAILS;
    $db_items = DBselect('SELECT DISTINCT h.hostid,h.name AS hostname,i.itemid,i.key_,i.value_type,i.lastvalue,i.units,i.lastclock,' . 'i.name,t.priority,i.valuemapid,t.value AS tr_value,t.triggerid' . ' FROM hosts h,items i' . ' LEFT JOIN functions f ON f.itemid=i.itemid' . ' LEFT JOIN triggers t ON t.triggerid=f.triggerid AND t.status=' . TRIGGER_STATUS_ENABLED . ' WHERE ' . dbConditionInt('h.hostid', $hostids) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . ' ORDER BY i.name,i.itemid');
    $options = array('output' => array('name', 'hostid'), 'monitored_hosts' => true, 'hostids' => $hostids, 'with_monitored_items' => true, 'preservekeys' => true);
    if ($view_style == STYLE_LEFT) {
        $options['selectScreens'] = API_OUTPUT_COUNT;
        $options['selectInventory'] = array('hostid');
    }
    // fetch data for the host JS menu
    $hosts = API::Host()->get($options);
    $items = array();
    while ($row = DBfetch($db_items)) {
        $descr = itemName($row);
        $row['hostname'] = get_node_name_by_elid($row['hostid'], null, ': ') . $row['hostname'];
        $hostnames[$row['hostid']] = $row['hostname'];
        // a little tricky check for attempt to overwrite active trigger (value=1) with
        // inactive or active trigger with lower priority.
        if (!isset($items[$descr][$row['hostname']]) || ($items[$descr][$row['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE && $row['tr_value'] == TRIGGER_VALUE_TRUE || ($items[$descr][$row['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE || $row['tr_value'] == TRIGGER_VALUE_TRUE) && $row['priority'] > $items[$descr][$row['hostname']]['severity'])) {
            $items[$descr][$row['hostname']] = array('itemid' => $row['itemid'], 'value_type' => $row['value_type'], 'lastvalue' => $row['lastvalue'], 'lastclock' => $row['lastclock'], 'units' => $row['units'], 'name' => $row['name'], 'valuemapid' => $row['valuemapid'], 'severity' => $row['priority'], 'tr_value' => $row['tr_value'], 'triggerid' => $row['triggerid']);
        }
    }
    $table = new CTableInfo(_('No items defined.'));
    if (empty($hostnames)) {
        return $table;
    }
    $table->makeVerticalRotation();
    order_result($hostnames);
    if ($view_style == STYLE_TOP) {
        $header = array(new CCol(_('Items'), 'center'));
        foreach ($hostnames as $hostname) {
            $header[] = new CCol($hostname, 'vertical_rotation');
        }
        $table->setHeader($header, 'vertical_header');
        foreach ($items as $descr => $ithosts) {
            $tableRow = array(nbsp($descr));
            foreach ($hostnames as $hostname) {
                $tableRow = get_item_data_overview_cells($tableRow, $ithosts, $hostname);
            }
            $table->addRow($tableRow);
        }
    } else {
        $hostScripts = API::Script()->getScriptsByHosts(zbx_objectValues($hosts, 'hostid'));
        foreach ($hostScripts as $hostid => $scripts) {
            $hosts[$hostid]['scripts'] = $scripts;
        }
        $header = array(new CCol(_('Hosts'), 'center'));
        foreach ($items as $descr => $ithosts) {
            $header[] = new CCol($descr, 'vertical_rotation');
        }
        $table->setHeader($header, 'vertical_header');
        foreach ($hostnames as $hostid => $hostname) {
            $host = $hosts[$hostid];
            // host js menu link
            $hostSpan = new CSpan(nbsp($host['name']), 'link_menu menu-host');
            $hostSpan->setAttribute('data-menu', hostMenuData($host, $hostScripts[$host['hostid']]));
            $tableRow = array(new CCol($hostSpan));
            foreach ($items as $ithosts) {
                $tableRow = get_item_data_overview_cells($tableRow, $ithosts, $hostname);
            }
            $table->addRow($tableRow);
        }
    }
    return $table;
}
예제 #7
0
    $userid = CWebUser::$data['userid'];
    $userGroups = getUserGroupsByUserId($userid);
    $sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY f.triggerid' . ' HAVING MIN(r.permission)>' . PERM_DENY . ')';
}
$sql .= ' AND ' . dbConditionInt('t.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . ' GROUP BY e.objectid' . ' ORDER BY cnt_event desc';
$result = DBselect($sql, 100);
while ($row = DBfetch($result)) {
    $triggersEventCount[$row['objectid']] = $row['cnt_event'];
}
$triggers = API::Trigger()->get(array('triggerids' => array_keys($triggersEventCount), 'output' => array('triggerid', 'description', 'expression', 'priority', 'flags', 'url', 'lastchange'), 'selectItems' => array('hostid', 'name', 'value_type', 'key_'), 'selectHosts' => array('hostid'), 'expandDescription' => true, 'expandData' => true, 'preservekeys' => true, 'nopermissions' => true));
$hostIds = array();
foreach ($triggers as $triggerId => $trigger) {
    $hostIds[$trigger['hostid']] = $trigger['hostid'];
    $triggerItems = array();
    foreach ($trigger['items'] as $item) {
        $triggerItems[] = array('name' => itemName($item), 'params' => array('itemid' => $item['itemid'], 'action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues'));
    }
    $triggers[$triggerId]['items'] = $triggerItems;
    $triggers[$triggerId]['cnt_event'] = $triggersEventCount[$triggerId];
}
CArrayHelper::sort($triggers, array(array('field' => 'cnt_event', 'order' => ZBX_SORT_DOWN), 'host', 'description', 'priority'));
$hosts = API::Host()->get(array('output' => array('hostid'), 'hostids' => $hostIds, 'selectScreens' => API_OUTPUT_COUNT, 'preservekeys' => true));
$scripts = API::Script()->getScriptsByHosts($hostIds);
foreach ($triggers as $trigger) {
    $hostId = $trigger['hostid'];
    $hostName = new CSpan($trigger['hostname'], 'link_menu');
    $hostName->setMenuPopup(getMenuPopupHost($hosts[$hostId], $scripts[$hostId]));
    $triggerDescription = new CSpan($trigger['description'], 'link_menu');
    $triggerDescription->setMenuPopup(getMenuPopupTrigger($trigger, $trigger['items']));
    $table->addRow(array(get_node_name_by_elid($trigger['triggerid']), $hostName, $triggerDescription, getSeverityCell($trigger['priority']), $trigger['cnt_event']));
}
예제 #8
0
 }
 // actions
 $actions = getEventActionsStatus(zbx_objectValues($events, 'eventid'));
 // events
 foreach ($events as $enum => $event) {
     $trigger = $triggers[$event['objectid']];
     $host = reset($trigger['hosts']);
     $host = $hosts[$host['hostid']];
     $items = array();
     foreach ($trigger['items'] as $item) {
         $i = array();
         $i['itemid'] = $item['itemid'];
         $i['value_type'] = $item['value_type'];
         // ZBX-3059: So it would be possible to show different caption for history for chars and numbers (KB)
         $i['action'] = str_in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues';
         $i['name'] = itemName($item);
         $items[] = $i;
     }
     $ack = getEventAckState($event, true);
     $description = CEventHelper::expandDescription(zbx_array_merge($trigger, array('clock' => $event['clock'], 'ns' => $event['ns'])));
     $tr_desc = new CSpan($description, 'pointer');
     $tr_desc->addAction('onclick', "create_mon_trigger_menu(event, " . " [{'triggerid': '" . $trigger['triggerid'] . "', 'lastchange': '" . $event['clock'] . "'}]," . zbx_jsvalue($items, true) . ");");
     // duration
     if ($nextEvent = get_next_event($event, $events, $_REQUEST['showUnknown'])) {
         $event['duration'] = zbx_date2age($event['clock'], $nextEvent['clock']);
     } else {
         $event['duration'] = zbx_date2age($event['clock']);
     }
     $statusSpan = new CSpan(trigger_value2str($event['value']));
     // add colors and blinking to span depending on configuration and trigger parameters
     addTriggerValueStyle($statusSpan, $event['value'], $event['clock'], $event['acknowledged']);
// create filter
if ($this->data['action'] == 'showvalues' || $this->data['action'] == 'showlatest') {
    if (isset($this->data['iv_string'][$this->data['item']['value_type']])) {
        $filterForm = new CFormTable(null, null, 'get');
        $filterForm->setAttribute('name', 'zbx_filter');
        $filterForm->setAttribute('id', 'zbx_filter');
        $filterForm->addVar('action', $this->data['action']);
        $filterForm->addVar('itemid', zbx_toHash($_REQUEST['itemid']));
        $itemListbox = new CListBox('cmbitemlist[]');
        foreach ($this->data['items'] as $itemid => $item) {
            if (!isset($this->data['iv_string'][$item['value_type']])) {
                unset($this->data['items'][$itemid]);
                continue;
            }
            $host = reset($item['hosts']);
            $itemListbox->addItem($itemid, $host['name'] . ': ' . itemName($item));
        }
        $addItemButton = new CButton('add_log', _('Add'), "return PopUp('popup.php?multiselect=1&real_hosts=1" . '&reference=itemid&srctbl=items&value_types[]=' . $this->data['item']['value_type'] . "&srcfld1=itemid');");
        $deleteItemButton = null;
        if (count($this->data['items']) > 1) {
            insert_js_function('removeSelectedItems');
            $deleteItemButton = new CSubmit('remove_log', _('Remove selected'), "javascript: removeSelectedItems('cmbitemlist_', 'itemid')");
        }
        $filterForm->addRow(_('Items list'), array($itemListbox, BR(), $addItemButton, $deleteItemButton));
        $filterForm->addRow(_('Select rows with value like'), new CTextBox('filter', get_request('filter', ''), ZBX_TEXTBOX_FILTER_SIZE));
        $filterTask = get_request('filter_task', 0);
        $taskComboBox = new CComboBox('filter_task', $filterTask, 'submit()');
        $taskComboBox->addItem(FILTER_TASK_SHOW, _('Show selected'));
        $taskComboBox->addItem(FILTER_TASK_HIDE, _('Hide selected'));
        $taskComboBox->addItem(FILTER_TASK_MARK, _('Mark selected'));
        $taskComboBox->addItem(FILTER_TASK_INVERT_MARK, _('Mark others'));
예제 #10
0
    $sql .= ' AND EXISTS (' . 'SELECT NULL' . ' FROM functions f,items i,hosts_groups hgg' . ' JOIN rights r' . ' ON r.id=hgg.groupid' . ' AND ' . dbConditionInt('r.groupid', $userGroups) . ' WHERE t.triggerid=f.triggerid' . ' AND f.itemid=i.itemid' . ' AND i.hostid=hgg.hostid' . ' GROUP BY f.triggerid' . ' HAVING MIN(r.permission)>=' . PERM_READ_ONLY . ')';
}
$sql .= ' AND ' . dbConditionInt('t.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . ' GROUP BY e.objectid' . ' ORDER BY cnt_event desc';
$result = DBselect($sql, 100);
while ($row = DBfetch($result)) {
    $triggersEventCount[$row['objectid']] = $row['cnt_event'];
}
$triggers = API::Trigger()->get(array('triggerids' => array_keys($triggersEventCount), 'output' => array('triggerid', 'description', 'expression', 'priority', 'flags', 'lastchange'), 'selectItems' => array('hostid', 'name', 'value_type', 'key_'), 'expandDescription' => true, 'expandData' => true, 'preservekeys' => true, 'nopermissions' => true));
$hosts = array();
foreach ($triggers as $tid => $trigger) {
    $hosts[$trigger['hostid']] = $trigger['hostid'];
    $trigger['cnt_event'] = $triggersEventCount[$tid];
    $items = $trigger['items'];
    $trigger['items'] = array();
    foreach ($items as $item) {
        $trigger['items'][$item['itemid']] = array('itemid' => $item['itemid'], 'action' => str_in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues', 'name' => itemName($item), 'value_type' => $item['value_type']);
    }
    $triggers[$tid] = $trigger;
}
CArrayHelper::sort($triggers, array(array('field' => 'cnt_event', 'order' => ZBX_SORT_DOWN), 'host', 'description', 'priority'));
$scripts_by_hosts = API::Script()->getScriptsByHosts($hosts);
foreach ($triggers as $trigger) {
    $menus = '';
    $host_nodeid = id2nodeid($trigger['hostid']);
    foreach ($scripts_by_hosts[$trigger['hostid']] as $script) {
        $script_nodeid = id2nodeid($script['scriptid']);
        if (bccomp($host_nodeid, $script_nodeid) == 0) {
            $menus .= "['" . $script['name'] . "',\"javascript: openWinCentered('scripts_exec.php?execute=1&hostid=" . $trigger['hostid'] . "&scriptid=" . $script['scriptid'] . "','Global script',760,540,'titlebar=no, resizable=yes, scrollbars=yes, dialog=no');\", null,{'outer' : ['pum_o_item'],'inner' : ['pum_i_item']}],";
        }
    }
    $menus .= "['" . _('URLs') . "',null,null,{'outer' : ['pum_oheader'],'inner' : ['pum_iheader']}],";
예제 #11
0
            $table->addRow(array($proxy['host'], getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $sec_10[$proxyid], !$sec_10[$proxyid]), getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $sec_30[$proxyid], !$sec_30[$proxyid]), getSeverityCell(TRIGGER_SEVERITY_WARNING, $sec_60[$proxyid], !$sec_60[$proxyid]), getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $sec_300[$proxyid], !$sec_300[$proxyid]), getSeverityCell(TRIGGER_SEVERITY_HIGH, $sec_600[$proxyid], !$sec_600[$proxyid]), getSeverityCell(TRIGGER_SEVERITY_DISASTER, $sec_rest[$proxyid], !$sec_rest[$proxyid])));
        }
    } else {
        if ($_REQUEST['config'] == 2) {
            $arr = array();
            $table->setHeader(array(_('Next check'), _('Delayed by'), is_show_all_nodes() ? _('Node') : null, _('Host'), _('Name')));
            while ($row = DBfetch($result)) {
                $res = calculateItemNextcheck($row['interfaceid'], $row['itemid'], $row['type'], $row['delay'], $row['delay_flex'], $row['lastclock']);
                if (0 != $row['proxy_hostid'] && 0 != $res['delay']) {
                    $res['nextcheck'] = $row['lastclock'] + $res['delay'];
                }
                $diff = $now - $res['nextcheck'];
                if ($diff <= 5) {
                    continue;
                }
                $arr[] = array($res['nextcheck'], $row['hostid'], $row['hostname'], itemName($row));
            }
            $rows = 0;
            sort($arr);
            foreach ($arr as $r) {
                $rows++;
                if ($rows > 500) {
                    $truncated = true;
                    break;
                }
                $table->addRow(array(zbx_date2str(QUEUE_NODES_DATE_FORMAT, $r[0]), zbx_date2age($r[0]), get_node_name_by_elid($r[1]), $r[2], $r[3]));
            }
        }
    }
}
$queue_wdgt->addItem($table);
예제 #12
0
        }
        $table->addRow(array($proxy['host'], getSeverityCell(TRIGGER_SEVERITY_NOT_CLASSIFIED, $proxyData['delay5'], !$proxyData['delay5']), getSeverityCell(TRIGGER_SEVERITY_INFORMATION, $proxyData['delay10'], !$proxyData['delay10']), getSeverityCell(TRIGGER_SEVERITY_WARNING, $proxyData['delay30'], !$proxyData['delay30']), getSeverityCell(TRIGGER_SEVERITY_AVERAGE, $proxyData['delay60'], !$proxyData['delay60']), getSeverityCell(TRIGGER_SEVERITY_HIGH, $proxyData['delay300'], !$proxyData['delay300']), getSeverityCell(TRIGGER_SEVERITY_DISASTER, $proxyData['delay600'], !$proxyData['delay600'])));
    }
} elseif ($config == QUEUE_DETAILS) {
    $queueData = zbx_toHash($queueData, 'itemid');
    $items = API::Item()->get(array('output' => array('itemid', 'name', 'key_'), 'selectHosts' => array('name'), 'itemids' => array_keys($queueData), 'webitems' => true, 'preservekeys' => true));
    $table->setHeader(array(_('Scheduled check'), _('Delayed by'), is_show_all_nodes() ? _('Node') : null, _('Host'), _('Name')));
    $i = 0;
    foreach ($queueData as $itemData) {
        if (!isset($items[$itemData['itemid']])) {
            continue;
        }
        // display only the first 500 items
        $i++;
        if ($i > QUEUE_DETAIL_ITEM_COUNT) {
            break;
        }
        $item = $items[$itemData['itemid']];
        $host = reset($item['hosts']);
        $table->addRow(array(zbx_date2str(QUEUE_NODES_DATE_FORMAT, $itemData['nextcheck']), zbx_date2age($itemData['nextcheck']), get_node_name_by_elid($item['itemid']), $host['name'], itemName($item)));
    }
}
$queueWidget->addItem($table);
$queueWidget->show();
// display the table footer
if ($config == QUEUE_OVERVIEW_BY_PROXY) {
    show_table_header(_('Total') . ': ' . $table->getNumRows());
} elseif ($config == QUEUE_DETAILS) {
    show_table_header(_('Total') . ': ' . $table->getNumRows() . (count($queueData) > QUEUE_DETAIL_ITEM_COUNT ? ' (' . _('Truncated') . ')' : ''));
}
require_once dirname(__FILE__) . '/include/page_footer.php';
/**
 * Creates and returns a trigger status cell for the trigger overview table.
 *
 * @see get_triggers_overview()
 *
 * @param array $triggerHosts	an array with the data about the trigger for each host
 * @param string $hostName		the name of the cells corresponding host
 * @param string $screenId
 *
 * @return CCol
 */
function get_trigger_overview_cells($triggerHosts, $hostName, $screenId = null)
{
    $ack = null;
    $css_class = null;
    $desc = array();
    $config = select_config();
    // for how long triggers should blink on status change (set by user in administration->general)
    if (isset($triggerHosts[$hostName])) {
        // problem trigger
        if ($triggerHosts[$hostName]['value'] == TRIGGER_VALUE_TRUE) {
            $css_class = getSeverityStyle($triggerHosts[$hostName]['priority']);
            $ack = null;
            if ($config['event_ack_enable'] == 1) {
                $event = get_last_event_by_triggerid($triggerHosts[$hostName]['triggerid']);
                if ($event) {
                    if ($screenId) {
                        global $page;
                        $ack_menu = array(_('Acknowledge'), 'acknow.php?eventid=' . $event['eventid'] . '&screenid=' . $screenId . '&backurl=' . $page['file']);
                    } else {
                        $ack_menu = array(_('Acknowledge'), 'acknow.php?eventid=' . $event['eventid'] . '&backurl=overview.php', array('tw' => '_blank'));
                    }
                    if ($event['acknowledged'] == 1) {
                        $ack = new CImg('images/general/tick.png', 'ack');
                    }
                }
            }
        } else {
            $css_class = 'normal';
        }
        $style = 'cursor: pointer; ';
        // set blinking gif as background if trigger age is less then $config['blink_period']
        if ($config['blink_period'] > 0 && time() - $triggerHosts[$hostName]['lastchange'] < $config['blink_period']) {
            $style .= 'background-image: url(images/gradients/blink.gif); background-position: top left; background-repeat: repeat;';
        }
        unset($item_menu);
        $tr_ov_menu = array(array(_('Trigger'), null, null, array('outer' => array('pum_oheader'), 'inner' => array('pum_iheader'))), array(_('Events'), 'events.php?triggerid=' . $triggerHosts[$hostName]['triggerid'], array('tw' => '_blank')));
        if (isset($ack_menu)) {
            $tr_ov_menu[] = $ack_menu;
        }
        $dbItems = DBselect('SELECT DISTINCT i.itemid,i.name,i.key_,i.value_type' . ' FROM items i,functions f' . ' WHERE f.itemid=i.itemid' . ' AND f.triggerid=' . $triggerHosts[$hostName]['triggerid']);
        while ($item = DBfetch($dbItems)) {
            $description = itemName($item);
            switch ($item['value_type']) {
                case ITEM_VALUE_TYPE_UINT64:
                case ITEM_VALUE_TYPE_FLOAT:
                    $action = 'showgraph';
                    $status_bar = _('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 = _('Show values of item') . ' \'' . $description . '\'';
                    break;
            }
            if (zbx_strlen($description) > 25) {
                $description = zbx_substr($description, 0, 22) . '...';
            }
            $item_menu[$action][] = array($description, 'history.php?action=' . $action . '&itemid=' . $item['itemid'] . '&period=3600', array('tw' => '', 'sb' => $status_bar));
        }
        if (isset($item_menu['showgraph'])) {
            $tr_ov_menu[] = array(_('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(_('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
        $triggerid = !empty($triggerHosts[$hostName]['triggerid']) ? $triggerHosts[$hostName]['triggerid'] : 0;
        $dep_table = new CTableInfo();
        $dep_table->setAttribute('style', 'width: 200px;');
        $dep_table->addRow(bold(_('Depends on') . ':'));
        $dependency = false;
        $dep_res = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_down=' . $triggerid);
        while ($dep_row = DBfetch($dep_res)) {
            $dep_table->addRow(SPACE . '-' . SPACE . CTriggerHelper::expandDescriptionById($dep_row['triggerid_up']));
            $dependency = true;
        }
        if ($dependency) {
            $img = new Cimg('images/general/arrow_down2.png', 'DEP_DOWN');
            $img->setAttribute('style', 'vertical-align: middle; border: 0px;');
            $img->setHint($dep_table, '', '', false);
            array_push($desc, $img);
        }
        unset($img, $dep_table, $dependency);
        // triggers that depend on this
        $dep_table = new CTableInfo();
        $dep_table->setAttribute('style', 'width: 200px;');
        $dep_table->addRow(bold(_('Dependent') . ':'));
        $dependency = false;
        $dep_res = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_up=' . $triggerid);
        while ($dep_row = DBfetch($dep_res)) {
            $dep_table->addRow(SPACE . '-' . SPACE . CTriggerHelper::expandDescriptionById($dep_row['triggerid_down']));
            $dependency = true;
        }
        if ($dependency) {
            $img = new Cimg('images/general/arrow_up2.png', 'DEP_UP');
            $img->setAttribute('style', 'vertical-align: middle; border: 0px;');
            $img->setHint($dep_table, '', '', false);
            array_push($desc, $img);
        }
        unset($img, $dep_table, $dependency);
    }
    if (is_array($desc) && count($desc) > 0 || $ack) {
        $tableColumn = new CCol(array($desc, $ack), $css_class . ' hosts');
    } else {
        $tableColumn = new CCol(SPACE, $css_class . ' hosts');
    }
    if (isset($style)) {
        $tableColumn->setAttribute('style', $style);
    }
    if (isset($tr_ov_menu)) {
        $tr_ov_menu = new CPUMenu($tr_ov_menu, 170);
        $tableColumn->onClick($tr_ov_menu->getOnActionJS());
        $tableColumn->addAction('onmouseover', 'jQuery(this).css({border: "1px dotted #0C0CF0", padding: "0 2px"})');
        $tableColumn->addAction('onmouseout', 'jQuery(this).css({border: "", padding: "1px 3px"})');
    }
    return $tableColumn;
}
$dstfld1 = get_request('dstfld1', '');
$itemid = get_request('itemid', 0);
$value = get_request('value', 0);
$param = get_request('param', 0);
$paramtype = get_request('paramtype');
if (!isset($function)) {
    $function = 'last[=]';
    $expr_type = $function;
}
if ($itemid) {
    $items_data = API::Item()->get(array('output' => API_OUTPUT_EXTEND, 'itemids' => $itemid, 'webitems' => true, 'selectHosts' => API_OUTPUT_EXTEND, 'filter' => array('flags' => null)));
    $item_data = reset($items_data);
    $item_key = $item_data['key_'];
    $item_host = reset($item_data['hosts']);
    $item_host = $item_host['host'];
    $description = $item_host . ':' . itemName($item_data);
} else {
    $item_key = $item_host = $description = '';
}
if (is_null($paramtype) && isset($functions[$expr_type]['params']['M'])) {
    $paramtype = is_array($functions[$expr_type]['params']['M']) ? reset($functions[$expr_type]['params']['M']) : $functions[$expr_type]['params']['M'];
} elseif (is_null($paramtype)) {
    $paramtype = PARAM_TYPE_SECONDS;
}
if (!is_array($param)) {
    if (isset($functions[$expr_type]['params'])) {
        $param = explode(',', $param, count($functions[$expr_type]['params']));
    } else {
        $param = array($param);
    }
}
    $graphFormList->addRow(_('Y axis MIN value'), $yaxisMinData);
    $yaxisMaxData = array();
    $yTypeComboBox = new CComboBox('ymax_type', $this->data['ymax_type'], 'submit()');
    $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_CALCULATED, _('Calculated'));
    $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_FIXED, _('Fixed'));
    $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, _('Item'));
    $yaxisMaxData[] = $yTypeComboBox;
    if ($this->data['ymax_type'] == GRAPH_YAXIS_TYPE_FIXED) {
        $yaxisMaxData[] = new CTextBox('yaxismax', $this->data['yaxismax'], 7);
    } elseif ($this->data['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE) {
        $graphForm->addVar('yaxismax', $this->data['yaxismax']);
        $ymax_name = '';
        if (!empty($this->data['ymax_itemid'])) {
            $max_host = get_host_by_itemid($this->data['ymax_itemid']);
            $max_item = get_item_by_itemid($this->data['ymax_itemid']);
            $ymax_name = $max_host['name'] . NAME_DELIMITER . itemName($max_item);
        }
        $yaxisMaxData[] = new CTextBox('ymax_name', $ymax_name, 36, 'yes');
        $yaxisMaxData[] = new CButton('yaxis_max', _('Select'), 'javascript: ' . 'return PopUp("popup.php?dstfrm=' . $graphForm->getName() . '&dstfld1=ymax_itemid' . '&dstfld2=ymax_name' . '&srctbl=items' . '&srcfld1=itemid' . '&srcfld2=name' . '&numeric=1' . '&writeonly=1" + getOnlyHostParam(), 0, 0, "zbx_popup_item");', 'formlist');
        // select prototype button
        if (!empty($this->data['parent_discoveryid'])) {
            $yaxisMaxData[] = new CButton('yaxis_max_prototype', _('Select prototype'), 'javascript: ' . 'return PopUp("popup.php?dstfrm=' . $graphForm->getName() . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&dstfld1=ymax_itemid' . '&dstfld2=ymax_name' . '&srctbl=prototypes' . '&srcfld1=itemid' . '&srcfld2=name' . '&numeric=1", 0, 0, "zbx_popup_item");', 'formlist');
        }
    } else {
        $graphForm->addVar('yaxismax', $this->data['yaxismax']);
    }
    $graphFormList->addRow(_('Y axis MAX value'), $yaxisMaxData);
} else {
    $graphFormList->addRow(_('3D view'), new CCheckBox('show_3d', $this->data['show_3d'], null, 1));
}
$graphFormList->addRow(_('Items'), new CDiv($itemsTable, 'objectgroup inlineblock border_dotted ui-corner-all'));
예제 #16
0
$dstfld1 = get_request('dstfld1', '');
$itemId = get_request('itemid', 0);
$value = get_request('value', 0);
$param = get_request('param', 0);
$paramType = get_request('paramtype');
if (!isset($function)) {
    $function = 'last[=]';
    $exprType = $function;
}
if ($itemId) {
    $items = API::Item()->get(array('output' => array('itemid', 'key_', 'name'), 'itemids' => $itemId, 'webitems' => true, 'selectHosts' => array('host'), 'filter' => array('flags' => null)));
    $item = reset($items);
    $itemKey = $item['key_'];
    $itemHost = reset($item['hosts']);
    $itemHost = $itemHost['host'];
    $description = $itemHost . NAME_DELIMITER . itemName($item);
} else {
    $itemKey = $itemHost = $description = '';
}
if (is_null($paramType) && isset($functions[$exprType]['params']['M'])) {
    $paramType = is_array($functions[$exprType]['params']['M']) ? reset($functions[$exprType]['params']['M']) : $functions[$exprType]['params']['M'];
} elseif (is_null($paramType)) {
    $paramType = PARAM_TYPE_TIME;
}
if (!is_array($param)) {
    if (isset($functions[$exprType]['params'])) {
        $param = explode(',', $param, count($functions[$exprType]['params']));
    } else {
        $param = array($param);
    }
}
$discoveryForm->setName('discovery');
$discoveryForm->addVar('hostid', $this->data['hostid']);
// create table
$discoveryTable = new CTableInfo(_('No discovery rules found.'));
$sortLink = new CUrl();
$sortLink->setArgument('hostid', $this->data['hostid']);
$sortLink = $sortLink->getUrl();
$discoveryTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $discoveryForm->getName() . "', 'all_items', 'g_hostdruleid');"), make_sorting_header(_('Name'), 'name', $sortLink), _('Items'), _('Triggers'), _('Graphs'), $data['host']['flags'] == ZBX_FLAG_DISCOVERY_NORMAL ? _('Hosts') : null, make_sorting_header(_('Key'), 'key_', $sortLink), make_sorting_header(_('Interval'), 'delay', $sortLink), make_sorting_header(_('Type'), 'type', $sortLink), make_sorting_header(_('Status'), 'status', $sortLink), $data['showErrorColumn'] ? _('Error') : null));
foreach ($data['discoveries'] as $discovery) {
    $description = array();
    if ($discovery['templateid']) {
        $template_host = get_realhost_by_itemid($discovery['templateid']);
        $description[] = new CLink($template_host['name'], '?hostid=' . $template_host['hostid'], 'unknown');
        $description[] = NAME_DELIMITER;
    }
    $discovery['name_expanded'] = itemName($discovery);
    $description[] = new CLink($discovery['name_expanded'], '?form=update&itemid=' . $discovery['itemid']);
    $status = new CLink(itemIndicator($discovery['status'], $discovery['state']), '?hostid=' . $_REQUEST['hostid'] . '&g_hostdruleid=' . $discovery['itemid'] . '&go=' . ($discovery['status'] ? 'activate' : 'disable'), itemIndicatorStyle($discovery['status'], $discovery['state']));
    if ($data['showErrorColumn']) {
        $error = '';
        if ($discovery['status'] == ITEM_STATUS_ACTIVE) {
            if (zbx_empty($discovery['error'])) {
                $error = new CDiv(SPACE, 'status_icon iconok');
            } else {
                $error = new CDiv(SPACE, 'status_icon iconerror');
                $error->setHint($discovery['error'], '', 'on');
            }
        }
    }
    // host prototype link
    $hostPrototypeLink = null;
 $graphFormList->addRow(_('Y axis MIN value'), $yaxisMinData);
 $yaxisMaxData = array();
 $yTypeComboBox = new CComboBox('ymax_type', $this->data['ymax_type'], 'submit()');
 $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_CALCULATED, _('Calculated'));
 $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_FIXED, _('Fixed'));
 $yTypeComboBox->addItem(GRAPH_YAXIS_TYPE_ITEM_VALUE, _('Item'));
 $yaxisMaxData[] = $yTypeComboBox;
 if ($this->data['ymax_type'] == GRAPH_YAXIS_TYPE_FIXED) {
     $yaxisMaxData[] = new CTextBox('yaxismax', $this->data['yaxismax'], 7);
 } elseif ($this->data['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE) {
     $graphForm->addVar('yaxismax', $this->data['yaxismax']);
     $ymax_name = '';
     if (!empty($this->data['ymax_itemid'])) {
         $max_host = get_host_by_itemid($this->data['ymax_itemid']);
         $max_item = get_item_by_itemid($this->data['ymax_itemid']);
         $ymax_name = $max_host['name'] . ': ' . itemName($max_item);
     }
     if (!empty($this->data['items'])) {
         $yaxisMaxData[] = new CTextBox('ymax_name', $ymax_name, 36, 'yes');
         $yaxisMaxData[] = new CButton('yaxis_max', _('Select'), 'javascript: ' . 'return PopUp("popup.php?dstfrm=' . $graphForm->getName() . '&dstfld1=ymax_itemid' . '&dstfld2=ymax_name' . '&srctbl=items' . '&srcfld1=itemid' . '&srcfld2=name" + getOnlyHostParam(), 0, 0, "zbx_popup_item");', 'formlist');
         // select prototype button
         if (!empty($this->data['parent_discoveryid'])) {
             $yaxisMaxData[] = new CButton('yaxis_min', _('Select prototype'), 'javascript: ' . 'return PopUp("popup.php?dstfrm=' . $graphForm->getName() . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&dstfld1=ymax_itemid' . '&dstfld2=ymax_name' . '&srctbl=prototypes' . '&srcfld1=itemid' . '&srcfld2=name", 0, 0, "zbx_popup_item");', 'formlist');
         }
     } else {
         $yaxisMaxData[] = SPACE;
         $yaxisMaxData[] = new CSpan(_('Add graph items first'), 'red');
     }
 } else {
     $graphForm->addVar('yaxismax', $this->data['yaxismax']);
 }
        $nodeName = get_node_name_by_elid($map['sysmapid']);
        if (!zbx_empty($nodeName)) {
            $caption = '(' . $nodeName . ') ' . $caption;
        }
    }
    $screenFormList->addVar('resourceid', $id);
    $screenFormList->addRow(_('Parameter'), array(new CTextBox('caption', $caption, ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=sysmaps&srcfld1=sysmapid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&writeonly=1", 400, 450);', 'formlist')));
} elseif ($resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) {
    $caption = '';
    $id = 0;
    $items = API::Item()->get(array('itemids' => $resourceid, 'selectHosts' => array('hostid', 'name'), 'output' => API_OUTPUT_EXTEND));
    if (!empty($items)) {
        $id = $resourceid;
        $item = reset($items);
        $item['host'] = reset($item['hosts']);
        $caption = $item['host']['name'] . ':' . itemName($item);
        $nodeName = get_node_name_by_elid($item['itemid']);
        if (!zbx_empty($nodeName)) {
            $caption = '(' . $nodeName . ') ' . $caption;
        }
    }
    if ($this->data['screen']['templateid']) {
        $selectButton = new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=items&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&templated_hosts=1&only_hostid=' . $this->data['screen']['templateid'] . '&writeonly=1", 800, 450);', 'formlist');
    } else {
        $selectButton = new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=items&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&real_hosts=1&writeonly=1&templated=0", 800, 450);', 'formlist');
    }
    $screenFormList->addVar('resourceid', $id);
    $screenFormList->addRow(_('Parameter'), array(new CTextBox('caption', $caption, ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), $selectButton));
    $screenFormList->addRow(_('Show lines'), new CNumericBox('elements', $elements, 2));
    $screenFormList->addRow(_('Show text as HTML'), new CCheckBox('style', $style, null, 1));
} else {
    if ($resourceId > 0) {
        $data = API::HostGroup()->get(array('groupids' => $resourceId, 'nodeids' => get_current_nodeid(true), 'output' => array('groupid', 'name'), 'editable' => true));
        if ($data) {
            $data = reset($data);
            $data['prefix'] = get_node_name_by_elid($data['groupid'], true, NAME_DELIMITER);
        }
    }
    $screenFormList->addRow(_('Group'), new CMultiSelect(array('name' => 'resourceid', 'objectName' => 'hostGroup', 'objectOptions' => array('editable' => true), 'data' => $data ? array(array('id' => $data['groupid'], 'name' => $data['name'], 'prefix' => $data['prefix'])) : null, 'defaultValue' => 0, 'selectedLimit' => 1)));
} elseif ($resourceType == SCREEN_RESOURCE_CLOCK) {
    $caption = get_request('caption', '');
    if (zbx_empty($caption) && TIME_TYPE_HOST == $style && $resourceId > 0) {
        $items = API::Item()->get(array('itemids' => $resourceId, 'selectHosts' => array('name'), 'output' => array('itemid', 'key_', 'name')));
        if ($items) {
            $item = reset($items);
            $host = reset($item['hosts']);
            $caption = $host['name'] . NAME_DELIMITER . itemName($item);
        }
    }
    $screenFormList->addVar('resourceid', $resourceId);
    $styleComboBox = new CComboBox('style', $style, 'javascript: submit();');
    $styleComboBox->addItem(TIME_TYPE_LOCAL, _('Local time'));
    $styleComboBox->addItem(TIME_TYPE_SERVER, _('Server time'));
    $styleComboBox->addItem(TIME_TYPE_HOST, _('Host time'));
    $screenFormList->addRow(_('Time type'), $styleComboBox);
    if (TIME_TYPE_HOST == $style) {
        if ($this->data['screen']['templateid']) {
            $selectButton = new CButton('select', _('Select'), "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption&srctbl=items&srcfld1=itemid&srcfld2=name&templated_hosts=1' . '&only_hostid=' . $this->data['screen']['templateid'] . "', 800, 450);", 'formlist');
        } else {
            $selectButton = new CButton('select', _('Select'), "javascript: return PopUp('popup.php?writeonly=1&dstfrm=" . $screenForm->getName() . '&dstfld1=resourceid' . "&dstfld2=caption&srctbl=items&srcfld1=itemid&srcfld2=name&real_hosts=1', 800, 450);", 'formlist');
        }
        $screenFormList->addRow(_('Parameter'), array(new CTextBox('caption', $caption, ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), $selectButton));
예제 #21
0
 public function addItem($itemid, $axis = GRAPH_YAXIS_SIDE_DEFAULT, $calc_fnc = CALC_FNC_AVG, $color = null, $drawtype = null, $type = null)
 {
     if ($this->type == GRAPH_TYPE_STACKED) {
         $drawtype = GRAPH_ITEM_DRAWTYPE_FILLED_REGION;
     }
     $item = get_item_by_itemid($itemid);
     $this->items[$this->num] = $item;
     $this->items[$this->num]['name'] = itemName($item);
     $this->items[$this->num]['delay'] = getItemDelay($item['delay'], $item['delay_flex']);
     if (strpos($item['units'], ',') !== false) {
         list($this->items[$this->num]['units'], $this->items[$this->num]['unitsLong']) = explode(',', $item['units']);
     } else {
         $this->items[$this->num]['unitsLong'] = '';
     }
     $host = get_host_by_hostid($item['hostid']);
     $this->items[$this->num]['hostname'] = $host['name'];
     $this->items[$this->num]['color'] = is_null($color) ? 'Dark Green' : $color;
     $this->items[$this->num]['drawtype'] = is_null($drawtype) ? GRAPH_ITEM_DRAWTYPE_LINE : $drawtype;
     $this->items[$this->num]['axisside'] = is_null($axis) ? GRAPH_YAXIS_SIDE_DEFAULT : $axis;
     $this->items[$this->num]['calc_fnc'] = is_null($calc_fnc) ? CALC_FNC_AVG : $calc_fnc;
     $this->items[$this->num]['calc_type'] = is_null($type) ? GRAPH_ITEM_SIMPLE : $type;
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_LEFT) {
         $this->yaxisleft = 1;
     }
     if ($this->items[$this->num]['axisside'] == GRAPH_YAXIS_SIDE_RIGHT) {
         $this->yaxisright = 1;
     }
     $this->num++;
 }
예제 #22
0
/**
 * Retrieve overview table object for items.
 *
 * @param array  $hostIds
 * @param string $application name of application to filter
 * @param int    $viewMode
 *
 * @return CTableInfo
 */
function getItemsDataOverview($hostIds, $application, $viewMode)
{
    $sqlFrom = '';
    $sqlWhere = '';
    if ($application !== '') {
        $sqlFrom = 'applications a,items_applications ia,';
        $sqlWhere = ' AND i.itemid=ia.itemid AND a.applicationid=ia.applicationid AND a.name=' . zbx_dbstr($application);
    }
    $dbItems = DBfetchArray(DBselect('SELECT DISTINCT h.hostid,h.name AS hostname,i.itemid,i.key_,i.value_type,i.units,' . 'i.name,t.priority,i.valuemapid,t.value AS tr_value,t.triggerid' . ' FROM hosts h,' . $sqlFrom . 'items i' . ' LEFT JOIN functions f ON f.itemid=i.itemid' . ' LEFT JOIN triggers t ON t.triggerid=f.triggerid AND t.status=' . TRIGGER_STATUS_ENABLED . ' WHERE ' . dbConditionInt('h.hostid', $hostIds) . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND h.hostid=i.hostid' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND ' . dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . $sqlWhere));
    CArrayHelper::sort($dbItems, array(array('field' => 'name', 'order' => ZBX_SORT_UP), array('field' => 'itemid', 'order' => ZBX_SORT_UP)));
    // fetch latest values
    $history = Manager::History()->getLast(zbx_toHash($dbItems, 'itemid'));
    // fetch data for the host JS menu
    $hosts = API::Host()->get(array('output' => array('name', 'hostid', 'status'), 'monitored_hosts' => true, 'hostids' => $hostIds, 'with_monitored_items' => true, 'preservekeys' => true, 'selectScreens' => $viewMode == STYLE_LEFT ? API_OUTPUT_COUNT : null));
    $items = array();
    foreach ($dbItems as $row) {
        $descr = itemName($row);
        $row['hostname'] = get_node_name_by_elid($row['hostid'], null, NAME_DELIMITER) . $row['hostname'];
        $hostNames[$row['hostid']] = $row['hostname'];
        // a little tricky check for attempt to overwrite active trigger (value=1) with
        // inactive or active trigger with lower priority.
        if (!isset($items[$descr][$row['hostname']]) || ($items[$descr][$row['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE && $row['tr_value'] == TRIGGER_VALUE_TRUE || ($items[$descr][$row['hostname']]['tr_value'] == TRIGGER_VALUE_FALSE || $row['tr_value'] == TRIGGER_VALUE_TRUE) && $row['priority'] > $items[$descr][$row['hostname']]['severity'])) {
            $items[$descr][$row['hostname']] = array('itemid' => $row['itemid'], 'value_type' => $row['value_type'], 'value' => isset($history[$row['itemid']]) ? $history[$row['itemid']][0]['value'] : null, 'units' => $row['units'], 'name' => $row['name'], 'valuemapid' => $row['valuemapid'], 'severity' => $row['priority'], 'tr_value' => $row['tr_value'], 'triggerid' => $row['triggerid']);
        }
    }
    $table = new CTableInfo(_('No items found.'));
    if (empty($hostNames)) {
        return $table;
    }
    $table->makeVerticalRotation();
    order_result($hostNames);
    if ($viewMode == STYLE_TOP) {
        $header = array(new CCol(_('Items'), 'center'));
        foreach ($hostNames as $hostName) {
            $header[] = new CCol($hostName, 'vertical_rotation');
        }
        $table->setHeader($header, 'vertical_header');
        foreach ($items as $descr => $ithosts) {
            $tableRow = array(nbsp($descr));
            foreach ($hostNames as $hostName) {
                $tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName);
            }
            $table->addRow($tableRow);
        }
    } else {
        $scripts = API::Script()->getScriptsByHosts(zbx_objectValues($hosts, 'hostid'));
        $header = array(new CCol(_('Hosts'), 'center'));
        foreach ($items as $descr => $ithosts) {
            $header[] = new CCol($descr, 'vertical_rotation');
        }
        $table->setHeader($header, 'vertical_header');
        foreach ($hostNames as $hostId => $hostName) {
            $host = $hosts[$hostId];
            $name = new CSpan($host['name'], 'link_menu');
            $name->setMenuPopup(getMenuPopupHost($host, $scripts[$hostId]));
            $tableRow = array(new CCol($name));
            foreach ($items as $ithosts) {
                $tableRow = getItemDataOverviewCells($tableRow, $ithosts, $hostName);
            }
            $table->addRow($tableRow);
        }
    }
    return $table;
}
$itemForm->addVar('parent_discoveryid', $this->data['parent_discoveryid']);
// create table
$itemTable = new CTableInfo(_('No item prototypes found.'));
$sortLink = new CUrl();
$sortLink->setArgument('parent_discoveryid', $this->data['parent_discoveryid']);
$sortLink = $sortLink->getUrl();
$itemTable->setHeader(array(new CCheckBox('all_items', null, "checkAll('" . $itemForm->getName() . "', 'all_items', 'group_itemid');"), make_sorting_header(_('Name'), 'name', $sortLink), make_sorting_header(_('Key'), 'key_', $sortLink), make_sorting_header(_('Interval'), 'delay', $sortLink), make_sorting_header(_('History'), 'history', $sortLink), make_sorting_header(_('Trends'), 'trends', $sortLink), make_sorting_header(_('Type'), 'type', $sortLink), _('Applications'), make_sorting_header(_('Status'), 'status', $sortLink)));
foreach ($this->data['items'] as $item) {
    $description = array();
    if (!empty($item['templateid'])) {
        $template_host = get_realhost_by_itemid($item['templateid']);
        $templateDiscoveryRuleId = get_realrule_by_itemid_and_hostid($this->data['parent_discoveryid'], $template_host['hostid']);
        $description[] = new CLink($template_host['name'], '?parent_discoveryid=' . $templateDiscoveryRuleId, 'unknown');
        $description[] = NAME_DELIMITER;
    }
    $description[] = new CLink(itemName($item), '?form=update&itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid']);
    $status = new CLink(itemIndicator($item['status']), '?group_itemid=' . $item['itemid'] . '&parent_discoveryid=' . $this->data['parent_discoveryid'] . '&go=' . ($item['status'] ? 'activate' : 'disable'), itemIndicatorStyle($item['status']));
    if (!empty($item['applications'])) {
        order_result($item['applications'], 'name');
        $applications = zbx_objectValues($item['applications'], 'name');
        $applications = implode(', ', $applications);
        if (empty($applications)) {
            $applications = '-';
        }
    } else {
        $applications = '-';
    }
    $itemTable->addRow(array(new CCheckBox('group_itemid[' . $item['itemid'] . ']', null, null, $item['itemid']), $description, $item['key_'], $item['delay'], $item['history'], in_array($item['value_type'], array(ITEM_VALUE_TYPE_STR, ITEM_VALUE_TYPE_LOG, ITEM_VALUE_TYPE_TEXT)) ? '' : $item['trends'], item_type2str($item['type']), new CCol($applications, 'wraptext'), $status));
}
// create go buttons
$goComboBox = new CComboBox('go');
예제 #24
0
 if (isset($this->data['iv_string'][$this->data['item']['value_type']])) {
     $filterForm = new CFormTable(null, null, 'get');
     $filterForm->setAttribute('name', 'zbx_filter');
     $filterForm->setAttribute('id', 'zbx_filter');
     $filterForm->addVar('action', $this->data['action']);
     $filterForm->addVar('itemid', zbx_toHash($_REQUEST['itemid']));
     $itemListbox = new CListBox('cmbitemlist[]');
     $itemsData = array();
     foreach ($this->data['items'] as $itemid => $item) {
         if (!isset($this->data['iv_string'][$item['value_type']])) {
             unset($this->data['items'][$itemid]);
             continue;
         }
         $host = reset($item['hosts']);
         $itemsData[$itemid]['id'] = $itemid;
         $itemsData[$itemid]['name'] = $host['name'] . NAME_DELIMITER . itemName($item);
     }
     order_result($itemsData, 'name');
     foreach ($itemsData as $item) {
         $itemListbox->addItem($item['id'], $item['name']);
     }
     $addItemButton = new CButton('add_log', _('Add'), "return PopUp('popup.php?multiselect=1&real_hosts=1" . '&reference=itemid&srctbl=items&value_types[]=' . $this->data['item']['value_type'] . "&srcfld1=itemid');");
     $deleteItemButton = null;
     if (count($this->data['items']) > 1) {
         $deleteItemButton = new CSubmit('remove_log', _('Remove selected'), "javascript: removeSelectedItems('cmbitemlist_', 'itemid')");
     }
     $filterForm->addRow(_('Items list'), array($itemListbox, BR(), $addItemButton, $deleteItemButton));
     $filterForm->addRow(_('Select rows with value like'), new CTextBox('filter', get_request('filter', ''), ZBX_TEXTBOX_FILTER_SIZE));
     $filterTask = get_request('filter_task', 0);
     $taskComboBox = new CComboBox('filter_task', $filterTask, 'submit()');
     $taskComboBox->addItem(FILTER_TASK_SHOW, _('Show selected'));
예제 #25
0
$db_hosts = array();
$db_hostids = array();
// select hosts
$sql = 'SELECT DISTINCT h.name,h.hostid ' . ' FROM hosts h' . $sql_from . ', items i ' . ' LEFT JOIN items_applications ia ON ia.itemid=i.itemid' . ' WHERE ia.itemid is NULL ' . $sql_where . ' AND h.hostid=i.hostid ' . ' AND ' . dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . ' AND ' . dbConditionInt('h.hostid', $available_hosts) . ' ORDER BY h.name';
$db_host_res = DBselect($sql);
while ($db_host = DBfetch($db_host_res)) {
    $db_host['item_cnt'] = 0;
    $db_hosts[$db_host['hostid']] = $db_host;
    $db_hostids[$db_host['hostid']] = $db_host['hostid'];
}
$tab_rows = array();
// select items
$sql = 'SELECT DISTINCT h.host as hostname,h.hostid,i.* ' . ' FROM hosts h' . $sql_from . ', items i ' . ' LEFT JOIN items_applications ia ON ia.itemid=i.itemid' . ' WHERE ia.itemid is NULL ' . $sql_where . ' AND h.hostid=i.hostid ' . ($_REQUEST['show_without_data'] ? '' : ' AND i.lastvalue IS NOT NULL') . ' AND (i.status=' . ITEM_STATUS_ACTIVE . ' OR i.status=' . ITEM_STATUS_NOTSUPPORTED . ')' . ' AND ' . dbConditionInt('i.flags', array(ZBX_FLAG_DISCOVERY_NORMAL, ZBX_FLAG_DISCOVERY_CREATED)) . ' AND ' . dbConditionInt('h.hostid', $db_hostids) . ' ORDER BY i.name,i.itemid';
$db_items = DBselect($sql);
while ($db_item = DBfetch($db_items)) {
    $description = itemName($db_item);
    if (!empty($_REQUEST['select']) && !zbx_stristr($description, $_REQUEST['select'])) {
        continue;
    }
    if (strpos($db_item['units'], ',') !== false) {
        list($db_item['units'], $db_item['unitsLong']) = explode(',', $db_item['units']);
    } else {
        $db_item['unitsLong'] = '';
    }
    $db_host =& $db_hosts[$db_item['hostid']];
    if (!isset($tab_rows[$db_host['hostid']])) {
        $tab_rows[$db_host['hostid']] = array();
    }
    $app_rows =& $tab_rows[$db_host['hostid']];
    $db_host['item_cnt']++;
    if (isset($showAll) && !empty($apps) && !isset($apps[0])) {
 $discoveryRuleList = array();
 foreach ($hostDiscoveryRules as $discoveryRule) {
     $discoveryRuleList[$discoveryRule['itemid']] = itemName($discoveryRule);
 }
 order_result($discoveryRuleList);
 $hostDiscoveryRuleids = array_keys($discoveryRuleList);
 $listBox = new CListBox('discoveryRules', null, 8);
 $listBox->setAttribute('disabled', 'disabled');
 $listBox->addItems($discoveryRuleList);
 $templateList->addRow(_('Discovery rules'), $listBox);
 // Item prototypes
 $hostItemPrototypes = API::ItemPrototype()->get(array('hostids' => $templateid, 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND));
 if (!empty($hostItemPrototypes)) {
     $prototypeList = array();
     foreach ($hostItemPrototypes as $itemPrototype) {
         $prototypeList[$itemPrototype['itemid']] = itemName($itemPrototype);
     }
     order_result($prototypeList);
     $listBox = new CListBox('itemsPrototypes', null, 8);
     $listBox->setAttribute('disabled', 'disabled');
     $listBox->addItems($prototypeList);
     $templateList->addRow(_('Item prototypes'), $listBox);
 }
 // Trigger prototypes
 $hostTriggerPrototypes = API::TriggerPrototype()->get(array('hostids' => $templateid, 'discoveryids' => $hostDiscoveryRuleids, 'inherited' => false, 'output' => API_OUTPUT_EXTEND));
 if (!empty($hostTriggerPrototypes)) {
     $prototypeList = array();
     foreach ($hostTriggerPrototypes as $triggerPrototype) {
         $prototypeList[$triggerPrototype['triggerid']] = $triggerPrototype['description'];
     }
     order_result($prototypeList);
예제 #27
0
/**
 * Creates and returns a trigger status cell for the trigger overview table.
 *
 * @see getTriggersOverview()
 *
 * @param array  $trigger
 * @param string $pageFile		the page where the element is displayed
 * @param string $screenId
 *
 * @return CCol
 */
function getTriggerOverviewCells($trigger, $pageFile, $screenId = null)
{
    $ack = null;
    $css = null;
    $style = null;
    $desc = array();
    $config = select_config();
    // for how long triggers should blink on status change (set by user in administration->general)
    $menuPopup = array();
    $triggerItems = array();
    $acknowledge = array();
    if ($trigger) {
        $style = 'cursor: pointer; ';
        // problem trigger
        if ($trigger['value'] == TRIGGER_VALUE_TRUE) {
            $css = getSeverityStyle($trigger['priority']);
            $ack = null;
            if ($config['event_ack_enable'] == 1) {
                if ($event = get_last_event_by_triggerid($trigger['triggerid'])) {
                    if ($screenId) {
                        $acknowledge = array('eventid' => $event['eventid'], 'screenid' => $screenId, 'backurl' => $pageFile);
                    } else {
                        $acknowledge = array('eventid' => $event['eventid'], 'backurl' => 'overview.php');
                    }
                    if ($event['acknowledged'] == 1) {
                        $ack = new CImg('images/general/tick.png', 'ack');
                    }
                }
            }
        } else {
            $css = 'normal';
        }
        $dbItems = DBselect('SELECT DISTINCT i.itemid,i.name,i.key_,i.value_type' . ' FROM items i,functions f' . ' WHERE f.itemid=i.itemid' . ' AND f.triggerid=' . zbx_dbstr($trigger['triggerid']));
        while ($item = DBfetch($dbItems)) {
            $triggerItems[] = array('name' => itemName($item), 'params' => array('action' => in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showlatest', 'itemid' => $item['itemid'], 'period' => 3600));
        }
        // dependency: triggers on which depends this
        $triggerId = empty($trigger['triggerid']) ? 0 : $trigger['triggerid'];
        // trigger dependency DOWN
        $dependencyTable = new CTableInfo();
        $dependencyTable->setAttribute('style', 'width: 200px;');
        $dependencyTable->addRow(bold(_('Depends on') . NAME_DELIMITER));
        $isDependencyFound = false;
        $dbDependencies = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_down=' . zbx_dbstr($triggerId));
        while ($dbDependency = DBfetch($dbDependencies)) {
            $dependencyTable->addRow(SPACE . '-' . SPACE . CMacrosResolverHelper::resolveTriggerNameById($dbDependency['triggerid_up']));
            $isDependencyFound = true;
        }
        if ($isDependencyFound) {
            $icon = new Cimg('images/general/arrow_down2.png', 'DEP_DOWN');
            $icon->setAttribute('style', 'vertical-align: middle; border: 0px;');
            $icon->setHint($dependencyTable, '', '', false);
            $desc[] = $icon;
        }
        // trigger dependency UP
        $dependencyTable = new CTableInfo();
        $dependencyTable->setAttribute('style', 'width: 200px;');
        $dependencyTable->addRow(bold(_('Dependent') . NAME_DELIMITER));
        $isDependencyFound = false;
        $dbDependencies = DBselect('SELECT td.* FROM trigger_depends td WHERE td.triggerid_up=' . zbx_dbstr($triggerId));
        while ($dbDependency = DBfetch($dbDependencies)) {
            $dependencyTable->addRow(SPACE . '-' . SPACE . CMacrosResolverHelper::resolveTriggerNameById($dbDependency['triggerid_down']));
            $isDependencyFound = true;
        }
        if ($isDependencyFound) {
            $icon = new Cimg('images/general/arrow_up2.png', 'DEP_UP');
            $icon->setAttribute('style', 'vertical-align: middle; border: none;');
            $icon->setHint($dependencyTable, '', '', false);
            $desc[] = $icon;
        }
    }
    $column = is_array($desc) && count($desc) > 0 || $ack ? new CCol(array($desc, $ack), $css . ' hosts') : new CCol(SPACE, $css . ' hosts');
    $column->setAttribute('style', $style);
    if ($trigger && $config['blink_period'] > 0 && time() - $trigger['lastchange'] < $config['blink_period']) {
        $column->addClass('blink');
        $column->setAttribute('data-toggle-class', $css);
    }
    if ($trigger) {
        $column->setMenuPopup(getMenuPopupTrigger($trigger, $triggerItems, $acknowledge));
    }
    return $column;
}
예제 #28
0
/**
 * Create report bar for for "Compare values for multiple periods"
 *
 * @return object $reportForm
 */
function valueComparisonFormForMultiplePeriods()
{
    $config = get_request('config', 1);
    $title = get_request('title', _('Report 3'));
    $xlabel = get_request('xlabel', '');
    $ylabel = get_request('ylabel', '');
    $scaletype = get_request('scaletype', TIMEPERIOD_TYPE_WEEKLY);
    $avgperiod = get_request('avgperiod', TIMEPERIOD_TYPE_DAILY);
    $report_timesince = get_request('report_timesince', date(TIMESTAMP_FORMAT_ZERO_TIME, time() - SEC_PER_DAY));
    $report_timetill = get_request('report_timetill', date(TIMESTAMP_FORMAT_ZERO_TIME));
    $itemId = get_request('itemid', 0);
    $hostids = get_request('hostids', array());
    $hostids = zbx_toHash($hostids);
    $showlegend = get_request('showlegend', 0);
    $palette = get_request('palette', 0);
    $palettetype = get_request('palettetype', 0);
    $reportForm = new CFormTable(null, null, 'get');
    $reportForm->setAttribute('name', 'zbx_report');
    $reportForm->setAttribute('id', 'zbx_report');
    if (isset($_REQUEST['report_show']) && $itemId) {
        $reportForm->addVar('report_show', 'show');
    }
    $reportForm->addVar('config', $config);
    $reportForm->addVar('report_timesince', date(TIMESTAMP_FORMAT, $report_timesince));
    $reportForm->addVar('report_timetill', date(TIMESTAMP_FORMAT, $report_timetill));
    $reportForm->addRow(_('Title'), new CTextBox('title', $title, 40));
    $reportForm->addRow(_('X label'), new CTextBox('xlabel', $xlabel, 40));
    $reportForm->addRow(_('Y label'), new CTextBox('ylabel', $ylabel, 40));
    $reportForm->addRow(_('Legend'), new CCheckBox('showlegend', $showlegend, null, 1));
    $reportForm->addVar('sortorder', 0);
    $groupids = get_request('groupids', array());
    $group_tb = new CTweenBox($reportForm, 'groupids', $groupids, 10);
    $options = array('real_hosts' => true, 'output' => 'extend');
    $db_groups = API::HostGroup()->get($options);
    order_result($db_groups, 'name');
    foreach ($db_groups as $gnum => $group) {
        $groupids[$group['groupid']] = $group['groupid'];
        $group_tb->addItem($group['groupid'], $group['name']);
    }
    $reportForm->addRow(_('Groups'), $group_tb->Get(_('Selected groups'), _('Other groups')));
    $groupid = get_request('groupid', 0);
    $cmbGroups = new CComboBox('groupid', $groupid, 'submit()');
    $cmbGroups->addItem(0, _('All'));
    foreach ($db_groups as $gnum => $group) {
        $cmbGroups->addItem($group['groupid'], $group['name']);
    }
    $td_groups = new CCol(array(_('Group'), SPACE, $cmbGroups));
    $td_groups->setAttribute('style', 'text-align: right;');
    $host_tb = new CTweenBox($reportForm, 'hostids', $hostids, 10);
    $options = array('real_hosts' => true, 'output' => array('hostid', 'name'));
    if ($groupid > 0) {
        $options['groupids'] = $groupid;
    }
    $db_hosts = API::Host()->get($options);
    $db_hosts = zbx_toHash($db_hosts, 'hostid');
    order_result($db_hosts, 'name');
    foreach ($db_hosts as $hnum => $host) {
        $host_tb->addItem($host['hostid'], $host['name']);
    }
    $options = array('real_hosts' => true, 'output' => array('hostid', 'name'), 'hostids' => $hostids);
    $db_hosts2 = API::Host()->get($options);
    order_result($db_hosts2, 'name');
    foreach ($db_hosts2 as $hnum => $host) {
        if (!isset($db_hosts[$host['hostid']])) {
            $host_tb->addItem($host['hostid'], $host['name']);
        }
    }
    $reportForm->addRow(_('Hosts'), $host_tb->Get(_('Selected hosts'), array(_('Other hosts | Group') . SPACE, $cmbGroups)));
    $reporttimetab = new CTable(null, 'calendar');
    $timeSinceRow = createDateSelector('report_timesince', $report_timesince, 'report_timetill');
    array_unshift($timeSinceRow, _('From'));
    $reporttimetab->addRow($timeSinceRow);
    $timeTillRow = createDateSelector('report_timetill', $report_timetill, 'report_timesince');
    array_unshift($timeTillRow, _('Till'));
    $reporttimetab->addRow($timeTillRow);
    $reportForm->addRow(_('Period'), $reporttimetab);
    $scale = new CComboBox('scaletype', $scaletype);
    $scale->addItem(TIMEPERIOD_TYPE_HOURLY, _('Hourly'));
    $scale->addItem(TIMEPERIOD_TYPE_DAILY, _('Daily'));
    $scale->addItem(TIMEPERIOD_TYPE_WEEKLY, _('Weekly'));
    $scale->addItem(TIMEPERIOD_TYPE_MONTHLY, _('Monthly'));
    $scale->addItem(TIMEPERIOD_TYPE_YEARLY, _('Yearly'));
    $reportForm->addRow(_('Scale'), $scale);
    $avgcmb = new CComboBox('avgperiod', $avgperiod);
    $avgcmb->addItem(TIMEPERIOD_TYPE_HOURLY, _('Hourly'));
    $avgcmb->addItem(TIMEPERIOD_TYPE_DAILY, _('Daily'));
    $avgcmb->addItem(TIMEPERIOD_TYPE_WEEKLY, _('Weekly'));
    $avgcmb->addItem(TIMEPERIOD_TYPE_MONTHLY, _('Monthly'));
    $avgcmb->addItem(TIMEPERIOD_TYPE_YEARLY, _('Yearly'));
    $reportForm->addRow(_('Average by'), $avgcmb);
    $itemName = '';
    if ($itemId) {
        $itemName = get_item_by_itemid($itemId);
        $itemName = itemName($itemName);
    }
    $itemidVar = new CVar('itemid', $itemId, 'itemid');
    $reportForm->addItem($itemidVar);
    $txtCondVal = new CTextBox('item_name', $itemName, 50, 'yes');
    $txtCondVal->setAttribute('id', 'item_name');
    $btnSelect = new CButton('btn1', _('Select'), 'return PopUp("popup.php?dstfrm=' . $reportForm->GetName() . '&dstfld1=itemid' . '&dstfld2=item_name' . '&srctbl=items' . '&srcfld1=itemid' . '&srcfld2=name' . '&monitored_hosts=1");', 'T');
    $reportForm->addRow(_('Item'), array($txtCondVal, $btnSelect));
    $paletteCmb = new CComboBox('palette', $palette);
    $paletteCmb->addItem(0, _s('Palette #%1$s', 1));
    $paletteCmb->addItem(1, _s('Palette #%1$s', 2));
    $paletteCmb->addItem(2, _s('Palette #%1$s', 3));
    $paletteCmb->addItem(3, _s('Palette #%1$s', 4));
    $paletteTypeCmb = new CComboBox('palettetype', $palettetype);
    $paletteTypeCmb->addItem(0, _('Middle'));
    $paletteTypeCmb->addItem(1, _('Darken'));
    $paletteTypeCmb->addItem(2, _('Brighten'));
    $reportForm->addRow(_('Palette'), array($paletteCmb, $paletteTypeCmb));
    $reportForm->addItemToBottomRow(new CSubmit('report_show', _('Show')));
    $reset = new CButton('reset', _('Reset'));
    $reset->setType('reset');
    $reportForm->addItemToBottomRow($reset);
    return $reportForm;
}
예제 #29
0
function make_graph_submenu()
{
    $graphids = array();
    $itemids = array();
    $favGraphs = array();
    $fav_graphs = CFavorite::get('web.favorite.graphids');
    if (!$fav_graphs) {
        return $favGraphs;
    }
    foreach ($fav_graphs as $favorite) {
        if ('itemid' == $favorite['source']) {
            $itemids[$favorite['value']] = $favorite['value'];
        } else {
            $graphids[$favorite['value']] = $favorite['value'];
        }
    }
    if ($graphids) {
        $options = array('graphids' => $graphids, 'selectHosts' => array('hostid', 'host'), 'output' => array('graphid', 'name'), 'expandName' => true);
        $graphs = API::Graph()->get($options);
        $graphs = zbx_toHash($graphs, 'graphid');
    }
    if ($itemids) {
        $options = array('itemids' => $itemids, 'selectHosts' => array('hostid', 'host'), 'output' => array('itemid', 'name', 'key_'), 'webitems' => 1);
        $items = API::Item()->get($options);
        $items = zbx_toHash($items, 'itemid');
    }
    foreach ($fav_graphs as $favorite) {
        $source = $favorite['source'];
        $sourceid = $favorite['value'];
        if ('itemid' == $source) {
            if (!isset($items[$sourceid])) {
                continue;
            }
            $item_added = true;
            $item = $items[$sourceid];
            $host = reset($item['hosts']);
            $item['name'] = itemName($item);
            $favGraphs[] = array('name' => $host['host'] . NAME_DELIMITER . $item['name'], 'favobj' => 'itemid', 'favid' => $sourceid, 'favaction' => 'remove');
        } else {
            if (!isset($graphs[$sourceid])) {
                continue;
            }
            $graph_added = true;
            $graph = $graphs[$sourceid];
            $ghost = reset($graph['hosts']);
            $favGraphs[] = array('name' => $ghost['host'] . NAME_DELIMITER . $graph['name'], 'favobj' => 'graphid', 'favid' => $sourceid, 'favaction' => 'remove');
        }
    }
    if (isset($graph_added)) {
        $favGraphs[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Graphs'), 'favobj' => 'graphid', 'favid' => 0, 'favaction' => 'remove');
    }
    if (isset($item_added)) {
        $favGraphs[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Simple graphs'), 'favobj' => 'itemid', 'favid' => 0, 'favaction' => 'remove');
    }
    return $favGraphs;
}
예제 #30
0
    }
}
$dep_res = DBselect('SELECT triggerid_down,triggerid_up' . ' FROM trigger_depends' . ' WHERE ' . dbConditionInt('triggerid_up', $triggerids));
$triggerids_down = array();
while ($row = DBfetch($dep_res)) {
    $triggerids_down[$row['triggerid_up']][] = intval($row['triggerid_down']);
}
foreach ($triggers as $tnum => $trigger) {
    $items = array();
    $used_hosts = array();
    foreach ($trigger['hosts'] as $th) {
        $used_hosts[$th['hostid']] = $th['name'];
    }
    $used_host_count = count($used_hosts);
    foreach ($trigger['items'] as $inum => $item) {
        $item_name = itemName($item);
        //if we have items from different hosts, we must prefix a host name
        if ($used_host_count > 1) {
            $item_name = $used_hosts[$item['hostid']] . ':' . $item_name;
        }
        $items[$inum]['itemid'] = $item['itemid'];
        $items[$inum]['value_type'] = $item['value_type'];
        //ZBX-3059: So it would be possible to show different caption for history for chars and numbers (KB)
        $items[$inum]['action'] = str_in_array($item['value_type'], array(ITEM_VALUE_TYPE_FLOAT, ITEM_VALUE_TYPE_UINT64)) ? 'showgraph' : 'showvalues';
        $items[$inum]['name'] = htmlspecialchars($item_name);
    }
    $trigger['items'] = $items;
    // trigger js menu
    $menu_trigger_conf = 'null';
    if ($admin_links && $trigger['flags'] == ZBX_FLAG_DISCOVERY_NORMAL) {
        $configurationUrl = 'triggers.php?form=update&triggerid=' . $trigger['triggerid'] . '&hostid=' . $pageFilter->hostid . '&switch_node=' . id2nodeid($trigger['triggerid']);