Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
setup:
- do:
cluster.health:
wait_for_status: yellow

---
teardown:
- do:
watcher.delete_watch:
id: "test_watch"
ignore: 404

---
"Test executing logging action using template with params":
- do:
put_script:
id: log-action
body: >
{
"script":
{
"lang": "mustache",
"source": "{{color}} alert"
}
}

- do:
watcher.put_watch:
id: "test_watch"
body: >
{
"trigger": {
"schedule" : { "interval": "1m" }
},
"input": {
"simple": {
}
},
"condition": {
"always": {}
},
"actions": {
"log" : {
"logging" : {
"text" : {
"id": "log-action",
"params": {
"color": "yellow"
}
}
}
}
}
}
- match: { _id: "test_watch" }
- match: { created: true }

- do:
watcher.execute_watch:
id: "test_watch"

- match: { watch_record.watch_id: "test_watch" }
- match: { watch_record.result.actions.0.id: "log" }
- match: { watch_record.result.actions.0.type: "logging" }
- match: { watch_record.result.actions.0.status: "success" }
- match: { watch_record.result.actions.0.logging.logged_text: "yellow alert" }
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,61 @@
- match: { "watch_record.result.actions.0.type" : "email" }
- match: { "watch_record.result.actions.0.email.message.subject" : "404 recently encountered" }

---
"Test executing logging action using scripts with params":
- do:
cluster.health:
wait_for_status: yellow

- do:
put_script:
id: log-action
body: >
{
"script":
{
"lang": "painless",
"source": "params.color + \" alert\""
}
}

- do:
watcher.put_watch:
id: "test_watch"
body: >
{
"trigger": {
"schedule" : { "interval": "1m" }
},
"input": {
"simple": {
}
},
"condition": {
"always": {}
},
"actions": {
"log" : {
"logging" : {
"text" : {
"id": "log-action",
"params": {
"color": "yellow"
}
}
}
}
}
}
- match: { _id: "test_watch" }
- match: { created: true }

- do:
watcher.execute_watch:
id: "test_watch"

- match: { watch_record.watch_id: "test_watch" }
- match: { watch_record.result.actions.0.id: "log" }
- match: { watch_record.result.actions.0.type: "logging" }
- match: { watch_record.result.actions.0.status: "success" }
- match: { watch_record.result.actions.0.logging.logged_text: "yellow alert" }
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public String render(TextTemplate textTemplate, Map<String, Object> model) {
Script script = new Script(textTemplate.getType(),
textTemplate.getType() == ScriptType.STORED ? null : "mustache", template, options, mergedModel);
TemplateScript.Factory compiledTemplate = service.compile(script, Watcher.SCRIPT_TEMPLATE_CONTEXT);
return compiledTemplate.newInstance(model).execute();
return compiledTemplate.newInstance(mergedModel).execute();
}

private String trimContentType(TextTemplate textTemplate) {
Expand Down