Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timezone config/ENV support for the clock widget #94

Merged
merged 2 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ENV ICINGA2_API_CERT_PATH pki/
ENV ICINGA2_API_NODENAME localhost
ENV ICINGAWEB2_URL http://localhost/icingaweb2
ENV DASHBOARD_SHOW_ONLY_HARD_STATE_PROBLEMS 0
ENV DASHBOARD_TIMEZONE UTC


EXPOSE 8005
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,15 @@ vim config/icinga2.local.json
"url": "http://localhost/icingaweb2"
},
"dashboard": {
"show_only_hard_state_problems": false
"show_only_hard_state_problems": false,
"timezone": "UTC"
}
}
```

The `show_only_hard_state_problems` option ignores NOT-OK states until they
reach a hard NOT-OK state (off by default).
reach a hard NOT-OK state (off by default). The `timezone` option controls the clock widget's
timezone.

If you prefer to use client certificates, set the `pki_path` attribute. The Icinga 2
job expects the certificate file names based on the local FQDN e.g. `pki/icinga2-master1.localdomain.crt`.
Expand All @@ -272,7 +274,8 @@ explicitly.
"url": "http://localhost/icingaweb2"
},
"dashboard": {
"show_only_hard_state_problems": false
"show_only_hard_state_problems": false,
"timezone": "UTC"
}
}
```
Expand All @@ -296,6 +299,7 @@ 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`.
DASHBOARD_SHOW_ONLY_HARD_STATE_PROBLEMS | **Optional.** Set `show_only_hard_state_problems` configuration option, toggle with `0|1`.
DASHBOARD_TIMEZONE | **Optional.** Set the `timezone` option for the dashboard, overriding the default `UTC` value.

> **Note**
>
Expand Down
10 changes: 10 additions & 0 deletions config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ configure do
return 'http://192.168.33.5/icingaweb2'
end
end

def getTimeZone()
# read configuration and try to fetch the correct path
icinga = Icinga2.new('config/icinga2.json') # fixed path
if icinga.time_zone != nil
return icinga.time_zone
else
return "UTC"
end
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion config/icinga2.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"url": "http://localhost/icingaweb2"
},
"dashboard": {
"show_only_hard_state_problems": false
"show_only_hard_state_problems": false,
"timezone": "UTC"
}
}
2 changes: 1 addition & 1 deletion dashboards/icinga2.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ $(function() {
<ul>
<!-- Statistics -->
<li data-row="1" data-col="1" data-sizex="1" data-sizey="1">
<div data-view="Clock" data-title="UTC" data-timezone="UTC"></div>
<div data-view="Clock" data-title="<%=getTimeZone()%>" data-timezone="<%=getTimeZone()%>"></div>
</li>

<li data-row="1" data-col="2" data-sizex="1" data-sizey="1">
Expand Down
8 changes: 8 additions & 0 deletions lib/icinga2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Icinga2
attr_reader :app_starttime
attr_reader :uptime
attr_reader :icingaweb2_url
attr_reader :time_zone

# general stats
attr_reader :avg_latency
Expand Down Expand Up @@ -112,7 +113,9 @@ def getConfEnv()
# external attribute
@icingaweb2_url = ENV['ICINGAWEB2_URL']

# dashboards
@showOnlyHardStateProblems = ENV['DASHBOARD_SHOW_ONLY_HARD_STATE_PROBLEMS']
@time_zone = ENV['DASHBOARD_TIMEZONE']

# check for the least required variables, the rest is read later on
if [@host, @port].all? {|value| value.nil? or value == ""}
Expand Down Expand Up @@ -166,6 +169,10 @@ def getConfFile(configFile)
if config_dashboard.key? 'show_only_hard_state_problems' # retire this check later
@showOnlyHardStateProblems = config_dashboard['show_only_hard_state_problems']
end

if config_dashboard.key? 'timezone'
@time_zone = config_dashboard['timezone']
end
end

if @config.key? 'icingaweb2'
Expand All @@ -181,6 +188,7 @@ def getConfFile(configFile)
@pkiPath = "pki/"
@nodeName = nil
@showOnlyHardStateProblems = false
@time_zone = "UTC"

# external attribute
@icingaweb2_url = 'http://localhost/icingaweb2'
Expand Down