Esempio n. 1
0
 public function bodyToString()
 {
     global $USER_DETAILS;
     $this->cleanItems();
     $total = 0;
     $accessible_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, get_current_nodeid(true));
     $cond_from = '';
     if (remove_nodes_from_id($this->groupid) > 0) {
         $cond_from = ', hosts_groups hg ';
         $cond_where = 'AND hg.hostid=h.hostid AND hg.groupid=' . $this->groupid;
     } else {
         $cond_where = ' AND ' . DBin_node('h.hostid', $this->nodeid);
     }
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_TRUE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $avail = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_FALSE . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $notav = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $db_host_cnt = DBselect('SELECT COUNT(DISTINCT h.hostid) as cnt ' . ' FROM hosts h' . $cond_from . ' WHERE h.available=' . HOST_AVAILABLE_UNKNOWN . ' AND h.status IN (' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ') ' . ' AND ' . DBcondition('h.hostid', $accessible_hosts) . $cond_where);
     $host_cnt = DBfetch($db_host_cnt);
     $uncn = $host_cnt['cnt'];
     $total += $host_cnt['cnt'];
     $node = get_node_by_nodeid($this->nodeid);
     $header_str = S_HOSTS_INFO . SPACE;
     $header_str .= S_FOR_GROUP_SMALL . SPACE . '"';
     if ($node > 0) {
         $header_str .= '(' . $node['name'] . ')' . SPACE;
     }
     if (remove_nodes_from_id($this->groupid) > 0) {
         $group = get_hostgroup_by_groupid($this->groupid);
         $header_str .= $group['name'] . '"';
     } else {
         $header_str .= S_ALL_S . '"';
     }
     $header = new CCol($header_str, "header");
     if ($this->style == STYLE_HORISONTAL) {
         $header->SetColspan(4);
     }
     $this->addRow($header);
     $avail = new CCol($avail . '  ' . S_AVAILABLE, 'avail');
     $notav = new CCol($notav . '  ' . S_NOT_AVAILABLE, 'notav');
     $uncn = new CCol($uncn . '  ' . S_UNKNOWN, 'uncn');
     $total = new CCol($total . '  ' . S_TOTAL, 'total');
     if ($this->style == STYLE_HORISONTAL) {
         $this->addRow(array($avail, $notav, $uncn, $total));
     } else {
         $this->addRow($avail);
         $this->addRow($notav);
         $this->addRow($uncn);
         $this->addRow($total);
     }
     return parent::bodyToString();
 }
Esempio n. 2
0
 function CZabbixXMLImport()
 {
     global $USER_DETAILS;
     $this->main_node = null;
     $this->sub_node = null;
     $this->data = null;
     $this->host = array('exist' => 0, 'missed' => 0);
     $this->template = array('exist' => 0, 'missed' => 0);
     $this->item = array('exist' => 0, 'missed' => 0);
     $this->trigger = array('exist' => 0, 'missed' => 0);
     $this->graph = array('exist' => 0, 'missed' => 0);
     $this->available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_WRITE);
     $this->available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE);
     $this->available_nodes = get_accessible_nodes_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY);
 }
