Scott Anderson [InfluxData] | Flux Alerts and Notifications | InfluxDays NA 2021

InfluxData
InfluxDataInfluxData
Flux Alerts &
Notifications
Scott Anderson
Senior Technical Writer & Technical Lead of
the Docs team @ InfluxData
© 2021  InfluxData Inc. All Rights Reserved.
Goals
● Demystify Flux notifications
● Explain notification conventions
● Demonstrate notifications in raw Flux
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
* *
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
5
© 2021  InfluxData Inc. All Rights Reserved.
Notification packages
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
Each notification package
An endpoint function
A function that outputs a function that iterates over all input rows
and generates another function that sends a notification for each
input row.
Notification function
A function that sends a single notification.
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
slack package
slack.endpoint()
slack.message()
pagerduty package
pagerduty.endpoint()
pagerduty.sendEvent()
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
Notification Conventions
● One-off convention
● Map convention
● Endpoint convention
© 2021  InfluxData Inc. All Rights Reserved.
9
© 2021  InfluxData Inc. All Rights Reserved.
One-off convention
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
sendFn(...)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
slack.message(...)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
slack.message(
url: "https://slack.com/api/chat.postMessage",
token: "mYSuP3rSecR37T0kEN",
channel: "#mychannel",
text: "Hey, here's a message!",
color: "danger"
)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
lastReported = data |> last() |> findRecord(fn: (key) => true, idx: 0)
slack.message(
url: "https://slack.com/api/chat.postMessage",
token: "mYSuP3rSecR37T0kEN",
channel: "#mychannel",
text: "The last reported value was ${lastReported._value}.",
color: "#000"
)
© 2021  InfluxData Inc. All Rights Reserved.
15
© 2021  InfluxData Inc. All Rights Reserved.
Map Convention
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
map(fn: (r) => ({ r with sent: sendFn(...) }))
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
data
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
data
|> map(fn: (r) => ({ ... }))
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
data
|> map(fn: (r) => ({ r with sent: ... }))
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
data
|> map(fn: (r) => ({ r with sent:
slack.message(
url: "https://slack.com/api/chat.postMessage",
token: "mYSuP3rSecR37T0kEN",
channel: "#mychannel",
text: "Oh no! *${r.tag} had a value of *${r._value}*.",
color: "danger"
}))
© 2021  InfluxData Inc. All Rights Reserved.
21
© 2021  InfluxData Inc. All Rights Reserved.
Endpoint convention
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
endpointFn(...) => (mapFn) => (tables=<-)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
data
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
data
|> slack.endpoint(...)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
data
|> slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: "mYSuP3rSecR37T0kEN"
)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
data
|> slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: "mYSuP3rSecR37T0kEN"
)(mapFn: (r) => ({
channel: "#mychannel",
text: "Oh no! *${r.tag} had a value of *${r._value}*.",
color: "danger"
}))
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "slack"
data
|> slack.endpoint(
url: "https://slack.com/api/chat.postMessage",
token: "mYSuP3rSecR37T0kEN"
)(mapFn: (r) => ({
channel: "#mychannel",
text: "Oh no! *${r.tag} had a value of *${r._value}*.",
color: "danger"
}))()
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "influxdata/influxdb/monitor"
import "influxdata/influxdb/secrets"
import "slack"
notification_data = {...}
token = secrets.get(key: "SLACK_TOKEN")
endpoint = slack.endpoint(token: token)(mapFn: (r) => ({
channel: "#mychannel",
text: "Oh no! *${r.tag} had a value of *${r._value}*.",
color: "#000"
}))
monitor.from(start: -1h, fn: (r) => r._level == "crit”)
|> monitor.notify(endpoint: endpoint, data: notification_data)
© 2021  InfluxData Inc. All Rights Reserved.
29
© 2021  InfluxData Inc. All Rights Reserved.
Custom notifications
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
http.post(
url: "...",
headers: "...",
data: bytes(v: "...")
)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "http"
tweet = (status, oauth) => {
}
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "http"
tweet = (status, oauth) => {
apiURL = "https://api.twitter.com/1.1/statuses/update.json"
}
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "http"
tweet = (status, oauth) => {
apiURL = "https://api.twitter.com/1.1/statuses/update.json"
return http.post(
)
}
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "http"
tweet = (status, oauth) => {
apiURL = "https://api.twitter.com/1.1/statuses/update.json"
return http.post(
url: "${apiURL}?status=${http.pathEscape(inputString: status)}"
headers:
{Authorization: "OAuth ${oauth}"}
)
}
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "http"
tweet = (status, oauth) => {...}
tweet(
status: "This tweet was created by Flux and InfluxDB!",
oauth: "..."
)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "http"
tweet = (status, oauth) => {...}
tweet(
status: "This tweet was created by Flux and InfluxDB!",
oauth: "..."
)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "http"
tweet = (status, oauth) => {...}
oauth: "..."
data
|> map(fn: (r) => ({ r with sent:
}))
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "http"
tweet = (status, oauth) => {...}
oauth: "..."
data
|> map(fn: (r) => ({ r with sent: tweet(
status: "At ${r._time}, ${r._field} was ${r._value}.",
oauth: oauth
)
}))
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
http.endpoint(url: "...") =>
(mapFn: (r) => ({ headers: "...", data: bytes(v: "...") })) =>
(tables=<-)
© 2021  InfluxData Inc. All Rights Reserved.
© 2021  InfluxData Inc. All Rights Reserved.
import "http"
import "influxdata/influxdb/monitor"
apiURL = "https://api.twitter.com/1.1/statuses/update.json"
oauth = "..."
notification_data = {...}
endpoint = http.endpoint(
url: "${apiURL}"
)(mapFn: (r) => ({
url: "${apiURL}?status=${http.pathEscape(inputString: r._message)}",
headers: {Authorization: "OAuth ${oauth}"},
data: bytes(v: "")
}))
monitor.from(start: -1h)
|> monitor.notify(endpoint: endpoint, data: notification_data)
© 2021  InfluxData Inc. All Rights Reserved.
Demo!
© 2021  InfluxData Inc. All Rights Reserved.
Questions?
© 2021  InfluxData Inc. All Rights Reserved.
Thank You
1 of 43

More Related Content

What's hot(20)

InfluxDB Cloud Product Update InfluxDB Cloud Product Update
InfluxDB Cloud Product Update
InfluxData103 views

Similar to Scott Anderson [InfluxData] | Flux Alerts and Notifications | InfluxDays NA 2021

Similar to Scott Anderson [InfluxData] | Flux Alerts and Notifications | InfluxDays NA 2021(20)

More from InfluxData(20)

Announcing InfluxDB ClusteredAnnouncing InfluxDB Clustered
Announcing InfluxDB Clustered
InfluxData99 views

Recently uploaded(20)

Liqid: Composable CXL PreviewLiqid: Composable CXL Preview
Liqid: Composable CXL Preview
CXL Forum118 views
ChatGPT and AI for Web DevelopersChatGPT and AI for Web Developers
ChatGPT and AI for Web Developers
Maximiliano Firtman152 views
Web Dev - 1 PPT.pdfWeb Dev - 1 PPT.pdf
Web Dev - 1 PPT.pdf
gdsczhcet48 views

Scott Anderson [InfluxData] | Flux Alerts and Notifications | InfluxDays NA 2021

  • 1. Flux Alerts & Notifications Scott Anderson Senior Technical Writer & Technical Lead of the Docs team @ InfluxData
  • 2. © 2021  InfluxData Inc. All Rights Reserved. Goals ● Demystify Flux notifications ● Explain notification conventions ● Demonstrate notifications in raw Flux
  • 3. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. * *
  • 4. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved.
  • 5. © 2021  InfluxData Inc. All Rights Reserved. 5 © 2021  InfluxData Inc. All Rights Reserved. Notification packages
  • 6. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. Each notification package An endpoint function A function that outputs a function that iterates over all input rows and generates another function that sends a notification for each input row. Notification function A function that sends a single notification.
  • 7. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. slack package slack.endpoint() slack.message() pagerduty package pagerduty.endpoint() pagerduty.sendEvent()
  • 8. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. Notification Conventions ● One-off convention ● Map convention ● Endpoint convention
  • 9. © 2021  InfluxData Inc. All Rights Reserved. 9 © 2021  InfluxData Inc. All Rights Reserved. One-off convention
  • 10. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. sendFn(...)
  • 11. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack"
  • 12. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" slack.message(...)
  • 13. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" slack.message( url: "https://slack.com/api/chat.postMessage", token: "mYSuP3rSecR37T0kEN", channel: "#mychannel", text: "Hey, here's a message!", color: "danger" )
  • 14. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" lastReported = data |> last() |> findRecord(fn: (key) => true, idx: 0) slack.message( url: "https://slack.com/api/chat.postMessage", token: "mYSuP3rSecR37T0kEN", channel: "#mychannel", text: "The last reported value was ${lastReported._value}.", color: "#000" )
  • 15. © 2021  InfluxData Inc. All Rights Reserved. 15 © 2021  InfluxData Inc. All Rights Reserved. Map Convention
  • 16. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. map(fn: (r) => ({ r with sent: sendFn(...) }))
  • 17. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" data
  • 18. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" data |> map(fn: (r) => ({ ... }))
  • 19. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" data |> map(fn: (r) => ({ r with sent: ... }))
  • 20. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" data |> map(fn: (r) => ({ r with sent: slack.message( url: "https://slack.com/api/chat.postMessage", token: "mYSuP3rSecR37T0kEN", channel: "#mychannel", text: "Oh no! *${r.tag} had a value of *${r._value}*.", color: "danger" }))
  • 21. © 2021  InfluxData Inc. All Rights Reserved. 21 © 2021  InfluxData Inc. All Rights Reserved. Endpoint convention
  • 22. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. endpointFn(...) => (mapFn) => (tables=<-)
  • 23. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" data
  • 24. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" data |> slack.endpoint(...)
  • 25. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" data |> slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: "mYSuP3rSecR37T0kEN" )
  • 26. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" data |> slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: "mYSuP3rSecR37T0kEN" )(mapFn: (r) => ({ channel: "#mychannel", text: "Oh no! *${r.tag} had a value of *${r._value}*.", color: "danger" }))
  • 27. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "slack" data |> slack.endpoint( url: "https://slack.com/api/chat.postMessage", token: "mYSuP3rSecR37T0kEN" )(mapFn: (r) => ({ channel: "#mychannel", text: "Oh no! *${r.tag} had a value of *${r._value}*.", color: "danger" }))()
  • 28. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "influxdata/influxdb/monitor" import "influxdata/influxdb/secrets" import "slack" notification_data = {...} token = secrets.get(key: "SLACK_TOKEN") endpoint = slack.endpoint(token: token)(mapFn: (r) => ({ channel: "#mychannel", text: "Oh no! *${r.tag} had a value of *${r._value}*.", color: "#000" })) monitor.from(start: -1h, fn: (r) => r._level == "crit”) |> monitor.notify(endpoint: endpoint, data: notification_data)
  • 29. © 2021  InfluxData Inc. All Rights Reserved. 29 © 2021  InfluxData Inc. All Rights Reserved. Custom notifications
  • 30. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. http.post( url: "...", headers: "...", data: bytes(v: "...") )
  • 31. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "http" tweet = (status, oauth) => { }
  • 32. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "http" tweet = (status, oauth) => { apiURL = "https://api.twitter.com/1.1/statuses/update.json" }
  • 33. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "http" tweet = (status, oauth) => { apiURL = "https://api.twitter.com/1.1/statuses/update.json" return http.post( ) }
  • 34. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "http" tweet = (status, oauth) => { apiURL = "https://api.twitter.com/1.1/statuses/update.json" return http.post( url: "${apiURL}?status=${http.pathEscape(inputString: status)}" headers: {Authorization: "OAuth ${oauth}"} ) }
  • 35. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "http" tweet = (status, oauth) => {...} tweet( status: "This tweet was created by Flux and InfluxDB!", oauth: "..." )
  • 36. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "http" tweet = (status, oauth) => {...} tweet( status: "This tweet was created by Flux and InfluxDB!", oauth: "..." )
  • 37. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "http" tweet = (status, oauth) => {...} oauth: "..." data |> map(fn: (r) => ({ r with sent: }))
  • 38. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "http" tweet = (status, oauth) => {...} oauth: "..." data |> map(fn: (r) => ({ r with sent: tweet( status: "At ${r._time}, ${r._field} was ${r._value}.", oauth: oauth ) }))
  • 39. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. http.endpoint(url: "...") => (mapFn: (r) => ({ headers: "...", data: bytes(v: "...") })) => (tables=<-)
  • 40. © 2021  InfluxData Inc. All Rights Reserved. © 2021  InfluxData Inc. All Rights Reserved. import "http" import "influxdata/influxdb/monitor" apiURL = "https://api.twitter.com/1.1/statuses/update.json" oauth = "..." notification_data = {...} endpoint = http.endpoint( url: "${apiURL}" )(mapFn: (r) => ({ url: "${apiURL}?status=${http.pathEscape(inputString: r._message)}", headers: {Authorization: "OAuth ${oauth}"}, data: bytes(v: "") })) monitor.from(start: -1h) |> monitor.notify(endpoint: endpoint, data: notification_data)
  • 41. © 2021  InfluxData Inc. All Rights Reserved. Demo!
  • 42. © 2021  InfluxData Inc. All Rights Reserved. Questions?
  • 43. © 2021  InfluxData Inc. All Rights Reserved. Thank You