From 2678277e31946f397609b74dbe19955057f04264 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Sat, 12 Oct 2024 20:09:06 +0200 Subject: [PATCH] cmd_acc: adde command to print acc reports - implemented 'top-src' - get report of the most active callers --- kamcli/commands/cmd_acc.py | 50 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/kamcli/commands/cmd_acc.py b/kamcli/commands/cmd_acc.py index 6052de5..5a61aed 100644 --- a/kamcli/commands/cmd_acc.py +++ b/kamcli/commands/cmd_acc.py @@ -270,12 +270,13 @@ def acc_mc_list(ctx, oformat, ostyle, limit): if limit == 0: query = "select * from missed_calls order by id desc" else: - query = "select * from missed_calls order by id desc limit {0}".format(limit) + query = "select * from missed_calls order by id desc limit {0}".format( + limit + ) res = e.execute(query) ioutils_dbres_print(ctx, oformat, ostyle, res) - @cli.command( "cdrs-generate", short_help="Run SQL stored procedure to generate CDRS", @@ -479,3 +480,48 @@ def acc_rates_generate(ctx, rate_group): for rg in rate_group: c.execute("call kamailio_rating({0!r})".format(rg)) t.commit() + + +@cli.command( + "acc-report", + short_help="Show various accounting reports", +) +@click.option( + "oformat", + "--output-format", + "-F", + type=click.Choice(["raw", "json", "table", "dict"]), + default=None, + help="Format the output", +) +@click.option( + "ostyle", + "--output-style", + "-S", + default=None, + help="Style of the output (tabulate table format)", +) +@click.option( + "limit", + "--limit", + "-l", + type=int, + default=20, + help="The limit of listed records (default: 20)", +) +@click.argument("name", metavar="") +@pass_context +def acc_report(ctx, oformat, ostyle, limit, name): + """Show various accounting reports + + \b + Parameters: + - name of the report (top-src) + """ + e = create_engine(ctx.gconfig.get("db", "rwurl")) + ctx.vlog("Showing accounting report: " + name) + query = "SELECT `src_user`, count(*) AS `count` FROM acc GROUP BY `src_user` ORDER BY count DESC" + if limit > 0: + query = query + " LIMIT {0}".format(limit) + res = e.execute(query) + ioutils_dbres_print(ctx, oformat, ostyle, res)