How to install and configure external dashboard for Icinga2

Install and configure Dashing with Icinga 2 to use external board for your Icinga2 instance.

Nextcloud
Dashing with Icinga 2

Icinga2 configuration

Add an API user for dashboard.

$  cat << EOF | sudo tee -a /etc/icinga2/conf.d/api-users.conf
object ApiUser "dashing" {
  password = "icinga2ondashingrandompassword"
  permissions = [ "status/query", "objects/query/*" ]
}
EOF
object ApiUser "dashing" {
  password = "icinga2ondashingrandompassword"
  permissions = [ "status/query", "objects/query/*" ]
}

Reload configuration.

$ systemctl reload icinga2

Dashboard setup

Update package index.

$ sudo apt-get update
Ign:1 http://deb.debian.org/debian stretch InRelease
Get:2 http://security.debian.org stretch/updates InRelease [63.0 kB]
Hit:3 http://deb.debian.org/debian stretch Release
Get:5 http://deb.debian.org/debian stretch/main Translation-en [5393 kB]
Get:6 http://security.debian.org stretch/updates/main amd64 Packages [302 kB]
Get:7 http://security.debian.org stretch/updates/main Translation-en [132 kB]          
Fetched 5890 kB in 2s (2456 kB/s)                                                                 
Reading package lists... Done

Upgrade already installed packages.

$ sudo apt-get upgrade
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Calculating upgrade... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Install ruby and nodejs.

$ sudo apt-get install ruby nodejs
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  ca-certificates fonts-lato javascript-common libffi6 libgdbm3 libgmp10 libicu57 libjs-jquery libreadline7
  libruby2.3 libssl1.1 libuv1 libyaml-0-2 openssl rake readline-common ruby-did-you-mean ruby-minitest
  ruby-net-telnet ruby-power-assert ruby-test-unit ruby2.3 rubygems-integration unzip zip
Suggested packages:
  apache2 | lighttpd | httpd readline-doc ri ruby-dev bundler
The following NEW packages will be installed:
  ca-certificates fonts-lato javascript-common libffi6 libgdbm3 libgmp10 libicu57 libjs-jquery libreadline7
  libruby2.3 libssl1.1 libuv1 libyaml-0-2 nodejs openssl rake readline-common ruby ruby-did-you-mean ruby-minitest
  ruby-net-telnet ruby-power-assert ruby-test-unit ruby2.3 rubygems-integration unzip zip
0 upgraded, 27 newly installed, 0 to remove and 0 not upgraded.
Need to get 20.8 MB of archives.
After this operation, 80.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
[...]

Install dependencies for ruby gems.

$ sudo apt-get install git build-essential ruby-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  binutils bzip2 cpp cpp-6 dirmngr dpkg-dev fakeroot g++ g++-6 gcc gcc-6 git-man gnupg gnupg-agent gnupg-l10n less
  libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan3 libassuan0 libatomic1
  libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libcurl3-gnutls libdpkg-perl liberror-perl libexpat1 libfakeroot
  libfile-fcntllock-perl libgcc-6-dev libgmp-dev libgmpxx4ldbl libgnutls30 libgomp1 libhogweed4 libidn2-0 libisl15
  libitm1 libksba8 libldap-2.4-2 libldap-common liblocale-gettext-perl liblsan0 libmpc3 libmpfr4 libmpx2
  libnettle6 libnghttp2-14 libnpth0 libp11-kit0 libperl5.24 libpopt0 libpsl5 libquadmath0 librtmp1 libsasl2-2
  libsasl2-modules libsasl2-modules-db libsqlite3-0 libssh2-1 libstdc++-6-dev libtasn1-6 libtsan0 libubsan0
  libunistring0 linux-libc-dev make manpages manpages-dev patch perl perl-modules-5.24 pinentry-curses
  publicsuffix rename rsync ruby2.3-dev xz-utils
Suggested packages:
  binutils-doc bzip2-doc cpp-doc gcc-6-locales dbus-user-session libpam-systemd pinentry-gnome3 tor debian-keyring
  g++-multilib g++-6-multilib gcc-6-doc libstdc++6-6-dbg gcc-multilib autoconf automake libtool flex bison gdb
  gcc-doc gcc-6-multilib libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan3-dbg liblsan0-dbg
  libtsan0-dbg libubsan0-dbg libcilkrts5-dbg libmpx2-dbg libquadmath0-dbg gettext-base git-daemon-run
  | git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch git-cvs git-mediawiki git-svn
  parcimonie xloadimage scdaemon glibc-doc gmp-doc libgmp10-doc libmpfr-dev gnutls-bin libsasl2-modules-gssapi-mit
  | libsasl2-modules-gssapi-heimdal libsasl2-modules-ldap libsasl2-modules-otp libsasl2-modules-sql
  libstdc++-6-doc make-doc man-browser ed diffutils-doc perl-doc libterm-readline-gnu-perl
  | libterm-readline-perl-perl pinentry-doc openssh-server
