2 * Copyright (c) 2017 highstreet technologies GmbH and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 define([ 'app/mwtnCommons/mwtnCommons.module'], function(mwtnCommonsApp) {
10 mwtnCommonsApp.register.directive('alarmStatus', function() {
13 templateUrl : 'src/app/mwtnFault/templates/alarmStatus.tpl.html',
14 controller : ['$scope', '$mwtnCommons', '$mwtnDatabase', '$timeout', function($scope, $mwtnCommons, $mwtnDatabase, $timeout){
16 $scope.link = '#/pnfFault/';
20 $scope.alarmStatus = {
27 $scope.getAlarmStatusSum = function(){
29 Object.keys($scope.alarmStatus).map(function(severity) {
30 sum = sum + $scope.alarmStatus[severity];
35 // Update: request the number of alarms in current alarm list per severity
36 var update = function() {
37 $mwtnCommons.getMountPoints().then(function(mountpoints) {
38 $scope.nodeCount = mountpoints.filter(function(mountpoint) {
39 return mountpoint['netconf-node-topology:connection-status'] === 'connected';
42 var functionId = 'sdnevents';
43 var docType = 'faultcurrent';
49 "field": "faultCurrent.severity"
54 $mwtnDatabase.getAggregations(functionId, docType, aggregations).then(function (success) {
55 var found = success.data.aggregations['severity'].buckets.map(function(bucket){
56 $scope.alarmStatus[bucket.key] = bucket.doc_count;
59 Object.keys($scope.alarmStatus).map(function(key){
60 if (!found.contains(key)) {
61 $scope.alarmStatus[key] = 0;
66 $scope.alarmStatus = {
75 // Object.keys($scope.alarmStatus).map(function(severity) {
76 // // usage of the ElasticSearch Count API
77 // $mwtnDatabase.getBase('sdnevents').then(function(success) {
78 // var databaseRequest = {
79 // base : success.base,
82 // index: success.index,
83 // docType: 'faultcurrent',
86 // 'faultCurrent.severity': severity
90 // $mwtnDatabase.genericRequest(databaseRequest).then(function(success){
91 // $scope.alarmStatus[severity] = success.data.count;
92 // }, function(error){
93 // console.error('severity', severity, error);
95 // }, function(error) {
96 // console.error('severity', severity, error);
102 var listenToNotifications = function() {
103 $mwtnCommons.getMwtnWebSocketUrl().then(function(success){
105 var notificationSocket = new WebSocket(success);
107 notificationSocket.onmessage = function(event) {
108 // we process our received event here
109 if (typeof event.data === 'string') {
110 // console.log('Client Received:\n', event.data);
111 $mwtnCommons.formatData(event).then(function(formated) {
112 switch (formated.notifType) {
113 case 'ProblemNotification':
114 $timeout(function(){update();}, 500);
116 case 'AttributeValueChangedNotification':
117 case 'ObjectCreationNotification':
118 case 'ObjectDeletionNotification':
122 console.error('Missing implementation for', formated.notifType);
130 notificationSocket.onerror = function(error) {
131 console.log("Socket error: " + error);
134 notificationSocket.onopen = function(event) {
135 console.log("Socket connection opened.");
136 function subscribe() {
137 if (notificationSocket.readyState === notificationSocket.OPEN) {
140 'scopes' : [ "ProblemNotification" ]
142 notificationSocket.send(JSON.stringify(data));
148 notificationSocket.onclose = function(event) {
149 console.log("Socket connection closed.");
152 console.error("Error when creating WebSocket.\n" + e);
155 console.error("Error when creating WebSocket.\n" + error);
158 listenToNotifications();