/**
  * Import maps.
  *
  * @param array $maps
  *
  * @return void
  */
 public function import(array $maps)
 {
     $maps = zbx_toHash($maps, 'name');
     $this->checkCircularMapReferences($maps);
     do {
         $im = $this->getIndependentMaps($maps);
         $mapsToCreate = array();
         $mapsToUpdate = array();
         foreach ($im as $name) {
             $map = $maps[$name];
             unset($maps[$name]);
             $map = $this->resolveMapReferences($map);
             if ($mapId = $this->referencer->resolveMap($map['name'])) {
                 $map['sysmapid'] = $mapId;
                 $mapsToUpdate[] = $map;
             } else {
                 $mapsToCreate[] = $map;
             }
         }
         if ($this->options['maps']['createMissing'] && $mapsToCreate) {
             $newMapIds = API::Map()->create($mapsToCreate);
             foreach ($mapsToCreate as $num => $map) {
                 $mapId = $newMapIds['sysmapids'][$num];
                 $this->referencer->addMapRef($map['name'], $mapId);
             }
         }
         if ($this->options['maps']['updateExisting'] && $mapsToUpdate) {
             API::Map()->update($mapsToUpdate);
         }
     } while (!empty($im));
 }
 protected function doAction()
 {
     CProfile::update('web.maps.sysmapid', $this->sysmapid, PROFILE_TYPE_ID);
     $data = ['fullscreen' => $this->getInput('fullscreen', 0)];
     $maps = API::Map()->get(['output' => ['name', 'severity_min'], 'sysmapids' => [$this->sysmapid]]);
     $data['map'] = reset($maps);
     $data['map']['editable'] = API::Map()->isWritable([$this->sysmapid]);
     $data['pageFilter'] = new CPageFilter(['severitiesMin' => ['default' => $data['map']['severity_min'], 'mapId' => $this->sysmapid], 'severityMin' => $this->hasInput('severity_min') ? $this->getInput('severity_min') : null]);
     $data['severity_min'] = $data['pageFilter']->severityMin;
     $response = new CControllerResponseData($data);
     $response->setTitle(_('Network maps'));
     $this->setResponse($response);
 }
示例#3
0
 /**
  * Import maps.
  *
  * @param array $maps
  *
  * @return void
  */
 public function import(array $maps)
 {
     $maps = zbx_toHash($maps, 'name');
     $this->checkCircularMapReferences($maps);
     $maps = $this->resolveMapElementReferences($maps);
     /*
      * Get all importable maps with removed elements and links. First import maps and then update maps with
      * elements and links from import file. This way we make sure we are able to resolve any references
      * between maps and links that are imported.
      */
     $mapsWithoutElements = $this->getMapsWithoutElements($maps);
     $mapsToProcess = array('createMissing' => array(), 'updateExisting' => array());
     foreach ($mapsWithoutElements as $mapName => $mapWithoutElements) {
         $mapId = $this->referencer->resolveMap($mapWithoutElements['name']);
         if ($mapId) {
             // Update sysmapid in source map too.
             $mapWithoutElements['sysmapid'] = $mapId;
             $maps[$mapName]['sysmapid'] = $mapId;
             $mapsToProcess['updateExisting'][] = $mapWithoutElements;
         } else {
             $mapsToProcess['createMissing'][] = $mapWithoutElements;
         }
     }
     if ($this->options['maps']['createMissing'] && $mapsToProcess['createMissing']) {
         $newMapIds = API::Map()->create($mapsToProcess['createMissing']);
         foreach ($mapsToProcess['createMissing'] as $num => $map) {
             $mapId = $newMapIds['sysmapids'][$num];
             $this->referencer->addMapRef($map['name'], $mapId);
             $maps[$map['name']]['sysmapid'] = $mapId;
         }
     }
     if ($this->options['maps']['updateExisting'] && $mapsToProcess['updateExisting']) {
         API::Map()->update($mapsToProcess['updateExisting']);
     }
     // Form an array of maps that need to be updated with elements and links, respecting the create/update options.
     $mapsToUpdate = array();
     foreach ($mapsToProcess as $mapActionKey => $mapArray) {
         if ($this->options['maps'][$mapActionKey] && $mapsToProcess[$mapActionKey]) {
             foreach ($mapArray as $mapItem) {
                 $map = array('sysmapid' => $maps[$mapItem['name']]['sysmapid'], 'name' => $mapItem['name'], 'selements' => $maps[$mapItem['name']]['selements'], 'links' => $maps[$mapItem['name']]['links']);
                 $map = $this->resolveMapReferences($map);
                 // Remove the map name so API does not make an update query to the database.
                 unset($map['name']);
                 $mapsToUpdate[] = $map;
             }
         }
     }
     if ($mapsToUpdate) {
         API::Map()->update($mapsToUpdate);
     }
 }
 /**
  * Prepare data for favourite maps menu popup.
  *
  * @return array
  */
 public static function getFavouriteMaps()
 {
     $maps = [];
     $favourites = CFavorite::get('web.favorite.sysmapids');
     if ($favourites) {
         $mapids = [];
         foreach ($favourites as $favourite) {
             $mapids[$favourite['value']] = true;
         }
         $db_maps = API::Map()->get(['output' => ['sysmapid', 'name'], 'sysmapids' => array_keys($mapids)]);
         foreach ($db_maps as $db_map) {
             $maps[] = ['id' => $db_map['sysmapid'], 'label' => $db_map['name']];
         }
     }
     return ['type' => 'favouriteMaps', 'maps' => $maps];
 }
 /**
  * Prepare data for favourite maps menu popup.
  *
  * @return array
  */
 public static function getFavouriteMaps()
 {
     $maps = array();
     $favourites = CFavorite::get('web.favorite.sysmapids');
     if ($favourites) {
         $mapIds = array();
         foreach ($favourites as $favourite) {
             $mapIds[$favourite['value']] = $favourite['value'];
         }
         $dbMaps = API::Map()->get(array('output' => array('sysmapid', 'name'), 'sysmapids' => $mapIds));
         foreach ($dbMaps as $dbMap) {
             $maps[] = array('id' => $dbMap['sysmapid'], 'label' => $dbMap['name']);
         }
     }
     return array('type' => 'favouriteMaps', 'maps' => $maps);
 }
 /**
  * Process screen.
  *
  * @return CDiv (screen inside container)
  */
 public function get()
 {
     $image = new CImg('map.php?noedit=1&sysmapid=' . $this->screenitem['resourceid'] . '&width=' . $this->screenitem['width'] . '&height=' . $this->screenitem['height'] . '&curtime=' . time());
     $image->setAttribute('id', 'map_' . $this->screenitem['screenitemid']);
     if ($this->mode == SCREEN_MODE_PREVIEW) {
         $sysmap = API::Map()->get(array('sysmapids' => $this->screenitem['resourceid'], 'output' => API_OUTPUT_EXTEND, 'selectSelements' => API_OUTPUT_EXTEND, 'selectLinks' => API_OUTPUT_EXTEND, 'expandUrls' => true, 'nopermissions' => true, 'preservekeys' => true));
         $sysmap = reset($sysmap);
         $actionMap = getActionMapBySysmap($sysmap);
         $image->setMap($actionMap->getName());
         $output = array($actionMap, $image);
     } elseif ($this->mode == SCREEN_MODE_EDIT) {
         $output = array($image, BR(), new CLink(_('Change'), $this->action));
     } else {
         $output = array($image);
     }
     $this->insertFlickerfreeJs();
     $div = new CDiv($output, 'map-container flickerfreescreen', $this->getScreenId());
     $div->setAttribute('data-timestamp', $this->timestamp);
     $div->addStyle('position: relative;');
     return $div;
 }
示例#7
0
} elseif ($srctbl == 'sysmaps') {
    $form = new CForm();
    $form->setName('sysmapform');
    $form->setAttribute('id', 'sysmaps');
    $table = new CTableInfo(_('No maps found.'));
    if ($multiselect) {
        $header = array(array(new CCheckBox('all_sysmaps', null, "javascript: checkAll('" . $form->getName() . "', 'all_sysmaps', 'sysmaps');"), _('Name')));
    } else {
        $header = array(_('Name'));
    }
    $table->setHeader($header);
    $options = array('nodeids' => $nodeId, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true);
    if (!is_null($writeonly)) {
        $options['editable'] = true;
    }
    $sysmaps = API::Map()->get($options);
    order_result($sysmaps, 'name');
    foreach ($sysmaps as $sysmap) {
        $sysmap['node_name'] = isset($sysmap['node_name']) ? '(' . $sysmap['node_name'] . ') ' : '';
        $name = $sysmap['node_name'] . $sysmap['name'];
        $description = new CSpan($sysmap['name'], 'link');
        if ($multiselect) {
            $js_action = 'javascript: addValue(' . zbx_jsvalue($reference) . ', ' . zbx_jsvalue($sysmap['sysmapid']) . ');';
        } else {
            $values = array($dstfld1 => $sysmap[$srcfld1], $dstfld2 => $sysmap[$srcfld2]);
            $js_action = 'javascript: addValues(' . zbx_jsvalue($dstfrm) . ', ' . zbx_jsvalue($values) . '); close_window(); return false;';
        }
        if (isset($excludeids[$sysmap['sysmapid']])) {
            $description->removeAttr('class');
        } else {
            $description->setAttribute('onclick', $js_action . ' jQuery(this).removeAttr("onclick");');
示例#8
0
/**
 * Get favourite maps data.
 *
 * @return array
 */
function getFavouriteMapsData()
{
    $maps = [];
    $favourites = CFavorite::get('web.favorite.sysmapids');
    if ($favourites) {
        $mapIds = [];
        foreach ($favourites as $favourite) {
            $mapIds[$favourite['value']] = $favourite['value'];
        }
        $dbMaps = API::Map()->get(['output' => ['sysmapid', 'name'], 'sysmapids' => $mapIds]);
        foreach ($dbMaps as $dbMap) {
            $maps[] = ['id' => $dbMap['sysmapid'], 'label' => $dbMap['name']];
        }
    }
    return $maps;
}
 /**
  * Get maps references by map ids.
  *
  * @param array $mapIds
  *
  * @return array
  */
 protected function getMapsReferences(array $mapIds)
 {
     $idents = array();
     $maps = API::Map()->get(array('sysmapids' => $mapIds, 'output' => array('name'), 'nodeids' => get_current_nodeid(true), 'preservekeys' => true));
     foreach ($maps as $id => $map) {
         $idents[$id] = array('name' => $map['name']);
     }
     return $idents;
 }
示例#10
0
            ob_clean();
            echo 'alert(' . zbx_jsvalue(implode("\r\n", $msg)) . ');';
        }
        @ob_flush();
        exit;
    }
}
if (PAGE_TYPE_HTML != $page['type']) {
    require_once dirname(__FILE__) . '/include/page_footer.php';
    exit;
}
/*
 * Permissions
 */
if (isset($_REQUEST['sysmapid'])) {
    $sysmap = API::Map()->get(['output' => ['sysmapid', 'expand_macros', 'grid_show', 'grid_align', 'grid_size', 'width', 'height', 'iconmapid'], 'selectSelements' => API_OUTPUT_EXTEND, 'selectLinks' => API_OUTPUT_EXTEND, 'sysmapids' => getRequest('sysmapid'), 'editable' => true, 'preservekeys' => true]);
    if (empty($sysmap)) {
        access_deny();
    } else {
        $sysmap = reset($sysmap);
    }
}
/*
 * Display
 */
