Skip to content

Instantly share code, notes, and snippets.

@dustin
Created June 19, 2011 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustin/1034925 to your computer and use it in GitHub Desktop.
Save dustin/1034925 to your computer and use it in GitHub Desktop.
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