Create Sites on Icingaweb2

Hello everyone

I’m wondering if it’s any possible to create an own created section/site on Icingaweb2. I already got somewhere by playing around with the specific files. For example, I modified the following file:

/usr/share/php/Icinga/Web/Menu.php

and modified:

    public function init()
{
    $this->addItem('dashboard', [
        'label'     => t('Dashboard'),
        'url'       => 'dashboard',
        'icon'      => 'dashboard',
        'priority'  => 10
    ]);
    $this->addItem('testsite', [
        'label'     => t('Test'),
        'url'       => 'about',
        'icon'      => 'dashboard',
        'priority'  => 10
    ]);

This gets me

which links to the about page

The about page can be modified in:

/usr/share/icingaweb2/application/views/scripts/about/index.phtml

If I modify that index.phtml and delete the full content (just for testing) and change the content to:

<h1>This is a title</h1>

I get:

title

Now, let’s say I want to create a completely different page. How can I do that? I tried to create a new folder in:

/usr/share/icingaweb2/application/views/scripts/

and I named it “test” and created an “index.phtml” in that folder. If I change the ‘url’ at the Menu.php to “test” I only get “Site not found”

I’m a bit stuck here and I’m hoping someone is able to help me

Thanks in advance.

Greetings
DaVu

I guess I might have answered my own question :wink:

I found the “controllers” and I copied the AboutController.php and changed it’s content to:

<?php
/* Icinga Web 2 | (c) 2015 Icinga Development Team | GPLv2+ */

namespace Icinga\Controllers;

use Icinga\Application\Icinga;
use Icinga\Application\Version;
use Icinga\Web\Controller;

class TestController extends Controller
{
    public function indexAction()
    {
        $this->view->version = Version::get();
        $this->view->modules = Icinga::app()->getModuleManager()->getLoadedModules();
        $this->view->tabs = $this->getTabs()->add(
            'test',
            array(
                'label' => $this->translate('Test'),
                'title' => $this->translate('Test Page'),
                'url'   => 'test'
            )
        )->activate('test');
    }
}

This, in combination with the changes mentioned above, gets me the new page

If that’s not the correct way, I’m open for any other suggestion

You should create your own module rather than modifying the existing code - I would look at the ‘doc’ module - https://github.com/Icinga/icingaweb2/tree/master/modules/doc - this will give you a good example of how to structure your own module.

Then you can create your own menu items, pages, etc.

Thanks much. I will have a look.