device

D. Namespace

device

Description:
  • The Domotz Device object. Exposes device related libraries for http, ssh, tcp, telnet remote call executions. Contains device information such as its Custom Driver Management credentials and IP address
Example
D.device

Namespaces

http
scp
snmpSession
tftpClient

Methods

(static) createSNMPSession(options) → {D.device.snmpSession}

Description:
  • Starts an SNMP session with the device.
Example
// returns an snmpSession object to use for snmp related queries
D.device.createSNMPSession()
See SNMP Driver Examples
Parameters:
Name Type Description
options Object The SNMP Session Options
Properties
Name Type Attributes Default Description
port integer <optional>
161 UDP port to send requests to
timeout integer <optional>
5000 The time the snmp session queries will persist for (in milisenconds).
maxRepetitions integer <optional>
24 How many rows of a table are to be retrieved in a single GetBulk operation. Used in SNMP Walk
Returns:
Type
D.device.snmpSession

(static) ip() → {string}

Description:
  • Returns the IP address of the device object.
Example
// returns '192.168.1.1' for a device with this local IP address
D.device.ip()
Returns:
Type
string

(static) macAddress() → {string}

Description:
  • Returns the MAC address of the device object.
Example
// returns '00:11:22:33:44:AA' for a device
D.device.macAddress()
Returns:
Type
string

(static) password() → {string}

Description:
  • Returns the stored password of a device.
Example
// returns 'the device password'
D.device.password()
Returns:
Type
string

(static) ping(pingOptions, callback)

Description:
  • Executes a ping operation to the device's IP address.
Example
D.device.ping({ count: 5, interval: 100 }, function (result, error) {
    if (error) {
        console.error('Ping failed:', error);
    } else {
        console.log('Ping result:', result.avg);
    }
});
Parameters:
Name Type Description
pingOptions object The options for the ping operation.
Properties
Name Type Attributes Default Description
count number <optional>
10 The number of ICMP requests to send.
interval number <optional>
100 The interval (in ms) between ICMP requests.
timeout number <optional>
1000 The timeout (in ms) for each ICMP request.
packet_size number <optional>
16 The size of the ICMP packet in bytes.
ttl number <optional>
64 The Time-To-Live (TTL) value for the ICMP packets.
callback function The callback function to handle the ping result.
Properties
Name Type Attributes Description
result object | null <optional>
The result of the ping operation, or `null` if an error occurred. Contains the following fields:
Properties
Name Type Description
jitter number The jitter in milliseconds.
avg number The average latency in milliseconds.
packet_loss number The packet loss percentage.
min number The minimum latency in milliseconds.
max number The maximum latency in milliseconds.
std number The standard deviation of latency in milliseconds.
samples array The raw samples, in milliseconds.
error Error | null <optional>
The error object if the ping operation failed, or `null` if successful.

(static) sendSSHCommand(options, callback)

Description:
  • Sends a command to the device via SSH.
Examples
D.device.sendSSHCommand(options, callback)
See SSH Driver Examples
Parameters:
Name Type Description
options Object The SSH Command execution options
Properties
Name Type Attributes Default Description
command string The ssh command to execute against the device
timeout int <optional>
The time to wait for the command execution
username string <optional>
The device username. If not set the custom driver management purpose one is used
password string <optional>
The device password. If not set the custom driver management purpose one is used
keyboard_interactive boolean <optional>
false Try keyboard-interactive user authentication if primary user authentication method fails
port string <optional>
22 The SSH port
algorithms SshAlgorithms <optional>
The SSH Kex and Ciphers to use * @example // Some available cipher and kex
callback function The SSH Command execution callback function
Properties
Name Type Attributes Description
output string The stdout from the SSH Command execution
error ErrorResult <optional>
Will be present if the execution resulted in an error

(static) sendSSHCommands(options, callback)

Description:
  • Sends a sequence of commands to the device via SSH.
