-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsubscriber_anc.js
35 lines (31 loc) · 939 Bytes
/
subscriber_anc.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
const { pxgrid, pxclient } = require('./pxgrid-setup');
const ancCallback = function(message) {
const body = message.body;
console.log(
`${Date.now()}: Endpoint ${body.macAddress} has had an ${
body.status
} ANC event.`
);
pxclient
.getAncEndpointByMac(body.macAddress)
.then(endpoint => console.log('Endpoint ANC Policies:', endpoint, '\n\n'));
};
function connect() {
retryInterval = 5 * 1000;
pxclient
.connect({ debug: true })
.then(session => pxclient.subscribeToAncPolicies(session, ancCallback))
.catch(error => {
if (error.toString().includes('None of the provided hosts responded')) {
console.log(error);
console.log(
`${Date(
Date.now()
).toString()}: Failed to connect to nodes, trying again in ${retryInterval /
1000} seconds`
);
setTimeout(connect, retryInterval);
}
});
}
connect();