Esempio n. 3
0
function sysmap_accessible($sysmapid, $perm)
{
    global $USER_DETAILS;
    $result = false;
    $sql = 'SELECT * ' . ' FROM sysmaps_elements ' . ' WHERE sysmapid=' . $sysmapid . ' AND ' . DBin_node('sysmapid', get_current_nodeid(null, $perm));
    if ($db_result = DBselect($sql)) {
        $result = true;
        $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, PERM_RES_IDS_ARRAY, get_current_nodeid(true));
        //SDI($available_hosts);
        while (($se_data = DBfetch($db_result)) && $result) {
            switch ($se_data['elementtype']) {
                case SYSMAP_ELEMENT_TYPE_HOST:
                    if (!isset($available_hosts[$se_data['elementid']])) {
                        $result = false;
                    }
                    break;
                case SYSMAP_ELEMENT_TYPE_MAP:
                    $result = sysmap_accessible($se_data['elementid'], $perm);
                    break;
                case SYSMAP_ELEMENT_TYPE_TRIGGER:
                    $available_triggers = get_accessible_triggers($perm, array(), PERM_RES_IDS_ARRAY);
                    if (!isset($available_triggers[$se_data['elementid']])) {
                        $result = false;
                    }
                    break;
                case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                    $available_groups = get_accessible_groups_by_user($USER_DETAILS, $perm);
                    if (!isset($available_groups[$se_data['elementid']])) {
                        $result = false;
                    }
                    break;
            }
        }
        //SDI($se_data['elementid']);
    } else {
        if (DBselect('SELECT sysmapid FROM sysmaps WHERE sysmapid=' . $sysmapid . ' AND ' . DBin_node('sysmapid', get_current_nodeid($perm)))) {
            $result = true;
        }
    }
    return $result;
}
Esempio n. 4
0
function get_accessible_maintenance_by_user($perm, $perm_res = null, $nodeid = null, $hostid = null, $cache = 1)
{
    global $USER_DETAILS;
    static $available_maintenances;
    $result = array();
    if (is_null($perm_res)) {
        $perm_res = PERM_RES_IDS_ARRAY;
    }
    $nodeid_str = is_array($nodeid) ? implode('', $nodeid) : strval($nodeid);
    $hostid_str = is_array($hostid) ? implode('', $hostid) : strval($hostid);
    if ($cache && isset($available_maintenances[$perm][$perm_res][$nodeid_str][$hostid_str])) {
        return $available_maintenances[$perm][$perm_res][$nodeid_str][$hostid_str];
    }
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, PERM_RES_IDS_ARRAY, $nodeid);
    $denied_maintenances = array();
    $available_maintenances = array();
    $sql = 'SELECT DISTINCT m.maintenanceid ' . ' FROM maintenances m, maintenances_hosts mh, maintenances_groups mg, hosts_groups hg ' . ' WHERE ' . DBcondition('hg.hostid', $available_hosts, true) . (!empty($hostid) ? ' AND hg.hostid=' . $hostid : '') . ' AND (' . '(mh.hostid=hg.hostid AND m.maintenanceid=mh.maintenanceid)' . ' OR (mg.groupid=hg.groupid AND m.maintenanceid=mg.maintenanceid))';
    //SDI($sql);
    $db_maintenances = DBselect($sql);
    while ($maintenance = DBfetch($db_maintenances)) {
        $denied_maintenances[] = $maintenance['maintenanceid'];
    }
    $sql = 'SELECT m.maintenanceid ' . ' FROM maintenances m ' . ' WHERE ' . DBin_node('m.maintenanceid') . ' AND ' . DBcondition('m.maintenanceid', $denied_maintenances, true);
    //SDI($sql);
    $db_maintenances = DBselect($sql);
    while ($maintenance = DBfetch($db_maintenances)) {
        $result[$maintenance['maintenanceid']] = $maintenance['maintenanceid'];
    }
    if (PERM_RES_STRING_LINE == $perm_res) {
        if (count($result) == 0) {
            $result = '-1';
        } else {
            $result = implode(',', $result);
        }
    }
    $available_maintenances[$perm][$perm_res][$nodeid_str][$hostid_str] = $result;
    return $result;
}
Esempio n. 5
0
foreach ($options as $option) {
    $params[$option] = 1;
}
$PAGE_GROUPS = get_viewed_groups(PERM_READ_ONLY, $params);
$PAGE_HOSTS = get_viewed_hosts(PERM_READ_ONLY, $PAGE_GROUPS['selected'], $params);
validate_group_with_host($PAGE_GROUPS, $PAGE_HOSTS);
// SDI($_REQUEST['groupid'].' : '.$_REQUEST['hostid']);
$rep2_wdgt = new CWidget();
// HEADER
if (0 == $config) {
    $available_groups = $PAGE_GROUPS['groupids'];
    $available_hosts = $PAGE_HOSTS['hostids'];
} else {
    $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY);
    if ($PAGE_HOSTS['selected'] != 0) {
        $PAGE_HOSTS['hostids'] = $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
    } else {
        $available_hosts = $PAGE_HOSTS['hostids'];
    }
}
$rep2_wdgt->addPageHeader(S_AVAILABILITY_REPORT_BIG);
//	show_report2_header($config, $PAGE_GROUPS, $PAGE_HOSTS);
if (isset($_REQUEST['triggerid'])) {
    $options = array('triggerids' => $_REQUEST['triggerid'], 'output' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_EXTEND, 'nodeids' => get_current_nodeid(true));
    $trigger_data = CTrigger::get($options);
    if (empty($trigger_data)) {
        unset($_REQUEST['triggerid']);
    } else {
        $trigger_data = reset($trigger_data);
        $host = reset($trigger_data['hosts']);
        $trigger_data['hostid'] = $host['hostid'];
Esempio n. 6
0
 $table->setHeader(array(S_TEMPLATES, S_HOSTS));
 $sql_from = '';
 $sql_where = '';
 if ($_REQUEST['groupid'] > 0) {
     $sql_from .= ',hosts_groups hg ';
     $sql_where .= ' AND hg.groupid=' . $_REQUEST['groupid'] . ' AND hg.hostid=h.hostid ';
 }
 $templates = array();
 $templateids = array();
 $sql = 'SELECT h.hostid, h.host ' . ' FROM hosts h ' . $sql_from . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . $sql_where . ' ORDER BY h.host';
 $result = DBSelect($sql);
 while ($template = DBfetch($result)) {
     $templateids[$template['hostid']] = $template['hostid'];
     $templates[$template['hostid']] = $template;
 }
 $allowed_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
 $sql = 'SELECT h.host, h.hostid, h.status, ht.templateid ' . ' FROM hosts h, hosts_templates ht ' . ' WHERE ht.hostid=h.hostid ' . ' AND ' . DBcondition('h.hostid', $allowed_hosts) . ' AND ' . DBcondition('ht.templateid', $templateids) . ' ORDER BY host';
 $result = DBSelect($sql);
 while ($host = DBfetch($result)) {
     if (!isset($templates[$host['templateid']]['hosts'])) {
         $templates[$host['templateid']]['hosts'] = array();
     }
     $templates[$host['templateid']]['hosts'][] = $host;
 }
 foreach ($templates as $templateid => $template) {
     $host_list = array();
     if (isset($template['hosts'])) {
         foreach ($template['hosts'] as $host) {
             switch ($host['status']) {
                 case HOST_STATUS_NOT_MONITORED:
                     $style = 'on';
Esempio n. 7
0
function bar_report_form3()
{
    global $USER_DETAILS;
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
    $config = get_request('config', 1);
    $title = get_request('title', S_REPORT . ' 3');
    $xlabel = get_request('xlabel', '');
    $ylabel = get_request('ylabel', '');
    $sorttype = get_request('sorttype', 0);
    $scaletype = get_request('scaletype', TIMEPERIOD_TYPE_WEEKLY);
    $avgperiod = get_request('avgperiod', TIMEPERIOD_TYPE_DAILY);
    $report_timesince = get_request('report_timesince', date('YmdHis', time() - 86400));
    $report_timetill = get_request('report_timetill', date('YmdHis'));
    $captions = get_request('captions', array());
    $items = get_request('items', array());
    $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');
    //,'events.php?report_set=1','POST',null,'sform');
    $reportForm->setAttribute('name', 'zbx_report');
    $reportForm->setAttribute('id', 'zbx_report');
    //	$reportForm->setMethod('post');
    if (isset($_REQUEST['report_show']) && !empty($items)) {
        $reportForm->addVar('report_show', 'show');
    }
    $reportForm->addVar('config', $config);
    $reportForm->addVar('report_timesince', date('YmdHis', $report_timesince));
    $reportForm->addVar('report_timetill', date('YmdHis', $report_timetill));
    //	$reportForm->addVar('items',$items); 				//params are set later!!
    //	$reportForm->addVar('periods',$periods);
    $reportForm->addRow(S_TITLE, new CTextBox('title', $title, 40));
    $reportForm->addRow(S_X . SPACE . S_LABEL, new CTextBox('xlabel', $xlabel, 40));
    $reportForm->addRow(S_Y . SPACE . S_LABEL, new CTextBox('ylabel', $ylabel, 40));
    $reportForm->addRow(S_LEGEND, new CCheckBox('showlegend', $showlegend, null, 1));
    $reportForm->addVar('sortorder', 0);
    // GROUPS
    $groupids = get_request('groupids', array());
    $group_tb = new CTweenBox($reportForm, 'groupids', $groupids, 10);
    $options = array('real_hosts' => 1, 'output' => 'extend');
    $db_groups = CHostGroup::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(S_GROUPS, $group_tb->Get(S_SELECTED_GROUPS, S_OTHER . SPACE . S_GROUPS));
    // ----------
    // HOSTS
    //	validate_group(PERM_READ_ONLY,array('real_hosts'),'web.last.conf.groupid');
    $groupid = get_request('groupid', 0);
    $cmbGroups = new CComboBox('groupid', $groupid, 'submit()');
    $cmbGroups->addItem(0, S_ALL_S);
    foreach ($db_groups as $gnum => $group) {
        $cmbGroups->addItem($group['groupid'], $group['name']);
    }
    $td_groups = new CCol(array(S_GROUP, SPACE, $cmbGroups));
    $td_groups->setAttribute('style', 'text-align: right;');
    $host_tb = new CTweenBox($reportForm, 'hostids', $hostids, 10);
    $options = array('real_hosts' => 1, 'output' => array('hostid', 'host'));
    if ($groupid > 0) {
        $options['groupids'] = $groupid;
    }
    $db_hosts = CHost::get($options);
    $db_hosts = zbx_toHash($db_hosts, 'hostid');
    order_result($db_hosts, 'host');
    foreach ($db_hosts as $hnum => $host) {
        $host_tb->addItem($host['hostid'], $host['host']);
    }
    $options = array('real_hosts' => 1, 'output' => array('hostid', 'host'), 'hostids' => $hostids);
    $db_hosts2 = CHost::get($options);
    order_result($db_hosts2, 'host');
    foreach ($db_hosts2 as $hnum => $host) {
        if (!isset($db_hosts[$host['hostid']])) {
            $host_tb->addItem($host['hostid'], $host['host']);
        }
    }
    $reportForm->addRow(S_HOSTS, $host_tb->Get(S_SELECTED_HOSTS, array(S_OTHER . SPACE . S_HOSTS . SPACE . '|' . SPACE . S_GROUP . SPACE, $cmbGroups)));
    // ----------
    //*/
    // PERIOD
    $clndr_icon = new CImg('images/general/bar/cal.gif', 'calendar', 16, 12, 'pointer');
    $clndr_icon->addAction('onclick', 'javascript: ' . 'var pos = getPosition(this); ' . 'pos.top+=10; ' . 'pos.left+=16; ' . "CLNDR['avail_report_since'].clndr.clndrshow(pos.top,pos.left);");
    $reporttimetab = new CTable(null, 'calendar');
    $reporttimetab->setAttribute('width', '10%');
    $reporttimetab->setCellPadding(0);
    $reporttimetab->setCellSpacing(0);
    $reporttimetab->addRow(array(S_FROM, new CNumericBox('report_since_day', $report_timesince > 0 ? date('d', $report_timesince) : '', 2), '/', new CNumericBox('report_since_month', $report_timesince > 0 ? date('m', $report_timesince) : '', 2), '/', new CNumericBox('report_since_year', $report_timesince > 0 ? date('Y', $report_timesince) : '', 4), SPACE, new CNumericBox('report_since_hour', $report_timesince > 0 ? date('H', $report_timesince) : '', 2), ':', new CNumericBox('report_since_minute', $report_timesince > 0 ? date('i', $report_timesince) : '', 2), $clndr_icon));
    zbx_add_post_js('create_calendar(null,' . '["report_since_day","report_since_month","report_since_year","report_since_hour","report_since_minute"],' . '"avail_report_since",' . '"report_timesince");');
    $clndr_icon->addAction('onclick', 'javascript: ' . 'var pos = getPosition(this); ' . 'pos.top+=10; ' . 'pos.left+=16; ' . "CLNDR['avail_report_till'].clndr.clndrshow(pos.top,pos.left);");
    $reporttimetab->addRow(array(S_TILL, new CNumericBox('report_till_day', $report_timetill > 0 ? date('d', $report_timetill) : '', 2), '/', new CNumericBox('report_till_month', $report_timetill > 0 ? date('m', $report_timetill) : '', 2), '/', new CNumericBox('report_till_year', $report_timetill > 0 ? date('Y', $report_timetill) : '', 4), SPACE, new CNumericBox('report_till_hour', $report_timetill > 0 ? date('H', $report_timetill) : '', 2), ':', new CNumericBox('report_till_minute', $report_timetill > 0 ? date('i', $report_timetill) : '', 2), $clndr_icon));
    zbx_add_post_js('create_calendar(null,' . '["report_till_day","report_till_month","report_till_year","report_till_hour","report_till_minute"],' . '"avail_report_till",' . '"report_timetill");');
    zbx_add_post_js('addListener($("filter_icon"),' . '"click",' . 'CLNDR[\'avail_report_since\'].clndr.clndrhide.bindAsEventListener(CLNDR[\'avail_report_since\'].clndr));' . 'addListener($("filter_icon"),' . '"click",' . 'CLNDR[\'avail_report_till\'].clndr.clndrhide.bindAsEventListener(CLNDR[\'avail_report_till\'].clndr));');
    $reportForm->addRow(S_PERIOD, $reporttimetab);
    //-----------
    $scale = new CComboBox('scaletype', $scaletype);
    $scale->addItem(TIMEPERIOD_TYPE_HOURLY, S_HOURLY);
    $scale->addItem(TIMEPERIOD_TYPE_DAILY, S_DAILY);
    $scale->addItem(TIMEPERIOD_TYPE_WEEKLY, S_WEEKLY);
    $scale->addItem(TIMEPERIOD_TYPE_MONTHLY, S_MONTHLY);
    $scale->addItem(TIMEPERIOD_TYPE_YEARLY, S_YEARLY);
    $reportForm->addRow(S_SCALE, $scale);
    $avgcmb = new CComboBox('avgperiod', $avgperiod);
    $avgcmb->addItem(TIMEPERIOD_TYPE_HOURLY, S_HOURLY);
    $avgcmb->addItem(TIMEPERIOD_TYPE_DAILY, S_DAILY);
    $avgcmb->addItem(TIMEPERIOD_TYPE_WEEKLY, S_WEEKLY);
    $avgcmb->addItem(TIMEPERIOD_TYPE_MONTHLY, S_MONTHLY);
    $avgcmb->addItem(TIMEPERIOD_TYPE_YEARLY, S_YEARLY);
    $reportForm->addRow(S_AVERAGE_BY, $avgcmb);
    // ITEMS
    $itemid = 0;
    $description = '';
    if (count($items) && $items[0]['itemid'] > 0) {
        $itemid = $items[0]['itemid'];
        $description = get_item_by_itemid($itemid);
        $description = item_description($description);
    }
    $reportForm->addVar('items[0][itemid]', $itemid);
    $txtCondVal = new CTextBox('items[0][description]', $description, 50, 'yes');
    $btnSelect = new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . $reportForm->GetName() . "&dstfld1=items[0][itemid]&dstfld2=items[0][description]&" . "srctbl=items&srcfld1=itemid&srcfld2=description&monitored_hosts=1');", 'T');
    $reportForm->addRow(S_ITEM, array($txtCondVal, $btnSelect));
    $paletteCmb = new CComboBox('palette', $palette);
    $paletteCmb->addItem(0, S_PALETTE . ' #1');
    $paletteCmb->addItem(1, S_PALETTE . ' #2');
    $paletteCmb->addItem(2, S_PALETTE . ' #3');
    $paletteCmb->addItem(3, S_PALETTE . ' #4');
    $paletteTypeCmb = new CComboBox('palettetype', $palettetype);
    $paletteTypeCmb->addItem(0, S_MIDDLE);
    $paletteTypeCmb->addItem(1, S_DARKEN);
    $paletteTypeCmb->addItem(2, S_BRIGHTEN);
    $reportForm->addRow(S_PALETTE, array($paletteCmb, $paletteTypeCmb));
    //--------------
    $reportForm->addItemToBottomRow(new CButton('report_show', S_SHOW));
    $reset = new CButton('reset', S_RESET);
    $reset->setType('reset');
    $reportForm->addItemToBottomRow($reset);
    return $reportForm;
}
Esempio n. 8
0
function get_accessible_graphs($perm, $hostids, $perm_res = null, $nodeid = null, $cache = 1)
{
    global $USER_DETAILS;
    static $available_graphs;
    if (is_null($perm_res)) {
        $perm_res = PERM_RES_IDS_ARRAY;
    }
    $nodeid_str = is_array($nodeid) ? implode('', $nodeid) : strval($nodeid);
    $hostid_str = implode('', $hostids);
    $cache_hash = md5($perm . $perm_res . $nodeid_str . $hostid_str);
    if ($cache && isset($available_graphs[$cache_hash])) {
        return $available_graphs[$cache_hash];
    }
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, PERM_RES_IDS_ARRAY, $nodeid);
    $denied_graphs = array();
    $result = array();
    $sql_where = '';
    if (!empty($hostids)) {
        $sql_where .= ' AND ' . DBcondition('i.hostid', $hostids);
    }
    $sql = 'SELECT DISTINCT g.graphid ' . ' FROM graphs g, graphs_items gi, items i ' . ' WHERE g.graphid=gi.graphid ' . ' AND i.itemid=gi.itemid ' . $sql_where . ' AND ' . DBcondition('i.hostid', $available_hosts, true);
    $db_graphs = DBselect($sql);
    while ($graph = DBfetch($db_graphs)) {
        $denied_graphs[] = $graph['graphid'];
    }
    $sql = 'SELECT DISTINCT g.graphid ' . ' FROM graphs g, graphs_items gi, items i ' . ' WHERE g.graphid=gi.graphid ' . ' AND i.itemid=gi.itemid ' . $sql_where . (!empty($denied_graphs) ? ' AND ' . DBcondition('g.graphid', $denied_graphs, true) : '');
    $db_graphs = DBselect($sql);
    while ($graph = DBfetch($db_graphs)) {
        $result[$graph['graphid']] = $graph['graphid'];
    }
    if (PERM_RES_STRING_LINE == $perm_res) {
        if (count($result) == 0) {
            $result = '-1';
        } else {
            $result = implode(',', $result);
        }
    }
    $available_graphs[$cache_hash] = $result;
    return $result;
}
Esempio n. 9
0
**
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
require_once "include/config.inc.php";
require_once "include/items.inc.php";
$page["title"] = "S_QUEUE_BIG";
$page["file"] = "queue.php";
$page['hist_arg'] = array('show');
define('ZBX_PAGE_DO_REFRESH', 1);
include_once "include/page_header.php";
//		VAR			TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array("show" => array(T_ZBX_INT, O_OPT, P_SYS, IN("0,1,2"), NULL));
check_fields($fields);
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
?>

<?php 
$_REQUEST["show"] = get_request("show", 0);
$form = new CForm();
$form->SetMethod('get');
$cmbMode = new CComboBox("show", $_REQUEST["show"], "submit();");
$cmbMode->AddItem(0, S_OVERVIEW);
$cmbMode->AddItem(1, S_OVERVIEW_BY_PROXY);
$cmbMode->AddItem(2, S_DETAILS);
$form->AddItem($cmbMode);
show_table_header(S_QUEUE_OF_ITEMS_TO_BE_UPDATED_BIG, $form);
?>

<?php 
Esempio n. 10
0
function check_right_on_trigger_by_expression($permission, $expression)
{
    global $USER_DETAILS;
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $permission, null, get_current_nodeid(true));
    $db_hosts = get_hosts_by_expression($expression);
    while ($host_data = DBfetch($db_hosts)) {
        if (!isset($available_hosts[$host_data['hostid']])) {
            return false;
        }
    }
    return true;
}
Esempio n. 11
0
$page['file'] = 'scripts_exec.php';
define('ZBX_PAGE_NO_MENU', 1);
include_once "include/page_header.php";
//---------------------------------- CHECKS ------------------------------------
//		VAR							TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array('hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), 'scriptid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({execute})'), 'execute' => array(T_ZBX_INT, O_OPT, P_ACT, IN('0,1'), null));
check_fields($fields);
if (isset($_REQUEST['execute'])) {
    if ($script = get_script_by_scriptid($_REQUEST['scriptid'])) {
        if ($script['host_access'] == PERM_READ_WRITE) {
            $hosts_read_write = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY);
            if (uint_in_array($_REQUEST['hostid'], $hosts_read_write)) {
                //SDI('WRITE: '.$_REQUEST['scriptid'].' : '.$_REQUEST['hostid']);
                //				$result = execute_script($_REQUEST['scriptid'],$_REQUEST['hostid']);
                //				insert_command_result_form($result["flag"],$result["message"]);
                insert_command_result_form($_REQUEST['scriptid'], $_REQUEST['hostid']);
                /*				echo nl2br(htmlspecialchars($result));*/
            }
        } else {
            $hosts_read_only = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
            if (uint_in_array($_REQUEST['hostid'], $hosts_read_only)) {
                //SDI('READ: '.$_REQUEST['scriptid'].' : '.$_REQUEST['hostid']);
                //				$result = execute_script($_REQUEST['scriptid'],$_REQUEST['hostid']);
                //				insert_command_result_form($result["flag"],$result["message"]);
                insert_command_result_form($_REQUEST['scriptid'], $_REQUEST['hostid']);
                /*				echo nl2br(htmlspecialchars($result));*/
            }
        }
    }
}
include_once "include/page_footer.php";
Esempio n. 12
0
function get_viewed_hosts($perm, $groupid = 0, $options = array(), $nodeid = null, $sql = array('monitored_hosts' => 1))
{
    global $USER_DETAILS;
    global $page;
    $def_sql = array('from' => array('hosts h'), 'where' => array());
    $def_options = array('allow_all' => 0, 'select_first_host' => 0, 'select_first_host_if_empty' => 0, 'select_host_on_group_switch' => 0, 'do_not_select' => 0, 'do_not_select_if_empty' => 0, 'monitored_hosts' => 0, 'templated_hosts' => 0, 'real_hosts' => 0, 'not_proxy_hosts' => 0, 'with_items' => 0, 'with_monitored_items' => 0, 'with_historical_items' => 0, 'with_triggers' => 0, 'with_monitored_triggers' => 0, 'with_httptests' => 0, 'with_monitored_httptests' => 0, 'with_graphs' => 0, 'only_current_node' => 0);
    $def_options = array_merge($def_options, $options);
    $dd_first_entry = ZBX_DROPDOWN_FIRST_ENTRY;
    if ($dd_first_entry == ZBX_DROPDOWN_FIRST_ZBX162) {
        $def_options['select_first_host_if_empty'] = 1;
        $dd_first_entry = ZBX_DROPDOWN_FIRST_ALL;
    }
    if ($def_options['allow_all']) {
        $dd_first_entry = ZBX_DROPDOWN_FIRST_ALL;
    }
    if ($dd_first_entry == ZBX_DROPDOWN_FIRST_ALL) {
        $def_options['select_host_on_group_switch'] = 1;
    }
    $result = array('original' => -1, 'selected' => 0, 'hosts' => array(), 'hostids' => array());
    $hosts =& $result['hosts'];
    $hostids =& $result['hostids'];
    $first_entry = $dd_first_entry == ZBX_DROPDOWN_FIRST_NONE ? S_NOT_SELECTED_SMALL : S_ALL_SMALL;
    $hosts['0'] = $first_entry;
    $hostids['0'] = '0';
    if (!is_array($groupid) && $groupid == 0) {
        if ($dd_first_entry == ZBX_DROPDOWN_FIRST_NONE) {
            return $result;
        }
    } else {
        zbx_value2array($groupid);
        $def_sql['from'][] = 'hosts_groups hg';
        $def_sql['where'][] = DBcondition('hg.groupid', $groupid);
        $def_sql['where'][] = 'hg.hostid=h.hostid';
    }
    $_REQUEST['hostid'] = $result['original'] = get_request('hostid', -1);
    //-----
    $nodeid = is_null($nodeid) ? get_current_nodeid(!$def_options['only_current_node']) : $nodeid;
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, $perm, PERM_RES_IDS_ARRAY, $nodeid, AVAILABLE_NOCACHE);
    // hosts
    if ($def_options['monitored_hosts']) {
        $def_sql['where'][] = 'h.status=' . HOST_STATUS_MONITORED;
    } else {
        if ($def_options['real_hosts']) {
            $def_sql['where'][] = 'h.status IN(' . HOST_STATUS_MONITORED . ',' . HOST_STATUS_NOT_MONITORED . ')';
        } else {
            if ($def_options['templated_hosts']) {
                $def_sql['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE;
            } else {
                if ($def_options['not_proxy_hosts']) {
                    $def_sql['where'][] = 'h.status<>' . HOST_STATUS_PROXY;
                }
            }
        }
    }
    // items
    if ($def_options['with_items']) {
        $def_sql['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE h.hostid=i.hostid )';
    } else {
        if ($def_options['with_monitored_items']) {
            $def_sql['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE h.hostid=i.hostid AND i.status=' . ITEM_STATUS_ACTIVE . ')';
        } else {
            if ($def_options['with_historical_items']) {
                $def_sql['where'][] = 'EXISTS (SELECT i.hostid FROM items i WHERE h.hostid=i.hostid AND (i.status=' . ITEM_STATUS_ACTIVE . ' OR i.status=' . ITEM_STATUS_NOTSUPPORTED . ') AND i.lastvalue IS NOT NULL)';
            }
        }
    }
    // triggers
    if ($def_options['with_triggers']) {
        $def_sql['where'][] = 'EXISTS( SELECT i.itemid ' . ' FROM items i, functions f, triggers t' . ' WHERE i.hostid=h.hostid ' . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid)';
    } else {
        if ($def_options['with_monitored_triggers']) {
            $def_sql['where'][] = 'EXISTS( SELECT i.itemid ' . ' FROM items i, functions f, triggers t' . ' WHERE i.hostid=h.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ')';
        }
    }
    // httptests
    if ($def_options['with_httptests']) {
        $def_sql['where'][] = 'EXISTS( SELECT a.applicationid ' . ' FROM applications a, httptest ht ' . ' WHERE a.hostid=h.hostid ' . ' AND ht.applicationid=a.applicationid)';
    } else {
        if ($def_options['with_monitored_httptests']) {
            $def_sql['where'][] = 'EXISTS( SELECT a.applicationid ' . ' FROM applications a, httptest ht ' . ' WHERE a.hostid=h.hostid ' . ' AND ht.applicationid=a.applicationid ' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE . ')';
        }
    }
    // graphs
    if ($def_options['with_graphs']) {
        $def_sql['where'][] = 'EXISTS( SELECT DISTINCT i.itemid ' . ' FROM items i, graphs_items gi ' . ' WHERE i.hostid=h.hostid ' . ' AND i.itemid=gi.itemid)';
    }
    //------
    foreach ($sql as $key => $value) {
        zbx_value2array($value);
        if (isset($def_sql[$key])) {
            $def_sql[$key] = array_merge($def_sql[$key], $value);
        } else {
            $def_sql[$key] = $value;
        }
    }
    $def_sql['from'] = array_unique($def_sql['from']);
    $def_sql['where'] = array_unique($def_sql['where']);
    $sql_from = '';
    $sql_where = '';
    if (!empty($def_sql['from'])) {
        $sql_from .= implode(',', $def_sql['from']);
    }
    if (!empty($def_sql['where'])) {
        $sql_where .= ' AND ' . implode(' AND ', $def_sql['where']);
    }
    $sql = 'SELECT DISTINCT h.hostid, h.host ' . ' FROM ' . $sql_from . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . $sql_where . ' ORDER BY h.host';
    $res = DBselect($sql);
    while ($host = DBfetch($res)) {
        $hosts[$host['hostid']] = $host['host'];
        $hostids[$host['hostid']] = $host['hostid'];
        if (bccomp($_REQUEST['hostid'], $host['hostid']) == 0) {
            $result['selected'] = $host['hostid'];
        }
    }
    $profile_hostid = get_profile('web.' . $page['menu'] . '.hostid');
    //-----
    if ($def_options['do_not_select']) {
        $_REQUEST['hostid'] = $result['selected'] = 0;
    } else {
        if ($def_options['do_not_select_if_empty'] && $_REQUEST['hostid'] == -1) {
            $_REQUEST['hostid'] = $result['selected'] = 0;
        } else {
            if ($def_options['select_first_host'] || $def_options['select_first_host_if_empty'] && $_REQUEST['hostid'] == -1 && is_null($profile_hostid) || $def_options['select_host_on_group_switch'] && $_REQUEST['hostid'] != -1 && bccomp($_REQUEST['hostid'], $result['selected']) != 0) {
                $first_hostid = next($hostids);
                reset($hostids);
                if ($first_hostid !== FALSE) {
                    $_REQUEST['hostid'] = $result['selected'] = $first_hostid;
                } else {
                    $_REQUEST['hostid'] = $result['selected'] = 0;
                }
            } else {
                if (ZBX_DROPDOWN_FIRST_REMEMBER) {
                    if ($_REQUEST['hostid'] == -1) {
                        $_REQUEST['hostid'] = is_null($profile_hostid) ? '0' : $profile_hostid;
                    }
                    if (uint_in_array($_REQUEST['hostid'], $hostids)) {
                        $result['selected'] = $_REQUEST['hostid'];
                    } else {
                        $_REQUEST['hostid'] = $result['selected'];
                    }
                } else {
                    $_REQUEST['hostid'] = $result['selected'];
                }
            }
        }
    }
    return $result;
}
Esempio n. 13
0
function get_screen($screenid, $editmode, $effectiveperiod = NULL)
{
    global $USER_DETAILS;
    if ($screenid == 0) {
        return new CTableInfo(S_NO_SCREENS_DEFINED);
    }
    if (!screen_accessible($screenid, $editmode == 1 ? PERM_READ_WRITE : PERM_READ_ONLY)) {
        access_deny();
    }
    if (is_null($effectiveperiod)) {
        $effectiveperiod = ZBX_MIN_PERIOD;
    }
    $result = DBselect('SELECT name,hsize,vsize FROM screens WHERE screenid=' . $screenid);
    $row = DBfetch($result);
    if (!$row) {
        return new CTableInfo(S_NO_SCREENS_DEFINED);
    }
    for ($r = 0; $r < $row['vsize']; $r++) {
        for ($c = 0; $c < $row['hsize']; $c++) {
            if (isset($skip_field[$r][$c])) {
                continue;
            }
            $sql = 'SELECT * FROM screens_items WHERE screenid=' . $screenid . ' AND x=' . $c . ' AND y=' . $r;
            $iresult = DBSelect($sql);
            $irow = DBfetch($iresult);
            if ($irow) {
                $colspan = $irow['colspan'];
                $rowspan = $irow['rowspan'];
            } else {
                $colspan = 0;
                $rowspan = 0;
            }
            for ($i = 0; $i < $rowspan || $i == 0; $i++) {
                for ($j = 0; $j < $colspan || $j == 0; $j++) {
                    if ($i != 0 || $j != 0) {
                        $skip_field[$r + $i][$c + $j] = 1;
                    }
                }
            }
        }
    }
    $table = new CTable(new CLink('No rows in screen ' . $row['name'], 'screenconf.php?config=0&form=update&screenid=' . $screenid), $editmode == 0 || $editmode == 2 ? 'screen_view' : 'screen_edit');
    $table->setAttribute('id', 'iframe');
    if ($editmode == 1) {
        $add_col_link = 'screenedit.php?config=1&screenid=' . $screenid . '&add_col=';
        $new_cols = array(new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1)));
        for ($c = 0; $c < $row['hsize'] + 1; $c++) {
            array_push($new_cols, new Ccol(new Clink(new Cimg('images/general/closed.gif'), $add_col_link . $c)));
        }
        $table->addRow($new_cols);
    }
    $empty_screen_col = array();
    for ($r = 0; $r < $row['vsize']; $r++) {
        $new_cols = array();
        $empty_screen_row = true;
        if ($editmode == 1) {
            $add_row_link = 'screenedit.php?config=1&screenid=' . $screenid . '&add_row=';
            array_push($new_cols, new Ccol(new Clink(new Cimg('images/general/closed.gif'), $add_row_link . $r)));
        }
        for ($c = 0; $c < $row['hsize']; $c++) {
            $item = array();
            if (isset($skip_field[$r][$c])) {
                continue;
            }
            $item_form = false;
            $iresult = DBSelect('SELECT * FROM screens_items WHERE screenid=' . $screenid . ' AND x=' . $c . ' AND y=' . $r);
            $irow = DBfetch($iresult);
            if ($irow) {
                $screenitemid = $irow['screenitemid'];
                $resourcetype = $irow['resourcetype'];
                $resourceid = $irow['resourceid'];
                $width = $irow['width'];
                $height = $irow['height'];
                $colspan = $irow['colspan'];
                $rowspan = $irow['rowspan'];
                $elements = $irow['elements'];
                $valign = $irow['valign'];
                $halign = $irow['halign'];
                $style = $irow['style'];
                $url = $irow['url'];
                $dynamic = $irow['dynamic'];
            } else {
                $screenitemid = 0;
                $resourcetype = 0;
                $resourceid = 0;
                $width = 0;
                $height = 0;
                $colspan = 0;
                $rowspan = 0;
                $elements = 0;
                $valign = VALIGN_DEFAULT;
                $halign = HALIGN_DEFAULT;
                $style = 0;
                $url = '';
                $dynamic = 0;
            }
            if ($screenitemid > 0) {
                $empty_screen_row = false;
                $empty_screen_col[$c] = 1;
            }
            if ($editmode == 1 && $screenitemid != 0) {
                $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&screenitemid=' . $screenitemid . "#form');";
                $action = 'screenedit.php?form=update' . url_param('screenid') . '&screenitemid=' . $screenitemid . '#form';
            } else {
                if ($editmode == 1 && $screenitemid == 0) {
                    $onclick_action = "ZBX_SCREENS['" . $_REQUEST['screenid'] . "'].screen.element_onclick('screenedit.php?form=update" . url_param('screenid') . '&x=' . $c . '&y=' . $r . "#form');";
                    $action = 'screenedit.php?form=update' . url_param('screenid') . '&x=' . $c . '&y=' . $r . '#form';
                } else {
                    $action = NULL;
                }
            }
            if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['x']) && $_REQUEST['x'] == $c && isset($_REQUEST['y']) && $_REQUEST['y'] == $r) {
                // click on empty field
                $item = get_screen_item_form();
                $item_form = true;
            } else {
                if ($editmode == 1 && isset($_REQUEST['form']) && isset($_REQUEST['screenitemid']) && bccomp($_REQUEST['screenitemid'], $screenitemid) == 0) {
                    // click on element
                    $item = get_screen_item_form();
                    $item_form = true;
                } else {
                    if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_GRAPH) {
                        if ($editmode == 0) {
                            $action = 'charts.php?graphid=' . $resourceid . url_param('period') . url_param('stime');
                        }
                        $graphid = null;
                        $graphtype = GRAPH_TYPE_NORMAL;
                        $yaxis = 0;
                        // GRAPH & ZOOM features
                        $sql = 'SELECT MAX(g.graphid) as graphid, MAX(g.graphtype) as graphtype, MIN(gi.yaxisside) as yaxissidel, MAX(gi.yaxisside) as yaxissider,' . ' MAX(g.show_legend) as legend, MAX(g.show_3d) as show3d ' . ' FROM graphs g, graphs_items gi ' . ' WHERE g.graphid=' . $resourceid . ' AND gi.graphid=g.graphid ';
                        $res = DBselect($sql);
                        while ($graph = DBfetch($res)) {
                            $graphid = $graph['graphid'];
                            $graphtype = $graph['graphtype'];
                            $yaxis = $graph['yaxissider'];
                            $yaxis = $graph['yaxissidel'] == $yaxis ? $yaxis : 2;
                            $legend = $graph['legend'];
                            $graph3d = $graph['show3d'];
                        }
                        if ($yaxis == 2) {
                            $shiftXleft = 60;
                            $shiftXright = 60;
                        } else {
                            if ($yaxis == 0) {
                                $shiftXleft = 60;
                                $shiftXright = 20;
                            } else {
                                $shiftXleft = 10;
                                $shiftXright = 60;
                            }
                        }
                        //-------------
                        // Host feature
                        if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) {
                            $def_items = array();
                            $di_res = get_graphitems_by_graphid($resourceid);
                            while ($gitem = DBfetch($di_res)) {
                                $def_items[] = $gitem;
                            }
                            $url = '';
                            if ($new_items = get_same_graphitems_for_host($def_items, $_REQUEST['hostid'])) {
                                $url .= make_url_from_gitems($new_items);
                            }
                            $url = make_url_from_graphid($resourceid, false) . $url;
                        }
                        //-------------
                        $default = false;
                        if ($graphtype == GRAPH_TYPE_PIE || $graphtype == GRAPH_TYPE_EXPLODED) {
                            if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) {
                                $url = 'chart6.php?graphid=' . $resourceid;
                                $default = true;
                            }
                            $g_img = new CImg($url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime') . '&legend=' . $legend . '&graph3d=' . $graph3d);
                        } else {
                            if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) {
                                $url = 'chart2.php?graphid=' . $resourceid;
                                $default = true;
                            }
                            $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid;
                            $g_img = new CImg($url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime'));
                            $g_img->setAttribute('id', $dom_graph_id);
                            if (!is_null($graphid) && $editmode != 1) {
                                insert_js('	A_SBOX["' . $dom_graph_id . '"] = new Object;' . 'A_SBOX["' . $dom_graph_id . '"].shiftT = 17;' . 'A_SBOX["' . $dom_graph_id . '"].shiftL = ' . $shiftXleft . ';');
                                if (isset($_REQUEST['stime'])) {
                                    $stime = $_REQUEST['stime'];
                                    $stime = mktime(substr($stime, 8, 2), substr($stime, 10, 2), 0, substr($stime, 4, 2), substr($stime, 6, 2), substr($stime, 0, 4));
                                } else {
                                    $stime = 'null';
                                }
                                global $page;
                                if ($page['type'] == PAGE_TYPE_HTML) {
                                    zbx_add_post_js('graph_zoom_init("' . $dom_graph_id . '",' . $stime . ',' . $effectiveperiod . ',' . $width . ',' . $height . ', false);');
                                } else {
                                    $g_img->setAttribute('onload', 'javascript: graph_zoom_init("' . $dom_graph_id . '",' . $stime . ',' . $effectiveperiod . ',' . $width . ',' . $height . ', false);');
                                    //								insert_js('graph_zoom_init("'.$dom_graph_id.'",'.$stime.','.$effectiveperiod.','.$width.','.$height.', false);');
                                }
                            }
                        }
                        if ($default && $editmode == 0) {
                            $item = new CLink($g_img, $action);
                        } else {
                            $item =& $g_img;
                        }
                    } else {
                        if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) {
                            if ($editmode == 0) {
                                $action = "history.php?action=showgraph&itemid={$resourceid}" . url_param("period") . url_param("inc") . url_param("dec");
                            }
                            // Host feature
                            if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) {
                                if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) {
                                    $resourceid = $newitemid;
                                } else {
                                    $resourceid = '';
                                }
                            }
                            //-------------
                            $url = empty($resourceid) ? 'chart3.php?' : "chart.php?itemid={$resourceid}&";
                            $item = new CLink(new CImg($url . "width={$width}&height={$height}" . "&period={$effectiveperiod}" . url_param("stime")), $action);
                        } else {
                            if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_MAP) {
                                $image_map = new CImg("map.php?noedit=1&sysmapid={$resourceid}" . "&width={$width}&height={$height}");
                                if ($editmode == 0) {
                                    $action_map = get_action_map_by_sysmapid($resourceid);
                                    $image_map->SetMap($action_map->GetName());
                                    $item = array($action_map, $image_map);
                                } else {
                                    $item = $image_map;
                                    //						$item = new CLink($image_map, $action);
                                }
                            } else {
                                if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_PLAIN_TEXT) {
                                    // Host feature
                                    if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) {
                                        if ($newitemid = get_same_item_for_host($resourceid, $_REQUEST['hostid'])) {
                                            $resourceid = $newitemid;
                                        } else {
                                            $resourceid = 0;
                                        }
                                    }
                                    //-------------
                                    $item = array(get_screen_plaintext($resourceid, $elements, $style));
                                    if ($editmode == 1) {
                                        array_push($item, new CLink(S_CHANGE, $action));
                                    }
                                } else {
                                    if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_STATUS_OF_TRIGGERS) {
                                        $params = array();
                                        $params['groupid'] = get_request('tr_groupid', get_profile('web.screens.tr_groupid', 0));
                                        $params['hostid'] = get_request('tr_hostid', get_profile('web.screens.tr_hostid', 0));
                                        $params['limit'] = $elements;
                                        update_profile('web.screens.tr_groupid', $params['groupid'], PROFILE_TYPE_ID);
                                        update_profile('web.screens.tr_hostid', $params['hostid'], PROFILE_TYPE_ID);
                                        $tr_form = new CForm();
                                        $cmbGroup = new CComboBox('tr_groupid', $params['groupid'], 'submit()');
                                        $cmbHosts = new CComboBox('tr_hostid', $params['hostid'], 'submit()');
                                        $cmbGroup->addItem(0, S_ALL_SMALL);
                                        $cmbHosts->addItem(0, S_ALL_SMALL);
                                        $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY);
                                        $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
                                        $available_triggers = get_accessible_triggers(PERM_READ_ONLY, PERM_RES_IDS_ARRAY);
                                        $sql = 'SELECT DISTINCT g.groupid,g.name ' . ' FROM groups g, hosts_groups hg, hosts h ' . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND hg.groupid=g.groupid ' . ' AND h.hostid=hg.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . ' AND EXISTS(SELECT i.itemid FROM items i WHERE i.status=' . ITEM_STATUS_ACTIVE . ' AND i.hostid=h.hostid ) ' . ' ORDER BY g.name';
                                        $tresult = DBselect($sql);
                                        while ($tr_row = DBfetch($tresult)) {
                                            $cmbGroup->addItem($tr_row['groupid'], get_node_name_by_elid($tr_row['groupid']) . $tr_row['name']);
                                        }
                                        $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup));
                                        $sql_from = '';
                                        $sql_where = '';
                                        if ($params['groupid'] > 0) {
                                            $sql_from .= ',hosts_groups hg ';
                                            $sql_where .= ' AND hg.hostid=h.hostid AND hg.groupid=' . $params['groupid'];
                                        }
                                        $sql = 'SELECT DISTINCT h.hostid,h.host ' . ' FROM hosts h, items i, functions f, triggers t ' . $sql_from . ' WHERE h.status=' . HOST_STATUS_MONITORED . $sql_where . ' AND h.hostid=i.hostid ' . ' AND i.status=' . ITEM_STATUS_ACTIVE . ' AND i.itemid=f.itemid ' . ' AND f.triggerid=t.triggerid ' . ' AND t.status=' . TRIGGER_STATUS_ENABLED . ' AND ' . DBcondition('h.hostid', $available_hosts) . ' ORDER BY h.host';
                                        $tresult = DBselect($sql);
                                        while ($tr_row = DBfetch($tresult)) {
                                            $cmbHosts->addItem($tr_row['hostid'], get_node_name_by_elid($tr_row['hostid']) . $tr_row['host']);
                                        }
                                        $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts));
                                        $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, date('[H:i:s]', time())), $tr_form));
                                        //*/
                                        //					$item = array();
                                        $item[] = make_latest_issues($params);
                                        if ($editmode == 1) {
                                            array_push($item, new CLink(S_CHANGE, $action));
                                        }
                                    } else {
                                        if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SYSTEM_STATUS) {
                                            $item = array(get_table_header(array(S_SYSTEM_STATUSBIG, SPACE, date('[H:i:s]', time()))));
                                            $item[] = make_system_summary();
                                            if ($editmode == 1) {
                                                array_push($item, new CLink(S_CHANGE, $action));
                                            }
                                        } else {
                                            if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOSTS_INFO) {
                                                $item = array(new CHostsInfo($resourceid, $style));
                                                if ($editmode == 1) {
                                                    array_push($item, new CLink(S_CHANGE, $action));
                                                }
                                            } else {
                                                if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_INFO) {
                                                    $item = new CTriggersInfo($style);
                                                    if ($resourceid > 0) {
                                                        $item->set_host_group($resourceid);
                                                    }
                                                    $item = array($item);
                                                    if ($editmode == 1) {
                                                        array_push($item, new CLink(S_CHANGE, $action));
                                                    }
                                                } else {
                                                    if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SERVER_INFO) {
                                                        //					$item = array(get_table_header(S_STATUS_OF_ZABBIX_BIG),make_status_of_zbx());
                                                        $item = array(new CServerInfo());
                                                        if ($editmode == 1) {
                                                            array_push($item, new CLink(S_CHANGE, $action));
                                                        }
                                                    } else {
                                                        if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_CLOCK) {
                                                            $item = new CFlashClock($width, $height, $style, $action);
                                                        } else {
                                                            if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SCREEN) {
                                                                $item = array(get_screen($resourceid, 2, $effectiveperiod));
                                                                if ($editmode == 1) {
                                                                    array_push($item, new CLink(S_CHANGE, $action));
                                                                }
                                                            } else {
                                                                if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_TRIGGERS_OVERVIEW) {
                                                                    $hostids = array();
                                                                    $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid);
                                                                    while ($tmp_host = DBfetch($res)) {
                                                                        $hostids[$tmp_host['hostid']] = $tmp_host['hostid'];
                                                                    }
                                                                    $item = array(get_triggers_overview($hostids, $style));
                                                                    if ($editmode == 1) {
                                                                        array_push($item, new CLink(S_CHANGE, $action));
                                                                    }
                                                                } else {
                                                                    if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_DATA_OVERVIEW) {
                                                                        $hostids = array();
                                                                        $res = DBselect('SELECT DISTINCT hg.hostid FROM hosts_groups hg WHERE hg.groupid=' . $resourceid);
                                                                        while ($tmp_host = DBfetch($res)) {
                                                                            $hostids[$tmp_host['hostid']] = $tmp_host['hostid'];
                                                                        }
                                                                        $item = array(get_items_data_overview($hostids, $style));
                                                                        if ($editmode == 1) {
                                                                            array_push($item, new CLink(S_CHANGE, $action));
                                                                        }
                                                                    } else {
                                                                        if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_URL) {
                                                                            $item = array(new CIFrame($url, $width, $height, "auto"));
                                                                            if ($editmode == 1) {
                                                                                array_push($item, BR(), new CLink(S_CHANGE, $action));
                                                                            }
                                                                        } else {
                                                                            if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_ACTIONS) {
                                                                                $item = array(get_history_of_actions($elements));
                                                                                if ($editmode == 1) {
                                                                                    array_push($item, new CLink(S_CHANGE, $action));
                                                                                }
                                                                            } else {
                                                                                if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_EVENTS) {
                                                                                    $item = array(get_history_of_triggers_events(0, $elements));
                                                                                    if ($editmode == 1) {
                                                                                        array_push($item, new CLink(S_CHANGE, $action));
                                                                                    }
                                                                                } else {
                                                                                    $item = array(SPACE);
                                                                                    if ($editmode == 1) {
                                                                                        array_push($item, BR(), new CLink(S_CHANGE, $action));
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            $str_halign = 'def';
            if ($halign == HALIGN_CENTER) {
                $str_halign = 'cntr';
            }
            if ($halign == HALIGN_LEFT) {
                $str_halign = 'left';
            }
            if ($halign == HALIGN_RIGHT) {
                $str_halign = 'right';
            }
            $str_valign = 'def';
            if ($valign == VALIGN_MIDDLE) {
                $str_valign = 'mdl';
            }
            if ($valign == VALIGN_TOP) {
                $str_valign = 'top';
            }
            if ($valign == VALIGN_BOTTOM) {
                $str_valign = 'bttm';
            }
            if ($editmode == 1 && !$item_form) {
                $item = new CDiv($item, 'draggable');
                $item->setAttribute('id', 'position_' . $r . '_' . $c);
                if ($editmode == 1) {
                    $item->setAttribute('onclick', 'javascript: ' . $onclick_action);
                }
            }
            $new_col = new CCol($item, $str_halign . '_' . $str_valign);
            if ($colspan) {
                $new_col->SetColSpan($colspan);
            }
            if ($rowspan) {
                $new_col->SetRowSpan($rowspan);
            }
            array_push($new_cols, $new_col);
        }
        if ($editmode == 1) {
            $rmv_icon = new Cimg('images/general/opened.gif');
            if ($empty_screen_row) {
                $rmv_row_link = 'javascript: location.href = ' . "'screenedit.php?config=1&screenid=" . $screenid . '&rmv_row=' . $r . "';";
            } else {
                $rmv_row_link = "javascript: if(Confirm('This screen-row is not empty. Delete it?')){" . " location.href = 'screenedit.php?config=1&screenid=" . $screenid . "&rmv_row=" . $r . "';}";
            }
            $rmv_icon->addAction('onclick', $rmv_row_link);
            array_push($new_cols, new Ccol($rmv_icon));
        }
        $table->AddRow(new CRow($new_cols));
    }
    if ($editmode == 1) {
        $add_row_link = 'screenedit.php?config=1&screenid=' . $screenid . '&add_row=';
        $new_cols = array(new Ccol(new Clink(new Cimg('images/general/closed.gif'), $add_row_link . $row['vsize'])));
        for ($c = 0; $c < $row['hsize']; $c++) {
            $rmv_icon = new Cimg('images/general/opened.gif');
            if (isset($empty_screen_col[$c])) {
                $rmv_col_link = "javascript: if(Confirm('This screen-column is not empty. Delete it?')){" . " location.href = 'screenedit.php?config=1&screenid=" . $screenid . "&rmv_col=" . $c . "';}";
            } else {
                $rmv_col_link = "javascript: location.href = 'screenedit.php?config=1&screenid=" . $screenid . "&rmv_col=" . $c . "';";
            }
            $rmv_icon->addAction('onclick', $rmv_col_link);
            array_push($new_cols, new Ccol($rmv_icon));
        }
        array_push($new_cols, new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1)));
        $table->addRow($new_cols);
    }
    return $table;
}
Esempio n. 14
0
require_once 'include/forms.inc.php';
$page['title'] = "S_CONFIGURATION_OF_GRAPHS";
$page['file'] = 'graphs.php';
$page['hist_arg'] = array();
$page['scripts'] = array('graphs.js');
include_once 'include/page_header.php';
//		VAR			TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array('groupid' => array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), 'hostid' => array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), 'copy_type' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), 'isset({copy})'), 'copy_mode' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0'), NULL), 'graphid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, '(isset({form})&&({form}=="update"))'), 'name' => array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({save})'), 'width' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), 'isset({save})'), 'height' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), 'isset({save})'), 'ymin_type' => array(T_ZBX_INT, O_OPT, NULL, IN('0,1,2'), null), 'ymax_type' => array(T_ZBX_INT, O_OPT, NULL, IN('0,1,2'), null), 'graphtype' => array(T_ZBX_INT, O_OPT, NULL, IN('0,1,2,3'), 'isset({save})'), 'yaxismin' => array(T_ZBX_DBL, O_OPT, NULL, null, 'isset({save})&&(({graphtype} == 0) || ({graphtype} == 1))'), 'yaxismax' => array(T_ZBX_DBL, O_OPT, NULL, null, 'isset({save})&&(({graphtype} == 0) || ({graphtype} == 1))'), 'graph3d' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'legend' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), "ymin_itemid" => array(T_ZBX_INT, O_OPT, NULL, DB_ID, 'isset({save})&&isset({ymin_type})&&({ymin_type}==3)'), "ymax_itemid" => array(T_ZBX_INT, O_OPT, NULL, DB_ID, 'isset({save})&&isset({ymax_type})&&({ymax_type}==3)'), 'percent_left' => array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(0, 100), null), 'percent_right' => array(T_ZBX_DBL, O_OPT, NULL, BETWEEN(0, 100), null), 'visible' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 1), null), 'items' => array(T_ZBX_STR, O_OPT, NULL, null, null), 'new_graph_item' => array(T_ZBX_STR, O_OPT, NULL, null, null), 'group_gid' => array(T_ZBX_STR, O_OPT, NULL, null, null), 'move_up' => array(T_ZBX_INT, O_OPT, NULL, null, null), 'move_down' => array(T_ZBX_INT, O_OPT, NULL, null, null), 'showworkperiod' => array(T_ZBX_INT, O_OPT, NULL, IN('1'), NULL), 'showtriggers' => array(T_ZBX_INT, O_OPT, NULL, IN('1'), NULL), 'group_graphid' => array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), 'copy_targetid' => array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), 'filter_groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({copy})&&(isset({copy_type})&&({copy_type}==0))'), 'add_item' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'delete_item' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'save' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'clone' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'copy' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'delete' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'cancel' => array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), 'form_copy_to' => array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), 'form_refresh' => array(T_ZBX_INT, O_OPT, NULL, NULL, NULL));
check_fields($fields);
validate_sort_and_sortorder('g.name', ZBX_SORT_UP);
$_REQUEST['items'] = get_request('items', array());
$_REQUEST['group_gid'] = get_request('group_gid', array());
$_REQUEST['graph3d'] = get_request('graph3d', 0);
$_REQUEST['legend'] = get_request('legend', 0);
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE);
$available_hosts_all_nodes = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE, null, get_current_nodeid(true));
$available_graphs = get_accessible_graphs(PERM_READ_WRITE, array(), null, get_current_nodeid(true));
// OPTIMAZE
// ---- <ACTIONS> ----
if (isset($_REQUEST['clone']) && isset($_REQUEST['graphid'])) {
    unset($_REQUEST['graphid']);
    $_REQUEST['form'] = 'clone';
} else {
    if (isset($_REQUEST['save'])) {
        $items = get_request('items', array());
        $itemids = array();
        foreach ($items as $gitem) {
            $itemids[$gitem['itemid']] = $gitem['itemid'];
        }
        if (!empty($itemids)) {
            $sql = 'SELECT h.hostid ' . ' FROM hosts h,items i ' . ' WHERE h.hostid=i.hostid ' . ' AND ' . DBcondition('i.itemid', $itemids) . ' AND ' . DBcondition('h.hostid', $available_hosts_all_nodes, true);
Esempio n. 15
0
**
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
require_once 'include/config.inc.php';
require_once 'include/hosts.inc.php';
require_once 'include/maintenances.inc.php';
require_once 'include/forms.inc.php';
$page['title'] = "S_HOSTS";
$page['file'] = 'hosts.php';
$page['hist_arg'] = array('groupid', 'config', 'hostid');
include_once 'include/page_header.php';
$_REQUEST['config'] = get_request('config', 'hosts.php');
$available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_WRITE);
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE);
if (isset($_REQUEST['groupid']) && $_REQUEST['groupid'] > 0 && !isset($available_groups[$_REQUEST['groupid']])) {
    access_deny();
}
if (isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0 && !isset($available_hosts[$_REQUEST['hostid']])) {
    access_deny();
}
if (isset($_REQUEST['apphostid']) && $_REQUEST['apphostid'] > 0 && !isset($available_hosts[$_REQUEST['apphostid']])) {
    access_deny();
}
//		VAR			TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array('config' => array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), 'hosts' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'groups' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'hostids' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'groupids' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'applications' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, NULL), 'groupid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({form})&&({form}=="update")'), 'hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({form})&&({form}=="update")'), 'host' => array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, 'isset({save})&&!isset({massupdate})'), 'proxy_hostid' => array(T_ZBX_INT, O_OPT, P_SYS, DB_ID, 'isset({save})&&!isset({massupdate})'), 'dns' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({save})&&!isset({massupdate})'), 'useip' => array(T_ZBX_STR, O_OPT, NULL, IN('0,1'), 'isset({save})&&!isset({massupdate})'), 'ip' => array(T_ZBX_IP, O_OPT, NULL, NULL, 'isset({save})&&!isset({massupdate})'), 'port' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), 'isset({save})&&!isset({massupdate})'), 'status' => array(T_ZBX_INT, O_OPT, NULL, IN('0,1,3'), 'isset({save})&&!isset({massupdate})'), 'newgroup' => array(T_ZBX_STR, O_OPT, NULL, NULL, NULL), 'templates' => array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY, NULL), 'clear_templates' => array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), 'useipmi' => array(T_ZBX_STR, O_OPT, NULL, NULL, NULL), 'ipmi_ip' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useipmi})&&!isset({massupdate})'), 'ipmi_port' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), 'isset({useipmi})&&!isset({massupdate})'), 'ipmi_authtype' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(-1, 6), 'isset({useipmi})&&!isset({massupdate})'), 'ipmi_privilege' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(1, 5), 'isset({useipmi})&&!isset({massupdate})'), 'ipmi_username' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useipmi})&&!isset({massupdate})'), 'ipmi_password' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useipmi})&&!isset({massupdate})'), 'useprofile' => array(T_ZBX_STR, O_OPT, NULL, NULL, NULL), 'devicetype' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'name' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'os' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'serialno' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'tag' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'macaddress' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'hardware' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'software' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'contact' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'location' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'notes' => array(T_ZBX_STR, O_OPT, NULL, NULL, 'isset({useprofile})&&!isset({massupdate})'), 'useprofile_ext' => array(T_ZBX_STR, O_OPT, NULL, NULL, NULL), 'ext_host_profiles' => array(T_ZBX_STR, O_OPT, P_UNSET_EMPTY, NULL, NULL), 'massupdate' => array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), 'visible' => array(T_ZBX_STR, O_OPT, null, null, null), 'go' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'add_to_group' => array(T_ZBX_INT, O_OPT, P_SYS | P_ACT, DB_ID, NULL), 'delete_from_group' => array(T_ZBX_INT, O_OPT, P_SYS | P_ACT, DB_ID, NULL), 'unlink' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'unlink_and_clear' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'save' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'clone' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'full_clone' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'delete' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'delete_and_clear' => array(T_ZBX_STR, O_OPT, P_SYS | P_ACT, NULL, NULL), 'cancel' => array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), 'form' => array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL), 'form_refresh' => array(T_ZBX_STR, O_OPT, NULL, NULL, NULL));
check_fields($fields);
validate_sort_and_sortorder('h.host', ZBX_SORT_UP);
$_REQUEST['go'] = get_request('go', 'none');
/************ ACTIONS FOR HOSTS ****************/
Esempio n. 16
0
function validate_operation($operation)
{
    global $USER_DETAILS;
    switch ($operation['operationtype']) {
        case OPERATION_TYPE_MESSAGE:
            switch ($operation['object']) {
                case OPERATION_OBJECT_USER:
                    if (!get_user_by_userid($operation['objectid'])) {
                        error(S_INCORRECT_USER);
                        return false;
                    }
                    break;
                case OPERATION_OBJECT_GROUP:
                    if (!get_group_by_usrgrpid($operation['objectid'])) {
                        error(S_INCORRECT_GROUP);
                        return false;
                    }
                    break;
                default:
                    error(S_INCORRECT_OBJECT_TYPE);
                    return false;
            }
            break;
        case OPERATION_TYPE_COMMAND:
            return validate_commands($operation['longdata']);
        case OPERATION_TYPE_HOST_ADD:
        case OPERATION_TYPE_HOST_REMOVE:
            break;
        case OPERATION_TYPE_GROUP_ADD:
        case OPERATION_TYPE_GROUP_REMOVE:
            if (!uint_in_array($operation['objectid'], get_accessible_groups_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) {
                error(S_INCORRECT_GROUP);
                return false;
            }
            break;
        case OPERATION_TYPE_TEMPLATE_ADD:
        case OPERATION_TYPE_TEMPLATE_REMOVE:
            if (!uint_in_array($operation['objectid'], get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE, PERM_RES_IDS_ARRAY))) {
                error(S_INCORRECT_HOST);
                return false;
            }
            break;
        default:
            error(S_INCORRECT_OPERATION_TYPE);
            return false;
    }
    return true;
}
Esempio n. 17
0
                        if (inarr_isset(array('edit_timeperiodid'))) {
                            $_REQUEST['edit_timeperiodid'] = array_keys($_REQUEST['edit_timeperiodid']);
                            $edit_timeperiodid = $_REQUEST['edit_timeperiodid'] = array_pop($_REQUEST['edit_timeperiodid']);
                            $_REQUEST['timeperiods'] = get_request('timeperiods', array());
                            if (isset($_REQUEST['timeperiods'][$edit_timeperiodid])) {
                                $_REQUEST['new_timeperiod'] = $_REQUEST['timeperiods'][$edit_timeperiodid];
                                $_REQUEST['new_timeperiod']['id'] = $edit_timeperiodid;
                            }
                        }
                    }
                }
            }
        }
    }
}
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE, null, null, AVAILABLE_NOCACHE);
/* update available_hosts after ACTIONS */
$params = array('only_current_node' => 1);
$PAGE_GROUPS = get_viewed_groups(PERM_READ_ONLY, $params);
$PAGE_HOSTS = get_viewed_hosts(PERM_READ_ONLY, $PAGE_GROUPS['selected'], $params);
validate_group_with_host($PAGE_GROUPS, $PAGE_HOSTS, true);
$available_groups = $PAGE_GROUPS['groupids'];
$available_hosts = $PAGE_HOSTS['hostids'];
$frmForm = new CForm();
$frmForm->setMethod('get');
if (!isset($_REQUEST['form'])) {
    $frmForm->addItem(new CButton('form', S_CREATE_MAINTENANCE_PERIOD));
}
show_table_header(S_CONFIGURATION_OF_MAINTENANCE_PERIODS, $frmForm);
$row_count = 0;
if (isset($_REQUEST["form"])) {
Esempio n. 18
0
function get_accessible_scripts_by_hosts($hosts)
{
    global $USER_DETAILS;
    if (!is_array($hosts)) {
        $hosts = array('0' => hosts);
    }
    // Selecting usrgroups by user
    $sql = 'SELECT ug.usrgrpid ' . ' FROM users_groups ug ' . ' WHERE ug.userid=' . $USER_DETAILS['userid'];
    $user_groups = DBfetch(DBselect($sql));
    $user_groups[] = 0;
    // to ALL user groups
    // --
    // Selecting groups by Hosts
    $sql = 'SELECT hg.hostid,hg.groupid ' . ' FROM hosts_groups hg ' . ' WHERE ' . DBcondition('hg.hostid', $hosts);
    $hg_res = DBselect($sql);
    while ($hg_rows = DBfetch($hg_res)) {
        $hosts_groups[$hg_rows['groupid']][$hg_rows['hostid']] = $hg_rows['hostid'];
        $hg_groups[$hg_rows['groupid']] = $hg_rows['groupid'];
    }
    $hg_groups[] = 0;
    // to ALL host groups
    // --
    $hosts_read_only = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
    $hosts_read_write = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_WRITE);
    $hosts_read_only = zbx_uint_array_intersect($hosts, $hosts_read_only);
    $hosts_read_write = zbx_uint_array_intersect($hosts, $hosts_read_write);
    $scripts_by_host = array();
    // initialize array
    foreach ($hosts as $id => $hostid) {
        $scripts_by_host[$hostid] = array();
    }
    //-----
    $sql = 'SELECT s.* ' . ' FROM scripts s ' . ' WHERE ' . DBin_node('s.scriptid') . ' AND ' . DBcondition('s.groupid', $hg_groups) . ' AND ' . DBcondition('s.usrgrpid', $user_groups) . ' ORDER BY scriptid ASC';
    $res = DBselect($sql);
    while ($script = DBfetch($res)) {
        $add_to_hosts = array();
        if (PERM_READ_WRITE == $script['host_access']) {
            if ($script['groupid'] > 0) {
                $add_to_hosts = zbx_uint_array_intersect($hosts_read_write, $hosts_groups[$script['groupid']]);
            } else {
                $add_to_hosts = $hosts_read_write;
            }
        } else {
            if (PERM_READ_ONLY == $script['host_access']) {
                if ($script['groupid'] > 0) {
                    $add_to_hosts = zbx_uint_array_intersect($hosts_read_only, $hosts_groups[$script['groupid']]);
                } else {
                    $add_to_hosts = $hosts_read_only;
                }
            }
        }
        foreach ($add_to_hosts as $id => $hostid) {
            $scripts_by_host[$hostid][] = $script;
        }
    }
    //SDI($scripts_by_host);
    return $scripts_by_host;
}
Esempio n. 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);
            }
        }
    }
}
Esempio n. 20
0
function insert_map_element_form()
{
    global $USER_DETAILS;
    $frmEl = new CFormTable('New map element', 'sysmap.php');
    $frmEl->SetHelp('web.sysmap.host.php');
    $frmEl->addVar('sysmapid', $_REQUEST['sysmapid']);
    if (isset($_REQUEST['selementid'])) {
        $frmEl->addVar('selementid', $_REQUEST['selementid']);
        $element = get_sysmaps_element_by_selementid($_REQUEST['selementid']);
        $frmEl->SetTitle('Map element "' . $element['label'] . '"');
    }
    if (isset($_REQUEST['selementid']) && !isset($_REQUEST['form_refresh'])) {
        $elementid = $element['elementid'];
        $elementtype = $element['elementtype'];
        $label = $element['label'];
        $x = $element['x'];
        $y = $element['y'];
        $url = $element['url'];
        $iconid_off = $element['iconid_off'];
        $iconid_on = $element['iconid_on'];
        $iconid_unknown = $element['iconid_unknown'];
        $iconid_disabled = $element['iconid_disabled'];
        $label_location = $element['label_location'];
        if (is_null($label_location)) {
            $label_location = -1;
        }
    } else {
        $elementid = get_request('elementid', 0);
        $elementtype = get_request('elementtype', SYSMAP_ELEMENT_TYPE_HOST);
        $label = get_request('label', '');
        $x = get_request('x', 0);
        $y = get_request('y', 0);
        $url = get_request('url', '');
        $iconid_off = get_request('iconid_off', 0);
        $iconid_on = get_request('iconid_on', 0);
        $iconid_unknown = get_request('iconid_unknown', 0);
        $iconid_disabled = get_request('iconid_disabled', 0);
        $label_location = get_request('label_location', '-1');
    }
    $cmbType = new CComboBox('elementtype', $elementtype, 'submit()');
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, null, get_current_nodeid(true));
    $sql = 'SELECT DISTINCT n.name as node_name,h.hostid,h.host ' . ' FROM hosts h' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('h.hostid') . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . ' ORDER BY node_name,h.host';
    $db_hosts = DBselect($sql);
    if ($db_hosts) {
        $cmbType->addItem(SYSMAP_ELEMENT_TYPE_HOST, S_HOST);
    }
    $db_maps = DBselect('SELECT sysmapid FROM sysmaps WHERE sysmapid!=' . $_REQUEST['sysmapid']);
    if (DBfetch($db_maps)) {
        $cmbType->addItem(SYSMAP_ELEMENT_TYPE_MAP, S_MAP);
    }
    $cmbType->addItem(SYSMAP_ELEMENT_TYPE_TRIGGER, S_TRIGGER);
    $cmbType->addItem(SYSMAP_ELEMENT_TYPE_HOST_GROUP, S_HOST_GROUP);
    $cmbType->addItem(SYSMAP_ELEMENT_TYPE_IMAGE, S_IMAGE);
    $frmEl->addRow(S_TYPE, $cmbType);
    $frmEl->addRow(S_LABEL, new CTextArea('label', $label, 32, 4));
    $cmbLocation = new CComboBox('label_location', $label_location);
    $cmbLocation->addItem(-1, '-');
    $cmbLocation->addItem(0, S_BOTTOM);
    $cmbLocation->addItem(1, S_LEFT);
    $cmbLocation->addItem(2, S_RIGHT);
    $cmbLocation->addItem(3, S_TOP);
    $frmEl->addRow(S_LABEL_LOCATION, $cmbLocation);
    if ($elementtype == SYSMAP_ELEMENT_TYPE_HOST) {
        $host = '';
        $host_info = DBfetch(DBselect('SELECT DISTINCT n.name as node_name,h.hostid,h.host ' . ' FROM hosts h ' . ' LEFT JOIN nodes n ON n.nodeid=' . DBid2nodeid('h.hostid') . ' WHERE ' . DBcondition('h.hostid', $available_hosts) . ' AND hostid=' . $elementid . ' ORDER BY node_name,h.host'));
        if ($host_info) {
            $host = $host_info['host'];
        } else {
            $elementid = 0;
        }
        if ($elementid == 0) {
            $host = '';
            $elementid = 0;
        }
        $frmEl->addVar('elementid', $elementid);
        $frmEl->addRow(S_HOST, array(new CTextBox('host', $host, 32, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . $frmEl->GetName() . "&dstfld1=elementid&dstfld2=host&srctbl=hosts&srcfld1=hostid&srcfld2=host',450,450);", 'T')));
    } else {
        if ($elementtype == SYSMAP_ELEMENT_TYPE_MAP) {
            $cmbMaps = new CComboBox('elementid', $elementid);
            $db_maps = DBselect('SELECT DISTINCT n.name as node_name,s.sysmapid,s.name ' . ' FROM sysmaps s' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('s.sysmapid') . ' ORDER BY node_name,s.name');
            while ($db_map = DBfetch($db_maps)) {
                if (!sysmap_accessible($db_map['sysmapid'], PERM_READ_ONLY)) {
                    continue;
                }
                $node_name = isset($db_map['node_name']) ? '(' . $db_map['node_name'] . ') ' : '';
                $cmbMaps->addItem($db_map['sysmapid'], $node_name . $db_map['name']);
            }
            $frmEl->addRow(S_MAP, $cmbMaps);
        } else {
            if ($elementtype == SYSMAP_ELEMENT_TYPE_TRIGGER) {
                $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_IDS_ARRAY, get_current_nodeid(true));
                $trigger = '';
                $trigger_info = DBfetch(DBselect('SELECT DISTINCT n.name as node_name,h.hostid,h.host,t.*' . ' FROM triggers t ' . ' LEFT JOIN functions f on t.triggerid=f.triggerid ' . ' LEFT JOIN items i on i.itemid=f.itemid ' . ' LEFT JOIN hosts h on h.hostid=i.hostid ' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('t.triggerid') . ' WHERE t.triggerid=' . $elementid . ' AND ' . DBcondition('t.triggerid', $available_triggers) . ' ORDER BY node_name,h.host,t.description'));
                if ($trigger_info) {
                    $trigger = expand_trigger_description_by_data($trigger_info);
                } else {
                    $elementid = 0;
                }
                if ($elementid == 0) {
                    $trigger = '';
                    $elementid = 0;
                }
                $frmEl->addVar('elementid', $elementid);
                $frmEl->addRow(S_TRIGGER, array(new CTextBox('trigger', $trigger, 32, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . $frmEl->GetName() . "&dstfld1=elementid&dstfld2=trigger&srctbl=triggers&srcfld1=triggerid&srcfld2=description');", 'T')));
            } else {
                if ($elementtype == SYSMAP_ELEMENT_TYPE_HOST_GROUP) {
                    $available_groups = get_accessible_groups_by_user($USER_DETAILS, PERM_READ_ONLY, null, get_current_nodeid(true));
                    $group = '';
                    $group_info = DBfetch(DBselect('SELECT DISTINCT n.name as node_name,g.groupid,g.name ' . ' FROM groups g ' . ' LEFT JOIN nodes n on n.nodeid=' . DBid2nodeid('g.groupid') . ' WHERE ' . DBcondition('g.groupid', $available_groups) . ' AND g.groupid=' . $elementid . ' ORDER BY node_name,g.name'));
                    if ($group_info) {
                        $group = $group_info['name'];
                    } else {
                        $elementid = 0;
                    }
                    if ($elementid == 0) {
                        $group = '';
                        $elementid = 0;
                    }
                    $frmEl->addVar('elementid', $elementid);
                    $frmEl->addRow(S_HOST_GROUP, array(new CTextBox('group', $group, 32, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . $frmEl->GetName() . "&dstfld1=elementid&dstfld2=group&srctbl=host_group&srcfld1=groupid&srcfld2=name',450,450);", 'T')));
                } else {
                    if ($elementtype == SYSMAP_ELEMENT_TYPE_IMAGE) {
                        $frmEl->addVar('elementid', 0);
                    }
                }
            }
        }
    }
    $cmbIconOff = new CComboBox('iconid_off', $iconid_off);
    $cmbIconOn = new CComboBox('iconid_on', $iconid_on);
    if ($elementtype != SYSMAP_ELEMENT_TYPE_MAP) {
        $cmbIconUnknown = new CComboBox('iconid_unknown', $iconid_unknown);
    }
    if ($elementtype != SYSMAP_ELEMENT_TYPE_HOST_GROUP && $elementtype != SYSMAP_ELEMENT_TYPE_MAP) {
        $cmbIconDisabled = new CComboBox('iconid_disabled', $iconid_disabled);
    }
    $result = DBselect('SELECT * FROM images WHERE imagetype=1 AND ' . DBin_node('imageid') . ' order by name');
    while ($row = DBfetch($result)) {
        $row['name'] = get_node_name_by_elid($row['imageid']) . $row['name'];
        $cmbIconOff->addItem($row['imageid'], $row['name']);
        $cmbIconOn->addItem($row['imageid'], $row['name']);
        if ($elementtype != SYSMAP_ELEMENT_TYPE_MAP) {
            $cmbIconUnknown->addItem($row['imageid'], $row['name']);
        }
        if ($elementtype != SYSMAP_ELEMENT_TYPE_HOST_GROUP && $elementtype != SYSMAP_ELEMENT_TYPE_MAP) {
            $cmbIconDisabled->addItem($row['imageid'], $row['name']);
        }
    }
    $frmEl->addRow(S_ICON_OK, $cmbIconOff);
    if ($elementtype != SYSMAP_ELEMENT_TYPE_IMAGE) {
        $frmEl->addRow(S_ICON_PROBLEM, $cmbIconOn);
    } else {
        $frmEl->addVar('iconid_on', 0);
    }
    if ($elementtype != SYSMAP_ELEMENT_TYPE_MAP && $elementtype != SYSMAP_ELEMENT_TYPE_IMAGE) {
        $frmEl->addRow(S_ICON_UNKNOWN, $cmbIconUnknown);
    } else {
        $frmEl->addVar('iconid_unknown', 0);
    }
    if ($elementtype != SYSMAP_ELEMENT_TYPE_HOST_GROUP && $elementtype != SYSMAP_ELEMENT_TYPE_MAP && $elementtype != SYSMAP_ELEMENT_TYPE_IMAGE) {
        $frmEl->addRow(S_ICON_DISABLED, $cmbIconDisabled);
    } else {
        $frmEl->addVar('iconid_disabled', 0);
    }
    $frmEl->addRow(S_COORDINATE_X, new CNumericBox('x', $x, 5));
    $frmEl->addRow(S_COORDINATE_Y, new CNumericBox('y', $y, 5));
    $frmEl->addRow(S_URL, new CTextBox('url', $url, 64));
    $frmEl->addItemToBottomRow(new CButton('save', S_SAVE));
    if (isset($_REQUEST['selementid'])) {
        $frmEl->addItemToBottomRow(SPACE);
        $frmEl->addItemToBottomRow(new CButtonDelete('Delete element?', url_param('form') . url_param('selementid') . url_param('sysmapid')));
    }
    $frmEl->addItemToBottomRow(SPACE);
    $frmEl->addItemToBottomRow(new CButtonCancel(url_param('sysmapid')));
    $frmEl->Show();
}
Esempio n. 21
0
** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
**/
require_once 'include/config.inc.php';
require_once 'include/graphs.inc.php';
$page['file'] = 'chart7.php';
$page['title'] = "S_CHART";
$page['type'] = PAGE_TYPE_IMAGE;
include_once 'include/page_header.php';
//		VAR			TYPE	OPTIONAL FLAGS	VALIDATION	EXCEPTION
$fields = array('period' => array(T_ZBX_INT, O_OPT, P_NZERO, BETWEEN(ZBX_MIN_PERIOD, ZBX_MAX_PERIOD), null), 'from' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'stime' => array(T_ZBX_INT, O_OPT, P_NZERO, null, null), 'border' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'name' => array(T_ZBX_STR, O_OPT, NULL, null, null), 'width' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), null), 'height' => array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0, 65535), null), 'graphtype' => array(T_ZBX_INT, O_OPT, NULL, IN('2,3'), null), 'graph3d' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'legend' => array(T_ZBX_INT, O_OPT, P_NZERO, IN('0,1'), null), 'items' => array(T_ZBX_STR, O_OPT, NULL, null, null));
check_fields($fields);
$available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_RES_IDS_ARRAY, get_current_nodeid(true));
$items = get_request('items', array());
asort_by_key($items, 'sortorder');
foreach ($items as $gitem) {
    if (!($host = DBfetch(DBselect('SELECT h.* FROM hosts h,items i WHERE h.hostid=i.hostid AND i.itemid=' . $gitem['itemid'])))) {
        fatal_error(S_NO_ITEM_DEFINED);
    }
    if (!isset($available_hosts[$host['hostid']])) {
        access_deny();
    }
}
$effectiveperiod = navigation_bar_calc();
if (count($items) == 1) {
    $_REQUEST['period'] = get_request('period', get_profile('web.item.graph.period', ZBX_PERIOD_DEFAULT, null, $items['itemid']));
    if ($_REQUEST['period'] >= ZBX_MIN_PERIOD) {
        update_profile('web.item.graph.period', $_REQUEST['period'], PROFILE_TYPE_INT, $items['itemid']);
Esempio n. 22
0
function get_history_of_triggers_events($start, $num, $groupid = 0, $hostid = 0)
{
    global $USER_DETAILS;
    $config = select_config();
    $show_unknown = get_profile('web.events.filter.show_unknown', 0);
    $sql_from = $sql_cond = '';
    $available_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_LIST);
    $available_triggers = get_accessible_triggers(PERM_READ_ONLY, array(), PERM_RES_DATA_ARRAY, get_current_nodeid());
    if ($hostid > 0) {
        $sql_cond = ' AND h.hostid=' . $hostid;
    } else {
        if ($groupid > 0) {
            $sql_from = ', hosts_groups hg ';
            $sql_cond = ' AND h.hostid=hg.hostid AND hg.groupid=' . $groupid;
        } else {
            $sql_from = '';
            $sql_cond = ' AND ' . DBcondition('h.hostid', $available_hosts);
        }
    }
    //---
    $triggers = array();
    $trigger_list = array();
    $sql = 'SELECT DISTINCT t.triggerid,t.priority,t.description,t.expression,h.host,t.type ' . ' FROM triggers t, functions f, items i, hosts h ' . $sql_from . ' WHERE ' . DBcondition('t.triggerid', $available_triggers) . ' AND t.triggerid=f.triggerid ' . ' AND f.itemid=i.itemid ' . ' AND i.hostid=h.hostid ' . ' AND h.status=' . HOST_STATUS_MONITORED . $sql_cond;
    $rez = DBselect($sql);
    while ($rowz = DBfetch($rez)) {
        $triggers[$rowz['triggerid']] = $rowz;
        array_push($trigger_list, $rowz['triggerid']);
    }
    $sql_cond = $show_unknown == 0 ? ' AND e.value<>' . TRIGGER_VALUE_UNKNOWN . ' ' : '';
    $table = new CTableInfo(S_NO_EVENTS_FOUND);
    $table->SetHeader(array(S_TIME, is_show_all_nodes() ? S_NODE : null, $hostid == 0 ? S_HOST : null, S_DESCRIPTION, S_VALUE, S_SEVERITY));
    if (!empty($triggers)) {
        $sql = 'SELECT e.eventid, e.objectid as triggerid, e.clock, e.value, e.acknowledged ' . ' FROM events e ' . ' WHERE e.object=' . EVENT_OBJECT_TRIGGER . ' AND ' . DBcondition('e.objectid', $trigger_list) . $sql_cond . ' ORDER BY e.eventid DESC';
        $result = DBselect($sql, 10 * ($start + $num));
    }
    $col = 0;
    $skip = $start;
    while (!empty($triggers) && $col < $num && ($row = DBfetch($result))) {
        if ($skip > 0) {
            if ($show_unknown == 0 && $row['value'] == TRIGGER_VALUE_UNKNOWN) {
                continue;
            }
            $skip--;
            continue;
        }
        $value = new CCol(trigger_value2str($row['value']), get_trigger_value_style($row['value']));
        $row = array_merge($triggers[$row['triggerid']], $row);
        if (0 == $show_unknown && !event_initial_time($row, $show_unknown)) {
            continue;
        }
        $table->AddRow(array(date("Y.M.d H:i:s", $row["clock"]), get_node_name_by_elid($row['triggerid']), $hostid == 0 ? $row['host'] : null, new CLink(expand_trigger_description_by_data($row, ZBX_FLAG_EVENT), 'tr_events.php?triggerid=' . $row['triggerid'] . '&eventid=' . $row['eventid'], 'action'), $value, new CCol(get_severity_description($row["priority"]), get_severity_style($row["priority"]))));
        $col++;
    }
    return $table;
}