Creating an agent from an existing script using the REST API

Instructions and examples in this document use an IP address that is reserved for documentation, 192.0.2.5, as an example of the IP address for the switch. To access your switch, you must use the IP address or hostname of that switch.

Prerequisites
  • You must be logged in to the switch REST API with a user name that has administrator rights.

  • The switch REST API access mode must be read-write.

  • The script you will use to create the agent must be in a VALIDATED state.

Procedure
Use the POST method on the URI of the nae_agents collection of the script. In the request body, provide the required information in JSON format.

This example creates an agent with the following characteristics:

  • The name of the agent is: com.myco.bgp_mon.Agent1

  • The name of the script is: com.myco.bgp_mon

  • The agent is created in a disabled state ("disabled":true).

  • The threshold parameter of the script is set to the value 10.

POST https://192.0.2.5/rest/v1/system/nae_scripts/com.myco.bgp_mon/nae_agents
{
    "name": "com.myco.bgp_mon.Agent1",
    "disabled":true,
    "parameters_values":{
             "threshold":"10"
     }
}
  • Agents must have a unique name. If an agent that has the same name exists, the request fails with response code 400 and the message:

    NAE agent <agent_name> exists already

  • If you supply a parameter value that is not the expected type for that parameter, the request fails with response code 400 and the message:

    Value type mismatch for the parameter <parameter_name>

  • If the JSON request body does not include a parameter, but the script defines a default value for that parameter, the default value is used.

    If the JSON request body does not include a parameter that is required by the script, and the script does not define a default for that parameter, the agent is created, but the agent has the following error message:

    The NAE Agent has Python errors. Please check hpe-policyd logs for Python errors.