Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
HAWKULAR-653 Triggers List (WIP)
Browse files Browse the repository at this point in the history
- get sorting working
- get notification working (limited to email only)
- fix trigger names for existing built-in alerts
- add 'Enabled' column
- experiment with Enable/Disable button
  • Loading branch information
jshaughn committed Oct 20, 2015
1 parent 66df8e2 commit 145e956
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ <h3 class="pull-left">Triggers ({{act.headerLinks.total}})</h3>
</div>

<div class="hk-table-container">
<div class="hk-actions-table">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown">
Change State
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" ng-click="act.enableSelected()" ng-disabled="!act.hasDisabledSelectedItems || act.isWorking">Enable</a></li>
<li role="presentation"><a role="menuitem" tabindex="-1" href="#" ng-click="act.disableSelected()" ng-disabled="act.hasEnabledselectedItems || act.isWorking">Disable</a></li>
</ul>
</div>
</div>
<div class="dataTables_header">
<div id="DataTables_Table_0_filter" class="dataTables_filter">
<label><input type="search" ng-model="act.search" aria-controls="DataTables_Table_0"></label>
Expand All @@ -46,6 +58,7 @@ <h3 class="pull-left">Triggers ({{act.headerLinks.total}})</h3>
<th ng-class="{'sorting_asc': act.sortField == 'description' && act.sortAsc, 'sorting_desc': act.sortField == 'description' && !act.sortAsc, 'sorting': act.sortField != 'description'}" ng-click="act.sortBy('description')">Description</th>
<th ng-class="{'sorting_asc': act.sortField == 'context.resourceName' && act.sortAsc, 'sorting_desc': act.sortField == 'context.resourceName' && !act.sortAsc, 'sorting': act.sortField != 'context.resourceName'}" ng-click="act.sortBy('context.resourceName')">Resource</th>
<th ng-class="{'sorting_asc': act.sortField == 'severity' && act.sortAsc, 'sorting_desc': act.sortField == 'severity' && !act.sortAsc, 'sorting': act.sortField != 'severity'}" ng-click="act.sortBy('severity')" ng-click="act.sortBy('severity')">Severity</th>
<th ng-class="{'sorting_asc': act.sortField == 'enabled' && act.sortAsc, 'sorting_desc': act.sortField == 'enabled' && !act.sortAsc, 'sorting': act.sortField != 'enabled'}" ng-click="act.sortBy('enabled')" ng-click="act.sortBy('enabled')">Enabled</th>
<th ng-class="{'sorting_asc': act.sortField == 'notifications' && act.sortAsc, 'sorting_desc': act.sortField == 'notifications' && !act.sortAsc, 'sorting': act.sortField != 'notifications'}" ng-click="act.sortBy('notifications')" ng-click="act.sortBy('notifications')">Notifications</th>
<th></th>
</tr>
Expand All @@ -56,9 +69,10 @@ <h3 class="pull-left">Triggers ({{act.headerLinks.total}})</h3>
<td><input type="checkbox" ng-checked="trigger.selected"/></td>
<td>{{trigger.name|firstUpper}}</td>
<td>{{trigger.description|firstUpper}}</td>
<td>{{trigger.context.resourceName | truncate: 30}}</td>
<td>{{trigger.context.resourceName|truncate: 30}}</td>
<td>{{trigger.severity|firstUpper}}</td>
<td>{{trigger.actions|firstUpper}}</td>
<td>{{trigger.enabled ? "True" : "False"}}</td>
<td>{{trigger.actions.email.length}} <i class="fa fa-envelope"></i></td>
<td><a class="btn btn-link"><i class="fa fa-chevron-circle-right fa-lg"
tooltip="View Details" tooltip-trigger tooltip-placement="top"
ng-click="act.showDetailPage(trigger.id)">
Expand Down
27 changes: 14 additions & 13 deletions console/src/main/scripts/plugins/metrics/ts/alertsCenterList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,26 @@ module HawkularMetrics {
ordering = 'desc';
}

