[SR-Users] Cost deduction in kamailio

Federico Cabiddu federico.cabiddu at gmail.com
Thu Sep 7 10:08:05 CEST 2017


Hi,
I have strictly no idea of where you decided to store the balance in the
db, what is the table structure you decided to use and so on.
>From where are you taking the user's credit before calling cnxcc? I suppose
you should use the same table/field when updating. There is no ready made
solution for this in Kamailio, you have to use its building blocks, the
modules, to achieve this.
Have a (deep) look at modules' documentation and at the example that has
been suggested.

Cheers,

Federico

On Thu, Sep 7, 2017 at 8:20 AM, Logeshwaran G <logeshwarangs at gmail.com>
wrote:

> Input Please
>
>
>
> Thanks & Kind Regards,
> *Logeshwaran G*
>
> *"Be Hungry, Stay Foolish"*
>
> On Tue, Sep 5, 2017 at 2:07 PM, Logeshwaran G <logeshwarangs at gmail.com>
> wrote:
>
>> Hi ,
>>
>> I have tried the Cnxcc to deduct the credit amount and its working fine.
>> Please find the below logs in kamailio -ddd mode.
>>
>> 10(19003) DEBUG: cnxcc [cnxcc_check.c:85]: check_calls_by_money(): CID
>> [4vL4DJsLpRSfwoMaJVbegWBLWy7k7-UP], start_timestamp [1504598301],
>> seconds alive [36], consumed credit [20.000000]
>> 10(19003) DEBUG: cnxcc [cnxcc_check.c:107]: check_calls_by_money():
>> Client [8888] | Ended-Calls-Credit-Spent: 0.000000  TotalCredit/MaxCredit:
>> 20.000000/30.000000
>> 10(19003) DEBUG: cnxcc [cnxcc_check.c:85]: check_calls_by_money(): CID
>> [4vL4DJsLpRSfwoMaJVbegWBLWy7k7-UP], start_timestamp [1504598301],
>> seconds alive [37], consumed credit [20.000000]
>> 10(19003) DEBUG: cnxcc [cnxcc_check.c:107]: check_calls_by_money():
>> Client [8888] | Ended-Calls-Credit-Spent: 0.000000  TotalCredit/MaxCredit:
>> 20.000000/30.000000
>>
>>
>> But Through Sql query how can I get the Deducted Value.. For Example in
>> my case, in the above kamailio log, Total Credit Spent is 20.00, Where this
>> values are storing in Database. Please Guide me
>>
>> Thanks & Kind Regards,
>> Logeshwaran G
>>
>> On Wed, Aug 30, 2017 at 2:12 PM, Logeshwaran G <logeshwarangs at gmail.com>
>> wrote:
>>
>>> Ok let me try it out!
>>>
>>> Will add the sqlops query module in the event route!
>>>
>>> Thanks
>>>
>>> Thanks & Kind Regards,
>>> Logeshwaran G
>>>
>>> On Wed, Aug 30, 2017 at 2:09 PM, Federico Cabiddu <
>>> federico.cabiddu at gmail.com> wrote:
>>>
>>>> Hi,
>>>> I told you previously hat you have to use sql_ops to actually do the
>>>> update of the balance after calculating the call cost using the dialog
>>>> variables.
>>>>
>>>> Cheers,
>>>>
>>>> Federico
>>>>
>>>>
>>>>
>>>> On Wed, Aug 30, 2017 at 10:34 AM, Logeshwaran G <
>>>> logeshwarangs at gmail.com> wrote:
>>>>
>>>>> As per your Input I have changed the Variables to dialog variables,
>>>>> But I dont know what to add in event route.
>>>>>
>>>>> Thanks & Kind Regards,
>>>>> Logeshwaran G
>>>>>
>>>>> On Wed, Aug 30, 2017 at 2:00 PM, Federico Cabiddu <
>>>>> federico.cabiddu at gmail.com> wrote:
>>>>>
>>>>>> Hi,
>>>>>> did you read this comment in the event_route?
>>>>>>
>>>>>> # perform some kind of notification, database update, email sending,
>>>>>> etc.
>>>>>>
>>>>>> Have you put any logic to do the accounting there (as I suggested)?
>>>>>>
>>>>>> Regards,
>>>>>>
>>>>>> Federico
>>>>>>
>>>>>> On Wed, Aug 30, 2017 at 9:50 AM, Logeshwaran G <
>>>>>> logeshwarangs at gmail.com> wrote:
>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I am using the below scenario : but there is no cost deduction
>>>>>>> happening , Correct me if I am wrong.
>>>>>>>
>>>>>>> route[CNXCC]
>>>>>>> {
>>>>>>>                 $dlg_var(subscriber)            = $fU;
>>>>>>>                 $dlg_var(customer_id)           = "customer-" + $fU;
>>>>>>>                 $dlg_var(initial_p)             = "1";
>>>>>>>                 $dlg_var(final_p)               = "1";
>>>>>>>                 $dlg_var(cps)   = "1"; ;
>>>>>>>         $var(minbal) = 1;
>>>>>>>         $var(ret) = avp_db_query("SELECT credits FROM subscriber
>>>>>>> where username='$fU'", "$avp(s:credits)");
>>>>>>>         xlog("L_WARN", "CNXCC: var(ret)=$var(ret)
>>>>>>> avp(s:credits)=$avp(s:credits)\n");
>>>>>>>         #if(!cnxcc_set_max_credit("$var(customer)",
>>>>>>> "$avp(s:credits)", "$var(cps)", "$var(initial_p)", "$var(final_p)"))
>>>>>>>         if(!cnxcc_set_max_credit("$dlg_var(subscriber)",
>>>>>>> "$avp(s:credits)", "$dlg_var(cps)", "$dlg_var(initial_p)",
>>>>>>> "$dlg_var(final_p)"))
>>>>>>>         {
>>>>>>>                 xlog("Error setting up credit control");
>>>>>>>                 sl_reply_error();
>>>>>>>                 exit;
>>>>>>>
>>>>>>>         }
>>>>>>>         if ($avp(s:credits)<  $var(minbal)){
>>>>>>>                 xlog("L_ALERT", "ALERT: Credit balance is low, sent
>>>>>>> 403:Forbidden. required=$var(minbal)\n");
>>>>>>>                 sl_send_reply("403", "Forbidden: Low balance");
>>>>>>>                 drop;
>>>>>>>
>>>>>>>         }
>>>>>>> }
>>>>>>>
>>>>>>> event_route[cnxcc:call-shutdown]
>>>>>>> {
>>>>>>>         xlog("L_ALERT", "event_route:cnxcc: [$ci]: call killed");
>>>>>>>
>>>>>>>         # perform some kind of notification, database update, email
>>>>>>> sending, etc.
>>>>>>> }
>>>>>>>
>>>>>>> Thanks & Kind Regards,
>>>>>>> Logeshwaran G
>>>>>>>
>>>>>>> On Wed, Aug 30, 2017 at 11:40 AM, Aqs Younas <aqsyounas at gmail.com>
>>>>>>> wrote:
>>>>>>>
>>>>>>>> This might help you.
>>>>>>>> https://github.com/caruizdiaz/cnxcc-example?files=1
>>>>>>>>
>>>>>>>> On 30 Aug 2017 11:09 am, "Logeshwaran G" <logeshwarangs at gmail.com>
>>>>>>>> wrote:
>>>>>>>>
>>>>>>>>> Thanks Federico! Will try it out.
>>>>>>>>>
>>>>>>>>> Thanks & Kind Regards,
>>>>>>>>> Logeshwaran G
>>>>>>>>>
>>>>>>>>> On Wed, Aug 30, 2017 at 11:34 AM, Federico Cabiddu <
>>>>>>>>> federico.cabiddu at gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>> yes it's correct, but if you want to deduct the cost at the end
>>>>>>>>>> of the call you should use dlg_var to store cps etc.
>>>>>>>>>>
>>>>>>>>>> Regards,
>>>>>>>>>>
>>>>>>>>>> Federico
>>>>>>>>>>
>>>>>>>>>> On Wed, Aug 30, 2017 at 7:16 AM, Logeshwaran G <
>>>>>>>>>> logeshwarangs at gmail.com> wrote:
>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> Is this the correct way of using the CNXCC for cost deduction,
>>>>>>>>>>> Guide me please.
>>>>>>>>>>>
>>>>>>>>>>> route[CNXCC]
>>>>>>>>>>> {
>>>>>>>>>>>         $var(customer) = $fU;
>>>>>>>>>>>         $var(cps)   = "1.00";      # cost per second
>>>>>>>>>>>         $var(initial_p)   = "1";   # intial pulse
>>>>>>>>>>>         $var(final_p)   = "1";    #Final_pulse
>>>>>>>>>>>         $var(minbal) = 1;
>>>>>>>>>>>         $var(ret) = avp_db_query("SELECT credits FROM subscriber
>>>>>>>>>>> where username='$fU'", "$avp(s:credits)");
>>>>>>>>>>>         xlog("L_WARN", "CNXCC: var(ret)=$var(ret)
>>>>>>>>>>> avp(s:credits)=$avp(s:credits)\n");
>>>>>>>>>>>         cnxcc_set_max_credit("$var(customer)",
>>>>>>>>>>> "$avp(s:credits)", "$var(cps)", "$var(initial_p)", "$var(final_p)");
>>>>>>>>>>>         if ($avp(s:credits)<  $var(minbal)){
>>>>>>>>>>>                 xlog("L_ALERT", "ALERT: Credit balance is low,
>>>>>>>>>>> sent 403:Forbidden. required=$var(minbal)\n");
>>>>>>>>>>>                 sl_send_reply("403", "Forbidden: Low balance");
>>>>>>>>>>>                 drop;
>>>>>>>>>>>
>>>>>>>>>>>         }
>>>>>>>>>>> }
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> Thanks & Kind Regards,
>>>>>>>>>>> Logeshwaran G
>>>>>>>>>>>
>>>>>>>>>>> On Fri, Aug 25, 2017 at 11:14 AM, Logeshwaran G <
>>>>>>>>>>> logeshwarangs at gmail.com> wrote:
>>>>>>>>>>>
>>>>>>>>>>>> Thanks For your Input Federico, Will try it .
>>>>>>>>>>>>
>>>>>>>>>>>> Thanks & Kind Regards,
>>>>>>>>>>>> Logeshwaran G
>>>>>>>>>>>>
>>>>>>>>>>>> On Wed, Aug 23, 2017 at 5:45 PM, Federico Cabiddu <
>>>>>>>>>>>> federico.cabiddu at gmail.com> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>> cnxcc doesn't provide this feature. Is not aware of any
>>>>>>>>>>>>> backend, it just controls subscriber's balance, money or time, as
>>>>>>>>>>>>> instructed.
>>>>>>>>>>>>> You can calculate the amount to be deducted after the call
>>>>>>>>>>>>> ends (if you're doing money based accounting) using dlg variables to store
>>>>>>>>>>>>> the needed information (start_time, end_time, cost per second) and then
>>>>>>>>>>>>> updating the balance via sqlops module's functions.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Cheers,
>>>>>>>>>>>>>
>>>>>>>>>>>>> Federico
>>>>>>>>>>>>>
>>>>>>>>>>>>> On Wed, Aug 23, 2017 at 7:50 AM, Logeshwaran G <
>>>>>>>>>>>>> logeshwarangs at gmail.com> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>> Hi,
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> How to deduct the call cost or credits for the subscribers
>>>>>>>>>>>>>> with the cnxcc module?
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Input Please
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thanks & Kind Regards,
>>>>>>>>>>>>>> Logeshwaran G
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>>> Kamailio (SER) - Users Mailing List
>>>>>>>>>>>>>> sr-users at lists.kamailio.org
>>>>>>>>>>>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> _______________________________________________
>>>>>>>>>>>>> Kamailio (SER) - Users Mailing List
>>>>>>>>>>>>> sr-users at lists.kamailio.org
>>>>>>>>>>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> _______________________________________________
>>>>>>>>>>> Kamailio (SER) - Users Mailing List
>>>>>>>>>>> sr-users at lists.kamailio.org
>>>>>>>>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> _______________________________________________
>>>>>>>>>> Kamailio (SER) - Users Mailing List
>>>>>>>>>> sr-users at lists.kamailio.org
>>>>>>>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> _______________________________________________
>>>>>>>>> Kamailio (SER) - Users Mailing List
>>>>>>>>> sr-users at lists.kamailio.org
>>>>>>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>>>>>>
>>>>>>>>>
>>>>>>>> _______________________________________________
>>>>>>>> Kamailio (SER) - Users Mailing List
>>>>>>>> sr-users at lists.kamailio.org
>>>>>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> Kamailio (SER) - Users Mailing List
>>>>>>> sr-users at lists.kamailio.org
>>>>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> Kamailio (SER) - Users Mailing List
>>>>>> sr-users at lists.kamailio.org
>>>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>>>
>>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Kamailio (SER) - Users Mailing List
>>>>> sr-users at lists.kamailio.org
>>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> Kamailio (SER) - Users Mailing List
>>>> sr-users at lists.kamailio.org
>>>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>>>
>>>>
>>>
>>
>
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20170907/e2af5eca/attachment.html>


More information about the sr-users mailing list