sql2slack - send sql results periodically to slack

栏目: IT技术 · 发布时间: 4年前

SQL2Slack

a cron deamon that executes the specified sql query and forward its result to slack ()

Features

  • Tiny & Portable.
  • Works with multiple sql engine.
  • Customize the slack message using javascript as well underscore.js .
  • Cron like syntax for scheduling sql jobs.
  • Uses hcl language for structured configurations.
  • Ability to define a job per single file for future maintainability of large jobs.

Quick Overview

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
}

Integrating Slack

  1. Go there .
  2. Click on Create New App .
  3. Choose Incoming Webhooks and activate it.
  4. Scroll down to Add New Webhook to Workspace and follow the instructions.
  5. Scroll down to the webhooks table, and copy the generated webhook url.

Available SQL Drivers

Driver DSN
mysql usrname:password@tcp(server:port)/dbname?option1=value1&...
postgres postgresql://username:password@server:port/dbname?option1=value1
sqlserver sqlserver://username:password@host/instance?param1=value&param2=value
sqlserver://username:password@host:port?param1=value&param2=value
sqlserver://sa@localhost/SQLExpress?database=master&connection+timeout=30
mssql server=localhost\\SQLExpress;user id=sa;database=master;app name=MyAppName
server=localhost;user id=sa;database=master;app name=MyAppName
odbc:server=localhost\\SQLExpress;user id=sa;database=master;app name=MyAppName
odbc:server=localhost;user id=sa;database=master;app name=MyAppName
clickhouse tcp://host1:9000?username=user&password=qwerty&database=clicks&read_timeout=10&write_timeout=20&alt_hosts=host2:9000,host3:9000

Installation

Notes

  • by default sql2slack uses the current working directory as jobs files source, you can override that using --jobs-dir flag.
  • each job file must have the .s2s.hcl suffix.

以上所述就是小编给大家介绍的《sql2slack - send sql results periodically to slack》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

软件开发本质论

软件开发本质论

Ron Jeffries / 王凌云 / 人民邮电出版社图灵分社 / 2017-1 / 39

想象你正在攀登一座名为“软件开发”的山峰。本书是与你同登一座山峰的敏捷先驱所带来的话语与图片。他在崎岖的山路边找到相当平坦的歇脚处,画下所见的风景,并写下自己的想法和发现。他瞧见很多条上山的路,愿以此书与你分享哪条路容易、哪条路困难、哪条路安全、哪条路危险。他还想指引你欣赏身后的美景。正是这些美景丰富了你的登山之旅,让你在重重困难中收获成长。 “对于每一位CTO、技术VP、软件产品总......一起来看看 《软件开发本质论》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具