-
Notifications
You must be signed in to change notification settings - Fork 2
/
elkstatus.js
98 lines (84 loc) · 3.34 KB
/
elkstatus.js
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
var xmldom = require('xmldom');
var utils = require('./utils.js');
var parser = require('xmldom').DOMParser;
var fs = require('fs');
function ElkStatus(statusFile, topologyFile) {
this.elkStatusContents = fs.readFileSync(statusFile).toString();
this.elkStatus = new parser().parseFromString(this.elkStatusContents.substring(2, this.elkStatusContents.length));
this.elkTopologyContents = fs.readFileSync(topologyFile).toString();
this.elkTopology = new parser().parseFromString(this.elkTopologyContents.substring(2, this.elkTopologyContents.length));
this.loadZoneList();
}
ElkStatus.prototype.loadZoneList = function() {
this.zoneMap = {};
this.zoneList = [];
var elkZones = this.elkTopology.getElementsByTagName('zone')
for(var zoneIndex = 0; zoneIndex < elkZones.length; zoneIndex++) {
var zoneId = elkZones[zoneIndex].getAttribute("id");
var zoneName = elkZones[zoneIndex].getAttribute("name")
var zoneAlarmDef = elkZones[zoneIndex].getAttribute("alarmDef")
var zoneData = { id: zoneId, name: zoneName, alarmDef: zoneAlarmDef};
this.zoneList.push(zoneData);
this.zoneMap[zoneId] = zoneData;
}
}
ElkStatus.prototype.getStatus = function() {
return this.elkStatus.toString();
}
ElkStatus.prototype.getTopology = function() {
return this.elkTopology.toString();
}
ElkStatus.prototype.getZones = function() {
return this.zoneList;
}
ElkStatus.prototype.getZoneData = function(id) {
var zoneEntry = this.zoneMap[id];
if(zoneEntry == null) {
return null;
}
var zoneData = {};
var zoneStatusElements = this.elkStatus.getElementsByTagName('ze');
for(var index = 0; index < zoneStatusElements.length; index++) {
var zoneStatusElement = zoneStatusElements[index];
if(zoneStatusElement.getAttribute("zone")==id) {
zoneData[zoneStatusElement.getAttribute("type")] = zoneStatusElement.getAttribute("val");
}
}
return zoneData;
}
ElkStatus.prototype.setZoneData = function(id, type, value) {
var changed = false;
var zoneEntry = this.zoneMap[id];
if(zoneEntry == null) {
return null;
}
var zoneStatusElements = this.elkStatus.getElementsByTagName('ze');
for(var index = 0; index < zoneStatusElements.length; index++) {
var zoneStatusElement = zoneStatusElements[index];
if(zoneStatusElement.getAttribute("zone")==id && zoneStatusElement.getAttribute("type")==type) {
changed = (zoneStatusElement.getAttribute("val")!=value);
zoneStatusElement.setAttribute("val",value);
break;
}
}
return changed;
}
ElkStatus.prototype.getAreaAttribute = function(type) {
var areaElements = this.elkStatus.getElementsByTagName('ae');
for(var index = 0; index < areaElements.length; index++) {
if(areaElements[index].getAttribute("type")==type) {
return areaElements[index].getAttribute("val");
}
}
}
ElkStatus.prototype.setAreaAttribute = function(type,value) {
var areaElements = this.elkStatus.getElementsByTagName('ae');
for(var index = 0; index < areaElements.length; index++) {
if(areaElements[index].getAttribute("type")==type) {
areaElements[index].setAttribute("val",value);
}
}
}
ElkStatus.prototype.setAlarmState = function(status) {
}
exports.ElkStatus = ElkStatus;