The following NEW packages will be installed:
  binutils build-essential bzip2 cpp cpp-6 dirmngr dpkg-dev fakeroot g++ g++-6 gcc gcc-6 git git-man gnupg
  gnupg-agent gnupg-l10n less libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan3
  libassuan0 libatomic1 libc-dev-bin libc6-dev libcc1-0 libcilkrts5 libcurl3-gnutls libdpkg-perl liberror-perl
  libexpat1 libfakeroot libfile-fcntllock-perl libgcc-6-dev libgmp-dev libgmpxx4ldbl libgnutls30 libgomp1
  libhogweed4 libidn2-0 libisl15 libitm1 libksba8 libldap-2.4-2 libldap-common liblocale-gettext-perl liblsan0
  libmpc3 libmpfr4 libmpx2 libnettle6 libnghttp2-14 libnpth0 libp11-kit0 libperl5.24 libpopt0 libpsl5 libquadmath0
  librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db libsqlite3-0 libssh2-1 libstdc++-6-dev libtasn1-6
  libtsan0 libubsan0 libunistring0 linux-libc-dev make manpages manpages-dev patch perl perl-modules-5.24
  pinentry-curses publicsuffix rename rsync ruby-dev ruby2.3-dev xz-utils
0 upgraded, 84 newly installed, 0 to remove and 0 not upgraded.
Need to get 63.1 MB of archives.
After this operation, 264 MB of additional disk space will be used.
Do you want to continue? [Y/n] 
[...]

Add user that will be used to execute dashboard.

$ sudo useradd --system --create-home --home-dir /srv/dashing --shell /bin/bash dashing

Verify installed ruby version.

$ apt-cache policy ruby
ruby:
  Installed: 1:2.3.3
  Candidate: 1:2.3.3
  Version table:
 *** 1:2.3.3 500
        500 http://deb.debian.org/debian stretch/main amd64 Packages
        100 /var/lib/dpkg/status

Set PATH and GEM_PATH accordingly to ruby version.

$ echo "PATH=\"\$PATH:/srv/dashing/.gem/ruby/2.3.0/bin\"" | sudo tee -a /srv/dashing/.profile
echo "GEM_PATH=\"/srv/dashing/.gem/ruby/2.3.0/\"" | sudo tee -a /srv/dashing/.profile

Install bundler gem.

$ cd /tmp && sudo -u dashing -i bash -c 'gem install --user-install bundler'
Fetching: bundler-1.16.1.gem (100%)
Successfully installed bundler-1.16.1
Parsing documentation for bundler-1.16.1
Installing ri documentation for bundler-1.16.1
Done installing documentation for bundler after 8 seconds
1 gem installed

Get Dashing with Icinga 2 source code.

