Пример #1
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;
}
Пример #2
0
 protected function addRelatedObjects(array $options, array $result)
 {
     $result = parent::addRelatedObjects($options, $result);
     $sysmapIds = array_keys($result);
     // adding elements
     if ($options['selectSelements'] !== null && $options['selectSelements'] != API_OUTPUT_COUNT) {
         $selements = API::getApiService()->select('sysmaps_elements', array('output' => $this->outputExtend($options['selectSelements'], array('selementid', 'sysmapid')), 'filter' => array('sysmapid' => $sysmapIds), 'preservekeys' => true));
         $relationMap = $this->createRelationMap($selements, 'sysmapid', 'selementid');
         // add selement URLs
         if ($this->outputIsRequested('urls', $options['selectSelements'])) {
             foreach ($selements as &$selement) {
                 $selement['urls'] = array();
             }
             unset($selement);
             if (!is_null($options['expandUrls'])) {
                 $dbMapUrls = DBselect('SELECT su.sysmapurlid,su.sysmapid,su.name,su.url,su.elementtype' . ' FROM sysmap_url su' . ' WHERE ' . dbConditionInt('su.sysmapid', $sysmapIds));
                 while ($mapUrl = DBfetch($dbMapUrls)) {
                     foreach ($selements as $snum => $selement) {
                         if (bccomp($selement['sysmapid'], $mapUrl['sysmapid']) == 0 && ($selement['elementtype'] == $mapUrl['elementtype'] && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP || $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS && $mapUrl['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST)) {
                             $selements[$snum]['urls'][] = $this->expandUrlMacro($mapUrl, $selement);
                         }
                     }
                 }
             }
             $dbSelementUrls = DBselect('SELECT seu.sysmapelementurlid,seu.selementid,seu.name,seu.url' . ' FROM sysmap_element_url seu' . ' WHERE ' . dbConditionInt('seu.selementid', array_keys($selements)));
             while ($selementUrl = DBfetch($dbSelementUrls)) {
                 $selements[$selementUrl['selementid']]['urls'][] = is_null($options['expandUrls']) ? $selementUrl : $this->expandUrlMacro($selementUrl, $selements[$selementUrl['selementid']]);
             }
         }
         $selements = $this->unsetExtraFields($selements, array('sysmapid', 'selementid'), $options['selectSelements']);
         $result = $relationMap->mapMany($result, $selements, 'selements');
     }
     // adding icon maps
     if ($options['selectIconMap'] !== null && $options['selectIconMap'] != API_OUTPUT_COUNT) {
         $iconMaps = API::IconMap()->get(array('output' => $this->outputExtend($options['selectIconMap'], array('sysmapid', 'iconmapid')), 'sysmapids' => $sysmapIds, 'preservekeys' => true, 'nopermissions' => true));
         $relationMap = $this->createRelationMap($iconMaps, 'sysmapid', 'iconmapid');
         $iconMaps = $this->unsetExtraFields($iconMaps, array('sysmapid', 'iconmapid'), $options['selectIconMap']);
         $result = $relationMap->mapOne($result, $iconMaps, 'iconmap');
     }
     // adding links
     if ($options['selectLinks'] !== null && $options['selectLinks'] != API_OUTPUT_COUNT) {
         $links = API::getApiService()->select('sysmaps_links', array('output' => $this->outputExtend($options['selectLinks'], array('sysmapid', 'linkid')), 'filter' => array('sysmapid' => $sysmapIds), 'preservekeys' => true));
         $relationMap = $this->createRelationMap($links, 'sysmapid', 'linkid');
         // add link triggers
         if ($this->outputIsRequested('linktriggers', $options['selectLinks'])) {
             $linkTriggers = DBFetchArrayAssoc(DBselect('SELECT DISTINCT slt.*' . ' FROM sysmaps_link_triggers slt' . ' WHERE ' . dbConditionInt('slt.linkid', $relationMap->getRelatedIds())), 'linktriggerid');
             $linkTriggerRelationMap = $this->createRelationMap($linkTriggers, 'linkid', 'linktriggerid');
             $links = $linkTriggerRelationMap->mapMany($links, $linkTriggers, 'linktriggers');
         }
         $links = $this->unsetExtraFields($links, array('sysmapid', 'linkid'), $options['selectLinks']);
         $result = $relationMap->mapMany($result, $links, 'links');
     }
     // adding urls
     if ($options['selectUrls'] !== null && $options['selectUrls'] != API_OUTPUT_COUNT) {
         $links = API::getApiService()->select('sysmap_url', array('output' => $this->outputExtend($options['selectUrls'], array('sysmapid', 'sysmapurlid')), 'filter' => array('sysmapid' => $sysmapIds), 'preservekeys' => true));
         $relationMap = $this->createRelationMap($links, 'sysmapid', 'sysmapurlid');
         $links = $this->unsetExtraFields($links, array('sysmapid', 'sysmapurlid'), $options['selectUrls']);
         $result = $relationMap->mapMany($result, $links, 'urls');
     }
     return $result;
 }
Пример #3
0
 /**
  * Update IconMap.
  * @param array $iconMaps
  * @return array
  */
 public function update(array $iconMaps)
 {
     if (USER_TYPE_SUPER_ADMIN != self::$userData['type']) {
         self::exception(ZBX_API_ERROR_PERMISSIONS, _('Only Super Admins can update icon maps.'));
     }
     $iconMaps = zbx_toArray($iconMaps);
     $iconMapids = zbx_objectValues($iconMaps, 'iconmapid');
     $updates = [];
     $duplicates = [];
     foreach ($iconMaps as $iconMap) {
         if (!check_db_fields(['iconmapid' => null], $iconMap)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect parameters for icon map update method "%s".', $iconMap['name']));
         }
         if (isset($iconMap['name'])) {
             if (zbx_empty($iconMap['name'])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map name cannot be empty.'));
             } elseif (isset($duplicates[$iconMap['name']])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot create icon maps with identical name "%s".', $iconMap['name']));
             } else {
                 $duplicates[$iconMap['name']] = $iconMap['name'];
             }
         }
     }
     $this->validateMappings($iconMaps, false);
     $iconMapsUpd = API::IconMap()->get(['iconmapids' => $iconMapids, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'selectMappings' => API_OUTPUT_EXTEND]);
     $oldIconMappings = [];
     $newIconMappings = [];
     foreach ($iconMaps as $iconMap) {
         if (!isset($iconMapsUpd[$iconMap['iconmapid']])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map with iconmapid "%s" does not exist.', $iconMap['iconmapid']));
         }
         // Existence
         if (isset($iconMap['name'])) {
             $iconMapExists = $this->get(['filter' => ['name' => $iconMap['name']], 'output' => ['iconmapid'], 'editable' => true, 'nopermissions' => true, 'preservekeys' => true]);
             if (($iconMapExists = reset($iconMapExists)) && bccomp($iconMapExists['iconmapid'], $iconMap['iconmapid']) != 0) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%s" already exists.', $iconMap['name']));
             }
         }
         if (isset($iconMap['mappings'])) {
             $mappingsDb = $iconMapsUpd[$iconMap['iconmapid']]['mappings'];
             foreach ($mappingsDb as $mapping) {
                 $oldIconMappings[] = $mapping;
             }
             foreach ($iconMap['mappings'] as $mapping) {
                 $mapping['iconmapid'] = $iconMap['iconmapid'];
                 $newIconMappings[] = $mapping;
             }
         }
         $iconMapid = $iconMap['iconmapid'];
         unset($iconMap['iconmapid']);
         if (!empty($iconMap)) {
             $updates[] = ['values' => $iconMap, 'where' => ['iconmapid' => $iconMapid]];
         }
     }
     DB::save('icon_map', $iconMaps);
     DB::replace('icon_mapping', $oldIconMappings, $newIconMappings);
     return ['iconmapids' => $iconMapids];
 }
Пример #4
0
    add_elementNames($map['selements']);
}
if (isset($_REQUEST['links']) || isset($_REQUEST['nolinks'])) {
    $map['links'] = get_request('links', '[]');
    $map['links'] = $json->decode($map['links'], true);
}
if (get_request('nocalculations', false)) {
    foreach ($map['selements'] as $selement) {
        if ($selement['elementtype'] != SYSMAP_ELEMENT_TYPE_IMAGE) {
            add_elementNames($map['selements']);
            break;
        }
    }
    // get default iconmap id to use for elements that use icon map
    if ($map['iconmapid']) {
        $iconMaps = API::IconMap()->get(array('iconmapids' => $map['iconmapid'], 'output' => array('default_iconid'), 'preservekeys' => true));
        $iconMap = reset($iconMaps);
        $defaultAutoIconId = $iconMap['default_iconid'];
    }
    $mapInfo = array();
    foreach ($map['selements'] as $selement) {
        // if element use icon map and icon map is set for map, and is host like element, we use default icon map icon
        if ($map['iconmapid'] && $selement['use_iconmap'] && ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST || $selement['elementtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS)) {
            $iconid = $defaultAutoIconId;
        } else {
            $iconid = $selement['iconid_off'];
        }
        $mapInfo[$selement['selementid']] = array('iconid' => $iconid, 'icon_type' => SYSMAP_ELEMENT_ICON_OFF);
        $mapInfo[$selement['selementid']]['name'] = $selement['elementtype'] == SYSMAP_ELEMENT_TYPE_IMAGE ? _('Image') : $selement['elementName'];
    }
    $allLinks = true;
Пример #5
0
 /**
  * Select icon map ids for previously added icon maps names.
  */
 protected function selectIconMaps()
 {
     if (!empty($this->iconMaps)) {
         $this->iconMapsRefs = array();
         $dbIconMaps = API::IconMap()->get(array('filter' => array('name' => $this->iconMaps), 'output' => array('iconmapid', 'name'), 'preservekeys' => true));
         foreach ($dbIconMaps as $iconMap) {
             $this->iconMapsRefs[$iconMap['name']] = $iconMap['iconmapid'];
         }
         $this->iconMaps = array();
     }
 }
Пример #6
0
 /**
  * Update IconMap.
  * @param array $iconMaps
  * @return array
  */
 public function update(array $iconMaps)
 {
     if (USER_TYPE_SUPER_ADMIN != self::$userData['type']) {
         self::exception(ZBX_API_ERROR_PERMISSIONS, _('Only Super Admins can update icon maps.'));
     }
     $iconMaps = zbx_toArray($iconMaps);
     $iconMapids = zbx_objectValues($iconMaps, 'iconmapid');
     $updates = array();
     $duplicates = array();
     foreach ($iconMaps as $iconMap) {
         if (!check_db_fields(array('iconmapid' => null), $iconMap)) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Incorrect parameters for icon map update method "%s".', $iconMap['name']));
         }
         if (isset($iconMap['name'])) {
             if (zbx_empty($iconMap['name'])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map name cannot be empty.'));
             } elseif (isset($duplicates[$iconMap['name']])) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Cannot create icon maps with identical name "%s".', $iconMap['name']));
             } else {
                 $duplicates[$iconMap['name']] = $iconMap['name'];
             }
         }
     }
     $this->validateMappings($iconMaps, false);
     $iconMapsUpd = API::IconMap()->get(array('iconmapids' => $iconMapids, 'output' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'selectMappings' => API_OUTPUT_EXTEND));
     $mappingsCreate = $mappingsUpdate = $mappingidsDelete = array();
     foreach ($iconMaps as $iconMap) {
         if (!isset($iconMapsUpd[$iconMap['iconmapid']])) {
             self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map with iconmapid "%s" does not exist.', $iconMap['iconmapid']));
         }
         // Existence
         if (isset($iconMap['name'])) {
             $iconMapExists = $this->get(array('filter' => array('name' => $iconMap['name']), 'output' => API_OUTPUT_SHORTEN, 'editable' => true, 'nopermissions' => true, 'preservekeys' => true));
             if (($iconMapExists = reset($iconMapExists)) && bccomp($iconMapExists['iconmapid'], $iconMap['iconmapid']) != 0) {
                 self::exception(ZBX_API_ERROR_PARAMETERS, _s('Icon map "%s" already exists.', $iconMap['name']));
             }
         }
         if (isset($iconMap['mappings'])) {
             $mappingsDb = $iconMapsUpd[$iconMap['iconmapid']]['mappings'];
             foreach ($iconMap['mappings'] as $mapping) {
                 $mapping['iconmapid'] = $iconMap['iconmapid'];
                 if (isset($mapping['iconmappingid']) && isset($mappingsDb[$mapping['iconmappingid']])) {
                     $iconmappingid = $mapping['iconmappingid'];
                     unset($mapping['iconmappingid']);
                     $mappingsUpdate[] = array('values' => $mapping, 'where' => array('iconmappingid' => $iconmappingid));
                     unset($mappingsDb[$iconmappingid]);
                 } else {
                     $mappingsCreate[] = $mapping;
                 }
             }
             $mappingidsDelete = array_merge($mappingidsDelete, array_keys($mappingsDb));
         }
         $iconMapid = $iconMap['iconmapid'];
         unset($iconMap['iconmapid']);
         if (!empty($iconMap)) {
             $updates[] = array('values' => $iconMap, 'where' => array('iconmapid' => $iconMapid));
         }
     }
     DB::update('icon_map', $updates);
     DB::insert('icon_mapping', $mappingsCreate);
     DB::update('icon_mapping', $mappingsUpdate);
     if (!empty($mappingidsDelete)) {
         DB::delete('icon_mapping', array('iconmappingid' => $mappingidsDelete));
     }
     return array('iconmapids' => $iconMapids);
 }
