Exemplo n.º 1
0
function update_graph_with_items($graphid, $name, $width, $height, $ymin_type, $ymax_type, $yaxismin, $yaxismax, $ymin_itemid, $ymax_itemid, $showworkperiod, $showtriggers, $graphtype, $legend, $graph3d, $percent_left, $percent_right, $gitems = array(), $templateid = 0)
{
    $result = false;
    if (!is_array($gitems) || count($gitems) < 1) {
        error('Missing items for graph "' . $name . '"');
        return $result;
    }
    /* check items for template graph */
    $tmp_hosts = get_hosts_by_graphid($graphid);
    $host = DBfetch($tmp_hosts);
    if ($host["status"] == HOST_STATUS_TEMPLATE) {
        unset($new_hostid);
        $itemid = array(0);
        foreach ($gitems as $gitem) {
            $itemid[] = $gitem['itemid'];
        }
        $db_item_hosts = DBselect('SELECT DISTINCT hostid from items where itemid in (' . implode(',', $itemid) . ')');
        while ($db_item = DBfetch($db_item_hosts)) {
            if (isset($new_hostid)) {
                error('Can not use multiple host items for template graph "' . $name . '"');
                return $result;
            }
            $new_hostid = $db_item['hostid'];
        }
        if (bccomp($host['hostid'], $new_hostid) != 0) {
            error('You must use items only from host "' . $host['host'] . '" for template graph "' . $name . '"');
            return $result;
        }
    }
    /* firstly update child graphs */
    $chd_graphs = get_graphs_by_templateid($graphid);
    while ($chd_graph = DBfetch($chd_graphs)) {
        $tmp_hosts = get_hosts_by_graphid($chd_graph['graphid']);
        $chd_host = DBfetch($tmp_hosts);
        if (!($new_gitems = get_same_graphitems_for_host($gitems, $chd_host['hostid']))) {
            /* skip host with missing items */
            error('Can not update graph "' . $name . '" for host "' . $chd_host['host'] . '"');
            return $result;
        }
        if (!($result = update_graph_with_items($chd_graph['graphid'], $name, $width, $height, $ymin_type, $ymax_type, $yaxismin, $yaxismax, $ymin_itemid, $ymax_itemid, $showworkperiod, $showtriggers, $graphtype, $legend, $graph3d, $percent_left, $percent_right, $new_gitems, $graphid))) {
            return $result;
        }
    }
    DBexecute('DELETE FROM graphs_items WHERE graphid=' . $graphid);
    foreach ($gitems as $gitem) {
        if (!($result = add_item_to_graph($graphid, $gitem['itemid'], $gitem['color'], $gitem['drawtype'], $gitem['sortorder'], $gitem['yaxisside'], $gitem['calc_fnc'], $gitem['type'], $gitem['periods_cnt']))) {
            return $result;
        }
    }
    if ($result = update_graph($graphid, $name, $width, $height, $ymin_type, $ymax_type, $yaxismin, $yaxismax, $ymin_itemid, $ymax_itemid, $showworkperiod, $showtriggers, $graphtype, $legend, $graph3d, $percent_left, $percent_right, $templateid)) {
        $host_list = array();
        $db_hosts = get_hosts_by_graphid($graphid);
        while ($db_host = DBfetch($db_hosts)) {
            $host_list[] = '"' . $db_host["host"] . '"';
        }
        info('Graph "' . $name . '" updated for hosts ' . implode(',', $host_list));
    }
    return $result;
}
Exemplo n.º 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;
 }
Exemplo n.º 3
0
function update_graph_with_items($graphid, $name, $width, $height, $ymin_type, $ymax_type, $yaxismin, $yaxismax, $ymin_itemid, $ymax_itemid, $showworkperiod, $showtriggers, $graphtype, $legend, $graph3d, $percent_left, $percent_right, $gitems = array(), $templateid = 0)
{
    $result = false;
    if (!is_array($gitems) || count($gitems) < 1) {
        error(S_MISSING_ITEMS_FOR_GRAPH . SPACE . '"' . $name . '"');
        return $result;
    }
    // check items for template graph
    $tmp_hosts = get_hosts_by_graphid($graphid);
    $host = DBfetch($tmp_hosts);
    if ($host["status"] == HOST_STATUS_TEMPLATE) {
        unset($new_hostid);
        $itemid = array(0);
        foreach ($gitems as $gitem) {
            $itemid[] = $gitem['itemid'];
        }
        $db_item_hosts = DBselect('SELECT DISTINCT hostid from items where itemid in (' . implode(',', $itemid) . ')');
        while ($db_item = DBfetch($db_item_hosts)) {
            if (isset($new_hostid)) {
                error(S_CANNOT_USE_MULTIPLE_HOST_ITEMS_TEMPLATE_GRAPH . SPACE . '"' . $name . '"');
                return $result;
            }
            $new_hostid = $db_item['hostid'];
        }
        if (bccomp($host['hostid'], $new_hostid) != 0) {
            error(S_MUST_USE_ITEMS_ONLY_FROM_HOST . SPACE . '"' . $host['host'] . '"' . SPACE . S_FOR_TEMPLATE_GRAPH_SMALL . SPACE . '"' . $name . '"');
            return $result;
        }
    }
    // firstly update child graphs
    $chd_graphs = get_graphs_by_templateid($graphid);
    while ($chd_graph = DBfetch($chd_graphs)) {
        $tmp_hosts = get_hosts_by_graphid($chd_graph['graphid']);
        $chd_host = DBfetch($tmp_hosts);
        if (!($new_gitems = get_same_graphitems_for_host($gitems, $chd_host['hostid']))) {
            /* skip host with missing items */
            error(S_CANNOT_UPDATE_GRAPH . SPACE . '"' . $name . '"' . SPACE . S_FOR_HOST_SMALL . SPACE . '"' . $chd_host['host'] . '"');
            return $result;
        }
        if (!($result = update_graph_with_items($chd_graph['graphid'], $name, $width, $height, $ymin_type, $ymax_type, $yaxismin, $yaxismax, $ymin_itemid, $ymax_itemid, $showworkperiod, $showtriggers, $graphtype, $legend, $graph3d, $percent_left, $percent_right, $new_gitems, $graphid))) {
            return $result;
        }
    }
    DBexecute('DELETE FROM graphs_items WHERE graphid=' . $graphid);
    foreach ($gitems as $gitem) {
        if (!($result = add_item_to_graph($graphid, $gitem['itemid'], $gitem['color'], $gitem['drawtype'], $gitem['sortorder'], $gitem['yaxisside'], $gitem['calc_fnc'], $gitem['type'], $gitem['periods_cnt']))) {
            return $result;
        }
    }
    if ($result = update_graph($graphid, $name, $width, $height, $ymin_type, $ymax_type, $yaxismin, $yaxismax, $ymin_itemid, $ymax_itemid, $showworkperiod, $showtriggers, $graphtype, $legend, $graph3d, $percent_left, $percent_right, $templateid)) {
        $host_list = array();
        $db_hosts = get_hosts_by_graphid($graphid);
        while ($db_host = DBfetch($db_hosts)) {
            $host_list[] = '"' . $db_host["host"] . '"';
        }
        info(S_GRAPH . SPACE . '"' . $name . '"' . SPACE . S_UPDATED_FOR_HOSTS . SPACE . implode(',', $host_list));
    }
    return $result;
}