|
| 1 | +# KillBill Analytics Reports Setup Script |
| 2 | + |
| 3 | +This script installs all necessary database DDLs and creates KillBill analytics reports for your KillBill environment. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [Overview](#overview) |
| 10 | +- [Prerequisites](#prerequisites) |
| 11 | +- [Usage](#usage) |
| 12 | +- [Environment Variables](#environment-variables) |
| 13 | +- [Script Behavior](#script-behavior) |
| 14 | +- [Examples](#examples) |
| 15 | +- [Reports List](#reports_list) |
| 16 | + |
| 17 | + |
| 18 | +--- |
| 19 | + |
| 20 | +## Overview |
| 21 | + |
| 22 | +This Bash script performs the following tasks: |
| 23 | + |
| 24 | +1. Installs database DDL files (`.sql` or `.ddl`) into the configured MySQL database. |
| 25 | +2. Creates KillBill analytics reports via the KillBill Analytics plugin REST API. |
| 26 | +3. Supports optional dropping of existing reports before creation. |
| 27 | + |
| 28 | +The script recursively installs DDL files, ensuring `v_report_*.ddl` files are installed before corresponding `report_*.ddl` files. If no `v_report_*.ddl` exists in a folder, all `.ddl` files in that folder are installed. |
| 29 | + |
| 30 | +--- |
| 31 | + |
| 32 | +## Prerequisites |
| 33 | + |
| 34 | +- **Bash shell** (Linux, macOS, or Windows Git Bash) |
| 35 | +- **MySQL client** installed and accessible in PATH |
| 36 | +- KillBill server running with the KillBill Analytics plugin installed |
| 37 | +- Appropriate permissions for the MySQL database and KillBill API |
| 38 | + |
| 39 | +--- |
| 40 | + |
| 41 | +## Usage |
| 42 | + |
| 43 | +Run the script from the directory containing your DDL files: |
| 44 | + |
| 45 | +```bash |
| 46 | +./setup_reports.sh |
| 47 | +``` |
| 48 | + |
| 49 | +By default, the script installs DDLs and creates all reports. |
| 50 | + |
| 51 | +--- |
| 52 | + |
| 53 | +## Environment Variables |
| 54 | + |
| 55 | +The script uses environment variables to configure MySQL and KillBill settings. Defaults are provided if variables are not set: |
| 56 | + |
| 57 | +| Variable | Default | Description | |
| 58 | +|--------------------------|--------------------------|---------------------------------------------------------------------------| |
| 59 | +| `KILLBILL_HTTP_PROTOCOL` | `http` | KillBill API protocol | |
| 60 | +| `KILLBILL_HOST` | `127.0.0.1` | KillBill host | |
| 61 | +| `KILLBILL_PORT` | `8080` | KillBill port | |
| 62 | +| `KILLBILL_USER` | `admin` | KillBill username | |
| 63 | +| `KILLBILL_PASSWORD` | `password` | KillBill password | |
| 64 | +| `KILLBILL_API_KEY` | `bob` | KillBill API key | |
| 65 | +| `KILLBILL_API_SECRET` | `lazar` | KillBill API secret | |
| 66 | +| `MYSQL_HOST` | `127.0.0.1` | MySQL host | |
| 67 | +| `MYSQL_USER` | `root` | MySQL user | |
| 68 | +| `MYSQL_PASSWORD` | `killbill` | MySQL password | |
| 69 | +| `MYSQL_DATABASE` | `killbill` | MySQL database name | |
| 70 | +| `INSTALL_DDL` | `true` | Whether to install DDL files (`true` or `false`) | |
| 71 | +| `DROP_EXISTING_REPORT` | `true` | Whether to drop existing reports before creating them (`true` or `false`) | |
| 72 | + |
| 73 | +You can export environment variables before running the script to override defaults: |
| 74 | + |
| 75 | +```bash |
| 76 | +export KILLBILL_HOST=192.168.1.10 |
| 77 | +export MYSQL_PASSWORD=mysecret |
| 78 | +export INSTALL_DDL=false |
| 79 | + |
| 80 | +./setup_reports.sh |
| 81 | +``` |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## Script Behavior |
| 86 | + |
| 87 | +1. **DDL Installation** |
| 88 | + - Installs ddl from the `utils` directory first. |
| 89 | + - Recursively installs DDLs from the other subdirectories: |
| 90 | + - If `v_report_*.ddl` files exist, they are installed first, followed by `report_*.ddl`. |
| 91 | + - If no `v_report_*.ddl` exists, all `.ddl` files in the folder are installed. |
| 92 | + |
| 93 | +2. **Report Creation** |
| 94 | + - All reports defined in the `create_all_reports` function are created. |
| 95 | + - If `DROP_EXISTING_REPORT=true`, existing reports are deleted before creation. |
| 96 | + - Reports are created via the KillBill Analytics plugin REST API. |
| 97 | + |
| 98 | +--- |
| 99 | + |
| 100 | +## Examples |
| 101 | + |
| 102 | +- **Run with default configuration:** |
| 103 | + |
| 104 | +```bash |
| 105 | +./setup_reports.sh |
| 106 | +``` |
| 107 | + |
| 108 | +- **Skip DDL installation:** |
| 109 | + |
| 110 | +```bash |
| 111 | +export INSTALL_DDL=false |
| 112 | +./setup_reports.sh |
| 113 | +``` |
| 114 | + |
| 115 | +- **Disable dropping existing reports:** |
| 116 | + |
| 117 | +```bash |
| 118 | +export DROP_EXISTING_REPORT=false |
| 119 | +./setup_reports.sh |
| 120 | +``` |
| 121 | + |
| 122 | +- **Override KillBill host and MySQL password:** |
| 123 | + |
| 124 | +```bash |
| 125 | +export KILLBILL_HOST=192.168.1.10 |
| 126 | +export MYSQL_PASSWORD=mysecret |
| 127 | +./setup_reports.sh |
| 128 | +``` |
| 129 | + |
| 130 | +## Reports List |
| 131 | + |
| 132 | +The script creates the following reports: |
| 133 | + |
| 134 | +|Report Name| Underlying Report Table |Report Description| |
| 135 | +|--|---------------------------------------|--| |
| 136 | +| [accounts_summary](accounts_summary/README.md) | report_accounts_summary |Provides an account summary. Provides details like account balance, account status, currency, etc.| |
| 137 | +| [active_by_product_term_monthly](active_by_product_term_monthly/README.md) | report_active_by_product_term_monthly |Compute (at the end of each month) the total number of active subscriptions per product and billing period.| |
| 138 | +| [bundles_summary](bundles_summary/README.md) | report_bundles_summary |Provides a subscription bundle summary. Provides details like CTD, plan name, price, for the base subscription in a bundle.| |
| 139 | +| [cancellations_daily](cancellations_daily/README.md) | report_cancellations_daily |Compute the total number of cancellations per day per phase.| |
| 140 | +| [chargebacks_daily](chargebacks_daily/README.md) | report_chargebacks_daily |Compute the total value (in the reference currency) of chargebacks per day per currency.| |
| 141 | +| [conversion-total-dollar-amount](conversion-total-dollar-amount/README.md) | report_conversion-total-dollar-amount |Compute (monthly) the total revenue from subscriptions converting out of trial, grouped by tenant and billing period.| |
| 142 | +| [invoice_aging](invoice_aging/README.md) | report_invoice_aging |This report lists all customer invoice aging with remaining balances, breaking them into standard aging buckets and converting amounts to USD for easy comparison.| |
| 143 | +| [invoice_aging_no_payment](invoice_aging_no_payment/README.md) | report_invoice_aging_no_payment |This report lists all customer invoices with no payments recorded, categorizing outstanding amounts into standard aging buckets and converting balances into USD for comparison. |
| 144 | +| |
| 145 | +| [invoice_credits_daily](invoice_credits_daily/README.md) | report_invoice_credits_daily |Total of invoice credits per tenant, per currency and per day.| |
| 146 | +| [invoice_credits_monthly](invoice_credits_monthly/README.md) | report_invoice_credits_monthly |Report of all invoice credits from the previous month, showing amounts in both original currency and USD equivalents.| |
| 147 | +| [invoice_item_adjustments_daily](invoice_item_adjustments_daily/README.md) | report_invoice_item_adjustments_daily |Total of invoice item adjustments per tenant, per currency and per day.| |
| 148 | +| [invoice_item_adjustments_monthly](invoice_item_adjustments_monthly/README.md) | report_invoice_item_adjustments_monthly |Report of all invoice item adjustments from the previous month, showing amounts in both original currency and USD equivalents.| |
| 149 | +| [invoice_items_monthly](invoice_items_monthly/README.md) | report_invoice_items_monthly |Report of all invoice items from the previous month, showing amounts in both original currency and USD equivalents.| |
| 150 | +| [invoices_balance_daily](invoices_balance_daily/README.md) | report_invoices_balance_daily |Compute the total sum of invoices balance (in the reference currency) per invoice created day. |
| 151 | +| |
| 152 | +| [invoices_daily](invoices_daily/README.md) | report_invoices_daily |Compute the total invoice amount charged (in the reference currency) per day per currency.| |
| 153 | +| [invoices_monthly](invoices_monthly/README.md) | report_invoices_monthly |Report of all invoices from the previous month, showing amounts in both original currency and USD equivalents.| |
| 154 | +| [mrr_daily](mrr_daily/README.md) | report_mrr_daily |Computes the total active MRR (monthly recurring revenue), broken down both by product and as a tenant-wide total (ALL) for each tenant and each day.| |
| 155 | +| [new_accounts_daily](new_accounts_daily/README.md) | report_new_accounts_daily |Compute the total amount of new accounts created per day for each tenant.| |
| 156 | +| [overdue-states-count-daily](overdue-states-count-daily/README.md) | report_overdue-states-count-daily |Count of overdue states per tenant and per day.| |
| 157 | +| [payments_monthly](payments_monthly/README.md) | report_payments_monthly |Report of all payments from the previous month, showing amounts in both original currency and USD equivalents.| |
| 158 | +| [payments_summary](payments_summary/README.md) | report_payments_summary |Provides payment summary. Provides details like payment_id, amount, etc.| |
| 159 | +| [payments_total_daily](payments_total_daily/README.md) | report_payments_total_daily |Compute the total value (in the reference currency) of payments per day per currency.| |
| 160 | +| [refunds-monthly](refunds-monthly/README.md) | report_refunds-monthly |Report of all refunds from the previous month, showing amounts in both original currency and USD equivalents.| |
| 161 | +| [refunds_total_daily](refunds_total_daily/README.md) | report_refunds_total_daily |Compute the total value (in the reference currency) of refunds per day per currency for each tenant.| |
| 162 | +| [subscribers-vs-non-subscribers](subscribers-vs-non-subscribers/README.md) | report_subscribers-vs-non-subscribers |Compute the total number of active (i.e. with at least one active subscription) and non-active accounts per tenant.| |
| 163 | +| [trial-starts-count-daily](trial-starts-count-daily/README.md) | report_trial-starts-count-daily |Count of new trial subscriptions per tenant, per day and per product.| |
| 164 | +| [trial-to-no-trial-conversions_daily](trial-to-no-trial-conversions_daily/README.md) | report_trial-to-no-trial-conversions_daily |Count of subscriptions converting from trial to non-trial per tenant per day.| |
| 165 | + |
0 commit comments