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
KeyRequiredTypeDescriptionNote
nameYesStringNameMaximum 255 characters
descriptionNoStringDescriptionMaximum 2,000 characters
enabledNoBooleanWhether the scheduled query is enabled or notDefault: false
queryYesStringQuery string
trigger_typeYesStringQuery trigger typeEither cron(Run at predefined intervals or on a predetermined schedule) or workflow(Run based on the preceding query result)
cron_scheduleYesStringCron expressionRequired when trigger_type is set to cron.
preceding_guidNoStringGUID of preceding queryRequired when trigger_type is set to workflow.
preceding_actionNoStringPreceding query statusEither succeeded, failed, or finished when trigger_type is set to workflow
node_typesNoList of stringsNode on which to run the queryComma-separated list of control(control node) or data(data node)
output_parameterNoBooleanWhether to pass the last result row as query parameter(s) to the subsequent queryDefault: false

Success Response

{
  "guid": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}

Error Responses

Required argument is missing

HTTP status code 400

{
  "error_code": "null-argument",
  "error_msg": "name should be not null"
}
name or description parameter length is invalid

HTTP status code 400

{
  "error_code": "invalid-argument",
  "error_msg": "'name' must be shorter than or equal to 255 characters."
}
guid is not a valid GUID

HTTP status code 400

{
  "error_code": "invalid-param-type",
  "error_msg": "guid should be guid type."
}
trigger_type: invalid value

HTTP status code 400

{
  "error_code": "invalid-argument",
  "error_msg": "trigger_type value must be either 'cron' or 'workflow'."
}
cron_schedule is missing when trigger_type is cron

HTTP status code 400

{
  "error_code": "null-argument",
  "error_msg": "cron_schedule should be not null"
}
preceding_action is missing when trigger_type is workflow

HTTP status code 400

{
  "error_code": "null-argument",
  "error_msg": "preceding_action should be not null"
}
preceding_action: invalid value

HTTP status code 400

{
  "error_code": "invalid-argument",
  "error_msg": "preceding_action value must be one of 'finished', 'succeeded', 'failed'."
}
Duplicated query name

HTTP status code 500

{
  "error_code": "illegal-state",
  "error_msg": "duplicated scheduled query name: cpu-check"
}
guid is duplicated

HTTP status code 500

{
  "error_code": "illegal-state",
  "error_msg": "duplicated scheduled query guid: a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
Permission denied

HTTP status code 500

{
  "error_code": "illegal-state",
  "error_msg": "no-permission"
}