Get started
An updating or monitoring campaign over a set of remote edge devices can be defined in a simple way as a set of operations that must be performed in a specific sequence and based on a decision flow. The operations involved in such campaign can be of many different types and depend on some conditions that must be verified before proceeding with the actual execution.
For example, the feasibility of performing an update of a operating system package, could depend on the check for sufficient disk space and the actual presence of the specific outdated version of the package on the target device.
IoT Catalyst allows the creation of even very complex workflows that can satisfy the scenario mentioned above. These workflows are named Automation Campaigns
The Automation Service is an IoT Catalyst add-on which allows to automate device management tasks over multiple Agents available in the IoT Catalyst domain. A typical use case can be updating the OS version of thousands of devices simultaneously.
IoT Catalyst Studio offers a graphical user interface which makes very easy the following operations:
- create and monitor the execution of Automation Campaigns over multiple target devices.
- create Automation Campaigns campaigns which will execute either immediately or postponed in time (specifying hours and/or minutes).
- manage Automation Campaigns schedule to repeatedly execute a campaign, either specifying hours/minutes, or by using a crontab-like format.
- alter the execution status of an Automation Campaign via various buttons which allow to pause/abort a campaign, unschedule its execution, or to launch again a finished campaign by cloning it.
- parallelize the execution of an Automation Campaign by splitting it into multiple subjobs: for example, a campaign over 10 targets can be splitted across 10 subjobs (so that every subjob will manage the whole campaign execution for a single target).
- observe the execution of a Automation Campaign in any detail.
The creation of a campaign involves the definition of one or more tasks, whose aim is to group many commands of the same kind:
Command Type | Description |
---|---|
API | it is a HTTP call to an IoT Catalyst API method. This is the only type of command which is directly executed by the Automation Service. The other kinds of commands (see below) will be taken in charge by an IoT Catalyst Agent.. |
Hypervisor | it is a command used to Start/Stop/Update an IoT Catalyst Hypervisor |
SHELL | It is an architecture-specific shell command. Examples of valid commands are 'sudo apt update', or 'df -h': basically anything that can be executed through a shell interface. |
METRIC | it's a special case of a SHELL command. Whenever an IoT Catalyst Agent executes a METRIC command, the command result is published on an MQTT topic and the value is periodically updated.
METRIC commands also allow users to specify conditional execution paths inside a campaign. For example, let's say you want to upgrade your Linux distribution only if there is enough disk space: you can define a METRIC task to check the overall storage availability, and subsequently a SHELL task (containing the commands to update your OS) which will execute based on the result of the previous task. |
At any point in time, a campaign will be in one of the following statuses:
Status | Description |
---|---|
NEVER_RUN | The campaign has been defined but has not started yet. |
RUNNING | The campaign has been launched but has not terminated yet |
PAUSED | The campaign execution has been paused (either by an error on a target or by an outside request) and will remain in this state until the user requires to resume it |
ABORTED | The campaign execution terminated before its time due to an outside request |
EXITED_OK | The campaign execution completed successfully on all target devices |
EXITED_KO | The campaign execution terminated before its time due to an error on a target device |
All the information and methods managed by the Automation Service are easily accessible using the RESTFul API here described.
Invoking the APIs
Once you've set up the frontend, you can use remote HTTP requests to call the API. To do that you need to send HTTP POST requests to the API endpoint file located in the frontend directory. For example, if your IoT Catalyst Studio frontend is installed under HTTPS://{IoTCatalystStudioEndpoint}, the HTTP request to call will look like this:
curl --location --request GET '<AutomationServiceBaseURL>/campaigns/10?schedule=10&page=1&results_per_page=500' \ --header 'Authorization: Bearer <valid IoT Catalyst Studio session token>'
The API makes use of query parameters in order to filter the results or simply in order to choose between id or name as keys in the results. Some endpoints have mandatory request parameters. The parameter "force_refresh", which if "true" would force the refresh of the cache, is always optional and defaults to "false".
Security
Before you can access any data inside of IoT Catalyst Automation Service you'll need to log in and obtain an authentication token. This can be done using the APISecurity.requestToken method.
Once you have obtained a valid IoTCatalyst Session Token, you should use it as a bearer token in your RESTFul API invocations
CURL Invocation Example
curl --location --request GET '<AutomationServiceBaseURL>/campaigns/10?schedule=10&page=1&results_per_page=500' \ --header 'Authorization: Bearer <valid IoT Catalyst Studio session token>'
JAVASCRIPT
const myHeaders = new Headers({
"Authorization": "Bearer <valid IoT Catalyst Studio session token>"
});
const requestOptions = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
fetch("/campaigns/10?schedule=10&page=1&results_per_page=500", requestOptions)
.then(response => response.json())
.then(result => console.log(result))
.catch(error => {
// error handling routine goes here...
});
Response Format
if everything goes well, IoT Catalyst Automation Service API response will contain a valid JSON data.
Here follows an example of JSON data generated by the API GetAllHypervisorsStatuses
{
"data": {
"id_campaign": 10,
"id_schedule": 10,
"summary": {
"id_campaign": 10,
"id_schedule": 10,
"progress": 0.0,
"status": "running",
"n_exited_subjobs": 0,
"start_time": 1679048484,
"end_time": null
},
"targets": [
{
"id_target": 1081,
"id_subjob": 1,
"progress": 0.0,
"status": "running",
"start_time": 1679048484,
"end_time": null,
"tasks": [
{
"name": "task",
"description": "task",
"conditions": [],
"on_error_policy": "exit",
"progress": 0.0,
"status": "running",
"start_time": 1679048484,
"end_time": null,
"commands": [
{
"name": "reboot",
"type": "SHELL",
"command": "sudo reboot",
"causes_reboot": false,
"timeout": 1,
"retries": 0,
"params": {},
"interpreter": "BASH"
}
]
}
]
}
]
},
"message": "",
"info": {
"page": 1,
"results_in_page": 1,
"total_pages": 1,
"total_elements": 1
}
}
Error Handling
Here is the list of possible error codes returned by the Automation Service, with possible explanations:
### 400
Bad request body (on initialization).
### 401
Request with no Authorization header.
### 403
Request forbidden.
### 404
Apart from the obvious bad endpoint, even a correct endpoint can return this code if the Automation Service is not initialized.
When asking for the status / stats of a Hypervisor or Container by id or name, the Automation Service returns this code if the requested entity was not found.
### 409
Automation Service already initialized.
### 422
A problem was encountered when initializing the Automation Service (e.g. bad IoTCatalyst Studio credentials).
This code can also be returned when the Automation Service is not functioning properly and thus cannot process the request.
Campaign's JSON definition
IoT Catalyst Automation Service uses JSON as the standard format for defining a Campaign. The JSON that describes an automation campaign can be very long and apparently complicated, because a campaign can also be very articulated and complex, i.e. organized into many tasks and many execution conditions.
In the upcoming sections, we will describe every single component (Task, Task's Conditions and Task's Commands), that extends the basic structure of the following basic JSON.
{
"name": <campaign's name>,
"description": <campaign's description>,
"target": {
"idComponentType": <id component type>,
"ids": <list of ids>
},
"execution": {
"processes": <number of processes>,
"on_error": <on error>,
"suspendable": <suspendable>,
"abortable": <abortable>
},
"tasks": <list of tasks>
}
Item | Description |
---|---|
<campaign's name> | Unique name of the Campaign. |
<campaign's description> | It is for description purposes. |
<id component type> | Should be set to 5 (Iot Ctaalyst Hypervisor Component Type Constant) |
<List of ids> | It is a list of ids of the intended targets of the campaign (e.g. [1, 2, 3]). As an alternative to the list of ids, it is possible to pass the key “tags”: <tags>, where <tags> is a comma separated sequence of tags (e.g. “tags”: “myTag1,myTag2,myTag3”, interpreted with an AND Boolean logic). |
<number of processes> | <number of processes> is a hint to the Automation Service about the number of processes to use when executing the requested campaign. For instance, if the number of processes is set to 2 and the <list of ids> contains 30 targets, the Automation Service uses 2 concurrent processes to execute the campaign, each of them processing 15 targets. Note: the actual number of processes can vary significantly from the number used in the request (for instance, if only one id is passed in the list of ids, the Automation Service will use one process to execute the campaign, regardless of the value of <number of processes>). |
<on error> | It tells the Automation Service what to do if an error is encountered when executing the command(s), it can be either “exit”, “pause” or “skip”. |
<suspendable> | It tells the Automation Service whether it is possible to pause the job from the outside (see “Pause job”), it can be either “true” or “false”. |
<abortable> | It tells the Automation Service whether it is possible to abort the job from the outside (see “Abort job”), it can be either “true” or “false”. |
<list of tasks> | It is a list containing the tasks to be executed in the campaign. The Automation Service Task has its own JSON definition as described in the next paragraph. |
Task definition
IoT Catalyst Automation Service uses JSON as the standard format for defining a Task. A task is a collection of commands of different types that are executed on a target device. The execution of a Task can be dependent on the result of the runtime evaluation of a list of conditions.
The basic structure of a JSON that defines an IoT Catalyst Automation Service Task is the following:
{
"name": <task name>,
"description": <task description>,
"on_error_policy": <task on error policy>,
"conditions": <list of conditions>,
"commands": <list of commands>
}
Item | Description |
---|---|
<name> | Unique name of the Task. |
<description> | It is for description purposes. |
<on_error_policy> | <on error policy> tells the task executor what to do in case of an error when executing the task. It can be either “exit”, “ignore” or “retry”. Note: the task executor is either an IoT Catalyst Agent (in case of SHELL/METRIC/PRESET commands) or the Automation Service itself (in case of API commands). |
<conditions> | It is a list of conditions which determine whether the current task will be executed or not. In case of an empty list, the overall condition defaults to TRUE. The Automation Service Condition has its own JSON definition as described in the specific paragraph. |
<commands> | It is a list containing the tasks to be executed in the campaign. The Automation Service Task has its own JSON definition as described in the specific paragraph. |
Task's Conditions definition
IoT Catalyst Automation Service uses JSON as the standard format for defining Task's conditions. A condition is an atomic element containing a logical check (a comparison) that the Automation Service performs automatically before executing a Task. A condition can be linked to other conditions in a condition chain. The link is performed by adding a condition to an existing conditions list and specifying how this newly added condition is linked to the preceding ones. The type of link is a boolean operator AND or OR. A conditions list is a sequence of atomic checks linked to form a single boolean operation.
The basic structure of a JSON that defines an IoT Catalyst Automation Service Task Condition is the following:
{
“operator”: <condition operator>,
“checks”: <list of checks>
}
Item | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
<condition operator> | Can be either “AND”, “OR”. Used to concatenate the current condition with the previous one. It can be empty only for the first condition on a given operation. | ||||||||||
<list of checks> |
It is the list of condition checks.
The basic structure of a JSON that defines an IoT Catalyst Automation Service Task Condition Check is the following:
|
Task's Commands definition
IoT Catalyst Automation Service uses JSON as the standard format for defining Task's commands. Automation Service supports four different command types.
-
Hypervisor Commands (PRESET): these are commands that are transmitted directly to the IoT Catalyst Studio management channel and are used to:
- Start a Hypervisor (START)
- Stop a Hypervisor (STOP)
- Request an update of a Hypervisor (UPDATE)
-
Shell Commands (SHELL): These commands will be sent to a remote device for execution in the Windows prompt / Linux shell, depending on the architecture.
Each command's outcome and output are collected and stored by the Automation Service for future consultation.
For each command, the following information must be entered:- Name
- Timeout, after how many seconds the agent running on edge must stop waiting to receive the result of the operation
- The number of attempts in case of failure of the operation
- Whether the command causes a reboot or not. The system is, in fact able to manage and resume the correct state of execution even after a reboot
- The command's code, i.e. the command that is executed on the remote device's command shell
-
Metrics (METRIC): it is possible to collect data of a scalar type from remote devices, for example, the amount of disk space, free memory, etc. This scalar data is referred to as metrics.
Metrics are used in conditions as arguments for the comparison checks. -
API Commands (API): Invokation to any IoT Catalyst Studio API methods.
The basic structure of a JSON that defines an IoT Catalyst Automation Service Task Command is the following:
{
“name”: <command name>,
“type”: <command type>
“causes_reboot”: <causes reboot>,
“timeout”: <timeout>,
“retries”: <retries>,
“params”: <params>,
“command”: <command>,
“refresh_interval”: <refresh interval>,
“data_type”: <data type>,
“date_format”: <date format>
}
Item | Description |
---|---|
<command name> | It is the name used to identify the command. |
<command type> | It defines the type of the command. It can be either “SHELL”, “METRIC”, “API”, or “PRESET”. Note: the commands of a given task must have the same type. |
<causes reboot> | is required only if type is “SHELL”. Indicates whether the command execution causes system reboot on the target machine. |
<timeout> | is a positive number. Indicates the command execution timeout. |
<retries> | is a positive integer. Indicates the maximum number of retries for the command. |
<params> | is required only if type is “API”. Must be a JSON object of API method parameters. |
<command> | is the command to be executed. Depends on the command type:
|
<refresh interval> | is required only if the type is “METRIC”. Indicates the frequency at which the command is executed (“refreshed”) by the target’s IoTCatalyst Agent. |
<data type> | is required only if type is “METRIC”. Indicates the metric datatype. Can be either “string”, “numeric”, or “date”. |
<date format> | is required only if type is “METRIC” and data type is “date”. Indicates the format of a “date” metric. Can be either “unix_timestamp” or “yyyy-mm-dd hh:mm:ss”. |
Request Token From IoT Catalyst Studio API
This endpoint gets a token from a IoT Catalyst Studio instance, the retrieved token is necessary to make authorized requests to the Automation Service as indicated in the relevant parts of this document.
METHOD
POST
URL
https://{{studio_ip}}/api
POST BODY FORMAT
json
POST BODY
<APISecurity.requestToken request body>
REQUEST PARAMETERS
None |
---|
Init Automation Service Via Userid And Password
This endpoint initializes the Automation Service. Until the Automation Service is not initialized, it does not allow the creation of any campaign.
METHOD
POST
URL
{{automation_api_host}}/automation-service/init
POST BODY FORMAT
json
POST BODY
<request body>
AUTH TYPE
bearer
AUTH FIELDS
Name | Value | Type |
---|---|---|
token | {{init_secret}} | string |
REQUEST PARAMETERS
None |
---|
Init Automation Service Via Passport
This endpoint initializes the Automation Service. Until the Automation Service is not initialized, it does not allow the creation of any campaign.
METHOD
POST
URL
{{automation_api_host}}/automation-service/init
POST BODY FORMAT
json
POST BODY
<request body>
REQUEST PARAMETERS
None |
---|
Get Automation Service Status
This endpoint gets the status of the Automation Service.
METHOD
GET
URL
{{automation_api_host}}/automation-service/status
REQUEST PARAMETERS
None |
---|
Create Campaign
This is the generic endpoint to create an Automation Service campaign and execute it based on a schedule
METHOD
POST
URL
{{automation_api_host}}/command
POST BODY FORMAT
json
POST BODY
<campaign json definition>
REQUEST PARAMETERS
None |
---|
Verify Campaign Definition Correctness
This endpoint can be used to verify the syntactic validity of a campaign JSON definition before executing it.
METHOD
POST
URL
{{automation_api_host}}/command/verify
POST BODY FORMAT
json
POST BODY
<campaign json definition>
REQUEST PARAMETERS
None |
---|
Validate Task
This endpoint is used by an IoTCatalyst Agent to verify the authenticity of the received campaign messages and therefore prevent Man-In-The-Middle attacks
METHOD
POST
URL
{{automation_api_host}}/validate-task
POST BODY FORMAT
json
POST BODY
<request body>
REQUEST PARAMETERS
None |
---|
Get All Campaigns
This endpoint gets the list of all the campaigns in the Automation Service.
METHOD
GET
URL
{{automation_api_host}}/campaigns?only_scheduled=<only scheduled>&status=<statuses>&page=<page>&results_per_page=<results per page>
REQUEST PARAMETERS
Name | Regex | Description | Mandatory |
---|---|---|---|
only_scheduled | <only scheduled> | Can be either 'true' or 'false', it specifies whether the search should be limited to scheduled campaigns. Defaults to false. | yes |
status | <statuses> | Comma-separated list of campaign statuses. It specifies whether the search should be limited to campaigns with a particular status (in case of scheduled campaigns the status refers to their last schedule). Accepted values for the status are: “running”, “paused”, “aborted”, “exited_ok”, “exited_ko”, “never_run”. | yes |
page | <page> | A positive integer. | yes |
results_per_page | <results per page> | A positive integer. | yes |
Get All Campaign Schedules
This endpoint gets the stats of all the schedules for the campaign
METHOD
GET
URL
{{automation_api_host}}/campaigns/<id campaign>?schedule=all&page=<page>&results_per_page=<results per page>
REQUEST PARAMETERS
Name | Regex | Description | Mandatory |
---|---|---|---|
schedule | all | Must be "all". | yes |
page | <page> | Positive integer. Pagination with respect to the campaign schedules. | yes |
results_per_page | <results per page> | Positive integer. Pagination with respect to the campaign schedules. | yes |
Get Schedule Details
This endpoint gets the detailed execution status of a campaign schedule. For each target, the execution result of each command is shown.
METHOD
GET
URL
{{automation_api_host}}/campaigns/<id campaign>?schedule=<id schedule>&page=<page>&results_per_page=<results per page>
REQUEST PARAMETERS
Name | Regex | Description | Mandatory |
---|---|---|---|
schedule | <id schedule> | A positive integer that indicates a valid schedule for the campaign with id equal to |
yes |
page | <page> | Positive integer. Pagination with respect to the campaign targets. | yes |
results_per_page | <results per page> | Positive integer. Pagination with respect to the campaign targets. | yes |
Get Target Details
This endpoint gets the detailed execution status of a schedule on a per-target basis.
METHOD
GET
URL
{{automation_api_host}}/campaigns/<id campaign>/schedules/<id schedule>/targets/<id target>
REQUEST PARAMETERS
None |
---|
Get Campaign Definition
This endpoint gets the original campaign JSON definition associated with
METHOD
GET
URL
{{automation_api_host}}/campaigns/<id campaign>/definition
REQUEST PARAMETERS
None |
---|
Remove Scheduled Campaign
This endpoint removes the schedule for the campaign
METHOD
DELETE
URL
{{automation_api_host}}/scheduled-campaigns/<id campaign>
REQUEST PARAMETERS
None |
---|
Delete Campaign's Data
This endpoint deletes information relative to the campaign
METHOD
DELETE
URL
{{automation_api_host}}/campaigns/<id campaign>
REQUEST PARAMETERS
None |
---|
Abort Campaign Execution
This endpoint aborts the last running schedule of the campaign
METHOD
POST
URL
{{automation_api_host}}/campaigns/<id campaign>/abort
REQUEST PARAMETERS
None |
---|
Pause Campaign Execution
This endpoint pauses the last running schedule of the campaign
METHOD
POST
URL
{{automation_api_host}}/campaigns/<id campaign>/pause
REQUEST PARAMETERS
None |
---|
Resume Campaign Execution
This endpoint resumes the last paused schedule of the campaign
METHOD
POST
URL
{{automation_api_host}}/campaigns/<id campaign>/resume
REQUEST PARAMETERS
None |
---|
Get Service Logs
This endpoint gets the logs of the Automation Service.
METHOD
GET
URL
{{automation_api_host}}/logs?level=<log level>&page=<page>&results_per_page=<results per page>
REQUEST PARAMETERS
Name | Regex | Description | Mandatory |
---|---|---|---|
level | <log level> | Positive integer. | yes |
page | <page> | Positive integer. | yes |
results_per_page | <results per page> | Must be either 'debug', 'info', 'warning', 'error', 'all'. Defaults to 'all'. | yes |
Delete Service Logs
This endpoint deletes logs generated before the given date.
METHOD
DELETE
URL
{{automation_api_host}}/logs?date=<log date>
REQUEST PARAMETERS
Name | Regex | Description | Mandatory |
---|---|---|---|
date | <log date> | Date in Unix Timestamp (seconds). | yes |
Get Endpoints Collection
This endpoint gets a json with a collection of exemplary endpoints.
METHOD
GET
URL
{{automation_api_host}}/endpoints-collection
REQUEST PARAMETERS
None |
---|
Get Endpoints Guide
This endpoint gets the Automation Service endpoints PDF guide.
METHOD
GET
URL
{{automation_api_host}}/help
REQUEST PARAMETERS
None |
---|
Create Library Command
This endpoint creates a new SHELL/METRIC command and saves it into the Automation Service library.
METHOD
POST
URL
{{automation_api_host}}/command-library/commands
POST BODY FORMAT
json
POST BODY
<command json definition>
REQUEST PARAMETERS
None |
---|
Update Library Command
This endpoint updates an existing command with a new version.
METHOD
PUT
URL
{{automation_api_host}}/command-library/commands/<id command>
REQUEST PARAMETERS
None |
---|
Get All Library Commands
This endpoint gets all the commands that are present into the Automation Service library.
METHOD
GET
URL
{{automation_api_host}}/command-library/commands?page=<page>&results_per_page=<results per page>&types=<command types>
REQUEST PARAMETERS
Name | Regex | Description | Mandatory |
---|---|---|---|
page | <page> | Positive integer. | yes |
results_per_page | <results per page> | Positive integer. | yes |
types | <command types> | Filter by command types. Must be a list of command types separated by a comma. Allowed command types are “SHELL” and “METRIC”. If not specified, the filter is not applied. | yes |
Delete Library Command
This endpoint deletes the specified command from the Automation Service library.
METHOD
DELETE
URL
{{automation_api_host}}/command-library/commands/<id command>
REQUEST PARAMETERS
None |
---|
P.IVA/VAT: IT14426491008 © Copyright IoT Catalyst srl - IoT Catalyst 2023 ©