-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/optional rule name #316
Changes from 7 commits
0e35221
c5eb1ff
2978155
607209a
a9a9cbf
b356343
0bfc9a0
de35ffd
ef4dda6
55110fb
b25bd0f
0917cbd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,7 +191,7 @@ A simplified format in JSON can be used to represent rules. The former visual ru | |
```json | ||
{ | ||
"name" : "prueba-test", | ||
"text" : "select *,\"prueba-test\" as ruleName from pattern [every ev=iotEvent((cast(id?, String) regexp \"asd\"))]", | ||
"text" : "select * from pattern [every ev=iotEvent((cast(id?, String) regexp \"asd\"))]", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doubt: at rule creation time ( However, what about of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The ruleName is added during the creation automatically in the 'text' field. If the rule is requested using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it's a good idea to mention it in the documentation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 0917cbd |
||
"action" : { | ||
"type" : "email", | ||
"template" : "DCA message", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ The “anatomy” of a rule is as follows | |
```json | ||
{ | ||
"name":"blood_rule_update", | ||
"text":"select *,\"blood_rule_update\" as ruleName, *, ev.BloodPressure? as Pressure, ev.id? as Meter from pattern [every ev=iotEvent(cast(cast(BloodPressure?,String),float)>1.5 and type=\"BloodMeter\")]", | ||
"text":"select *, *, ev.BloodPressure? as Pressure, ev.id? as Meter from pattern [every ev=iotEvent(cast(cast(BloodPressure?,String),float)>1.5 and type=\"BloodMeter\")]", | ||
"action":{ | ||
"type":"update", | ||
"parameters":{ | ||
|
@@ -36,16 +36,15 @@ EPL is documented in [Esper website](http://www.espertech.com/esper/esper-docume | |
A EPL statement to use with perseo could be: | ||
|
||
``` | ||
select *, "blood_rule_update" as ruleName, | ||
ev.BloodPressure? as Pressure, ev.id? as Meter | ||
select *, ev.BloodPressure? as Pressure, ev.id? as Meter | ||
from pattern | ||
[every ev=iotEvent(cast(cast(BloodPressure?,String),float)>1.5 and type="BloodMeter")] | ||
[every ev=iotEvent(cast(cast(BloodPressure?,String),float)>1.5 and type="BloodMeter")] | ||
``` | ||
|
||
|
||
* The rule name must be present with **ruleName** alias. It must be equal to the ‘name’ field of the rule object | ||
* The *from* pattern must name the event as **ev** and the event stream from which take events must be **iotEvent** | ||
* A *type=* condition must be concatenated for avoiding mixing different kinds of entities | ||
* The name of the rule is not mandatory, but for backward compatibility, it can be present as ** ruleName ** alias (`e.g: select *, "blood_rule_update" as ruleName...`) in the select clause. If present, it must be equal to the ‘name’ field of the rule object. If it is not present, you can still use the variable 'ruleName' in the actions, because it will be included automatically. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest split this and include part as in a a remarked "backward compatibility note". In particular I mean: To leave this in the bullet list:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 55110fb |
||
|
||
|
||
The used entity's attributes must be cast to `float` in case of being numeric (like in the example). Alphanumeric | ||
values must be cast to `String`. Nested cast to string and to float is something we are analyzing, and could be | ||
|
@@ -335,7 +334,7 @@ could be used by a rule so | |
```json | ||
{ | ||
"name": "blood_rule_email_md", | ||
"text": "select *,\"blood_rule_email_md\" as ruleName, *,ev.BloodPressure? as Pression, ev.id? as Meter from pattern [every ev=iotEvent(cast(BloodPressure__metadata__crs__system?,String)=\"WGS84\" and type=\"BloodMeter\")]", | ||
"text": "select *, *,ev.BloodPressure? as Pression, ev.id? as Meter from pattern [every ev=iotEvent(cast(BloodPressure__metadata__crs__system?,String)=\"WGS84\" and type=\"BloodMeter\")]", | ||
"action": { | ||
"type": "email", | ||
"template": "Meter ${Meter} has pression ${Pression} (GEN RULE) and system is ${BloodPressure__metadata__crs__system}", | ||
|
@@ -474,7 +473,7 @@ An example of rule taking advantage of these derived attributes could be: | |
```json | ||
{ | ||
"name": "rule_distance", | ||
"text": "select *, \"rule_distance\" as ruleName from pattern [every ev=iotEvent(Math.pow((cast(cast(position__x?,String),float) - 618618.8286057833), 2) + Math.pow((cast(cast(position__y?,String),float) - 9764160.736945232), 2) < Math.pow(5e3,2))]", | ||
"text": "select *, from pattern [every ev=iotEvent(Math.pow((cast(cast(position__x?,String),float) - 618618.8286057833), 2) + Math.pow((cast(cast(position__y?,String),float) - 9764160.736945232), 2) < Math.pow(5e3,2))]", | ||
"action": { | ||
"type": "email", | ||
"template": "${id} (${type}) is at ${position__lat}, ${position__lon} (${position__x}, ${position__y})", | ||
|
@@ -654,7 +653,7 @@ A rule that will check if the employee has been hired in the last half hour, cou | |
```json | ||
{ | ||
"name": "rule_time", | ||
"text": "select *, \"rule_time\" as ruleName from pattern [every ev=iotEvent(cast(cast(hire__ts?,String),float) > current_timestamp - 30*60*1000)]", | ||
"text": "select *, from pattern [every ev=iotEvent(cast(cast(hire__ts?,String),float) > current_timestamp - 30*60*1000)]", | ||
"action": { | ||
"type": "email", | ||
"template": "So glad with our new ${role}, ${id}!", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
* | ||
* For those usages not covered by the GNU Affero General Public License | ||
* please contact with::[[email protected]] | ||
* | ||
* Modified by: Carlos Blanco - Future Internet Consulting and Development Solutions (FICODES) | ||
*/ | ||
'use strict'; | ||
|
||
|
@@ -132,6 +134,23 @@ function putR2core(rules, callback) { | |
myutils.requestHelperWOMetrics('put', {url: config.perseoCore.rulesURL, json: rulesAndContexts}, callback); | ||
} | ||
|
||
/** | ||
* Add ruleName if necessary in rule text field | ||
* | ||
* @param rule The rule object | ||
*/ | ||
function normalizeRuleName(rule) { | ||
|
||
var newAs = '"' + rule.name + '" as ruleName'; | ||
// Add "name as ruleName" if not exist | ||
if (rule.text && rule.text.indexOf(' as ruleName') === -1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation should be changed to explain that now the name is not mandatory and which happens if the name is ommited (i.e. an example of autogenerated name would be great). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have changed the documentation but I do not know if I have approached it in the right way, please check if the change seems appropriate. b356343 |
||
var idx = rule.text.toLowerCase().indexOf('select') + 7; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 7 seems to be a magic number, a bit obscure :) Where it comes from? It seems to be len(select) +1, so maybe it would be more clear (i.e. less magical ;) something like this:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in b25bd0f |
||
rule.text = rule.text = rule.text.slice(0, idx) + newAs + ', ' + rule.text.slice(idx); | ||
} | ||
|
||
return rule; | ||
} | ||
|
||
module.exports = { | ||
FindAll: function(service, subservice, callback) { | ||
rulesStore.FindAll(service, subservice, function(err, data) { | ||
|
@@ -150,6 +169,10 @@ module.exports = { | |
myutils.logErrorIf(localError); | ||
return callback(localError); | ||
} | ||
|
||
// Normalize the rule text | ||
rule = normalizeRuleName(rule); | ||
|
||
async.series( | ||
[ | ||
function(localCallback) { | ||
|
@@ -208,6 +231,10 @@ module.exports = { | |
myutils.logErrorIf(localError); | ||
return callback(localError); | ||
} | ||
|
||
// Normalize the rule text | ||
rule = normalizeRuleName(rule); | ||
|
||
async.series( | ||
[ | ||
delR2core.bind(null, rule), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "theCorrectName", | ||
"text": "select *, \"badRuleleName\" as ruleName, ev.xPressure? as Pression, ev.id? as Meter from pattern [every ev=iotEvent(cast(cast(xPressure?,String),float)>1.5 and type=\"xMeter\")]", | ||
"action": { | ||
"type": "post", | ||
"template": "Meter ${Meter} has pression ${Pression}.", | ||
"parameters": { | ||
"url": "localhost:1111" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "x_post_auto", | ||
"text": "select *, ev.xPressure? as Pression, ev.id? as Meter from pattern [every ev=iotEvent(cast(cast(xPressure?,String),float)>1.5 and type=\"xMeter\")]", | ||
"action": { | ||
"type": "post", | ||
"template": "Meter ${Meter} has pression ${Pression}.", | ||
"parameters": { | ||
"url": "localhost:1111" | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argg... issue number is #307, not #208.
My fault sorry :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ef4dda6