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
6 changes: 3 additions & 3 deletions contrib/examples/rules/sample-rule.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"type": {
"name": "st2.test.action"
},
"mapping": {
"ip2": "{{system.k1}}",
"ip1": "{{trigger.t1_p}}"
"parameters": {
"ip1": "{{trigger.t1_p}}",
"ip2": "{{system.k1}}"
}
},

Expand Down
8 changes: 4 additions & 4 deletions st2common/st2common/models/api/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class RuleAPI(StormBaseAPI):
e.g.
"action":
{ "type": {"id": "2345678901"}
, "mapping":
, "parameters":
{ "command": "{{ system.foo }}"
, "args": "--email {{ trigger.from }} --subject \'{{ user[stanley].ALERT_SUBJECT }}\'"}
}
Expand All @@ -97,7 +97,7 @@ def from_model(kls, model):
rule.trigger = model.trigger
rule.criteria = dict(model.criteria)
rule.action = {'type': model.action.action,
'mapping': dict(model.action.data_mapping)}
'parameters': dict(model.action.parameters)}
rule.enabled = model.enabled
return rule

Expand All @@ -110,8 +110,8 @@ def to_model(kls, rule):
model.action = ActionExecutionSpecDB()
if 'type' in rule.action:
model.action.action = rule.action['type']
if 'mapping' in rule.action:
model.action.data_mapping = rule.action['mapping']
if 'parameters' in rule.action:
model.action.parameters = rule.action['parameters']
model.enabled = rule.enabled
return model

Expand Down
2 changes: 1 addition & 1 deletion st2common/st2common/models/db/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class TriggerInstanceDB(StormFoundationDB):

class ActionExecutionSpecDB(me.EmbeddedDocument):
action = me.DictField()
data_mapping = me.DictField()
parameters = me.DictField()


class RuleDB(StormBaseDB):
Expand Down
2 changes: 1 addition & 1 deletion st2common/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _create_save_rule(trigger, action=None, enabled=True):
created.criteria = {}
created.action = ActionExecutionSpecDB()
created.action.action = reference.get_ref_from_model(action)
created.action.data_mapping = {}
created.action.parameters = {}
return Rule.add_or_update(created)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion st2reactor/st2reactor/rules/enforcer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def enforce(self):
rule_enforcement = RuleEnforcementDB()
rule_enforcement.trigger_instance = reference.get_ref_from_model(self.trigger_instance)
rule_enforcement.rule = reference.get_ref_from_model(self.rule)
data = self.data_transformer(self.rule.action.data_mapping)
data = self.data_transformer(self.rule.action.parameters)
LOG.info('Invoking action %s for trigger_instance %s with data %s.',
RuleEnforcer.__get_action_name(self.rule.action), self.trigger_instance.id,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be simplified to self.rule.action.name

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in PR #301

json.dumps(data))
Expand Down
2 changes: 1 addition & 1 deletion st2reactorcontroller/tests/controllers/test_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'type': {
'name': 'st2.test.action'
},
'mapping': {
'parameters': {
'ip2': '{{rule.k1}}',
'ip1': '{{trigger.t1_p}}'
}
Expand Down