Beispiel #1
0
/**
 * Creates nodes that can be used to display the service configuration tree using the CTree class.
 *
 * @see CTree
 *
 * @param array $services
 * @param array $parentService
 * @param array $service
 * @param array $dependency
 * @param array $tree
 */
function createServiceConfigurationTree(array $services, &$tree, array $parentService = [], array $service = [], array $dependency = [])
{
    if (!$service) {
        $serviceNode = ['id' => 0, 'parentid' => 0, 'caption' => _('root'), 'trigger' => [], 'action' => new CHorList([(new CLink(_('Add child'), 'services.php?form=1&parentname=' . _('root')))->addClass(ZBX_STYLE_LINK_ACTION)]), 'algorithm' => SPACE, 'description' => SPACE];
        $service = $serviceNode;
        $service['serviceid'] = 0;
        $service['dependencies'] = [];
        $service['trigger'] = [];
        // add all top level services as children of "root"
        foreach ($services as $topService) {
            if (!$topService['parent']) {
                $service['dependencies'][] = ['servicedownid' => $topService['serviceid'], 'soft' => 0, 'linkid' => 0];
            }
        }
        $tree = [$serviceNode];
    } else {
        // service is deletable only if it has no hard dependency
        $deletable = true;
        foreach ($service['dependencies'] as $dep) {
            if ($dep['soft'] == 0) {
                $deletable = false;
                break;
            }
        }
        $serviceNode = ['id' => $service['serviceid'], 'caption' => new CLink($service['name'], 'services.php?form=1&serviceid=' . $service['serviceid']), 'action' => new CHorList([(new CLink(_('Add child'), 'services.php?form=1&parentid=' . $service['serviceid'] . '&parentname=' . $service['name']))->addClass(ZBX_STYLE_LINK_ACTION), $deletable ? (new CLink(_('Delete'), 'services.php?delete=1&serviceid=' . $service['serviceid']))->addClass(ZBX_STYLE_LINK_ACTION)->addConfirmation(_s('Delete service "%1$s"?', $service['name']))->addSID() : null]), 'description' => $service['trigger'] ? $service['trigger']['description'] : '', 'parentid' => $parentService ? $parentService['serviceid'] : 0, 'algorithm' => serviceAlgorithm($service['algorithm'])];
    }
    if (!$dependency || !$dependency['soft']) {
        $tree[$serviceNode['id']] = $serviceNode;
        foreach ($service['dependencies'] as $dependency) {
            $childService = $services[$dependency['servicedownid']];
            createServiceConfigurationTree($services, $tree, $service, $childService, $dependency);
        }
    } else {
        $serviceNode['caption'] = (new CSpan($serviceNode['caption']))->addClass('service-caption-soft');
        $tree[$serviceNode['id'] . '.' . $dependency['linkid']] = $serviceNode;
    }
}
Beispiel #2
0
        $data['trigger'] = '';
    }
    // render view
    $servicesView = new CView('configuration.services.edit', $data);
    $servicesView->render();
    $servicesView->show();
} else {
    // services
    $services = API::Service()->get(array('output' => array('name', 'serviceid', 'algorithm'), 'selectParent' => array('serviceid'), 'selectDependencies' => array('servicedownid', 'soft', 'linkid'), 'selectTrigger' => array('description', 'triggerid', 'expression'), 'preservekeys' => true, 'sortfield' => 'sortorder', 'sortorder' => ZBX_SORT_UP));
    // triggers
    $triggers = zbx_objectValues($services, 'trigger');
    $triggers = CMacrosResolverHelper::resolveTriggerNames($triggers);
    foreach ($services as &$service) {
        if ($service['trigger']) {
            $service['trigger'] = $triggers[$service['trigger']['triggerid']];
        }
    }
    unset($service);
    $treeData = array();
    createServiceConfigurationTree($services, $treeData);
    $tree = new CServiceTree('service_conf_tree', $treeData, array('caption' => _('Service'), 'algorithm' => _('Status calculation'), 'description' => _('Trigger')));
    if (empty($tree)) {
        error(_('Cannot format tree.'));
    }
    $data = array('tree' => $tree);
    // render view
    $servicesView = new CView('configuration.services.list', $data);
    $servicesView->render();
    $servicesView->show();
}
require_once dirname(__FILE__) . '/include/page_footer.php';
/**
 * Creates nodes that can be used to display the service configuration tree using the CTree class.
 *
 * @see CTree
 *
 * @param array $services
 * @param array $parentService
 * @param array $service
 * @param array $dependency
 * @param array $tree
 */
function createServiceConfigurationTree(array $services, &$tree, array $parentService = array(), array $service = array(), array $dependency = array())
{
    if (!$service) {
        $caption = new CLink(_('root'), '#', 'service-conf-menu');
        $caption->setAttribute('data-menu', array('serviceid' => 0, 'name' => _('root'), 'hasDependencies' => true));
        $serviceNode = array('id' => 0, 'parentid' => 0, 'caption' => $caption, 'trigger' => array(), 'algorithm' => SPACE, 'description' => SPACE);
        $service = $serviceNode;
        $service['serviceid'] = 0;
        $service['dependencies'] = array();
        $service['trigger'] = array();
        // add all top level services as children of "root"
        foreach ($services as $topService) {
            if (!$topService['parent']) {
                $service['dependencies'][] = array('servicedownid' => $topService['serviceid'], 'soft' => 0, 'linkid' => 0);
            }
        }
        $tree = array($serviceNode);
    } else {
        // caption
        $caption = new CLink($service['name'], '#', 'service-conf-menu');
        // service is deletable only if it has no hard dependency
        $deletable = true;
        foreach ($service['dependencies'] as $dep) {
            if ($dep['soft'] == 0) {
                $deletable = false;
                break;
            }
        }
        $caption->setAttribute('data-menu', array('serviceid' => $service['serviceid'], 'name' => $service['name'], 'deletable' => $deletable));
        $serviceNode = array('id' => $service['serviceid'], 'caption' => $caption, 'description' => $service['trigger'] ? $service['trigger']['description'] : '-', 'parentid' => $parentService ? $parentService['serviceid'] : 0, 'algorithm' => serviceAlgorythm($service['algorithm']));
    }
    if (!$dependency || !$dependency['soft']) {
        $tree[$serviceNode['id']] = $serviceNode;
        foreach ($service['dependencies'] as $dependency) {
            $childService = $services[$dependency['servicedownid']];
            createServiceConfigurationTree($services, $tree, $service, $childService, $dependency);
        }
    } else {
        $serviceNode['caption'] = new CSpan($serviceNode['caption'], 'service-caption-soft');
        $tree[$serviceNode['id'] . '.' . $dependency['linkid']] = $serviceNode;
    }
}