Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Replicate only my alerting sensors.
{
"_id": "alerting-temperatures",
"source": "temperature",
"target": "temperature-alerting",
"filter": "app/alerting",
"query_params": {
"ranges": {
"1081841E000000DF": {
"low": 4,
"high": 31
},
"10C8892A00000096": {
"low": 5,
"high": 30
},
"101D8A2A000000F7": {
"low": 5,
"high": 27
},
"1013A51E00000035": {
"low": 5,
"high": 30
}
}
}
}
(doc, req) ->
if (! (doc.type? == 'reading'))
return true
ranges = if typeof(req.query.ranges) == "string" then JSON.parse(req.query.ranges) else req.query.ranges
if (!ranges)
throw("Need the serial number alert levels in 'ranges' parameter.")
if (! ranges[doc.sn])
return false
return (!(ranges[doc.sn].low < doc.reading < ranges[doc.sn].high))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment