diff --git a/README.markdown b/README.markdown index 025e90c..8bc4e36 100755 --- a/README.markdown +++ b/README.markdown @@ -111,6 +111,17 @@ Litle more advanced: ``` uchiwa::ssl: { 'certfile': '/opt/ssl/%{::hostname}.crt', 'keyfile': '/opt/ssl/%{::hostname}.key' } ``` +## Users Options + +Example of declaring the UsersOptions hash as defined in https://docs.uchiwa.io/getting-started/configuration/#users-options: + +Via hiera: +``` +uchiwa::usersoptions: + disableNoExpiration: true + requireSilencingReason: true + defaultExpireOnResolve: true +``` ## License diff --git a/manifests/init.pp b/manifests/init.pp index 889da8d..a16d8ea 100755 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -154,6 +154,7 @@ $users = $uchiwa::params::users, $auth = $uchiwa::params::auth, $ssl = $uchiwa::params::ssl, + $usersoptions = $uchiwa::params::usersoptions, ) inherits uchiwa::params { # validate parameters here @@ -177,6 +178,7 @@ validate_array($users) validate_hash($auth) validate_hash($ssl) + validate_hash($usersoptions) anchor { 'uchiwa::begin': } -> class { 'uchiwa::install': } -> diff --git a/manifests/params.pp b/manifests/params.pp index 2fc7ccf..89cfc9d 100755 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -49,4 +49,5 @@ $users = [] $auth = {} $ssl = {} + $usersoptions = {} } diff --git a/spec/classes/uchiwa_spec.rb b/spec/classes/uchiwa_spec.rb index 284785b..129fc26 100644 --- a/spec/classes/uchiwa_spec.rb +++ b/spec/classes/uchiwa_spec.rb @@ -178,4 +178,13 @@ } end + context 'with usersoptions' do + let(:params) {{ :usersoptions => { 'disableNoExpiration' => true, 'defaultTheme' => 'uchiwa-default' } }} + it { + should contain_file('/etc/sensu/uchiwa.json') \ + .with_content(/"disableNoExpiration": true/) \ + .with_content(/"defaultTheme": "uchiwa-default"/) + } + end + end diff --git a/templates/etc/sensu/uchiwa.json.erb b/templates/etc/sensu/uchiwa.json.erb index 1d6c6f5..f09d79b 100644 --- a/templates/etc/sensu/uchiwa.json.erb +++ b/templates/etc/sensu/uchiwa.json.erb @@ -21,7 +21,7 @@ "timeout": <%= endpoint['timeout'] || default_endpoint['timeout'] %> }<%= ',' if j < (endpoint['host'].size - 1) -%> <%- end -%> - <%= ',' if i < (@sensu_api_endpoints.size - 1) %> +<%= ',' if i < (@sensu_api_endpoints.size - 1) %> <%- end -%> ], "uchiwa": { @@ -29,7 +29,7 @@ "port": <%= @port %>, "user": "<%= @user %>", "pass": "<%= @pass %>", - "refresh": <%= @refresh %><%= ',' if @users.size > 0 or @auth.size == 2 or @ssl.size == 2%> + "refresh": <%= @refresh %><%= ',' if @users.size > 0 or @auth.size == 2 or @ssl.size == 2 or @usersoptions.size > 0 %> <%- if @users.size > 0 -%> "users": [ <%- @users.each_with_index do |user, i| -%> @@ -41,19 +41,30 @@ } }<%= ',' if i < (@users.size - 1) %> <%- end -%> - ]<%= ',' if @users.size %> + ]<%= ',' if @auth.size == 2 or @ssl.size == 2 or @usersoptions.size > 0 %> <%- end -%> <%- if @auth.size == 2 -%> "auth": { "publickey": "<%= @auth['publickey'] %>", "privatekey": "<%= @auth['privatekey'] %>" - }<%= ',' if @ssl.size == 2 %> + }<%= ',' if @ssl.size == 2 || @usersoptions.size > 0 %> <%- end -%> <%- if @ssl.size == 2 -%> "ssl": { "certfile": "<%= @ssl['certfile'] %>", "keyfile": "<%= @ssl['keyfile'] %>" - } + }<%= ',' if @usersoptions.size > 0 %> + <%- end -%> + <%- if @usersoptions.size > 0 -%> + "usersOptions": { + <%- @usersoptions.each_with_index do |(k,v), idx| -%> + <%- if [true, false].include? v -%> + "<%= k %>": <%= v %><%= ',' if idx != (@usersoptions.size - 1) %> + <%- else -%> + "<%= k %>": "<%= v %>"<%= ',' if idx != (@usersoptions.size - 1) %> + <%- end -%> + <%- end -%> + } <%- end -%> } }