-
Notifications
You must be signed in to change notification settings - Fork 30
/
4-custom-messages.js
66 lines (54 loc) · 1.8 KB
/
4-custom-messages.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
//
// Copyright (c) 2018 Cisco Systems
// Licensed under the MIT License
//
/**
* Modify some of your device's configuration settings
* In this example, we'll change the Halfwake and Awake messages
*/
//
// Connect to the device
//
const jsxapi = require('jsxapi');
// Check args
if (!process.env.JSXAPI_DEVICE_URL || !process.env.JSXAPI_USERNAME) {
console.info("Please specify info to connect to your device as JSXAPI_DEVICE_URL, JSXAPI_USERNAME, JSXAPI_PASSWORD env variables");
console.info("Bash example: JSXAPI_DEVICE_URL='ssh://192.168.1.34' JSXAPI_USERNAME='integrator' JSXAPI_PASSWORD='integrator' node example.js");
process.exit(1);
}
// Empty passwords are supported
const password = process.env.JSXAPI_PASSWORD ? process.env.JSXAPI_PASSWORD : "";
// Connect to the device
console.log("connecting to your device...");
const xapi = jsxapi.connect(process.env.JSXAPI_DEVICE_URL, {
username: process.env.JSXAPI_USERNAME,
password: password
});
xapi.on('error', (err) => {
console.error(`connexion failed: ${err}, exiting`);
process.exit(1);
});
//
// Custom logic
//
xapi.on('ready', () => {
console.log("connexion successful");
// Update Halfwake message
xapi.config.set('UserInterface OSD HalfwakeMessage', "I am API addict")
.then(() => {
console.info('updated HalfwakeMessage')
})
.catch((err) => {
console.error(`could not update Halfwake message : ${err.message}`)
});
// Update Awake message
xapi.config.set('UserInterface CustomMessage', "I am G33K")
.then(() => {
console.log('updated Awake message')
// Ending script
xapi.close();
})
.catch((err) => {
console.error(`could not update Awake message : ${err.message}`)
});
});