Skip to content

Commit d6b2b9d

Browse files
committed
#1 updates
1 parent eca644f commit d6b2b9d

File tree

11 files changed

+122
-50
lines changed

11 files changed

+122
-50
lines changed

generator/index.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ process.env.JOOLA_CONFIG_STORE_LOGGER_CONSOLE_LEVEL = 'trace';
88

99
var counter = 0;
1010

11-
joola.init({host: 'http://localhost:8081', APIToken: 'apitoken-demo'}, function (err) {
11+
joola.init({host: 'http://lab-001.joo.la:8081', APIToken: 'apitoken-demo'}, function (err) {
1212
if (err)
1313
throw err;
1414

@@ -49,12 +49,13 @@ joola.events.on('goahead', function () {
4949
var collection = _point._collection ? _point._collection.value : 'geo';
5050
delete _point._save;
5151
delete _point._collection;
52+
5253
joola.insert(collection, [_point], function (err) {
5354
if (err)
5455
throw err;
5556
counter++;
56-
if (counter % 1000 === 0)
57-
console.log('Pushed 1000 events');
57+
if (counter % 100 === 0)
58+
console.log('Pushed 100 events');
5859
});
5960
}
6061
});

generator/sources/iec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ module.exports = {
99
return new Date().getTime();
1010
}},
1111
site_id: {key: 'site_id', type: 'dimension', datatype: 'string', value: function () {
12-
return ((Math.floor(Math.random() * 100) + 1) / 100) < 0.7 ? '1' : '2'
12+
return ((Math.floor(Math.random() * 100) + 1) / 100) < 0.3 ? '1' : (Math.floor(Math.random() * 3) + 2).toString()
1313
}},
1414
event_id: {key: 'event_id', type: 'dimension', datatype: 'string', value: function () {
1515
return '1234';
1616
}},
1717
event_type: {key: 'event_type', type: 'dimension', datatype: 'string', value: function () {
18-
return ((Math.floor(Math.random() * 100) + 1) / 100) < 0.9 ? 'info' : 'alert';
18+
return ((Math.floor(Math.random() * 100) + 1) / 100) < 0.98 ? 'info' : 'alert';
1919
}},
2020
event_ip: {key: 'event_ip', type: 'dimension', datatype: 'string', value: function () {
2121
var ips = [

public/css/bootstrap.min.css

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/iec.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
66
<meta charset="utf-8">
77
<link rel="stylesheet" href="http://layout.jquery-dev.com/lib/css/layout-default-latest.css">
8-
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
8+
<link rel="stylesheet" href="/css/bootstrap.min.css">
99
<link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
1010
<link rel="stylesheet" href="/iec/js/vendor/introjs.min.css">
1111

@@ -20,8 +20,8 @@
2020
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/vis/3.11.0/vis.css">
2121
<link rel="stylesheet" href="/iec/css/default.css">
2222

23-
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
24-
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
23+
<script src="/js/vendor/jquery-1.11.2.min.js"></script>
24+
<script src="/js/vendor/jquery-ui.min.js"></script>
2525
<script src="http://layout.jquery-dev.com/lib/js/jquery.layout-latest.js"></script>
2626
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.2/underscore-min.js"></script>
2727
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.6/mapbox.js'></script>
@@ -41,7 +41,7 @@
4141
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.min.js"></script>
4242

4343
<script src="https://cdnjs.cloudflare.com/ajax/libs/vis/3.11.0/vis.js"></script>
44-
<script src="http://home.joo.la:8081/joola.js"></script>
44+
<script src="http://lab-001.joo.la:8081/joola.js"></script>
4545
<script src="/iec/js/state.js"></script>
4646
<script src="/iec/js/globals.js"></script>
4747
<script src="/iec/js/geohash.js"></script>

public/iec/js/globals.js

+27
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,32 @@ var GeoJSON = [
7777
]
7878
}
7979

80+
},
81+
{
82+
"type": "Feature",
83+
"geometry": {
84+
"type": "Point",
85+
"coordinates": [34.892,32.176]
86+
},
87+
"properties": {
88+
"site_id": "3",
89+
"title": "IEC Site 003",
90+
"marker-size": "small"
91+
},
92+
"viz_data": {
93+
nodes: [
94+
{id: 1, label: 'Node 1', ip: '10.0.0.1'},
95+
{id: 2, label: 'Node 2', ip: '10.0.0.2'},
96+
{id: 3, label: 'Node 3', ip: '10.0.0.3'},
97+
{id: 4, label: 'Node 4', ip: '10.0.0.4'},
98+
{id: 5, label: 'Node 5', ip: '10.0.0.5'}
99+
],
100+
edges: [
101+
{from: 1, to: 2},
102+
{from: 1, to: 3},
103+
{from: 2, to: 4},
104+
{from: 2, to: 5}
105+
]
106+
}
80107
}
81108
];

public/iec/js/joola.js

+47-36
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,65 @@ joola.on('ready', function () {
99
throw err;
1010
data = data[0].documents;
1111

12+
GeoJSON.forEach(function (site) {
13+
site.alerts = [];
14+
site.viz_data.nodes.forEach(function (node) {
15+
node.alerts = [];
16+
});
17+
});
18+
1219
data.forEach(function (point) {
20+
var theSite = null;
1321
GeoJSON.forEach(function (site) {
1422
if (site.properties.site_id === point.site_id) {
15-
site.properties.counter = site.properties.counter || {};
16-
site.properties.counter[point.event_type] = site.properties.counter[point.event_type] || 0;
17-
site.properties.counter[point.event_type] = point.metric;
18-
19-
var description = '<h3>Site details<h3>';
20-
Object.keys(site.properties.counter).forEach(function (key) {
21-
description += '<strong>' + key + '</strong>: ' + site.properties.counter[key] + '<br/>';
22-
});
23-
24-
site.alerts = site.alerts || [];
25-
site.alerts.push(point);
26-
site.viz_data.nodes.forEach(function (node) {
27-
if (node.ip === point.event_ip) {
28-
node.alerts = node.alerts || [];
29-
node.alerts.push(point);
30-
node.color = {background: '#fc4353'};
31-
}
32-
});
33-
34-
23+
theSite = site;
3524
}
3625
});
26+
if (!theSite)
27+
return;
28+
theSite.properties.counter = theSite.properties.counter || {};
29+
theSite.properties.counter[point.event_type] = theSite.properties.counter[point.event_type] || 0;
30+
theSite.properties.counter[point.event_type] = point.metric;
31+
32+
var description = '<h3>Site details<h3>';
33+
Object.keys(theSite.properties.counter).forEach(function (key) {
34+
description += '<strong>' + key + '</strong>: ' + theSite.properties.counter[key] + '<br/>';
35+
});
36+
37+
//theSite.alerts = theSite.alerts || [];
38+
if (point.event_type === 'alert') {
39+
theSite.alerts.push(point);
40+
theSite.viz_data.nodes.forEach(function (node) {
41+
if (node.ip === point.event_ip) {
42+
//node.alerts = node.alerts || [];
43+
node.alerts.push(point);
44+
//node.color = {background: '#fc4353'};
45+
}
46+
});
47+
}
3748
});
3849
refreshHeatmap();
3950
updateFeatures();
4051
showAlertList();
4152
});
4253
});
4354

