예제 #1
0
function make_graph_submenu()
{
    $graphids = array();
    $fav_graphs = get_favorites('web.favorite.graphids');
    foreach ($fav_graphs as $key => $favorite) {
        $source = $favorite['source'];
        $sourceid = $favorite['value'];
        if ('itemid' == $source) {
            if (!($item = get_item_by_itemid($sourceid))) {
                continue;
            }
            $item_added = true;
            $host = get_host_by_itemid($sourceid);
            $item["description"] = item_description($item);
            $graphids[] = array('name' => $host['host'] . ':' . $item['description'], 'favobj' => 'itemid', 'favid' => $sourceid, 'action' => 'remove');
        } else {
            if (!($graph = get_graph_by_graphid($sourceid))) {
                continue;
            }
            $graph_added = true;
            $result = get_hosts_by_graphid($sourceid);
            $ghost = DBFetch($result);
            $graphids[] = array('name' => $ghost['host'] . ':' . $graph['name'], 'favobj' => 'graphid', 'favid' => $sourceid, 'action' => 'remove');
        }
    }
    if (isset($graph_added)) {
        $graphids[] = array('name' => S_REMOVE . SPACE . S_ALL_S . SPACE . S_GRAPHS, 'favobj' => 'graphid', 'favid' => 0, 'action' => 'remove');
    }
    if (isset($item_added)) {
        $graphids[] = array('name' => S_REMOVE . SPACE . S_ALL_S . SPACE . S_SIMPLE_GRAPHS, 'favobj' => 'itemid', 'favid' => 0, 'action' => 'remove');
    }
    return $graphids;
}
예제 #2
0
 protected static function addItems_rec($graphid, $items, $tpl_graph = false)
 {
     if ($tpl_graph) {
         $chd_graphs = get_graphs_by_templateid($graphid);
         while ($chd_graph = DBfetch($chd_graphs)) {
             $result = self::addItems_rec($chd_graph['graphid'], $items, $tpl_graph);
             if (!$result) {
                 return false;
             }
         }
         $tmp_hosts = get_hosts_by_graphid($graphid);
         $graph_host = DBfetch($tmp_hosts);
         if (!($items = get_same_graphitems_for_host($items, $graph_host['hostid']))) {
             self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Can not update graph "' . $chd_graph['name'] . '" for host "' . $graph_host['host'] . '"');
             return false;
         }
     }
     foreach ($items as $item) {
         $result = add_item_to_graph($graphid, $item['itemid'], $item['color'], $item['drawtype'], $item['sortorder'], $item['yaxisside'], $item['calc_fnc'], $item['type'], $item['periods_cnt']);
         if (!$result) {
             return false;
         }
     }
     return true;
 }
