Generating the Multi-Command File
Generate multiCommandTemplate.sh automatically with the fetch_agent_details_and_create_amt_commands.py utility instead of building command rows by hand.
Generating the Multi-Command File#
When you need to fetch configuration files from many Component Agents at once, building the multi-command file by hand is slow and error-prone: every row needs the host address, the supervisor identifier and the agent's physical agent identifier, all looked up from the database and typed in without a mistake.
The fetch_agent_details_and_create_amt_commands.py utility does that lookup for you. It reads the agent topology straight from the appsone schema and writes a ready-to-run FetchFile command file, skipping any host whose agent mapping is ambiguous.
It produces three files:
| File | What it is |
|---|---|
multiCommandTemplate.sh |
The command file you hand to the Agent Maintenance Tool — one FetchFile row per qualifying host. |
agent_identifiers.csv |
A reference list of the supervisor, Component Agent and physical agent identifiers for each qualifying host. |
fetch_agent_details_and_create_amt_commands.log |
The run log, including one line per host that was skipped and why. |
Note: This utility only generates the command file. Running it is a separate step — see Agent Configuration for the command file format and the
-fileinvocation.
Before you begin#
- Python 3.6 or later.
- Network access from the machine running the script to the MySQL server (host and port).
- A MySQL account with read access to the
appsoneschema — specifically thesupervisor_details,agentandphysical_agenttables. - The
pymysqlpackage, which is supplied with the script. See below.
Note: Do not run
pip install pymysqlon the HEAL server. Installing or upgrading packages there risks disrupting the existing Python environment. The dependency is shipped with the utility precisely so that no installation step is needed.
The utility ships pymysql in a deps folder alongside the script. At start-up it first checks whether pymysql is already available in the server's Python environment, and if it is not, loads it from deps instead. As long as deps stays next to the script, no installation is required.
Setting up the script folder#
The dependency is delivered as a compressed archive. Extract it so that deps sits beside the script, not inside another folder:
unzip deps.zip
The resulting layout must look like this:
Fetch_Agent_Details_And_Create_AMT_Commands/
|-- fetch_agent_details_and_create_amt_commands.py
`-- deps/
`-- pymysql/
Run the script from inside that folder. All three output files are written to the current working directory.
Running the script#
python3 fetch_agent_details_and_create_amt_commands.py --files-to-fetch <file1>,<file2>,...
The --files-to-fetch argument is mandatory and accepts only the following four values:
| Value | Written to the command file as |
|---|---|
agent-details.json |
config/agent-details.json |
basic.properties |
config/basic.properties |
advanced.properties |
config/advanced.properties |
version.txt |
version.txt (no config/ prefix) |
You can supply one, several or all four values. Extra spaces are trimmed, duplicates are removed, and the order you type them in is preserved exactly in the generated config_file1=, config_file2= entries. Any value outside the list of four is rejected and nothing is written.
For example:
python3 fetch_agent_details_and_create_amt_commands.py \
--files-to-fetch basic.properties,advanced.properties,agent-details.json,version.txt
The argument is validated first. If it is invalid or empty, the script exits immediately and no database connection is attempted.
You are then prompted for the database connection details:
- MySQL host or IP
- MySQL port
- MySQL username
- MySQL password — hidden as you type, and not echoed to the screen
The schema is not prompted for; the utility always connects to appsone.
How the script runs#
Each run follows the same sequence. Validation happens before any database work, so a bad argument or an unreachable database costs you nothing.
- Validate
--files-to-fetch— if any value is outside the four permitted names, or the list is empty, the script reports the error and exits. No connection is attempted. - Prompt for the database details — host, port, username and password. The password is hidden as you type.
- Validate the port — a non-numeric value is rejected and the script exits.
- Connect to MySQL using the
appsoneschema. A failed connection is logged and the script exits cleanly rather than raising a stack trace. - Query the topology —
supervisor_details, thenagent(Component Agents only), thenphysical_agent. - Evaluate every host against the mapping rules below, sorting each into either the clean list or a skip reason.
- Write the output files —
agent_identifiers.csv,multiCommandTemplate.sh, and the run log. - Print a summary — totals, the files written, and the breakdown of skipped hosts.
The diagram below shows the same flow, including every decision point and where each skip reason is raised.

