$tr++; $row->addItem(SPACE); } $table->addRow($row); } $cnf_wdgt->addItem($table); } } else { if ($_REQUEST['config'] == 5) { // Other parameters $frmOther = new CFormTable(S_OTHER_PARAMETERS, 'config.php'); $frmOther->setHelp('web.config.other.php'); $frmOther->addVar('config', get_request('config', 5)); $frmOther->addRow(S_REFRESH_UNSUPPORTED_ITEMS, new CNumericBox('refresh_unsupported', $config['refresh_unsupported'], 5)); $cmbGrp = new CComboBox('discovery_groupid', $config['discovery_groupid']); $groups = CHostGroup::get(array('sortfield' => 'name', 'editable' => 1, 'extendoutput' => 1)); foreach ($groups as $gnum => $group) { $cmbGrp->addItem($group['groupid'], $group['name']); } $frmOther->addRow(S_GROUP_FOR_DISCOVERED_HOSTS, $cmbGrp); $cmbUsrGrp = new CComboBox('alert_usrgrpid', $config['alert_usrgrpid']); $cmbUsrGrp->addItem(0, S_NONE); $result = DBselect('SELECT usrgrpid,name FROM usrgrp' . ' WHERE ' . DBin_node('usrgrpid') . ' order by name'); while ($row = DBfetch($result)) { $cmbUsrGrp->addItem($row['usrgrpid'], get_node_name_by_elid($row['usrgrpid'], null, ': ') . $row['name']); } $frmOther->addRow(S_USER_GROUP_FOR_DATABASE_DOWN_MESSAGE, $cmbUsrGrp); $frmOther->addItemToBottomRow(new CButton('save', S_SAVE)); $cnf_wdgt->addItem($frmOther); } elseif ($_REQUEST['config'] == 6) { // Value Mapping
$frmHostG->addItemToBottomRow($dltButton); } $frmHostG->addItemToBottomRow(SPACE); $frmHostG->addItemToBottomRow(new CButtonCancel(url_param('config'))); $frmHostG->show(); } else { $config = select_config(); $numrows = new CSpan(null, 'info'); $numrows->setAttribute('name', 'numrows'); $header = get_table_header(array(S_HOST_GROUPS_BIG, new CSpan(SPACE . SPACE . '|' . SPACE . SPACE, 'divider'), S_FOUND . ': ', $numrows)); show_table_header($header); $form = new CForm('hostgroups.php'); $form->setName('form_groups'); $table = new CTableInfo(S_NO_HOST_GROUPS_DEFINED); $table->setHeader(array(new CCheckBox('all_groups', NULL, "checkAll('" . $form->GetName() . "','all_groups','groups');"), make_sorting_link(S_NAME, 'g.name'), ' # ', S_MEMBERS)); $groups = CHostGroup::get(array('order' => 'name', 'editable' => 1, 'extendoutput' => 1, 'select_hosts' => 1)); foreach ($groups as $groupid => $group) { $tpl_count = 0; $host_count = 0; $i = 0; $hosts_output = array(); foreach ($group['hosts'] as $hostid => $host) { $i++; if ($i > $config['max_in_table']) { $hosts_output[] = '...'; $hosts_output[] = '//empty for array_pop'; break; } switch ($host['status']) { case HOST_STATUS_NOT_MONITORED: $style = 'on';
} else { $cbFilter = new CSpan(S_DISABLED, 'red underline pointer'); $cbFilter->setAttribute('onclick', "\$('dashform').enable(); create_var('" . $dashForm->getName() . "', 'filterEnable', 1, true);"); } $dashForm->addRow(S_DASHBOARD_FILTER, $cbFilter); $dashForm->addVar('groupids', $groupids); $cmbGroups = new CComboBox('grpswitch', $grpswitch, 'submit();'); $cmbGroups->addItem(0, S_ALL_S); $cmbGroups->addItem(1, S_SELECTED); if (!$filterEnable) { $cmbGroups->setAttribute('disabled', 'disabled'); } $dashForm->addRow(S_HOST_GROUPS, $cmbGroups); if ($grpswitch == 1) { $options = array('nodeids' => get_current_nodeid(true), 'groupids' => $groupids, 'output' => API_OUTPUT_EXTEND); $groups = CHostGroup::get($options); order_result($groups, 'name'); $lstGroups = new CListBox('del_groups[]', null, 15); $lstGroups->setAttribute('style', 'width: 200px;'); foreach ($groups as $gnum => $group) { $lstGroups->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], true, ':') . $group['name']); } if (!$filterEnable) { $lstGroups->setAttribute('disabled', 'disabled'); } $addButton = new CButton('add', S_ADD, "return PopUp('popup_right.php?dstfrm=" . $dashForm->getName() . "&permission=" . PERM_READ_WRITE . "',450,450);"); if (!$filterEnable) { $addButton->setAttribute('disabled', 'disabled'); } $delButton = new CButton('delete', S_DELETE_SELECTED); if (!$filterEnable) {
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; }
$wdgt_hosts = new CWidget('search_hosts', $table); $wdgt_hosts->setClass('header'); $wdgt_hosts->addHeader(S_HOSTS, SPACE); $left_tab->addRow($wdgt_hosts); //---------------- // Find Host groups $params = array('nodeids' => get_current_nodeid(true), 'output' => API_OUTPUT_EXTEND, 'search' => array('name' => $search), 'limit' => $rows_per_page); $db_hostGroups = CHostGroup::get($params); order_result($db_hostGroups, 'name'); $hostGroups = selectByPattern($db_hostGroups, 'name', $search, $rows_per_page); $groupids = zbx_objectValues($hostGroups, 'groupid'); $params = array('nodeids' => get_current_nodeid(true), 'groupids' => $groupids, 'editable' => 1); $rw_hostGroups = CHostGroup::get($params); $rw_hostGroups = zbx_toHash($rw_hostGroups, 'groupid'); $params = array('nodeids' => get_current_nodeid(true), 'search' => array('name' => $search), 'countOutput' => 1); $overalCount = CHostGroup::get($params); $viewCount = count($hostGroups); $header = array(ZBX_DISTRIBUTED ? new CCol(S_NODE) : null, new CCol(S_HOST_GROUP), new CCol(S_LATEST_DATA), new CCol(S_TRIGGERS), new CCol(S_EVENTS), $admin ? new CCol(S_EDIT_HOSTS) : null); $table = new CTableInfo(); $table->setHeader($header); foreach ($hostGroups as $hnum => $group) { $hostgroupid = $group['groupid']; $caption = make_decoration($group['name'], $search); $link = 'groupid=' . $hostgroupid . '&hostid=0&switch_node=' . id2nodeid($hostgroupid); if ($admin) { if (isset($rw_hostGroups[$hostgroupid])) { $admin_link = new CLink(S_EDIT_HOSTS, 'hosts.php?config=1&groupid=' . $hostgroupid . '&hostid=0' . '&switch_node=' . id2nodeid($hostgroupid)); $hgroup_link = new CLink($caption, 'hostgroups.php?form=update&' . $link); } else { $admin_link = new CSpan(S_EDIT_HOSTS, 'unknown'); $hgroup_link = new CSpan($caption);
if ($_REQUEST['go'] == 'delete' && isset($_REQUEST['group_graphid'])) { $go_result = CGraph::delete($_REQUEST['group_graphid']); show_messages($go_result, S_GRAPHS_DELETED, S_CANNOT_DELETE_GRAPHS); } else { if ($_REQUEST['go'] == 'copy_to' && isset($_REQUEST['copy']) && isset($_REQUEST['group_graphid'])) { if (isset($_REQUEST['copy_targetid']) && $_REQUEST['copy_targetid'] > 0 && isset($_REQUEST['copy_type'])) { $go_result = true; $options = array('editable' => 1, 'nodes' => get_current_nodeid(true), 'templated_hosts' => 1); if (0 == $_REQUEST['copy_type']) { // hosts $options['hostids'] = $_REQUEST['copy_targetid']; } else { // groups zbx_value2array($_REQUEST['copy_targetid']); $opt = array('groupids' => $_REQUEST['copy_targetid'], 'editable' => 1, 'nodes' => get_current_nodeid(true)); $db_groups = CHostGroup::get($opt); $db_groups = zbx_toHash($db_groups, 'groupid'); foreach ($_REQUEST['copy_targetid'] as $gnum => $groupid) { if (!isset($db_groups[$groupid])) { access_deny(); } } $options['groupids'] = $_REQUEST['copy_targetid']; } $db_hosts = CHost::get($options); DBstart(); foreach ($_REQUEST['group_graphid'] as $gnum => $graph_id) { foreach ($db_hosts as $hnum => $host) { $go_result &= (bool) copy_graph_to_host($graph_id, $host['hostid'], true); } }
$options = array('output' => API_OUTPUT_EXTEND, 'real_hosts' => 1, 'editable' => 1, 'hostids' => $hostids); $hosts_selected = CHost::get($options); $hosts = array_merge($hosts, $hosts_selected); $hosts = zbx_toHash($hosts, 'hostid'); order_result($hosts, 'host'); foreach ($hosts as $host) { $host_tb->addItem($host['hostid'], $host['host']); } $tblHlink = new CTable(null, 'formElementTable'); $tblHlink->addRow($host_tb->Get(S_IN . SPACE . S_MAINTENANCE, array(S_OTHER . SPACE . S_HOSTS . SPACE . '|' . SPACE . S_GROUP . SPACE, $cmbGroups))); $right_tab->addRow(new CFormElement(S_HOSTS_IN_MAINTENANCE, $tblHlink)); // }}} MAINTENANCE HOSTS // MAINTENANCE GROUPS {{{ $tblGlink = new CTable(null, 'formElementTable'); if (isset($_REQUEST['maintenanceid']) && !isset($_REQUEST['form_refresh'])) { $groupids = CHostGroup::get(array('maintenanceids' => $_REQUEST['maintenanceid'], 'real_hosts' => 1, 'output' => API_OUTPUT_SHORTEN, 'editable' => 1)); $groupids = zbx_objectValues($groupids, 'groupid'); } else { $groupids = get_request('groupids', array()); } $group_tb = new CTweenBox($frmMaintenance, 'groupids', $groupids, 10); foreach ($all_groups as $group) { $group_tb->addItem($group['groupid'], $group['name']); } $tblGlink->addRow($group_tb->Get(S_IN . SPACE . S_MAINTENANCE, S_OTHER . SPACE . S_GROUPS)); $right_tab->addRow(new CFormElement(S_GROUPS_IN_MAINTENANCE, $tblGlink)); // }}} MAINTENANCE GROUPS $td_l = new CCol($left_tab); $td_l->setAttribute('valign', 'top'); $td_r = new CCol($right_tab); $td_r->setAttribute('valign', 'top');
$frmHouseKeep->SetHelp("web.config.housekeeper.php"); $frmHouseKeep->addVar("config", get_request("config", 0)); $frmHouseKeep->addRow(S_DO_NOT_KEEP_ACTIONS_OLDER_THAN, new CNumericBox("alert_history", $config["alert_history"], 5)); $frmHouseKeep->addRow(S_DO_NOT_KEEP_EVENTS_OLDER_THAN, new CNumericBox("event_history", $config["event_history"], 5)); $frmHouseKeep->addItemToBottomRow(new CButton("save", S_SAVE)); $frmHouseKeep->Show(); } else { if ($_REQUEST['config'] == 5) { // Other parameters echo SBR; $frmOther = new CFormTable(S_OTHER_PARAMETERS, 'config.php'); $frmOther->SetHelp('web.config.other.php'); $frmOther->addVar('config', get_request('config', 5)); $frmOther->addRow(S_REFRESH_UNSUPPORTED_ITEMS, new CNumericBox('refresh_unsupported', $config['refresh_unsupported'], 5)); $cmbGrp = new CComboBox('discovery_groupid', $config['discovery_groupid']); $groups = CHostGroup::get(array('order' => 'name', 'editable' => 1)); foreach ($groups as $groupid => $group) { $cmbGrp->addItem($groupid, $group['name']); } $frmOther->addRow(S_GROUP_FOR_DISCOVERED_HOSTS, $cmbGrp); $cmbUsrGrp = new CComboBox('alert_usrgrpid', $config['alert_usrgrpid']); $cmbUsrGrp->addItem(0, S_NONE); $result = DBselect('SELECT usrgrpid,name FROM usrgrp' . ' WHERE ' . DBin_node('usrgrpid') . ' order by name'); while ($row = DBfetch($result)) { $cmbUsrGrp->addItem($row['usrgrpid'], get_node_name_by_elid($row['usrgrpid']) . $row['name']); } $frmOther->addRow(S_USER_GROUP_FOR_DATABASE_DOWN_MESSAGE, $cmbUsrGrp); $frmOther->addItemToBottomRow(new CButton('save', S_SAVE)); $frmOther->show(); } else { if ($_REQUEST['config'] == 7) {
function insert_host_form() { global $USER_DETAILS; $host_groups = get_request('groups', array()); if (isset($_REQUEST['groupid']) && $_REQUEST['groupid'] > 0 && empty($host_groups)) { array_push($host_groups, $_REQUEST['groupid']); } $newgroup = get_request('newgroup', ''); $host = get_request('host', ''); $port = get_request('port', CProfile::get('HOST_PORT', 10050)); $status = get_request('status', HOST_STATUS_MONITORED); $useip = get_request('useip', 1); $dns = get_request('dns', ''); $ip = get_request('ip', '0.0.0.0'); $proxy_hostid = get_request('proxy_hostid', ''); $useipmi = get_request('useipmi', 'no'); $ipmi_ip = get_request('ipmi_ip', ''); $ipmi_port = get_request('ipmi_port', 623); $ipmi_authtype = get_request('ipmi_authtype', -1); $ipmi_privilege = get_request('ipmi_privilege', 2); $ipmi_username = get_request('ipmi_username', ''); $ipmi_password = get_request('ipmi_password', ''); $useprofile = get_request('useprofile', 'no'); $devicetype = get_request('devicetype', ''); $name = get_request('name', ''); $os = get_request('os', ''); $serialno = get_request('serialno', ''); $tag = get_request('tag', ''); $macaddress = get_request('macaddress', ''); $hardware = get_request('hardware', ''); $software = get_request('software', ''); $contact = get_request('contact', ''); $location = get_request('location', ''); $notes = get_request('notes', ''); $_REQUEST['hostid'] = get_request('hostid', 0); // BEGIN: HOSTS PROFILE EXTENDED Section $useprofile_ext = get_request('useprofile_ext', 'no'); $ext_host_profiles = get_request('ext_host_profiles', array()); // END: HOSTS PROFILE EXTENDED Section $templates = get_request('templates', array()); $clear_templates = get_request('clear_templates', array()); $frm_title = S_HOST; if ($_REQUEST['hostid'] > 0) { $db_host = get_host_by_hostid($_REQUEST['hostid']); $frm_title .= SPACE . ' [' . $db_host['host'] . ']'; $original_templates = get_templates_by_hostid($_REQUEST['hostid']); } else { $original_templates = array(); } if ($_REQUEST['hostid'] > 0 && !isset($_REQUEST['form_refresh'])) { $proxy_hostid = $db_host['proxy_hostid']; $host = $db_host['host']; $port = $db_host['port']; $status = $db_host['status']; $useip = $db_host['useip']; $useipmi = $db_host['useipmi'] ? 'yes' : 'no'; $ip = $db_host['ip']; $dns = $db_host['dns']; $ipmi_ip = $db_host['ipmi_ip']; $ipmi_port = $db_host['ipmi_port']; $ipmi_authtype = $db_host['ipmi_authtype']; $ipmi_privilege = $db_host['ipmi_privilege']; $ipmi_username = $db_host['ipmi_username']; $ipmi_password = $db_host['ipmi_password']; // add groups $options = array('hostids' => $_REQUEST['hostid']); $host_groups = CHostGroup::get($options); $host_groups = zbx_objectValues($host_groups, 'groupid'); // read profile $db_profiles = DBselect('SELECT * FROM hosts_profiles WHERE hostid=' . $_REQUEST['hostid']); $useprofile = 'no'; $db_profile = DBfetch($db_profiles); if ($db_profile) { $useprofile = 'yes'; $devicetype = $db_profile['devicetype']; $name = $db_profile['name']; $os = $db_profile['os']; $serialno = $db_profile['serialno']; $tag = $db_profile['tag']; $macaddress = $db_profile['macaddress']; $hardware = $db_profile['hardware']; $software = $db_profile['software']; $contact = $db_profile['contact']; $location = $db_profile['location']; $notes = $db_profile['notes']; } // BEGIN: HOSTS PROFILE EXTENDED Section $useprofile_ext = 'no'; $db_profiles_alt = DBselect('SELECT * FROM hosts_profiles_ext WHERE hostid=' . $_REQUEST['hostid']); if ($ext_host_profiles = DBfetch($db_profiles_alt)) { $useprofile_ext = 'yes'; } else { $ext_host_profiles = array(); } // END: HOSTS PROFILE EXTENDED Section $templates = $original_templates; } $ext_profiles_fields = array('device_alias' => S_DEVICE_ALIAS, 'device_type' => S_DEVICE_TYPE, 'device_chassis' => S_DEVICE_CHASSIS, 'device_os' => S_DEVICE_OS, 'device_os_short' => S_DEVICE_OS_SHORT, 'device_hw_arch' => S_DEVICE_HW_ARCH, 'device_serial' => S_DEVICE_SERIAL, 'device_model' => S_DEVICE_MODEL, 'device_tag' => S_DEVICE_TAG, 'device_vendor' => S_DEVICE_VENDOR, 'device_contract' => S_DEVICE_CONTRACT, 'device_who' => S_DEVICE_WHO, 'device_status' => S_DEVICE_STATUS, 'device_app_01' => S_DEVICE_APP_01, 'device_app_02' => S_DEVICE_APP_02, 'device_app_03' => S_DEVICE_APP_03, 'device_app_04' => S_DEVICE_APP_04, 'device_app_05' => S_DEVICE_APP_05, 'device_url_1' => S_DEVICE_URL_1, 'device_url_2' => S_DEVICE_URL_2, 'device_url_3' => S_DEVICE_URL_3, 'device_networks' => S_DEVICE_NETWORKS, 'device_notes' => S_DEVICE_NOTES, 'device_hardware' => S_DEVICE_HARDWARE, 'device_software' => S_DEVICE_SOFTWARE, 'ip_subnet_mask' => S_IP_SUBNET_MASK, 'ip_router' => S_IP_ROUTER, 'ip_macaddress' => S_IP_MACADDRESS, 'oob_ip' => S_OOB_IP, 'oob_subnet_mask' => S_OOB_SUBNET_MASK, 'oob_router' => S_OOB_ROUTER, 'date_hw_buy' => S_DATE_HW_BUY, 'date_hw_install' => S_DATE_HW_INSTALL, 'date_hw_expiry' => S_DATE_HW_EXPIRY, 'date_hw_decomm' => S_DATE_HW_DECOMM, 'site_street_1' => S_SITE_STREET_1, 'site_street_2' => S_SITE_STREET_2, 'site_street_3' => S_SITE_STREET_3, 'site_city' => S_SITE_CITY, 'site_state' => S_SITE_STATE, 'site_country' => S_SITE_COUNTRY, 'site_zip' => S_SITE_ZIP, 'site_rack' => S_SITE_RACK, 'site_notes' => S_SITE_NOTES, 'poc_1_name' => S_POC_1_NAME, 'poc_1_email' => S_POC_1_EMAIL, 'poc_1_phone_1' => S_POC_1_PHONE_1, 'poc_1_phone_2' => S_POC_1_PHONE_2, 'poc_1_cell' => S_POC_1_CELL, 'poc_1_screen' => S_POC_1_SCREEN, 'poc_1_notes' => S_POC_1_NOTES, 'poc_2_name' => S_POC_2_NAME, 'poc_2_email' => S_POC_2_EMAIL, 'poc_2_phone_1' => S_POC_2_PHONE_1, 'poc_2_phone_2' => S_POC_2_PHONE_2, 'poc_2_cell' => S_POC_2_CELL, 'poc_2_screen' => S_POC_2_SCREEN, 'poc_2_notes' => S_POC_2_NOTES); foreach ($ext_profiles_fields as $field => $caption) { if (!isset($ext_host_profiles[$field])) { $ext_host_profiles[$field] = ''; } } $clear_templates = array_intersect($clear_templates, array_keys($original_templates)); $clear_templates = array_diff($clear_templates, array_keys($templates)); natcasesort($templates); $frmHost = new CForm('hosts.php', 'post'); $frmHost->setName('web.hosts.host.php.'); // $frmHost->setHelp('web.hosts.host.php'); // $frmHost->addVar('config',get_request('config',0)); $frmHost->addVar('form', get_request('form', 1)); $from_rfr = get_request('form_refresh', 0); $frmHost->addVar('form_refresh', $from_rfr + 1); $frmHost->addVar('clear_templates', $clear_templates); // HOST WIDGET { $host_tbl = new CTable('', 'tablestripped'); $host_tbl->setOddRowClass('form_odd_row'); $host_tbl->setEvenRowClass('form_even_row'); if ($_REQUEST['hostid'] > 0) { $frmHost->addVar('hostid', $_REQUEST['hostid']); } if ($_REQUEST['groupid'] > 0) { $frmHost->addVar('groupid', $_REQUEST['groupid']); } $host_tbl->addRow(array(S_NAME, new CTextBox('host', $host, 54))); $grp_tb = new CTweenBox($frmHost, 'groups', $host_groups, 10); $all_groups = CHostGroup::get(array('editable' => 1, 'extendoutput' => 1)); order_result($all_groups, 'name'); foreach ($all_groups as $group) { $grp_tb->addItem($group['groupid'], $group['name']); } $host_tbl->addRow(array(S_GROUPS, $grp_tb->get(S_IN_GROUPS, S_OTHER_GROUPS))); $host_tbl->addRow(array(S_NEW_GROUP, new CTextBox('newgroup', $newgroup))); // onchange does not work on some browsers: MacOS, KDE browser $host_tbl->addRow(array(S_DNS_NAME, new CTextBox('dns', $dns, '40'))); if (defined('ZBX_HAVE_IPV6')) { $host_tbl->addRow(array(S_IP_ADDRESS, new CTextBox('ip', $ip, '39'))); } else { $host_tbl->addRow(array(S_IP_ADDRESS, new CTextBox('ip', $ip, '15'))); } $cmbConnectBy = new CComboBox('useip', $useip); $cmbConnectBy->addItem(0, S_DNS_NAME); $cmbConnectBy->addItem(1, S_IP_ADDRESS); $host_tbl->addRow(array(S_CONNECT_TO, $cmbConnectBy)); $host_tbl->addRow(array(S_AGENT_PORT, new CNumericBox('port', $port, 5))); //Proxy $cmbProxy = new CComboBox('proxy_hostid', $proxy_hostid); $cmbProxy->addItem(0, S_NO_PROXY); $options = array('extendoutput' => 1); $db_proxies = CProxy::get($options); order_result($db_proxies, 'host'); foreach ($db_proxies as $proxy) { $cmbProxy->addItem($proxy['proxyid'], $proxy['host']); } $host_tbl->addRow(array(S_MONITORED_BY_PROXY, $cmbProxy)); //---------- $cmbStatus = new CComboBox('status', $status); $cmbStatus->addItem(HOST_STATUS_MONITORED, S_MONITORED); $cmbStatus->addItem(HOST_STATUS_NOT_MONITORED, S_NOT_MONITORED); $host_tbl->addRow(array(S_STATUS, $cmbStatus)); $host_tbl->addRow(array(S_USEIPMI, new CCheckBox('useipmi', $useipmi, 'submit()'))); if ($useipmi == 'yes') { $host_tbl->addRow(array(S_IPMI_IP_ADDRESS, new CTextBox('ipmi_ip', $ipmi_ip, defined('ZBX_HAVE_IPV6') ? 39 : 15))); $host_tbl->addRow(array(S_IPMI_PORT, new CNumericBox('ipmi_port', $ipmi_port, 5))); $cmbIPMIAuthtype = new CComboBox('ipmi_authtype', $ipmi_authtype); $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_DEFAULT, S_AUTHTYPE_DEFAULT); $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_NONE, S_AUTHTYPE_NONE); $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_MD2, S_AUTHTYPE_MD2); $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_MD5, S_AUTHTYPE_MD5); $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_STRAIGHT, S_AUTHTYPE_STRAIGHT); $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_OEM, S_AUTHTYPE_OEM); $cmbIPMIAuthtype->addItem(IPMI_AUTHTYPE_RMCP_PLUS, S_AUTHTYPE_RMCP_PLUS); $host_tbl->addRow(array(S_IPMI_AUTHTYPE, $cmbIPMIAuthtype)); $cmbIPMIPrivilege = new CComboBox('ipmi_privilege', $ipmi_privilege); $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_CALLBACK, S_PRIVILEGE_CALLBACK); $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_USER, S_PRIVILEGE_USER); $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_OPERATOR, S_PRIVILEGE_OPERATOR); $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_ADMIN, S_PRIVILEGE_ADMIN); $cmbIPMIPrivilege->addItem(IPMI_PRIVILEGE_OEM, S_PRIVILEGE_OEM); $host_tbl->addRow(array(S_IPMI_PRIVILEGE, $cmbIPMIPrivilege)); $host_tbl->addRow(array(S_IPMI_USERNAME, new CTextBox('ipmi_username', $ipmi_username, 16))); $host_tbl->addRow(array(S_IPMI_PASSWORD, new CTextBox('ipmi_password', $ipmi_password, 20))); } else { $frmHost->addVar('ipmi_ip', $ipmi_ip); $frmHost->addVar('ipmi_port', $ipmi_port); $frmHost->addVar('ipmi_authtype', $ipmi_authtype); $frmHost->addVar('ipmi_privilege', $ipmi_privilege); $frmHost->addVar('ipmi_username', $ipmi_username); $frmHost->addVar('ipmi_password', $ipmi_password); } if ($_REQUEST['form'] == 'full_clone') { // Host items $options = array('inherited' => 0, 'hostids' => $_REQUEST['hostid'], 'output' => API_OUTPUT_EXTEND, 'webitems' => 1); $host_items = CItem::get($options); if (!empty($host_items)) { $items_lbx = new CListBox('items', null, 8); $items_lbx->setAttribute('disabled', 'disabled'); order_result($host_items, 'description'); foreach ($host_items as $hitem) { $items_lbx->addItem($hitem['itemid'], item_description($hitem)); } $host_tbl->addRow(array(S_ITEMS, $items_lbx)); } // Host triggers $options = array('inherited' => 0, 'hostids' => $_REQUEST['hostid'], 'output' => API_OUTPUT_EXTEND, 'expandDescription' => true); $host_triggers = CTrigger::get($options); if (!empty($host_triggers)) { $trig_lbx = new CListBox('triggers', null, 8); $trig_lbx->setAttribute('disabled', 'disabled'); order_result($host_triggers, 'description'); foreach ($host_triggers as $htrigger) { $trig_lbx->addItem($htrigger['triggerid'], $htrigger['description']); } $host_tbl->addRow(array(S_TRIGGERS, $trig_lbx)); } // Host graphs $options = array('inherited' => 0, 'hostids' => $_REQUEST['hostid'], 'select_hosts' => API_OUTPUT_REFER, 'output' => API_OUTPUT_EXTEND); $host_graphs = CGraph::get($options); if (!empty($host_graphs)) { $graphs_lbx = new CListBox('graphs', null, 8); $graphs_lbx->setAttribute('disabled', 'disabled'); order_result($host_graphs, 'name'); foreach ($host_graphs as $hgraph) { if (count($hgraph['hosts']) > 1) { continue; } $graphs_lbx->addItem($hgraph['graphid'], $hgraph['name']); } if ($graphs_lbx->ItemsCount() > 1) { $host_tbl->addRow(array(S_GRAPHS, $graphs_lbx)); } } } $host_footer = array(); $host_footer[] = new CButton('save', S_SAVE); if ($_REQUEST['hostid'] > 0 && $_REQUEST['form'] != 'full_clone') { array_push($host_footer, SPACE, new CButton('clone', S_CLONE), SPACE, new CButton('full_clone', S_FULL_CLONE), SPACE, new CButtonDelete(S_DELETE_SELECTED_HOST_Q, url_param('form') . url_param('hostid') . url_param('groupid'))); } array_push($host_footer, SPACE, new CButtonCancel(url_param('groupid'))); $host_footer = new CCol($host_footer); $host_footer->setColSpan(2); $host_tbl->setFooter($host_footer); $host_wdgt = new CWidget(); $host_wdgt->setClass('header'); $host_wdgt->addHeader($frm_title); $host_wdgt->addItem($host_tbl); // } HOST WIDGET // TEMPLATES{ $template_tbl = new CTableInfo(S_NO_TEMPLATES_LINKED, 'tablestripped'); $template_tbl->setOddRowClass('form_odd_row'); $template_tbl->setEvenRowClass('form_even_row'); foreach ($templates as $id => $temp_name) { $frmHost->addVar('templates[' . $id . ']', $temp_name); $template_tbl->addRow(new CCol(array(new CCheckBox('templates_rem[' . $id . ']', 'no', null, $id), $temp_name))); } $footer = new CCol(array(new CButton('add_template', S_ADD, "return PopUp('popup.php?dstfrm=" . $frmHost->getName() . "&dstfld1=new_template&srctbl=templates&srcfld1=hostid&srcfld2=host" . url_param($templates, false, 'existed_templates') . "',450,450)", 'T'), SPACE, new CButton('unlink', S_UNLINK), SPACE, new CButton('unlink_and_clear', S_UNLINK_AND_CLEAR))); //$footer->setColSpan(2); $template_tbl->setFooter($footer); $template_wdgt = new CWidget(); $template_wdgt->setClass('header'); $template_wdgt->addHeader(S_LINKED_TEMPLATES); $template_wdgt->addItem($template_tbl); // } TEMPLATES // MACROS WIDGET { $macros_wdgt = get_macros_widget($_REQUEST['hostid']); // } MACROS WIDGET // PROFILE WIDGET { $profile_tbl = new CTable('', 'tablestripped'); $profile_tbl->setOddRowClass('form_odd_row'); $profile_tbl->setEvenRowClass('form_even_row'); $profile_tbl->addRow(array(S_USE_PROFILE, new CCheckBox('useprofile', $useprofile, 'submit()'))); if ($useprofile == 'yes') { $profile_tbl->addRow(array(S_DEVICE_TYPE, new CTextBox('devicetype', $devicetype, 61))); $profile_tbl->addRow(array(S_NAME, new CTextBox('name', $name, 61))); $profile_tbl->addRow(array(S_OS, new CTextBox('os', $os, 61))); $profile_tbl->addRow(array(S_SERIALNO, new CTextBox('serialno', $serialno, 61))); $profile_tbl->addRow(array(S_TAG, new CTextBox('tag', $tag, 61))); $profile_tbl->addRow(array(S_MACADDRESS, new CTextBox('macaddress', $macaddress, 61))); $profile_tbl->addRow(array(S_HARDWARE, new CTextArea('hardware', $hardware, 60, 4))); $profile_tbl->addRow(array(S_SOFTWARE, new CTextArea('software', $software, 60, 4))); $profile_tbl->addRow(array(S_CONTACT, new CTextArea('contact', $contact, 60, 4))); $profile_tbl->addRow(array(S_LOCATION, new CTextArea('location', $location, 60, 4))); $profile_tbl->addRow(array(S_NOTES, new CTextArea('notes', $notes, 60, 4))); } else { $frmHost->addVar('devicetype', $devicetype); $frmHost->addVar('name', $name); $frmHost->addVar('os', $os); $frmHost->addVar('serialno', $serialno); $frmHost->addVar('tag', $tag); $frmHost->addVar('macaddress', $macaddress); $frmHost->addVar('hardware', $hardware); $frmHost->addVar('software', $software); $frmHost->addVar('contact', $contact); $frmHost->addVar('location', $location); $frmHost->addVar('notes', $notes); } $profile_wdgt = new CWidget(); $profile_wdgt->setClass('header'); $profile_wdgt->addHeader(S_PROFILE); $profile_wdgt->addItem($profile_tbl); // } PROFILE WIDGET // EXT PROFILE WIDGET { $ext_profile_tbl = new CTable('', 'tablestripped'); $ext_profile_tbl->setOddRowClass('form_odd_row'); $ext_profile_tbl->setEvenRowClass('form_even_row'); $ext_profile_tbl->addRow(array(S_USE_EXTENDED_PROFILE, new CCheckBox('useprofile_ext', $useprofile_ext, 'submit()', 'yes'))); foreach ($ext_profiles_fields as $prof_field => $caption) { if ($useprofile_ext == 'yes') { $ext_profile_tbl->addRow(array($caption, new CTextBox('ext_host_profiles[' . $prof_field . ']', $ext_host_profiles[$prof_field], 40))); } else { $frmHost->addVar('ext_host_profiles[' . $prof_field . ']', $ext_host_profiles[$prof_field]); } } $ext_profile_wdgt = new CWidget(); $ext_profile_wdgt->setClass('header'); $ext_profile_wdgt->addHeader(S_EXTENDED_HOST_PROFILE); $ext_profile_wdgt->addItem($ext_profile_tbl); // } EXT PROFILE WIDGET $left_table = new CTable(); $left_table->setCellPadding(4); $left_table->setCellSpacing(4); $left_table->addRow($host_wdgt); $right_table = new CTable(); $right_table->setCellPadding(4); $right_table->setCellSpacing(4); $right_table->addRow($template_wdgt); $right_table->addRow($macros_wdgt); $right_table->addRow($profile_wdgt); $right_table->addRow($ext_profile_wdgt); $td_l = new CCol($left_table); $td_l->setAttribute('valign', 'top'); $td_r = new CCol($right_table); $td_r->setAttribute('valign', 'top'); $outer_table = new CTable(); $outer_table->addRow(array($td_l, $td_r)); $frmHost->addItem($outer_table); return $frmHost; }
/** * remove Hosts to HostGroups. All Hosts are added to all HostGroups. * * @param array $data * @param array $data['templateids'] * @param array $data['groupids'] * @param array $data['hostids'] * @param array $data['macroids'] * @return boolean */ public static function massRemove($data) { $templateids = zbx_toArray($data['templateids']); try { self::BeginTransaction(__METHOD__); $upd_templates = self::get(array('templateids' => $templateids, 'editable' => 1, 'preservekeys' => 1)); foreach ($templateids as $templateid) { if (!isset($upd_templates[$templateid])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } } if (isset($data['groupids'])) { $options = array('groupids' => zbx_toArray($data['groupids']), 'templateids' => $templateids); $result = CHostGroup::massRemove($options); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t unlink groups'); } } if (isset($data['hostids'])) { $hostids = zbx_toArray($data['hostids']); foreach ($hostids as $hostid) { foreach ($templateids as $templateid) { $result = unlink_template($hostid, $templateid, true); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t unlink hosts'); } } } } if (isset($data['templateids_link'])) { $templateids_link = zbx_toArray($data['templateids_link']); foreach ($templateids_link as $templateid_link) { foreach ($templateids as $templateid) { $result = unlink_template($templateid, $templateid_link, true); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t unlink templates'); } } } } if (isset($data['macros'])) { $options = array('templateids' => $templateids, 'macros' => zbx_toArray($data['macros'])); $result = CUserMacro::massRemove($options); if (!$result) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Can\'t remove macros'); } } self::EndTransaction(true, __METHOD__); return array('templateids' => $templateids); } catch (APIException $e) { self::EndTransaction(false, __METHOD__); $error = $e->getErrors(); $error = reset($error); self::setError(__METHOD__, $e->getCode(), $error); return false; } }
$create_new = true; $msg_ok = S_HOST_ADDED; $msg_fail = S_CANNOT_ADD_HOST; } $clone_hostid = false; if ($_REQUEST['form'] == 'full_clone') { $create_new = true; $clone_hostid = $_REQUEST['hostid']; } $templates = array_keys($templates); $templates = zbx_toObject($templates, 'templateid'); $templates_clear = zbx_toObject($templates_clear, 'templateid'); // START SAVE TRANSACTION {{{ DBstart(); if (!empty($_REQUEST['newgroup'])) { $group = CHostGroup::create(array('name' => $_REQUEST['newgroup'])); if ($group) { $groups = array_merge($groups, $group['groupids']); } else { throw new Exception(); } } $groups = zbx_toObject($groups, 'groupid'); $macros = get_request('macros', array()); foreach ($macros as $mnum => $macro) { if (zbx_empty($macro['value'])) { unset($macros[$mnum]); } } $host = array('host' => $_REQUEST['host'], 'port' => $_REQUEST['port'], 'status' => $_REQUEST['status'], 'useip' => $_REQUEST['useip'], 'dns' => $_REQUEST['dns'], 'ip' => $_REQUEST['ip'], 'proxy_hostid' => get_request('proxy_hostid', 0), 'useipmi' => isset($_REQUEST['useipmi']) ? 1 : 0, 'ipmi_ip' => $_REQUEST['ipmi_ip'], 'ipmi_port' => $_REQUEST['ipmi_port'], 'ipmi_authtype' => $_REQUEST['ipmi_authtype'], 'ipmi_privilege' => $_REQUEST['ipmi_privilege'], 'ipmi_username' => $_REQUEST['ipmi_username'], 'ipmi_password' => $_REQUEST['ipmi_password'], 'groups' => $groups, 'templates' => $templates, 'macros' => $macros, 'extendedProfile' => get_request('useprofile_ext', 'no') == 'yes' ? get_request('ext_host_profiles', array()) : array()); if ($create_new) {
public static function parseMain($rules) { $triggers_for_dependencies = array(); try { if (isset($rules['host']['exist']) || isset($rules['host']['missed'])) { $xpath = new DOMXPath(self::$xml); $hosts = $xpath->query('hosts/host'); foreach ($hosts as $hnum => $host) { $host_db = self::mapXML2arr($host, XML_TAG_HOST); if (!isset($host_db['status'])) { $host_db['status'] = HOST_STATUS_TEMPLATE; } $current_host = $host_db['status'] == HOST_STATUS_TEMPLATE ? CTemplate::exists($host_db) : CHost::exists($host_db); if (!$current_host && !isset($rules['host']['missed'])) { info('Host [' . $host_db['host'] . '] skipped - user rule'); continue; // break if update nonexist } if ($current_host && !isset($rules['host']['exist'])) { info('Host [' . $host_db['host'] . '] skipped - user rule'); continue; // break if not update exist } if (isset($host_db['proxy_hostid'])) { $proxy_exists = CProxy::get(array('proxyids' => $host_db['proxy_hostid'])); if (empty($proxy_exists)) { $host_db['proxy_hostid'] = 0; } } if ($current_host) { $options = array('filter' => array('host' => $host_db['host']), 'output' => API_OUTPUT_EXTEND, 'editable' => 1); if ($host_db['status'] == HOST_STATUS_TEMPLATE) { $current_host = CTemplate::get($options); } else { $current_host = CHost::get($options); } if (empty($current_host)) { throw new APIException(1, 'No permission for host [' . $host_db['host'] . ']'); } else { $current_host = reset($current_host); } } // HOST GROUPS {{{ $groups = $xpath->query('groups/group', $host); $host_db['groups'] = array(); $groups_to_parse = array(); foreach ($groups as $gnum => $group) { $groups_to_parse[] = array('name' => $group->nodeValue); } if (empty($groups_to_parse)) { $groups_to_parse[] = array('name' => ZBX_DEFAULT_IMPORT_HOST_GROUP); } foreach ($groups_to_parse as $group) { $current_group = CHostGroup::exists($group); if ($current_group) { $options = array('filter' => $group, 'output' => API_OUTPUT_EXTEND, 'editable' => 1); $current_group = CHostGroup::get($options); if (empty($current_group)) { throw new APIException(1, 'No permissions for group ' . $group['name']); } $host_db['groups'][] = reset($current_group); } else { $result = CHostGroup::create($group); if (!$result) { throw new APIException(1, CHostGroup::resetErrors()); } $options = array('groupids' => $result['groupids'], 'output' => API_OUTPUT_EXTEND); $new_group = CHostgroup::get($options); $host_db['groups'][] = reset($new_group); } } // }}} HOST GROUPS // MACROS $macros = $xpath->query('macros/macro', $host); $host_db['macros'] = array(); if ($macros->length > 0) { foreach ($macros as $macro) { $host_db['macros'][] = self::mapXML2arr($macro, XML_TAG_MACRO); } } // }}} MACROS // TEMPLATES {{{ if (isset($rules['template']['exist'])) { $templates = $xpath->query('templates/template', $host); $host_db['templates'] = array(); foreach ($templates as $tnum => $template) { $options = array('filter' => array('host' => $template->nodeValue), 'output' => API_OUTPUT_EXTEND, 'editable' => 1); $current_template = CTemplate::get($options); if (empty($current_template)) { throw new APIException(1, 'No permission for Template [' . $template->nodeValue . ']'); } $current_template = reset($current_template); if (!$current_template && !isset($rules['template']['missed'])) { info('Template [' . $template->nodeValue . '] skipped - user rule'); continue; // break if update nonexist } if ($current_template && !isset($rules['template']['exist'])) { info('Template [' . $template->nodeValue . '] skipped - user rule'); continue; // break if not update exist } $host_db['templates'][] = $current_template; } } // }}} TEMPLATES // HOSTS if ($current_host && isset($rules['host']['exist'])) { if ($host_db['status'] == HOST_STATUS_TEMPLATE) { $host_db['templateid'] = $current_host['hostid']; $result = CTemplate::update($host_db); if (!$result) { throw new APIException(1, CTemplate::resetErrors()); } $options = array('templateids' => $result['templateids'], 'output' => API_OUTPUT_EXTEND); $current_host = CTemplate::get($options); } else { $host_db['hostid'] = $current_host['hostid']; $result = CHost::update($host_db); if (!$result) { throw new APIException(1, CHost::resetErrors()); } $options = array('hostids' => $result['hostids'], 'output' => API_OUTPUT_EXTEND); $current_host = CHost::get($options); } if ($current_host === false) { throw new APIException(1, $host_db['status'] == HOST_STATUS_TEMPLATE ? CTemplate::resetErrors() : CHost::resetErrors()); } } if (!$current_host && isset($rules['host']['missed'])) { if ($host_db['status'] == HOST_STATUS_TEMPLATE) { $result = CTemplate::create($host_db); if (!$result) { throw new APIException(1, CTemplate::resetErrors()); } $options = array('templateids' => $result['templateids'], 'output' => API_OUTPUT_EXTEND); $current_host = CTemplate::get($options); } else { $result = CHost::create($host_db); if (!$result) { throw new APIException(1, CHost::resetErrors()); } $options = array('hostids' => $result['hostids'], 'output' => API_OUTPUT_EXTEND); $current_host = CHost::get($options); } } $current_host = reset($current_host); // HOST PROFILES {{{ $profile_node = $xpath->query('host_profile/*', $host); if ($profile_node->length > 0) { $profile = array(); foreach ($profile_node as $num => $field) { $profile[$field->nodeName] = $field->nodeValue; } delete_host_profile($current_host['hostid']); add_host_profile($current_host['hostid'], $profile['devicetype'], $profile['name'], $profile['os'], $profile['serialno'], $profile['tag'], $profile['macaddress'], $profile['hardware'], $profile['software'], $profile['contact'], $profile['location'], $profile['notes']); } $profile_ext_node = $xpath->query('host_profiles_ext/*', $host); if ($profile_ext_node->length > 0) { $profile_ext = array(); foreach ($profile_ext_node as $num => $field) { $profile_ext[$field->nodeName] = $field->nodeValue; } delete_host_profile_ext($current_host['hostid']); add_host_profile_ext($current_host['hostid'], $profile_ext); } // }}} HOST PROFILES // ITEMS {{{ if (isset($rules['item']['exist']) || isset($rules['item']['missed'])) { $items = $xpath->query('items/item', $host); foreach ($items as $inum => $item) { $item_db = self::mapXML2arr($item, XML_TAG_ITEM); $item_db['hostid'] = $current_host['hostid']; if ($current_item = CItem::exists($item_db)) { $options = array('filter' => array('hostid' => $item_db['hostid'], 'key_' => $item_db['key_']), 'webitems' => 1, 'output' => API_OUTPUT_EXTEND, 'editable' => 1); $current_item = CItem::get($options); if (empty($current_item)) { throw new APIException(1, 'No permission for Item [' . $item_db['key_'] . ']'); } $current_item = reset($current_item); } if (!$current_item && !isset($rules['item']['missed'])) { info('Item [' . $item_db['key_'] . '] skipped - user rule'); continue; // break if not update exist } if ($current_item && !isset($rules['item']['exist'])) { info('Item [' . $item_db['key_'] . '] skipped - user rule'); continue; // break if not update exist } // ITEM APPLICATIONS {{{ $applications = $xpath->query('applications/application', $item); $item_applications = array(); $applications_to_add = array(); foreach ($applications as $application) { $application_db = array('name' => $application->nodeValue, 'hostid' => $current_host['hostid']); if ($current_application = CApplication::exists($application_db)) { $current_application = CApplication::get(array('filter' => $application_db, 'output' => API_OUTPUT_EXTEND)); if (empty($current_application)) { throw new APIException(1, 'No permission for Application [' . $application_db['name'] . ']'); } } if ($current_application) { $item_applications = array_merge($item_applications, $current_application); } else { $applications_to_add[] = $application_db; } } if (!empty($applications_to_add)) { $result = CApplication::create($applications_to_add); if (!$result) { throw new APIException(1, CApplication::resetErrors()); } $options = array('applicationids' => $result['applicationids'], 'output' => API_OUTPUT_EXTEND); $new_applications = CApplication::get($options); $item_applications = array_merge($item_applications, $new_applications); } // }}} ITEM APPLICATIONS if ($current_item && isset($rules['item']['exist'])) { $item_db['itemid'] = $current_item['itemid']; $result = CItem::update($item_db); if (!$result) { throw new APIException(1, CItem::resetErrors()); } $options = array('itemids' => $result['itemids'], 'webitems' => 1, 'output' => API_OUTPUT_EXTEND); $current_item = CItem::get($options); } if (!$current_item && isset($rules['item']['missed'])) { $result = CItem::create($item_db); if (!$result) { throw new APIException(1, CItem::resetErrors()); } $options = array('itemids' => $result['itemids'], 'webitems' => 1, 'output' => API_OUTPUT_EXTEND); $current_item = CItem::get($options); } $r = CApplication::massAdd(array('applications' => $item_applications, 'items' => $current_item)); if ($r === false) { throw new APIException(1, CApplication::resetErrors()); } } } // }}} ITEMS // TRIGGERS {{{ if (isset($rules['trigger']['exist']) || isset($rules['trigger']['missed'])) { $triggers = $xpath->query('triggers/trigger', $host); $triggers_to_add = array(); $triggers_to_upd = array(); foreach ($triggers as $trigger) { $trigger_db = self::mapXML2arr($trigger, XML_TAG_TRIGGER); $trigger_db['expression'] = str_replace('{{HOSTNAME}:', '{' . $host_db['host'] . ':', $trigger_db['expression']); $trigger_db['hostid'] = $current_host['hostid']; if ($current_trigger = CTrigger::exists($trigger_db)) { $ctriggers = CTrigger::get(array('filter' => array('description' => $trigger_db['description']), 'hostids' => $current_host['hostid'], 'output' => API_OUTPUT_EXTEND, 'editable' => 1)); $current_trigger = false; foreach ($ctriggers as $tnum => $ct) { $tmp_exp = explode_exp($ct['expression'], false); if (strcmp($trigger_db['expression'], $tmp_exp) == 0) { $current_trigger = $ct; break; } } if (!$current_trigger) { throw new APIException(1, 'No permission for Trigger [' . $trigger_db['description'] . ']'); } } if (!$current_trigger && !isset($rules['trigger']['missed'])) { info('Trigger [' . $trigger_db['description'] . '] skipped - user rule'); continue; // break if not update exist } if ($current_trigger && !isset($rules['trigger']['exist'])) { info('Trigger [' . $trigger_db['description'] . '] skipped - user rule'); continue; // break if not update exist } if ($current_trigger && isset($rules['trigger']['exist'])) { $trigger_db['triggerid'] = $current_trigger['triggerid']; $triggers_to_upd[] = $trigger_db; } if (!$current_trigger && isset($rules['trigger']['missed'])) { $triggers_to_add[] = $trigger_db; } } if (!empty($triggers_to_upd)) { $result = CTrigger::update($triggers_to_upd); if (!$result) { throw new APIException(1, CTrigger::resetErrors()); } $options = array('triggerids' => $result['triggerids'], 'output' => API_OUTPUT_EXTEND); $r = CTrigger::get($options); $triggers_for_dependencies = array_merge($triggers_for_dependencies, $r); } if (!empty($triggers_to_add)) { $result = CTrigger::create($triggers_to_add); if (!$result) { throw new APIException(1, CTrigger::resetErrors()); } $options = array('triggerids' => $result['triggerids'], 'output' => API_OUTPUT_EXTEND); $r = CTrigger::get($options); $triggers_for_dependencies = array_merge($triggers_for_dependencies, $r); } } // }}} TRIGGERS // GRAPHS {{{ if (isset($rules['graph']['exist']) || isset($rules['graph']['missed'])) { $graphs = $xpath->query('graphs/graph', $host); $graphs_to_add = array(); $graphs_to_upd = array(); foreach ($graphs as $gnum => $graph) { // GRAPH ITEMS {{{ $gitems = $xpath->query('graph_elements/graph_element', $graph); $graph_hostids = array(); $graph_items = array(); foreach ($gitems as $ginum => $gitem) { $gitem_db = self::mapXML2arr($gitem, XML_TAG_GRAPH_ELEMENT); $data = explode(':', $gitem_db['host_key_']); $gitem_host = array_shift($data); $gitem_db['host'] = $gitem_host == '{HOSTNAME}' ? $host_db['host'] : $gitem_host; $gitem_db['key_'] = implode(':', $data); if ($current_item = CItem::exists($gitem_db)) { $current_item = CItem::get(array('filter' => array('key_' => $gitem_db['key_']), 'webitems' => 1, 'host' => $gitem_db['host'], 'output' => API_OUTPUT_EXTEND, 'editable' => 1)); if (empty($current_item)) { throw new APIException(1, 'No permission for Item [' . $gitem_db['key_'] . ']'); } $current_item = reset($current_item); $graph_hostids[] = $current_item['hostid']; $gitem_db['itemid'] = $current_item['itemid']; $graph_items[] = $gitem_db; } else { throw new APIException(1, 'Item [' . $gitem_db['host_key_'] . '] does not exists'); } } // }}} GRAPH ITEMS $graph_db = self::mapXML2arr($graph, XML_TAG_GRAPH); $graph_db['hostids'] = $graph_hostids; if ($current_graph = CGraph::exists($graph_db)) { $current_graph = CGraph::get(array('filter' => array('name' => $graph_db['name']), 'hostids' => $graph_db['hostids'], 'output' => API_OUTPUT_EXTEND, 'editable' => 1)); if (empty($current_graph)) { throw new APIException(1, 'No permission for Graph [' . $graph_db['name'] . ']'); } $current_graph = reset($current_graph); } if (!$current_graph && !isset($rules['graph']['missed'])) { info('Graph [' . $graph_db['name'] . '] skipped - user rule'); continue; // break if not update exist } if ($current_graph && !isset($rules['graph']['exist'])) { info('Graph [' . $graph_db['name'] . '] skipped - user rule'); continue; // break if not update exist } if ($graph_db['ymin_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE) { $item_data = explode(':', $graph_db['ymin_item_key'], 2); if (count($item_data) < 2) { throw new APIException(1, 'Incorrect y min item for graph [' . $graph_db['name'] . ']'); } if (!($item = get_item_by_key($item_data[1], $item_data[0]))) { throw new APIException(1, 'Missing item [' . $graph_db['ymin_item_key'] . '] for host [' . $host_db['host'] . ']'); } $graph_db['ymin_itemid'] = $item['itemid']; } if ($graph_db['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE) { $item_data = explode(':', $graph_db['ymax_item_key'], 2); if (count($item_data) < 2) { throw new APIException(1, 'Incorrect y max item for graph [' . $graph_db['name'] . ']'); } if (!($item = get_item_by_key($item_data[1], $item_data[0]))) { throw new APIException(1, 'Missing item [' . $graph_db['ymax_item_key'] . '] for host [' . $host_db['host'] . ']'); } $graph_db['ymax_itemid'] = $item['itemid']; } $graph_db['gitems'] = $graph_items; if ($current_graph) { $graph_db['graphid'] = $current_graph['graphid']; $graphs_to_upd[] = $graph_db; } else { $graphs_to_add[] = $graph_db; } } if (!empty($graphs_to_add)) { $r = CGraph::create($graphs_to_add); if ($r === false) { throw new APIException(1, CGraph::resetErrors()); } } if (!empty($graphs_to_upd)) { $r = CGraph::update($graphs_to_upd); if ($r === false) { throw new APIException(1, CGraph::resetErrors()); } } } } // DEPENDENCIES $dependencies = $xpath->query('dependencies/dependency'); if ($dependencies->length > 0) { $triggers_for_dependencies = zbx_objectValues($triggers_for_dependencies, 'triggerid'); $triggers_for_dependencies = array_flip($triggers_for_dependencies); foreach ($dependencies as $dependency) { $triggers_to_add_dep = array(); $trigger_description = $dependency->getAttribute('description'); $current_triggerid = get_trigger_by_description($trigger_description); // sdi('<b><u>Trigger Description: </u></b>'.$trigger_description.' | <b>Current_triggerid: </b>'. $current_triggerid['triggerid']); if ($current_triggerid && isset($triggers_for_dependencies[$current_triggerid['triggerid']])) { $depends_on_list = $xpath->query('depends', $dependency); foreach ($depends_on_list as $depends_on) { $depends_triggerid = get_trigger_by_description($depends_on->nodeValue); // sdi('<b>depends on description: </b>'.$depends_on->nodeValue.' | <b>depends_triggerid: </b>'. $depends_triggerid['triggerid']); if ($depends_triggerid['triggerid']) { $triggers_to_add_dep[] = $depends_triggerid['triggerid']; } } $r = update_trigger($current_triggerid['triggerid'], null, $current_triggerid['description'], null, null, null, null, null, $triggers_to_add_dep, null); if ($r === false) { throw new APIException(); } } } } } return true; } catch (APIException $e) { error($e->getErrors()); return false; } }
public static function getScriptsByHosts($hostids) { zbx_value2array($hostids); $obj_params = array('hostids' => $hostids, 'preservekeys' => 1); $hosts_read_only = CHost::get($obj_params); $hosts_read_only = zbx_objectValues($hosts_read_only, 'hostid'); $obj_params = array('editable' => 1, 'hostids' => $hostids, 'preservekeys' => 1); $hosts_read_write = CHost::get($obj_params); $hosts_read_write = zbx_objectValues($hosts_read_write, 'hostid'); // initialize array $scripts_by_host = array(); foreach ($hostids as $id => $hostid) { $scripts_by_host[$hostid] = array(); } //----- $options = array('hostids' => $hostids, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1); $groups = CHostGroup::get($options); $obj_params = array('groupids' => zbx_objectValues($groups, 'groupid'), 'sortfield' => 'name', 'output' => API_OUTPUT_EXTEND, 'preservekeys' => 1); $scripts = CScript::get($obj_params); foreach ($scripts as $num => $script) { $add_to_hosts = array(); $hostids = zbx_objectValues($groups[$script['groupid']]['hosts'], 'hostid'); if (PERM_READ_WRITE == $script['host_access']) { if ($script['groupid'] > 0) { $add_to_hosts = zbx_uint_array_intersect($hosts_read_write, $hostids); } 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, $hostids); } else { $add_to_hosts = $hosts_read_only; } } } foreach ($add_to_hosts as $id => $hostid) { $scripts_by_host[$hostid][] = $script; } } //SDII(count($scripts_by_host)); return $scripts_by_host; }
/** * Update maintenances * * @param _array $maintenances * @return boolean */ public static function update($maintenances) { global $USER_DETAILS; $maintenances = zbx_toArray($maintenances); $maintenanceids = zbx_objectValues($maintenances, 'maintenanceid'); try { self::BeginTransaction(__METHOD__); if ($USER_DETAILS['type'] == USER_TYPE_ZABBIX_USER) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } // Maintenance permissions $hostids = array(); $groupids = array(); $options = array('maintenanceids' => zbx_objectValues($maintenances, 'maintenanceid'), 'editable' => 1, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1); $upd_maintenances = self::get($options); foreach ($maintenances as $maintenance) { if (!isset($upd_maintenances[$maintenance['maintenanceid']])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } //checkig wheter a maintence with this name and different already exists //first, getting all maintences with the same name as this $options = array('filter' => array('name' => $maintenance['name'])); $received_maintenaces = CMaintenance::get($options); //now going though a result, to find records with different id, then our object foreach ($received_maintenaces as $r_maintenace) { if ($r_maintenace['maintenanceid'] != $maintenance['maintenanceid']) { //error! Maintenance with this name already exists self::exception(ZBX_API_ERROR_PARAMETERS, S_MAINTENANCE . ' [ ' . $maintenance['name'] . ' ] ' . S_ALREADY_EXISTS_SMALL); } } $hostids = array_merge($hostids, $maintenance['hostids']); $groupids = array_merge($groupids, $maintenance['groupids']); } if (empty($hostids) && empty($groupids)) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_GROUP_OR_HOST_NEEDED); } // hosts permissions $options = array('hostids' => $hostids, 'editable' => 1, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1); $upd_hosts = CHost::get($options); foreach ($hostids as $hostid) { if (!isset($upd_hosts[$hostid])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } } // groups permissions $options = array('groupids' => $groupids, 'editable' => 1, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1); $upd_groups = CHostGroup::get($options); foreach ($groupids as $groupid) { if (!isset($upd_groups[$groupid])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } } $timeperiodids = array(); $sql = 'SELECT DISTINCT tp.timeperiodid ' . ' FROM timeperiods tp, maintenances_windows mw ' . ' WHERE ' . DBcondition('mw.maintenanceid', $maintenanceids) . ' AND tp.timeperiodid=mw.timeperiodid '; $db_timeperiods = DBselect($sql); while ($timeperiod = DBfetch($db_timeperiods)) { $timeperiodids[] = $timeperiod['timeperiodid']; } DB::delete('timeperiods', DBcondition('timeperiodid', $timeperiodids)); DB::delete('maintenances_windows', DBcondition('maintenanceid', $maintenanceids)); $tid = 0; $update = array(); $timeperiods = array(); $insert_timeperiods = array(); foreach ($maintenances as $mnum => $maintenance) { $db_fields = array('maintenanceid' => null); if (!check_db_fields($db_fields, $maintenance)) { self::exception(ZBX_API_ERROR_PARAMETERS, 'Incorrect parameters used for Maintenance'); } $update[$mnum] = array('values' => $maintenance, 'where' => array('maintenanceid=' . $maintenance['maintenanceid'])); foreach ($maintenance['timeperiods'] as $timeperiod) { $tid++; $insert_timeperiods[$tid] = $timeperiod; $timeperiods[$tid] = $mnum; } } DB::update('maintenances', $update); $timeperiodids = DB::insert('timeperiods', $insert_timeperiods); $insert_windows = array(); foreach ($timeperiods as $tid => $mnum) { $insert_windows[] = array('timeperiodid' => $timeperiodids[$tid], 'maintenanceid' => $maintenances[$mnum]['maintenanceid']); } DB::insert('maintenances_windows', $insert_windows); DB::delete('maintenances_hosts', DBcondition('maintenanceid', $maintenanceids)); DB::delete('maintenances_groups', DBcondition('maintenanceid', $maintenanceids)); $insert_hosts = array(); $insert_groups = array(); foreach ($maintenances as $mnum => $maintenance) { foreach ($maintenance['hostids'] as $hostid) { $insert_hosts[] = array('hostid' => $hostid, 'maintenanceid' => $maintenance['maintenanceid']); } foreach ($maintenance['groupids'] as $groupid) { $insert_groups[] = array('groupid' => $groupid, 'maintenanceid' => $maintenance['maintenanceid']); } } DB::insert('maintenances_hosts', $insert_hosts); DB::insert('maintenances_groups', $insert_groups); self::EndTransaction(true, __METHOD__); return true; } catch (APIException $e) { self::EndTransaction(false, __METHOD__); $error = $e->getErrors(); $error = reset($error); self::setError(__METHOD__, $e->getCode(), $error); return false; } }
$groupid = $script['groupid']; $access = $script['host_access']; } } $frmScr->addRow(S_NAME, new CTextBox('name', $name, 80)); $frmScr->addRow(S_COMMAND, new CTextBox('command', $command, 80)); $usr_groups = new CCombobox('usrgrpid', $usrgrpid); $usr_groups->addItem(0, S_ALL_S); $usrgrps = CUserGroup::get(array('extendoutput' => 1, 'sortfield' => 'name')); foreach ($usrgrps as $ugnum => $usr_group) { $usr_groups->addItem($usr_group['usrgrpid'], $usr_group['name']); } $frmScr->addRow(S_USER_GROUPS, $usr_groups); $host_groups = new CCombobox('groupid', $groupid); $host_groups->addItem(0, S_ALL_S); $groups = CHostGroup::get(array('extendoutput' => 1, 'sortfield' => 'name')); foreach ($groups as $gnum => $group) { $host_groups->addItem($group['groupid'], $group['name']); } $frmScr->addRow(S_HOST_GROUPS, $host_groups); $select_acc = new CCombobox('access', $access); $select_acc->addItem(PERM_READ_ONLY, S_READ); $select_acc->addItem(PERM_READ_WRITE, S_WRITE); $frmScr->addRow(S_REQUIRED_HOST . SPACE . S_PERMISSIONS_SMALL, $select_acc); $frmScr->addItemToBottomRow(new CButton('save', S_SAVE, "javascript: document.getElementById('scripts').action+='?action=1'; ")); $frmScr->addItemToBottomRow(SPACE); if (isset($_REQUEST['scriptid'])) { $deleteButton = new CButtonDelete(S_DELETE_SCRIPTS_Q, '&action=1&scriptid=' . $_REQUEST['scriptid']); $frmScr->addItemToBottomRow($deleteButton); $frmScr->addItemToBottomRow(SPACE); }
/** * Get Map data * * @param _array $options * @param array $options['nodeids'] Node IDs * @param array $options['groupids'] HostGroup IDs * @param array $options['hostids'] Host IDs * @param boolean $options['monitored_hosts'] only monitored Hosts * @param boolean $options['templated_hosts'] include templates in result * @param boolean $options['with_items'] only with items * @param boolean $options['with_monitored_items'] only with monitored items * @param boolean $options['with_historical_items'] only with historical items * @param boolean $options['with_triggers'] only with triggers * @param boolean $options['with_monitored_triggers'] only with monitored triggers * @param boolean $options['with_httptests'] only with http tests * @param boolean $options['with_monitored_httptests'] only with monitored http tests * @param boolean $options['with_graphs'] only with graphs * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins * @param int $options['extendoutput'] return all fields for Hosts * @param int $options['count'] count Hosts, returned column name is rowscount * @param string $options['pattern'] search hosts by pattern in host names * @param int $options['limit'] limit selection * @param string $options['sortorder'] * @param string $options['sortfield'] * @return array|boolean Host data as array or false if error */ public static function get($options = array()) { global $USER_DETAILS; $result = array(); $user_type = $USER_DETAILS['type']; $sort_columns = array('name'); // allowed columns for sorting $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); // allowed output options for [ select_* ] params $sql_parts = array('select' => array('sysmaps' => 's.sysmapid'), 'from' => array('sysmaps' => 'sysmaps s'), 'where' => array(), 'order' => array(), 'limit' => null); $def_options = array('nodeids' => null, 'sysmapids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'extendoutput' => null, 'output' => API_OUTPUT_REFER, 'select_selements' => null, 'select_links' => null, 'countOutput' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null); $options = zbx_array_merge($def_options, $options); if (!is_null($options['extendoutput'])) { $options['output'] = API_OUTPUT_EXTEND; if (!is_null($options['select_selements'])) { $options['select_selements'] = API_OUTPUT_EXTEND; } if (!is_null($options['select_links'])) { $options['select_links'] = API_OUTPUT_EXTEND; } } // editable + PERMISSION CHECK // nodeids $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid(); // sysmapids if (!is_null($options['sysmapids'])) { zbx_value2array($options['sysmapids']); $sql_parts['where']['sysmapid'] = DBcondition('s.sysmapid', $options['sysmapids']); } // search if (!is_null($options['search'])) { zbx_db_search('sysmaps s', $options, $sql_parts); } // filter if (!is_null($options['filter'])) { zbx_value2array($options['filter']); if (isset($options['filter']['sysmapid']) && !is_null($options['filter']['sysmapid'])) { zbx_value2array($options['filter']['sysmapid']); $sql_parts['where']['sysmapid'] = DBcondition('s.sysmapid', $options['filter']['sysmapid']); } if (isset($options['filter']['name']) && !is_null($options['filter']['name'])) { zbx_value2array($options['filter']['name']); $sql_parts['where']['name'] = DBcondition('s.name', $options['filter']['name'], false, true); } } // output if ($options['output'] == API_OUTPUT_EXTEND) { $sql_parts['select']['sysmaps'] = 's.*'; } // countOutput if (!is_null($options['countOutput'])) { $options['sortfield'] = ''; $sql_parts['select'] = array('count(DISTINCT s.sysmapid) as rowscount'); } // order // restrict not allowed columns for sorting $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : ''; if (!zbx_empty($options['sortfield'])) { $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP; $sql_parts['order'][] = 's.' . $options['sortfield'] . ' ' . $sortorder; if (!str_in_array('s.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('s.*', $sql_parts['select'])) { $sql_parts['select'][] = 's.' . $options['sortfield']; } } // limit if (zbx_ctype_digit($options['limit']) && $options['limit']) { $sql_parts['limit'] = $options['limit']; } //------- $sysmapids = array(); $sql_parts['select'] = array_unique($sql_parts['select']); $sql_parts['from'] = array_unique($sql_parts['from']); $sql_parts['where'] = array_unique($sql_parts['where']); $sql_parts['order'] = array_unique($sql_parts['order']); $sql_select = ''; $sql_from = ''; $sql_where = ''; $sql_order = ''; if (!empty($sql_parts['select'])) { $sql_select .= implode(',', $sql_parts['select']); } if (!empty($sql_parts['from'])) { $sql_from .= implode(',', $sql_parts['from']); } if (!empty($sql_parts['where'])) { $sql_where .= ' AND ' . implode(' AND ', $sql_parts['where']); } if (!empty($sql_parts['order'])) { $sql_order .= ' ORDER BY ' . implode(',', $sql_parts['order']); } $sql_limit = $sql_parts['limit']; $sql = 'SELECT ' . zbx_db_distinct($sql_parts) . ' ' . $sql_select . ' FROM ' . $sql_from . ' WHERE ' . DBin_node('s.sysmapid', $nodeids) . $sql_where . $sql_order; $res = DBselect($sql, $sql_limit); while ($sysmap = DBfetch($res)) { if ($options['countOutput']) { $result = $sysmap['rowscount']; } else { $sysmapids[$sysmap['sysmapid']] = $sysmap['sysmapid']; if ($options['output'] == API_OUTPUT_SHORTEN) { $result[$sysmap['sysmapid']] = array('sysmapid' => $sysmap['sysmapid']); } else { if (!isset($result[$sysmap['sysmapid']])) { $result[$sysmap['sysmapid']] = array(); } if (!is_null($options['select_selements']) && !isset($result[$sysmap['sysmapid']]['selements'])) { $result[$sysmap['sysmapid']]['selements'] = array(); } if (!is_null($options['select_links']) && !isset($result[$sysmap['sysmapid']]['links'])) { $result[$sysmap['sysmapid']]['links'] = array(); } if (isset($sysmap['highlight'])) { $sysmap['expandproblem'] = $sysmap['highlight'] & ZBX_MAP_EXPANDPROBLEM ? 0 : 1; $sysmap['markelements'] = $sysmap['highlight'] & ZBX_MAP_MARKELEMENTS ? 1 : 0; if (($sysmap['highlight'] & ZBX_MAP_EXTACK_SEPARATED) == ZBX_MAP_EXTACK_SEPARATED) { $sysmap['show_unack'] = EXTACK_OPTION_BOTH; } else { if ($sysmap['highlight'] & ZBX_MAP_EXTACK_UNACK) { $sysmap['show_unack'] = EXTACK_OPTION_UNACK; } else { $sysmap['show_unack'] = EXTACK_OPTION_ALL; } } $sysmap['highlight'] = $sysmap['highlight'] & ZBX_MAP_HIGHLIGHT ? 1 : 0; } $result[$sysmap['sysmapid']] += $sysmap; } } } if (USER_TYPE_SUPER_ADMIN == $user_type || $options['nopermissions']) { } else { if (!empty($result)) { $link_triggers = array(); $sql = 'SELECT slt.triggerid, sl.sysmapid' . ' FROM sysmaps_link_triggers slt, sysmaps_links sl' . ' WHERE ' . DBcondition('sl.sysmapid', $sysmapids) . ' AND sl.linkid=slt.linkid'; $db_link_triggers = DBselect($sql); while ($link_trigger = DBfetch($db_link_triggers)) { $link_triggers[$link_trigger['sysmapid']] = $link_trigger['triggerid']; } if (!empty($link_triggers)) { $all_triggers = CTrigger::get(array('triggerids' => $link_triggers, 'editable' => $options['editable'], 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1)); foreach ($link_triggers as $id => $triggerid) { if (!isset($all_triggers[$triggerid])) { unset($result[$id], $sysmapids[$id]); } } } $hosts_to_check = array(); $maps_to_check = array(); $triggers_to_check = array(); $host_groups_to_check = array(); $selements = array(); $db_selements = DBselect('SELECT * FROM sysmaps_elements WHERE ' . DBcondition('sysmapid', $sysmapids)); while ($selement = DBfetch($db_selements)) { $selements[$selement['selementid']] = $selement; switch ($selement['elementtype']) { case SYSMAP_ELEMENT_TYPE_HOST: $hosts_to_check[$selement['elementid']] = $selement['elementid']; break; case SYSMAP_ELEMENT_TYPE_MAP: $maps_to_check[$selement['elementid']] = $selement['elementid']; break; case SYSMAP_ELEMENT_TYPE_TRIGGER: $triggers_to_check[$selement['elementid']] = $selement['elementid']; break; case SYSMAP_ELEMENT_TYPE_HOST_GROUP: $host_groups_to_check[$selement['elementid']] = $selement['elementid']; break; } } // sdi($hosts_to_check); // sdi($maps_to_check); // sdi($triggers_to_check); // sdi($host_groups_to_check); $nodeids = get_current_nodeid(true); if (!empty($hosts_to_check)) { $host_options = array('hostids' => $hosts_to_check, 'nodeids' => $nodeids, 'editable' => $options['editable'], 'preservekeys' => 1, 'output' => API_OUTPUT_SHORTEN); $allowed_hosts = CHost::get($host_options); foreach ($hosts_to_check as $elementid) { if (!isset($allowed_hosts[$elementid])) { foreach ($selements as $selementid => $selement) { if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && $selement['elementid'] == $elementid) { unset($result[$selement['sysmapid']], $selements[$selementid]); } } } } } if (!empty($maps_to_check)) { $map_options = array('sysmapids' => $maps_to_check, 'nodeids' => $nodeids, 'editable' => $options['editable'], 'preservekeys' => 1, 'output' => API_OUTPUT_SHORTEN); $allowed_maps = self::get($map_options); foreach ($maps_to_check as $elementid) { if (!isset($allowed_maps[$elementid])) { foreach ($selements as $selementid => $selement) { if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP && $selement['elementid'] == $elementid) { unset($result[$selement['sysmapid']], $selements[$selementid]); } } } } } if (!empty($triggers_to_check)) { $trigger_options = array('triggerids' => $triggers_to_check, 'nodeids' => $nodeids, 'editable' => $options['editable'], 'preservekeys' => 1, 'output' => API_OUTPUT_SHORTEN); $allowed_triggers = CTrigger::get($trigger_options); foreach ($triggers_to_check as $elementid) { if (!isset($allowed_triggers[$elementid])) { foreach ($selements as $selementid => $selement) { if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER && $selement['elementid'] == $elementid) { unset($result[$selement['sysmapid']], $selements[$selementid]); } } } } } if (!empty($host_groups_to_check)) { $hostgroup_options = array('groupids' => $host_groups_to_check, 'nodeids' => $nodeids, 'editable' => $options['editable'], 'preservekeys' => 1, 'output' => API_OUTPUT_SHORTEN); $allowed_host_groups = CHostGroup::get($hostgroup_options); foreach ($host_groups_to_check as $elementid) { if (!isset($allowed_host_groups[$elementid])) { foreach ($selements as $selementid => $selement) { if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST_GROUP && $selement['elementid'] == $elementid) { unset($result[$selement['sysmapid']], $selements[$selementid]); } } } } } } } COpt::memoryPick(); if (!is_null($options['countOutput'])) { if (is_null($options['preservekeys'])) { $result = zbx_cleanHashes($result); } return $result; } // Adding Elements if (!is_null($options['select_selements']) && str_in_array($options['select_selements'], $subselects_allowed_outputs)) { if (!isset($map_selements)) { $map_selements = array(); $sql = 'SELECT se.* ' . ' FROM sysmaps_elements se ' . ' WHERE ' . DBcondition('se.sysmapid', $sysmapids); $db_selements = DBselect($sql); while ($selement = DBfetch($db_selements)) { $map_selements[$selement['selementid']] = $selement; } } foreach ($map_selements as $num => $selement) { if (!isset($result[$selement['sysmapid']]['selements'])) { $result[$selement['sysmapid']]['selements'] = array(); } $result[$selement['sysmapid']]['selements'][] = $selement; } } // Adding Links if (!is_null($options['select_links']) && str_in_array($options['select_links'], $subselects_allowed_outputs)) { if (!isset($map_links)) { $linkids = array(); $map_links = array(); $sql = 'SELECT sl.* FROM sysmaps_links sl WHERE ' . DBcondition('sl.sysmapid', $sysmapids); $db_links = DBselect($sql); while ($link = DBfetch($db_links)) { $link['linktriggers'] = array(); $map_links[$link['linkid']] = $link; $linkids[$link['linkid']] = $link['linkid']; } $sql = 'SELECT DISTINCT slt.* FROM sysmaps_link_triggers slt WHERE ' . DBcondition('slt.linkid', $linkids); $db_link_triggers = DBselect($sql); while ($link_trigger = DBfetch($db_link_triggers)) { $map_links[$link_trigger['linkid']]['linktriggers'][] = $link_trigger; } } foreach ($map_links as $num => $link) { if (!isset($result[$link['sysmapid']]['links'])) { $result[$link['sysmapid']]['links'] = array(); } $result[$link['sysmapid']]['links'][] = $link; } } COpt::memoryPick(); // removing keys (hash -> array) if (is_null($options['preservekeys'])) { $result = zbx_cleanHashes($result); } return $result; }
function validate_operation($operation) { if (isset($operation['esc_period']) && ($operation['esc_period'] > 0 && $operation['esc_period'] < 60)) { error(S_INCORRECT_ESCALATION_PERIOD); return false; } switch ($operation['operationtype']) { case OPERATION_TYPE_MESSAGE: switch ($operation['object']) { case OPERATION_OBJECT_USER: $users = CUser::get(array('userids' => $operation['objectid'], 'output' => API_OUTPUT_EXTEND)); if (empty($users)) { error(S_INCORRECT_USER); return false; } break; case OPERATION_OBJECT_GROUP: $usrgrps = CUserGroup::get(array('usrgrpids' => $operation['objectid'], 'output' => API_OUTPUT_EXTEND)); if (empty($usrgrps)) { 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: case OPERATION_TYPE_HOST_ENABLE: case OPERATION_TYPE_HOST_DISABLE: break; case OPERATION_TYPE_GROUP_ADD: case OPERATION_TYPE_GROUP_REMOVE: $groups = CHostGroup::get(array('groupids' => $operation['objectid'], 'output' => API_OUTPUT_SHORTEN, 'editable' => 1)); if (empty($groups)) { error(S_INCORRECT_GROUP); return false; } break; case OPERATION_TYPE_TEMPLATE_ADD: case OPERATION_TYPE_TEMPLATE_REMOVE: $tpls = CTemplate::get(array('templateids' => $operation['objectid'], 'output' => API_OUTPUT_SHORTEN, 'editable' => 1)); if (empty($tpls)) { error(S_INCORRECT_HOST); return false; } break; default: error(S_INCORRECT_OPERATION_TYPE); return false; } return true; }
private static function hostgroup($action, $params) { CHostGroup::$error = array(); switch ($action) { default: $result = call_user_func(array('CHostGroup', $action), $params); } self::$result = $result; }
function make_webmon_overview($filter) { $options = array('groupids' => $filter['groupids'], 'monitored_hosts' => 1, 'filter' => array('maintenance_status' => $filter['maintenance'])); $available_hosts = CHost::get($options); $available_hosts = zbx_objectValues($available_hosts, 'hostid'); $table = new CTableInfo(); $table->setHeader(array(is_show_all_nodes() ? S_NODE : null, S_HOST_GROUP, S_OK, S_FAILED, S_IN_PROGRESS, S_UNKNOWN)); $options = array('monitored_hosts' => 1, 'with_monitored_httptests' => 1, 'output' => API_OUTPUT_EXTEND); $groups = CHostGroup::get($options); foreach ($groups as $gnum => $group) { $showGroup = false; $apps['ok'] = 0; $apps['failed'] = 0; $apps[HTTPTEST_STATE_BUSY] = 0; $apps[HTTPTEST_STATE_UNKNOWN] = 0; $sql = 'SELECT DISTINCT ht.name, ht.httptestid, ht.curstate, ht.lastfailedstep ' . ' FROM httptest ht, applications a, hosts_groups hg, groups g ' . ' WHERE g.groupid=' . $group['groupid'] . ' AND ' . DBcondition('hg.hostid', $available_hosts) . ' AND hg.groupid=g.groupid ' . ' AND a.hostid=hg.hostid ' . ' AND ht.applicationid=a.applicationid ' . ' AND ht.status=' . HTTPTEST_STATUS_ACTIVE; $db_httptests = DBselect($sql); while ($httptest_data = DBfetch($db_httptests)) { $showGroup = true; if (HTTPTEST_STATE_BUSY == $httptest_data['curstate']) { $apps[HTTPTEST_STATE_BUSY]++; } else { if (HTTPTEST_STATE_IDLE == $httptest_data['curstate']) { if ($httptest_data['lastfailedstep'] > 0) { $apps['failed']++; } else { $apps['ok']++; } } else { $apps[HTTPTEST_STATE_UNKNOWN]++; } } } if (!$showGroup) { continue; } $table->addRow(array(is_show_all_nodes() ? get_node_name_by_elid($group['groupid']) : null, $group['name'], new CSpan($apps['ok'], 'off'), new CSpan($apps['failed'], $apps['failed'] ? 'on' : 'off'), new CSpan($apps[HTTPTEST_STATE_BUSY], $apps[HTTPTEST_STATE_BUSY] ? 'orange' : 'off'), new CSpan($apps[HTTPTEST_STATE_UNKNOWN], 'unknown'))); } $table->setFooter(new CCol(S_UPDATED . ': ' . zbx_date2str(S_BLOCKS_WEBMON_TIME_FORMAT))); return $table; }
function insert_copy_elements_to_forms($elements_array_name) { $copy_type = get_request("copy_type", 0); $copy_mode = get_request("copy_mode", 0); $filter_groupid = get_request("filter_groupid", 0); $group_itemid = get_request($elements_array_name, array()); $copy_targetid = get_request("copy_targetid", array()); if (!is_array($group_itemid) || is_array($group_itemid) && count($group_itemid) < 1) { error("Incorrect list of items."); return; } $frmCopy = new CFormTable(count($group_itemid) . ' ' . S_X_ELEMENTS_COPY_TO_DOT_DOT_DOT, null, 'post', null, 'go'); $frmCopy->SetHelp('web.items.copyto.php'); $frmCopy->addVar($elements_array_name, $group_itemid); $cmbCopyType = new CComboBox('copy_type', $copy_type, 'submit()'); $cmbCopyType->addItem(0, S_HOSTS); $cmbCopyType->addItem(1, S_HOST_GROUPS); $frmCopy->addRow(S_TARGET_TYPE, $cmbCopyType); $target_list = array(); $groups = CHostGroup::get(array('extendoutput' => 1, 'order' => 'name')); if (0 == $copy_type) { $cmbGroup = new CComboBox('filter_groupid', $filter_groupid, 'submit()'); foreach ($groups as $groupid => $group) { if (empty($filter_groupid)) { $filter_groupid = $groupid; } $cmbGroup->addItem($groupid, $group['name']); } $frmCopy->addRow('Group', $cmbGroup); $options = array('extendoutput' => 1, 'order' => 'host', 'groupids' => $filter_groupid); $hosts = CHost::get($options); foreach ($hosts as $hostid => $host) { array_push($target_list, array(new CCheckBox('copy_targetid[' . $hostid . ']', uint_in_array($hostid, $copy_targetid), null, $hostid), SPACE, $host['host'], BR())); } } else { foreach ($groups as $groupid => $group) { array_push($target_list, array(new CCheckBox('copy_targetid[' . $groupid . ']', uint_in_array($groupid, $copy_targetid), null, $groupid), SPACE, $group['name'], BR())); } } $frmCopy->addRow(S_TARGET, $target_list); $cmbCopyMode = new CComboBox('copy_mode', $copy_mode); $cmbCopyMode->addItem(0, S_UPDATE_EXISTING_NON_LINKED_ITEMS); $cmbCopyMode->addItem(1, S_SKIP_EXISTING_ITEMS); $cmbCopyMode->setEnabled(false); $frmCopy->addRow(S_MODE, $cmbCopyMode); $frmCopy->addItemToBottomRow(new CButton("copy", S_COPY)); $frmCopy->addItemToBottomRow(array(SPACE, new CButtonCancel(url_param('groupid') . url_param("hostid") . url_param("config")))); $frmCopy->show(); }
function get_screen($screenid, $editmode, $effectiveperiod = NULL) { global $USER_DETAILS; if ($screenid == 0) { return new CTableInfo(S_NO_SCREENS_DEFINED); } $r = CScreen::get(array('screenids' => $screenid, 'editable' => $editmode == 1 ? 1 : null, 'output' => API_OUTPUT_SHORTEN)); if (empty($r)) { 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); } $sql = 'SELECT * FROM screens_items WHERE screenid=' . $screenid; $iresult = DBSelect($sql); $skip_field = array(); $irows = array(); while ($irow = DBfetch($iresult)) { $irows[] = $irow; for ($i = 0; $i < $irow['rowspan'] || $i == 0; $i++) { for ($j = 0; $j < $irow['colspan'] || $j == 0; $j++) { if ($i != 0 || $j != 0) { if (!isset($skip_field[$irow['y'] + $i])) { $skip_field[$irow['y'] + $i] = array(); } $skip_field[$irow['y'] + $i][$irow['x'] + $j] = 1; } } } } $table = new CTable(new CLink(S_NO_ROWS_IN_SCREEN . SPACE . $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) { $new_cols = array(new Ccol(new Cimg('images/general/zero.gif', 'zero', 1, 1))); for ($c = 0; $c < $row['hsize'] + 1; $c++) { $add_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer'); $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_col={$c}';"); array_push($new_cols, new Ccol($add_icon)); } $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_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer'); $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_row={$r}';"); array_push($new_cols, new Ccol($add_icon)); } for ($c = 0; $c < $row['hsize']; $c++) { $item = array(); if (isset($skip_field[$r][$c])) { continue; } $item_form = false; $irow = false; foreach ($irows as $tmprow) { if ($tmprow['x'] == $c && $tmprow['y'] == $r) { $irow = $tmprow; break; } } 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'); } // GRAPH & ZOOM features $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid; $containerid = 'graph_cont_' . $screenitemid . '_' . $resourceid; $graphDims = getGraphDims($resourceid); $graphDims['graphHeight'] = $height; $graphDims['width'] = $width; $graph = get_graph_by_graphid($resourceid); $graphid = $graph['graphid']; $legend = $graph['show_legend']; $graph3d = $graph['show_3d']; //------------- // Host feature if ($dynamic == SCREEN_DYNAMIC_ITEM && isset($_REQUEST['hostid']) && $_REQUEST['hostid'] > 0) { $options = array('hostids' => $_REQUEST['hostid'], 'output' => array('hostid', 'host')); $hosts = CHost::get($options); $host = reset($hosts); $options = array('graphids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'select_hosts' => API_OUTPUT_REFER, 'select_graph_items' => API_OUTPUT_EXTEND); $graph = CGraph::get($options); $graph = reset($graph); if (count($graph['hosts']) == 1) { // if items from one host we change them, or set calculated if not exist on that host if ($graph['ymax_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymax_itemid']) { $new_dinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymax_itemid'])), $_REQUEST['hostid'], false); $new_dinamic = reset($new_dinamic); if (isset($new_dinamic['itemid']) && $new_dinamic['itemid'] > 0) { $graph['ymax_itemid'] = $new_dinamic['itemid']; } else { $graph['ymax_type'] = GRAPH_YAXIS_TYPE_CALCULATED; } } if ($graph['ymin_type'] == GRAPH_YAXIS_TYPE_ITEM_VALUE && $graph['ymin_itemid']) { $new_dinamic = get_same_graphitems_for_host(array(array('itemid' => $graph['ymin_itemid'])), $_REQUEST['hostid'], false); $new_dinamic = reset($new_dinamic); if (isset($new_dinamic['itemid']) && $new_dinamic['itemid'] > 0) { $graph['ymin_itemid'] = $new_dinamic['itemid']; } else { $graph['ymin_type'] = GRAPH_YAXIS_TYPE_CALCULATED; } } } $url = $graph['graphtype'] == GRAPH_TYPE_PIE || $graph['graphtype'] == GRAPH_TYPE_EXPLODED ? 'chart7.php' : 'chart3.php'; $url = new Curl($url); foreach ($graph as $name => $value) { if ($name == 'width' || $name == 'height') { continue; } $url->setArgument($name, $value); } $new_items = get_same_graphitems_for_host($graph['gitems'], $_REQUEST['hostid'], false); foreach ($new_items as $gitem) { unset($gitem['gitemid']); unset($gitem['graphid']); foreach ($gitem as $name => $value) { $url->setArgument('items[' . $gitem['itemid'] . '][' . $name . ']', $value); } } $url->setArgument('name', $host['host'] . ': ' . $graph['name']); $url = $url->getUrl(); } //------------- $objData = array('id' => $resourceid, 'domid' => $dom_graph_id, 'containerid' => $containerid, 'objDims' => $graphDims, 'loadSBox' => 0, 'loadImage' => 1, 'loadScroll' => 0, 'dynamic' => 0); $default = false; if ($graphDims['graphtype'] == GRAPH_TYPE_PIE || $graphDims['graphtype'] == GRAPH_TYPE_EXPLODED) { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart6.php?graphid=' . $resourceid; $default = true; } $timeline = array(); $timeline['period'] = $effectiveperiod; $timeline['starttime'] = date('YmdHis', get_min_itemclock_by_graphid($resourceid)); if (isset($_REQUEST['stime'])) { $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']); } // $src = $url.'&width='.$width.'&height='.$height.'&legend='.$legend.'&graph3d='.$graph3d; $src = $url . '&width=' . $width . '&height=' . $height . '&legend=' . $legend . '&graph3d=' . $graph3d . '&period=' . $effectiveperiod . url_param('stime'); $objData['src'] = $src; } else { if ($dynamic == SCREEN_SIMPLE_ITEM || empty($url)) { $url = 'chart2.php?graphid=' . $resourceid; $default = true; } $src = $url . '&width=' . $width . '&height=' . $height . '&period=' . $effectiveperiod . url_param('stime'); $timeline = array(); if (isset($graphid) && !is_null($graphid) && $editmode != 1) { $timeline['period'] = $effectiveperiod; $timeline['starttime'] = date('YmdHis', time() - ZBX_MAX_PERIOD); //get_min_itemclock_by_graphid($graphid); if (isset($_REQUEST['stime'])) { $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']); } $objData['loadSBox'] = 1; } $objData['src'] = $src; } if ($editmode || !$default) { $item = new CDiv(); } else { $item = new CLink(null, $action); } $item->setAttribute('id', $containerid); $item = array($item); if ($editmode == 1) { $item[] = BR(); $item[] = new CLink(S_CHANGE, $action); } if ($editmode == 2) { insert_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } else { zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_SIMPLE_GRAPH) { $dom_graph_id = 'graph_' . $screenitemid . '_' . $resourceid; $containerid = 'graph_cont_' . $screenitemid . '_' . $resourceid; $graphDims = getGraphDims(); $graphDims['graphHeight'] = $height; $graphDims['width'] = $width; $objData = array('id' => $resourceid, 'domid' => $dom_graph_id, 'containerid' => $containerid, 'objDims' => $graphDims, 'loadSBox' => 0, 'loadImage' => 1, 'loadScroll' => 0, 'dynamic' => 0); // 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 = ''; } } //------------- if ($editmode == 0 && !empty($resourceid)) { $action = 'history.php?action=showgraph&itemid=' . $resourceid . url_param('period') . url_param('stime'); } $timeline = array(); $timeline['starttime'] = date('YmdHis', time() - ZBX_MAX_PERIOD); if (!zbx_empty($resourceid) && $editmode != 1) { $timeline['period'] = $effectiveperiod; if (isset($_REQUEST['stime'])) { $timeline['usertime'] = date('YmdHis', zbxDateToTime($_REQUEST['stime']) + $timeline['period']); } $objData['loadSBox'] = 1; } $src = zbx_empty($resourceid) ? 'chart3.php?' : 'chart.php?itemid=' . $resourceid . '&'; $src .= $url . 'width=' . $width . '&height=' . $height; $objData['src'] = $src; if ($editmode) { $item = new CDiv(); } else { $item = new CLink(null, $action); } $item->setAttribute('id', $containerid); $item = array($item); if ($editmode == 1) { $item[] = BR(); $item[] = new CLink(S_CHANGE, $action); } if ($editmode == 2) { insert_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } else { zbx_add_post_js('timeControl.addObject("' . $dom_graph_id . '",' . zbx_jsvalue($timeline) . ',' . zbx_jsvalue($objData) . ');'); } } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_MAP) { $image_map = new CImg("map.php?noedit=1&sysmapid={$resourceid}" . "&width={$width}&height={$height}&curtime=" . time()); if ($editmode == 0) { $options = array('sysmapids' => $resourceid, 'output' => API_OUTPUT_EXTEND, 'select_selements' => API_OUTPUT_EXTEND, 'nopermissions' => 1); $sysmaps = CMap::get($options); $sysmap = reset($sysmaps); $action_map = getActionMapBySysmap($sysmap); $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_HOSTGROUP_TRIGGERS) { $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => $elements); $tr_form = S_ALL_S; if ($resourceid > 0) { $options = array('groupids' => $resourceid, 'output' => API_OUTPUT_EXTEND); $hostgroups = CHostgroup::get($options); $hostgroup = reset($hostgroups); $tr_form = new CSpan(S_GROUP . ': ' . $hostgroup['name'], 'white'); $params['groupids'] = $hostgroup['groupid']; } else { $groupid = get_request('tr_groupid', CProfile::get('web.screens.tr_groupid', 0)); $hostid = get_request('tr_hostid', CProfile::get('web.screens.tr_hostid', 0)); CProfile::update('web.screens.tr_groupid', $groupid, PROFILE_TYPE_ID); CProfile::update('web.screens.tr_hostid', $hostid, PROFILE_TYPE_ID); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); $groups = CHostGroup::get($options); order_result($groups, 'name'); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); if ($groupid > 0) { $options['groupids'] = $groupid; } $hosts = CHost::get($options); $hosts = zbx_toHash($hosts, 'hostid'); order_result($hosts, 'host'); if (!isset($hosts[$hostid])) { $hostid = 0; } $tr_form = new CForm(); $cmbGroup = new CComboBox('tr_groupid', $groupid, 'submit()'); $cmbHosts = new CComboBox('tr_hostid', $hostid, 'submit()'); $cmbGroup->addItem(0, S_ALL_SMALL); $cmbHosts->addItem(0, S_ALL_SMALL); foreach ($groups as $gnum => $group) { $cmbGroup->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], null, ': ') . $group['name']); } foreach ($hosts as $hnum => $host) { $cmbHosts->addItem($host['hostid'], get_node_name_by_elid($host['hostid'], null, ': ') . $host['host']); } $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup)); $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); if ($groupid > 0) { $params['groupids'] = $groupid; } if ($hostid > 0) { $params['hostids'] = $hostid; } } $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)), $tr_form)); $item[] = make_latest_issues($params); if ($editmode == 1) { array_push($item, new CLink(S_CHANGE, $action)); } ///----------------------- } else { if ($screenitemid != 0 && $resourcetype == SCREEN_RESOURCE_HOST_TRIGGERS) { $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => $elements); $tr_form = S_ALL_S; if ($resourceid > 0) { $options = array('hostids' => $resourceid, 'output' => API_OUTPUT_EXTEND); $hosts = CHost::get($options); $host = reset($hosts); $tr_form = new CSpan(S_HOST . ': ' . $host['host'], 'white'); $params['hostids'] = $host['hostid']; } else { $groupid = get_request('tr_groupid', CProfile::get('web.screens.tr_groupid', 0)); $hostid = get_request('tr_hostid', CProfile::get('web.screens.tr_hostid', 0)); CProfile::update('web.screens.tr_groupid', $groupid, PROFILE_TYPE_ID); CProfile::update('web.screens.tr_hostid', $hostid, PROFILE_TYPE_ID); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); $groups = CHostGroup::get($options); order_result($groups, 'name'); $options = array('monitored_hosts' => 1, 'output' => API_OUTPUT_EXTEND); if ($groupid > 0) { $options['groupids'] = $groupid; } $hosts = CHost::get($options); $hosts = zbx_toHash($hosts, 'hostid'); order_result($hosts, 'host'); if (!isset($hosts[$hostid])) { $hostid = 0; } $tr_form = new CForm(); $cmbGroup = new CComboBox('tr_groupid', $groupid, 'submit()'); $cmbHosts = new CComboBox('tr_hostid', $hostid, 'submit()'); $cmbGroup->addItem(0, S_ALL_SMALL); $cmbHosts->addItem(0, S_ALL_SMALL); foreach ($groups as $gnum => $group) { $cmbGroup->addItem($group['groupid'], get_node_name_by_elid($group['groupid'], null, ': ') . $group['name']); } foreach ($hosts as $hnum => $host) { $cmbHosts->addItem($host['hostid'], get_node_name_by_elid($host['hostid'], null, ': ') . $host['host']); } $tr_form->addItem(array(S_GROUP . SPACE, $cmbGroup)); $tr_form->addItem(array(SPACE . S_HOST . SPACE, $cmbHosts)); if ($groupid > 0) { $params['groupids'] = $groupid; } if ($hostid > 0) { $params['hostids'] = $hostid; } } ///----------------------- $item = array(get_table_header(array(S_STATUS_OF_TRIGGERS_BIG, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)), $tr_form)); $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) { $params = array('groupids' => null, 'hostids' => null, 'maintenance' => null, 'severity' => null, 'limit' => null, 'extAck' => 0); $item = array(get_table_header(array(S_SYSTEM_STATUS, SPACE, zbx_date2str(S_SCREENS_TRIGGER_FORM_DATE_FORMAT)))); $item[] = make_system_status($params); 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($resourceid, null, $style); $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) { $options = array('monitored' => 1, 'value' => array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE), 'limit' => $elements); $hide_unknown = CProfile::get('web.events.filter.hide_unknown', 0); if ($hide_unknown) { $options['value'] = array(TRIGGER_VALUE_TRUE, TRIGGER_VALUE_FALSE); } $item = new CTableInfo(S_NO_EVENTS_FOUND); $item->SetHeader(array(S_TIME, is_show_all_nodes() ? S_NODE : null, S_HOST, S_DESCRIPTION, S_VALUE, S_SEVERITY)); $events = getLastEvents($options); foreach ($events as $enum => $event) { $trigger = $event['trigger']; $host = $event['host']; $value = new CCol(trigger_value2str($event['value']), get_trigger_value_style($event['value'])); // $row = zbx_array_merge($triggers[$row['triggerid']],$row); // if((1 == $hide_unknown) && (!event_initial_time($row,$hide_unknown))) continue; $item->addRow(array(zbx_date2str(S_EVENTS_TRIGGERS_EVENTS_HISTORY_LIST_DATE_FORMAT, $event['clock']), get_node_name_by_elid($event['objectid']), $host['host'], new CLink($trigger['description'], 'tr_events.php?triggerid=' . $event['objectid'] . '&eventid=' . $event['eventid']), $value, new CCol(get_severity_description($trigger['priority']), get_severity_style($trigger['priority'])))); } $item = array($item); 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', NULL, NULL, NULL, 'pointer'); 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('" . S_THIS_SCREEN_ROW_NOT_EMPTY . '. ' . S_DELETE_IT_Q . "')){" . " 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_icon = new Cimg('images/general/closed.gif', NULL, NULL, NULL, 'pointer'); $add_icon->addAction('onclick', "javascript: location.href = 'screenedit.php?config=1&screenid={$screenid}&add_row={$row['vsize']}';"); $new_cols = array(new Ccol($add_icon)); for ($c = 0; $c < $row['hsize']; $c++) { $rmv_icon = new Cimg('images/general/opened.gif', NULL, NULL, NULL, 'pointer'); if (isset($empty_screen_col[$c])) { $rmv_col_link = "javascript: if(Confirm('" . S_THIS_SCREEN_COLUMN_NOT_EMPTY . '. ' . S_DELETE_IT_Q . "')){" . " 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; }
function getSelementsInfo($sysmap) { $config = select_config(); $show_unack = $config['event_ack_enable'] ? $sysmap['show_unack'] : EXTACK_OPTION_ALL; $triggers_map = array(); $triggers_map_submaps = array(); $hostgroups_map = array(); $hosts_map = array(); $selements = zbx_toHash($sysmap['selements'], 'selementid'); foreach ($selements as $selementid => $selement) { $selements[$selementid]['hosts'] = array(); $selements[$selementid]['triggers'] = array(); switch ($selement['elementtype']) { case SYSMAP_ELEMENT_TYPE_MAP: $mapids = array($selement['elementid']); while (!empty($mapids)) { $options = array('sysmapids' => $mapids, 'output' => API_OUTPUT_EXTEND, 'select_selements' => API_OUTPUT_EXTEND, 'nopermissions' => 1, 'nodeids' => get_current_nodeid(true)); $maps = CMap::get($options); $mapids = array(); foreach ($maps as $map) { foreach ($map['selements'] as $sel) { switch ($sel['elementtype']) { case SYSMAP_ELEMENT_TYPE_MAP: $mapids[] = $sel['elementid']; break; case SYSMAP_ELEMENT_TYPE_HOST_GROUP: $hostgroups_map[$sel['elementid']][$selementid] = $selementid; break; case SYSMAP_ELEMENT_TYPE_HOST: $hosts_map[$sel['elementid']][$selementid] = $selementid; break; case SYSMAP_ELEMENT_TYPE_TRIGGER: $triggers_map_submaps[$sel['elementid']][$selementid] = $selementid; break; } } } } break; case SYSMAP_ELEMENT_TYPE_HOST_GROUP: $hostgroups_map[$selement['elementid']][$selement['selementid']] = $selement['selementid']; break; case SYSMAP_ELEMENT_TYPE_HOST: $hosts_map[$selement['elementid']][$selement['selementid']] = $selement['selementid']; break; case SYSMAP_ELEMENT_TYPE_TRIGGER: $triggers_map[$selement['elementid']][$selement['selementid']] = $selement['selementid']; break; } } // get hosts data {{{ $all_hosts = array(); if (!empty($hosts_map)) { $options = array('hostids' => array_keys($hosts_map), 'output' => API_OUTPUT_EXTEND, 'nopermissions' => 1, 'nodeids' => get_current_nodeid(true)); $hosts = CHost::get($options); $all_hosts = array_merge($all_hosts, $hosts); foreach ($hosts as $host) { foreach ($hosts_map[$host['hostid']] as $belongs_to_sel) { $selements[$belongs_to_sel]['hosts'][$host['hostid']] = $host['hostid']; } } } if (!empty($hostgroups_map)) { $options = array('groupids' => array_keys($hostgroups_map), 'output' => API_OUTPUT_EXTEND, 'nopermissions' => 1, 'nodeids' => get_current_nodeid(true)); $hosts = CHost::get($options); $all_hosts = array_merge($all_hosts, $hosts); foreach ($hosts as $host) { foreach ($host['groups'] as $group) { foreach ($hostgroups_map[$group['groupid']] as $belongs_to_sel) { $selements[$belongs_to_sel]['hosts'][$host['hostid']] = $host['hostid']; // add hosts to hosts_map for trigger selection; if (!isset($hosts_map[$host['hostid']])) { $hosts_map[$host['hostid']] = array(); } $hosts_map[$host['hostid']][$belongs_to_sel] = $belongs_to_sel; } } } } $all_hosts = zbx_toHash($all_hosts, 'hostid'); $monitored_hostids = array(); foreach ($all_hosts as $hostid => $host) { if ($host['status'] == HOST_STATUS_MONITORED) { $monitored_hostids[$hostid] = $hostid; } } // }}} // get triggers data {{{ $all_triggers = array(); // triggers from current map, select all if (!empty($triggers_map)) { $options = array('nodeids' => get_current_nodeid(true), 'triggerids' => array_keys($triggers_map), 'output' => API_OUTPUT_EXTEND, 'nopermissions' => 1); $triggers = CTrigger::get($options); $all_triggers = array_merge($all_triggers, $triggers); foreach ($triggers as $trigger) { foreach ($triggers_map[$trigger['triggerid']] as $belongs_to_sel) { $selements[$belongs_to_sel]['triggers'][$trigger['triggerid']] = $trigger['triggerid']; } } } // triggers from submaps, skip dependent if (!empty($triggers_map_submaps)) { $options = array('nodeids' => get_current_nodeid(true), 'triggerids' => array_keys($triggers_map_submaps), 'filter' => array('value' => array(TRIGGER_VALUE_UNKNOWN, TRIGGER_VALUE_TRUE)), 'skipDependent' => 1, 'output' => API_OUTPUT_EXTEND, 'nopermissions' => 1); $triggers = CTrigger::get($options); $all_triggers = array_merge($all_triggers, $triggers); foreach ($triggers as $trigger) { foreach ($triggers_map_submaps[$trigger['triggerid']] as $belongs_to_sel) { $selements[$belongs_to_sel]['triggers'][$trigger['triggerid']] = $trigger['triggerid']; } } } // triggers from all hosts/hostgroups, skip dependent if (!empty($monitored_hostids)) { $options = array('hostids' => $monitored_hostids, 'output' => API_OUTPUT_EXTEND, 'nopermissions' => 1, 'filter' => array('value' => array(TRIGGER_VALUE_UNKNOWN, TRIGGER_VALUE_TRUE)), 'nodeids' => get_current_nodeid(true), 'monitored' => true, 'skipDependent' => 1); $triggers = CTrigger::get($options); $all_triggers = array_merge($all_triggers, $triggers); foreach ($triggers as $trigger) { foreach ($trigger['hosts'] as $host) { foreach ($hosts_map[$host['hostid']] as $belongs_to_sel) { $selements[$belongs_to_sel]['triggers'][$trigger['triggerid']] = $trigger['triggerid']; } } } } $all_triggers = zbx_toHash($all_triggers, 'triggerid'); $options = array('triggerids' => array_keys($all_triggers), 'withLastEventUnacknowledged' => true, 'output' => API_OUTPUT_SHORTEN, 'nodeids' => get_current_nodeid(true), 'nopermissions' => 1, 'monitored' => true, 'filter' => array('value' => TRIGGER_VALUE_TRUE)); $unack_triggerids = CTrigger::get($options); $unack_triggerids = zbx_toHash($unack_triggerids, 'triggerid'); // }}} $info = array(); foreach ($selements as $selementid => $selement) { $i = array('disabled' => 0, 'maintenance' => 0, 'problem' => 0, 'problem_unack' => 0, 'unknown' => 0, 'priority' => 0, 'trigger_disabled' => 0, 'latelyChanged' => false, 'ack' => true); foreach ($selement['hosts'] as $hostid) { $host = $all_hosts[$hostid]; $last_hostid = $hostid; if ($host['status'] == HOST_STATUS_NOT_MONITORED) { $i['disabled']++; } else { if ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) { $i['maintenance']++; } } } foreach ($selement['triggers'] as $triggerid) { $trigger = $all_triggers[$triggerid]; if ($trigger['status'] == TRIGGER_STATUS_DISABLED) { $i['trigger_disabled']++; } else { if ($trigger['value'] == TRIGGER_VALUE_TRUE) { $i['problem']++; $last_problemid = $triggerid; if ($i['priority'] < $trigger['priority']) { $i['priority'] = $trigger['priority']; } } else { if ($trigger['value'] == TRIGGER_VALUE_UNKNOWN) { $i['unknown']++; } } if (isset($unack_triggerids[$triggerid])) { $i['problem_unack']++; } $i['latelyChanged'] |= time() - $trigger['lastchange'] < TRIGGER_BLINK_PERIOD; } } $i['ack'] = (bool) (!$i['problem_unack']); if ($sysmap['expandproblem'] && $i['problem'] == 1) { $i['problem_title'] = expand_trigger_description_by_data($all_triggers[$last_problemid]); } if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && $i['maintenance'] == 1) { $mnt = get_maintenance_by_maintenanceid($all_hosts[$last_hostid]['maintenanceid']); $i['maintenance_title'] = $mnt['name']; } switch ($selement['elementtype']) { case SYSMAP_ELEMENT_TYPE_MAP: $info[$selementid] = getMapsInfo($selement, $i, $show_unack); break; case SYSMAP_ELEMENT_TYPE_HOST_GROUP: $info[$selementid] = getHostGroupsInfo($selement, $i, $show_unack); break; case SYSMAP_ELEMENT_TYPE_HOST: $info[$selementid] = getHostsInfo($selement, $i, $show_unack); break; case SYSMAP_ELEMENT_TYPE_TRIGGER: $info[$selementid] = getTriggersInfo($selement, $i); break; case SYSMAP_ELEMENT_TYPE_IMAGE: $info[$selementid] = getImagesInfo($selement); break; } } // get names if is needed if ($sysmap['label_type'] == MAP_LABEL_TYPE_NAME) { $elems = separateMapElements($sysmap); if (!empty($elems['sysmaps'])) { $maps = CMap::get(array('sysmapids' => zbx_objectValues($elems['sysmaps'], 'elementid'), 'nopermissions' => 1, 'output' => API_OUTPUT_EXTEND)); $maps = zbx_toHash($maps, 'sysmapid'); foreach ($elems['sysmaps'] as $elem) { $info[$elem['selementid']]['name'] = $maps[$elem['elementid']]['name']; } } if (!empty($elems['hostgroups'])) { $hostgroups = CHostGroup::get(array('groupids' => zbx_objectValues($elems['hostgroups'], 'elementid'), 'nopermissions' => 1, 'output' => API_OUTPUT_EXTEND)); $hostgroups = zbx_toHash($hostgroups, 'groupid'); foreach ($elems['hostgroups'] as $elem) { $info[$elem['selementid']]['name'] = $hostgroups[$elem['elementid']]['name']; } } if (!empty($elems['triggers'])) { foreach ($elems['triggers'] as $elem) { $info[$elem['selementid']]['name'] = expand_trigger_description_by_data($all_triggers[$elem['elementid']]); } } if (!empty($elems['hosts'])) { foreach ($elems['hosts'] as $elem) { $info[$elem['selementid']]['name'] = $all_hosts[$elem['elementid']]['host']; } } } return $info; }
private static function hostgroup($action, $params) { CHostGroup::$error = array(); switch ($action) { case 'add': $result = CHostGroup::add($params); break; case 'get': $result = CHostGroup::get($params); break; case 'getById': $result = CHostGroup::getById($params); break; case 'getId': $result = CHostGroup::getId($params); break; case 'update': $result = CHostGroup::update($params); break; case 'addHosts': $result = CHostGroup::addHosts($params); break; case 'removeHosts': $result = CHostGroup::removeHosts($params); break; case 'addGroupsToHost': $result = CHostGroup::addGroupsToHost($params); break; case 'updateGroupsToHost': $result = CHostGroup::updateGroupsToHost($params); break; case 'delete': $result = CHostGroup::delete($params); break; default: self::$result = array('error' => ZBX_API_ERROR_NO_METHOD, 'data' => 'Method: "' . $action . '" doesn\'t exist.'); return; //exit function } if ($result !== false) { self::$result = array('result' => $result); } else { self::$result = CHostGroup::$error; } }
/** * Get graph data * * @param array $options * @return array */ public static function get($options = array()) { global $USER_DETAILS; $user_type = $USER_DETAILS['type']; $userid = $USER_DETAILS['userid']; $result = array(); $sort_columns = array('graphid', 'name'); // allowed columns for sorting $subselects_allowed_outputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND); // allowed output options for [ select_* ] params $sql_parts = array('select' => array('graphs' => 'g.graphid'), 'from' => array('graphs' => 'graphs g'), 'where' => array(), 'group' => array(), 'order' => array(), 'limit' => null); $def_options = array('nodeids' => null, 'groupids' => null, 'templateids' => null, 'hostids' => null, 'graphids' => null, 'itemids' => null, 'type' => null, 'templated' => null, 'inherited' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'startSearch' => null, 'excludeSearch' => null, 'output' => API_OUTPUT_REFER, 'select_groups' => null, 'select_templates' => null, 'select_hosts' => null, 'select_items' => null, 'select_graph_items' => null, 'extendoutput' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null); $options = zbx_array_merge($def_options, $options); if (!is_null($options['extendoutput'])) { $options['output'] = API_OUTPUT_EXTEND; if (!is_null($options['select_hosts'])) { $options['select_hosts'] = API_OUTPUT_EXTEND; } if (!is_null($options['select_groups'])) { $options['select_groups'] = API_OUTPUT_EXTEND; } if (!is_null($options['select_templates'])) { $options['select_templates'] = API_OUTPUT_EXTEND; } if (!is_null($options['select_items'])) { $options['select_items'] = API_OUTPUT_EXTEND; } if (!is_null($options['select_graph_items'])) { $options['select_graph_items'] = API_OUTPUT_EXTEND; } } // editable + PERMISSION CHECK if (USER_TYPE_SUPER_ADMIN == $user_type || $options['nopermissions']) { } else { $permission = $options['editable'] ? PERM_READ_WRITE : PERM_READ_ONLY; $sql_parts['from']['graphs_items'] = 'graphs_items gi'; $sql_parts['from']['items'] = 'items i'; $sql_parts['from']['hosts_groups'] = 'hosts_groups hg'; $sql_parts['from']['rights'] = 'rights r'; $sql_parts['from']['users_groups'] = 'users_groups ug'; $sql_parts['where']['gig'] = 'gi.graphid=g.graphid'; $sql_parts['where']['igi'] = 'i.itemid=gi.itemid'; $sql_parts['where']['hgi'] = 'hg.hostid=i.hostid'; $sql_parts['where'][] = 'r.id=hg.groupid '; $sql_parts['where'][] = 'r.groupid=ug.usrgrpid'; $sql_parts['where'][] = 'ug.userid=' . $userid; $sql_parts['where'][] = 'r.permission>=' . $permission; $sql_parts['where'][] = 'NOT EXISTS( ' . ' SELECT gii.graphid ' . ' FROM graphs_items gii, items ii ' . ' WHERE gii.graphid=g.graphid ' . ' AND gii.itemid=ii.itemid ' . ' AND EXISTS( ' . ' SELECT hgg.groupid ' . ' FROM hosts_groups hgg, rights rr, users_groups ugg ' . ' WHERE ii.hostid=hgg.hostid ' . ' AND rr.id=hgg.groupid ' . ' AND rr.groupid=ugg.usrgrpid ' . ' AND ugg.userid=' . $userid . ' AND rr.permission<' . $permission . '))'; } // nodeids $nodeids = !is_null($options['nodeids']) ? $options['nodeids'] : get_current_nodeid(); // groupids if (!is_null($options['groupids'])) { zbx_value2array($options['groupids']); if ($options['output'] != API_OUTPUT_SHORTEN) { $sql_parts['select']['groupid'] = 'hg.groupid'; } $sql_parts['from']['graphs_items'] = 'graphs_items gi'; $sql_parts['from']['items'] = 'items i'; $sql_parts['from']['hosts_groups'] = 'hosts_groups hg'; $sql_parts['where'][] = DBcondition('hg.groupid', $options['groupids']); $sql_parts['where'][] = 'hg.hostid=i.hostid'; $sql_parts['where']['gig'] = 'gi.graphid=g.graphid'; $sql_parts['where']['igi'] = 'i.itemid=gi.itemid'; $sql_parts['where']['hgi'] = 'hg.hostid=i.hostid'; if (!is_null($options['groupCount'])) { $sql_parts['group']['hg'] = 'hg.groupid'; } } // templateids if (!is_null($options['templateids'])) { zbx_value2array($options['templateids']); if (!is_null($options['hostids'])) { zbx_value2array($options['hostids']); $options['hostids'] = array_merge($options['hostids'], $options['templateids']); } else { $options['hostids'] = $options['templateids']; } } // hostids if (!is_null($options['hostids'])) { zbx_value2array($options['hostids']); if ($options['output'] != API_OUTPUT_SHORTEN) { $sql_parts['select']['hostid'] = 'i.hostid'; } $sql_parts['from']['graphs_items'] = 'graphs_items gi'; $sql_parts['from']['items'] = 'items i'; $sql_parts['where'][] = DBcondition('i.hostid', $options['hostids']); $sql_parts['where']['gig'] = 'gi.graphid=g.graphid'; $sql_parts['where']['igi'] = 'i.itemid=gi.itemid'; if (!is_null($options['groupCount'])) { $sql_parts['group']['i'] = 'i.hostid'; } } // graphids if (!is_null($options['graphids'])) { zbx_value2array($options['graphids']); $sql_parts['where'][] = DBcondition('g.graphid', $options['graphids']); } // itemids if (!is_null($options['itemids'])) { zbx_value2array($options['itemids']); if ($options['output'] != API_OUTPUT_SHORTEN) { $sql_parts['select']['itemid'] = 'gi.itemid'; } $sql_parts['from']['graphs_items'] = 'graphs_items gi'; $sql_parts['where']['gig'] = 'gi.graphid=g.graphid'; $sql_parts['where'][] = DBcondition('gi.itemid', $options['itemids']); } // type if (!is_null($options['type'])) { $sql_parts['where'][] = 'g.type=' . $options['type']; } // templated if (!is_null($options['templated'])) { $sql_parts['from']['graphs_items'] = 'graphs_items gi'; $sql_parts['from']['items'] = 'items i'; $sql_parts['from']['hosts'] = 'hosts h'; $sql_parts['where']['igi'] = 'i.itemid=gi.itemid'; $sql_parts['where']['ggi'] = 'g.graphid=gi.graphid'; $sql_parts['where']['hi'] = 'h.hostid=i.hostid'; if ($options['templated']) { $sql_parts['where'][] = 'h.status=' . HOST_STATUS_TEMPLATE; } else { $sql_parts['where'][] = 'h.status<>' . HOST_STATUS_TEMPLATE; } } // inherited if (!is_null($options['inherited'])) { if ($options['inherited']) { $sql_parts['where'][] = 'g.templateid<>0'; } else { $sql_parts['where'][] = 'g.templateid=0'; } } // extendoutput if ($options['output'] == API_OUTPUT_EXTEND) { $sql_parts['select']['graphs'] = 'g.*'; } // countOutput if (!is_null($options['countOutput'])) { $options['sortfield'] = ''; $sql_parts['select'] = array('count(DISTINCT g.graphid) as rowscount'); //groupCount if (!is_null($options['groupCount'])) { foreach ($sql_parts['group'] as $key => $fields) { $sql_parts['select'][$key] = $fields; } } } // search if (is_array($options['search'])) { zbx_db_search('graphs g', $options, $sql_parts); } // filter if (is_array($options['filter'])) { if (isset($options['filter']['name'])) { zbx_value2array($options['filter']['name']); $sql_parts['where']['name'] = DBcondition('g.name', $options['filter']['name'], false, true); } if (isset($options['filter']['templateid'])) { zbx_value2array($options['filter']['templateid']); $sql_parts['where']['templateid'] = DBcondition('g.templateid', $options['filter']['templateid']); } if (isset($options['filter']['host'])) { zbx_value2array($options['filter']['host']); $sql_parts['from']['graphs_items'] = 'graphs_items gi'; $sql_parts['from']['items'] = 'items i'; $sql_parts['from']['hosts'] = 'hosts h'; $sql_parts['where']['gig'] = 'gi.graphid=g.graphid'; $sql_parts['where']['igi'] = 'i.itemid=gi.itemid'; $sql_parts['where']['hi'] = 'h.hostid=i.hostid'; $sql_parts['where']['host'] = DBcondition('h.host', $options['filter']['host'], false, true); } if (isset($options['filter']['hostid'])) { zbx_value2array($options['filter']['hostid']); $sql_parts['from']['graphs_items'] = 'graphs_items gi'; $sql_parts['from']['items'] = 'items i'; $sql_parts['where']['gig'] = 'gi.graphid=g.graphid'; $sql_parts['where']['igi'] = 'i.itemid=gi.itemid'; $sql_parts['where']['hostid'] = DBcondition('i.hostid', $options['filter']['hostid']); } } // order // restrict not allowed columns for sorting $options['sortfield'] = str_in_array($options['sortfield'], $sort_columns) ? $options['sortfield'] : ''; if (!zbx_empty($options['sortfield'])) { $sortorder = $options['sortorder'] == ZBX_SORT_DOWN ? ZBX_SORT_DOWN : ZBX_SORT_UP; $sql_parts['order'][] = 'g.' . $options['sortfield'] . ' ' . $sortorder; if (!str_in_array('g.' . $options['sortfield'], $sql_parts['select']) && !str_in_array('g.*', $sql_parts['select'])) { $sql_parts['select'][] = 'g.' . $options['sortfield']; } } // limit if (zbx_ctype_digit($options['limit']) && $options['limit']) { $sql_parts['limit'] = $options['limit']; } //------------ $graphids = array(); $sql_parts['select'] = array_unique($sql_parts['select']); $sql_parts['from'] = array_unique($sql_parts['from']); $sql_parts['where'] = array_unique($sql_parts['where']); $sql_parts['group'] = array_unique($sql_parts['group']); $sql_parts['order'] = array_unique($sql_parts['order']); $sql_select = ''; $sql_from = ''; $sql_where = ''; $sql_group = ''; $sql_order = ''; if (!empty($sql_parts['select'])) { $sql_select .= implode(',', $sql_parts['select']); } if (!empty($sql_parts['from'])) { $sql_from .= implode(',', $sql_parts['from']); } if (!empty($sql_parts['where'])) { $sql_where .= ' AND ' . implode(' AND ', $sql_parts['where']); } if (!empty($sql_parts['group'])) { $sql_where .= ' GROUP BY ' . implode(',', $sql_parts['group']); } if (!empty($sql_parts['order'])) { $sql_order .= ' ORDER BY ' . implode(',', $sql_parts['order']); } $sql_limit = $sql_parts['limit']; $sql = 'SELECT ' . zbx_db_distinct($sql_parts) . ' ' . $sql_select . ' FROM ' . $sql_from . ' WHERE ' . DBin_node('g.graphid', $nodeids) . $sql_where . $sql_group . $sql_order; //SDI($sql); $db_res = DBselect($sql, $sql_limit); while ($graph = DBfetch($db_res)) { if (!is_null($options['countOutput'])) { if (!is_null($options['groupCount'])) { $result[] = $graph; } else { $result = $graph['rowscount']; } } else { $graphids[$graph['graphid']] = $graph['graphid']; if ($options['output'] == API_OUTPUT_SHORTEN) { $result[$graph['graphid']] = array('graphid' => $graph['graphid']); } else { if (!isset($result[$graph['graphid']])) { $result[$graph['graphid']] = array(); } if (!is_null($options['select_hosts']) && !isset($result[$graph['graphid']]['hosts'])) { $result[$graph['graphid']]['hosts'] = array(); } if (!is_null($options['select_graph_items']) && !isset($result[$graph['graphid']]['gitems'])) { $result[$graph['graphid']]['gitems'] = array(); } if (!is_null($options['select_templates']) && !isset($result[$graph['graphid']]['templates'])) { $result[$graph['graphid']]['templates'] = array(); } if (!is_null($options['select_items']) && !isset($result[$graph['graphid']]['items'])) { $result[$graph['graphid']]['items'] = array(); } // hostids if (isset($graph['hostid']) && is_null($options['select_hosts'])) { if (!isset($result[$graph['graphid']]['hosts'])) { $result[$graph['graphid']]['hosts'] = array(); } $result[$graph['graphid']]['hosts'][] = array('hostid' => $graph['hostid']); unset($graph['hostid']); } // itemids if (isset($graph['itemid']) && is_null($options['select_items'])) { if (!isset($result[$graph['graphid']]['items'])) { $result[$graph['graphid']]['items'] = array(); } $result[$graph['graphid']]['items'][] = array('itemid' => $graph['itemid']); unset($graph['itemid']); } $result[$graph['graphid']] += $graph; } } } COpt::memoryPick(); if (!is_null($options['countOutput'])) { if (is_null($options['preservekeys'])) { $result = zbx_cleanHashes($result); } return $result; } // Adding GraphItems if (!is_null($options['select_graph_items']) && str_in_array($options['select_graph_items'], $subselects_allowed_outputs)) { $obj_params = array('nodeids' => $nodeids, 'output' => $options['select_graph_items'], 'graphids' => $graphids, 'nopermissions' => 1, 'preservekeys' => 1); $gitems = CGraphItem::get($obj_params); //SDI($gitems); foreach ($gitems as $gitemid => $gitem) { $ggraphs = $gitem['graphs']; unset($gitem['graphs']); foreach ($ggraphs as $num => $graph) { $result[$graph['graphid']]['gitems'][] = $gitem; } } } // Adding Hostgroups if (!is_null($options['select_groups'])) { if (is_array($options['select_groups']) || str_in_array($options['select_groups'], $subselects_allowed_outputs)) { $obj_params = array('nodeids' => $nodeids, 'output' => $options['select_groups'], 'graphids' => $graphids, 'nopermissions' => 1, 'preservekeys' => 1); $groups = CHostGroup::get($obj_params); foreach ($groups as $groupis => $group) { $ggraphs = $group['graphs']; unset($group['graphs']); foreach ($ggraphs as $num => $graph) { $result[$graph['graphid']]['groups'][] = $group; } } } } // Adding Hosts if (!is_null($options['select_hosts'])) { if (is_array($options['select_hosts']) || str_in_array($options['select_hosts'], $subselects_allowed_outputs)) { $obj_params = array('nodeids' => $nodeids, 'output' => $options['select_hosts'], 'graphids' => $graphids, 'nopermissions' => 1, 'preservekeys' => 1); $hosts = CHost::get($obj_params); foreach ($hosts as $hostid => $host) { $hgraphs = $host['graphs']; unset($host['graphs']); foreach ($hgraphs as $num => $graph) { $result[$graph['graphid']]['hosts'][] = $host; } } } } // Adding Templates if (!is_null($options['select_templates']) && str_in_array($options['select_templates'], $subselects_allowed_outputs)) { $obj_params = array('nodeids' => $nodeids, 'output' => $options['select_templates'], 'graphids' => $graphids, 'nopermissions' => 1, 'preservekeys' => 1); $templates = CTemplate::get($obj_params); foreach ($templates as $templateid => $template) { $tgraphs = $template['graphs']; unset($template['graphs']); foreach ($tgraphs as $num => $graph) { $result[$graph['graphid']]['templates'][] = $template; } } } // Adding Items if (!is_null($options['select_items']) && str_in_array($options['select_items'], $subselects_allowed_outputs)) { $obj_params = array('nodeids' => $nodeids, 'output' => $options['select_items'], 'graphids' => $graphids, 'nopermissions' => 1, 'preservekeys' => 1); $items = CItem::get($obj_params); foreach ($items as $itemid => $item) { $igraphs = $item['graphs']; unset($item['graphs']); foreach ($igraphs as $num => $graph) { $result[$graph['graphid']]['items'][] = $item; } } } COpt::memoryPick(); // removing keys (hash -> array) if (is_null($options['preservekeys'])) { $result = zbx_cleanHashes($result); } return $result; }
private function _initGroups($groupid, $options) { $def_options = array('nodeids' => $this->config['all_nodes'] ? get_current_nodeid() : null, 'output' => API_OUTPUT_EXTEND); $options = zbx_array_merge($def_options, $options); $groups = CHostGroup::get($options); order_result($groups, 'name'); $this->data['groups'] = array(); foreach ($groups as $group) { $this->data['groups'][$group['groupid']] = $group['name']; } if (is_null($groupid)) { $groupid = $this->_profileIds['groupid']; } if (!isset($this->data['groups'][$groupid]) && $groupid > 0 || is_null($groupid)) { if ($this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_NONE) { $groupid = 0; } else { if (is_null($this->_requestIds['groupid']) || $this->_requestIds['groupid'] > 0) { $groupids = array_keys($this->data['groups']); $groupid = empty($groupids) ? 0 : reset($groupids); } } } if (!is_null($this->_requestIds['groupid'])) { CProfile::update($this->_profileIdx['groups'], $groupid, PROFILE_TYPE_ID); CProfile::update(self::GROUP_LATEST_IDX, $groupid, PROFILE_TYPE_ID); } $this->isSelected['groupsSelected'] = $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['groups']) || $groupid > 0; $this->isSelected['groupsAll'] = $this->config['DDFirst'] == ZBX_DROPDOWN_FIRST_ALL && !empty($this->data['groups']) && $groupid == 0; $this->ids['groupid'] = $groupid; }
protected static function checkItems($screenitems) { $hostgroups = array(); $hosts = array(); $graphs = array(); $items = array(); $maps = array(); $screens = array(); $resources = array(SCREEN_RESOURCE_GRAPH, SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT, SCREEN_RESOURCE_MAP, SCREEN_RESOURCE_SCREEN, SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW); foreach ($screenitems as $item) { if (isset($item['resourcetype']) && !isset($item['resourceid']) || !isset($item['resourcetype']) && isset($item['resourceid'])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } if (isset($item['resourceid']) && $item['resourceid'] == 0) { if (uint_in_array($item['resourcetype'], $resources)) { throw new Exception(S_INCORRECT_RESOURCE_PROVIDED_FOR_SCREEN_ITEM); } else { continue; } } switch ($item['resourcetype']) { case SCREEN_RESOURCE_HOSTS_INFO: case SCREEN_RESOURCE_TRIGGERS_INFO: case SCREEN_RESOURCE_TRIGGERS_OVERVIEW: case SCREEN_RESOURCE_DATA_OVERVIEW: case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS: $hostgroups[] = $item['resourceid']; break; case SCREEN_RESOURCE_HOST_TRIGGERS: $hosts[] = $item['resourceid']; break; case SCREEN_RESOURCE_GRAPH: $graphs[] = $item['resourceid']; break; case SCREEN_RESOURCE_SIMPLE_GRAPH: case SCREEN_RESOURCE_PLAIN_TEXT: $items[] = $item['resourceid']; break; case SCREEN_RESOURCE_MAP: $maps[] = $item['resourceid']; break; case SCREEN_RESOURCE_SCREEN: $screens[] = $item['resourceid']; break; } } if (!empty($hostgroups)) { $result = CHostGroup::get(array('groupids' => $hostgroups, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1)); foreach ($hostgroups as $id) { if (!isset($result[$id])) { self::exception(ZBX_API_ERROR_PERMISSIONS, 'Incorrect Host group identity "' . $id . '" provided for Screens item resource'); } } } if (!empty($hosts)) { $result = CHost::get(array('hostids' => $hosts, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1)); foreach ($hosts as $id) { if (!isset($result[$id])) { self::exception(ZBX_API_ERROR_PERMISSIONS, 'Incorrect Host identity "' . $id . '" provided for Screens item resource'); } } } if (!empty($graphs)) { $result = CGraph::get(array('graphids' => $graphs, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1)); foreach ($graphs as $id) { if (!isset($result[$id])) { self::exception(ZBX_API_ERROR_PERMISSIONS, 'Incorrect Graph identity "' . $id . '" provided for Screens item resource'); } } } if (!empty($items)) { $result = CItem::get(array('itemids' => $items, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1, 'webitems' => 1)); foreach ($items as $id) { if (!isset($result[$id])) { self::exception(ZBX_API_ERROR_PERMISSIONS, 'Incorrect Item identity "' . $id . '" provided for Screens item resource'); } } } if (!empty($maps)) { $result = CMap::get(array('sysmapids' => $maps, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1)); foreach ($maps as $id) { if (!isset($result[$id])) { self::exception(ZBX_API_ERROR_PERMISSIONS, 'Incorrect Map identity "' . $id . '" provided for Screens item resource'); } } } if (!empty($screens)) { $result = self::get(array('screenids' => $screens, 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => 1)); foreach ($screens as $id) { if (!isset($result[$id])) { self::exception(ZBX_API_ERROR_PERMISSIONS, 'Incorrect Screen identity "' . $id . '" provided for Screens item resource'); } } } }
$caption = make_decoration($host['host'], $search); $hostip = make_decoration($host['ip'], $search); $hostdns = make_decoration($host['dns'], $search); $table->addRow(array(get_node_name_by_elid($hostid), $caption, $hostip, $hostdns, new CLink(S_GO, 'latest.php?' . $link), new CLink(S_GO, 'tr_status.php?' . $link), new CLink(S_GO, 'events.php?' . $link), $pageSelect)); } $table->setFooter(new CCol(S_DISPLAYING . SPACE . $viewCount . SPACE . S_OF_SMALL . SPACE . $overalCount . SPACE . S_FOUND_SMALL)); $wdgt_hosts = new CWidget('search_hosts', $table); $wdgt_hosts->addHeader(S_HOSTS, SPACE); $left_tab->addRow($wdgt_hosts); //---------------- // Find Host groups $params = array('nodeids' => get_current_nodeid(), 'extendoutput' => 1, 'pattern' => $search, 'limit' => $rows_per_page, 'order' => 'name'); $db_hostGroups = CHostGroup::get($params); $hostGroups = selectByPattern($db_hostGroups, 'name', $search, $rows_per_page); $params = array('nodeids' => get_current_nodeid(), 'pattern' => $search, 'count' => 1); $groups_count = CHostGroup::get($params); $overalCount = $groups_count['rowscount']; $viewCount = count($hostGroups); $header = array(is_show_all_nodes() ? new CCol(S_NODE) : null, new CCol(S_HOST_GROUP), new CCol(S_LATEST_DATA), new CCol(S_TRIGGERS), new CCol(S_EVENTS), $admin ? new CCol(S_EDIT) : null); $table = new CTableInfo(); $table->setHeader($header); foreach ($hostGroups as $num => $group) { $hostgroupid = $group['groupid']; $caption = make_decoration($group['name'], $search); $admin_link = $admin ? new CLink(S_GO, 'hosts.php?config=1&groupid=' . $hostgroupid . '&hostid=0') : null; $table->addRow(array(get_node_name_by_elid($hostgroupid), $caption, new CLink(S_GO, 'latest.php?groupid=' . $hostgroupid . '&hostid=0'), new CLink(S_GO, 'tr_status.php?groupid=' . $hostgroupid . '&hostid=0'), new CLink(S_GO, 'events.php?groupid=' . $hostgroupid . '&hostid=0'), $admin_link)); } $table->setFooter(new CCol(S_DISPLAYING . SPACE . $viewCount . SPACE . S_OF_SMALL . SPACE . $overalCount . SPACE . S_FOUND_SMALL)); $wdgt_hgroups = new CWidget('search_hostgroup', $table); $wdgt_hgroups->addHeader(S_HOST_GROUPS, SPACE); $right_tab->addRow($wdgt_hgroups);
/** * Update Host's HostGroups with new HostGroups (rewrite) * * {@source} * @access public * @static * @since 1.8 * @version 1 * * @static * @param string $hostid * @param array $groupids * @return boolean */ public static function updateGroupsToHost($data) { $hostid = $data['hostid']; $groupids = $data['groupids']; $result = update_host_groups($hostid, $groupids); if ($result) { return true; } else { self::$error = array('error' => ZBX_API_ERROR_INTERNAL, 'data' => 'Internal zabbix error'); return false; } }
/** * remove Hosts from HostGroups. All Hosts are removed from all HostGroups. * * @param array $data * @param array $data['hostids'] * @param array $data['groupids'] * @param array $data['templateids'] * @param array $data['macroids'] * @return array */ public static function massRemove($data) { $hostids = zbx_toArray($data['hostids']); try { self::BeginTransaction(__METHOD__); $options = array('hostids' => $hostids, 'editable' => 1, 'preservekeys' => 1, 'output' => API_OUTPUT_SHORTEN); $upd_hosts = self::get($options); foreach ($hostids as $hostid) { if (!isset($upd_hosts[$hostid])) { self::exception(ZBX_API_ERROR_PERMISSIONS, S_NO_PERMISSION); } } if (isset($data['groupids'])) { $options = array('hostids' => $hostids, 'groupids' => zbx_toArray($data['groupids'])); $result = CHostGroup::massRemove($options); if (!$result) { self::exception(); } } if (isset($data['templateids'])) { $options = array('hostids' => $hostids, 'templateids' => zbx_toArray($data['templateids'])); $result = CTemplate::massRemove($options); if (!$result) { self::exception(); } } if (isset($data['macros'])) { $options = array('hostids' => $hostids, 'macros' => zbx_toArray($data['macros'])); $result = CUserMacro::massRemove($options); if (!$result) { self::exception(); } } self::EndTransaction(true, __METHOD__); return array('hostids' => $hostids); } catch (APIException $e) { self::EndTransaction(false, __METHOD__); $error = $e->getErrors(); $error = reset($error); self::setError(__METHOD__, $e->getCode(), $error); return false; } }
function available_groups($groupids, $editable = null) { $options = array(); $options['groupids'] = $groupids; $options['editable'] = $editable; $groups = CHostGroup::get($options); return zbx_objectValues($groups, 'groupid'); }