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.