The collection 'rules' stores information about the rules to be sent to the core. It includes the VisualRule passed in by the Portal for giving it back when the Portal requests it
Fields:
- _ID ObjectId: unique object ID used by mongoDB
- name string: name of the rule
- description string: (optional) description of the rule
- misc object: (optional) miscelanea data of the rule
- service string : service which the rule belongs to.
- subservice string: subservice which the rule belongs to.
- text string: EPL sentence for the rule, to be propagated to core
- action object: action to be executed when the rule is fired. Each action type has different field set as
described in Plain rules
- type ( string ): type of action.
- Other subfields, depending on the rule type.
- VR object: VisualRule object passed in by the Portal
- nosignal object: no signal condition for nosignal rules
- checkInterval string: time in minutes for checking the attribute
- attribute string: attribute for watch
- reportInterval string: time in seconds to see an entity as silent
- ID string: ID of the entity to watch
- idRegexp string: regular expression to match entities by ID
- type string: type of entities to watch
- internalCurrentTime string: current UTC Time in ISO 8601 to use as reference of time in the rule (i.e. the "t0" of the no signal checkings)
Only rules with EPL have a field text and only rules for no-signal detection has a field nosignal.
Example:
{
"_id": ObjectId("5530d83e38f4962d13479c47"),
"VR": {
"name": "ReglaId",
"active": 1,
"cards": [],
"updateTime": "2014-05-06T10:39:47.696Z",
"subservice": "/",
"service": "unknownt"
},
"name": "ReglaId",
"action": {
"type": "email",
"template": "${device.asset.name} ${measure.value}",
"parameters": {
"to": "[email protected]",
"from": "[email protected]",
"subject": "calor"
}
},
"subservice": "/",
"service": "unknownt",
"text": "select * from pattern [every ev=iotEvent((cast(`id`?, String) regexp \"^value.*\"))]"
}
Example no-signal rule
{
"_id": ObjectId("5530d8dd38f4962d13479c48"),
"VR": {
"name": "VR_nonsignal_complex",
"active": 1,
"cards": [],
"updateTime": "2014-03-26T14:29:40.561Z",
"subservice": "/",
"service": "unknownt"
},
"name": "VR_nonsignal_complex",
"action": {
"type": "sms",
"template": "${device.asset.name}",
"parameters": {
"to": "123456789"
}
},
"subservice": "/",
"service": "unknownt",
"nosignal": {
"checkInterval": "1",
"attribute": "temperature",
"reportInterval": "5",
"id": null,
"idRegexp": "^value.*",
"type": null
}
}
The collection 'executions' stores information about the successfully executed actions. A TTL index deletes exectutions older than ine day
Fields:
- _ID ObjectId: unique object ID used by mongoDB
- ID string: entity ID that fired the rule
- name string: name fo the fired rule
- notice string: notice ID that fired the rule
- service string : service which the fired rule belongs to.
- subservice string: subservice which the fired rule belongs to.
- lastTime Date object: timestamp of the execution
Example
{
"_id": ObjectId("552fc1997fa3e7b1d5e97ab2"),
"id": "bloodm1",
"name": "blood_rule_email",
"notice": "9a140d10-e441-11e4-86f7-179be4a75b65",
"service": "tenant2",
"subservice": "/subservicio2",
"lastTime": ISODate("2015-04-16T14:05:13.922Z")
}
An index guarantees that every rule is identified by the tuple (name, service, subservice)
The index is created/ensured when perseo-fe starts, but it can be created from a mongoDB shell with
db.rules.ensureIndex({ name: 1, subservice: 1, service: 1 }, { unique: true });
A TTL index deletes documents with a life longer than one day
The index is created/ensured when perseo-fe starts, but it can be created from a mongoDB shell with
db.executions.ensureIndex({ lastTime: 1 }, { expireAfterSeconds: 86400 });