/
monitor.html
186 lines (159 loc) · 6.64 KB
/
monitor.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!-- SPDX-License-Identifier: CC-BY-4.0 -->
<!-- Copyright Contributors to the ODPi Egeria project. -->
<!doctype html>
<html>
<head>
<title>OMRS Event Monitor</title>
<style>
* { margin: 10; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; background-color: #FFFFFF }
#graphviz { position: absolute; top : 200px; right: 8px; width: 600px; height: 600px; background-color: #66CCDD; }
#messages { list-style-type: none; margin: 10; padding: 10; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
.node {
fill: #FFF;
stroke: #08F;
stroke-width: 2px;
}
.link {
stroke: #F70;
stroke-width: 2px;
}
.nodelabel {
color: red;
font: 10px sans-serif;
}
</style>
</head>
<body>
<center>
<h1>OMRS Event Monitor</h1>
<p>Simple demonstration that displays recent events seen on the OMRS topic for the cohort specified in the URL (e.g. http://localhost:58080/cohort/<cohort-name>)</p>
<p>A summary of each event is shown in the scrollable list below. The OMRS events are also logged as JSON in the console.</p>
<p>When the list or the visualization gets too cluttered, reload the page to start again clean.</p>
</center>
<div id='cohortName'>Cohort: <i>loading...</i> </div>
<div id='graphviz'>Visualization Area</div>
<div id="" style="overflow:scroll; height:600px; width:800px;">
<ul id="messages"></ul>
</div>
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script src="https://d3js.org/d3.v5.min.js"></script>
<script src="/d3_graphviz.js"></script>
<script>
$( function () {
var socket = io();
socket.on('cohort', function(msg){
console.log('Monitoring activity for cohort: '+msg);
$('#cohortName').html("Cohort: "+msg);
omrsMon_initialize();
});
socket.on('event', function(msg){
console.log(msg);
// TODO Should combine event extraction into a single function that builds a JSON object...
eventString = extractEventDetails(msg);
eventType = extractEventType(msg);
$('#messages').append($('<li>').text(eventString));
if (eventType == 'REGISTRY') {
console.log('Handled registry event - nothing added to graph');
}
else if (eventType == 'ENTITY') {
eventGuid = extractEventGuid(msg);
entityName = extractEventEntityName(msg);
omrsMon_addNode(eventGuid,entityName);
}
else if (eventType == 'RELATIONSHIP') {
eventGuid = extractEventGuid(msg);
end1Guid = extractEventEnd1Guid(msg);
end2Guid = extractEventEnd2Guid(msg);
omrsMon_addLink(eventGuid, end1Guid, end2Guid);
}
});
});
extractEventDetails = function(msg) {
var eventString = '';
var date = new Date(parseInt(msg.timestamp));
eventString += ' '+date.toLocaleString();
eventString += ' '+msg.originator.serverName;
if (msg.eventCategory != null && msg.eventCategory == 'REGISTRY') {
eventString += ' '+msg.originator.serverName;
if (msg.originator.metadataCollectionId != null) {
eventString += ' '+msg.originator.metadataCollectionId;
}
eventString += ' '+msg.registryEventSection.registryEventType;
}
else if (msg.eventCategory != null && msg.eventCategory == 'INSTANCE') {
eventString += ' '+msg.instanceEventSection.eventType;
if (msg.instanceEventSection.eventType == 'NEW_ENTITY_EVENT') {
eventString += ' '+msg.instanceEventSection.typeDefName;
if (msg.instanceEventSection.entity.properties.instanceProperties.qualifiedName != null) {
eventString += ' '+msg.instanceEventSection.entity.properties.instanceProperties.qualifiedName.primitiveValue;
}
eventString += ' '+msg.instanceEventSection.entity.guid;
}
else if (msg.instanceEventSection.eventType == 'NEW_RELATIONSHIP_EVENT') {
eventString += ' '+msg.instanceEventSection.eventType;
eventString += ' '+msg.instanceEventSection.typeDefName;
eventString += ' '+msg.instanceEventSection.relationship.guid;
}
}
return eventString;
};
extractEventGuid = function(msg) {
var eventGuid = '';
if (msg.eventCategory != null && msg.eventCategory == 'INSTANCE') {
if (msg.instanceEventSection.eventType == 'NEW_ENTITY_EVENT') {
eventGuid = msg.instanceEventSection.entity.guid;
}
else if (msg.instanceEventSection.eventType == 'NEW_RELATIONSHIP_EVENT') {
eventGuid = msg.instanceEventSection.relationship.guid;
}
}
return eventGuid;
}
extractEventType = function(msg) {
var eventType = '';
if (msg.eventCategory != null && msg.eventCategory == 'REGISTRY') {
eventType = 'REGISTRY';
}
if (msg.eventCategory != null && msg.eventCategory == 'INSTANCE') {
if (msg.instanceEventSection.eventType == 'NEW_ENTITY_EVENT') {
eventType = 'ENTITY';
}
else if (msg.instanceEventSection.eventType == 'NEW_RELATIONSHIP_EVENT') {
eventType = 'RELATIONSHIP';
}
}
return eventType;
}
extractEventEntityName = function(msg) {
var entityName = '';
if (msg.eventCategory != null && msg.eventCategory == 'INSTANCE') {
if (msg.instanceEventSection.eventType == 'NEW_ENTITY_EVENT') {
// Huge leap of faith here....
entityName = msg.instanceEventSection.entity.properties.instanceProperties.qualifiedName.primitiveValue;
}
}
return entityName;
}
extractEventEnd1Guid = function(msg) {
var end1Guid = '';
if (msg.instanceEventSection.eventType == 'NEW_RELATIONSHIP_EVENT') {
end1Guid = msg.instanceEventSection.relationship.entityOneProxy.guid;
}
console.log('end 1 has guid '+end1Guid);
return end1Guid;
}
extractEventEnd2Guid = function(msg) {
var end2Guid = '';
if (msg.instanceEventSection.eventType == 'NEW_RELATIONSHIP_EVENT') {
end2Guid = msg.instanceEventSection.relationship.entityTwoProxy.guid;
}
console.log('end 2 has guid '+end2Guid);
return end2Guid;
}
</script>
</body>
</html>