Which hosts are included#
A host appears in both output files only if all of the following are true. Any host that fails a check is excluded from both files and recorded in the log with the reason, so the underlying mapping can be corrected.
| Condition | If not met |
|---|---|
The host has an entry in supervisor_details |
The host is not considered at all — this is the starting point. |
| The host has exactly one Component Agent mapped to it | Skipped, and logged as no_component_agent (none mapped) or multiple_component_agents (more than one mapped, with the conflicting identifiers listed). |
| That Component Agent has a resolvable physical agent identifier | Skipped, and logged as no_physical_identifier. |
Note: A host mapped to more than one Component Agent is a data-quality problem rather than a script limitation — the Agent Maintenance Tool expects exactly one agent per host. Ask the administrator who owns the agent-to-host mapping to correct it, then re-run. See Agent Maintenance Tool Issues.
Output files#
agent_identifiers.csv contains one row per qualifying host:
| Column | Source |
|---|---|
supervisor_identifier |
supervisor_details.identifier |
host_address |
supervisor_details.host_address |
component_agent_identifier |
The Component Agent's unique_token from the agent table |
component_agent_physical_identifier |
The linked physical_agent.identifier |
multiCommandTemplate.sh uses the standard multi-command format described in Agent Configuration. The utility fills the columns as follows:
| Column | Value |
|---|---|
HostIP |
The host address |
supervisorID |
The supervisor identifier |
agentId |
The Component Agent's physical agent identifier — not its own unique_token |
userDetailId |
Fixed value 7640123a-fbde-4fe5-9812-581cd1e3a9c1 |
agentType |
ComponentAgent |
command |
FetchFile |
commandType |
MaintenanceCmds |
metadata |
Built from --files-to-fetch, for example config_file1=config/basic.properties;config_file2=version.txt |
Args |
Always blank |
commandTimeout |
3000 |
Example run#
python3 fetch_agent_details_and_create_amt_commands.py \
--files-to-fetch agent-details.json,basic.properties,version.txt
Expected output:
INFO: files_to_fetch = ['agent-details.json', 'basic.properties', 'version.txt']
INFO: Using schema: appsone
INFO: Supervisor/host summary: total=5 clean=3 skipped=2 (no_component_agent=1, multiple_component_agents=1, no_physical_identifier=0)
WARNING: SKIPPED (no ComponentAgent mapped): supervisor='sup-a1' host='192.0.2.31'
WARNING: SKIPPED (multiple ComponentAgents mapped): supervisor='sup-b2' host='192.0.2.42' component_agents=['ca-b2-alpha', 'ca-b2-beta']
INFO: Wrote 3 row(s) to agent_identifiers.csv
INFO: Wrote 3 command row(s) to multiCommandTemplate.sh
INFO: SUMMARY: 5 host(s) processed, 3 clean host(s) written, 2 host(s) skipped.
A generated command row looks like this:
#HostIP,supervisorID,agentId,userDetailId,agentType,command,commandType,metadata,Args,commandTimeout
192.0.2.119,2cce6952-c5ad-4460-989e-0bec0a66f581,ca-119-physical,7640123a-fbde-4fe5-9812-581cd1e3a9c1,ComponentAgent,FetchFile,MaintenanceCmds,config_file1=config/agent-details.json;config_file2=config/basic.properties;config_file3=version.txt,,3000
The utility is safe to re-run at any time. It re-reads current data from the database and overwrites all three output files on every run; it never appends to a previous run.
Handing off to the Agent Maintenance Tool#
Once you are satisfied with the generated file:
1. Back up the multi-command template file already present in the tool's config folder, so you can roll back if needed.
cd <base_dir>/<agent-maintenance-tool>/config
cp multiCommandTemplate.sh multiCommandTemplate.sh.bak_$(date +%Y%m%d_%H%M%S)
2. Copy the newly generated file into that config folder, replacing the existing one.
3. Confirm the tool's conf.properties is correctly filled in — in particular the RabbitMQ host and port and the output directory. See Agent Maintenance Tool: Introduction.
4. Run the tool against the new command file from its home directory, as described in Agent Configuration:
./agent-maintenance-tool.sh -file config/multiCommandTemplate.sh
Tip: Keep the backup from step 1 until you have confirmed the run completed successfully.
Troubleshooting#
For the error messages this utility can report, and how to resolve them, see Multi-Command File Generation Errors in Agent Maintenance Tool Issues.
See also: Agent Maintenance Tool: Command Structure · Agent Maintenance Tool: Agent File · Agent Maintenance Tool Issues