惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

雷峰网
雷峰网
小众软件
小众软件
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
V
V2EX
aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
Forbes - Security
Forbes - Security
Project Zero
Project Zero
Microsoft Security Blog
Microsoft Security Blog
Cyberwarzone
Cyberwarzone
Security Latest
Security Latest
S
Securelist
NISL@THU
NISL@THU
B
Blog RSS Feed
爱范儿
爱范儿
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
Darknet – Hacking Tools, Hacker News & Cyber Security
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Hacker News: Front Page
F
Full Disclosure
J
Java Code Geeks
Recent Commits to openclaw:main
Recent Commits to openclaw:main
The Hacker News
The Hacker News
L
LangChain Blog
Google DeepMind News
Google DeepMind News
I
InfoQ
Last Week in AI
Last Week in AI
S
Security @ Cisco Blogs
PCI Perspectives
PCI Perspectives
IT之家
IT之家
P
Proofpoint News Feed
AI
AI
Hacker News - Newest:
Hacker News - Newest: "LLM"
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Martin Fowler
Martin Fowler
L
LINUX DO - 热门话题
T
Tenable Blog
M
MIT News - Artificial intelligence
N
News | PayPal Newsroom
Blog — PlanetScale
Blog — PlanetScale
Recorded Future
Recorded Future
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏

轶哥博客

blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog blog
blog
2021-03-10 · via 轶哥博客

转眼间使用Redash已经两年多了,redash给我的感觉就是省心省事。基础需求都能实现,用户体验很好,升级版本也容易,二次开发也方便简单。

只不过有两个需求redash没有实现:

  • API刷新整个仪表盘
  • 导出仪表盘中所有的Widget数据为Excel文件

第二个需求,我在《Redash导出仪表盘中所有数据为Excel文件》一文进行了实现说明。

需求分析

redash.png

Refresh按钮可以设置定时刷新,但是某些情况下我们需要根据条件触发刷新。

或者在内网部署,通过iframe将Share的链接嵌入到OA系统。分享链接不具备刷新功能。

刷新整个仪表盘

官方API文档中就有关于刷新整个仪表盘的说明,指向了这个文件:https://github.com/getredash/redash-toolbelt/blob/master/redash_toolbelt/examples/refresh_dashboard.py

执行上面的代码需要安装Poetry,可以参考《Poetry快速安装教程》。

安装poetry后,安装依赖:

poetry install

然后可以执行:

poetry run python3 redash_toolbelt/examples/refresh_dashboard.py https://example.com API_Key slug

实现对相应slug的仪表盘所有query进行刷新。

refresh_dashboard.py代码默认的刷新周期需要手动进行修改:

params = {
  "created_at": {
    # p.get("name"): fill_dynamic_val(todays_dates, p)
    # for p in qry["options"].get("parameters", [])
    "start": str(start) + " 00:00:00",
    "end": str(end) + " 23:59:59"
  }
}

封装命令为API

from flask import Flask
import subprocess, json

app = Flask(__name__)


@app.route("/")
def welcome():
    output = subprocess.check_output(["poetry run python3 redash_toolbelt/examples/refresh_dashboard.py https://example.com API_Key slug"], shell = True)
    out = output.decode()
    return json.dumps({"out": out},ensure_ascii=False)


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5001)

访问http://127.0.0.1:5001即可实现对指定仪表盘进行刷新。

这个实现方法过于简单除暴,只适用于临时使用,正式实现还是参考redash_toolbelt代码来写吧。