$ cd /tmp && sudo -u dashing git clone --depth 1 https://github.com/Icinga/dashing-icinga2.git /srv/dashing/dashing-icinga2
Cloning into '/srv/dashing/dashing-icinga2'...
remote: Counting objects: 116, done.
remote: Compressing objects: 100% (99/99), done.
remote: Total 116 (delta 8), reused 94 (delta 6), pack-reused 0
Receiving objects: 100% (116/116), 658.11 KiB | 0 bytes/s, done.
Resolving deltas: 100% (8/8), done.
$ sudo -u dashing -i bash -c 'cd /srv/dashing/dashing-icinga2/ && bundle install --path /srv/dashing/.gem'
Fetching gem metadata from https://rubygems.org/.........
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Fetching backports 3.11.1
Installing backports 3.11.1
Using bundler 1.16.1
Fetching coffee-script-source 1.12.2
Installing coffee-script-source 1.12.2
Fetching execjs 2.0.2
Installing execjs 2.0.2
Fetching coffee-script 2.2.0
Installing coffee-script 2.2.0
Fetching daemons 1.2.6
Installing daemons 1.2.6
Fetching rack 1.5.5
Installing rack 1.5.5
Fetching thread_safe 0.3.6
Installing thread_safe 0.3.6
Fetching tzinfo 1.2.5
Installing tzinfo 1.2.5
Fetching rufus-scheduler 2.0.24
Installing rufus-scheduler 2.0.24
Fetching sass 3.2.19
Installing sass 3.2.19
Fetching rack-protection 1.5.4
Installing rack-protection 1.5.4
Fetching tilt 1.4.1
Installing tilt 1.4.1
Fetching sinatra 1.4.8
Installing sinatra 1.4.8
Fetching multi_json 1.13.1
Installing multi_json 1.13.1
Fetching rack-test 0.7.0
Installing rack-test 0.7.0
Fetching sinatra-contrib 1.4.7
Installing sinatra-contrib 1.4.7
Fetching hike 1.2.3
Installing hike 1.2.3
Fetching sprockets 2.10.2
Installing sprockets 2.10.2
Fetching eventmachine 1.2.5
Installing eventmachine 1.2.5 with native extensions
Fetching thin 1.6.4
Installing thin 1.6.4 with native extensions
Fetching thor 0.20.0
Installing thor 0.20.0
Fetching dashing 1.3.7
Installing dashing 1.3.7
Fetching unf_ext 0.0.7.5
Installing unf_ext 0.0.7.5 with native extensions
Fetching unf 0.1.4
Installing unf 0.1.4
Fetching domain_name 0.5.20170404
Installing domain_name 0.5.20170404
Fetching http-cookie 1.0.3
Installing http-cookie 1.0.3
Fetching json 2.1.0
Installing json 2.1.0 with native extensions
Fetching mime-types-data 3.2016.0521
Installing mime-types-data 3.2016.0521
Fetching mime-types 3.1
Installing mime-types 3.1
Fetching netrc 0.11.0
Installing netrc 0.11.0
Fetching rest-client 2.0.2
Installing rest-client 2.0.2
Bundle complete! 6 Gemfile dependencies, 32 gems now installed.
Bundled gems are installed into `/srv/dashing/.gem`

Define Icinga2 host, port, API user, API password and URL to configure dashboard.

$ cat << EOF | sudo tee /srv/dashing/dashing-icinga2/config/icinga2.json 
{
  "icinga2": {
    "api": {
      "host": "10.66.91.37",
      "port": 5665,
      "user": "dashing",
      "password": "icinga2ondashingrandompassword"
    }
  },
  "icingaweb2": {
    "url": "http://10.66.91.37/icingaweb2"
  }
}
EOF
{
  "icinga2": {
    "api": {
      "host": "10.66.91.37",
      "port": 5665,
      "user": "dashing",
      "password": "icinga2ondashingrandompassword"
    }
  },
  "icingaweb2": {
    "url": "http://10.66.91.37/icingaweb2"
  }
}

Execute dashing in foreground to test dashboard.

