Categorygithub.com/anothrNick/send-query-result
modulepackage
0.0.0-20200229214007-e3da20d66070
Repository: https://github.com/anothrnick/send-query-result.git
Documentation: pkg.go.dev

# README

send-query-result

Stable Version

Sends the text output of a Postgres query to a Slack channel via Incoming Web Hook (or any web hook). The query is run on a configurable interval.

For example, if you wanted to know the count of records for a specific table in Postgres (and you don't have metrics), you could run this container with the following query:

select count(id) as user_count from app_users;

The message will appear as standard SQL output:

 user_count 
------------
          5 
(1 row)

Environment Variables

A configuration file would be better, but env vars will do for this project

KeyDescription
POSTGRES_USERUsername of the Postgres user
POSTGRES_PWPassword of the Postgres user
POSTGRES_HOSTPostgres hostname or ip address
POSTGRES_DBPostgres database name
POSTGRES_SSLPostgres SSL Mode
STAT_QUERYThe SQL query to be executed. Can result in single or multiple rows
STAT_INTERVALThe interval, in minutes, to run the query and send the result to the web hook url
STAT_URLThe web hook URL to send the result (does not have to be Slack)

POST Body Format

This script is meant to send to a Slack Incoming Web Hook, so the request body will be formatted like so:

{
    "text": "```<sql_output>```"
}

Howevever, the sql output can be sent to any web hook

Dependencies

github.com/shomali11/xsql