Public API examples

Change password for all monitored storage devices in a script

This script is a Node.js utility designed to update SSH passwords for specific host configurations using public API. It interacts with a REST API to authenticate, retrieve host configurations, and update the SSH passwords for entries that match certain criteria. The script also provides an interactive prompt for user confirmation before updating each password.

Detailed Workflow
Command-Line Arguments, the script expects four arguments:
  • username: The username for authentication.
  • password: The password for authentication.
  • sshUsername: The SSH username to filter host configurations.
  • sshPassword: The new SSH password to set for matching configurations.
Authentication:
The script sends a POST request to the server's /api/public/v1/auth endpoint to authenticate using the provided username and password.
Upon successful authentication, it retrieves an API key.

Fetching Host Configurations:
The script sends a GET request to the /api/public/v1/hostcfg endpoint to fetch host configurations of the storage class.
It filters the configurations to include only entries that:
Match the provided SSH username.

Interactive Password Update:
For each filtered host configuration:
The script prompts the user to confirm whether they want to update the password for the specific entry.
If the user confirms (y), the script updates the sshPassword field with the new password
If the user declines (n), the script skips the entry.

Usage
Run the script with the following command:
node ./password_change.js <username> <password> <sshUsername> <sshPassword>
Example:
node ./password_change.js xormon xormon sshUser newPassword123
Download password_change.js.gz