Hello,

Works like a charm!
Thank you Daniel.

On Fri, 7 Aug 2020 at 13:30, Daniel-Constantin Mierla <miconda@gmail.com> wrote:

Hello,

use:

modparam("htable", "htable", "isp=>size=8;dbtable=isp;cols=ispname,ispip,ispuser,ipsprefix,ispprefix")

then you have the $sht(ispname) with value corresponding to "ispip,ispuser,ipsprefix,ispprefix" and then you can use {s.select,,0} to get ispname value, then {s.select,,1} to get ispip value, etc...

An alternative would be to keep only two columns in database, one (the key) with ispname and the second (the value) all fields serialized in a json document and you use jansson to parse them in config.

Cheers,
Daniel

On 07.08.20 13:06, Ilie Soltanici wrote:
Hello,

What will be the best way to save ISP Information in Kamailio memory?

I have the following information for each ISP into the DB:

ISP Name |  ISP IP  | ISP Username | ISP Password | ISP Prefix
ISP1          |  1.1.1.1 | user                  | pass                 | 1234

This info it's not changed/updated too often, so I want to avoid querying the DB on every call and get this info directly from the memory.

I was thinking to use htable for that, so I created a htable as an array for that and loaded all the information there manually, something like that:

kamcmd htable.sets isp ISP1[address] 1.1.1.1
kamcmd htable.sets isp ISP1[username] user
kamcmd htable.sets isp ISP1[password] pass
kamcmd htable.sets isp ISP1[prefix] 1234

$sht( isp => ISP1[address]) == "1.1.1.1"
$sht( isp => ISP1[username]) == "user"
$sht( isp => ISP1[password]) == "pass"
$sht( isp => ISP1[prefix]) == "1234"

So far so good, I'm able to get this information from the htable and use it whenever I need it.
Now, the problem comes when I want to load all this information automatically from the DB. How can I setup htable module to get the array key (address, username...) from the database automatically on server restart, and append this array_key to the column value?

I've tried this way:
modparam("htable""htable""isp=>size=8;dbtable=isp;cols='trunk_name[address],trunk_address'")

But it's not working unfortunately, getting back this error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[address]'

If I'm setting this way:
modparam("htable""htable""isp=>size=8;dbtable=isp;cols='trunk_name,trunk_address'")

and setting trunk_name value to: ISP1[address], then it's working fine, but in this case I will have to create by one column for each array key, which may be confusing and it's a lot of unnecessarily information into the DB.
Is it possible to do that, or better to trigger a script on each restart which will load this information from the DB into htable?
Thanks


_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users@lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Funding: https://www.paypal.me/dcmierla