$ cd /tmp && sudo -u dashing -i bash -c  'cd /srv/dashing/dashing-icinga2/ && dashing start -p 8000 --pid tmp/pids/thin.pid'
First trying to read environment variables
Environment variables not found, falling back to configuration file config/icinga2.json
Detecting local config file '/srv/dashing/dashing-icinga2/config/icinga2.local.json'.
Using config file '/srv/dashing/dashing-icinga2/config/icinga2.json'.
Reading config{"icinga2"=>{"api"=>{"host"=>"10.66.91.37", "port"=>5665, "user"=>"dashing", "password"=>"icinga2ondashingrandompassword"}}, "icingaweb2"=>{"url"=>"http://10.66.91.37/icingaweb2"}}
Thin web server (v1.6.4 codename Gob Bluth)
Maximum connections set to 1024
Listening on 0.0.0.0:8000, CTRL+C to stop
App Info: {"icingaapplication"=>{"app"=>{"enable_event_handlers"=>true, "enable_flapping"=>true, "enable_host_checks"=>true, "enable_notifications"=>true, "enable_perfdata"=>true, "enable_service_checks"=>true, "node_name"=>"monitoring.fishsilentcruise.space", "pid"=>3059.0, "program_start"=>1519078339.793984, "version"=>"r2.8.1-1"}}}
Meter widget: Hosts 0.0/13 Services 24.0/123
Stats: [{"label"=>"Host checks/min", "value"=>2.0}, {"label"=>"Service checks/min", "value"=>5.0}, {"label"=>"json_rpc queue rate", "value"=>"0.45"}, {"label"=>"ido-pgsql queue rate", "value"=>"1.72"}]
Severity: [{"label"=>"www.sleeplessbeastie.eu - Check memory", "color"=>"red", "state"=>2}, {"label"=>"statistics.sleeplessbeastie.eu - Check HTTP", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for survey.sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for statistics.sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for blog.sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for www.sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - SSH", "color"=>"red", "state"=>2}, {"label"=>"news.fishsilentcruise.space - Check memory", "color"=>"red", "state"=>2}, {"label"=>"monitoring.sleeplessbeastie.eu - Check memory", "color"=>"red", "state"=>2}, {"label"=>"monitoring.fishsilentcruise.space - Check memory", "color"=>"red", "state"=>2}, {"label"=>"monitoring.fishsilentcruise.space - APT checks", "color"=>"red", "state"=>2}, {"label"=>"fishsilentcruise.space - APT checks", "color"=>"red", "state"=>2}, {"label"=>"survey.sleeplessbeastie.eu - Check memory", "color"=>"yellow", "state"=>1}, {"label"=>"www.sleeplessbeastie.eu - APT checks", "color"=>"yellow", "state"=>1}, {"label"=>"survey.sleeplessbeastie.eu - APT checks", "color"=>"yellow", "state"=>1}, {"label"=>"statistics.sleeplessbeastie.eu - APT checks", "color"=>"yellow", "state"=>1}, {"label"=>"news.fishsilentcruise.space - APT checks", "color"=>"yellow", "state"=>1}, {"label"=>"fishsilentcruise.space - Check pocesses", "color"=>"yellow", "state"=>1}, {"label"=>"draw.fishsilentcruise.space - APT checks", "color"=>"yellow", "state"=>1}]
Host Down: 0
Service Critical: 14
Service Warning: 10
Service Unknown: 0
^C
Stopping ...

Execute dashing in background.

$ cd /tmp && sudo -u dashing -i bash -c  'cd /srv/dashing/dashing-icinga2/ && dashing start -p 8000 --pid tmp/pids/thin.pid -d'

Stop dashing if necessary.

$ cd /tmp && sudo -u dashing -i bash -c  'cd /srv/dashing/dashing-icinga2/ && dashing stop'
Sending QUIT signal to process 5659 ...

Inspect log file.

$ cd /tmp && sudo -u dashing tail -f /srv/dashing/dashing-icinga2/log/thin.log
Listening on 0.0.0.0:8000, CTRL+C to stop
App Info: {"icingaapplication"=>{"app"=>{"enable_event_handlers"=>true, "enable_flapping"=>true, "enable_host_checks"=>true, "enable_notifications"=>true, "enable_perfdata"=>true, "enable_service_checks"=>true, "node_name"=>"monitoring.fishsilentcruise.space", "pid"=>3059.0, "program_start"=>1519078339.793984, "version"=>"r2.8.1-1"}}}
Meter widget: Hosts 0.0/13 Services 24.0/123
Stats: [{"label"=>"Host checks/min", "value"=>11.0}, {"label"=>"Service checks/min", "value"=>50.0}, {"label"=>"json_rpc queue rate", "value"=>"1.47"}, {"label"=>"ido-pgsql queue rate", "value"=>"3.63"}]
Severity: [{"label"=>"www.sleeplessbeastie.eu - Check memory", "color"=>"red", "state"=>2}, {"label"=>"statistics.sleeplessbeastie.eu - Check HTTP", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for survey.sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for statistics.sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for blog.sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - Check SSL certificate for www.sleeplessbeastie.eu", "color"=>"red", "state"=>2}, {"label"=>"sleeplessbeastie.eu - SSH", "color"=>"red", "state"=>2}, {"label"=>"news.fishsilentcruise.space - Check memory", "color"=>"red", "state"=>2}, {"label"=>"monitoring.sleeplessbeastie.eu - Check memory", "color"=>"red", "state"=>2}, {"label"=>"monitoring.fishsilentcruise.space - Check memory", "color"=>"red", "state"=>2}, {"label"=>"monitoring.fishsilentcruise.space - APT checks", "color"=>"red", "state"=>2}, {"label"=>"fishsilentcruise.space - APT checks", "color"=>"red", "state"=>2}, {"label"=>"survey.sleeplessbeastie.eu - Check memory", "color"=>"yellow", "state"=>1}, {"label"=>"www.sleeplessbeastie.eu - APT checks", "color"=>"yellow", "state"=>1}, {"label"=>"survey.sleeplessbeastie.eu - APT checks", "color"=>"yellow", "state"=>1}, {"label"=>"statistics.sleeplessbeastie.eu - APT checks", "color"=>"yellow", "state"=>1}, {"label"=>"news.fishsilentcruise.space - APT checks", "color"=>"yellow", "state"=>1}, {"label"=>"fishsilentcruise.space - Check pocesses", "color"=>"yellow", "state"=>1}, {"label"=>"draw.fishsilentcruise.space - APT checks", "color"=>"yellow", "state"=>1}]
Host Down: 0
Service Critical: 14
Service Warning: 10
Service Unknown: 0
Exiting!
^C

Inspect dashboards directory to create your own dashboards.

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.