Code Monkey home page Code Monkey logo

bell's Introduction

๐Ÿ›Ž Bell

A tool to send you alerts from your AWS instances

Quickstart

Install

pip install git+https://github.com/MantisAI/bell.git@main

Use bell ๐Ÿ›Ž to get alerts that your AWS instance is on

bell --webhook-url SLACK_WEBHOOK_URL

Use bell ๐Ÿ›Ž to get alerts about when a command starts, fails or finishes

export SLACK_WEBHOOK_URL=xxx

bell python -c "print('hello')"

Note that you can pass the slack webhook URL either as a command line parameter --webhook-url or as an environment variable SLACK_WEBHOOK_URL

You can capture the output of the process by passing the --capture-output option. This will then get printed to slack.

bell --cpature-output python -c "print('hello')"

The results will be printed in slack as:

๐Ÿ›Ž๏ธ command python -c print('hello') started ๐Ÿš€

hello

๐Ÿ›Ž๏ธ command python -c print('hello') finished ๐Ÿ’ฅ

You can read how to setup a slack webbook here

Cron

This tool works well with a scheduler like cron. Here is an example cron command which sends an alert every 2 hours

SLACK_WEBHOOK_URL=xxx

0 */2 * * * bell

Note that cron's environment is different to your user or root environment. See troubleshooting if you have problems setting up bell to work with cron.

CLI

usage: bell [-h] [--webhook-url WEBHOOK_URL]

optional arguments:
  -h, --help            show this help message and exit
  --webhook-url WEBHOOK_URL
                        incoming slack webhook url

Troubleshooting

Logs

By default bell sets the logging level at INFO. For debugging purposes, it is more helpful to set it at DEBUG. You can do that via the environment variable LOGGING_LEVEL by running

export LOGGING_LEVEL=DEBUG

Bell works when run manually but not through cron

In order for cron to work it needs to have access to both bell, python packages and AWS credentials. For this reason we recommend you install a cron job under your user account and not root, otherwise you might need to install the tool with sudo and ensure root has access to AWS credentials.

Even in that case as it turns out cron has a different more minimal PATH than what you see in the terminal if you run echo $PATH. For that reason, you should probably define the same PATH in your cron job as the one you see when you test the tool.

Region not specified

We assume you have AWS credentials setup either through environment variables, aws configure or proper IAM roles. We use boto under the hood to query AWS, see its documentation around credentials here

bell's People

Contributors

nsorros avatar ivyleavedtoadflax avatar

Stargazers

 avatar

Watchers

 avatar

bell's Issues

Import Error

Just installed from main in a virtualenv with pip install .:

bell https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                                                 Traceback (most recent call last):
  File "/home/matthew/Documents/mantis/bell/bell/bin/bell", line 5, in <module>
    from bell import cli
ImportError: cannot import name 'cli' from 'bell' (unknown location)

Must specify a region

Just installed on an ec2 instance and received the following:

ubuntu@ip-XXX-XX-XX-XXX:~$ pip install pip install git+https://github.com/MantisAI/bell.git
ubuntu@ip-XXX-XX-XX-XXX:~$ bell https://hooks.slack.com/services/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx
Traceback (most recent call last):
  File "/home/ubuntu/.local/bin/bell", line 8, in <module>
    sys.exit(app())
  File "/home/ubuntu/.local/lib/python3.8/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/typer/main.py", line 500, in wrapper
    return callback(**use_params)  # type: ignore
  File "/home/ubuntu/.local/lib/python3.8/site-packages/bell.py", line 15, in bell
    ec2 = boto3.client("ec2")
  File "/home/ubuntu/.local/lib/python3.8/site-packages/boto3/__init__.py", line 92, in client
    return _get_default_session().client(*args, **kwargs)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/boto3/session.py", line 299, in client
    return self._session.create_client(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/session.py", line 884, in create_client
    client = client_creator.create_client(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/client.py", line 102, in create_client
    client_args = self._get_client_args(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/client.py", line 384, in _get_client_args
    return args_creator.get_client_args(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/args.py", line 71, in get_client_args
    final_args = self.compute_client_args(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/args.py", line 148, in compute_client_args
    endpoint_config = self._compute_endpoint_config(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/args.py", line 234, in _compute_endpoint_config
    return self._resolve_endpoint(**resolve_endpoint_kwargs)
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/args.py", line 320, in _resolve_endpoint
    return endpoint_bridge.resolve(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/client.py", line 465, in resolve
    resolved = self.endpoint_resolver.construct_endpoint(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/regions.py", line 196, in construct_endpoint
    result = self._endpoint_for_partition(
  File "/home/ubuntu/.local/lib/python3.8/site-packages/botocore/regions.py", line 230, in _endpoint_for_partition
    raise NoRegionError()
botocore.exceptions.NoRegionError: You must specify a region.

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.