Пример #7
0
$data['sysmap']['selements'] = zbx_toHash($data['sysmap']['selements'], 'selementid');
$data['sysmap']['links'] = zbx_toHash($data['sysmap']['links'], 'linkid');
// get links
foreach ($data['sysmap']['links'] as &$link) {
    foreach ($link['linktriggers'] as $lnum => $linkTrigger) {
        $dbTrigger = API::Trigger()->get(array('triggerids' => $linkTrigger['triggerid'], 'output' => array('description', 'expression'), 'selectHosts' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'expandDescription' => true));
        $dbTrigger = reset($dbTrigger);
        $host = reset($dbTrigger['hosts']);
        $link['linktriggers'][$lnum]['desc_exp'] = $host['name'] . NAME_DELIMITER . $dbTrigger['description'];
    }
    order_result($link['linktriggers'], 'desc_exp');
}
unset($link);
// get iconmapping
if ($data['sysmap']['iconmapid']) {
    $iconMap = API::IconMap()->get(array('iconmapids' => $data['sysmap']['iconmapid'], 'output' => array('default_iconid'), 'preservekeys' => true));
    $iconMap = reset($iconMap);
    $data['defaultAutoIconId'] = $iconMap['default_iconid'];
}
// get icon list
$icons = DBselect('SELECT i.imageid,i.name FROM images i WHERE i.imagetype=' . IMAGE_TYPE_ICON);
while ($icon = DBfetch($icons)) {
    $data['iconList'][] = array('imageid' => $icon['imageid'], 'name' => $icon['name']);
    if ($icon['name'] == MAP_DEFAULT_ICON || !isset($data['defaultIconId'])) {
        $data['defaultIconId'] = $icon['imageid'];
        $data['defaultIconName'] = $icon['name'];
    }
}
if ($data['iconList']) {
    CArrayHelper::sort($data['iconList'], array('name'));
    $data['iconList'] = array_values($data['iconList']);
Пример #8
0
    $data['iconList'][$icon['imageid']] = $icon['name'];
}
$inventoryFields = getHostInventories();
foreach ($inventoryFields as $field) {
    $data['inventoryList'][$field['nr']] = $field['title'];
}
if (isset($_REQUEST['form'])) {
    if ($data['form_refresh'] || $_REQUEST['form'] === 'clone') {
        $data['iconmap'] = get_request('iconmap');
    } elseif (isset($_REQUEST['iconmapid'])) {
        $data['iconmap'] = reset($iconMap);
    } else {
        $firstIcon = reset($iconList);
        $data['iconmap'] = array('name' => '', 'default_iconid' => $firstIcon['imageid'], 'mappings' => array());
    }
    $iconMapView = new CView('administration.general.iconmap.edit', $data);
} else {
    $iconMapWidget->addHeader(_('Icon mapping'));
    $data['iconmaps'] = API::IconMap()->get(array('output' => API_OUTPUT_EXTEND, 'editable' => true, 'preservekeys' => true, 'selectMappings' => API_OUTPUT_EXTEND));
    order_result($data['iconmaps'], 'name');
    // nodes
    foreach ($data['iconmaps'] as &$iconMap) {
        order_result($iconMap['mappings'], 'sortorder');
        $iconMap['nodename'] = $data['displayNodes'] ? get_node_name_by_elid($iconMap['iconmapid'], true) : '';
    }
    unset($iconMap);
    $iconMapView = new CView('administration.general.iconmap.list', $data);
}
$iconMapWidget->addItem($iconMapView->render());
$iconMapWidget->show();
require_once dirname(__FILE__) . '/include/page_footer.php';
Пример #9
0
$data['sysmap']['selements'] = zbx_toHash($data['sysmap']['selements'], 'selementid');
$data['sysmap']['links'] = zbx_toHash($data['sysmap']['links'], 'linkid');
// get links
foreach ($data['sysmap']['links'] as &$link) {
    foreach ($link['linktriggers'] as $lnum => $linkTrigger) {
        $dbTrigger = API::Trigger()->get(['triggerids' => $linkTrigger['triggerid'], 'output' => ['description', 'expression'], 'selectHosts' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'expandDescription' => true]);
        $dbTrigger = reset($dbTrigger);
        $host = reset($dbTrigger['hosts']);
        $link['linktriggers'][$lnum]['desc_exp'] = $host['name'] . NAME_DELIMITER . $dbTrigger['description'];
    }
    order_result($link['linktriggers'], 'desc_exp');
}
unset($link);
// get iconmapping
if ($data['sysmap']['iconmapid']) {
    $iconMap = API::IconMap()->get(['iconmapids' => $data['sysmap']['iconmapid'], 'output' => ['default_iconid'], 'preservekeys' => true]);
    $iconMap = reset($iconMap);
    $data['defaultAutoIconId'] = $iconMap['default_iconid'];
}
// get icon list
$icons = DBselect('SELECT i.imageid,i.name FROM images i WHERE i.imagetype=' . IMAGE_TYPE_ICON);
while ($icon = DBfetch($icons)) {
    $data['iconList'][] = ['imageid' => $icon['imageid'], 'name' => $icon['name']];
    if ($icon['name'] == MAP_DEFAULT_ICON || !isset($data['defaultIconId'])) {
        $data['defaultIconId'] = $icon['imageid'];
        $data['defaultIconName'] = $icon['name'];
    }
}
if ($data['iconList']) {
    CArrayHelper::sort($data['iconList'], ['name']);
    $data['iconList'] = array_values($data['iconList']);
Пример #10
0
 /**
  * Get Map data
  *
  * @param array $options
  * @param array $options['nodeids'] Node IDs
  * @param array $options['groupids'] HostGroup IDs
  * @param array $options['hostids'] Host IDs
  * @param boolean $options['monitored_hosts'] only monitored Hosts
  * @param boolean $options['templated_hosts'] include templates in result
  * @param boolean $options['with_items'] only with items
  * @param boolean $options['with_historical_items'] only with historical items
  * @param boolean $options['with_triggers'] only with triggers
  * @param boolean $options['with_httptests'] only with http tests
  * @param boolean $options['with_graphs'] only with graphs
  * @param boolean $options['editable'] only with read-write permission. Ignored for SuperAdmins
  * @param int $options['count'] count Hosts, returned column name is rowscount
  * @param string $options['pattern'] search hosts by pattern in host names
  * @param int $options['limit'] limit selection
  * @param string $options['sortorder']
  * @param string $options['sortfield']
  * @return array|boolean Host data as array or false if error
  */
 public function get($options = array())
 {
     $result = array();
     $userType = self::$userData['type'];
     // allowed columns for sorting
     $sortColumns = array('name', 'width', 'height');
     // allowed output options for [ select_* ] params
     $subselectsAllowedOutputs = array(API_OUTPUT_REFER, API_OUTPUT_EXTEND);
     $sqlParts = array('select' => array('sysmaps' => 's.sysmapid'), 'from' => array('sysmaps' => 'sysmaps s'), 'where' => array(), 'order' => array(), 'limit' => null);
     $defOptions = array('nodeids' => null, 'sysmapids' => null, 'editable' => null, 'nopermissions' => null, 'filter' => null, 'search' => null, 'searchByAny' => null, 'startSearch' => null, 'excludeSearch' => null, 'searchWildcardsEnabled' => null, 'output' => API_OUTPUT_REFER, 'selectSelements' => null, 'selectLinks' => null, 'selectIconMap' => null, 'countOutput' => null, 'expandUrls' => null, 'preservekeys' => null, 'sortfield' => '', 'sortorder' => '', 'limit' => null);
     $options = zbx_array_merge($defOptions, $options);
     if (is_array($options['output'])) {
         unset($sqlParts['select']['sysmaps']);
         $dbTable = DB::getSchema('sysmaps');
         $sqlParts['select']['sysmapid'] = 's.sysmapid';
         foreach ($options['output'] as $field) {
             if (isset($dbTable['fields'][$field])) {
                 $sqlParts['select'][$field] = 's.' . $field;
             }
         }
         $options['output'] = API_OUTPUT_CUSTOM;
     }
     // sysmapids
     if (!is_null($options['sysmapids'])) {
         zbx_value2array($options['sysmapids']);
         $sqlParts['where']['sysmapid'] = dbConditionInt('s.sysmapid', $options['sysmapids']);
     }
     // search
     if (!is_null($options['search'])) {
         zbx_db_search('sysmaps s', $options, $sqlParts);
     }
     // filter
     if (!is_null($options['filter'])) {
         $this->dbFilter('sysmaps s', $options, $sqlParts);
     }
     // output
     if ($options['output'] == API_OUTPUT_EXTEND) {
         $sqlParts['select']['sysmaps'] = 's.*';
     }
     // countOutput
     if (!is_null($options['countOutput'])) {
         $options['sortfield'] = '';
         $sqlParts['select'] = array('count(DISTINCT s.sysmapid) as rowscount');
     }
     // sorting
     zbx_db_sorting($sqlParts, $options, $sortColumns, 's');
     // limit
     if (zbx_ctype_digit($options['limit']) && $options['limit']) {
         $sqlParts['limit'] = $options['limit'];
     }
     $sysmapids = array();
     $sqlParts = $this->applyQueryNodeOptions($this->tableName(), $this->tableAlias(), $options, $sqlParts);
     $res = DBselect($this->createSelectQueryFromParts($sqlParts), $sqlParts['limit']);
     while ($sysmap = DBfetch($res)) {
         if ($options['countOutput']) {
             $result = $sysmap['rowscount'];
         } else {
             $sysmapids[$sysmap['sysmapid']] = $sysmap['sysmapid'];
             if ($options['output'] == API_OUTPUT_SHORTEN) {
                 $result[$sysmap['sysmapid']] = array('sysmapid' => $sysmap['sysmapid']);
             } else {
                 if (!isset($result[$sysmap['sysmapid']])) {
                     $result[$sysmap['sysmapid']] = array();
                 }
                 // originally we intended not to pass those parameters if advanced labels are off, but they might be useful
                 // leaving this block commented
                 // if (isset($sysmap['label_format']) && ($sysmap['label_format'] == SYSMAP_LABEL_ADVANCED_OFF)) {
                 // 	unset($sysmap['label_string_hostgroup'], $sysmap['label_string_host'], $sysmap['label_string_trigger'], $sysmap['label_string_map'], $sysmap['label_string_image']);
                 // }
                 if (!is_null($options['selectSelements']) && !isset($result[$sysmap['sysmapid']]['selements'])) {
                     $result[$sysmap['sysmapid']]['selements'] = array();
                 }
                 if (!is_null($options['selectLinks']) && !isset($result[$sysmap['sysmapid']]['links'])) {
                     $result[$sysmap['sysmapid']]['links'] = array();
                 }
                 if (!is_null($options['selectIconMap']) && !isset($result[$sysmap['sysmapid']]['iconmap'])) {
                     $result[$sysmap['sysmapid']]['iconmap'] = array();
                 }
                 if (!isset($result[$sysmap['sysmapid']]['urls'])) {
                     $result[$sysmap['sysmapid']]['urls'] = array();
                 }
                 $result[$sysmap['sysmapid']] += $sysmap;
             }
         }
     }
     if ($userType != USER_TYPE_SUPER_ADMIN && !$options['nopermissions']) {
         if (!empty($result)) {
             $linkTriggers = array();
             $dbLinkTriggers = DBselect('SELECT slt.triggerid,sl.sysmapid' . ' FROM sysmaps_link_triggers slt,sysmaps_links sl' . ' WHERE ' . dbConditionInt('sl.sysmapid', $sysmapids) . ' AND sl.linkid=slt.linkid');
             while ($linkTrigger = DBfetch($dbLinkTriggers)) {
                 $linkTriggers[$linkTrigger['sysmapid']] = $linkTrigger['triggerid'];
             }
             if (!empty($linkTriggers)) {
                 $trigOptions = array('triggerids' => $linkTriggers, 'editable' => $options['editable'], 'output' => API_OUTPUT_SHORTEN, 'preservekeys' => true);
                 $allTriggers = API::Trigger()->get($trigOptions);
                 foreach ($linkTriggers as $id => $triggerid) {
                     if (!isset($allTriggers[$triggerid])) {
                         unset($result[$id], $sysmapids[$id]);
                     }
                 }
             }
             $hostsToCheck = array();
             $mapsToCheck = array();
             $triggersToCheck = array();
             $hostGroupsToCheck = array();
             $selements = array();
             $dbSelements = DBselect('SELECT se.* FROM sysmaps_elements se WHERE ' . dbConditionInt('se.sysmapid', $sysmapids));
             while ($selement = DBfetch($dbSelements)) {
                 $selements[$selement['selementid']] = $selement;
                 switch ($selement['elementtype']) {
                     case SYSMAP_ELEMENT_TYPE_HOST:
                         $hostsToCheck[$selement['elementid']] = $selement['elementid'];
                         break;
                     case SYSMAP_ELEMENT_TYPE_MAP:
                         $mapsToCheck[$selement['elementid']] = $selement['elementid'];
                         break;
                     case SYSMAP_ELEMENT_TYPE_TRIGGER:
                         $triggersToCheck[$selement['elementid']] = $selement['elementid'];
                         break;
                     case SYSMAP_ELEMENT_TYPE_HOST_GROUP:
                         $hostGroupsToCheck[$selement['elementid']] = $selement['elementid'];
                         break;
                 }
             }
             $nodeids = get_current_nodeid(true);
             if (!empty($hostsToCheck)) {
                 $hostOptions = array('hostids' => $hostsToCheck, 'nodeids' => $nodeids, 'editable' => $options['editable'], 'preservekeys' => true, 'output' => API_OUTPUT_SHORTEN);
                 $allowedHosts = API::Host()->get($hostOptions);
                 foreach ($hostsToCheck as $elementid) {
                     if (!isset($allowedHosts[$elementid])) {
                         foreach ($selements as $selementid => $selement) {
                             if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST && bccomp($selement['elementid'], $elementid) == 0) {
                                 unset($result[$selement['sysmapid']], $selements[$selementid]);
                             }
                         }
                     }
                 }
             }
             if (!empty($mapsToCheck)) {
                 $mapOptions = array('sysmapids' => $mapsToCheck, 'nodeids' => $nodeids, 'editable' => $options['editable'], 'preservekeys' => true, 'output' => API_OUTPUT_SHORTEN);
                 $allowedMaps = $this->get($mapOptions);
                 foreach ($mapsToCheck as $elementid) {
                     if (!isset($allowedMaps[$elementid])) {
                         foreach ($selements as $selementid => $selement) {
                             if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_MAP && bccomp($selement['elementid'], $elementid) == 0) {
                                 unset($result[$selement['sysmapid']], $selements[$selementid]);
                             }
                         }
                     }
                 }
             }
             if (!empty($triggersToCheck)) {
                 $triggeridOptions = array('triggerids' => $triggersToCheck, 'nodeids' => $nodeids, 'editable' => $options['editable'], 'preservekeys' => true, 'output' => API_OUTPUT_SHORTEN);
                 $allowedTriggers = API::Trigger()->get($triggeridOptions);
                 foreach ($triggersToCheck as $elementid) {
                     if (!isset($allowedTriggers[$elementid])) {
                         foreach ($selements as $selementid => $selement) {
                             if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_TRIGGER && bccomp($selement['elementid'], $elementid) == 0) {
                                 unset($result[$selement['sysmapid']], $selements[$selementid]);
                             }
                         }
                     }
                 }
             }
             if (!empty($hostGroupsToCheck)) {
                 $hostgroupOptions = array('groupids' => $hostGroupsToCheck, 'nodeids' => $nodeids, 'editable' => $options['editable'], 'preservekeys' => true, 'output' => API_OUTPUT_SHORTEN);
                 $allowedHostGroups = API::HostGroup()->get($hostgroupOptions);
                 foreach ($hostGroupsToCheck as $elementid) {
                     if (!isset($allowedHostGroups[$elementid])) {
                         foreach ($selements as $selementid => $selement) {
                             if ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST_GROUP && bccomp($selement['elementid'], $elementid) == 0) {
                                 unset($result[$selement['sysmapid']], $selements[$selementid]);
                             }
                         }
                     }
                 }
             }
             $sysmapids = array_keys($result);
         }
     }
     if (!is_null($options['countOutput'])) {
         return $result;
     }
     // adding elements
     if (!is_null($options['selectSelements']) && str_in_array($options['selectSelements'], $subselectsAllowedOutputs)) {
         $selements = array();
         $dbSelements = DBselect('SELECT se.*' . ' FROM sysmaps_elements se' . ' WHERE ' . dbConditionInt('se.sysmapid', $sysmapids));
         while ($selement = DBfetch($dbSelements)) {
             $selement['urls'] = array();
             $selements[$selement['selementid']] = $selement;
         }
         if (!is_null($options['expandUrls'])) {
             $dbMapUrls = DBselect('SELECT sysmapurlid, sysmapid, name, url, elementtype' . ' FROM sysmap_url' . ' WHERE ' . dbConditionInt('sysmapid', $sysmapids));
             while ($mapUrl = DBfetch($dbMapUrls)) {
                 foreach ($selements as $snum => $selement) {
                     if (bccomp($selement['sysmapid'], $mapUrl['sysmapid']) == 0 && ($selement['elementtype'] == $mapUrl['elementtype'] && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP || $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS && $mapUrl['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST)) {
                         $selements[$snum]['urls'][] = $this->expandUrlMacro($mapUrl, $selement);
                     }
                 }
             }
         }
         $dbSelementUrls = DBselect('SELECT seu.sysmapelementurlid,seu.selementid,seu.name,seu.url' . ' FROM sysmap_element_url seu' . ' WHERE ' . dbConditionInt('seu.selementid', array_keys($selements)));
         while ($selementUrl = DBfetch($dbSelementUrls)) {
             if (is_null($options['expandUrls'])) {
                 $selements[$selementUrl['selementid']]['urls'][] = $selementUrl;
             } else {
                 $selements[$selementUrl['selementid']]['urls'][] = $this->expandUrlMacro($selementUrl, $selements[$selementUrl['selementid']]);
             }
         }
         foreach ($selements as $selement) {
             if (!isset($result[$selement['sysmapid']]['selements'])) {
                 $result[$selement['sysmapid']]['selements'] = array();
             }
             if (!is_null($options['preservekeys'])) {
                 $result[$selement['sysmapid']]['selements'][$selement['selementid']] = $selement;
             } else {
                 $result[$selement['sysmapid']]['selements'][] = $selement;
             }
         }
     }
     // adding icon maps
     if (!is_null($options['selectIconMap']) && str_in_array($options['selectIconMap'], $subselectsAllowedOutputs)) {
         $iconMaps = API::IconMap()->get(array('sysmapids' => $sysmapids, 'output' => $options['selectIconMap'], 'selectMappings' => API_OUTPUT_EXTEND, 'preservekeys' => true, 'nopermissions' => true));
         foreach ($iconMaps as $iconMap) {
             $isysmaps = $iconMap['sysmaps'];
             unset($iconMap['sysmaps']);
             foreach ($isysmaps as $sysmap) {
                 $result[$sysmap['sysmapid']]['iconmap'] = $iconMap;
             }
         }
     }
     // adding links
     if (!is_null($options['selectLinks']) && str_in_array($options['selectLinks'], $subselectsAllowedOutputs)) {
         $linkids = array();
         $mapLinks = array();
         $dbLinks = DBselect('SELECT sl.* FROM sysmaps_links sl WHERE ' . dbConditionInt('sl.sysmapid', $sysmapids));
         while ($link = DBfetch($dbLinks)) {
             $link['linktriggers'] = array();
             $mapLinks[$link['linkid']] = $link;
             $linkids[$link['linkid']] = $link['linkid'];
         }
         $dbLinkTriggers = DBselect('SELECT DISTINCT slt.* FROM sysmaps_link_triggers slt WHERE ' . dbConditionInt('slt.linkid', $linkids));
         while ($linkTrigger = DBfetch($dbLinkTriggers)) {
             $mapLinks[$linkTrigger['linkid']]['linktriggers'][$linkTrigger['linktriggerid']] = $linkTrigger;
         }
         foreach ($mapLinks as $link) {
             if (!isset($result[$link['sysmapid']]['links'])) {
                 $result[$link['sysmapid']]['links'] = array();
             }
             if (!is_null($options['preservekeys'])) {
                 $result[$link['sysmapid']]['links'][$link['linkid']] = $link;
             } else {
                 $result[$link['sysmapid']]['links'][] = $link;
             }
         }
     }
     // adding urls
     if ($options['output'] != API_OUTPUT_SHORTEN) {
         $dbUrls = DBselect('SELECT su.* FROM sysmap_url su WHERE ' . dbConditionInt('su.sysmapid', $sysmapids));
         while ($url = DBfetch($dbUrls)) {
             $sysmapid = $url['sysmapid'];
             unset($url['sysmapid']);
             $result[$sysmapid]['urls'][] = $url;
         }
     }
     // removing keys (hash -> array)
     if (is_null($options['preservekeys'])) {
         $result = zbx_cleanHashes($result);
     }
     return $result;
 }
Пример #11
0
    }
    $data['current_user_userid'] = $current_userid;
    $data['form_refresh'] = getRequest('form_refresh');
    // config
    $data['config'] = select_config();
    // advanced labels
    $data['labelTypes'] = sysmapElementLabel();
    $data['labelTypesLimited'] = $data['labelTypes'];
    unset($data['labelTypesLimited'][MAP_LABEL_TYPE_IP]);
    $data['labelTypesImage'] = $data['labelTypesLimited'];
    unset($data['labelTypesImage'][MAP_LABEL_TYPE_STATUS]);
    // images
    $data['images'] = API::Image()->get(['output' => ['imageid', 'name'], 'filter' => ['imagetype' => IMAGE_TYPE_BACKGROUND]]);
    order_result($data['images'], 'name');
    // icon maps
    $data['iconMaps'] = API::IconMap()->get(['output' => ['iconmapid', 'name'], 'preservekeys' => true]);
    order_result($data['iconMaps'], 'name');
    // render view
    $mapView = new CView('monitoring.sysmap.edit', $data);
    $mapView->render();
    $mapView->show();
} else {
    CProfile::delete('web.maps.sysmapid');
    $sortField = getRequest('sort', CProfile::get('web.' . $page['file'] . '.sort', 'name'));
    $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();
Пример #12
0
    // config
    $data['config'] = select_config();
    // advanced labels
    $data['labelTypes'] = sysmapElementLabel();
    $data['labelTypesLimited'] = $data['labelTypes'];
    unset($data['labelTypesLimited'][MAP_LABEL_TYPE_IP]);
    $data['labelTypesImage'] = $data['labelTypesLimited'];
    unset($data['labelTypesImage'][MAP_LABEL_TYPE_STATUS]);
    // images
    $data['images'] = API::Image()->get(array('output' => array('imageid', 'name'), 'filter' => array('imagetype' => IMAGE_TYPE_BACKGROUND)));
    order_result($data['images'], 'name');
    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
Пример #13
0
    add_elementNames($map['selements']);
}
if (isset($_REQUEST['links']) || isset($_REQUEST['nolinks'])) {
    $map['links'] = getRequest('links', '[]');
    $map['links'] = $json->decode($map['links'], true);
}
if (getRequest('nocalculations', false)) {
    foreach ($map['selements'] as $selement) {
        if ($selement['elementtype'] != SYSMAP_ELEMENT_TYPE_IMAGE) {
            add_elementNames($map['selements']);
            break;
        }
    }
    // get default iconmap id to use for elements that use icon map
    if ($map['iconmapid']) {
        $iconMaps = API::IconMap()->get(['iconmapids' => $map['iconmapid'], 'output' => ['default_iconid'], 'preservekeys' => true]);
        $iconMap = reset($iconMaps);
        $defaultAutoIconId = $iconMap['default_iconid'];
    }
    $mapInfo = [];
    foreach ($map['selements'] as $selement) {
        // if element use icon map and icon map is set for map, and is host like element, we use default icon map icon
        if ($map['iconmapid'] && $selement['use_iconmap'] && ($selement['elementtype'] == SYSMAP_ELEMENT_TYPE_HOST || $selement['elementtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP && $selement['elementsubtype'] == SYSMAP_ELEMENT_SUBTYPE_HOST_GROUP_ELEMENTS)) {
            $iconid = $defaultAutoIconId;
        } else {
            $iconid = $selement['iconid_off'];
        }
        $mapInfo[$selement['selementid']] = ['iconid' => $iconid, 'icon_type' => SYSMAP_ELEMENT_ICON_OFF];
        $mapInfo[$selement['selementid']]['name'] = $selement['elementtype'] == SYSMAP_ELEMENT_TYPE_IMAGE ? _('Image') : $selement['elementName'];
    }
    $allLinks = true;