this.HawkularAlertsManager.queryAlerts({statuses: this.alertsStatuses,
this.HawkularAlertsManager.queryAlerts({
statuses: this.alertsStatuses,
startTime: this.alertsTimeStart,
endTime: this.alertsTimeEnd,
currentPage: this.alertsCurPage,
perPage: this.alertsPerPage,
sort: this.sortField,
order: ordering
})
})
.then((queriedAlerts) => {
this.headerLinks = this.HkHeaderParser.parse(queriedAlerts.headers);
this.alertsList = queriedAlerts.alertList;
this.lastUpdateDate = new Date();
}, (error) => {
this.$log.warn(error);
}).catch((error) => {
this.$log.error('Error:' + error);
}).finally(() => {
this.lastUpdateDate = new Date();
});
}, (error) => {
this.$log.warn(error);
}).catch((error) => {
this.$log.error('Error:' + error);
}).finally(() => {
this.lastUpdateDate = new Date();
});
}

public showDetailPage(alertId:AlertId):void {
Expand Down Expand Up @@ -191,13 +192,13 @@ module HawkularMetrics {

public selectItem(item:IAlert):void {
item.selected = !item.selected;
this.selectedItems = _.filter(this.alertsList, 'selected');
this.selectedItems = _.filter(this.alertsList, 'selected');
this.selectCount = this.selectedItems.length;
this.hasOpenSelectedItems = _.some(this.selectedItems,{'status': 'OPEN'});
this.hasOpenSelectedItems = _.some(this.selectedItems, {'status': 'OPEN'});
}

public hasResolvedItems(): boolean {
return _.some(this.selectedItems,{'status': 'RESOLVED'});
public hasResolvedItems():boolean {
return _.some(this.selectedItems, {'status': 'RESOLVED'});
}

private resetAllUnselected() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ module HawkularMetrics {
public triggersCurPage = 0;
public headerLinks:any = {};
public selectCount = 0;
public hasOpenSelectedItems:boolean = false;
public hasEnabledSelectedItems:boolean = false;
public hasDisabledSelectedItems:boolean = false;
public sortField:string = 'name';
public sortAsc:boolean = false;


public loadingMoreItems:boolean = false;
public addProgress:boolean = false;
Expand Down Expand Up @@ -78,8 +82,15 @@ module HawkularMetrics {

public getTriggers():void {

let ordering = 'asc';
if (!this.sortAsc) {
ordering = 'desc';
}

this.HawkularAlertsManager.queryTriggers({currentPage: this.triggersCurPage,
perPage: this.triggersPerPage
perPage: this.triggersPerPage,
sort: this.sortField,
order: ordering
})
.then((queriedTriggers) => {
this.headerLinks = this.HkHeaderParser.parse(queriedTriggers.headers);
Expand All @@ -95,6 +106,73 @@ module HawkularMetrics {
});
}

public enableSelected():void {
this.$log.debug('Enable Selected Triggers');

// Error notification done with callback function on error
let errorCallback = (error:any, msg:string) => {
this.$log.error('Error:' + error);
};

this.isWorking = true;
let isError = false;
// Check if email action exists

console.log('Start!');
let updateTriggersPromises = this.updateSelected(true, errorCallback);

this.$q.all(updateTriggersPromises).finally(()=> {
this.isWorking = false;
console.log('Done!');
if (!isError) {
// notify success ?
}
});
}

public disableSelected():void {
this.$log.debug('Disable Selected Triggers');

// Error notification done with callback function on error
let errorCallback = (error:any, msg:string) => {
this.$log.error('Error:' + error);
};

this.isWorking = true;
let isError = false;
// Check if email action exists

let updateTriggersPromises = this.updateSelected(false, errorCallback);

this.$q.all(updateTriggersPromises).finally(()=> {
this.isWorking = false;

if (!isError) {
// notify success ?
}
});
}

updateSelected(enabled, errorCallback):Array<ng.IPromise<any>> {

let promises = [];
let triggerDefinition = {};
let triggerBackup = {};

this.triggersList.forEach((triggerItem:IAlertTrigger) => {
if (triggerItem.selected && (triggerItem.enabled !== enabled)) {
console.log("Setting " + enabled.toString());
triggerDefinition['trigger'] = angular.copy(triggerItem);
triggerBackup['trigger'] = angular.copy(triggerItem);
triggerDefinition['trigger'].enabled = enabled;
promises.push(this.HawkularAlertsManager.updateTrigger(triggerDefinition, errorCallback, triggerBackup));
console.log("Called Server!");
}
});

return promises;
}

public showDetailPage(triggerId:TriggerId):void {
this.$location.url(`/hawkular-ui/alerts-center-trigger-detail/${triggerId}`);
}
Expand All @@ -108,12 +186,17 @@ module HawkularMetrics {
item.selected = !item.selected;
this.selectedItems = _.filter(this.triggersList, 'selected');
this.selectCount = this.selectedItems.length;
this.hasOpenSelectedItems = _.some(this.selectedItems,{'status': 'OPEN'});
this.hasEnabledSelectedItems = _.some(this.selectedItems,{'enabled': true});
this.hasDisabledSelectedItems = _.some(this.selectedItems,{'enabled': false});
console.log("selectedItems:" + this.selectedItems.length);
console.log("hasEnabled:" + this.hasEnabledSelectedItems);
console.log("hasDisabled:" + this.hasDisabledSelectedItems);
}

private resetAllUnselected() {
this.selectCount = 0;
this.hasOpenSelectedItems = false;
this.hasEnabledSelectedItems = false;
this.hasDisabledSelectedItems = false;
this.triggersList.forEach((item:IAlertTrigger) => {
item.selected = false;
});
Expand All @@ -127,6 +210,13 @@ module HawkularMetrics {
this.selectCount = toggleTo ? this.triggersList.length : 0;
}

public sortBy(field:string):void {
this.sortField = field;
this.sortAsc = !this.sortAsc;
this.getTriggers();
this.$log.debug('Sorting by ' + field + ' ascending ' + this.sortAsc + ' ' + new Date());
}

}

_module.controller('AlertsCenterTriggerController', AlertsCenterTriggerController);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module HawkularMetrics {

let fullTrigger = {
trigger: {
name: resourceId,
name: 'JVM Heap Used',
id: triggerId,
description: 'JVM Heap Used for ' + resourceId,
autoDisable: true, // Disable trigger after firing, to not have repeated alerts of same issue
Expand Down Expand Up @@ -144,7 +144,7 @@ module HawkularMetrics {
let dataId:string = 'MI~R~[' + resourceId + '~~]~MT~WildFly Memory Metrics~NonHeap Used';
let fullTrigger = {
trigger: {
name: resourceId,
name: 'JVM Non Heap Used',
id: triggerId,
description: 'JVM Non Heap Used for ' + resourceId,
autoDisable: true, // Disable trigger after firing, to not have repeated alerts of same issue
Expand Down Expand Up @@ -200,7 +200,7 @@ module HawkularMetrics {
let dataId:string = 'MI~R~[' + resourceId + '~~]~MT~WildFly Memory Metrics~Accumulated GC Duration';
let fullTrigger = {
trigger: {
name: resourceId,
name: 'Accumulated GC Duration',
id: triggerId,
description: 'Accumulated GC Duration for ' + resourceId,
autoDisable: true, // Disable trigger after firing, to not have repeated alerts of same issue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module HawkularMetrics {

let fullTrigger = {
trigger: {
name: resourceId,
name: 'Active Web Sessions',
id: triggerId,
description: 'Active Web Sessions for ' + resourceId,
autoDisable: true, // Disable trigger after firing, to not have repeated alerts of same issue
Expand Down Expand Up @@ -145,7 +145,7 @@ module HawkularMetrics {

let fullTrigger = {
trigger: {
name: resourceId,
name: 'Expired Web Sessions',
id: triggerId,
description: 'Expired Web Sessions for ' + resourceId,
autoDisable: true, // Disable trigger after firing, to not have repeated alerts of same issue
Expand Down Expand Up @@ -203,7 +203,7 @@ module HawkularMetrics {

let fullTrigger = {
trigger: {
name: resourceId,
name: 'Rejected Web Sessions',
id: triggerId,
description: 'Rejected Web Sessions for ' + resourceId,
autoDisable: true, // Disable trigger after firing, to not have repeated alerts of same issue
Expand Down

0 comments on commit 145e956

Please sign in to comment.