Skip to main content

redashsync is a tool integrating Redash with Slack. It gets data from Redash and send it to Slack channel.

Install

pip install redashsync

How to get necessary keys

Redash API Key and Query ID

Click Show API Key and You would get below address.

http://localhost/api/queries/2/results.json?api_key=2CHjsILfC3fD4Q8nJU7IejS2CuRtKG8lKztY1HOk

Your API Key : 2CHjsILfC3fD4Q8nJU7IejS2CuRtKG8lKztY1HOk

Your Query ID : 2

Slack Bot Token and Setting

https://api.slack.com/apps

Create New App.

Get Your Bot Token.

Add an OAuth Scope. 1) chat:write 2) files:write

Invite your slack bot.

Your YAML

Follow the format below to complete your yaml file.

# ./resource/sample.yml

slack_configs:
  slack:
    token: <YOUR_SLACK_BOT_TOKEN> # "xoxb-***-***-***"
    username: <YOUR_USER_NAME> # "redash-echo"

redash_configs:
  url: <YOUR_HOST> # "http://localhost"
  user_email: <YOUR_EMAIL> # "myname@example.com"
  query_api_key: <YOUR_QUERY_API_KEY>  # "2CHjsILfC3fD4Q8nJU7IejS2CuRtKG8lKztY1HOk"

Use

Send messages regularly

from redashsync.redash.data import Redash
from redashsync.slack.messages import Slack
from redashsync.config.yaml import Config
from datetime import datetime
from cron_converter import Cron

config = Config("./resource/sample.yml")
redashHost = config.getRedashHost()
redashQueryKey = config.getQueryApiKey()
redashQueryId = config.getQueryId()
slackBotToken = config.getSlackBotToken()

redash = Redash(redashHost)
slack = Slack(slackBotToken)

cron = Cron()
cron.from_string("*/1 * * * *") # Send every 1 minute
referenceTime = datetime.now()
schedule = cron.schedule(referenceTime)
expectedTime = schedule.next().isoformat()

while True:
    if(expectedTime == datetime.now().isoformat()[0:19]):
        print(expectedTime)
        expectedTime = schedule.next().isoformat()

        response = redash.getQueriesFromRedash(redashQueryId, redashQueryKey)
        result = redash.getColumnData(response, ['Open', 'Close'])
        # result : [ [123, 456], [789, 987], ... ]
        
        template = "*시가* : %s \n*종가* : %s \n"
        
        # 2 is inside array's length.
        result = redash.getMarkdown(template, result[0:5], 2)

        # "#redash-echo" is channel name.
        slack.sendMessage("#redash-echo", result)

Send a graph image

from redashsync.redash.data import Redash
from redashsync.slack.messages import Slack
from redashsync.config.yaml import Config
from datetime import datetime
from cron_converter import Cron

config = Config("./resource/sample.yml")
redashHost = config.getRedashHost()
redashQueryKey = config.getQueryApiKey()
redashQueryId = config.getQueryId()
slackBotToken = config.getSlackBotToken()

redash = Redash(redashHost)
slack = Slack(slackBotToken)

# Histogram
response = redash.getQueriesFromRedash(redashQueryId, redashQueryKey)
result = redash.getColumnData(response, ['Open', 'Close'])

# If you want to name image one.png and locate it at ./resource 
redash.visualizeHistplotAndSave(result, "./resource/one.png")
slack.sendFile("./resource/one.png", "#redash-echo", "Title", "comment")

Release files for redashsync 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for redashsync 0.0.8
File Size Uploaded
redashsync-0.0.8.tar.gz 5.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for redashsync 0.0.8
File Interpreter ABI Platform
redashsync-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 12.3 kB

Release files / redashsync-0.0.8.tar.gz

Download URL redashsync-0.0.8.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
ea0561b2b281cacb3c8f8149ee614f2350174a1f9543498434304ce9e8cadc14
BLAKE2b-256 checksum
How to use checksums
7d275cafe235744f9b48c169e610cb96ea53f8f954f178b813ee036886f93074
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release files / redashsync-0.0.8-py3-none-any.whl

Download URL redashsync-0.0.8-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
109d3c86a7eb1e1481c1376df37b959abebcb17a21e61b40fc7ae147f15f4995
BLAKE2b-256 checksum
How to use checksums
14c86ffa64b10647075acb86447157f34063c14e611dc4045f24405501ac393d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page