Example
D.device.sendSSHCommands(options, callback)
Parameters:
Name Type Description
options Object The SSH Commands execution options
Properties
Name Type Attributes Default Description
commands Array.<string> The ssh commands to execute against the device
username string <optional>
The device username. If not set the custom driver management purpose one is used
password string <optional>
The device password. If not set the custom driver management purpose one is used
keyboard_interactive boolean <optional>
false Try keyboard-interactive user authentication if primary user authentication method fails*
prompt string <optional>
# The device ssh prompt expected. If not set correctly it may result in a timeout
prompt_regex string <optional>
The device ssh prompt regular expression expected. Used if a device prompt changes during ssh sequence execution
error_prompt string <optional>
The device error prompt expected. Used when there is an expected error prompt string to halt the execution
inter_command_timeout_ms int <optional>
1000 Timeout to wait between ssh sequence commands executions
global_timeout_ms int <optional>
30000 The global ssh shell sequence execution timeout. When expired results in TIMEOUT_ERROR
port string <optional>
22 The SSH port
algorithms SshAlgorithms <optional>
The SSH Kex and Ciphers to use
callback function The SSH Commands execution callback function
Properties
Name Type Attributes Description
outputs Array.<string> The output list of the SSH Commands executions
error ErrorResult <optional>
Will be present if the execution resulted in an error

(static) sendTCPCommand(options, callback)

Description:
  • Sends a command to the device via TCP.
Example
D.device.sendTCPCommand(options, callback)
See TCP Driver Examples
Parameters:
Name Type Description
options Object The TCP Command execution options
Properties
Name Type Attributes Default Description
command string The tcp command to execute against the device
port int <optional>
23 The tcp port to connect to
timeout int <optional>
500 The time the tcp command will execute for at most (in milliseconds)
keepAlive boolean <optional>
false Boolean flag to use if the TCP connection should persist until the timeout value runs out. Disabled by default
encoding str <optional>
utf8 The tcp command response encoding. Default 'utf8'
callback function The TCP Command execution callback function
Properties
Name Type Attributes Description
output string The Result from the tcp command execution
error ErrorResult <optional>
Will be present if the execution resulted in an error

(static) sendTelnetCommand(options, callback)

Description:
  • Sends a command to the device via Telnet.
Example
D.device.sendTelnetCommand(options, callback)
See Telnet Driver Examples
Parameters:
Name Type Description
options Object The Telnet Command execution options
Properties
Name Type Attributes Default Description
command string The telnet command to execute against the device
port int <optional>
23 The telnet port to connect to
timeout int <optional>
500 The time the telnet session will persist for (in milisenconds)
negotiationMandatory boolean <optional>
false Set this to true if the telnet session requires authentication
shellPrompt string <optional>
/(?:\/ )?#\s/ The expected shell prompt regular expression for the telnet session
loginPrompt string <optional>
/login[: ]*$/i The expected username prompt regular expression for the telnet session
passwordPrompt string <optional>
/Password: /i The expected password prompt regular expression for the telnet session
callback function The Telnet Command execution callback function
Properties
Name Type Attributes Description
output string The Result from the telnet command execution
error ErrorResult <optional>
Will be present if the execution resulted in an error

(static) sendWinRMCommand(options, callback)

Description:
Examples
D.device.sendWinRMCommand(options, callback)
See WinRM Driver Examples
Parameters:
Name Type Description
options Object The WinRM Command execution options
Properties
Name Type Attributes Default Description
command string The winrm command to execute against the device
username string <optional>
The device username. If not set the custom driver management purpose one is used
password string <optional>
The device password. If not set the custom driver management purpose one is used
port string <optional>
5985 The WinRM port
callback callback The WinRM Command execution callback function
Properties
Name Type Attributes Description
output Object <optional>
Output of the execution, present if no error has occurred
Properties
Name Type Attributes Description
commandId string Id of the WinRM command
shellId string Id of the remote shell that executed the command
stdout string standard output produced by the command
stderr string <optional>
standard error produced by the command (should always be null)
error Object <optional>
Will be present if the execution resulted in an error
Properties
Name Type Attributes Description
code Number <optional>
The error code coming from WinRM command
message string <optional>
The error message
exitCode int <optional>
exit code of the command (should always be 0)

(static) serial() → {string}

Description:
  • Returns the serial number of the device object.
Example
// returns 'serial_number' for a device
D.device.serial()
Returns:
Type
string

(static) username() → {string}

Description:
  • Returns stored username of a device.
Example
// returns 'the device username'
D.device.username()
Returns:
Type
string