Skip to content

Commit

Permalink
cmd/bosun: add user and message fields to silences
Browse files Browse the repository at this point in the history
fixes #1092
  • Loading branch information
maddyblue committed Jul 1, 2015
1 parent 16b8f49 commit 1d765ef
Show file tree
Hide file tree
Showing 8 changed files with 292 additions and 237 deletions.
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
443 changes: 223 additions & 220 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 @@ -343,6 +343,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 (!angular.isArray(search.key)) {
Expand All @@ -25,7 +25,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
18 changes: 15 additions & 3 deletions cmd/bosun/web/static/js/bosun.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,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 @@ -312,7 +318,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 (!angular.isArray(search.key)) {
Expand All @@ -329,7 +335,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 @@ -2203,6 +2209,8 @@ 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';
}
Expand Down Expand Up @@ -2263,7 +2271,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 @@ -2286,13 +2296,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
8 changes: 8 additions & 0 deletions 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,6 +30,8 @@ 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';
}
Expand Down Expand Up @@ -89,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 @@ -111,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
16 changes: 16 additions & 0 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 @@ -88,6 +100,8 @@ <h3 ng-bind="silence.name"></h3>
<th>end</th>
<th>alert</th>
<th>tags</th>
<th>user</th>
<th>message</th>
<th>edit</th>
</tr>
</thead>
Expand All @@ -97,6 +111,8 @@ <h3 ng-bind="silence.name"></h3>
<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 @@ -518,7 +518,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 1d765ef

Please sign in to comment.