Skip to content

Commit

Permalink
Slack webhook after a rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
Ouziel committed Mar 4, 2025
1 parent 9e2b2dd commit 2d66cd9
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions counterparty-core/counterpartycore/lib/cli/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from counterpartycore.lib.cli import bootstrap, log
from counterpartycore.lib.ledger.backendheight import BackendHeight
from counterpartycore.lib.ledger.currentstate import CurrentState
from counterpartycore.lib.monitors import slack
from counterpartycore.lib.parser import blocks, check, follow
from counterpartycore.lib.utils import database, helpers

Expand Down Expand Up @@ -183,6 +184,7 @@ def run_server(self):
blocks.catch_up(self.db)

if self.stop_when_ready:
slack.trigger_webhook()

Check warning on line 187 in counterparty-core/counterpartycore/lib/cli/server.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/cli/server.py#L187

Added line #L187 was not covered by tests
self.stop() # stop here
return

Expand Down
22 changes: 22 additions & 0 deletions counterparty-core/counterpartycore/lib/monitors/slack.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import logging
import os

import requests

from counterpartycore.lib import config

logger = logging.getLogger(config.LOGGER_NAME)


def trigger_webhook():
webhook_url = os.environ.get("SLACK_HOOK")
if not webhook_url:
return False
try:
response = requests.get(webhook_url, timeout=10)
response.raise_for_status()
logging.info("Message sent to slack")
return True
except requests.exceptions.RequestException as e:
logging.error(f"Error sending message to slack: {e}")

Check warning

Code scanning / pylint

Use lazy % formatting in logging functions. Warning

Use lazy % formatting in logging functions.
return False

Check warning on line 22 in counterparty-core/counterpartycore/lib/monitors/slack.py

View check run for this annotation

Codecov / codecov/patch

counterparty-core/counterpartycore/lib/monitors/slack.py#L12-L22

Added lines #L12 - L22 were not covered by tests
1 change: 1 addition & 0 deletions release-notes/release-notes-v11.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ counterparty-server start

## CLI

- Adds support for the `SLACK_HOOK` environment variable containing a webhook URL called after a rebuild

# Credits

Expand Down

0 comments on commit 2d66cd9

Please sign in to comment.