-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
167 lines (131 loc) · 5.83 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE html>
<html>
<head>
<title>VMTurbo Entity Graph</title>
<link rel="stylesheet" href="css/main.css">
<link type="text/css" rel="Stylesheet" href="js/libs/blackbirdjs/blackbird.css" />
<script type="text/javascript" src="js/libs/blackbirdjs/blackbird.js"></script>
<script src="js/libs/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="js/libs/tcoz/jsbase/jsbase.js"></script>
<script type="text/javascript" src="js/libs/tcoz/jsbase/singletons_jsbase.js"></script>
<script type="text/javascript" src="js/libs/tcoz/jsbase/commands_jsbase.js"></script>
<script type="text/javascript" src="js/libs/tcoz/jsbase/utils_jsbase.js"></script>
<script type="text/javascript" src="http://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<script type="text/javascript">
// tcoz Framework namespace, only used by the utils and parser scripts in simple version.
// don't delete or change this or the tcoz and parser scripts won't work.
tcoz = { },
that = this;
// Alter these for your needs, watch the formatting, like trailing slashes and such.
var applianceAddress = 'http://administrator:administrator@localhost:8400/vmturbo/api/';
var notificationsURL = applianceAddress + 'notifications?category=MarketProblem';
var hostsURL = applianceAddress + 'markets/Market/hosts';
// When the document loads, this will run.
jQuery ( document ).ready ( function ( ) {
startApp ( );
} );
var _ajaxCallCommand = ( tcoz.ajaxCallCommand = baseCommand ( ) );
function startApp ( ) {
_ajaxCallCommand.dispatchCommandNotification ( 'AJAX_CALL',
{ 'destination' : notificationsURL, 'callback' : onStartupCallsReturn }
);
_ajaxCallCommand.dispatchCommandNotification ( 'AJAX_CALL',
{ 'destination' : hostsURL, 'callback' : onStartupCallsReturn }
);
}
var _notificationsList = [ ];
var _hostUUIDs = [ ];
var _startupCounter = 0;
function onStartupCallsReturn ( dataObj ) {
var i, xmlDoc, hosts, notifications;
try { xmlDoc = jQuery.parseXML ( dataObj.ajaxReturn ); }
catch ( err ) { xmlDoc = jQuery.parseXML ( '<root />' ); }
hosts = jQuery ( xmlDoc ).find ( 'ServiceEntity' );
notifications = jQuery ( xmlDoc ).find ( 'Notification' );
if ( hosts.length > 0 ) {
for ( i = 0; i < hosts.length; i += 1 ) {
var hostElement = hosts [ i ];
var uuid = jQuery ( hostElement ).attr ( 'uuid' );
_hostUUIDs.push ( uuid );
}
}
else if ( notifications.length > 0 ) {
_notificationsList = notifications;
}
_startupCounter += 1;
if ( _startupCounter === 2 )
intersectData ( );
}
function intersectData ( ) {
var i, j, intersectedData = [ ];
for ( i = 0; i < _notificationsList.length; i += 1 ) {
var notificationHostUUID = jQuery ( _notificationsList [ i ] ).attr ( 'notificationObjectUuid' );
for ( j = 0; j < _hostUUIDs.length; j += 1 ) {
if ( _hostUUIDs [ j ] === notificationHostUUID ) {
var severity = jQuery ( _notificationsList [ i ] ).attr ( 'severity' );
intersectedData.push ( { 'host' : notificationHostUUID, 'severity' : severity } );
}
}
}
intersectedData.sortOn ( 'host' );
chartTheData ( intersectedData );
}
function chartTheData ( intersectedData ) {
var i, j,
severities = [ 'minor', 'major', 'critical' ],
severityCounts = [ 0, 0, 0 ],
totalNotNormalSeverities = 0,
normalSeverities = 0,
totalEntities = _hostUUIDs.length,
seriesData = [ { 'type': 'pie', 'name': 'Percent', 'data': [ ] } ];
if ( _notificationsList.length === 0 ) {
seriesData [ 0 ].data.push ( [ 'Normal', 100.0 ] );
}
else {
for ( i = 0; i < severities.length; i += 1 ) {
for ( j = 0; j < intersectedData.length; j += 1 ) {
if ( severities [ i ].toLowerCase ( ) === intersectedData [ j ].severity.toLowerCase ( ) ) {
severityCounts [ i ] = severityCounts [ i ] += 1;
}
}
}
totalNotNormalSeverities = severityCounts [ 0 ] + severityCounts [ 1 ] + severityCounts [ 2 ];
normalSeverities = totalEntities - totalNotNormalSeverities;
seriesData [ 0 ].data.push ( [ 'Normal', ( normalSeverities / totalEntities ) ] );
if ( severityCounts [ 0 ] > 0 ) {
seriesData [ 0 ].data.push ( [ 'Minor', ( severityCounts [ 0 ] / totalEntities ) ] );
}
if ( severityCounts [ 1 ] > 0 ) {
seriesData [ 0 ].data.push ( [ 'Major', ( severityCounts [ 1 ] / totalEntities ) ] );
}
if ( severityCounts [ 2 ] > 0 ) {
seriesData [ 0 ].data.push ( [ 'Critical', ( severityCounts [ 2 ] / totalEntities ) ] );
}
}
var chart1 = new Highcharts.Chart ( {
chart: {
renderTo: 'chartContainer',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
credits: {
enabled: false
},
title: {
text: 'Health'
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
series: seriesData,
colors: [ '#228B22', '#EEE9BF', '#FFA500', 'EE0000' ]
} );
}
</script>
<div id="chartContainer"></div>
</body>
</html>