Skip to content

Commit

Permalink
Merge pull request #1111 from bosun-monitor/improve-silence-page
Browse files Browse the repository at this point in the history
Improve silence page
  • Loading branch information
maddyblue committed Jul 6, 2015
2 parents 45fa1a0 + 6bcc566 commit f9e7923
Show file tree
Hide file tree
Showing 9 changed files with 558 additions and 427 deletions.
2 changes: 1 addition & 1 deletion cmd/bosun/sched/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestCheckSilence(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = s.AddSilence(time.Now().Add(-time.Hour), time.Now().Add(time.Hour), "a", "", false, true, "")
_, err = s.AddSilence(time.Now().Add(-time.Hour), time.Now().Add(time.Hour), "a", "", false, true, "", "user", "message")
if err != nil {
t.Fatal(err)
}
Expand Down
30 changes: 19 additions & 11 deletions cmd/bosun/sched/silence.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type Silence struct {
Alert string
Tags opentsdb.TagSet
Forget bool
User string
Message string
}

func (s *Silence) MarshalJSON() ([]byte, error) {
Expand All @@ -23,12 +25,16 @@ func (s *Silence) MarshalJSON() ([]byte, error) {
Alert string
Tags string
Forget bool
User string
Message string
}{
Start: s.Start,
End: s.End,
Alert: s.Alert,
Tags: s.Tags.Tags(),
Forget: s.Forget,
Start: s.Start,
End: s.End,
Alert: s.Alert,
Tags: s.Tags.Tags(),
Forget: s.Forget,
User: s.User,
Message: s.Message,
})
}

Expand Down Expand Up @@ -81,7 +87,7 @@ func (s *Schedule) Silenced() map[expr.AlertKey]Silence {
return aks
}

