Skip to content

ANMS API Examples

Brian Sipos edited this page May 13, 2025 · 6 revisions

This set of examples exercises the internal-to-host unsecured REST API to send commands to specific managed Agents and then uses the PGSQL interface to query into the contents of reported data from those Agents.

Send Command to Create Reporting Rule

This page maintains a user-side utility amp_command.py to sequence access to the REST API in order to encode a specific execution of a control to create a time-based rule (TBR) which itself has an action to produce a report for desired telemetry.

The utility can be run from the factory-default ANMS test environment with the following command. This will create a TBR that starts immediately, executes its action every 60 seconds, and stops after 100 cycles. The action generates a single report based on the bp_agent ADM full_report report template (RPTT). The utility will also wait for a single report to be received from the Agent with the --wait-report option but that is not necessary for the successful creation of the TBR.

python3 amp_command.py --log-level=debug --mgrapi http://localhost:5555/ --agent 'ipn:2.6' --wait-report=1 'ari:/IANA:amp_agent/CTRL.add_tbr(ari:/tbr.rpt-bp-agent,TV.0,TV.60,UVAST.100,[ari:/IANA:amp_agent/CTRL.gen_rpts([ari:/IANA:bp_agent/RPTT.full_report],["ipn:1.7"])],"rpt-bp-agent")'

Observe Time-series Reported Telemetry

The telemetry data warehouse is kept within a PostgreSQL database and can be accessed using the SQL schema (including read-only views) defined by the AMP Manager within the ANMS.

A client connection needs to be first made into the ANMS database using a shell command similar to the following, using factory default account name.

psql -h localhost -U root amp_core

Within the SQL client session a "show all" query can be made for reports from that above-commanded agent "ipn:2.6" as the following.

SELECT
  time,
  "ADM",
  "Report Name",
  "Report ID",
  "String Values",
  "UINT Values",
  "INT Values",
  "UVAST Values",
  "VAST Values"
FROM
  vw_rpt_entries
WHERE
  "Agent ID" = 'ipn:2.6'
;

A more narrow query based on exactly the report template from the earlier commanding and reading only the UVAST counter values is the following.

SELECT
  time,
  "Report ID",
  "UVAST Values"
FROM
  vw_rpt_entries
WHERE
  "Agent ID" = 'ipn:2.6'
  AND "ADM" = 'bp_agent'
  AND "Report Name" = 'full_report'
;
The output of this query looks like the following (depending on specific report contents), where the view used here joins together all of the UVAST counters from each report using comma separators.
    time    | Report ID |                                         UVAST Values                                          
------------+-----------+-----------------------------------------------------------------------------------------------
 1732628535 |    252081 | 1000000400000,0,0,0,0,0,0,0,0,0,0,0,0,21,0,0,3828,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,4083
 1732628536 |    252084 | 1000000400000,0,0,0,0,0,0,0,0,0,0,0,0,22,0,0,4020,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,25,4275
...
The items of the report correspond with the report template documented in the bp_agent.json ADM file.

Clone this wiki locally