GithubHelp home page GithubHelp logo

getsentry / sentlog Goto Github PK

View Code? Open in Web Editor NEW
17.0 3.0 2.0 38 KB

CLI util for parsing arbitrary text data and sending error-like events to Sentry

License: MIT License

Makefile 2.25% Go 94.82% Dockerfile 1.86% Shell 1.08%
sentry logging grok golang go tag-non-production

sentlog's Introduction

sentlog

This is a Sentry Hackweek project! Development may stop anytime. You've been warned.

sentlog is a command-line tool that can read arbitrary text files (e.g., webserver or database logs), search for specific user-defined patterns, and report the findings to Sentry.

Table of Contents

Introduction

Sentry provides SDKs for a lot of different platforms and frameworks. However, you might also want to use Sentry for parts of your infrastructure that were not developed by you, or don't have an integration with Sentry (yet): databases, web servers, and even operating system kernels. What do these tools have in common? They normally have some sort of output (i.e. logs), where both regular events and errors are usually logged. So why not parsing those logs and look for entries that look like errors? We can do that. And what platform do we usually use for error management? Sentry, of course!

And this is when sentlog steps in.

Downloads

sentlog binaries can be downloaded from GitHub releases.

Command Line Arguments

usage: sentlog [<flags>] [<file>]

Flags:
      --help             Show context-sensitive help (also try --help-long and --help-man).
  -p, --pattern=PATTERN  Pattern to look for
      --dry-run          Dry-run mode
      --no-follow        Do not wait for the new data
      --from-line=-1     Start reading from this line number
  -c, --config=CONFIG    Path to the configuration
  -v, --verbose          Print every match

Args:
  [<file>]  File to parse

sentlog can operate in two modes:

  1. Basic: filename and pattern are specified on the command line
  2. Advanced: using the configuration file provided by --config argument

Example

The following example shows how you can run sentlog in Basic mode.

export SENTLOG_SENTRY_DSN="https://[email protected]/YYY"   # Your Sentry DSN
sentlog /var/log/postgresql/postgresql-9.6.log \
        -p '^%{DATESTAMP:timestamp}.*FATAL:.*host "%{IP:host}", user "%{USERNAME:user}", database "%{WORD:database}"'

...will watch the PostgreSQL log (/var/log/postgresql/postgresql-9.6.log) for events that look like this:

2019-05-21 08:51:09 GMT [11212]: FATAL: no pg_hba.conf entry for host "123.123.123.123", user "postgres", database "testdb"

sentlog will extract the timestamp, IP address, username, and database from the entry, and will add them as tags to the Sentry event.

Configuration File

---
# Sentry DSN (also can be configured via environment)
sentry_dsn: https://[email protected]/YYY
# Additional Grok pattern files
pattern_files:
  - ./patterns1.txt
  - ../patterns2.txt

# List of files that we want to watch
inputs:
  - file: /var/log/nginx/error.log
    # Patterns to find and report
    patterns:
      - "%{NGINX_ERROR_LOG}"
    # Additional tags that will be added to the Sentry event
    tags:
      pattern: nginx_error
      custom: tag

About Patterns

sentlog uses Grok patterns to match your data. A cool thing about Grok expressions is that they can be nested, which lets you to define complex matching expressions based on smaller building blocks (example).

This Grok debugger can be quite helpful when preparing your Grok expressions: https://grokdebug.herokuapp.com/

sentlog's People

Contributors

aldy505 avatar tonyo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.