func (s *Schedule) AddSilence(start, end time.Time, alert, tagList string, forget, confirm bool, edit string) (map[expr.AlertKey]bool, error) {
func (s *Schedule) AddSilence(start, end time.Time, alert, tagList string, forget, confirm bool, edit, user, message string) (map[expr.AlertKey]bool, error) {
if start.IsZero() || end.IsZero() {
return nil, fmt.Errorf("both start and end must be specified")
}
Expand All @@ -95,11 +101,13 @@ func (s *Schedule) AddSilence(start, end time.Time, alert, tagList string, forge
return nil, fmt.Errorf("must specify either alert or tags")
}
si := &Silence{
Start: start,
End: end,
Alert: alert,
Tags: make(opentsdb.TagSet),
Forget: forget,
Start: start,
End: end,
Alert: alert,
Tags: make(opentsdb.TagSet),
Forget: forget,
User: user,
Message: message,
}
if tagList != "" {
tags, err := opentsdb.ParseTags(tagList)
Expand Down
818 changes: 414 additions & 404 deletions cmd/bosun/web/static.go

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions cmd/bosun/web/static/js/0-bosun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ function eraseCookie(name) {
createCookie(name, "", -1);
}

function getUser() {
return readCookie('action-user');
}

function setUser(name) {
createCookie('action-user', name, 1000);
}

// from: http://stackoverflow.com/a/15267754/864236

bosunApp.filter('reverse', function() {
Expand Down
4 changes: 2 additions & 2 deletions cmd/bosun/web/static/js/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface IActionScope extends IExprScope {

bosunControllers.controller('ActionCtrl', ['$scope', '$http', '$location', '$route', function($scope: IActionScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService) {
var search = $location.search();
$scope.user = readCookie("action-user");
$scope.user = getUser();
$scope.type = search.type;
$scope.notify = true;
if (search.key) {
Expand All @@ -30,7 +30,7 @@ bosunControllers.controller('ActionCtrl', ['$scope', '$http', '$location', '$rou
Keys: $scope.keys,
Notify: $scope.notify,
};
createCookie("action-user", $scope.user, 1000);
setUser($scope.user);
$http.post('/api/action', data)
.success((data) => {
$location.url('/');
Expand Down
54 changes: 50 additions & 4 deletions cmd/bosun/web/static/js/bosun.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ function readCookie(name) {
function eraseCookie(name) {
createCookie(name, "", -1);
}
function getUser() {
return readCookie('action-user');
}
function setUser(name) {
createCookie('action-user', name, 1000);
}
// from: http://stackoverflow.com/a/15267754/864236
bosunApp.filter('reverse', function () {
return function (items) {
Expand All @@ -324,7 +330,7 @@ bosunApp.filter('reverse', function () {
});
bosunControllers.controller('ActionCtrl', ['$scope', '$http', '$location', '$route', function ($scope, $http, $location, $route) {
var search = $location.search();
$scope.user = readCookie("action-user");
$scope.user = getUser();
$scope.type = search.type;
$scope.notify = true;
if (search.key) {
Expand All @@ -346,7 +352,7 @@ bosunControllers.controller('ActionCtrl', ['$scope', '$http', '$location', '$rou
Keys: $scope.keys,
Notify: $scope.notify
};
createCookie("action-user", $scope.user, 1000);
setUser($scope.user);
$http.post('/api/action', data)
.success(function (data) {
$location.url('/');
Expand Down Expand Up @@ -2220,13 +2226,49 @@ bosunControllers.controller('SilenceCtrl', ['$scope', '$http', '$location', '$ro
$scope.tags = search.tags;
$scope.edit = search.edit;
$scope.forget = search.forget;
$scope.user = getUser();
$scope.message = search.message;
if (!$scope.end && !$scope.duration) {
$scope.duration = '1h';
}
function filter(data, startBefore, startAfter, endAfter, endBefore) {
var ret = [];
_.each(data, function (v) {
var s = moment(v.Start).utc();
var e = moment(v.End).utc();
if (startBefore && s > startBefore) {
return;
}
if (startAfter && s < startAfter) {
return;
}
if (endAfter && e < endAfter) {
return;
}
if (endBefore && e > endBefore) {
return;
}
ret.push(v);
});
return ret;
}
function get() {
$http.get('/api/silence/get')
.success(function (data) {
$scope.silences = data;
$scope.silences = [];
var now = moment.utc();
$scope.silences.push({
name: 'Active',
silences: filter(data, now, null, now, null)
});
$scope.silences.push({
name: 'Upcoming',
silences: filter(data, null, now, null, null)
});
$scope.silences.push({
name: 'Past',
silences: filter(data, null, null, null, now).slice(0, 25)
});
})
.error(function (error) {
$scope.error = error;
Expand All @@ -2246,7 +2288,9 @@ bosunControllers.controller('SilenceCtrl', ['$scope', '$http', '$location', '$ro
alert: $scope.alert,
tags: tags.join(','),
edit: $scope.edit,
forget: $scope.forget ? 'true' : null
forget: $scope.forget ? 'true' : null,
user: $scope.user,
message: $scope.message
};
return data;
}
Expand All @@ -2269,13 +2313,15 @@ bosunControllers.controller('SilenceCtrl', ['$scope', '$http', '$location', '$ro
});
}
$scope.test = function () {
setUser($scope.user);
$location.search('start', $scope.start || null);
$location.search('end', $scope.end || null);
$location.search('duration', $scope.duration || null);
$location.search('alert', $scope.alert || null);
$location.search('hosts', $scope.hosts || null);
$location.search('tags', $scope.tags || null);
$location.search('forget', $scope.forget || null);
$location.search('message', $scope.message || null);
$route.reload();
};
$scope.confirm = function () {
Expand Down
44 changes: 43 additions & 1 deletion cmd/bosun/web/static/js/silence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ interface ISilenceScope extends ng.IScope {
disableConfirm: boolean;
time: (v: any) => string;
forget: string;
user: string;
message: string;
}

bosunControllers.controller('SilenceCtrl', ['$scope', '$http', '$location', '$route', function($scope: ISilenceScope, $http: ng.IHttpService, $location: ng.ILocationService, $route: ng.route.IRouteService) {
Expand All @@ -28,13 +30,49 @@ bosunControllers.controller('SilenceCtrl', ['$scope', '$http', '$location', '$ro
$scope.tags = search.tags;
$scope.edit = search.edit;
$scope.forget = search.forget;
$scope.user = getUser();
$scope.message = search.message;
if (!$scope.end && !$scope.duration) {
$scope.duration = '1h';
}
function filter(data: any[], startBefore: any, startAfter: any, endAfter: any, endBefore: any) {
var ret = [];
_.each(data, function(v) {
var s = moment(v.Start).utc();
var e = moment(v.End).utc();
if (startBefore && s > startBefore) {
return;
}
if (startAfter && s< startAfter) {
return;
}
if (endAfter && e < endAfter) {
return;
}
if (endBefore && e > endBefore) {
return;
}
ret.push(v);
});
return ret;
}
function get() {
$http.get('/api/silence/get')
.success((data) => {
$scope.silences = data;
$scope.silences = [];
var now = moment.utc();
$scope.silences.push({
name: 'Active',
silences: filter(data, now, null, now, null)
});
$scope.silences.push({
name: 'Upcoming',
silences: filter(data, null, now, null, null)
});
$scope.silences.push({
name: 'Past',
silences: filter(data, null, null, null, now).slice(0, 25)
});
})
.error((error) => {
$scope.error = error;
Expand All @@ -55,6 +93,8 @@ bosunControllers.controller('SilenceCtrl', ['$scope', '$http', '$location', '$ro
tags: tags.join(','),
edit: $scope.edit,
forget: $scope.forget ? 'true' : null,
user: $scope.user,
message: $scope.message,
};
return data;
}
Expand All @@ -77,13 +117,15 @@ bosunControllers.controller('SilenceCtrl', ['$scope', '$http', '$location', '$ro
});
}
$scope.test = () => {
setUser($scope.user);
$location.search('start', $scope.start || null);
$location.search('end', $scope.end || null);
$location.search('duration', $scope.duration || null);
$location.search('alert', $scope.alert || null);
$location.search('hosts', $scope.hosts || null);
$location.search('tags', $scope.tags || null);
$location.search('forget', $scope.forget || null);
$location.search('message', $scope.message || null);
$route.reload();
};
$scope.confirm = () => {
Expand Down
23 changes: 20 additions & 3 deletions cmd/bosun/web/static/partials/silence.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
<p class="help-block">Optional. Ex: port=637?,cluster=1,iface=lo*|if*. tagvs are <a href="http://golang.org/pkg/path/filepath/#Match">globs</a>, separated by pipes (|). Example: <code>port=637?</code>.</p>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">username</label>
<div class="col-sm-6">
<input type="text" class="form-control" ng-model="user">
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">message</label>
<div class="col-sm-10">
<input type="text" class="form-control" ng-model="message">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<div class="checkbox">
Expand Down Expand Up @@ -78,24 +90,29 @@ <h2>Will be silenced:</h2>
<span ng-show="edit" class="label label-warning">editing rule {{edit}}</span>
</div>
</div>
<div class="row">
<div class="row" ng-repeat="silence in silences">
<div class="col-sm-12">
<table class="table" ts-table-sort="[[1,0]]">
<h3 ng-bind="silence.name"></h3>
<table class="table" ts-table-sort="[[1,1]]">
<thead>
<tr>
<th>start</th>
<th>end</th>
<th>alert</th>
<th>tags</th>
<th>user</th>
<th>message</th>
<th>edit</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="(id, s) in silences">
<tr ng-repeat="(id, s) in silence.silences">
<td ts-time="s.Start"></td>
<td ts-time="s.End"></td>
<td ng-bind="s.Alert"></td>
<td ng-bind="s.Tags"></td>
<td ng-bind="s.User"></td>
<td ng-bind="s.Message"></td>
<td>
<a class="btn btn-primary btn-xs" ng-href="/silence?start={{time(s.Start)}}&end={{time(s.End)}}&alert={{s.Alert}}&tags={{encode(s.Tags)}}{{s.Forget ? '&forget': ''}}&edit={{id}}">edit</a>
<button class="btn btn-danger btn-xs" ng-click="clear(id)">clear</button>
Expand Down
2 changes: 1 addition & 1 deletion cmd/bosun/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ func SilenceSet(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (i
}
end = start.Add(time.Duration(d))
}
return schedule.AddSilence(start, end, data["alert"], data["tags"], data["forget"] == "true", len(data["confirm"]) > 0, data["edit"])
return schedule.AddSilence(start, end, data["alert"], data["tags"], data["forget"] == "true", len(data["confirm"]) > 0, data["edit"], data["user"], data["message"])
}

func SilenceClear(t miniprofiler.Timer, w http.ResponseWriter, r *http.Request) (interface{}, error) {
Expand Down

0 comments on commit f9e7923

Please sign in to comment.