2 * Copyright (c) 2016 Tech Mahindra Ltd. 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
10 [ 'app/mwtnEvents/mwtnEvents.module', 'app/mwtnEvents/mwtnEvents.services', 'app/mwtnCommons/mwtnCommons.services'],
11 function(mwtnEventsApp) {
13 mwtnEventsApp.register
21 function($scope, $rootScope, $mwtnEvents, uiGridConstants) {
23 $rootScope.section_logo = 'src/app/mwtnEvents/images/mwtnEvents.png';
25 $scope.status = {alarms:true};
26 $scope.oneATime = true;
28 $scope.gridOptionsAlarms = JSON.parse(JSON.stringify($mwtnEvents.gridOptions));
29 $scope.gridOptionsAlarms.columnDefs = [
30 // { field: 'id', type: 'number', displayName: 'No.', headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true },
31 // { field: 'icon', type: 'string', displayName: '', headerCellClass: $scope.highlightFilteredHeader, width: 25, enableSorting: false, enableFiltering:false, cellTemplate: iconCell },
32 { field: 'timeStamp', type: 'string', displayName: 'Timestamp', headerCellClass: $scope.highlightFilteredHeader, width : 200,sort: {
33 direction: uiGridConstants.DESC,
36 { field: 'counter', type: 'number', displayName: 'Counter', headerCellClass: $scope.highlightFilteredHeader, width: 90 },
37 { field: 'nodeName', type: 'string', displayName: 'NetworkElement', headerCellClass: $scope.highlightFilteredHeader, width: 170 },
38 { field: 'objectId', type: 'string', displayName: 'Object', headerCellClass: $scope.highlightFilteredHeader, width: 400 },
40 { field: 'problem', type: 'string', displayName: 'Alarm', headerCellClass: $scope.highlightFilteredHeader, width : 140 },
41 { field: 'severity', type: 'string', displayName: 'Severity', headerCellClass: $scope.highlightFilteredHeader, width : 100 }
44 $scope.gridOptionsAVC = JSON.parse(JSON.stringify($mwtnEvents.gridOptions));
45 $scope.gridOptionsAVC.columnDefs = [
46 // { field: 'id', type: 'number', displayName: 'No.', headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true },
47 // { field: 'icon', type: 'string', displayName: '', headerCellClass: $scope.highlightFilteredHeader, width: 25, enableSorting: false, enableFiltering:false, cellTemplate: iconCell },
48 { field: 'timeStamp', type: 'string', displayName: 'Timestamp', headerCellClass: $scope.highlightFilteredHeader, width : 200,sort: {
49 direction: uiGridConstants.DESC,
52 { field: 'counter', type: 'number', displayName: 'Counter', headerCellClass: $scope.highlightFilteredHeader, width: 90 },
53 { field: 'nodeName', type: 'string', displayName: 'NetworkElement', headerCellClass: $scope.highlightFilteredHeader, width: 170 },
54 { field: 'objectId', type: 'string', displayName: 'Object', headerCellClass: $scope.highlightFilteredHeader, width: 400 },
55 { field: 'attributeName', type: 'string', displayName: 'Attribute', headerCellClass: $scope.highlightFilteredHeader, width : 140 },
56 { field: 'newValue', type: 'string', displayName: 'New value', headerCellClass: $scope.highlightFilteredHeader, width : 140 }
59 $scope.gridOptionsObject = JSON.parse(JSON.stringify($mwtnEvents.gridOptions));
60 $scope.gridOptionsObject.columnDefs = [
61 // { field: 'id', type: 'number', displayName: 'No.', headerCellClass: $scope.highlightFilteredHeader, width : 50, cellClass: 'number', pinnedLeft : true },
62 // { field: 'icon', type: 'string', displayName: '', headerCellClass: $scope.highlightFilteredHeader, width: 25, enableSorting: false, enableFiltering:false, cellTemplate: iconCell },
63 { field: 'timeStamp', type: 'string', displayName: 'Timestamp', headerCellClass: $scope.highlightFilteredHeader, width : 200,sort: {
64 direction: uiGridConstants.DESC,
67 { field: 'counter', type: 'number', displayName: 'Counter', headerCellClass: $scope.highlightFilteredHeader, width: 90 },
68 { field: 'nodeName', type: 'string', displayName: 'NetworkElement', headerCellClass: $scope.highlightFilteredHeader, width: 170 },
69 { field: 'objectId', type: 'string', displayName: 'Object', headerCellClass: $scope.highlightFilteredHeader, width: 400 },
70 { field: 'objectType', type: 'string', displayName: 'Type', headerCellClass: $scope.highlightFilteredHeader, width: 400 },
71 { field: 'action', type: 'string', displayName: 'Action', headerCellClass: $scope.highlightFilteredHeader, width: 100 }
75 var listenToNotifications = function() {
76 $mwtnEvents.getMwtnWebSocketUrl().then(function(success){
79 var notificationSocket = new WebSocket(success);
81 notificationSocket.onmessage = function(event) {
82 // we process our received event here
83 if (typeof event.data === 'string') {
84 // console.log("Client Received:\n" + event.data);
85 // console.log("---------------------------");
86 $mwtnEvents.formatData(event).then(function(formated) {
87 switch (formated.notifType) {
88 case 'ProblemNotification':
89 $scope.gridOptionsAlarms.data.push(formated);
91 case 'AttributeValueChangedNotification':
92 $scope.gridOptionsAVC.data.push(formated);
94 case 'ObjectCreationNotification':
95 formated.action = 'created';
96 if (formated.nodeName.contains('SDN-Controller')) {
97 formated.objectType = 'NETCONF session';
99 $scope.gridOptionsObject.data.push(formated);
101 case 'ObjectDeletionNotification':
102 formated.action = 'deleted';
103 if (formated.nodeName.contains('SDN-Controller')) {
104 formated.objectType = 'NETCONF session';
106 $scope.gridOptionsObject.data.push(formated);
109 console.error('Missing implementation for', formated.notifType);
117 notificationSocket.onerror = function(error) {
118 console.log("Socket error: " + error);
121 notificationSocket.onopen = function(event) {
122 console.log("Socket connection opened.");
123 console.log("---------------------------");
125 function subscribe() {
126 if (notificationSocket.readyState === notificationSocket.OPEN) {
129 'scopes' : [ "ObjectCreationNotification",
130 "ObjectDeletionNotification",
131 "AttributeValueChangedNotification",
132 "ProblemNotification" ]
134 notificationSocket.send(JSON.stringify(data));
140 notificationSocket.onclose = function(event) {
141 console.log("Socket connection closed.");
144 console.error("Error when creating WebSocket.\n" + e);
147 console.error("Error when creating WebSocket.\n" + error);
150 listenToNotifications();