Create Scheduled Query

Creates a new scheduled query. Administrator privileges are required to call this API.

HTTP Request

POST /api/sonar/scheduled-queries

Request using cURL

curl -H "Authorization: Bearer <API_KEY>" \
     -d name="test" \
     -d query="table duration=1m sonar_cpu_logs | search idle <= 10" \
     -d type="cron" \
     -d cron_schedule="* * * * *" \
     -X POST https://HOSTNAME/api/sonar/scheduled-queries

Request Parameters

KeyRequiredTypeDescriptionNote
nameOStringNameMaximum 255 characters
descriptionXStringDescriptionMaximum 2,000 characters
enabledXBooleanWhether the scheduled query is enabled or notDefault: false
queryOStringQuery string
trigger_typeOStringQuery trigger typeEither cron(Run at predefined intervals or on a predetermined schedule) or workflow(Run based on the preceding query result)
cron_scheduleOStringCron expressionRequired when trigger_type is set to cron.
preceding_guidXStringGUID of preceding queryRequired when trigger_type is set to workflow.
preceding_actionXStringPreceding query statusEither succeeded, failed, or finished when trigger_type is set to workflow
node_typesXList of stringsNode on which to run the queryComma-separated list of control(control node) or data(data node)
output_parameterXBooleanWhether to pass the last result row as query parameter(s) to the subsequent queryDefault: 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"
}