Sending DataSunrise notifications to Slack
Slack is a popular instant messenger with more than a million users.
Since it is impossible to send notifications from DataSunrise to Slack directly, we will use Slack IP interface created by a third-party developer.
There is a console client for Slack API developed. (https://github.com/candrholdings/slack-cli). This client is created in the form of a Node.js application.
Since it is Node.js-based, this client requires Node.js platform installed along with NPM packet manager. You can find short Node.js installation guide at the official website: https://nodejs.org/en/download/package-manager/
Installation of required components
To install Node.js and the packet manager, execute the following commands via Linux Terminal:
sudo apt-get update
sudo apt-get install nodejs-legacy
Now it is necessary to install Slack Client. To do this, execute the following command:
npm install -g slack-cli
Please ensure that the path to NPM path is included into PATH environment variable.
Since the client had been installed, you need to register it at Slack API system. The outcome of the registration is the token. It is a hash string for authorization and authentication of a client at Slack system.
Creating Slack API App
To get the token you need to create and register Slack API App. Essentially, it is a bot used to send messages.
To create an App, go to the following page: https://api.slack.com/apps and click Create New App. Enter your app’s name into the new window.
Please note the Development Slack Team. The bot you’re creating should belong to your organization and to one of your teams. If you’ve created it successfully, you will see the following:
Save Client ID and Client Secret strings — they are required to get the token.
Then you need to get the OAuth code. To get this code it is necessary to specify the “Redirect URL” parameter. This parameter is useless when using SlackCli, but it requires to get the OAuth code.
Go to the following page and select the App, you’ve created at previous stage: https://api.slack.com/apps
Click App’s name to get to its settings. Select OAuth & Permissions — text field will appear. Input at least one URL into that field. It could be any URL, but I suggest to use https://api.slack.com.
Click Save changes to save the settings.
Getting the OAuth code
Now everything is ready for getting the OAuth code. To query the code you need to make and execute GET query like the following:
https://slack.com/oauth/authorize?client_id=ClientID&redirect_uri=https://api.slack.com&scope=chat:write:bot channels:read chat:write:user
Note three parameters:
- Сlient_id you’ve received when creating an App. You can find it in “Basic information” subsection of the App’s settings
- redirect_uri — it is the URL you’ve specified in the OAuth & Permissions at the previous stage.
- scope — This parameter defines bot’s privileges. For the discussed task it is enough to give the bot the right to send messages to Slack channels. You can find the full list of scope settings here: https://api.slack.com/docs/oauth-scopes
After you’ve prepared a string for the GET query, open it via your web browser. If all parameters were specified correctly, you will be redirected to the following page:
Click Authorize. You will be redirected to the page specified in redirect_uri parameter. Leave the page open. Take a look at the address bar. You will see there something like the following:
Extract the code parameter out of the URL string and save it somewhere.
Getting the token
All preparations are made and now it is the final step to make.
Open the following page:
Input the parameters you’ve got earlier into the corresponding text fields:
Then click Test Method. You will get a response like the following:
You can find the token needed as the access_token parameter value. Save it somewhere and don’t loose.
Also, note that the code parameter value is actual for short time, so hurry.
To test the configuration, use Linux Terminal to execute the following command:
Slackcli –t [token] -h [channel] -m “message text”
Replace [token] with the token got, [channel] with Slack channel’s name you want to send messages to. Use the “*” quotes to define the text of message.
Configuring DataSunrise for sending messages to Slack
Enter DataSunrise GUI and go to the Configurations section, Subscribers subsection.
Click Server+ to create a new server.
Select External via the Type drop-down list.
Input the following code into the Command field:
Slackcli –t [token]
[token] is the token you’ve got earlier.
slackcli -t xoxp-47309483958-47311871014-89399430464-2cbb715689726a101728808d440e5934
Click Save to save the server settings.
Now you need to configure a subscriber. Click Subscriber+ button to create new subscriber. Select the server you’ve created via the Gate drop-down list.
Input the following into the Additional Parameters field:
-h [Slack channel] -m
[Slack channel] is the name of Slack channel you want to send messages to.
-h general –m
Check the events notifications on which you want to send to Slack and click Save button.
DataSunrise supports all major databases and data warehouses such as Oracle, Exadata, IBM DB2, IBM Netezza, MySQL, MariaDB, Greenplum, Amazon Aurora, Amazon Redshift, Microsoft SQL Server, Azure SQL, Teradata and more. You are welcome to download a free trial if would like to install on your premises. In case you are a cloud user and run your database on Amazon AWS or Microsoft Azure you can get it from AWS market place or Azure market place.