Global dashlets available?

Hi,

is it anyhow possible to create global dashlets (for all users or specific user groups)?

Weeeell, no. At least not by an easy way.

You may create your own module, let it provide a dashboard and control who can see this dashboard by the usual module privileges.

The simplest way to do this is:

  • Create a directory beneath your module path (Package default: /usr/share/icingaweb2/modules)
  • Give it a catchy name such as global-dashboards
  • Create a file called configuration.php in the newly created directory, put the following into it:
<?php

$dashboard = $this->dashboard('Global Dashboards', ['priority' => 100]);
$dashboard->add(
    'Dashboard #1',
    'monitoring/list/hosts'
);
$dashboard->add(
    'Dashboard #2',
    'monitoring/list/services'
);

Then enable the module. To see its dashboard(s) a user requires access to the module. (Permission: module/global-dashboards) This can be controlled the usual way with roles.

3 Likes

Thanks a lot so far, but how can I assign this module a dashboard, which is displayed globally?

That’s what you define in the file configuration.php:

  • Global Dashboards is the dashboard name
  • Dashboard #1 the first dashlet’s name
  • Dashboard #2 the second dashlet’s name

The argument on the line below each dashlet name is the url that is shown.

And yes, that’s only adjustable by this file, not in the UI. That’s why I called this the not so easy way. :wink:

2 Likes

If you want to have Dasboards limited to usergroups just use this code (change to the group that should see the ddashboard)

<?php

use Icinga\Authentication\Auth;

$userGroups = "";

$auth = Auth::getInstance();
if ($auth->isAuthenticated()) {
  $userGroups = $auth->getUser()->getGroups();
  //var_dump($userGroups);
  //exit;
}

if (in_array("<USERGROUPNAME>", $userGroups)) {
  $dashboard = $this->dashboard('Global Dashboards', ['priority' => 1]);
  $dashboard->add(
      'Dashboard #1',
      'monitoring/list/hosts'
  );
  $dashboard->add(
      'Dashboard #2',
      'monitoring/list/services'
  );
}

if (in_array("<USERGROUPNAME>", $userGroups)) {
  $dashboard = $this->dashboard('Global Dashboards2', ['priority' => 2]);
  $dashboard->add(
      'Dashboard #1',
      'monitoring/list/hosts'
  );
  $dashboard->add(
      'Dashboard #2',
      'monitoring/list/services'
  );
}

Dirty hack, but it works :slight_smile:

1 Like

updated post above to fix an error if user is not in any group or not authenticated.

I know this thread is quite old, but I’d like to get back to your proposal of a workaround :slight_smile:

I have implemented my own module like you described and added a dashboard with some dashlets.

What annoys me is that the dashlets are displayed in alphabetical order instead of how they are put in the configuration.php

This seems to be some mechanic provided by icingaweb2, similar to the mechnism that the host and service problem listings will always be displayed on the same position on the default dashboard.
Can I avoid this alphabetcial sorting somehow?

<?php

$dashboard = $this->dashboard('My Dashboard', ['priority' => 0]);
$dashboard->add(
    'My tactical overview',
    'monitoring/tactical'
);
$dashboard->add(
    'Hostgroups',
    'monitoring/list/hostgroups'
);

$dashboard->add(
    'Services NOT OK',
    'monitoring/list/services?service_problem=1&sort=service_severity&dir=desc&limit=15'
);

$dashboard->add(
    'Hosts DOWN',
    'monitoring/list/hosts?host_problem=1&sort=host_severity'
);
?>

Also both php scripts posted here are missing a closing ?> if I am not mistaken?

Also also the “enhanced” script

seems to mess up the login page.

You can also pass a priority as a dashlet’s config.

$dashboard->add(
    'My tactical overview',
    'monitoring/tactical',
    0 // Should be the first dashlet then
);

That’s only necessary if there’s remaining non-PHP. Otherwise they’re discouraged.

That’s probably because it accesses the Auth object which is not recommended at this stage. If it’s about access to all dashboards this module provides (not individual ones), I’d rather solve this with a special role.

1 Like

Hi @nilmerg and @log1c:
Could this be done with Roles instead of Groups?
The problem in our case is that we can give permissions to our dashboard-module over a special role, but our administrators who have unrestricted access to icingaweb also see the dashboard and they don’t want to. Is there a solution for this?

After almost 2 years we still have this messed up login page. Is there another workaround to NOT lose the module restrictions but keep the beautiful login page?

The solution is the version 2.9 of Icinga Web and role refusals. I guess.

Put your admins in a role which refuses the permission to access said dashboards.

1 Like

Damn that was too easy, I should have thought of that myself! Of course we already use 2.9.6
Thank you, Johannes!
It is actually the “Deny General Module Access” Button which I enabled for the Administrators role.