Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #657 from palourde/refactoring-silenced
Browse files Browse the repository at this point in the history
Silenced refactoring
  • Loading branch information
palourde authored Mar 21, 2017
2 parents b32fbc5 + a10d556 commit 5d7927d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
7 changes: 7 additions & 0 deletions fixtures/users/config_users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"uchiwa": {
"usersOptions": {
"silenceDurations": [2]
}
}
}
4 changes: 2 additions & 2 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<link href="bower_components/fontawesome/css/font-awesome.min.css?rel=1489178318313" rel="stylesheet">
<link href="bower_components/angular-toastr/dist/angular-toastr.min.css?rel=1489178318313" rel="stylesheet">
<link href="bower_components/highlightjs/styles/tomorrow.css?rel=1489178318313" rel="stylesheet">
<link href="bower_components/angular-mass-autocomplete-uchiwa/massautocomplete.theme.css?rel=1489178318313" rel="stylesheet">
<link href="bower_components/moment-picker/dist/angular-moment-picker.min.css?rel=1489178318312" rel="stylesheet">

<!-- Uchiwa CSS -->
<link href="bower_components/uchiwa-web/css/uchiwa-default/uchiwa-default.css?rel=1489178318313" rel="stylesheet" site-theme>
Expand Down Expand Up @@ -47,9 +47,9 @@ <h3 class="font-bold">We couldn't load Uchiwa configuration.</h3>
<script src="bower_components/angular-toastr/dist/angular-toastr.tpls.min.js?rel=1489178318312"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js?rel=1489178318312"></script>
<script src="bower_components/highlightjs/highlight.pack.js?rel=1489178318312"></script>
<script src="bower_components/angular-mass-autocomplete-uchiwa/massautocomplete.min.js?rel=1489178318312"></script>
<script src="bower_components/moment/min/moment.min.js?rel=1489178318312"></script>
<script src="bower_components/angular-moment/angular-moment.min.js?rel=1489178318312"></script>
<script src="bower_components/moment-picker/dist/angular-moment-picker.min.js?rel=1489178318312"></script>
<script src="bower_components/angular-gravatar/build/angular-gravatar.min.js?rel=1489178318312"></script>
<script src="bower_components/ua-parser-js/dist/ua-parser.min.js?rel=1489178318313"></script>

Expand Down
3 changes: 2 additions & 1 deletion uchiwa/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ var (
},
UsersOptions: UsersOptions{
DateFormat: "YYYY-MM-DD HH:mm:ss",
DefaultExpireOnResolve: false,
DefaultTheme: "uchiwa-default",
DisableNoExpiration: false,
RequireSilencingReason: false,
SilenceDurations: []float32{0.25, 1, 24},
},
}
defaultSensuConfig = SensuConfig{
Expand Down Expand Up @@ -250,6 +250,7 @@ func initUchiwa(global GlobalConfig) GlobalConfig {
// Set the logger level
logger.SetLogLevel(global.LogLevel)

// Initialize the users options
// Set the refresh rate for frontend
global.UsersOptions.Refresh = global.Refresh * 1000

Expand Down
8 changes: 6 additions & 2 deletions uchiwa/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ func TestLoad(t *testing.T) {
assert.Equal(t, 10, conf.Sensu[0].Timeout)
assert.Equal(t, 10, conf.Uchiwa.Refresh)
assert.Equal(t, "YYYY-MM-DD HH:mm:ss", conf.Uchiwa.UsersOptions.DateFormat)
assert.Equal(t, false, conf.Uchiwa.UsersOptions.DefaultExpireOnResolve)
assert.Equal(t, "uchiwa-default", conf.Uchiwa.UsersOptions.DefaultTheme)
assert.Equal(t, false, conf.Uchiwa.UsersOptions.DisableNoExpiration)
assert.Equal(t, "", conf.Uchiwa.UsersOptions.LogoURL)
assert.Equal(t, 10000, conf.Uchiwa.UsersOptions.Refresh)
assert.Equal(t, false, conf.Uchiwa.UsersOptions.RequireSilencingReason)
assert.Equal(t, 389, conf.Uchiwa.Ldap.Port)
assert.Equal(t, "person", conf.Uchiwa.Ldap.UserObjectClass)
Expand Down Expand Up @@ -168,3 +166,9 @@ func TestGetPublic(t *testing.T) {
assert.Equal(t, "*****", pubConf.Uchiwa.Github.ClientSecret)
assert.Equal(t, "*****", pubConf.Uchiwa.Ldap.BindPass)
}

func TestUsersOptions(t *testing.T) {
// The SilenceDurations default value should be overwritten
conf := Load("../../fixtures/config_test.json", "../../fixtures/users")
assert.Equal(t, 4, len(conf.Uchiwa.UsersOptions.SilenceDurations))
}
2 changes: 1 addition & 1 deletion uchiwa/config/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ type SSL struct {
// UsersOptions struct contains various config tweaks
type UsersOptions struct {
DateFormat string
DefaultExpireOnResolve bool
DefaultTheme string
DisableNoExpiration bool
LogoURL string
Refresh int
RequireSilencingReason bool
SilenceDurations []float32
}
2 changes: 1 addition & 1 deletion uchiwa/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ func (u *Uchiwa) silencedHandler(w http.ResponseWriter, r *http.Request) {
return
}

if u.Config.Uchiwa.UsersOptions.DisableNoExpiration && data.Expire < 1 {
if u.Config.Uchiwa.UsersOptions.DisableNoExpiration && (data.Expire < 1 && !data.ExpireOnResolve) {
http.Error(w, "Open-ended silence entries are disallowed", http.StatusNotFound)
return
}
Expand Down

0 comments on commit 5d7927d

Please sign in to comment.