Skip to content

SSH

D.device.sendSSHCommand runs a single command over SSH. D.device.sendSSHCommands runs a sequence in one session — useful for devices that require a shell context (entering enable mode, chaining commands that depend on each other).

D.device.sendSSHCommand({
command: 'uptime',
timeout: 5000
}, function (output, error) {
if (error) return D.failure(D.errorType.RESOURCE_UNAVAILABLE);
console.log(output);
});

The callback is (output, error). output is the full stdout as a string.

D.device.sendSSHCommands({
commands: [
'enable',
'show version',
'exit'
],
prompt: '#',
inter_command_timeout_ms: 1000,
global_timeout_ms: 30000
}, function (outputs, error) {
if (error) return D.failure(D.errorType.RESOURCE_UNAVAILABLE);
var version = outputs[1];
// ...
});

outputs is an array in the same order as commands. Each entry is the string the device emitted between two prompts.

D.device.sendSSHCommand({
command: 'uptime', // required
timeout: 5000, // ms; default varies by device
username: 'admin', // overrides D.device.username()
password: 'secret', // overrides D.device.password()
keyboard_interactive: false, // enable if primary auth fails and device wants keyboard-interactive
port: 22, // SSH port
algorithms: { // override cipher / kex lists for old devices
kex: ['diffie-hellman-group14-sha1'],
cipher: ['aes128-ctr']
}
});

D.device.sendSSHCommands supports the same auth/port/algorithms plus:

{
commands: [...], // required
prompt: '#', // exact string after which the device is ready for the next command
prompt_regex: undefined, // use instead of prompt if the prompt changes between commands
error_prompt: undefined, // if this string shows up, stop the sequence with an error
inter_command_timeout_ms: 1000, // wait between commands
global_timeout_ms: 30000 // total wall clock for the whole sequence
}

The shell-sequence mode watches stdout for prompt (or prompt_regex) to decide when a command finished. Pick a prompt that is:

  • Unique. If > shows up inside command output, the runner will misfire.
  • Stable. Device prompts that change after enable need prompt_regex: '(?:>|#)\\s?$'.
  • Anchored. Trailing whitespace and end-of-line are your friends.

If your sequence needs a different prompt after a mode change, set prompt_regex to a pattern that matches either.

Default: uses the Custom Driver Management username/password configured in the Domotz portal (D.device.username() / D.device.password()).

Per-call override: pass username and password explicitly. Useful when one driver needs to talk with an admin account for a specific command and a read-only account otherwise.

Public-key auth is not exposed to custom drivers — password-based auth only.

Many switches and firewalls still require old KEX / ciphers. If the default connect fails, override:

D.device.sendSSHCommand({
command: 'show version',
algorithms: {
kex: [
'diffie-hellman-group1-sha1',
'diffie-hellman-group14-sha1'
],
cipher: [
'3des-cbc',
'aes128-cbc'
]
}
}, callback);

See SshAlgorithms for the full shape.

D.device.sendSSHCommand({ command: 'uptime' }, function (output, error) {
if (error) {
if (error.code === 'AUTHENTICATION_FAILED') {
return D.failure(D.errorType.AUTHENTICATION_ERROR);
}
if (error.code === 'TIMEOUT_ERROR') {
return D.failure(D.errorType.TIMEOUT_ERROR);
}
return D.failure(D.errorType.RESOURCE_UNAVAILABLE);
}
// output is ready
});

The exact error.code values are listed in D.errorType.

Command output tends to be free-form. Prefer regex on anchored markers to brittle column splits:

// uptime: "12:34:56 up 7 days, 3:42, 1 user, load average: 0.05, 0.10, 0.12"
var m = output.match(/load average:\s+([\d.]+)/);
var loadMin1 = m ? parseFloat(m[1]) : null;

For JSON over SSH (e.g. ip -j link on Linux), JSON.parse(output) in a try/catch with D.failure(D.errorType.PARSING_ERROR) on throw.