Metadata-Version: 2.4
Name: fastalert
Version: 0.0.2
Author-email: Nathan Cooper <nathanacooper@proton.me>
License-Expression: Apache-2.0
Project-URL: Repository, https://github.com/AnswerDotAI/fastalert
Project-URL: Documentation, https://AnswerDotAI.github.io/fastalert/
Keywords: nbdev
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastlite
Requires-Dist: python-fasthtml
Dynamic: license-file

# fastalert


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

## Usage

### Installation

Install latest from the GitHub [repository](https://github.com/AnswerDotAI/fastalert):

``` sh
$ pip install git+https://github.com/AnswerDotAI/fastalert.git
```

or from [pypi](https://pypi.org/project/fastalert/)

``` sh
$ pip install fastalert
```

### Documentation

Documentation can be found hosted on this GitHub [repository](https://github.com/AnswerDotAI/fastalert)’s [pages](https://AnswerDotAI.github.io/fastalert/). Additionally you can find package manager specific guidelines on [pypi](https://pypi.org/project/fastalert/) respectively.

## How to use

To start your `fastalert` server, you can run the following in your terminal:

``` python
!fastalert --port 6001
```

    Link: http://localhost:6001
    INFO:     Will watch for changes in these directories: ['/home/natedawg/aai-ws/fastalert/nbs']
    INFO:     Uvicorn running on http://0.0.0.0:6001 (Press CTRL+C to quit)
    INFO:     Started reloader process [64466] using WatchFiles
    INFO:     Started server process [64502]
    INFO:     Waiting for application startup.
    INFO:     Application startup complete.
    ^C
    INFO:     Shutting down
    INFO:     Waiting for application shutdown.
    INFO:     Application shutdown complete.
    INFO:     Finished server process [64502]
    INFO:     Stopping reloader process [64466]

`fastalert` supports token based authentication. To enable authentication, store your token in `FASTALERT_API_KEY` environment variable before starting your `fastalert` server.

`fastalert` supports two kinds of alerts. Immediate and heartbeat. Immediate alerts does not wait any set amount of time before sending the alert whereas heartbeat alerts wait a specific amount of time and can be canceled. To configure an immediate alert, you need to provide the name and the url you want to be alerted:

``` python
!curl -X POST http://localhost:6001/alert -H 'Content-Type: application/json' -d '{"name": "test", "url": "https://httpbingo.org/post"}'
```

The url will be send a post request with the following data: `{"content": "An alert has been triggered for test."`.

For heartbeats, you send to also specify the time to wait in seconds before triggering the alert:

``` python
!curl -X POST http://localhost:6001/heartbeat -H 'Content-Type: application/json' -d '{"name": "test", "url": "https://httpbingo.org/post", "ttl": 5}'
```

Resending a post request to the [`heartbeat`](https://AnswerDotAI.github.io/fastalert/core.html#heartbeat) route will cancel the previous alert timer for the alert with the same `name` and rearm the new one with the provided `ttl`.