$data = ['sysmap' => $sysmap, 'iconList' => [], 'defaultAutoIconId' => null, 'defaultIconId' => null, 'defaultIconName' => null];
// get selements
add_elementNames($data['sysmap']['selements']);
$data['sysmap']['selements'] = zbx_toHash($data['sysmap']['selements'], 'selementid');
$data['sysmap']['links'] = zbx_toHash($data['sysmap']['links'], 'linkid');
// get links
示例#11
0
    unset($_REQUEST['sysmapid']);
    foreach ($maps as $map) {
        if ($map['name'] === $mapName) {
            $_REQUEST['sysmapid'] = $map['sysmapid'];
        }
    }
} elseif (empty($_REQUEST['sysmapid'])) {
    $_REQUEST['sysmapid'] = CProfile::get('web.maps.sysmapid');
    if (!$_REQUEST['sysmapid'] && !isset($maps[$_REQUEST['sysmapid']])) {
        if ($firstMap = reset($maps)) {
            $_REQUEST['sysmapid'] = $firstMap['sysmapid'];
        }
    }
}
if (isset($_REQUEST['sysmapid']) && !isset($maps[$_REQUEST['sysmapid']])) {
    access_deny();
}
CProfile::update('web.maps.sysmapid', $_REQUEST['sysmapid'], PROFILE_TYPE_ID);
/*
 * Display
 */
$data = array('fullscreen' => $_REQUEST['fullscreen'], 'sysmapid' => $_REQUEST['sysmapid'], 'maps' => $maps);
$data['map'] = API::Map()->get(array('output' => API_OUTPUT_EXTEND, 'sysmapids' => $data['sysmapid'], 'expandUrls' => true, 'selectSelements' => API_OUTPUT_EXTEND, 'selectLinks' => API_OUTPUT_EXTEND, 'preservekeys' => true));
$data['map'] = reset($data['map']);
$data['pageFilter'] = new CPageFilter(array('severitiesMin' => array('default' => $data['map']['severity_min'], 'mapId' => $data['sysmapid']), 'severityMin' => get_request('severity_min')));
$data['severity_min'] = $data['pageFilter']->severityMin;
// render view
$mapsView = new CView('monitoring.maps', $data);
$mapsView->render();
$mapsView->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
示例#12
0
 /**
  * Select map ids for previously added maps names.
  */
 protected function selectMaps()
 {
     if (!empty($this->maps)) {
         $this->mapsRefs = [];
         $dbMaps = API::Map()->get(['filter' => ['name' => $this->maps], 'output' => ['sysmapid', 'name'], 'preservekeys' => true]);
         foreach ($dbMaps as $dbMap) {
             $this->mapsRefs[$dbMap['name']] = $dbMap['sysmapid'];
         }
         $this->maps = [];
     }
 }