function get_realhosts_by_graphid($graphid)
{
    $graph = get_graph_by_graphid($graphid);
    if (!empty($graph['templateid'])) {
        return get_realhosts_by_graphid($graph['templateid']);
    }
    return get_hosts_by_graphid($graphid);
}
예제 #4
0
     }
     // templates
     if (!empty($data['templateid'])) {
         $parentGraphid = $data['templateid'];
         do {
             $parentGraph = getGraphByGraphId($parentGraphid);
             // parent graph prototype link
             if (get_request('parent_discoveryid')) {
                 $parentGraphPrototype = API::GraphPrototype()->get(array('graphids' => $parentGraph['graphid'], 'selectTemplates' => API_OUTPUT_EXTEND, 'selectDiscoveryRule' => array('itemid')));
                 if ($parentGraphPrototype) {
                     $parentGraphPrototype = reset($parentGraphPrototype);
                     $parentTemplate = reset($parentGraphPrototype['templates']);
                     $link = new CLink($parentTemplate['name'], 'graphs.php?form=update&graphid=' . $parentGraphPrototype['graphid'] . '&hostid=' . $parentTemplate['templateid'] . '&parent_discoveryid=' . $parentGraphPrototype['discoveryRule']['itemid']);
                 }
             } else {
                 $parentTemplate = get_hosts_by_graphid($parentGraph['graphid']);
                 $parentTemplate = DBfetch($parentTemplate);
                 $link = new CLink($parentTemplate['name'], 'graphs.php?form=update&graphid=' . $parentGraph['graphid'] . '&hostid=' . $parentTemplate['hostid']);
             }
             if (isset($link)) {
                 $data['templates'][] = $link;
                 $data['templates'][] = SPACE . RARR . SPACE;
             }
             $parentGraphid = $parentGraph['templateid'];
         } while ($parentGraphid != 0);
         $data['templates'] = array_reverse($data['templates']);
         array_shift($data['templates']);
     }
     // items
     $data['items'] = API::GraphItem()->get(array('output' => array('gitemid', 'graphid', 'itemid', 'type', 'drawtype', 'yaxisside', 'calc_fnc', 'color', 'sortorder'), 'graphids' => $data['graphid'], 'sortfield' => 'gitemid'));
 } else {
예제 #5
0
function delete_template_graphs($hostid, $templateids = null, $unlink_mode = false)
{
    zbx_value2array($templateids);
    $db_graphs = get_graphs_by_hostid($hostid);
    while ($db_graph = DBfetch($db_graphs)) {
        if ($db_graph['templateid'] == 0) {
            continue;
        }
        if (!is_null($templateids)) {
            $tmp_hhosts = get_hosts_by_graphid($db_graph['templateid']);
            $tmp_host = DBfetch($tmp_hhosts);
            if (!uint_in_array($tmp_host['hostid'], $templateids)) {
                continue;
            }
        }
        if ($unlink_mode) {
            if (DBexecute('UPDATE graphs SET templateid=0 WHERE graphid=' . $db_graph['graphid'])) {
                info('Graph "' . $db_graph['name'] . '" unlinked');
            }
        } else {
            delete_graph($db_graph['graphid']);
        }
    }
}
예제 #6
0
파일: graphs.php 프로젝트: rennhak/zabbix
 $form->addVar('hostid', $_REQUEST['hostid']);
 $table = new CTableInfo(S_NO_GRAPHS_DEFINED);
 $table->setHeader(array($_REQUEST['hostid'] != 0 ? NULL : S_HOSTS, array(new CCheckBox('all_graphs', NULL, "CheckAll('" . $form->GetName() . "','all_graphs');"), make_sorting_link(S_NAME, 'g.name')), make_sorting_link(S_WIDTH, 'g.width'), make_sorting_link(S_HEIGHT, 'g.height'), make_sorting_link(S_GRAPH_TYPE, 'g.graphtype')));
 $sql_from = '';
 $sql_where = '';
 if ($PAGE_HOSTS['selected'] > 0) {
     $sql_where .= ' AND i.hostid=' . $PAGE_HOSTS['selected'];
 }
 $sql = 'SELECT DISTINCT g.* ' . ' FROM graphs g, graphs_items gi,items i ' . $sql_from . ' WHERE ' . DBcondition('g.graphid', $available_graphs) . ' AND gi.graphid=g.graphid ' . ' AND i.itemid=gi.itemid ' . $sql_where . order_by('g.name,g.width,g.height,g.graphtype', 'g.graphid');
 $result = DBselect($sql);
 while ($row = DBfetch($result)) {
     if ($_REQUEST['hostid'] != 0) {
         $host_list = NULL;
     } else {
         $host_list = array();
         $db_hosts = get_hosts_by_graphid($row['graphid']);
         while ($db_host = DBfetch($db_hosts)) {
             array_push($host_list, $db_host['host']);
         }
         $host_list = implode(',', $host_list);
     }
     if ($row['templateid'] == 0) {
         $name = new CLink($row['name'], 'graphs.php?graphid=' . $row['graphid'] . '&form=update', 'action');
     } else {
         $real_hosts = get_realhosts_by_graphid($row['templateid']);
         $real_host = DBfetch($real_hosts);
         if ($real_host) {
             $name = array(new CLink($real_host['host'], 'graphs.php?' . 'hostid=' . $real_host['hostid'], 'action'), ':', $row['name']);
         } else {
             array_push($description, new CSpan('error', 'on'), ':', expand_trigger_description($row['triggerid']));
         }