An integration to feed weather alerts from AccuWeather into Big Pandas Alert API
Depends on Panda Flask API for message queueing. For testing purposes, there is a
-d option for the send command, which will send alerts directly to BigPanda.
graph TD;
A(alerts2panda) --> |request current conditions| B[[AccuWeather]];
B --> |Response with current conditions| A;
A --> |Send data| C((Panda Flask API));
A --> |Get Queue Status| C;
A --> |HealthCheck| C;
C --> |Queue message| D[(RabbitMQ)];
D --> |Consume Queue| C;
C --> |Send Alert| E[[BigPanda Alert API]];
C --> |Send to DLQ on failure| D;
%% Set the classes.
classDef app fill:#8FD27F,font-size:16px,color:#000000;
classDef api fill:#A2C3FB,font-size:16px,color:#000000;
classDef db fill:#FABE78,font-size:16px,color:#000000;
%% Assign the classes.
class A app;
class B,C,E api;
class D db;
The following commands are assuming alerts2panda is installed with setup.py. This is how it would normally
run in Docker. Also, you can achieve this running in docker by placing the alerts2panda Bash script in /usr/bin.
There are 3 different objects in the alerts2panda.yaml configuration file. This configuration file can be mounted
in the docker image to /alerts2panda. You can pass a config to a different config file using
alerts2panda -c /path/to/config.yaml.
Environment variables can be read from the config file. To read from ENV Vars, use the tag !ENV with the following format:
zipcode: !ENV ${ZIPCODE}
The integration searches for the !ENV tag, which triggers the Environment Variable lookup. You can also just hardcode the value in the config file.
A .env file can also be used to load environment variables. The integration uses python-dotenv to load variables found in a .env file.
Make sure to use all UPPERCASE names for Environment Variables.
There are 2 ways to pull current weather conditions, both which rely on a location key.
- Zip Code
- Public IP Address
The zip code can be passed in the config file or by using the -z flag. If no zip code is found the integration sends a request to ifconfig.me, which returns
your public ip address. Keep this in mind if you are using a VPN, as the IP Address will be local to the VPN endpoint.
Usage: alerts2panda [OPTIONS] COMMAND [ARGS]...
An integration for sending weather conditions to BigPanda's alert API.
Default is to pull weather conditions based on zipcode loaded from either
environment variables, or passed into the integration as an optional command
line argument.
You can override the ENV option by setting the zipcode value in config.
config path for zipcode: weather.api.location.zip.code
Options:
-c, --config PATH Config file.
-d, --debug Debug output STDERR
-v, --verbose All logging modules printed to output.
-z, --zipcode TEXT Zip can be passed in, or set in config to load from env
vars: !ENV ${ZIPCODE}
--help Show this message and exit.
Commands:
healthcheck Gets a healthcheck status from the Panda Flask API
send Sends an AccuWeather Alert to BigPanda's Alert API.
status Checks the status of the RabbitMQ Main Queue and DLQ
Usage: alerts2panda send [OPTIONS]
Sends an AccuWeather Alert to BigPanda's Alert API. This command sends a
request to the Panda Flask API, which then forwards the alert to RabbitMQ
for processing.
You can bypass the Flask server by passing in the -d, --direct flag, which
sends the alert directly to BigPanda. Understand that this will also bypass
the message queue and could cause alerts to be undeliverable.
You can override the status of the alert by passing the -s, --status. Use
this option to force a static alert status.
Options:
-s, --status [ok|warn|crit|ack]
Override the alert status
-d, --direct Sends an alert directly to BigPanda,
bypassing the Flask API
-r, --raw Raw output to stdout for parsing with JQ
--help Show this message and exit.
Usage: alerts2panda status [OPTIONS]
Checks the status of the RabbitMQ Main Queue and DLQ
Options:
-r, --raw Raw output to stdout for parsing with JQ
--help Show this message and exit.
Usage: alerts2panda.py healthcheck [OPTIONS]
Gets a healthcheck status from the Panda Flask API
Options:
-r, --raw Raw output to stdout for parsing with JQ
--help Show this message and exit.
Build the docker image from the root directory of Panda-Weather-Alerts with the following command:
DOCKER_BUILDKIT=1 docker build . -t alerts2panda:latest
This will build an image called alerts2devo:latest, which you can verify with docker image ls. The image is
built with an entrypoint, so docker run will run the base command of alerts2devo and print the --help message
if no arguments are passed.
alerts2devo has a few ENV Variables, which will automatically be loaded if a .env file is mounted.
There are a couple of methods to load ENVs, but you can also just write everything into a config file and mount it to the container.
I'll list a few methods here, which all work to get you up and running.
The following ENV Vars are available in the Docker image:
- WEATHER_TOKEN
- ZIPCODE
- PANDA_BEARER_TOKEN
- PANDA_APP_KEY
If running Panda Flask API in docker with and nginx-proxy, you need to configure your container to reach the local domains set up in that walkthrough.
To reach a service being proxied by an NGINX server, make sure to connect to the host docker network. This will help bypass any docker networking issues you may have.
- Mount a config file and .env file (should you be using one) and run the container:
sudo mkdir /etc/alerts2pandasudo cp alerts2panda.yaml .env /etc/alerts2pandadocker run --rm -it --network host -v /etc/alerts2panda:/alerts2panda alerts2panda [OPTIONS] [COMMAND]
- Pass in the ENV Vars to docker run and run the integration:
docker run --rm -it \
-e WEATHER_TOKEN=<AccuWeather API Token> \
-e PANDA_APP_KEY=<integration app key> \
--network host \
alerts2panda
Create a bash script to run the docker run command with the following command in /usr/local/bin/alerts2panda:
docker container run --rm -v /etc/alerts2panda:/alerts2panda -e WEATHER_TOKEN=<AccuWeather API Token> -e PANDA_APP_KEY=<BigPanda App Key> -e PANDA_BEARER_TOKEN=<BigPanda bearer token> --network host alerts2panda:latest $@- The
$@directs input as commands to alerts2panda container - The --network
hostwill allow you to connect to the nginx-reverse proxy if one is being used locally for testing
- The
Make it executable
sudo chmod +x /usr/local/bin/alerts2panda
Make an alias entry in ~/.bashrc:
alias alerts2panda=/usr/local/bin/alerts2panda
Source ~/.bashrc or launch a new terminal. You should now be able to call the docker container as follows:
alerts2panda --help