|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# |
| 4 | +# Copyright 2020-2025 Equinix, Inc |
| 5 | +# Copyright 2014-2025 The Billing Project, LLC |
| 6 | +# |
| 7 | +# The Billing Project licenses this file to you under the Apache License, version 2.0 |
| 8 | +# (the "License"); you may not use this file except in compliance with the |
| 9 | +# License. You may obtain a copy of the License at: |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, software |
| 14 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 16 | +# License for the specific language governing permissions and limitations |
| 17 | +# under the License. |
| 18 | +# |
| 19 | + |
| 20 | +HERE=`cd \`dirname $0\`; pwd` |
| 21 | + |
| 22 | +KILLBILL_HTTP_PROTOCOL=${KILLBILL_HTTP_PROTOCOL-"http"} |
| 23 | +KILLBILL_HOST=${KILLBILL_HOST-"127.0.0.1"} |
| 24 | +KILLBILL_PORT=${KILLBILL_PORT-"8080"} |
| 25 | + |
| 26 | +KILLBILL_USER=${KILLBILL_USER-"admin"} |
| 27 | +KILLBILL_PASSWORD=${KILLBILL_PASSWORD-"password"} |
| 28 | +KILLBILL_API_KEY=${KILLBILL_API_KEY-"bob"} |
| 29 | +KILLBILL_API_SECRET=${KILLBILL_API_SECRET-"lazar"} |
| 30 | + |
| 31 | +MYSQL_HOST=${MYSQL_HOST-"127.0.0.1"} |
| 32 | +MYSQL_USER=${MYSQL_USER-"root"} |
| 33 | +MYSQL_PASSWORD=${MYSQL_PASSWORD-"killbill"} |
| 34 | +MYSQL_DATABASE=${MYSQL_DATABASE-"killbill"} |
| 35 | +INSTALL_DDL=true |
| 36 | +DROP_EXISTING_REPORT=false |
| 37 | + |
| 38 | +REPORTS=$HERE |
| 39 | + |
| 40 | +function install_ddl() { |
| 41 | + local ddl=$1 |
| 42 | + mysql -h$MYSQL_HOST -u$MYSQL_USER -p$MYSQL_PASSWORD $MYSQL_DATABASE -e "source $ddl" |
| 43 | +} |
| 44 | + |
| 45 | +install_all_ddls() { |
| 46 | + echo "Installing DDLs from utils directory first..." |
| 47 | + ( |
| 48 | + cd "$REPORTS" || exit 1 |
| 49 | + |
| 50 | + # Process utils first if it exists |
| 51 | + if [ -d "./utils" ]; then |
| 52 | + for ddl_pattern in "v_report_*.ddl" "report_*.ddl" "*.ddl" "*.sql"; do |
| 53 | + shopt -s nullglob |
| 54 | + for ddl in ./utils/$ddl_pattern; do |
| 55 | + [ -f "$ddl" ] && install_ddl "$ddl" |
| 56 | + done |
| 57 | + shopt -u nullglob |
| 58 | + done |
| 59 | + fi |
| 60 | + |
| 61 | + echo "Installing other DDLs..." |
| 62 | + # Loop over all directories except utils |
| 63 | + find . -type d ! -path "./utils" -print0 | while IFS= read -r -d '' dir; do |
| 64 | + for ddl_pattern in "v_report_*.ddl" "report_*.ddl"; do |
| 65 | + shopt -s nullglob |
| 66 | + for ddl in "$dir"/$ddl_pattern; do |
| 67 | + [ -f "$ddl" ] && install_ddl "$ddl" |
| 68 | + done |
| 69 | + shopt -u nullglob |
| 70 | + done |
| 71 | + done |
| 72 | + ) |
| 73 | +} |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +function create_report() { |
| 78 | + local report_name=$1 |
| 79 | + local report_pretty_name=$2 |
| 80 | + local report_type=$3 |
| 81 | + local source_table_name=$4 |
| 82 | + local refresh_procedure_name=$5 |
| 83 | + |
| 84 | +if [[ "$DROP_EXISTING_REPORT" == "true" ]]; then |
| 85 | + |
| 86 | + curl -v \ |
| 87 | + -X DELETE \ |
| 88 | + -u "$KILLBILL_USER:$KILLBILL_PASSWORD" \ |
| 89 | + -H "X-Killbill-ApiKey:$KILLBILL_API_KEY" \ |
| 90 | + -H "X-Killbill-ApiSecret:$KILLBILL_API_SECRET" \ |
| 91 | + "http://127.0.0.1:8080/plugins/killbill-analytics/reports/$report_name" |
| 92 | +fi |
| 93 | + |
| 94 | + |
| 95 | + curl -v \ |
| 96 | + -X POST \ |
| 97 | + -u $KILLBILL_USER:$KILLBILL_PASSWORD \ |
| 98 | + -H "X-Killbill-ApiKey:$KILLBILL_API_KEY" \ |
| 99 | + -H "X-Killbill-ApiSecret:$KILLBILL_API_SECRET" \ |
| 100 | + -H 'Content-Type: application/json' \ |
| 101 | + -d "{\"reportName\": \"$report_name\", |
| 102 | + \"reportPrettyName\": \"$report_pretty_name\", |
| 103 | + \"reportType\": \"$report_type\", |
| 104 | + \"sourceTableName\": \"$source_table_name\", |
| 105 | + \"refreshProcedureName\": \"$refresh_procedure_name\", |
| 106 | + \"refreshFrequency\": \"HOURLY\" |
| 107 | + }" \ |
| 108 | + $KILLBILL_HTTP_PROTOCOL://$KILLBILL_HOST:$KILLBILL_PORT/plugins/killbill-analytics/reports |
| 109 | +} |
| 110 | + |
| 111 | +# Create all Killbill reports |
| 112 | +create_all_reports() { |
| 113 | + declare -a reports=( |
| 114 | + "report_accounts_summary|Account Summary|TABLE|report_accounts_summary|refresh_report_accounts_summary" |
| 115 | + "active_by_product_term_monthly|Active Subscriptions|TIMELINE|report_active_by_product_term_monthly|refresh_report_active_by_product_term_monthly" |
| 116 | + "report_bundles_summary|Bundles Summary|TABLE|report_bundles_summary|refresh_report_bundles_summary" |
| 117 | + "cancellations_count_daily|Cancellations Daily|TIMELINE|report_cancellations_daily|refresh_report_cancellations_daily" |
| 118 | + "chargebacks_daily|Chargebacks Daily|TIMELINE|report_chargebacks_daily|refresh_report_chargebacks_daily" |
| 119 | + "conversions_daily|Conversions Daily|TIMELINE|report_conversions_daily|refresh_report_conversions_daily" |
| 120 | + "invoice_aging|Invoice Aging|TABLE|report_invoice_aging|refresh_report_invoice_aging" |
| 121 | + "invoice_aging_no_pmt|Invoice Aging No Payments|TABLE|report_invoice_aging_no_payment|refresh_report_invoice_aging_no_payment" |
| 122 | + "invoice_credits_daily|Invoice Credits Daily|TIMELINE|report_invoice_credits_daily|refresh_report_invoice_credits_daily" |
| 123 | + "invoice_credits_Monthly|Invoice Credits Monthly|TABLE|report_invoice_credits_monthly|refresh_report_invoice_credits_monthly" |
| 124 | + "invoice_item_adjustments_daily|Invoice Item Adjustments Daily|TIMELINE|report_invoice_item_adjustments_daily|refresh_report_invoice_item_adjustments_daily" |
| 125 | + "invoice_item_adjustments_monthly|Invoice Item Adjustments Monthly|TABLE|report_invoice_item_adjustments_monthly|refresh_report_invoice_item_adjustments_monthly" |
| 126 | + "invoice_items_monthly|Invoice Items Monthly|TABLE|report_invoice_items_monthly|refresh_report_invoice_items_monthly" |
| 127 | + "invoices_balance_daily|Invoice Balance|TIMELINE|report_invoices_balance_daily|refresh_report_invoices_balance_daily" |
| 128 | + "invoices_daily|Invoices Daily|TIMELINE|report_invoices_daily|refresh_report_invoices_daily" |
| 129 | + "invoice_monthly|Invoices Monthly|TABLE|report_invoices_monthly|refresh_report_invoices_monthly" |
| 130 | + "mrr_daily|MRR|TIMELINE|report_mrr_daily|refresh_report_mrr_daily" |
| 131 | + "new_accounts_daily|New Accounts Daily|TIMELINE|report_new_accounts_daily|refresh_report_new_accounts_daily" |
| 132 | + "overdue_states_count_daily|Overdue States Count|TIMELINE|report_overdue_states_count_daily|refresh_report_overdue_states_count_daily" |
| 133 | + "payments_monthly|Payments Monthly|TABLE|report_payments_monthly|refresh_report_payments_monthly" |
| 134 | + "payments_summary|Payments Summary|TABLE|report_payments_summary|refresh_report_payments_summary" |
| 135 | + "payments_total_daily|Payment Total Daily|TIMELINE|report_payments_total_daily|refresh_report_payments_total_daily" |
| 136 | + "refunds_monthly|Refunds Monthly|TABLE|report_refunds_summary|refresh_report_refunds_summary" |
| 137 | + "refunds_total_daily|Refunds Total Daily|TIMELINE|report_refunds_total_daily|refresh_report_refunds_total_daily" |
| 138 | + "subscribers_vs_non_subscribers|Subscribers v/s Non Subscribers|COUNTERS|report_subscribers_vs_non_subscribers|refresh_report_subscribers_vs_non_subscribers" |
| 139 | + "trial_starts_count_daily|Trials Start Count|TIMELINE|report_trial_starts_count_daily|refresh_report_trial_starts_count_daily" |
| 140 | + "trial_to_no_trial_conversions_daily|Trial to No Trial Conversions Daily|TIMELINE|report_trial_to_no_trial_conversions_daily|refresh_report_trial_to_no_trial_conversions_daily" |
| 141 | + ) |
| 142 | + |
| 143 | + for r in "${reports[@]}"; do |
| 144 | + IFS="|" read -r name pretty type source refresh <<< "$r" |
| 145 | + create_report "$name" "$pretty" "$type" "$source" "$refresh" |
| 146 | + done |
| 147 | +} |
| 148 | + |
| 149 | +# ======================== |
| 150 | +# Main Execution |
| 151 | +# ======================== |
| 152 | + |
| 153 | +if [[ "$INSTALL_DDL" == "true" ]]; then |
| 154 | + install_all_ddls |
| 155 | +else |
| 156 | + echo "INSTALL_DDL is not true. Skipping DDL installation." |
| 157 | +fi |
| 158 | + |
| 159 | +create_all_reports |
| 160 | + |
0 commit comments