瀏覽代碼

cmd_acc: adde command to print acc reports

- implemented 'top-src' - get report of the most active callers
Daniel-Constantin Mierla 11 月之前
父節點
當前提交
2678277e31
共有 1 個文件被更改,包括 48 次插入2 次删除
  1. 48 2
      kamcli/commands/cmd_acc.py

+ 48 - 2
kamcli/commands/cmd_acc.py

@@ -270,12 +270,13 @@ def acc_mc_list(ctx, oformat, ostyle, limit):
     if limit == 0:
     if limit == 0:
         query = "select * from missed_calls order by id desc"
         query = "select * from missed_calls order by id desc"
     else:
     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)
     res = e.execute(query)
     ioutils_dbres_print(ctx, oformat, ostyle, res)
     ioutils_dbres_print(ctx, oformat, ostyle, res)
 
 
 
 
-
 @cli.command(
 @cli.command(
     "cdrs-generate",
     "cdrs-generate",
     short_help="Run SQL stored procedure to generate CDRS",
     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:
             for rg in rate_group:
                 c.execute("call kamailio_rating({0!r})".format(rg))
                 c.execute("call kamailio_rating({0!r})".format(rg))
         t.commit()
         t.commit()
+
+
[email protected](
+    "acc-report",
+    short_help="Show various accounting reports",
+)
[email protected](
+    "oformat",
+    "--output-format",
+    "-F",
+    type=click.Choice(["raw", "json", "table", "dict"]),
+    default=None,
+    help="Format the output",
+)
[email protected](
+    "ostyle",
+    "--output-style",
+    "-S",
+    default=None,
+    help="Style of the output (tabulate table format)",
+)
[email protected](
+    "limit",
+    "--limit",
+    "-l",
+    type=int,
+    default=20,
+    help="The limit of listed records (default: 20)",
+)
[email protected]("name", metavar="<name>")
+@pass_context
+def acc_report(ctx, oformat, ostyle, limit, name):
+    """Show various accounting reports
+
+    \b
+    Parameters:
+        <name> - 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)