Skip to content
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

InfluxDB v2 - MS-Teams - Notification Endpoint #17939

Open
StefanSa opened this issue May 2, 2020 · 10 comments
Open

InfluxDB v2 - MS-Teams - Notification Endpoint #17939

StefanSa opened this issue May 2, 2020 · 10 comments
Labels
area/flux Issues related to the Flux query engine kind/feature-request team/ui

Comments

@StefanSa
Copy link

StefanSa commented May 2, 2020

Proposal:
Add MS-Teams as Endpoint Notification.

Current behavior:
No exist this option currently

Desired behavior:
I want to enable notifications of alerts and send them to a MS-Teams group.

Alternatives considered:
Describe other solutions or features you considered.

Use case:
It does not exist in Cronograf. That be great have in InfluxDB v2.

I know there is some antipathy to MS Teams.
All the more i hope that influxdata jumps over its own shadow and manages to implement this feature request.

@sranka
Copy link
Contributor

sranka commented Jun 10, 2020

This feature depends on influxdata/flux#2866, then it has to wait on a flux release with influxdata/flux#2866 and a flux upgrade (dependency update) in influxdata/influxdb master

@StefanSa
Copy link
Author

Hi there,
Any ETA for release of this feature?

@sranka sranka removed their assignment Feb 19, 2021
@S1r-Lanzelot
Copy link

Yes any update @russorat? I attended a webinar on Influxdb 2.0 and we asked the presenter specifically about MS Teams on their paid platform and they said it was supported.... I just signed up for InfluxDb Cloud and it is not supported. Are we missing something?

@russorat
Copy link
Contributor

@S1r-Lanzelot it is supported in the platform, just not exposed in the UI yet (although we are working on adding it). Here's a link to the docs for it: https://docs.influxdata.com/influxdb/cloud/reference/flux/stdlib/contrib/teams/

to use it, you will need to create a custom notification endpoint. there is an example of how to do that in this blog: https://www.influxdata.com/blog/influxdbs-checks-and-notifications-system/

@sawo1337
Copy link

@S1r-Lanzelot it is supported in the platform, just not exposed in the UI yet (although we are working on adding it). Here's a link to the docs for it: https://docs.influxdata.com/influxdb/cloud/reference/flux/stdlib/contrib/teams/

to use it, you will need to create a custom notification endpoint. there is an example of how to do that in this blog: https://www.influxdata.com/blog/influxdbs-checks-and-notifications-system/

Doesn't seem to be supported except for user-contributed custom function, which according to the docs "can be updated or removed at any time.". I doubt people would want to be depending on such a functionality. Over a year later, there is no change in that, seems like the product overall is still nearly a beta and far, far away from InfluxDB 1.8/Kapacitor in terms of functionality. Kapacitor can send messages to Teams without any custom functions, it is a shame InfluxDB can't do that years later.

@sawo1337
Copy link

If anyone is interested, I can post 30 lines php script here that you can put on your webserver and post to that via the default HTTP endpoint so it sends the webhook to Teams. It can be reduced further as well if you want message rather than the fancier message card. I know it would have been better to have it integrated, but at least it is a code that you can maintain yourself and make sure will work across versions, won't get removed, etc.

@sanderson
Copy link
Contributor

sanderson commented Dec 16, 2022

@sawo1337 The language about these user-contributed functions being removed at any time can probably be removed. This functions are here to stay. Although it's not a selectable option in the UI, you can create a custom task to send these notifications.

There are a few ways to send a notification to MS teams with Flux:

  • teams.endpoint(): (designed for the InfluxDB checks and notifications system) This function iterates over an input stream and sends a message to Teams for each row. This isn't my favorite method to use because the syntax and patterns used aren't that intuitive. It's designed to be a part of the backend of the GUI-based checks and notifications system.

  • map() with teams.message(): map() iterates over each input and then uses teams.message() to send a message to Teams. This essentially works the same way as teams.endpoint(), but is more intuitive and readable.

    import "contrib/sranka/teams"
    
    option task = {
        name: "Send alerts to MS Teams",
        every: 1h,
    }
    
    from(bucket: "example-bucket")
        |> range(start: -task.every)
        |> filter(fn: (r) => r._measurement == "example-measurement")
        |> filter(fn: (r) => r._field == "example-field")
        |> map(fn: (r) => ({r with level: if r._value >= 90.0 then "Critical" else if r._value >= 70.0 and r._value < 90.0 then "Warning" else "ok"}))
        |> filter(fn: (r) => r.level == "Warning" or r.level == "Critical")
        |> map(fn: (r) => {
                response = teams.message(
                    url: "https://outlook.office.com/webhook/example-webhook",
                    title: "${r.level}: ${r._field}",
                    text: "${r.level}: ${r._field} is ${r._value}",
                )
    
                return {r with responseCode: response}
            }
        )
  • teams.message(): Sends a single message to MS Teams using a scalar string.

    import "contrib/sranka/teams"
    
    option task = {
        name: "Hourly level summary",
        every: 1h,
    }
    
    data = from(bucket: "example-bucket")
        |> range(start: -task.every)
        |> filter(fn: (r) => r._measurement == "example-measurement")
        |> filter(fn: (r) => r._field == "example-field")
        |> map(fn: (r) => ({r with level: if r._value >= 90.0 then "Critical" else if r._value >= 70.0 and r._value < 90.0 then "Warning" else "ok"}))
    
    getCount = (tables=<-) =>
        (tables
            |> count()
            |> findColumn(fn: (key) => true, column: "_value")
        )[0]
    
    crit = data |> filter(fn: (r) => r.level == "Critical") |> getCount()
    warn = data |> filter(fn: (r) => r.level == "Warning") |> getCount()
    
    teams.message(
        url: "https://outlook.office.com/webhook/example-webhook",
        title: "1 hour level summary",
        text: "Critcal: ${crit}, Warning: ${warn}",
    )

@sawo1337
Copy link

@sanderson thanks a lot for the details! Confirming that sranka is permanent is definitely a good start! I'll test out the examples mentioned, if we can skip on the custom stuff, that would be a great.
PS. you've got a small typo (teams.messate())

@sawo1337
Copy link

@sanderson isn't this supposed to be "else if r._value >= 70.0 and r._value < 90.0 then"? with or I've got message about every value which was below 90 yet status was set to warning? Although changing the condition to "and" doesn't fire any messages.

@sanderson
Copy link
Contributor

sanderson commented Dec 19, 2022

@sawo1337 Yes, you're right. That logic was just thrown in there as placeholder, but that should be and instead of or.

Edit: I updated the examples above to reflect this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/flux Issues related to the Flux query engine kind/feature-request team/ui
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants