sql2slack alash3al 开源的又个轻量级工具
从名称上是sql 到slack 消息的处理,实际上可以支持基本上各类的webhook 处理
特性
- 小巧
- 支持多sql 引擎
- 可以通过underscore.js 自定义消息
- cron 语法格式的sql 任务调度
- 使用hcl 做为配置管理语言
- 对于大量job,可以直接基于文件的配置(启动的时候会扫描job定义文件)
job 格式
job tst {
// slack-channel webhook url
channel = "https://hooks.slack.com/services/xxxxxxxxxxxxxxxxxxxxx"
// which sql driver do you use?
driver = "mysql"
// data source name (connection string)
dsn = "root:root@tcp(127.0.0.1:3306)/dbname"
// the query this is a multiline example, you can just write the following
// query = "select * from users"
query = <<SQL
SELECT users.* FROM users;
SQL
// cron like syntax
schedule = "* * * * *"
// here you need to build the text message that will be sent
// to the slack channel.
// -------
// say(....): a function that will append the specified arguments into the main slack text message.
// log(....): a logger function, for debugging purposes.
// $rows: a variable that holds the output of the query execution.
message = <<JS
if ( $rows.length < 1 ) {
return
}
say("there are (", $rows.length, ") new users!")
say("users list is:")
_.chain($rows).pluck('name').each(function(name){
say("- ", name, " .")
})
JS
}
简单说明
上边的channel,可以替换为各类的webhook(比如钉钉webhook),目前消息处理系统提供了内建函数say(我们也可以发送json格式)
按照设计以及代码,我们可以在job 中支持多种数据库链接(使用多job 文件),注意文件格式为<name>..s2s.hcl
。
目前内置的js context
$rows sql 查询数据
log 记录log的
say 提供数据包装的函数,很简单,这个我们剋用扩展,返回值为string
整个技术栈 go-resty resty 处理,hashicorp/hcl hcl 解析处理,robfig/cron cron 表达式处理,robertkrimen/otto js 引擎,其他的主要是sql 处理的
基于sqlx,整个设计还是比较简介高效的,很不错和sqler代码模式一样
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
2017-06-29 keycloak 了解
2017-06-29 apiman 安装&&使用
2017-06-29 apiman 一个apigateway