示例#13
0
 /**
  * Validates screen items.
  *
  * If the $dbScreenItems parameter is given, the screen items will be matched
  * against the ones given in $dbScreenItems. If a screen item is not present in
  * $dbScreenItems, a ZBX_API_ERROR_PERMISSIONS exception will be thrown.
  *
  * @throws APIException if a validation error occurred.
  *
  * @param array $screenItems
  * @param array $dbScreenItems
  */
 protected function checkInput(array $screenItems, array $dbScreenItems = array())
 {
     $hostGroupsIds = array();
     $hostIds = array();
     $graphIds = array();
     $itemIds = array();
     $mapIds = array();
     $screenIds = array();
     $itemPrototypeIds = array();
     $graphPrototypeIds = array();
     $screenItems = $this->extendFromObjects($screenItems, $dbScreenItems, array('resourcetype'));
     $validStyles = array(SCREEN_RESOURCE_CLOCK => array(TIME_TYPE_LOCAL, TIME_TYPE_SERVER, TIME_TYPE_HOST), SCREEN_RESOURCE_DATA_OVERVIEW => array(STYLE_TOP, STYLE_LEFT), SCREEN_RESOURCE_TRIGGERS_OVERVIEW => array(STYLE_TOP, STYLE_LEFT), SCREEN_RESOURCE_HOSTS_INFO => array(STYLE_VERTICAL, STYLE_HORIZONTAL), SCREEN_RESOURCE_TRIGGERS_INFO => array(STYLE_VERTICAL, STYLE_HORIZONTAL));
     foreach ($screenItems as $screenItem) {
         // check permissions
         if (isset($screenItem['screenitemid']) && !isset($dbScreenItems[$screenItem['screenitemid']])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
         if (!$this->isValidResourceType($screenItem['resourcetype'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect resource type provided for screen item.'));
         }
         if (!isset($screenItem['resourceid'])) {
             $screenItem['resourceid'] = null;
         }
         // check resource id
         switch ($screenItem['resourcetype']) {
             case SCREEN_RESOURCE_HOSTS_INFO:
             case SCREEN_RESOURCE_TRIGGERS_INFO:
             case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
             case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
             case SCREEN_RESOURCE_DATA_OVERVIEW:
                 $overviewResources = array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW);
                 if (in_array($screenItem['resourcetype'], $overviewResources)) {
                     if (!$screenItem['resourceid']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('No host group ID provided for screen element.'));
                     }
                 }
                 if ($screenItem['resourceid']) {
                     $hostGroupsIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_HOST_TRIGGERS:
                 if ($screenItem['resourceid']) {
                     $hostIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_GRAPH:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No graph ID provided for screen element.'));
                 }
                 $graphIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_LLD_GRAPH:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No graph prototype ID provided for screen element.'));
                 }
                 $graphPrototypeIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_LLD_SIMPLE_GRAPH:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No item prototype ID provided for screen element.'));
                 }
                 $itemPrototypeIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_SIMPLE_GRAPH:
             case SCREEN_RESOURCE_PLAIN_TEXT:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
                 }
                 $itemIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_CLOCK:
                 if (isset($screenItem['style'])) {
                     if ($screenItem['style'] == TIME_TYPE_HOST) {
                         if (!$screenItem['resourceid']) {
                             self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
                         }
                         $itemIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                     } elseif ($screenItem['resourceid']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot set resource ID for screen element.'));
                     }
                 }
                 break;
             case SCREEN_RESOURCE_MAP:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No map ID provided for screen element.'));
                 }
                 $mapIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_SCREEN:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No screen ID provided for screen element.'));
                 }
                 $screenIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_ACTIONS:
             case SCREEN_RESOURCE_SERVER_INFO:
             case SCREEN_RESOURCE_SYSTEM_STATUS:
             case SCREEN_RESOURCE_URL:
                 if ($screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('Cannot set resource ID for screen element.'));
                 }
                 break;
         }
         // check url
         if ($screenItem['resourcetype'] == SCREEN_RESOURCE_URL) {
             if (!isset($screenItem['url']) || zbx_empty($screenItem['url'])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No URL provided for screen element.'));
             }
         }
         // check "Show lines"
         if (isset($screenItem['elements'])) {
             switch ($screenItem['resourcetype']) {
                 case SCREEN_RESOURCE_ACTIONS:
                 case SCREEN_RESOURCE_EVENTS:
                 case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
                 case SCREEN_RESOURCE_HOST_TRIGGERS:
                 case SCREEN_RESOURCE_PLAIN_TEXT:
                     if ($screenItem['elements'] < 1 || $screenItem['elements'] > 100) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $screenItem['elements'], 'elements', 1, 100));
                     }
                     break;
             }
         }
         // check 'max_columns' parameter for LLD screen resources:
         // is set and valid for create method, and is valid for update method, if set
         $dbScreenItem = isset($screenItem['screenitemid']) ? $dbScreenItems[$screenItem['screenitemid']] : null;
         $lldResources = array(SCREEN_RESOURCE_LLD_GRAPH, SCREEN_RESOURCE_LLD_SIMPLE_GRAPH);
         if (in_array($screenItem['resourcetype'], $lldResources)) {
             $set = isset($screenItem['max_columns']);
             $valid = $set && $this->isValidMaxColumns($screenItem['max_columns']);
             $error = $dbScreenItem ? $set && !$valid : !$set || !$valid;
             if ($error) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect max columns provided for screen element.'));
             }
         }
         if (isset($validStyles[$screenItem['resourcetype']]) && !in_array($screenItem['style'], $validStyles[$screenItem['resourcetype']])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect style provided for screen element.'));
         }
     }
     // check host groups
     if ($hostGroupsIds) {
         $dbHostGroups = API::HostGroup()->get(array('output' => array('groupid'), 'groupids' => $hostGroupsIds, 'editable' => true, 'preservekeys' => true));
         foreach ($hostGroupsIds as $hostGroupsId) {
             if (!isset($dbHostGroups[$hostGroupsId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host group ID "%1$s" provided for screen element.', $hostGroupsId));
             }
         }
     }
     // check hosts
     if ($hostIds) {
         $dbHosts = API::Host()->get(array('output' => array('hostid'), 'hostids' => $hostIds, 'editable' => true, 'preservekeys' => true));
         foreach ($hostIds as $hostId) {
             if (!isset($dbHosts[$hostId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host ID "%1$s" provided for screen element.', $hostId));
             }
         }
     }
     // check graphs
     if ($graphIds) {
         $dbGraphs = API::Graph()->get(array('output' => array('graphid'), 'graphids' => $graphIds, 'editable' => true, 'preservekeys' => true));
         foreach ($graphIds as $graphId) {
             if (!isset($dbGraphs[$graphId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph ID "%1$s" provided for screen element.', $graphId));
             }
         }
     }
     // check graph prototypes
     if ($graphPrototypeIds) {
         $dbGraphPrototypes = API::GraphPrototype()->get(array('output' => array('graphid'), 'graphids' => $graphPrototypeIds, 'editable' => true, 'preservekeys' => true));
         foreach ($graphPrototypeIds as $graphPrototypeId) {
             if (!isset($dbGraphPrototypes[$graphPrototypeId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph prototype ID "%1$s" provided for screen element.', $graphPrototypeId));
             }
         }
     }
     // check items
     if ($itemIds) {
         $dbItems = API::Item()->get(array('output' => array('itemid'), 'itemids' => $itemIds, 'editable' => true, 'preservekeys' => true, 'webitems' => true));
         foreach ($itemIds as $itemId) {
             if (!isset($dbItems[$itemId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item ID "%1$s" provided for screen element.', $itemId));
             }
         }
     }
     // check item prototypes
     if ($itemPrototypeIds) {
         $dbItemPrototypes = API::ItemPrototype()->get(array('output' => array('itemid'), 'itemids' => $itemPrototypeIds, 'editable' => true, 'preservekeys' => true));
         foreach ($itemPrototypeIds as $itemPrototypeId) {
             if (!isset($dbItemPrototypes[$itemPrototypeId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item prototype ID "%1$s" provided for screen element.', $itemPrototypeId));
             }
         }
     }
     // check maps
     if ($mapIds) {
         $dbMaps = API::Map()->get(array('output' => array('sysmapid'), 'sysmapids' => $mapIds, 'editable' => true, 'preservekeys' => true));
         foreach ($mapIds as $mapId) {
             if (!isset($dbMaps[$mapId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect map ID "%1$s" provided for screen element.', $mapId));
             }
         }
     }
     // check screens
     if ($screenIds) {
         $dbScreens = API::Screen()->get(array('output' => array('screenid'), 'screenids' => $screenIds, 'editable' => true, 'preservekeys' => true));
         if (count($dbScreens) < count($screenIds)) {
             $dbTemplateScreens = API::TemplateScreen()->get(array('output' => array('screenid'), 'screenids' => $screenIds, 'editable' => true, 'preservekeys' => true));
             if ($dbTemplateScreens) {
                 $dbScreens = zbx_array_merge($dbScreens, $dbTemplateScreens);
             }
         }
         foreach ($screenIds as $screenId) {
             if (!isset($dbScreens[$screenId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect screen ID "%1$s" provided for screen element.', $screenId));
             }
         }
     }
 }
示例#14
0
 /**
  * Validates screen items.
  *
  * If the $dbScreenItems parameter is given, the screen items will be matched
  * against the ones given in $dbScreenItems. If a screen item is not present in
  * $dbScreenItems, a ZBX_API_ERROR_PERMISSIONS exception will be thrown.
  *
  * @throws APIException if a validation error occurred.
  *
  * @param array $screenItems
  * @param array $dbScreenItems
  */
 protected function checkInput(array $screenItems, array $dbScreenItems = array())
 {
     $hostGroupsIds = $hostIds = $graphIds = $itemIds = $mapIds = $screenIds = array();
     $screenItems = $this->extendFromObjects($screenItems, $dbScreenItems, array('resourcetype', 'resourceid'));
     foreach ($screenItems as $screenItem) {
         // check permissions
         if (isset($screenItem['screenitemid']) && !isset($dbScreenItems[$screenItem['screenitemid']])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
         if (!$this->isValidResourceType($screenItem['resourcetype'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect resource type provided for screen item.'));
         }
         if (!isset($screenItem['resourceid'])) {
             $screenItem['resourceid'] = null;
         }
         // check resource id
         switch ($screenItem['resourcetype']) {
             case SCREEN_RESOURCE_HOSTS_INFO:
             case SCREEN_RESOURCE_TRIGGERS_INFO:
             case SCREEN_RESOURCE_TRIGGERS_OVERVIEW:
             case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
             case SCREEN_RESOURCE_DATA_OVERVIEW:
                 if (in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW))) {
                     if (!$screenItem['resourceid']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('No host group ID provided for screen element.'));
                     }
                 }
                 if ($screenItem['resourceid']) {
                     $hostGroupsIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_HOST_TRIGGERS:
                 if ($screenItem['resourceid']) {
                     $hostIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_GRAPH:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No graph ID provided for screen element.'));
                 }
                 $graphIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_SIMPLE_GRAPH:
             case SCREEN_RESOURCE_PLAIN_TEXT:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
                 }
                 $itemIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_CLOCK:
                 if (isset($screenItem['style']) && $screenItem['style'] == TIME_TYPE_HOST) {
                     if (!$screenItem['resourceid']) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
                     }
                     $itemIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 }
                 break;
             case SCREEN_RESOURCE_MAP:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No map ID provided for screen element.'));
                 }
                 $mapIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
             case SCREEN_RESOURCE_SCREEN:
                 if (!$screenItem['resourceid']) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _('No screen ID provided for screen element.'));
                 }
                 $screenIds[$screenItem['resourceid']] = $screenItem['resourceid'];
                 break;
         }
         // check url
         if ($screenItem['resourcetype'] == SCREEN_RESOURCE_URL) {
             if (!isset($screenItem['url']) || zbx_empty($screenItem['url'])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No URL provided for screen element.'));
             }
         }
         // check "Show lines"
         if (isset($screenItem['elements'])) {
             switch ($screenItem['resourcetype']) {
                 case SCREEN_RESOURCE_ACTIONS:
                 case SCREEN_RESOURCE_EVENTS:
                 case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
                 case SCREEN_RESOURCE_HOST_TRIGGERS:
                 case SCREEN_RESOURCE_PLAIN_TEXT:
                     if ($screenItem['elements'] < 1 || $screenItem['elements'] > 100) {
                         self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $screenItem['elements'], 'elements', 1, 100));
                     }
                     break;
             }
         }
     }
     // check host groups
     if ($hostGroupsIds) {
         $dbHostGroups = API::HostGroup()->get(array('groupids' => $hostGroupsIds, 'output' => array('groupid'), 'editable' => true, 'preservekeys' => true));
         foreach ($hostGroupsIds as $hostGroupsId) {
             if (!isset($dbHostGroups[$hostGroupsId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host group ID "%1$s" provided for screen element.', $hostGroupsId));
             }
         }
     }
     // check hosts
     if ($hostIds) {
         $dbHosts = API::Host()->get(array('hostids' => $hostIds, 'output' => array('hostid'), 'editable' => true, 'preservekeys' => true));
         foreach ($hostIds as $hostId) {
             if (!isset($dbHosts[$hostId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host ID "%1$s" provided for screen element.', $hostId));
             }
         }
     }
     // check graphs
     if ($graphIds) {
         $dbGraphs = API::Graph()->get(array('graphids' => $graphIds, 'output' => array('graphid'), 'editable' => true, 'preservekeys' => true));
         foreach ($graphIds as $graphId) {
             if (!isset($dbGraphs[$graphId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph ID "%1$s" provided for screen element.', $graphId));
             }
         }
     }
     // check items
     if ($itemIds) {
         $dbItems = API::Item()->get(array('itemids' => $itemIds, 'output' => array('itemid'), 'editable' => true, 'preservekeys' => true, 'webitems' => true));
         foreach ($itemIds as $itemId) {
             if (!isset($dbItems[$itemId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item ID "%1$s" provided for screen element.', $itemId));
             }
         }
     }
     // check maps
     if ($mapIds) {
         $dbMaps = API::Map()->get(array('sysmapids' => $mapIds, 'output' => array('sysmapid'), 'editable' => true, 'preservekeys' => true));
         foreach ($mapIds as $mapId) {
             if (!isset($dbMaps[$mapId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect map ID "%1$s" provided for screen element.', $mapId));
             }
         }
     }
     // check screens
     if ($screenIds) {
         $dbScreens = API::Screen()->get(array('screenids' => $screenIds, 'output' => array('screenid'), 'editable' => true, 'preservekeys' => true));
         if (count($dbScreens) < count($screenIds)) {
             $dbTemplateScreens = API::TemplateScreen()->get(array('screenids' => $screenIds, 'output' => array('screenid'), 'editable' => true, 'preservekeys' => true));
             if ($dbTemplateScreens) {
                 $dbScreens = zbx_array_merge($dbScreens, $dbTemplateScreens);
             }
         }
         foreach ($screenIds as $screenId) {
             if (!isset($dbScreens[$screenId])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect screen ID "%1$s" provided for screen element.', $screenId));
             }
         }
     }
 }
示例#15
0
/**
 * Prepare map elements data.
 * Calculate problem triggers and priorities. Populate map elements with automatic icon mapping, acknowledging and
 * recent change markers.
 *
 * @param array $sysmap
 * @param int   $options
 * @param int   $options['severity_min'] Minimum trigger severity, default value is maximal (Disaster)
 *
 * @return array
 */
function getSelementsInfo($sysmap, array $options = array())
{
    if (!isset($options['severity_min'])) {
        $options['severity_min'] = TRIGGER_SEVERITY_NOT_CLASSIFIED;
    }
    $config = select_config();
    $showUnacknowledged = $config['event_ack_enable'] ? $sysmap['show_unack'] : EXTACK_OPTION_ALL;
    $triggerIdToSelementIds = array();
    $subSysmapTriggerIdToSelementIds = array();
    $hostGroupIdToSelementIds = array();
    $hostIdToSelementIds = array();
    if ($sysmap['sysmapid']) {
        $iconMap = API::IconMap()->get(array('sysmapids' => $sysmap['sysmapid'], 'selectMappings' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND));
        $iconMap = reset($iconMap);
    }
    $hostsToGetInventories = array();
    $selements = $sysmap['selements'];
    $selementIdToSubSysmaps = array();
    foreach ($selements as $selementId => &$selement) {
        $selement['hosts'] = array();
        $selement['triggers'] = array();
        switch ($selement['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_MAP:
                $sysmapIds = array($selement['elementid']);
                while (!empty($sysmapIds)) {
                    $subSysmaps = API::Map()->get(array('sysmapids' => $sysmapIds, 'output' => array('sysmapid'), 'selectSelements' => API_OUTPUT_EXTEND, 'nopermissions' => true, 'preservekeys' => true));
                    if (!isset($selementIdToSubSysmaps[$selementId])) {
                        $selementIdToSubSysmaps[$selementId] = array();
                    }
                    $selementIdToSubSysmaps[$selementId] += $subSysmaps;
                    $sysmapIds = array();
                    foreach ($subSysmaps as $subSysmap) {
                        foreach ($subSysmap['selements'] as $subSysmapSelement) {
                            switch ($subSysmapSelement['elementtype']) {
                                case SYSMAP_ELEMENT_TYPE_MAP:
                                    $sysmapIds[] = $subSysmapSelement['elementid'];
                                    break;
                                case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                                    $hostGroupIdToSelementIds[$subSysmapSelement['elementid']][$selementId] = $selementId;
                                    break;
                                case SYSMAP_ELEMENT_TYPE_HOST:
                                    $hostIdToSelementIds[$subSysmapSelement['elementid']][$selementId] = $selementId;
                                    break;
                                case SYSMAP_ELEMENT_TYPE_TRIGGER:
                                    $subSysmapTriggerIdToSelementIds[$subSysmapSelement['elementid']][$selementId] = $selementId;
                                    break;
                            }
                        }
                    }
                }
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $hostGroupId = $selement['elementid'];
                $hostGroupIdToSelementIds[$hostGroupId][$selementId] = $selementId;
                break;
            case SYSMAP_ELEMENT_TYPE_HOST:
                $hostId = $selement['elementid'];
                $hostIdToSelementIds[$hostId][$selementId] = $selementId;
                // if we have icon map applied, we need to get inventories for all hosts,
                // where automatic icon selection is enabled.
                if ($sysmap['iconmapid'] && $selement['use_iconmap']) {
                    $hostsToGetInventories[] = $hostId;
                }
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $triggerId = $selement['elementid'];
                $triggerIdToSelementIds[$triggerId][$selementId] = $selementId;
                break;
        }
    }
    unset($selement);
    // get host inventories
    if ($sysmap['iconmapid']) {
        $hostInventories = API::Host()->get(array('hostids' => $hostsToGetInventories, 'output' => array('hostid'), 'nopermissions' => true, 'preservekeys' => true, 'selectInventory' => API_OUTPUT_EXTEND));
    }
    $allHosts = array();
    if (!empty($hostIdToSelementIds)) {
        $hosts = API::Host()->get(array('hostids' => array_keys($hostIdToSelementIds), 'output' => array('name', 'status', 'maintenance_status', 'maintenanceid'), 'nopermissions' => true, 'preservekeys' => true));
        $allHosts = array_merge($allHosts, $hosts);
        foreach ($hosts as $hostId => $host) {
            foreach ($hostIdToSelementIds[$hostId] as $selementId) {
                $selements[$selementId]['hosts'][$hostId] = $hostId;
            }
        }
    }
    $hostsFromHostGroups = array();
    if (!empty($hostGroupIdToSelementIds)) {
        $hostsFromHostGroups = API::Host()->get(array('groupids' => array_keys($hostGroupIdToSelementIds), 'output' => array('name', 'status', 'maintenance_status', 'maintenanceid'), 'selectGroups' => array('groupid'), 'nopermissions' => true, 'preservekeys' => true));
        foreach ($hostsFromHostGroups as $hostId => $host) {
            foreach ($host['groups'] as $group) {
                $groupId = $group['groupid'];
                if (isset($hostGroupIdToSelementIds[$groupId])) {
                    foreach ($hostGroupIdToSelementIds[$groupId] as $selementId) {
                        $selement =& $selements[$selementId];
                        $selement['hosts'][$hostId] = $hostId;
                        // add hosts to hosts_map for trigger selection;
                        if (!isset($hostIdToSelementIds[$hostId])) {
                            $hostIdToSelementIds[$hostId] = array();
                        }
                        $hostIdToSelementIds[$hostId][$selementId] = $selementId;
                        unset($selement);
                    }
                }
            }
        }
        $allHosts = array_merge($allHosts, $hostsFromHostGroups);
    }
    $allHosts = zbx_toHash($allHosts, 'hostid');
    // get triggers data, triggers from current map, select all
    $allTriggers = array();
    if (!empty($triggerIdToSelementIds)) {
        $triggerOptions = array('output' => array('triggerid', 'status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'triggerids' => array_keys($triggerIdToSelementIds), 'filter' => array('state' => null), 'nopermissions' => true, 'preservekeys' => true);
        if ($showUnacknowledged) {
            $triggerOptions['selectLastEvent'] = array('acknowledged');
        }
        $triggers = API::Trigger()->get($triggerOptions);
        $allTriggers = array_merge($allTriggers, $triggers);
        foreach ($triggers as $triggerId => $trigger) {
            foreach ($triggerIdToSelementIds[$triggerId] as $selementId) {
                $selements[$selementId]['triggers'][$triggerId] = $triggerId;
            }
        }
    }
    // triggers from submaps, skip dependent
    if (!empty($subSysmapTriggerIdToSelementIds)) {
        $triggerOptions = array('output' => array('triggerid', 'status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'triggerids' => array_keys($subSysmapTriggerIdToSelementIds), 'filter' => array('state' => null), 'skipDependent' => true, 'nopermissions' => true, 'preservekeys' => true, 'only_true' => true);
        if ($showUnacknowledged) {
            $triggerOptions['selectLastEvent'] = array('acknowledged');
        }
        $triggers = API::Trigger()->get($triggerOptions);
        $allTriggers = array_merge($allTriggers, $triggers);
        foreach ($triggers as $triggerId => $trigger) {
            foreach ($subSysmapTriggerIdToSelementIds[$triggerId] as $selementId) {
                $selements[$selementId]['triggers'][$triggerId] = $triggerId;
            }
        }
    }
    $monitoredHostIds = array();
    foreach ($allHosts as $hostId => $host) {
        if ($host['status'] == HOST_STATUS_MONITORED) {
            $monitoredHostIds[$hostId] = $hostId;
        }
    }
    // triggers from all hosts/hostgroups, skip dependent
    if ($monitoredHostIds) {
        $triggerOptions = array('output' => array('triggerid', 'status', 'value', 'priority', 'lastchange', 'description', 'expression'), 'selectHosts' => array('hostid'), 'selectItems' => array('itemid'), 'hostids' => $monitoredHostIds, 'filter' => array('state' => null), 'monitored' => true, 'skipDependent' => true, 'nopermissions' => true, 'preservekeys' => true, 'only_true' => true);
        if ($showUnacknowledged) {
            $triggerOptions['selectLastEvent'] = array('acknowledged');
        }
        $triggersFromMonitoredHosts = API::Trigger()->get($triggerOptions);
        foreach ($triggersFromMonitoredHosts as $triggerId => $trigger) {
            foreach ($trigger['hosts'] as $host) {
                $hostId = $host['hostid'];
                if (isset($hostIdToSelementIds[$hostId])) {
                    foreach ($hostIdToSelementIds[$hostId] as $selementId) {
                        $selements[$selementId]['triggers'][$triggerId] = $triggerId;
                    }
                }
            }
        }
        $subSysmapHostApplicationFilters = getSelementHostApplicationFilters($selements, $selementIdToSubSysmaps, $hostsFromHostGroups);
        $selements = filterSysmapTriggers($selements, $subSysmapHostApplicationFilters, $triggersFromMonitoredHosts, $subSysmapTriggerIdToSelementIds);
        $allTriggers = array_merge($allTriggers, $triggersFromMonitoredHosts);
    }
    $allTriggers = zbx_toHash($allTriggers, 'triggerid');
    $info = array();
    foreach ($selements as $selementId => $selement) {
        $i = array('disabled' => 0, 'maintenance' => 0, 'problem' => 0, 'problem_unack' => 0, 'priority' => 0, 'trigger_disabled' => 0, 'latelyChanged' => false, 'ack' => true);
        foreach ($selement['hosts'] as $hostId) {
            $host = $allHosts[$hostId];
            $last_hostid = $hostId;
            if ($host['status'] == HOST_STATUS_NOT_MONITORED) {
                $i['disabled']++;
            } elseif ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) {
                $i['maintenance']++;
            }
        }
        foreach ($selement['triggers'] as $triggerId) {
            $trigger = $allTriggers[$triggerId];
            if ($options['severity_min'] <= $trigger['priority']) {
                if ($trigger['status'] == TRIGGER_STATUS_DISABLED) {
                    $i['trigger_disabled']++;
                } else {
                    if ($trigger['value'] == TRIGGER_VALUE_TRUE) {
                        $i['problem']++;
                        $lastProblemId = $triggerId;
                        if ($i['priority'] < $trigger['priority']) {
                            $i['priority'] = $trigger['priority'];
                        }
                    }
                    if ($showUnacknowledged && $trigger['lastEvent'] && !$trigger['lastEvent']['acknowledged']) {
                        $i['problem_unack']++;
                    }
                    $i['latelyChanged'] |= time() - $trigger['lastchange'] < $config['blink_period'];
                }
            }
        }
        $i['ack'] = (bool) (!$i['problem_unack']);
        if ($sysmap['expandproblem'] && $i['problem'] == 1) {
            if (!isset($lastProblemId)) {
                $lastProblemId = null;
            }
            $i['problem_title'] = CMacrosResolverHelper::resolveTriggerName($allTriggers[$lastProblemId]);
        }
        if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && $i['maintenance'] == 1) {
            $mnt = get_maintenance_by_maintenanceid($allHosts[$last_hostid]['maintenanceid']);
            $i['maintenance_title'] = $mnt['name'];
        }
        // replace default icons
        if (!$selement['iconid_on']) {
            $selement['iconid_on'] = $selement['iconid_off'];
        }
        if (!$selement['iconid_maintenance']) {
            $selement['iconid_maintenance'] = $selement['iconid_off'];
        }
        if (!$selement['iconid_disabled']) {
            $selement['iconid_disabled'] = $selement['iconid_off'];
        }
        switch ($selement['elementtype']) {
            case SYSMAP_ELEMENT_TYPE_MAP:
                $info[$selementId] = getMapsInfo($selement, $i, $showUnacknowledged);
                break;
            case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                $info[$selementId] = getHostGroupsInfo($selement, $i, $showUnacknowledged);
                break;
            case SYSMAP_ELEMENT_TYPE_HOST:
                $info[$selementId] = getHostsInfo($selement, $i, $showUnacknowledged);
                if ($sysmap['iconmapid'] && $selement['use_iconmap']) {
                    $info[$selementId]['iconid'] = getIconByMapping($iconMap, $hostInventories[$selement['elementid']]);
                }
                break;
            case SYSMAP_ELEMENT_TYPE_TRIGGER:
                $info[$selementId] = getTriggersInfo($selement, $i, $showUnacknowledged);
                break;
            case SYSMAP_ELEMENT_TYPE_IMAGE:
                $info[$selementId] = getImagesInfo($selement);
                break;
        }
    }
    if ($sysmap['label_format'] == SYSMAP_LABEL_ADVANCED_OFF) {
        $hlabel = $hglabel = $tlabel = $mlabel = $sysmap['label_type'] == MAP_LABEL_TYPE_NAME;
    } else {
        $hlabel = $sysmap['label_type_host'] == MAP_LABEL_TYPE_NAME;
        $hglabel = $sysmap['label_type_hostgroup'] == MAP_LABEL_TYPE_NAME;
        $tlabel = $sysmap['label_type_trigger'] == MAP_LABEL_TYPE_NAME;
        $mlabel = $sysmap['label_type_map'] == MAP_LABEL_TYPE_NAME;
    }
    // get names if needed
    $elems = separateMapElements($sysmap);
    if (!empty($elems['sysmaps']) && $mlabel) {
        $subSysmaps = API::Map()->get(array('sysmapids' => zbx_objectValues($elems['sysmaps'], 'elementid'), 'nopermissions' => true, 'output' => array('name')));
        $subSysmaps = zbx_toHash($subSysmaps, 'sysmapid');
        foreach ($elems['sysmaps'] as $elem) {
            $info[$elem['selementid']]['name'] = $subSysmaps[$elem['elementid']]['name'];
        }
    }
    if (!empty($elems['hostgroups']) && $hglabel) {
        $hostgroups = API::HostGroup()->get(array('groupids' => zbx_objectValues($elems['hostgroups'], 'elementid'), 'nopermissions' => true, 'output' => array('name')));
        $hostgroups = zbx_toHash($hostgroups, 'groupid');
        foreach ($elems['hostgroups'] as $elem) {
            $info[$elem['selementid']]['name'] = $hostgroups[$elem['elementid']]['name'];
        }
    }
    if (!empty($elems['triggers']) && $tlabel) {
        foreach ($elems['triggers'] as $elem) {
            $info[$elem['selementid']]['name'] = CMacrosResolverHelper::resolveTriggerName($allTriggers[$elem['elementid']]);
        }
    }
    if (!empty($elems['hosts']) && $hlabel) {
        foreach ($elems['hosts'] as $elem) {
            $info[$elem['selementid']]['name'] = $allHosts[$elem['elementid']]['name'];
        }
    }
    return $info;
}
        $nodeName = get_node_name_by_elid($item['itemid']);
        if (!zbx_empty($nodeName)) {
            $caption = '(' . $nodeName . ') ' . $caption;
        }
    }
    if ($this->data['screen']['templateid']) {
        $selectButton = new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=items&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&templated_hosts=1&only_hostid=' . $this->data['screen']['templateid'] . '&templated=1&writeonly=1&numeric=1", 800, 450);', 'formlist');
    } else {
        $selectButton = new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=items&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&real_hosts=1&with_simple_graph_items=1&writeonly=1&templated=0&numeric=1", 800, 450);', 'formlist');
    }
    $screenFormList->addVar('resourceid', $id);
    $screenFormList->addRow(_('Parameter'), array(new CTextBox('caption', $caption, ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), $selectButton));
} elseif ($resourceType == SCREEN_RESOURCE_MAP) {
    $caption = '';
    $id = 0;
    $maps = API::Map()->get(array('sysmapids' => $resourceId, 'output' => API_OUTPUT_EXTEND));
    if (!empty($maps)) {
        $id = $resourceId;
        $map = reset($maps);
        $caption = $map['name'];
        $nodeName = get_node_name_by_elid($map['sysmapid']);
        if (!zbx_empty($nodeName)) {
            $caption = '(' . $nodeName . ') ' . $caption;
        }
    }
    $screenFormList->addVar('resourceid', $id);
    $screenFormList->addRow(_('Parameter'), array(new CTextBox('caption', $caption, ZBX_TEXTBOX_STANDARD_SIZE, 'yes'), new CButton('select', _('Select'), 'javascript: return PopUp("popup.php?srctbl=sysmaps&srcfld1=sysmapid&srcfld2=name' . '&dstfrm=' . $screenForm->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&writeonly=1", 400, 450);', 'formlist')));
} elseif ($resourceType == SCREEN_RESOURCE_PLAIN_TEXT) {
    $caption = '';
    $id = 0;
    $items = API::Item()->get(array('itemids' => $resourceId, 'selectHosts' => array('name'), 'output' => array('itemid', 'hostid', 'key_', 'name')));
示例#17
0
/**
 * Get parent maps for current map.
 *
 * @param int $sysmapid
 *
 * @return array
 */
function get_parent_sysmaps($sysmapid)
{
    $db_sysmaps_elements = DBselect('SELECT DISTINCT se.sysmapid' . ' FROM sysmaps_elements se' . ' WHERE ' . dbConditionInt('se.elementtype', [SYSMAP_ELEMENT_TYPE_MAP]) . ' AND ' . dbConditionInt('se.elementid', [$sysmapid]));
    $sysmapids = [];
    while ($db_sysmaps_element = DBfetch($db_sysmaps_elements)) {
        $sysmapids[] = $db_sysmaps_element['sysmapid'];
    }
    if ($sysmapids) {
        $sysmaps = API::Map()->get(['output' => ['sysmapid', 'name'], 'sysmapids' => $sysmapids]);
        CArrayHelper::sort($sysmaps, ['name']);
        return $sysmaps;
    }
    return [];
}
示例#18
0
 /**
  * Validates the given screen items.
  *
  * If the $dbScreenItems parameter is given, the screen items will be matched
  * against the ones given in $dbScreenItems. If a screen item is not present in
  * $dbScreenItems, a ZBX_API_ERROR_PERMISSIONS exception will be thrown.
  *
  * @throws APIException if a validation error occurred.
  *
  * @param array $screenItems	An array of screen items to validate
  * @param array $dbScreenItems	An array of screen items $screenItems should be matched against
  */
 protected function checkInput(array $screenItems, array $dbScreenItems = array())
 {
     $hostgroups = array();
     $hosts = array();
     $graphs = array();
     $items = array();
     $maps = array();
     $screens = array();
     foreach ($screenItems as $screenItem) {
         // check if the item is editable
         if (!empty($screenItem['screenitemid']) && !isset($dbScreenItems[$screenItem['screenitemid']])) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
         }
         // check resource type
         if (!$this->isValidResourceType($screenItem['resourcetype'])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _('Incorrect resource type provided for screen item.'));
         }
         // perform resource type specific validation
         // save the affected object ids to validate them later
         $hostGroupResourceTypes = array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO, SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_DATA_OVERVIEW);
         if (in_array($screenItem['resourcetype'], $hostGroupResourceTypes)) {
             $resourceIdRequired = !in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_HOSTGROUP_TRIGGERS, SCREEN_RESOURCE_TRIGGERS_INFO));
             if (!$screenItem['resourceid'] && $resourceIdRequired) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No host group ID provided for screen element.'));
             } elseif ($screenItem['resourceid']) {
                 $hostgroups[] = $screenItem['resourceid'];
             }
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_HOST_TRIGGERS && $screenItem['resourceid']) {
             $hosts[] = $screenItem['resourceid'];
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_GRAPH) {
             if (!$screenItem['resourceid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No graph ID provided for screen element.'));
             }
             $graphs[] = $screenItem['resourceid'];
         } elseif (in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT)) || $screenItem['resourcetype'] == SCREEN_RESOURCE_CLOCK && $screenItem['style'] == TIME_TYPE_HOST) {
             if (!$screenItem['resourceid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No item ID provided for screen element.'));
             }
             $items[] = $screenItem['resourceid'];
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_MAP) {
             if (!$screenItem['resourceid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No map ID provided for screen element.'));
             }
             $maps[] = $screenItem['resourceid'];
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_SCREEN) {
             if (!$screenItem['resourceid']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No screen ID provided for screen element.'));
             }
             $screens[] = $screenItem['resourceid'];
         } elseif ($screenItem['resourcetype'] == SCREEN_RESOURCE_URL) {
             if (!$screenItem['url']) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _('No URL provided for screen element.'));
             }
         }
         // check fields specific to each resource type
         // check "Show lines" field
         switch ($screenItem['resourcetype']) {
             case SCREEN_RESOURCE_ACTIONS:
             case SCREEN_RESOURCE_EVENTS:
             case SCREEN_RESOURCE_HOSTGROUP_TRIGGERS:
             case SCREEN_RESOURCE_HOST_TRIGGERS:
             case SCREEN_RESOURCE_PLAIN_TEXT:
                 if ($screenItem['elements'] < 1 || $screenItem['elements'] > 100) {
                     self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect value "%1$s" for "%2$s" field: must be between %3$s and %4$s.', $screenItem['elements'], 'elements', 1, 100));
                 }
                 break;
         }
     }
     // check host groups
     if (!empty($hostgroups)) {
         $result = API::HostGroup()->get(array('groupids' => $hostgroups, 'output' => array('groupid'), 'preservekeys' => true));
         foreach ($hostgroups as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host group ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check hosts
     if ($hosts) {
         $result = API::Host()->get(array('hostids' => $hosts, 'output' => array('hostid'), 'preservekeys' => true));
         foreach ($hosts as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect host ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check graphs
     if ($graphs) {
         $result = API::Graph()->get(array('graphids' => $graphs, 'output' => array('graphid'), 'preservekeys' => true));
         foreach ($graphs as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect graph ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check items
     if ($items) {
         $result = API::Item()->get(array('itemids' => $items, 'output' => array('itemid'), 'preservekeys' => true, 'webitems' => true));
         foreach ($items as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect item ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check maps
     if ($maps) {
         $result = API::Map()->get(array('sysmapids' => $maps, 'output' => array('sysmapid'), 'preservekeys' => true));
         foreach ($maps as $id) {
             if (!isset($result[$id])) {
                 self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect map ID "%s" provided for screen element.', $id));
             }
         }
     }
     // check screens
     if ($screens) {
         $result = API::Screen()->get(array('screenids' => $screens, 'output' => array('screenid'), 'preservekeys' => true));
         if (empty($result)) {
             self::exception(ZBX_API_ERROR_PERMISSIONS, _s('Incorrect screen ID "%s" provided for screen element.', $id));
         }
     }
 }
示例#19
0
 /**
  * Get screen data.
  *
  * @param array  $options
  * @param array  $options['nodeids']		node IDs
  * @param bool   $options['editable']		only with read-write permission. Ignored for SuperAdmins
  * @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['order']			deprecated parameter (for now)
  *
  * @return array
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     $sqlParts = array('select' => array('screens' => 's.screenid'), 'from' => array('screens' => 'screens s'), 'where' => array('template' => 's.templateid IS NULL'), 'order' => array(), 'group' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'screenids' => null, 'screenitemids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectScreenItems' => null, 'countOutput' => null, 'groupCount' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     // screenids
     if (!is_null($options['screenids'])) {
         zbx_value2array($options['screenids']);
         $sqlParts['where'][] = dbConditionInt('s.screenid', $options['screenids']);
     }
     // screenitemids
     if (!is_null($options['screenitemids'])) {
         zbx_value2array($options['screenitemids']);
         if ($options['output'] != API_OUTPUT_EXTEND) {
             $sqlParts['select']['screenitemid'] = 'si.screenitemid';
         }
         $sqlParts['from']['screens_items'] = 'screens_items si';
         $sqlParts['where']['ssi'] = 'si.screenid=s.screenid';
         $sqlParts['where'][] = dbConditionInt('si.screenitemid', $options['screenitemids']);
     }
     // filter
     if (is_array($options['filter'])) {
         $this->dbFilter('screens s', $options, $sqlParts);
     }
     // search
     if (is_array($options['search'])) {
         zbx_db_search('screens s', $options, $sqlParts);
     }
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $screenIds = array();
     $sqlParts = $this->applyQueryOutputOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $sqlParts = $this->applyQuerySortOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $sqlParts = $this->applyQueryNodeOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
     while ($screen = DBfetch($res)) {
         if ($options['countOutput'] !== null) {
             if ($options['groupCount'] !== null) {
                 $result[] = $screen;
             } else {
                 $result = $screen['rowscount'];
             }
         } else {
             $screenIds[$screen['screenid']] = $screen['screenid'];
             if (!isset($result[$screen['screenid']])) {
                 $result[$screen['screenid']] = array();
             }
             if (isset($screen['screenitemid']) && $options['selectScreenItems'] === null) {
                 if (!isset($result[$screen['screenid']]['screenitems'])) {
                     $result[$screen['screenid']]['screenitems'] = array();
                 }
                 $result[$screen['screenid']]['screenitems'][] = array('screenitemid' => $screen['screenitemid']);
                 unset($screen['screenitemid']);
             }
             $result[$screen['screenid']] += $screen;
         }
     }
     // editable + PERMISSION CHECK
     if ($userType == USER_TYPE_SUPER_ADMIN || $options['nopermissions']) {
     } elseif ($result) {
         $groupsToCheck = array();
         $hostsToCheck = array();
         $graphsToCheck = array();
         $itemsToCheck = array();
         $mapsToCheck = array();
         $screensToCheck = array();
         $screensItems = array();
         $dbScreenItems = DBselect('SELECT si.* FROM screens_items si WHERE ' . dbConditionInt('si.screenid', $screenIds));
         while ($screenItem = DBfetch($dbScreenItems)) {
             $screensItems[$screenItem['screenitemid']] = $screenItem;
             if ($screenItem['resourceid']) {
                 switch ($screenItem['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:
                         $groupsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_HOST_TRIGGERS:
                         $hostsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_GRAPH:
                         $graphsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_SIMPLE_GRAPH:
                     case SCREEN_RESOURCE_PLAIN_TEXT:
                         $itemsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_MAP:
                         $mapsToCheck[] = $screenItem['resourceid'];
                         break;
                     case SCREEN_RESOURCE_SCREEN:
                         $screensToCheck[] = $screenItem['resourceid'];
                         break;
                 }
             }
         }
         $groupsToCheck = array_unique($groupsToCheck);
         $hostsToCheck = array_unique($hostsToCheck);
         $graphsToCheck = array_unique($graphsToCheck);
         $itemsToCheck = array_unique($itemsToCheck);
         $mapsToCheck = array_unique($mapsToCheck);
         $screensToCheck = array_unique($screensToCheck);
         // group
         $allowedGroups = API::HostGroup()->get(array('nodeids' => $options['nodeids'], 'groupids' => $groupsToCheck, 'editable' => $options['editable']));
         $allowedGroups = zbx_objectValues($allowedGroups, 'groupid');
         // host
         $allowedHosts = API::Host()->get(array('nodeids' => $options['nodeids'], 'hostids' => $hostsToCheck, 'editable' => $options['editable']));
         $allowedHosts = zbx_objectValues($allowedHosts, 'hostid');
         // graph
         $allowedGraphs = API::Graph()->get(array('nodeids' => $options['nodeids'], 'graphids' => $graphsToCheck, 'editable' => $options['editable']));
         $allowedGraphs = zbx_objectValues($allowedGraphs, 'graphid');
         // item
         $allowedItems = API::Item()->get(array('output' => array('itemid'), 'nodeids' => $options['nodeids'], 'itemids' => $itemsToCheck, 'webitems' => true, 'editable' => $options['editable']));
         $allowedItems = zbx_objectValues($allowedItems, 'itemid');
         // map
         $allowedMaps = API::Map()->get(array('nodeids' => $options['nodeids'], 'sysmapids' => $mapsToCheck, 'editable' => $options['editable']));
         $allowedMaps = zbx_objectValues($allowedMaps, 'sysmapid');
         // screen
         $allowedScreens = API::Screen()->get(array('nodeids' => $options['nodeids'], 'screenids' => $screensToCheck, 'editable' => $options['editable']));
         $allowedScreens = zbx_objectValues($allowedScreens, 'screenid');
         $restrGroups = array_diff($groupsToCheck, $allowedGroups);
         $restrHosts = array_diff($hostsToCheck, $allowedHosts);
         $restrGraphs = array_diff($graphsToCheck, $allowedGraphs);
         $restrItems = array_diff($itemsToCheck, $allowedItems);
         $restrMaps = array_diff($mapsToCheck, $allowedMaps);
         $restrScreens = array_diff($screensToCheck, $allowedScreens);
         // group
         foreach ($restrGroups as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && uint_in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_HOSTS_INFO, SCREEN_RESOURCE_TRIGGERS_INFO, SCREEN_RESOURCE_TRIGGERS_OVERVIEW, SCREEN_RESOURCE_DATA_OVERVIEW, SCREEN_RESOURCE_HOSTGROUP_TRIGGERS))) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // host
         foreach ($restrHosts as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && uint_in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_HOST_TRIGGERS))) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // graph
         foreach ($restrGraphs as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && $screenItem['resourcetype'] == SCREEN_RESOURCE_GRAPH) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // item
         foreach ($restrItems as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && uint_in_array($screenItem['resourcetype'], array(SCREEN_RESOURCE_SIMPLE_GRAPH, SCREEN_RESOURCE_PLAIN_TEXT))) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // map
         foreach ($restrMaps as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && $screenItem['resourcetype'] == SCREEN_RESOURCE_MAP) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
         // screen
         foreach ($restrScreens as $resourceId) {
             foreach ($screensItems as $screenItemId => $screenItem) {
                 if (bccomp($screenItem['resourceid'], $resourceId) == 0 && $screenItem['resourcetype'] == SCREEN_RESOURCE_SCREEN) {
                     unset($result[$screenItem['screenid']], $screensItems[$screenItemId]);
                 }
             }
         }
     }
     if ($options['countOutput'] !== null) {
         return $result;
     }
     if ($result) {
         $result = $this->addRelatedObjects($options, $result);
     }
     // removing keys (hash -> array)
     if ($options['preservekeys'] === null) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
示例#20
0
    foreach ($data['images'] as $num => $image) {
        $data['images'][$num]['name'] = get_node_name_by_elid($image['imageid'], null, NAME_DELIMITER) . $image['name'];
    }
    // icon maps
    $data['iconMaps'] = API::IconMap()->get(array('output' => array('iconmapid', 'name'), 'preservekeys' => true));
    order_result($data['iconMaps'], 'name');
    // render view
    $mapView = new CView('configuration.sysmap.edit', $data);
    $mapView->render();
    $mapView->show();
} else {
    $data = array();
    // get maps
    $sortField = getPageSortField('name');
    $sortOrder = getPageSortOrder();
    $data['maps'] = API::Map()->get(array('editable' => true, 'output' => array('sysmapid', 'name', 'width', 'height'), 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1));
    order_result($data['maps'], $sortField, $sortOrder);
    // paging
    $data['paging'] = getPagingLine($data['maps'], array('sysmapid'));
    // nodes
    if ($data['displayNodes'] = is_array(get_current_nodeid())) {
        foreach ($data['maps'] as &$map) {
            $map['nodename'] = get_node_name_by_elid($map['sysmapid'], true);
        }
        unset($map);
    }
    // render view
    $mapView = new CView('configuration.sysmap.list', $data);
    $mapView->render();
    $mapView->show();
}
 /**
  * Get maps references by map ids.
  *
  * @param array $mapIds
  *
  * @return array
  */
 protected function getMapsReferences(array $mapIds)
 {
     $ids = [];
     $maps = API::Map()->get(['sysmapids' => $mapIds, 'output' => ['name'], 'preservekeys' => true]);
     foreach ($maps as $id => $map) {
         $ids[$id] = ['name' => $map['name']];
     }
     return $ids;
 }
        $item = reset($items);
        $item['host'] = reset($item['hosts']);
        $caption = $item['host']['name'] . NAME_DELIMITER . $item['name_expanded'];
    }
    if ($this->data['screen']['templateid']) {
        $selectButton = (new CButton('select', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: return PopUp("popup.php?srctbl=item_prototypes&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $form->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&templated_hosts=1&only_hostid=' . $this->data['screen']['templateid'] . '&numeric=1");');
    } else {
        $selectButton = (new CButton('select', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: return PopUp("popup.php?srctbl=item_prototypes&srcfld1=itemid&srcfld2=name' . '&dstfrm=' . $form->getName() . '&dstfld1=resourceid&dstfld2=caption' . '&real_hosts=1&with_discovery_rule=1&items=1&numeric=1");');
    }
    $form->addVar('resourceid', $id);
    $screenFormList->addRow(_('Item prototype'), [(new CTextBox('caption', $caption, true))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), $selectButton]);
    $screenFormList->addRow(_('Max columns'), (new CNumericBox('max_columns', $maxColumns, 3, false, false, false))->setWidth(ZBX_TEXTAREA_NUMERIC_STANDARD_WIDTH));
} elseif ($resourceType == SCREEN_RESOURCE_MAP) {
    $caption = '';
    $id = 0;
    $maps = API::Map()->get(['sysmapids' => $resourceId, 'output' => API_OUTPUT_EXTEND]);
    if (!empty($maps)) {
        $id = $resourceId;
        $map = reset($maps);
        $caption = $map['name'];
    }
    $form->addVar('resourceid', $id);
    $screenFormList->addRow(_('Map'), [(new CTextBox('caption', $caption, true))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CButton('select', _('Select')))->addClass(ZBX_STYLE_BTN_GREY)->onClick('javascript: return PopUp("popup.php?srctbl=sysmaps&srcfld1=sysmapid&srcfld2=name' . '&dstfrm=' . $form->getName() . '&dstfld1=resourceid&dstfld2=caption");')]);
} elseif ($resourceType == SCREEN_RESOURCE_PLAIN_TEXT) {
    $caption = '';
    $id = 0;
    $items = API::Item()->get(['itemids' => $resourceId, 'selectHosts' => ['name'], 'output' => ['itemid', 'hostid', 'key_', 'name']]);
    if ($items) {
        $items = CMacrosResolverHelper::resolveItemNames($items);
        $id = $resourceId;
        $item = reset($items);
 /**
  * Select map ids for previously added maps names.
  */
 protected function selectMaps()
 {
     if (!empty($this->maps)) {
         $this->mapsRefs = array();
         $dbMaps = API::Map()->get(array('filter' => array('name' => $this->maps), 'output' => array('sysmapid', 'name'), 'preservekeys' => true));
         foreach ($dbMaps as $dbMap) {
             $this->mapsRefs[$dbMap['name']] = $dbMap['sysmapid'];
         }
         $this->maps = array();
     }
 }
示例#24
0
 /**
  * Checks that the user has write permissions to objects used in the map elements.
  *
  * @throws APIException if the user has no permissions to at least one of the objects
  *
  * @param array $selements
  */
 protected function checkSelementPermissions(array $selements)
 {
     if (CWebUser::getType() == USER_TYPE_SUPER_ADMIN) {
         return;
     }
     $hostIds = $groupIds = $triggerIds = $mapIds = array();
     foreach ($selements as $selement) {
         switch ($selement['elementtype']) {
             case SYSMAP_ELEMENT_TYPE_HOST:
                 $hostIds[$selement['elementid']] = $selement['elementid'];
                 break;
             case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                 $groupIds[$selement['elementid']] = $selement['elementid'];
                 break;
             case SYSMAP_ELEMENT_TYPE_TRIGGER:
                 $triggerIds[$selement['elementid']] = $selement['elementid'];
                 break;
             case SYSMAP_ELEMENT_TYPE_MAP:
                 $mapIds[$selement['elementid']] = $selement['elementid'];
                 break;
         }
     }
     if ($hostIds && !API::Host()->isWritable($hostIds) || $groupIds && !API::HostGroup()->isWritable($groupIds) || $triggerIds && !API::Trigger()->isWritable($triggerIds) || $mapIds && !API::Map()->isWritable($mapIds)) {
         self::exception(ZBX_API_ERROR_PERMISSIONS, _('No permissions to referred object or it does not exist!'));
     }
 }
示例#25
0
 public static function parseMap($rules)
 {
     $importMaps = self::XMLtoArray(self::$xml);
     if (!isset($importMaps['zabbix_export'])) {
         $importMaps['zabbix_export'] = $importMaps;
     }
     if (CWebUser::$data['type'] == USER_TYPE_SUPER_ADMIN && isset($importMaps['zabbix_export']['images'])) {
         $images = $importMaps['zabbix_export']['images'];
         $images_to_add = array();
         $images_to_update = array();
         foreach ($images as $image) {
             if (API::Image()->exists($image)) {
                 if ($image['imagetype'] == IMAGE_TYPE_ICON && !empty($rules['images']['updateExisting']) || $image['imagetype'] == IMAGE_TYPE_BACKGROUND && !empty($rules['images']['updateExisting'])) {
                     $options = array('filter' => array('name' => $image['name']), 'output' => array('imageid'));
                     $imgs = API::Image()->get($options);
                     $img = reset($imgs);
                     $image['imageid'] = $img['imageid'];
                     // image will be decoded in class.image.php
                     $image['image'] = $image['encodedImage'];
                     unset($image['encodedImage']);
                     $images_to_update[] = $image;
                 }
             } else {
                 if ($image['imagetype'] == IMAGE_TYPE_ICON && !empty($rules['images']['createMissing']) || $image['imagetype'] == IMAGE_TYPE_BACKGROUND && !empty($rules['images']['createMissing'])) {
                     // No need to decode_base64
                     $image['image'] = $image['encodedImage'];
                     unset($image['encodedImage']);
                     $images_to_add[] = $image;
                 }
             }
         }
         if (!empty($images_to_add)) {
             $result = API::Image()->create($images_to_add);
             if (!$result) {
                 throw new Exception(_('Cannot add image.'));
             }
         }
         if (!empty($images_to_update)) {
             $result = API::Image()->update($images_to_update);
             if (!$result) {
                 throw new Exception(_('Cannot update image.'));
             }
         }
     }
     if (!isset($importMaps['zabbix_export']['sysmaps'])) {
         return true;
     }
     $importMaps = $importMaps['zabbix_export']['sysmaps'];
     foreach ($importMaps as $mnum => &$sysmap) {
         unset($sysmap['sysmapid']);
         $exists = API::Map()->exists(array('name' => $sysmap['name']));
         if (!isset($sysmap['label_format'])) {
             $sysmap['label_format'] = SYSMAP_LABEL_ADVANCED_OFF;
         }
         if ($exists && !empty($rules['maps']['updateExisting'])) {
             $db_maps = API::Map()->getObjects(array('name' => $sysmap['name']));
             if (empty($db_maps)) {
                 throw new Exception(_s('No permissions for map "%1$s".', $sysmap['name']));
             }
             $db_map = reset($db_maps);
             $sysmap['sysmapid'] = $db_map['sysmapid'];
         } else {
             if ($exists || empty($rules['maps']['createMissing'])) {
                 info(_s('Map "%1$s" skipped - user rule.', $sysmap['name']));
                 unset($importMaps[$mnum]);
                 continue;
                 // break if not update updateExisting
             }
         }
         if (isset($sysmap['backgroundid'])) {
             $image = getImageByIdent($sysmap['backgroundid']);
             if (!$image) {
                 error(_s('Cannot find background image "%1$s" used in map "%2$s".', $sysmap['backgroundid']['name'], $sysmap['name']));
                 $sysmap['backgroundid'] = 0;
             } else {
                 $sysmap['backgroundid'] = $image['imageid'];
             }
         } else {
             $sysmap['backgroundid'] = 0;
         }
         if (!isset($sysmap['selements'])) {
             $sysmap['selements'] = array();
         } else {
             $sysmap['selements'] = array_values($sysmap['selements']);
         }
         if (!isset($sysmap['links'])) {
             $sysmap['links'] = array();
         } else {
             $sysmap['links'] = array_values($sysmap['links']);
         }
         foreach ($sysmap['selements'] as &$selement) {
             $nodeCaption = isset($selement['elementid']['node']) ? $selement['elementid']['node'] . ':' : '';
             if (!isset($selement['elementid'])) {
                 $selement['elementid'] = 0;
             }
             switch ($selement['elementtype']) {
                 case SYSMAP_ELEMENT_TYPE_MAP:
                     $db_sysmaps = API::Map()->getObjects($selement['elementid']);
                     if (empty($db_sysmaps)) {
                         $error = _s('Cannot find map "%1$s" used in exported map "%2$s".', $nodeCaption . $selement['elementid']['name'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $tmp = reset($db_sysmaps);
                     $selement['elementid'] = $tmp['sysmapid'];
                     break;
                 case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                     $db_hostgroups = API::HostGroup()->getObjects($selement['elementid']);
                     if (empty($db_hostgroups)) {
                         $error = _s('Cannot find group "%1$s" used in map "%2$s".', $nodeCaption . $selement['elementid']['name'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $tmp = reset($db_hostgroups);
                     $selement['elementid'] = $tmp['groupid'];
                     break;
                 case SYSMAP_ELEMENT_TYPE_HOST:
                     $db_hosts = API::Host()->getObjects($selement['elementid']);
                     if (empty($db_hosts)) {
                         $error = _s('Cannot find host "%1$s" used in map "%2$s".', $nodeCaption . $selement['elementid']['host'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $tmp = reset($db_hosts);
                     $selement['elementid'] = $tmp['hostid'];
                     break;
                 case SYSMAP_ELEMENT_TYPE_TRIGGER:
                     $db_triggers = API::Trigger()->getObjects($selement['elementid']);
                     if (empty($db_triggers)) {
                         $error = _s('Cannot find trigger "%1$s" used in map "%2$s".', $nodeCaption . $selement['elementid']['host'] . ':' . $selement['elementid']['description'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $tmp = reset($db_triggers);
                     $selement['elementid'] = $tmp['triggerid'];
                     break;
                 case SYSMAP_ELEMENT_TYPE_IMAGE:
                 default:
             }
             $icons = array('iconid_off', 'iconid_on', 'iconid_disabled', 'iconid_maintenance');
             foreach ($icons as $icon) {
                 if (isset($selement[$icon])) {
                     $image = getImageByIdent($selement[$icon]);
                     if (!$image) {
                         $error = _s('Cannot find icon "%1$s" used in map "%2$s".', $selement[$icon]['name'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $selement[$icon] = $image['imageid'];
                 } else {
                     $selement[$icon] = 0;
                 }
             }
         }
         unset($selement);
         foreach ($sysmap['links'] as &$link) {
             if (!isset($link['linktriggers'])) {
                 continue;
             }
             foreach ($link['linktriggers'] as &$linktrigger) {
                 $db_triggers = API::Trigger()->getObjects($linktrigger['triggerid']);
                 if (empty($db_triggers)) {
                     $nodeCaption = isset($linktrigger['triggerid']['node']) ? $linktrigger['triggerid']['node'] . ':' : '';
                     $error = _s('Cannot find trigger "%1$s" used in map "%2$s".', $nodeCaption . $linktrigger['triggerid']['host'] . ':' . $linktrigger['triggerid']['description'], $sysmap['name']);
                     throw new Exception($error);
                 }
                 $tmp = reset($db_triggers);
                 $linktrigger['triggerid'] = $tmp['triggerid'];
             }
             unset($linktrigger);
         }
         unset($link);
     }
     unset($sysmap);
     foreach ($importMaps as $importMap) {
         if (isset($importMap['sysmapid'])) {
             $result = API::Map()->update($importMap);
             if ($result === false) {
                 throw new Exception(_s('Cannot update map "%s".', $importMap['name']));
             } else {
                 info(_s('Map "%s" updated.', $importMap['name']));
             }
         } else {
             $result = API::Map()->create($importMap);
             if ($result === false) {
                 throw new Exception(_s('Cannot create map "%s".', $importMap['name']));
             } else {
                 info(_s('Map "%s" created.', $importMap['name']));
             }
         }
     }
     return true;
 }
示例#26
0
 public static function parseMap($rules)
 {
     $importMaps = self::XMLtoArray(self::$xml);
     if (!isset($importMaps['zabbix_export'])) {
         $importMaps['zabbix_export'] = $importMaps;
     }
     if (CWebUser::$data['type'] == USER_TYPE_SUPER_ADMIN && isset($importMaps['zabbix_export']['images'])) {
         $allImages = $importMaps['zabbix_export']['images'];
         $allImages = zbx_toHash($allImages, 'name');
         $dbImages = API::Image()->get(array('output' => array('imageid', 'name'), 'filter' => array('name' => zbx_objectValues($allImages, 'name'))));
         $dbImages = zbx_toHash($dbImages, 'name');
         $imagesToCreate = array();
         $imagesToUpdate = array();
         foreach ($allImages as $imageName => $image) {
             if (isset($dbImages[$imageName])) {
                 $image['imageid'] = $dbImages[$imageName]['imageid'];
                 $image['image'] = $image['encodedImage'];
                 unset($image['encodedImage'], $image['imagetype']);
                 $imagesToUpdate[] = $image;
             } else {
                 $image['image'] = $image['encodedImage'];
                 unset($image['encodedImage']);
                 $imagesToCreate[] = $image;
             }
         }
         if ($rules['images']['createMissing'] && $imagesToCreate) {
             API::Image()->create($imagesToCreate);
         }
         if ($rules['images']['updateExisting'] && $imagesToUpdate) {
             API::Image()->update($imagesToUpdate);
         }
     }
     if (!isset($importMaps['zabbix_export']['sysmaps'])) {
         return true;
     }
     $importMaps = $importMaps['zabbix_export']['sysmaps'];
     foreach ($importMaps as $mnum => &$sysmap) {
         unset($sysmap['sysmapid']);
         if (!isset($sysmap['label_format'])) {
             $sysmap['label_format'] = SYSMAP_LABEL_ADVANCED_OFF;
         }
         $mapExists = API::Map()->get(array('output' => array('sysmapid'), 'filter' => array('name' => $sysmap['name']), 'nopermissions' => true, 'limit' => 1));
         if ($mapExists && $rules['maps']['updateExisting']) {
             $db_maps = API::Map()->get(array('filter' => array('name' => $sysmap['name']), 'output' => array('sysmapid')));
             if (empty($db_maps)) {
                 throw new Exception(_s('No permissions for map "%1$s".', $sysmap['name']));
             }
             $db_map = reset($db_maps);
             $sysmap['sysmapid'] = $db_map['sysmapid'];
         } elseif ($mapExists || !$rules['maps']['createMissing']) {
             info(_s('Map "%1$s" skipped - user rule.', $sysmap['name']));
             unset($importMaps[$mnum]);
             continue;
         }
         if (isset($sysmap['backgroundid'])) {
             $image = getImageByIdent($sysmap['backgroundid']);
             if (!$image) {
                 error(_s('Cannot find background image "%1$s" used in map "%2$s".', $sysmap['backgroundid']['name'], $sysmap['name']));
                 $sysmap['backgroundid'] = 0;
             } else {
                 $sysmap['backgroundid'] = $image['imageid'];
             }
         } else {
             $sysmap['backgroundid'] = 0;
         }
         if (!isset($sysmap['selements'])) {
             $sysmap['selements'] = array();
         } else {
             $sysmap['selements'] = array_values($sysmap['selements']);
         }
         if (!isset($sysmap['links'])) {
             $sysmap['links'] = array();
         } else {
             $sysmap['links'] = array_values($sysmap['links']);
         }
         foreach ($sysmap['selements'] as &$selement) {
             if (!isset($selement['elementid'])) {
                 $selement['elementid'] = 0;
             }
             switch ($selement['elementtype']) {
                 case SYSMAP_ELEMENT_TYPE_MAP:
                     $db_sysmaps = API::Map()->get(array('filter' => array($selement['elementid']), 'output' => array('sysmapid')));
                     if (empty($db_sysmaps)) {
                         $error = _s('Cannot find map "%1$s" used in exported map "%2$s".', $selement['elementid']['name'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $tmp = reset($db_sysmaps);
                     $selement['elementid'] = $tmp['sysmapid'];
                     break;
                 case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                     $db_hostgroups = API::HostGroup()->get(array('filter' => array($selement['elementid']), 'output' => array('groupid')));
                     if (empty($db_hostgroups)) {
                         $error = _s('Cannot find group "%1$s" used in map "%2$s".', $selement['elementid']['name'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $tmp = reset($db_hostgroups);
                     $selement['elementid'] = $tmp['groupid'];
                     break;
                 case SYSMAP_ELEMENT_TYPE_HOST:
                     $db_hosts = API::Host()->get(array('filter' => array($selement['elementid']), 'output' => array('hostid')));
                     if (empty($db_hosts)) {
                         $error = _s('Cannot find host "%1$s" used in map "%2$s".', $selement['elementid']['host'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $tmp = reset($db_hosts);
                     $selement['elementid'] = $tmp['hostid'];
                     break;
                 case SYSMAP_ELEMENT_TYPE_TRIGGER:
                     $db_triggers = API::Trigger()->get(array('filter' => array($selement['elementid']), 'output' => array('triggerid')));
                     if (empty($db_triggers)) {
                         $error = _s('Cannot find trigger "%1$s" used in map "%2$s".', $selement['elementid']['host'] . ':' . $selement['elementid']['description'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $tmp = reset($db_triggers);
                     $selement['elementid'] = $tmp['triggerid'];
                     break;
                 case SYSMAP_ELEMENT_TYPE_IMAGE:
                 default:
             }
             $icons = array('iconid_off', 'iconid_on', 'iconid_disabled', 'iconid_maintenance');
             foreach ($icons as $icon) {
                 if (isset($selement[$icon])) {
                     $image = getImageByIdent($selement[$icon]);
                     if (!$image) {
                         $error = _s('Cannot find icon "%1$s" used in map "%2$s".', $selement[$icon]['name'], $sysmap['name']);
                         throw new Exception($error);
                     }
                     $selement[$icon] = $image['imageid'];
                 } else {
                     $selement[$icon] = 0;
                 }
             }
         }
         unset($selement);
         foreach ($sysmap['links'] as &$link) {
             if (!isset($link['linktriggers'])) {
                 continue;
             }
             foreach ($link['linktriggers'] as &$linktrigger) {
                 $triggerData = $linktrigger['triggerid'];
                 $dbTriggers = API::Trigger()->get(array('output' => array('triggerid', 'expression'), 'filter' => array('host' => $triggerData['host'], 'description' => $triggerData['description']), 'expandExpression' => true));
                 $error = _s('Cannot find trigger "%1$s" used in map "%2$s".', $triggerData['host'] . ':' . $triggerData['description'], $sysmap['name']);
                 if (!$dbTriggers) {
                     throw new Exception($error);
                 }
                 $dbTriggerId = null;
                 foreach ($dbTriggers as $dbTrigger) {
                     if ($dbTrigger['expression'] === $triggerData['expression']) {
                         $dbTriggerId = $dbTrigger['triggerid'];
                         break;
                     }
                 }
                 if (!$dbTriggerId) {
                     throw new Exception($error);
                 }
                 $linktrigger['triggerid'] = $dbTriggerId;
             }
             unset($linktrigger);
         }
         unset($link);
     }
     unset($sysmap);
     foreach ($importMaps as $importMap) {
         if (isset($importMap['sysmapid'])) {
             $result = API::Map()->update($importMap);
             if ($result === false) {
                 throw new Exception(_s('Cannot update map "%s".', $importMap['name']));
             } else {
                 info(_s('Map "%s" updated.', $importMap['name']));
             }
         } else {
             $result = API::Map()->create($importMap);
             if ($result === false) {
                 throw new Exception(_s('Cannot create map "%s".', $importMap['name']));
             } else {
                 info(_s('Map "%s" created.', $importMap['name']));
             }
         }
     }
     return true;
 }
示例#27
0
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/
require_once dirname(__FILE__) . '/include/config.inc.php';
require_once dirname(__FILE__) . '/include/maps.inc.php';
$page['title'] = _('Logo');
$page['file'] = 'zbxe-customer-logo.php';
$page['type'] = detect_page_type(PAGE_TYPE_IMAGE);
require_once dirname(__FILE__) . '/include/page_header.php';
// VAR	TYPE	OPTIONAL	FLAGS	VALIDATION		EXCEPTION
$fields = array('sysmapid' => array(T_ZBX_INT, O_MAND, P_SYS, DB_ID, null), 'selements' => array(T_ZBX_STR, O_OPT, P_SYS, DB_ID, null), 'links' => array(T_ZBX_STR, O_OPT, P_SYS, DB_ID, null), 'noselements' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'nolinks' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'nocalculations' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'expand_macros' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null), 'show_triggers' => array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1,2,3'), null), 'severity_min' => array(T_ZBX_INT, O_OPT, null, IN('0,1,2,3,4,5'), null), 'grid' => array(T_ZBX_INT, O_OPT, null, BETWEEN(0, 500), null), 'base64image' => array(T_ZBX_INT, O_OPT, null, IN('0,1'), null));
check_fields($fields);
$maps = API::Map()->get(array('sysmapids' => $_REQUEST['sysmapid'], 'selectSelements' => API_OUTPUT_EXTEND, 'selectLinks' => API_OUTPUT_EXTEND, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true));
$map = reset($maps);
if (empty($map)) {
    access_deny();
}
$mapPainter = new CMapPainter($map, array('map' => array('drawAreas' => !isset($_REQUEST['selements']) && !isset($_REQUEST['noselements'])), 'grid' => array('size' => get_request('grid', 0))));
$im = $mapPainter->paint();
$colors['Red'] = imagecolorallocate($im, 255, 0, 0);
$colors['Dark Red'] = imagecolorallocate($im, 150, 0, 0);
$colors['Green'] = imagecolorallocate($im, 0, 255, 0);
$colors['Dark Green'] = imagecolorallocate($im, 0, 150, 0);
$colors['Blue'] = imagecolorallocate($im, 0, 0, 255);
$colors['Dark Blue'] = imagecolorallocate($im, 0, 0, 150);
$colors['Yellow'] = imagecolorallocate($im, 255, 255, 0);
$colors['Dark Yellow'] = imagecolorallocate($im, 150, 150, 0);
$colors['Cyan'] = imagecolorallocate($im, 0, 255, 255);
示例#28
0
    $sortOrder = getRequest('sortorder', CProfile::get('web.' . $page['file'] . '.sortorder', ZBX_SORT_UP));
    CProfile::update('web.' . $page['file'] . '.sort', $sortField, PROFILE_TYPE_STR);
    CProfile::update('web.' . $page['file'] . '.sortorder', $sortOrder, PROFILE_TYPE_STR);
    if (hasRequest('filter_set')) {
        CProfile::update('web.sysmapconf.filter_name', getRequest('filter_name', ''), PROFILE_TYPE_STR);
    } elseif (hasRequest('filter_rst')) {
        DBStart();
        CProfile::delete('web.sysmapconf.filter_name');
        DBend();
    }
    $config = select_config();
    $data = ['filter' => ['name' => CProfile::get('web.sysmapconf.filter_name', '')], 'sort' => $sortField, 'sortorder' => $sortOrder];
    // get maps
    $data['maps'] = API::Map()->get(['output' => ['sysmapid', 'name', 'width', 'height'], 'sortfield' => $sortField, 'limit' => $config['search_limit'] + 1, 'search' => ['name' => $data['filter']['name'] === '' ? null : $data['filter']['name']], 'preservekeys' => true]);
    $user_type = CWebUser::getType();
    if ($user_type != USER_TYPE_SUPER_ADMIN && $user_type != USER_TYPE_ZABBIX_ADMIN) {
        $editable_maps = API::Map()->get(['output' => [], 'sysmapids' => array_keys($data['maps']), 'editable' => true, 'preservekeys' => true]);
        foreach ($data['maps'] as &$map) {
            $map['editable'] = array_key_exists($map['sysmapid'], $editable_maps);
        }
        unset($map);
    }
    order_result($data['maps'], $sortField, $sortOrder);
    // paging
    $data['paging'] = getPagingLine($data['maps'], $sortOrder, new CUrl('sysmaps.php'));
    // render view
    $mapView = new CView('monitoring.sysmap.list', $data);
    $mapView->render();
    $mapView->show();
}
require_once dirname(__FILE__) . '/include/page_footer.php';
示例#29
0
function make_sysmap_submenu()
{
    $fav_sysmaps = CFavorite::get('web.favorite.sysmapids');
    $favMaps = array();
    $sysmapids = array();
    foreach ($fav_sysmaps as $favorite) {
        $sysmapids[$favorite['value']] = $favorite['value'];
    }
    $options = array('sysmapids' => $sysmapids, 'output' => array('sysmapid', 'name'));
    $sysmaps = API::Map()->get($options);
    foreach ($sysmaps as $sysmap) {
        $favMaps[] = array('name' => $sysmap['name'], 'favobj' => 'sysmapid', 'favid' => $sysmap['sysmapid'], 'favaction' => 'remove');
    }
    if (!empty($favMaps)) {
        $favMaps[] = array('name' => _('Remove') . ' ' . _('All') . ' ' . _('Maps'), 'favobj' => 'sysmapid', 'favid' => 0, 'favaction' => 'remove');
    }
    return $favMaps;
}
示例#30
0
 /**
  * Validates the input parameters for the delete() method.
  *
  * @param array $userids
  *
  * @throws APIException if the input is invalid.
  */
 protected function validateDelete(array $userids)
 {
     if (!$userids) {
         self::exception(ZBX_API_ERROR_PARAMETERS, _('Empty input parameter.'));
     }
     $this->checkPermissions($userids);
     $this->checkDeleteCurrentUser($userids);
     $this->checkDeleteInternal($userids);
     // Check if deleted users have a map.
     $user_maps = API::Map()->get(['output' => ['name', 'userid'], 'userids' => $userids]);
     if ($user_maps) {
         // Get first problem user and map.
         $user_map = reset($user_maps);
         $db_users = $this->get(['output' => ['alias'], 'userids' => [$user_map['userid']], 'limit' => 1]);
         // Get first problem user.
         $db_user = reset($db_users);
         self::exception(ZBX_API_ERROR_PARAMETERS, _s('User "%1$s" is map "%2$s" owner.', $db_user['alias'], $user_map['name']));
     }
     // Check if deleted users have a screen.
     $user_screens = API::Screen()->get(['output' => ['name', 'userid'], 'userids' => $userids]);
     if ($user_screens) {
         // Get first problem user and screen.
         $user_screen = reset($user_screens);
         $db_users = $this->get(['output' => ['alias'], 'userids' => [$user_screen['userid']], 'limit' => 1]);
         // Get first problem user.
         $db_user = reset($db_users);
         self::exception(ZBX_API_ERROR_PARAMETERS, _s('User "%1$s" is screen "%2$s" owner.', $db_user['alias'], $user_screen['name']));
     }
     // Check if deleted users have a slide show.
     $user_slideshow = DBfetch(DBselect('SELECT s.name,s.userid' . ' FROM slideshows s' . ' WHERE ' . dbConditionInt('s.userid', $userids)));
     if ($user_slideshow) {
         $db_users = $this->get(['output' => ['alias'], 'userids' => [$user_slideshow['userid']], 'limit' => 1]);
         // Get first problem user.
         $db_user = reset($db_users);
         self::exception(ZBX_API_ERROR_PARAMETERS, _s('User "%1$s" is slide show "%2$s" owner.', $db_user['alias'], $user_slideshow['name']));
     }
 }