-
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
allow access entities using NGSIv2 API for non_signal rules #726
Changes from all commits
46d4bf3
cea4ca5
693a388
3f87d0e
08ca5db
ae7708d
2071248
b9a40f2
df171c0
0ac60c9
c046597
82a4910
801fa80
b7168c1
dcf84dd
f71575e
b0958b9
cabcd0d
4fd3bf0
b3ef4fe
3cdf6ce
c88639f
d2038d2
18c2c89
bb3f154
a289a3d
c036794
184f6b7
164fb54
b0ba12e
cb70ed8
87c1766
04543fa
b251606
7f16995
aa79f86
4b63d3d
a0b86c3
e593c4c
543cfdd
cb84048
ebdd267
145e798
92aa5fe
c513522
3020ed0
2f53ae4
38a2932
53f1a47
e240874
897e205
2369f6b
f3207ec
00dcd96
b2e11dd
855cde0
53796c1
3f3b8ef
06d20d8
8613403
7c6bcc8
d939e62
6cd8488
4086d69
b1808b2
249a179
023724b
5e55352
b1ac552
43501ba
790b9a6
77dd194
ba8cd92
7d86c11
860d818
9c6338f
ffa6fb8
c08ca19
f68a9df
927f42d
241a7a7
eac5024
aa3a6e4
05c0ef5
480d7cd
3eac6d4
fe27602
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
- Add: allow access entities using NGSIv2 API for non_signal rules (new setting nonSignalByAPI / PERSEO_CHECK_NON_SIGNAL_BY_API) (#549) | ||
- Remove support for ngsv1 notifications (#714) | ||
- Remove ngsiv1 support for updateAction (#714) | ||
- Fix: check timer string in lower case in TimedRule checker | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,36 +63,63 @@ function alertFunc(nsLineRule, entity) { | |
d.exit(); | ||
}); | ||
d.run(function() { | ||
logger.debug(context, 'alertfunc nsLineRule %j entity %j ', nsLineRule, entity); | ||
// We duplicate info in event and event.ev for VR and non-VR action parameters | ||
var event = { | ||
service: nsLineRule[SERVICE], | ||
subservice: nsLineRule[SUBSERVICE], | ||
ruleName: nsLineRule[NAME], | ||
reportInterval: nsLineRule[REPORT_INTERVAL], | ||
id: entity._id.id, | ||
type: entity._id.type, | ||
internalCurrentTime: new Date().toISOString() | ||
}; | ||
|
||
// Search for modDate of the entity's attribute | ||
// and copy every attribute (if not in event yet) | ||
// for use in action template | ||
Object.keys(entity.attrs).forEach(function(attrName) { | ||
if (attrName === nsLineRule[ATTRIBUTE]) { | ||
if (!config.nonSignalByAPI) { | ||
// entity is really a entity doc obtained from mongo | ||
event.id = entity._id.id; | ||
event.type = entity._id.type; | ||
logger.debug(context, 'alertfunc event %j ', event); | ||
// Search for modDate of the entity's attribute | ||
// and copy every attribute (if not in event yet) | ||
// for use in action template | ||
Object.keys(entity.attrs).forEach(function(attrName) { | ||
if (attrName === nsLineRule[ATTRIBUTE]) { | ||
try { | ||
lastTime = new Date(entity.attrs[attrName].modDate * 1000).toISOString(); | ||
} catch (ex) { | ||
myutils.logErrorIf(ex, 'run ', d.context); | ||
} | ||
} | ||
if (event[attrName] === undefined) { | ||
if (entity.attrs[attrName].type === 'DateTime') { | ||
event[attrName] = new Date(entity.attrs[attrName].value * 1000).toISOString(); | ||
} else { | ||
event[attrName] = entity.attrs[attrName].value; | ||
} | ||
} | ||
}); | ||
} else { | ||
// entity is and NGSI object | ||
event.id = entity.id; | ||
event.type = entity.type; | ||
logger.debug(context, 'alertfunc event %j ', event); | ||
// Search for modDate of the entity's attribute | ||
// and copy every attribute (if not in event yet) | ||
// for use in action template | ||
const attrName = nsLineRule[ATTRIBUTE]; | ||
if (entity[attrName]) { | ||
try { | ||
lastTime = new Date(entity.attrs[attrName].modDate * 1000).toISOString(); | ||
lastTime = entity[attrName].metadata.TimeInstant.value; | ||
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. Comment for all: we are checking the attr metadata, but not the modDate... I'm not sure it is correct. Probably is the best we have, but not every attribute will be suitable for this mechanism. We've got an internal _modDate for the entity but no for the attr, right? 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. Fermin clarifies that "modDate" is the built in metadata from MONGO/NGSI and not an arbitrary metadata. OK. 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. As extra info: the name of the metadata is |
||
} catch (ex) { | ||
myutils.logErrorIf(ex, 'run ', d.context); | ||
} | ||
} | ||
if (event[attrName] === undefined) { | ||
if (entity.attrs[attrName].type === 'DateTime') { | ||
event[attrName] = new Date(entity.attrs[attrName].value * 1000).toISOString(); | ||
} else { | ||
event[attrName] = entity.attrs[attrName].value; | ||
if (event[attrName] === undefined) { | ||
if (entity[attrName].type === 'DateTime') { | ||
event[attrName] = entity[attrName].metadata.TimeInstant.value; | ||
} else { | ||
event[attrName] = entity[attrName].value; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
logger.debug(context, 'lastTime could be ', lastTime); | ||
if (lastTime !== undefined && lastTime !== null) { | ||
|
@@ -119,6 +146,7 @@ function checkNoSignal(period) { | |
currentContext.srv = 'n/a'; | ||
currentContext.subsrv = 'n/a'; | ||
logger.debug(currentContext, 'Executing no-signal handler for period of %d (%d rules)', period, list.length); | ||
|
||
list.forEach(function(nsrule) { | ||
currentContext.srv = nsrule[SERVICE]; | ||
currentContext.subsrv = nsrule[SUBSERVICE]; | ||
|
@@ -192,6 +220,7 @@ function addNSRule(service, subservice, name, nsr) { | |
); | ||
intervalAsNum = MIN_INTERVAL_MS; | ||
} | ||
|
||
arrayRule = nsr2arr(service, subservice, name, nsr); | ||
nsRulesByInterval[nsr.checkInterval] = nsRulesByInterval[nsr.checkInterval] || []; | ||
nsRulesByInterval[nsr.checkInterval].forEach(function(element, index, array) { | ||
|
@@ -206,6 +235,7 @@ function addNSRule(service, subservice, name, nsr) { | |
logger.debug(context, util.format('Adding no-signal rule (%s, %s, %s)', service, subservice, name)); | ||
} | ||
if (!checkers.hasOwnProperty(nsr.checkInterval)) { | ||
logger.info(context, util.format('no-signal rule (%s, %s, %s)', service, subservice, name)); | ||
checkers[nsr.checkInterval] = setInterval(checkNoSignal, intervalAsNum, nsr.checkInterval); | ||
checkers[nsr.checkInterval].unref(); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"_id": "6474761fa509a6104ad7e415", | ||
"name": "update_nonsignal", | ||
"description": "testUpdate2", | ||
"misc": "", | ||
"text": "", | ||
"VR": "", | ||
"action": { | ||
"type": "update", | ||
"parameters": { | ||
"id": "alarma:${id}", | ||
"type": "Alarm", | ||
"attributes": [ | ||
{ | ||
"name": "msg", | ||
"value": "El status de ${id} es ${status}" | ||
} | ||
] | ||
} | ||
}, | ||
"nosignal": { | ||
"checkInterval": "1", | ||
"attribute": "temperature", | ||
"reportInterval": "5", | ||
"id": "thing:disp1", | ||
"idRegexp": null, | ||
"type": "thing" | ||
}, | ||
"subservice": "/test", | ||
"service": "smartcity" | ||
} |
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.
the library takes pagination into account? it's there a problem with thousand of entities? I think it does, but check.
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.
Solved in these commits: aa79f86#diff-d21abada9564b2a8fdaf4c061d51c73f386a5b4869659ab7517d94c9f665818c , cb70ed8