2015-10-12 15:08:07 +00:00
|
|
|
'use strict';
|
|
|
|
|
2015-10-21 14:34:38 +00:00
|
|
|
angular.module('am.directives', []);
|
|
|
|
|
|
|
|
angular.module('am.directives').directive('route',
|
|
|
|
function(RecursionHelper) {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
|
|
|
route: '='
|
|
|
|
},
|
|
|
|
templateUrl: '/app/partials/route.html',
|
|
|
|
compile: function(element) {
|
|
|
|
// Use the compile function from the RecursionHelper,
|
|
|
|
// And return the linking function(s) which it returns
|
|
|
|
return RecursionHelper.compile(element);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
angular.module('am.directives').directive('alert',
|
|
|
|
function() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
2015-11-09 10:09:32 +00:00
|
|
|
alert: '=',
|
2015-11-09 11:03:36 +00:00
|
|
|
group: '='
|
2015-10-21 14:34:38 +00:00
|
|
|
},
|
|
|
|
templateUrl: '/app/partials/alert.html'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-11-06 14:27:28 +00:00
|
|
|
angular.module('am.directives').directive('silence',
|
|
|
|
function() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
|
|
|
sil: '='
|
|
|
|
},
|
|
|
|
templateUrl: '/app/partials/silence.html'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-27 18:54:21 +00:00
|
|
|
angular.module('am.directives').directive('silenceForm',
|
|
|
|
function() {
|
|
|
|
return {
|
|
|
|
restrict: 'E',
|
|
|
|
scope: {
|
|
|
|
silence: '='
|
|
|
|
},
|
|
|
|
templateUrl: '/app/partials/silence-form.html'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-12 15:08:07 +00:00
|
|
|
angular.module('am.services', ['ngResource']);
|
|
|
|
|
|
|
|
angular.module('am.services').factory('Silence',
|
2015-10-21 14:34:38 +00:00
|
|
|
function($resource) {
|
|
|
|
return $resource('', {
|
|
|
|
id: '@id'
|
|
|
|
}, {
|
|
|
|
'query': {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/silences'
|
|
|
|
},
|
|
|
|
'create': {
|
|
|
|
method: 'POST',
|
|
|
|
url: '/api/v1/silences'
|
|
|
|
},
|
|
|
|
'get': {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/silence/:id'
|
|
|
|
},
|
|
|
|
'delete': {
|
|
|
|
method: 'DELETE',
|
|
|
|
url: '/api/v1/silence/:id'
|
|
|
|
}
|
2015-10-12 15:08:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-15 14:24:27 +00:00
|
|
|
angular.module('am.services').factory('Alert',
|
2015-10-21 14:34:38 +00:00
|
|
|
function($resource) {
|
2015-10-15 14:24:27 +00:00
|
|
|
return $resource('', {}, {
|
2015-10-21 14:34:38 +00:00
|
|
|
'query': {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/alerts'
|
|
|
|
}
|
2015-10-15 14:24:27 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-11-07 13:29:54 +00:00
|
|
|
angular.module('am.services').factory('AlertGroups',
|
2015-10-21 14:34:38 +00:00
|
|
|
function($resource) {
|
|
|
|
return $resource('', {}, {
|
|
|
|
'query': {
|
|
|
|
method: 'GET',
|
2015-11-07 13:29:54 +00:00
|
|
|
url: '/api/v1/alerts/groups'
|
2015-10-21 14:34:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
angular.module('am.services').factory('Alert',
|
|
|
|
function($resource) {
|
|
|
|
return $resource('', {}, {
|
|
|
|
'query': {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/alerts'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
2015-10-12 15:08:07 +00:00
|
|
|
angular.module('am.controllers', []);
|
|
|
|
|
2015-10-15 10:01:19 +00:00
|
|
|
angular.module('am.controllers').controller('NavCtrl',
|
|
|
|
function($scope, $location) {
|
2015-10-21 14:34:38 +00:00
|
|
|
$scope.items = [{
|
|
|
|
name: 'Silences',
|
|
|
|
url: '/silences'
|
|
|
|
}, {
|
|
|
|
name: 'Alerts',
|
|
|
|
url: '/alerts'
|
|
|
|
}, {
|
|
|
|
name: 'Status',
|
|
|
|
url: '/status'
|
|
|
|
}];
|
2015-10-15 10:01:19 +00:00
|
|
|
|
|
|
|
$scope.selected = function(item) {
|
|
|
|
return item.url == $location.path()
|
2015-10-21 14:34:38 +00:00
|
|
|
}
|
2015-10-15 10:01:19 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-22 08:46:52 +00:00
|
|
|
angular.module('am.controllers').controller('AlertCtrl',
|
2015-10-27 18:54:21 +00:00
|
|
|
function($scope) {
|
2015-11-06 17:17:41 +00:00
|
|
|
$scope.showDetails = false;
|
|
|
|
|
|
|
|
$scope.toggleDetails = function() {
|
|
|
|
$scope.showDetails = !$scope.showDetails
|
|
|
|
}
|
|
|
|
|
2015-10-27 18:54:21 +00:00
|
|
|
$scope.showSilenceForm = false;
|
|
|
|
|
|
|
|
$scope.toggleSilenceForm = function() {
|
|
|
|
$scope.showSilenceForm = !$scope.showSilenceForm
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.silence = {
|
|
|
|
matchers: []
|
|
|
|
}
|
2015-11-09 10:09:32 +00:00
|
|
|
angular.forEach($scope.alert.labels, function(value, key) {
|
2015-10-27 18:54:21 +00:00
|
|
|
this.push({
|
|
|
|
name: key,
|
|
|
|
value: value,
|
2015-11-09 10:09:32 +00:00
|
|
|
isRegex: false
|
2015-10-27 18:54:21 +00:00
|
|
|
});
|
|
|
|
}, $scope.silence.matchers);
|
|
|
|
|
2015-11-06 16:35:37 +00:00
|
|
|
$scope.$on('silence-created', function(evt) {
|
|
|
|
$scope.toggleSilenceForm();
|
|
|
|
});
|
2015-10-27 18:54:21 +00:00
|
|
|
}
|
2015-10-22 08:46:52 +00:00
|
|
|
);
|
|
|
|
|
2015-10-15 14:24:27 +00:00
|
|
|
angular.module('am.controllers').controller('AlertsCtrl',
|
2015-11-07 13:29:54 +00:00
|
|
|
function($scope, AlertGroups) {
|
|
|
|
$scope.groups = null;
|
2015-11-10 12:47:04 +00:00
|
|
|
$scope.allReceivers = [];
|
2015-10-15 14:24:27 +00:00
|
|
|
|
2015-11-09 15:42:52 +00:00
|
|
|
$scope.notEmpty = function(group) {
|
|
|
|
var l = 0;
|
|
|
|
angular.forEach(group.groups, function(g) {
|
2015-11-10 12:47:04 +00:00
|
|
|
if ($scope.receiver.indexOf(g.routeOpts.receiver) >= 0) {
|
2015-11-09 15:42:52 +00:00
|
|
|
l += g.alerts.length;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return l > 0;
|
|
|
|
};
|
|
|
|
|
2015-10-15 14:24:27 +00:00
|
|
|
$scope.refresh = function() {
|
2015-11-07 13:29:54 +00:00
|
|
|
AlertGroups.query({},
|
2015-10-15 14:24:27 +00:00
|
|
|
function(data) {
|
2015-11-07 13:29:54 +00:00
|
|
|
$scope.groups = data.data;
|
2015-11-09 10:09:32 +00:00
|
|
|
|
2015-11-10 12:47:04 +00:00
|
|
|
$scope.allReceivers = [];
|
2015-11-09 10:09:32 +00:00
|
|
|
angular.forEach($scope.groups, function(group) {
|
|
|
|
angular.forEach(group.groups, function(g) {
|
2015-11-10 12:47:04 +00:00
|
|
|
if ($scope.allReceivers.indexOf(g.routeOpts.receiver) < 0) {
|
|
|
|
$scope.allReceivers.push(g.routeOpts.receiver);
|
2015-11-09 10:09:32 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
|
2015-11-10 12:47:04 +00:00
|
|
|
if (!$scope.receivers) {
|
|
|
|
$scope.receivers = angular.copy($scope.allReceivers);
|
2015-11-09 10:09:32 +00:00
|
|
|
}
|
2015-10-15 14:24:27 +00:00
|
|
|
},
|
|
|
|
function(data) {
|
2015-11-06 13:14:46 +00:00
|
|
|
$scope.error = data.data;
|
2015-10-15 14:24:27 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.refresh();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-11-06 16:07:55 +00:00
|
|
|
angular.module('am.controllers').controller('SilenceCtrl',
|
2015-11-09 14:30:02 +00:00
|
|
|
function($scope, $location, Silence) {
|
2015-11-06 16:07:55 +00:00
|
|
|
|
2015-11-09 14:30:02 +00:00
|
|
|
$scope.highlight = $location.search()['hl'] == $scope.sil.id;
|
2015-11-06 17:17:41 +00:00
|
|
|
$scope.showDetails = false;
|
|
|
|
|
|
|
|
$scope.toggleDetails = function() {
|
|
|
|
$scope.showDetails = !$scope.showDetails
|
|
|
|
}
|
|
|
|
|
2015-11-06 16:07:55 +00:00
|
|
|
$scope.delete = function(sil) {
|
|
|
|
Silence.delete({id: sil.id},
|
|
|
|
function(data) {
|
2015-11-06 16:35:37 +00:00
|
|
|
$scope.$emit('silence-deleted');
|
2015-11-06 16:07:55 +00:00
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
$scope.error = data.data;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-12 15:08:07 +00:00
|
|
|
angular.module('am.controllers').controller('SilencesCtrl',
|
|
|
|
function($scope, Silence) {
|
|
|
|
$scope.silences = [];
|
2015-11-06 16:07:55 +00:00
|
|
|
$scope.order = "endsAt";
|
2015-10-12 20:22:21 +00:00
|
|
|
|
2015-11-09 14:19:22 +00:00
|
|
|
$scope.showForm = false;
|
|
|
|
|
|
|
|
$scope.toggleForm = function() {
|
|
|
|
$scope.showForm = !$scope.showForm
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-12 20:22:21 +00:00
|
|
|
$scope.refresh = function() {
|
|
|
|
Silence.query({},
|
2015-11-06 16:07:55 +00:00
|
|
|
function(data) {
|
2015-10-12 20:22:21 +00:00
|
|
|
$scope.silences = data.data || [];
|
2015-11-06 16:07:55 +00:00
|
|
|
|
|
|
|
angular.forEach($scope.silences, function(value) {
|
|
|
|
value.endsAt = new Date(value.endsAt);
|
|
|
|
value.startsAt = new Date(value.startsAt);
|
|
|
|
value.createdAt = new Date(value.createdAt);
|
|
|
|
});
|
2015-10-13 14:59:37 +00:00
|
|
|
},
|
|
|
|
function(data) {
|
2015-11-02 17:51:54 +00:00
|
|
|
$scope.error = data.data;
|
2015-10-12 20:22:21 +00:00
|
|
|
}
|
|
|
|
);
|
2015-11-02 17:51:54 +00:00
|
|
|
};
|
2015-10-12 20:22:21 +00:00
|
|
|
|
2015-11-06 13:14:46 +00:00
|
|
|
$scope.$on('silence-created', function(evt) {
|
|
|
|
$scope.refresh();
|
|
|
|
});
|
2015-11-06 16:07:55 +00:00
|
|
|
$scope.$on('silence-deleted', function(evt) {
|
|
|
|
$scope.refresh();
|
|
|
|
});
|
2015-11-06 13:14:46 +00:00
|
|
|
|
2015-11-10 10:19:04 +00:00
|
|
|
$scope.elapsed = function(elapsed) {
|
|
|
|
return function(sil) {
|
|
|
|
if (elapsed) {
|
|
|
|
return sil.endsAt <= new Date;
|
|
|
|
}
|
|
|
|
return sil.endsAt > new Date;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-10-12 20:22:21 +00:00
|
|
|
$scope.refresh();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
angular.module('am.controllers').controller('SilenceCreateCtrl',
|
2015-11-06 16:35:37 +00:00
|
|
|
function($scope, Silence) {
|
2015-10-12 15:08:07 +00:00
|
|
|
|
2015-10-13 14:59:37 +00:00
|
|
|
$scope.error = null;
|
2015-11-06 14:27:28 +00:00
|
|
|
$scope.silence = $scope.silence || {};
|
2015-10-13 14:59:37 +00:00
|
|
|
|
2015-11-06 14:27:28 +00:00
|
|
|
if (!$scope.silence.matchers) {
|
|
|
|
$scope.silence.matchers = [{}, {}];
|
|
|
|
}
|
2015-11-06 13:14:46 +00:00
|
|
|
|
2015-11-06 14:27:28 +00:00
|
|
|
var origSilence = angular.copy($scope.silence);
|
2015-11-06 13:14:46 +00:00
|
|
|
|
2015-10-15 14:24:27 +00:00
|
|
|
$scope.reset = function() {
|
2015-10-27 18:54:21 +00:00
|
|
|
var now = new Date();
|
|
|
|
var end = new Date();
|
|
|
|
|
2015-10-15 14:24:27 +00:00
|
|
|
now.setMilliseconds(0);
|
|
|
|
end.setMilliseconds(0);
|
|
|
|
now.setSeconds(0);
|
|
|
|
end.setSeconds(0);
|
|
|
|
|
2015-11-06 13:14:46 +00:00
|
|
|
end.setHours(end.getHours() + 4)
|
2015-10-27 18:54:21 +00:00
|
|
|
|
2015-11-06 14:27:28 +00:00
|
|
|
$scope.silence = angular.copy(origSilence);
|
|
|
|
|
|
|
|
$scope.silence.startsAt = now;
|
|
|
|
$scope.silence.endsAt = end;
|
2015-11-02 17:51:54 +00:00
|
|
|
};
|
2015-10-13 14:59:37 +00:00
|
|
|
|
2015-10-15 14:24:27 +00:00
|
|
|
$scope.reset();
|
2015-11-06 14:27:28 +00:00
|
|
|
|
|
|
|
$scope.addMatcher = function() {
|
|
|
|
$scope.silence.matchers.push({});
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.delMatcher = function(i) {
|
|
|
|
$scope.silence.matchers.splice(i, 1);
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.create = function() {
|
|
|
|
Silence.create($scope.silence,
|
|
|
|
function(data) {
|
2015-11-06 16:35:37 +00:00
|
|
|
$scope.$emit('silence-created');
|
2015-11-06 14:27:28 +00:00
|
|
|
$scope.reset();
|
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
$scope.error = data.data;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
2015-10-12 15:08:07 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-11-02 18:41:23 +00:00
|
|
|
angular.module('am.services').factory('Status',
|
|
|
|
function($resource) {
|
|
|
|
return $resource('', {}, {
|
|
|
|
'get': {
|
|
|
|
method: 'GET',
|
|
|
|
url: '/api/v1/status'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
angular.module('am.controllers').controller('StatusCtrl',
|
|
|
|
function($scope, Status) {
|
2015-11-02 18:47:12 +00:00
|
|
|
Status.get({},
|
|
|
|
function(data) {
|
|
|
|
$scope.config = data.data.config;
|
|
|
|
$scope.versionInfo = data.data.versionInfo;
|
2015-11-02 19:04:37 +00:00
|
|
|
$scope.uptime = data.data.uptime;
|
2015-11-02 18:47:12 +00:00
|
|
|
},
|
|
|
|
function(data) {
|
|
|
|
console.log(data.data);
|
|
|
|
})
|
2015-11-02 18:41:23 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2015-10-12 15:08:07 +00:00
|
|
|
angular.module('am', [
|
|
|
|
'ngRoute',
|
2015-11-09 12:32:41 +00:00
|
|
|
'ngSanitize',
|
2015-11-06 16:07:55 +00:00
|
|
|
'angularMoment',
|
2015-10-12 15:08:07 +00:00
|
|
|
|
|
|
|
'am.controllers',
|
2015-10-21 14:34:38 +00:00
|
|
|
'am.services',
|
|
|
|
'am.directives'
|
2015-10-12 15:08:07 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
angular.module('am').config(
|
|
|
|
function($routeProvider) {
|
|
|
|
$routeProvider.
|
2015-10-21 14:34:38 +00:00
|
|
|
when('/alerts', {
|
|
|
|
templateUrl: '/app/partials/alerts.html',
|
|
|
|
controller: 'AlertsCtrl'
|
|
|
|
}).
|
|
|
|
when('/silences', {
|
|
|
|
templateUrl: '/app/partials/silences.html',
|
|
|
|
controller: 'SilencesCtrl'
|
|
|
|
}).
|
2015-11-02 18:47:12 +00:00
|
|
|
when('/status', {
|
|
|
|
templateUrl: '/app/partials/status.html',
|
|
|
|
controller: 'StatusCtrl'
|
|
|
|
}).
|
2015-10-21 14:34:38 +00:00
|
|
|
otherwise({
|
2015-11-09 15:42:52 +00:00
|
|
|
redirectTo: '/alerts'
|
2015-10-21 14:34:38 +00:00
|
|
|
});
|
2015-10-12 15:08:07 +00:00
|
|
|
}
|
2015-10-21 14:34:38 +00:00
|
|
|
);
|