4. Overview
§ Perseo is a GE under incubation
§ Context-aware CEP GE
• Listen to events from context information to identify patterns described by rules, and
immediately react by triggering actions.
• Designed to be NGSI-compliant, and thus, to implement systems that works seamless
and jointly with Orion CB.
• Based on Esper CEP
§ It is focused on Complex Event Processing, not on Stream Processing.
• It defines a rule (query) engine, not a graph engine.
□ No need to write code
• Rules are set using SQL-like queries (EPL)
§ It defines a simplified version of the CEP GE Open Specification and Architecture.
• Uses NGSI as communication protocol for events
• Follows a PUSH model (CB pushes events on it)
3
5. Main concepts
4
Notice vs Event
§ Notifications or notices from Context Broker
are processed by Perseo before being sent
to perseo-core (Esper) as events.
§ They correspond to changes in the values of
an attribute of an entity to which Perseo is
susbcribed to.
{
"subscriptionId": "51c04a21d714fb3b37d7d5a7",
"originator": "localhost",
"contextResponses": [
{
"contextElement": {
"attributes": [
{
"name": "BloodPressure",
"type": "centigrade",
"value": "2"
},
{
"name": "TimeInstant",
"type": "urn:x-ogc:def:trs:IDAS:1.0:ISO8601",
"value": "2014-04-29T13:18:05Z"
}
],
"type": "BloodMeter",
"isPattern": "false",
"id": "bloodm1"
},
"statusCode": {
"code": "200",
"reasonPhrase": "OK"
}
}
]
}
Notice
6. Main concepts
5
Notice vs Event
§ Notifications or notices from Context Broker
are processed by Perseo before being sent
to perseo-core (Esper) as events.
§ They correspond to changes in the values of
an attribute of an entity to which Perseo is
susbcribed to.
{
"noticeId":"a64fa410-8aad-11e4-87e4-632f5115a641",
"id":"bloodm1",
"type":"BloodMeter",
"isPattern":"false",
"service":"/",
"tenant":"unknown",
"BloodPressure":"2",
"BloodPressure__type":"centigrade",
"TimeInstant":"2014-04-29T13:18:05Z",
"TimeInstant__type":"urn:x-ogc:def:trs:IDAS:1.0:ISO8601"
}
Event
Restriction:
§ An attribute cannot be named id or type
7. Main concepts
6
Rule
§ By means of rules we can create 'complex'
events from the incoming event.
§ Perseo rules have three mandatory sections:
• name, text and action
{
"name": "blood_rule_update",
"text": "select *,"blood_rule_update" as ruleName
from pattern [every ev=iotEvent(cast(cast(bloodPressure?, String), float)
> 1.0 and type="BloodMeter")]",
"action": {
"type": "update",
"parameters": {
"attributes": [
{
"name": "normal",
"type": "boolean",
"value": "false"
}
]
}}}
Rule
8. Main concepts
7
Rule text - EPL
§ Based on Esper EPL SQL-like
rules
§ The name of the rule must be
included as ruleName
§ Pattern matching:
• from pattern
• match_recognize
§ Event stream called iotEvent
and named ev
§ We can use predefined
functions, such as cast(),
avg(), etc…
SELECT *, "blood_rule_update" as ruleName
FROM pattern
[every ev=iotEvent(cast(cast(
bloodPressure?, String),float) > 1.0
and type="BloodMeter")]
EPL using pattern clause
SELECT *, "warning_on" as ruleName
FROM iotEvent(type="AirQualityAveraged").win:time(1 minute)
MATCH_RECOGNIZE (
measures A.average? as average
pattern (A B)
define
A as cast(cast(A.average?, String), float) > 180,
B as cast(cast(B.average?, String), float) > 180 and
B.id? != A.id)
EPL using match_recognize
9. Main concepts
8
Rule actions
§ Options:
• Update context broker entity
• SMS
• Email
• HTTP invocation
• Send a tweet
§ We can use placeholders, ${X},
to insert data from the events
"action":{
"type":"update",
"parameters":{
"id":"${id}_mirror",
"attributes": [
{
"name":"abnormal",
"type":"boolean",
"value":"true"
}
]}}
Update CB entity action
"action": {
"type": "sms",
"template": "Meter ${Meter} has pressure ${Pressure}",
"parameters": {
"to": "123456789"
}}
SMS action
10. Main concepts
9
Rule actions
§ Options:
• Update context broker entity
• SMS
• Email
• HTTP invocation
• Send a tweet
§ We can use placeholders, ${X},
to insert data from the events
"action": {
"type": "email",
"template": "Meter ${Meter} has pressure ${Pressure}",
"parameters": {
"to": "someone@fiware.eu",
"from": "cep@system.org",
"subject": "It's The End Of The World As We Know
It (And I Feel Fine)"
}
}
Email action
11. Main concepts
10
Rule actions
§ Options:
• Update context broker entity
• SMS
• Email
• HTTP invocation
• Send a tweet
§ We can use placeholders, ${X},
to insert data from the events
"action":{
"type":"post",
"template":"BloodPressure is ${BloodPressure}",
"parameters":{
"url": "http://localhost:9182/${type}/${id}",
"method": "PUT",
"headers": {
"Content-type": "text/plain",
"X-${type}-pressure": "${BloodPressure}"
},
"qs": {
"${id}": "${BloodPressure}"
}
}
}
HTTP action
12. Main concepts
11
Rule actions
§ Options:
• Update context broker entity
• SMS
• Email
• HTTP invocation
• Send a tweet
§ We can use placeholders, ${X},
to insert data from the events
"action": {
"type": "twitter",
"template": "Meter ${Meter} has pressure ${Pressure}",
"parameters": {
"consumer_key": "xvz1evFS4wEEPTGEFPHBog",
"consumer_secret":
"L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg",
"access_token_key": "xvz1evFS4wEEPTGEFPHBog",
"access_token_secret":
"L8qq9PZyRg6ieKGEKhZolGC0vJWLw8iEJ88DRdyOg"
}
}
Tweet action