[OpenSIPS-Users] variable/avp value check

Ben Newlin Ben.Newlin at genesys.com
Fri Feb 9 23:37:59 UTC 2024


The SQL Cacher module I mentioned does exactly this already. It seems you’ve just created a very simplified version of that module in your script. I’d recommend checking it out:

https://opensips.org/docs/modules/3.2.x/sql_cacher.html

Ben Newlin

From: Users <users-bounces at lists.opensips.org> on behalf of Alexey <slackway2me at gmail.com>
Date: Friday, February 9, 2024 at 12:46 PM
To: OpenSIPS users mailling list <users at lists.opensips.org>
Subject: Re: [OpenSIPS-Users] variable/avp value check
 EXTERNAL EMAIL - Please use caution with links and attachments

Hi list,
the problem was solved.


Highlights:

1. Select data from DB using timer_route with timeout (for regular data updates)
and store it in AVP. This AVP is seen in timer_route only. So, put all
its values
into the local_cache (with the same timeout), to be able to use it in
the main route.

timer_route[id_update, 300] {
    # get all IDs of customers who have some feature (our inner logic)
    # and store all them in a single AVP.
    avp_db_query("select customer_id from customers","$avp(goldencustomers)");

        # put each AVP's index value into a separate local_cache
attribute (record) with value "1".
        for ($var(blahblah) in $(avp(goldencustomers)[*]))
        cache_store ("local","goldencustomers_$var(blahblah)","1",300);
}

--------------------------------------------------------------------------------

2. Get needed parts of SIP-headers according to our inner logic...
Don't forget to reset variables before applying the value!
(See "Hints" section:
https://www.opensips.org/Documentation/Script-CoreVar-3-2#varscript )

# main route
route {
...

# initial INVITES section
...
    $var(customerfullid) = NULL;
    $var(customerfullid) = $(fn{s.select,0, }); # get "Customer-1234
from full CallerID. index 0, separator is space.

    $var(customerid) = NULL;
    $var(customerid) = $(var(customerfullid){s.select,1,-}); # get
1234 from "Customer-1234

    $var(ret) = NULL;
    cache_fetch("local", "goldencustomers_$var(blahblah)", $var(ret));
# check if there is a local_cache attribute value for INVITE with such
ID in 'From:' header
    if ($var(ret) == "1") {
        xlog("L_INFO", "[$ci] attr value from cache_local is:
$var(ret) . $var(customerfullid) has privileges. goto route
customers_gold");
        route(customers_gold);
    } else {
        xlog("L_INFO", "[$ci] attr value from cache_local is:
$var(ret) . $var(customerfullid) has no privileges. goto route
customers_all");
        route(customers_all);
    }
...
} #main route END

--------------------------------------------------------------------------------

3. Additional routes.

# do not apply global call-limits here
route[customers_gold] {
    xlog("L_INFO", "[$ci] This is $route . This $var(customerfullid)
has privileges. Global call-limits not applied.");
    ...
}

# apply global call-limits here
route[customers_all] {
    xlog("L_INFO", "[$ci] This is $route . This $var(customerfullid)
has no privileges. Global call-limits applied.");
   ... # call-limit logic
}




--
best regards, Alexey
https://alexeyka.zantsev.com

_______________________________________________
Users mailing list
Users at lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20240209/349abd48/attachment.html>


More information about the Users mailing list