LoginSignup
0
0

More than 1 year has passed since last update.

Re:DashでIBM Cloud Db2 に接続してみた

Last updated at Posted at 2022-06-08

初めに

オープンソースのBIツールであるRe:Dashから、IBM Cloud のDb2に接続してみた内容になっています。

Re:Dash では、標準でDb2の接続機能を持っています。
ただし、IBM CloudのDb2には、SSL接続する必要がありますが、標準でSSL接続には対応していないため、ソースコードの変更が必要になります。

※注意
投稿時の内容のため、バージョンアップ等で変わる可能性があります。また当内容を実施した結果の責任は負えませんので、ご了承ください。

ソースの変更

/redash/query_runner/db2.py の「configuration_schema」と「_get_connection」メソッドをを以下のように変更します。

    def configuration_schema(cls):
        return {
            "type": "object",
            "properties": {
                "user": {"type": "string"},
                "password": {"type": "string"},
                "host": {"type": "string", "default": "127.0.0.1"},
                "port": {"type": "number", "default": 50000},
                "dbname": {"type": "string", "title": "Database Name"},
         "sslcert": {"type": "string", "title": "SSL Certification"}
            },
            "order": ["host", "port", "user", "password", "dbname"],
            "required": ["dbname"],
            "secret": ["password"],
        }

    def _get_connection(self):
        self.connection_string = ""DATABASE={};HOSTNAME={};PORT={};PROTOCOL=TCPIP;UID={};PWD={};Security=Ssl;SSLServerCertificate={};".format(
            self.configuration["dbname"],
            self.configuration["host"],
            self.configuration["port"],
            self.configuration["user"],
            self.configuration["password"],
      self.configuration["sslcert"]
        )
        connection = ibm_db_dbi.connect(self.connection_string, "", "")

        return connection

Redashでの接続設定

ソースを変更後、Re:Dashを起動し、下記図のDb2接続設定画面で、接続に必要な情報を入力します。
「SSL Certification」には、証明書のパスを指定します。(事前にIBM Cloudから証明書のファイルをダウンロードして、Re:Dashを動かすサーバーに配置しておいてください)

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0