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

(feature) webhook alerts #244

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

pro1code1hack
Copy link
Contributor

@pro1code1hack pro1code1hack commented Jul 11, 2024

Please describe your changes using the checklist below.

Self-hosted support

  • Your feature is implemented for the selfhosted version of Swetrix
  • This PR only updates the production code (e.g. paddle webhooks, CAPTCHA, blog, etc.)

Database migrations

  • Clickhouse / MySQL migrations added for this PR
  • No table schemas changed in this PR

Documentation

  • You have updated the documentation according to your PR
  • This PR did not change any publicly documented endpoints

How to test this feature:

  • Insert the following data into the db
mysql> select * from users_webhooks;
+--------------------------------------+--------------------------------------+------+-------------------------------+----------------------------+----------------------------+
| id                                   | userId                               | name | url                           | createdAt                  | updatedAt                  |
+--------------------------------------+--------------------------------------+------+-------------------------------+----------------------------+----------------------------+
| f04816b4-7516-44ba-9fb3-82e065667785 | c6df6997-80a9-4b27-9248-a15af0b97ca9 | Test | http://localhost:3000/webhook | 2024-07-11 21:12:51.266892 | 2024-07-12 20:05:35.460372 |
+--------------------------------------+--------------------------------------+------+-------------------------------+----------------------------+----------------------------+
  • Create express JS server
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = 3000;

app.use(bodyParser.json());

app.post('/webhook', (req, res) => {
    console.log('Received webhook:', req.body);

    res.status(200).send('Webhook received');
});

app.listen(port, () => {
    console.log(`Webhook receiver listening at http://localhost:${port}`);
});

You should see the following output in the console:

 {
  event: 'user.alert.metrics',
  data: {
    alertName: 'Test Alert',
    projectName: 'Your awesome project',
    count: 0,
    queryMetric: 'page_views',
    queryCustomEvent: null,
    queryTime: '0'
  }
}

@pro1code1hack pro1code1hack force-pushed the feature/webhook_alerts branch from 144d255 to d28637f Compare July 12, 2024 21:16
@pro1code1hack pro1code1hack requested a review from Blaumaus July 12, 2024 21:54
@pro1code1hack pro1code1hack self-assigned this Aug 3, 2024
@CLAassistant
Copy link

CLAassistant commented Nov 21, 2024

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants