GithubHelp home page GithubHelp logo

slebetman / sendgrid-event-logger Goto Github PK

View Code? Open in Web Editor NEW
4.0 4.0 6.0 268 KB

Small, fast http server to log Sendgrid Event API callback to Elasticsearch

License: GNU General Public License v2.0

JavaScript 100.00%

sendgrid-event-logger's Introduction

Logo Sendgrid Event Logger

Small, fast http server to log Sendgrid Event Webhook callback to Elasticsearch

Kibana

Monitoring sendgrid events on Kibana dashboard

npm stats

Build Status codecov

Installing

Just install globally with npm:

npm install -g sendgrid-event-logger

Setup

  1. Install and run Elasticsearch. Refer to the docs for details: https://www.elastic.co/guide/en/elasticsearch/reference/current/_installation.html

  2. Install the default config file by running:

     sendgrid-event-logger install
    

    If you're running elasticsearch on a port other than 9200 the above command will generate an error. Don't worry about it for now.

  3. Check /etc/sendgrid-event-logger.json and edit if necessary.

  4. To run the server, simply type:

     sendgrid-event-logger
    

    It is highly recommended that you run the server using a process manager like PM2 or forever.

  5. Configure your Sendgrid account to point the Event Webhook to:

     http://your.server.address:port/logger
    

    Refer to the docs for how to set up the Event Webhook: https://sendgrid.com/docs/API_Reference/Webhooks/event.html

    Note: If you enable basic auth then set the URL to:

     http://username:[email protected]:port/logger
    

Integrating with Kibana

  1. Install Kibana. Refer to the docs for details: https://www.elastic.co/guide/en/kibana/current/setup.html

  2. Configure a new index pattern.

    • Select "Index contains time-based events" checkbox

      Kibana config

    • In the "Index name or pattern" entry type: mail-*

      Kibana config

    • In the "Time-field name" entry select "timestamp"

      Kibana config

    • Press "Create"

Configuration

The config file is located at: /etc/sendgrid-event-logger.json. The following are the configurations available:

  • elasticsearch_host Location of the elasticsearch server.

  • port The port the server listens on

  • use_basicauth Enable or disable basic authentication

  • basicauth.user Login username if basicauth is enabled

  • basicauth.password Login password if basicauth is enabled

  • use_https Enable or disable TLS

  • https.key_file Location of TLS key file on disk

  • https.cert_file Location of TLS certificate file on disk

  • days_to_retain_log Number of days to keep logs. Logs older than this will be deleted periodically. Set to 0 or false to disable automatic deletion of old logs.

    Note: I've personally found that elasticsearch takes up roughly 200MB of disk space for every 100000 emails delivered by Sendgrid. So you can use it as a rough guideline to calculate how much disk you need. For example, if you send 200k emails per month on average then you'd need 400MB per month or roughly 5GB per year. You can then set days_to_retain_log appropriately depending on how much disk space you have.

Implementation details

All sendgrid events are logged to a time-series index with the prefix mail-. The server logs events to a new index each day similar to how logstash works.

By default the server listens to port 8080 but this can be changed in the config file.

The server exposes 4 URL endpoints:

  • POST /logger This receives data from Sendgrid Event Webhook callback It expects the data to be an array of events. At minimum, the data format must be at least:

      [
          {
              timestamp: ${unix_timestamp}
          }
      ]
    

    The only mandatory field is timestamp. Which means you can also post your own events to this URL if you want to correlate your data with sendgrid events.

  • GET /status This simply returns {status:'ok'}. This URL may be used to check if the server is still alive.

  • GET /copyright Returns copyright and license information.

  • GET /version Returns version information.

License

Copyright (C) 2016 TrustedCompany.com

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 (GPL-2.0) as published bythe Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

sendgrid-event-logger's People

Contributors

slebetman avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.