Action Menu

new in release v1.86

The Action Menu is a way to create custom icons and menus for every host or service. You may add multiple action icons or even multiple menus for each host or service. You can then open links or trigger server actions from that menu or icons.

Action Menu

Adding an Action Menu

There are 3 ways to add an action menu to a host or service.

  • set the menu directly by the _THRUK_ACTION_MENU custom variable

  • reference an existing menu from the action_menu_items by a _THRUK_ACTION_MENU custom variable

  • use apply rules from action_menu_apply

The are some examples in the configuration documentation.

Server Actions

Server Action can be triggered from icons or menu items by using a pseudo url like this in your action urls. See the configuration section on how and where to set this link.

    server://*scriptname*/argument1/argument2/...

To make this work, you need to define that scriptname in your thruk_local.conf:

  <action_menu_actions>
      scriptname   = /usr/local/bin/sample.sh $HOSTNAME$ $SERVICEDESC$
  </action_menu_actions>

When somebody clicks on that link, Thruk will start the sample.sh script like:

    /usr/local/bin/sample.sh <hostname> <servicename> argument1 argument2

First it uses the complete commandline from the thruk_local.conf and replaces all available macros. Then it adds the arguments from the link configuration.

See Macros for a list of all available macros.

Scripts

The scripts can do whatever they want. However you should consider a few things:

  • Make the script exit quickly. Thruk waits for the script to return. Long running tasks should be started in the background.

  • Give the user useful feedback on STDOUT

  • Exit codes should be zero if OK and greater than zero on errors.

script output

Script output will be displayed as user response which allows the script to give feedback to the user. HTML is allowed and will be used in the output.

Authorization / Security

The Script will be run whenever the user has access to the given host and service. Its general good advice to check the $REMOTE_USER and/or $REMOTE_USER_GROUPS environment variables before running critical scripts. Macros used in the command line defined in your config and the REMOTE_USER variables can be trusted. Variables supplied by the url can easily be faked and are considered unsafe.

Available standard environment variables are listed on the CLI Environment page.

Examples

Panorama Dashboard

This is a small example script which uses perl to change the color of a shaped icon.

icon settings

Dashboard Icon

thruk_local.conf
  <action_menu_actions>
    switch_color    = .../switch_color.pl $DASHBOARD_ID$ $DASHBOARD_ICON$
  </action_menu_actions>
switch_color.pl

just changes the color of the icon.

#!/usr/bin/perl

use warnings;
use strict;
use Thruk::Utils;

my $file  = 'var/panorama/'.$ARGV[0].'.tab';
my $data  = Thruk::Utils::read_data_file($file);
my $color = $data->{$ARGV[1]}->{'xdata'}->{'appearance'}->{'shapecolor_ok'};
if($color eq '#CA1414') {
    $color = '#199C0F';
} else {
    $color = '#CA1414';
}
$data->{$ARGV[1]}->{'xdata'}->{'appearance'}->{'shapecolor_ok'} = $color;
Thruk::Utils::write_data_file($file, $data);

print "switched color to $color\n";

Confirmation Dialog

new in release v2.14-2

Using arbitrary attributes, you can easily add a confirmation dialog to your server actions.

action_menus/confirm_restart.json
{
  "icon":"/thruk/themes//images/arrow_refresh.png",
  "label":"service restart",
  "action":"server://restart_service",
  "onclick": "return(confirm('Really restart service?'));"
}
Edit page on GitHub