SSH Data Source
The SSH data source executes commands on remote systems over SSH and captures the command output as Mango data point values. Each data point defines a query command that runs on every poll cycle, and optionally a set command that executes when a value is written to the point. This data source supports all Mango data types (Binary, Multistate, Numeric, and Alphanumeric), with automatic type conversion applied to the command output.
The SSH data source is useful for monitoring remote Linux/Unix servers, reading sensor values from embedded devices accessible via SSH, controlling equipment through command-line interfaces, and collecting metrics from systems that expose data only through shell commands.
Overview
| Property | Value |
|---|---|
| Module | mangoAutomation-Ssh |
| Protocol | SSH |
| Direction | Polling |
| Typical Use | Executing remote commands and collecting output via SSH |
Prerequisites
- SSH access to the remote host. The remote system must be running an SSH server (such as OpenSSH or Dropbear).
- Authentication credentials -- either password-based or public key-based authentication.
- Knowledge of the commands to execute on the remote system and the format of their output.
- Network connectivity between the Mango server and the remote host on the SSH port (default: 22).
Setting Up Public Key Authentication
Public key authentication is recommended for unattended operation because it eliminates the need to store passwords.
Linux/OpenSSH example:
- Log in to the Mango server.
- Generate an RSA key pair (do not enter a passphrase):
ssh-keygen -t rsa - Copy the generated public key to the remote server:
scp ~/.ssh/id_rsa.pub user@remotehost:.ssh/authorized_mango_keys - Log in to the remote server and append the public key to the authorized keys file:
cat ~/.ssh/authorized_mango_keys >> ~/.ssh/authorized_keys - Set correct permissions on all SSH files:
chmod 600 ~/.ssh/authorized_keys ~/.ssh/authorized_mango_keys
The default location for authorized keys varies by SSH server implementation:
- OpenSSH:
/root/.ssh/authorized_keys(or~/.ssh/authorized_keysfor non-root users) - Dropbear:
/home/root/.ssh/authorized_keys
To change the passphrase on an existing key, use ssh-keygen -p.
Configuration
Data Source Settings
| Setting | Description |
|---|---|
| Name | A descriptive name for the data source. |
| Host | The IP address or hostname of the remote SSH server. |
| Port | The SSH port number (default: 22). |
| Username | The SSH login username. |
| Password | The SSH password (if using password authentication). |
| Update period | How frequently the data source polls the remote system by executing query commands. |
| Timeout | Maximum time to wait for a response from the SSH server. |
Data Point Configuration
| Setting | Description |
|---|---|
| Device Name | The device name for organizational purposes. |
| Name | The display name of the data point. |
| XID | A unique identifier for the data point. |
| Data type | The Mango data type. Determines how the command output is interpreted (see below). |
| Queryable | When checked, the Query Command is issued every poll cycle and the response is captured as the point value. |
| Query Command | The shell command to execute on the remote system. The output is parsed according to the data type. |
| Settable | When checked, the point can be written to, which triggers execution of the Set Command. |
| Set Command | The shell command to execute when a value is written to this point. Every occurrence of the string VALUE (all capitals) in the command is replaced with the value being set. |
Data Type Conversion
| Data Type | Expected Output | Conversion Behavior |
|---|---|---|
| Binary | Any text | Output starting with 0 or yielding no response is treated as false. All other output is true. Setting false sends 0; setting true sends 1. |
| Multistate | An integer | The response must be a single integer value. |
| Numeric | A floating-point number | The response must be a single double-precision number. |
| Alphanumeric | Any text | The full response text is captured as the point value. |
Multiple Commands and Delays
Both query and set commands support executing multiple commands in sequence within the same SSH channel:
- Linux/Unix: Delimit commands with
;(e.g.,command1; command2; command3;) - Windows: Delimit commands with
&(e.g.,command1 & command2 & command3)
This is particularly important for set commands, where a delay may be needed between setting a value and querying the result:
program set-value VALUE; sleep 0.2s; program read-value;
The delay (using sleep or equivalent) ensures the controlled device has time to process the set command before the query command reads the new state.
Because the query string is also used in the set channel to read back the new value, it is best practice to end set commands with the OS-specific delimiter (; for Linux, & for Windows), even if there is only one set command. If the point is not queryable, this is not strictly necessary, but it is a good habit.
Common Patterns
Monitoring Remote Server Metrics
Create points to read CPU temperature, disk usage, memory utilization, or process counts from a remote Linux server:
| Metric | Example Query Command |
|---|---|
| CPU temperature | cat /sys/class/thermal/thermal_zone0/temp |
| Disk usage (%) | df / --output=pcent | tail -1 | tr -d ' %' |
| Available memory (MB) | free -m | awk '/Mem:/ {print $7}' |
| Process count | ps aux | wc -l |
Reading Embedded Device Sensors
Many embedded devices (Raspberry Pi, BeagleBone, industrial edge devices) expose sensor data through system files or command-line utilities. The SSH data source can read these values without installing any additional software on the device.
Remote Equipment Control
Use settable points to control equipment on a remote system. For example, to toggle a GPIO pin on a Raspberry Pi:
- Set Command:
echo VALUE > /sys/class/gpio/gpio18/value; sleep 0.1s; - Query Command:
cat /sys/class/gpio/gpio18/value
Network Device Monitoring
SSH into network switches, routers, or firewalls to read interface statistics, routing table entries, or device status. Many network devices provide SSH access with proprietary CLI commands.
Troubleshooting
Connection Refused
- Verify the remote host is running an SSH server and listening on the configured port.
- Check for firewall rules blocking SSH traffic between the Mango server and the remote host.
- Confirm the hostname or IP address is correct and reachable from the Mango server.
Authentication Failures
- Password auth: Verify the username and password are correct. Some SSH servers disable password authentication by default.
- Public key auth: Ensure the public key is correctly appended to the remote server's
authorized_keysfile and that file permissions are set to 600. - Check that the SSH key was generated without a passphrase. Mango cannot interactively enter a passphrase.
Wrong or Missing Values
- Command output format -- if the query command returns extra text (headers, labels, whitespace), the data type conversion will fail. Use shell utilities like
awk,grep,tr, orcutto extract only the numeric or text value. - Binary points returning false -- remember that any output starting with
0is treated as false. If the command returns0.5, the binary conversion sees the leading0and returns false. - Multistate points failing -- ensure the command output is a clean integer with no extra characters or whitespace.
Stale Values After Set
If the query command immediately after a set returns the old value, the remote device may need time to process the change. Add a sleep command between the set and query commands in the set command string.
Connection Drops
Long-running SSH connections may be terminated by firewalls or SSH server idle timeouts. If the data source shows intermittent connection errors, check the SSH server's ClientAliveInterval and ClientAliveCountMax settings, and any firewall rules that expire idle TCP connections.
Related Pages
- Data Sources Overview — General data source and data point concepts
- Serial Data Source — General-purpose serial port communication for local device connections
- TCP/IP Data Source — General-purpose TCP/IP socket communication for custom protocols
- Vmstat Data Source — Monitor local system performance metrics without SSH