Create Scheduled Query
Creates a new scheduled query. Administrator privileges are required to call this API.
Required Permissions
Requires the ADMIN role or higher.
HTTP Request
POST /api/sonar/scheduled-queries
cURL Example
curl -H "Authorization: Bearer <API_KEY>" \
-d name="test" \
-d query="table duration=1m sonar_cpu_logs | search idle <= 10" \
-d trigger_type="cron" \
-d cron_schedule="* * * * *" \
-X POST https://HOSTNAME/api/sonar/scheduled-queries
Request Parameters
| Key | Required | Type | Description | Note |
|---|---|---|---|---|
| name | O | String | Name | Maximum 255 characters |
| description | X | String | Description | Maximum 2,000 characters |
| enabled | X | Boolean | Whether the scheduled query is enabled or not | Default: false |
| query | O | String | Query string | |
| trigger_type | O | String | Query trigger type | Either cron(Run at predefined intervals or on a predetermined schedule) or workflow(Run based on the preceding query result) |
| cron_schedule | O | String | Cron expression | Required when trigger_type is set to cron. |
| preceding_guid | X | String | GUID of preceding query | Required when trigger_type is set to workflow. |
| preceding_action | X | String | Preceding query status | Either succeeded, failed, or finished when trigger_type is set to workflow |
| node_types | X | List of strings | Node on which to run the query | Comma-separated list of control(control node) or data(data node) |
| output_parameter | X | Boolean | Whether to pass the last result row as query parameter(s) to the subsequent query | Default: false |
Success Response
{}
Error Responses
Required argument is missing
HTTP status code 400
{
"error_code": "null-argument",
"error_msg": "name should be not null"
}
Invalid argument length
HTTP status code 400
{
"error_code": "invalid-argument",
"error_msg": "'name' must be shorter than or equal to 255 characters."
}
Duplicated query name
HTTP status code 500
{
"error_code": "illegal-state",
"error_msg": "duplicated name: test"
}
Missing cron_schedule value when trigger_type is set to cron
HTTP status code 400
{
"error_code": "null-argument",
"error_msg": "cron_schedule should be not null"
}
Missing preceding_action value when trigger_type is set to workflow
HTTP status code 400
{
"error_code": "null-argument",
"error_msg": "preceding_action should be not null"
}
Invalid preceding_action value when trigger_type is set to workflow
HTTP status code 400
{
"error_code": "invalid-argument",
"error_msg": "preceding_action value must be one of 'finished', 'succeeded', 'failed'."
}
No administrator privileges
HTTP status code 500
{
"error_code": "illegal-state",
"error_msg": "no-permission"
}