-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebsocket_nodeClient.js
60 lines (52 loc) · 1.73 KB
/
websocket_nodeClient.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
//
// IMPORTANT
//
// Your use of this Software is pursuant to the Silver Peak Disclaimer - see the README file for this repository
//
//
const WebSocket = require('ws');
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
/**
* Update these variables here for your Orchestrator environment
* ipOrDNS: ip address or FQDN of the target Orchestrator
* receiverId: id of websocket remote log receiver created on Orchestrator (integer)
* key: key that Orchestrator generates after websocket server is configured
*/
var ipOrDNS = "localhost";
var receiverId = 1;
var key = "";
//modify ipOrDNS, receiverId and key for your test
const ws = new WebSocket(`wss://${ipOrDNS}/remoteLogWebSocket/${receiverId}`, null, {
headers: {
"X-Auth-Token": key
}
});
ws.on('open', function open() { });
ws.on('message', function incoming(data) {
console.log("WS1 GOT MESSAGE:");
console.log(JSON.parse(data));
});
function requestActiveAlarm() {
// The client can request current active alarms over the websocket
if (ws != null) {
var req = {
action: "ACTIVE_ALARMS"
}
ws.send(JSON.stringify(req));
console.log(`Send request to ws, ${JSON.stringify(req)}`);
}
}
function requestAlarmByIds() {
// The client can request specific alarms or audit log notifications based on sequence IDs
// ids is a list of integers or integer ranges identifying the requested sequenceIds
var ids = ["2", "3", "4-6"];
if (ws != null) {
var req = {
action: "RESUBMISSION",
type: "SEQUENCE_ID",
data: JSON.stringify(ids)
}
ws.send(JSON.stringify(req));
console.log(`Send request to ws, ${JSON.stringify(req)}`);
}
}