44-
setInterval(function () {
45-
GeoJSON.forEach(function (site) {
46-
site.viz_data.nodes.forEach(function (node) {
47-
if (node.alerts) {
48-
node.alerts.forEach(function (alert, i) {
49-
var max_diff_sec = 90;
50-
var diff = (new Date().getTime() - new Date(alert.timestamp).getTime()) / 1000;
51-
if (diff > max_diff_sec) {
52-
console.log('removing alert from viz node');
53-
node.alerts.splice(i, 1);
54-
}
55-
});
56-
}
57-
});
58-
});
59-
}, 1000);
55+
/*setInterval(function () {
56+
GeoJSON.forEach(function (site) {
57+
site.viz_data.nodes.forEach(function (node) {
58+
if (node.alerts) {
59+
node.alerts.forEach(function (alert, i) {
60+
var max_diff_sec = 90;
61+
var diff = (new Date().getTime() - new Date(alert.timestamp).getTime()) / 1000;
62+
if (diff > max_diff_sec) {
63+
console.log('removing alert from viz node');
64+
node.alerts.splice(i, 1);
65+
}
66+
});
67+
}
68+
});
69+
});
70+
}, 1000);*/
6071

6172
joola.beacon.subscribe(function (err) {
6273
if (err)

public/iec/js/leaflet.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,15 @@ function showAlertList() {
9191
var counter = 0;
9292
var trs = [];
9393
featureLayer.eachLayer(function (marker) {
94+
if (!marker.feature.alerts)
95+
return;
9496
if (counter > 10)
9597
return;
9698

9799
marker.feature.alerts.forEach(function (alert, i) {
98100
var max_diff_sec = 90;
99101
var diff = (new Date().getTime() - new Date(alert.timestamp).getTime()) / 1000;
100102
if (diff > max_diff_sec) {
101-
console.log('removing alert from marker',diff);
102103
marker.feature.alerts.splice(i, 1);
103104
}
104105
});
@@ -107,6 +108,8 @@ function showAlertList() {
107108
marker.feature.alerts.forEach(function (alert) {
108109
if (counter > 10)
109110
return;
111+
112+
if (alert.event_type==='alert'){
110113
var $tr = $('<tr></tr>');
111114
var $td = $('<td></td>');
112115
$td.html('<time class="timeago" datetime="' + new Date(alert.timestamp).toISOString() + '">' + timeDifference(new Date, new Date(alert.timestamp)) + '</time>');
@@ -125,6 +128,7 @@ function showAlertList() {
125128
});
126129
$tr.timestamp = alert.timestamp;
127130
counter++;
131+
}
128132
});
129133
}
130134
});
@@ -138,7 +142,7 @@ function showAlertList() {
138142
trs.forEach(function ($tr) {
139143
$table.append($tr);
140144
});
141-
if (trs.length===0){
145+
if (trs.length === 0) {
142146
var $tr = $('<tr></tr>');
143147
var $td = $('<td>No alerts registered, trying zooming out.</td>');
144148
$tr.append($td);

public/iec/js/network.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@ var network = null;
44

55
function draw(data, site) {
66

7-
console.log(site);
7+
site.viz_data.nodes.forEach(function(node){
8+
if (node.alerts && node.alerts.length>0)
9+
node.color='#a3e46b';
10+
else
11+
node.color='#fc4353';
12+
});
13+
14+
815
$('#site-name').html(site.properties.title + ' Description');
916
// create a network
1017
var container = document.getElementById('mynetwork');
@@ -91,7 +98,7 @@ function draw(data, site) {
9198
});
9299

93100
if (site.alerts.length > 0) {
94-
console.log('alerts', site.alerts[0]);
101+
//console.log('alerts', site.alerts[0]);
95102
$tr = $('<tr></tr>');
96103
['Timestamp', 'Node', 'Event'].forEach(function (key) {
97104
if (['site_id', 'event_type', 'metric'].indexOf(key) === -1) {

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<script src="/js/leaflet.js"></script>
4444
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.min.js"></script>
4545

46-
<script src="http://home.joo.la:8081/joola.js"></script>
46+
<script src="http://localhost:8081/joola.js"></script>
4747
<script src="/js/state.js"></script>
4848
<script src="/js/globals.js"></script>
4949
<script src="/js/geohash.js"></script>

public/js/vendor/jquery-1.11.2.min.js

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/vendor/jquery-ui.min.js

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)