Skip to content

Commit

Permalink
Merge pull request #3064 from CounterpartyXCP/slack
Browse files Browse the repository at this point in the history
Slack webhook after a rebuild
  • Loading branch information
ouziel-slama authored Mar 4, 2025
2 parents 56f1a5a + 2d66cd9 commit d7b9460
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()
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}")
return False
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 @@ -43,6 +43,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 d7b9460

Please sign in to comment.