-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomstep.js
69 lines (53 loc) · 2.21 KB
/
customstep.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
if (input.htmlBody !== null) {
//skip execution if "Heartbeat Missed" message received
if (input.htmlBody.indexOf("Heartbeat Missed") !== -1) {
throw new Error("Heartbeat Missed - skip alarm creation");
}
//grab copy of body vefore stripping
var htmlText = input.htmlBody;
//strip all before start of relevant info
htmlText = htmlText.slice(htmlText.indexOf("Current Alarm States"));
//remove everything after relevant table close tag
htmlText = htmlText.slice(0, htmlText.indexOf("</table>") + 8);
console.log('HTML text body: ' + htmlText);
//grab copy of HTML output
var plainText = htmlText;
// remove all HTML tags and anything inside of them
plainText = plainText.replace(/(<([^>]+)>)/gi, '');
//remove all carriage returns
plainText = plainText.replace(/\r/g, "");
//replace 4 line breaks with single
plainText = plainText.replace(/\n{4,}/g, '\n');
//replace 3 line breaks with single
plainText = plainText.replace(/\n{3,}/g, '\n');
//replace 2 line breaks with null
plainText = plainText.replace(/\n{2,}/g, '');
//trim ending newline
plainText = plainText.trim();
console.log('Plain text body: ' + plainText);
var recipients = input.recipients;
if (recipients == "argus") {
var textArray = plainText.split("\n");
var hits = 0;
console.log('Text Array length: ' + textArray.length);
for (var i = 0; i < textArray.length; i++) {
if (textArray[i].toLowerCase().includes("dig")
|| textArray[i].toLowerCase().includes("septic")
|| textArray[i].toLowerCase().includes("solar")
|| textArray[i].toLowerCase().includes("silent")
|| textArray[i].toLowerCase().includes("had an alarm")) {
hits++;
console.log('Number of hits: ' + hits);
}
}
if (hits < (textArray.length - 1)) {
recipients = "greenhouse";
} else {
throw new Error("No group should receive this alarm");
//recipients = "technicalservices";
}
}
}
output.targetGroup = recipients;
output.modhtmlBody = htmlText;
output.modBody = plainText;