Giter VIP home page Giter VIP logo

critbot's Introduction

critbot

Sending critical errors from python to syslog, slack, email, {your_plugin}.

Install:

pip install critbot

Add to "config.py" file:

import critbot.plugins.syslog
import critbot.plugins.slack
import critbot.plugins.email
from critbot import crit_defaults
import logging

crit_defaults.subject = 'MyService host:port CRIT'

crit_defaults.plugins = [
    critbot.plugins.syslog.plugin(),
    critbot.plugins.slack.plugin(
        token='Get it from https://my.slack.com/services/new/bot',
        channel='#general', # '@private' or '#channel'
        users='', # '@user1 @user2 @userN'
    ),
    critbot.plugins.email.plugin(
        to='Name1 <[email protected]>, Name2 <[email protected]>',
        user='[email protected]', # Add more config if not GMail.
        password='pa$$word',
    ),
]

crit_defaults.crit_in_crit = logging.getLogger('critbot').critical

Check other config options and their defaults, e.g. "seconds_per_notification=60" and "spam=False":

Use "crit" in other files of your project:

from my_project import config
from critbot import crit

try:
    1/0
except Exception:
    crit()
    # More processing if needed.

try:
    1/0
except Exception:
    crit(also='test2')

if True:
    crit('test3')

If you are using http://supervisord.org/
then you can monitor stderr, EXITED and FATAL states with:

[eventlistener:critvisor]
command=critvisor /path/to/config.py
events=PROCESS_LOG_STDERR,PROCESS_STATE_EXITED,PROCESS_STATE_FATAL

[program:my_program]
stderr_events_enabled=true

Optional "crit_defaults.skip_stderrs" list allows to avoid some "safe" crits.
Optional "crit_defaults.max_stderr_crit_length" allows to save e.g. Slack from being broken.

If you want to convert stderr of your small scripts to crits:

stdcrit /path/to/config.py /path/to/script.py arg...

To stop spam from multiple processes on the same host:

crit_defaults.stop_spam_file.enabled = True
# "crit_defaults.stop_spam_file.path" defaults to "/run/lock/critbot" - RAM, no disk IO.

To stop spam from multiple hosts:

apt-get install libmemcached-dev zlib1g-dev
pip install pylibmc
crit_defaults.mc.enabled = True

And either "apt-get install memcached"
or update "crit_defaults.mc.servers" list.

Please fork https://github.com/denis-ryzhkov/critbot
and create pull requests with new plugins inside.

critbot version 0.1.19
Copyright (C) 2015-2016 by Denis Ryzhkov [email protected]
MIT License, see http://opensource.org/licenses/MIT

critbot's People

Contributors

denis-ryzhkov avatar

Watchers

James Cloos 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.