diff --git a/README.md b/README.md index 19cbf85..98be052 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,9 @@ In case you want to use client certificates, set the `client_cn` accordingly. Copy the example configuration from `config/icinga2.json` into `config/icinga2.local.json` and adjust the settings for the Icinga 2 API credentials. +The `icingaweb2` section allows you to specify the Icinga Web 2 URL +for the iframe widgets. This is read on startup once. + ``` cp config/icinga2.json config/icinga2.local.json ``` @@ -196,6 +199,9 @@ vim config/icinga2.local.json "user": "dashing", "password": "icinga2ondashingr0xx" } + }, + "icingaweb2": { + "url": "http://localhost/icingaweb2" } } ``` @@ -214,6 +220,9 @@ explicitly. "user": "dashing", "pki_path": "pki/" } + }, + "icingaweb2": { + "url": "http://localhost/icingaweb2" } } ``` @@ -238,6 +247,7 @@ ICINGA2\_API\_USERNAME | **Optional.** Required for basic auth as username. ICINGA2\_API\_PASSWORD | **Optional.** Required for basic auth as password. ICINGA2\_API\_CERT\_PATH | **Optional.** Client certificate path. ICINGA2\_API\_NODENAME | **Optional.** If client certificates do not match the host name, override it. +ICINGAWEB2\_URL | **Optional.** Set the Icinga Web 2 Url. Defaults to `http://localhost/icingaweb2`. > **Note** > diff --git a/config.ru b/config.ru index 19b7561..1074b5f 100644 --- a/config.ru +++ b/config.ru @@ -1,4 +1,5 @@ require 'dashing' +require './lib/icinga2' configure do set :auth_token, 'YOUR_AUTH_TOKEN' @@ -14,6 +15,19 @@ configure do # Put any authentication code you want in here. # This method is run before accessing any resource. end + + # Specify Icinga Web 2 URL + # https://github.com/Shopify/dashing/issues/509 + def getIcingaWeb2Url() + # read configuration and try to fetch the correct path + icinga = Icinga2.new('config/icinga2.json') # fixed path + + if icinga.icingaweb2_url != nil + return icinga.icingaweb2_url + else + return 'http://192.168.33.5/icingaweb2' + end + end end end diff --git a/config/icinga2.json b/config/icinga2.json index 2d3a02b..e2174aa 100644 --- a/config/icinga2.json +++ b/config/icinga2.json @@ -6,5 +6,8 @@ "user": "dashing", "password": "icinga2ondashingr0xx" } + }, + "icingaweb2": { + "url": "http://localhost/icingaweb2" } } diff --git a/dashboards/icinga2.erb b/dashboards/icinga2.erb index bcaac3e..f5e42bb 100644 --- a/dashboards/icinga2.erb +++ b/dashboards/icinga2.erb @@ -44,12 +44,12 @@ $(function() {
- +
  • -
    +
  • -
    +
  • diff --git a/lib/icinga2.rb b/lib/icinga2.rb index 387973e..fe8a1a3 100644 --- a/lib/icinga2.rb +++ b/lib/icinga2.rb @@ -30,6 +30,7 @@ class Icinga2 attr_reader :node_name attr_reader :app_starttime attr_reader :uptime + attr_reader :icingaweb2_url # general stats attr_reader :avg_latency @@ -109,6 +110,9 @@ def getConfEnv() @pkiPath = ENV['ICINGA2_API_CERT_PATH'] @nodeName = ENV['ICINGA2_API_NODENAME'] + # external attribute + @icingaweb2_url = ENV['ICINGAWEB2_URL'] + # check for the least required variables, the rest is read later on if [@host, @port].all? {|value| value.nil? or value == ""} raise ArgumentError.new('Required environment variables not found!') @@ -139,12 +143,25 @@ def getConfFile(configFile) if (File.exist?(realConfigFile)) file = File.read(realConfigFile) @config = JSON.parse(file) - @host = @config["icinga2"]["api"]["host"] - @port = @config["icinga2"]["api"]["port"] - @user = @config["icinga2"]["api"]["user"] - @password = @config["icinga2"]["api"]["password"] - @pkiPath = @config["icinga2"]["api"]["pki_path"] - @nodeName = @config['icinga2']['api']['node_name'] + + if @config.key? 'icinga2' + config_icinga2 = @config['icinga2'] + + if config_icinga2.key? 'api' + @host = @config["icinga2"]["api"]["host"] + @port = @config["icinga2"]["api"]["port"] + @user = @config["icinga2"]["api"]["user"] + @password = @config["icinga2"]["api"]["password"] + @pkiPath = @config["icinga2"]["api"]["pki_path"] + @nodeName = @config['icinga2']['api']['node_name'] + end + end + + puts "Reading config" + @config.to_s + if @config.key? 'icingaweb2' + # external attribute + @icingaweb2_url = @config['icingaweb2']['url'] + end else @log.warn(sprintf('Config file %s not found! Using default config.', configFile)) @host = "localhost" @@ -153,6 +170,9 @@ def getConfFile(configFile) @password = "icinga2ondashingr0xx" @pkiPath = "pki/" @nodeName = nil + + # external attribute + @icingaweb2_url = 'http://localhost/icingaweb2' end rescue JSON::ParserError => e