[SOLVED] Multiple blacklist families in AstDB?

Hi everyone

We have several asterisk servers, usually one per client, but there is one server with multiple “tenants” for smaller clients with one or two phones. Each tenant has their own inbound and outbound context, but they are all happily residing on a single server.

I have recently been experimenting with blacklist to get rid of nuisance calls and anonymous callers with no caller IDs. I implemented that via asterisk BLACKLIST function and it is working fine. But the downside is that I can’t figure out a way to have multiple blacklists because surely not every user wants to block the same numbers. I can create my own families in AstDB if I want to, but I can’t find a way to tell function BLACKLIST to use any family other than inbuilt ‘blacklist’.

I was wondering is there a way to hack the function BLACKLIST to look for a different family in the AstDB? Surely it should be possible to have multiple functions. Or perhaps I’m approaching it from a wrong perspective?

Thanks in advance!
R

Hello.

An elegant way is to use a database , an ODBC connection to it from Asterisk and an extremely cool func_odbc.so . With it you can select (and write if you need) any values from any column of the database table. (This is also very useful: asteriskdocs.org/en/3rd_Edit … k-DB-FIG-1)

If you really want to use AstDB, I think there’s nothing impossible if you will add/get blacklisted numbers to/from AstDB with its native tools of working with AstDB.

As we know, AstDB keeps data in ‘family/key value’ format.
Nothing prevents you from creating such a structure (a unique family for each customer/context):
‘bl_customer1/123456 1’
‘bl_customer1/234567 1’

‘bl_customer2/345678 1’
‘bl_customer2/275439 1’

and so on.

same => n,Set(DB(bl_customer1/123456)=1)
same => n,Set(DB(bl_customer1/234567)=1)

or manually from Asterisk CLI:

Asterisk CLI> database put bl_customer1 123456 1 Asterisk CLI> database put bl_customer1 234567 1

then check an incoming CALLERID(num) in each tenant’s dialplan:

[incoming-customer1]
exten => XXXXXX,1,Set(isblacklisted=${DB(bl_customer1/${CALLERID(num)})})
    same => n,GotoIf($["${isblacklisted}" = "1"]?hang:dial)
    same => n(hang),Hangup()
    same => n(dial),Dial(SIP/cstmr1-ip-phone)
    ...
[incoming-customer2]
exten => XXXXXX,1,Set(isblacklisted=${DB(bl_customer2/${CALLERID(num)})})
    same => n,GotoIf($["${isblacklisted}" = "1"]?hang:dial)
    same => n(hang),Hangup()
    same => n(dial),Dial(SIP/cstmr2-ip-phone)
    ...

Using Set application, AstDB functions and GotoIf application you may add/get/delete data from AstDB and do call routing based on this selection.

Thanks a lot Lexus45, this is extremely useful! I’m going to give this a go.
Interesting stuff about func_odbc.so, definitely worth checking out too. But I suppose doing it AstDB way will be quicker for now.
Cheers!

[quote=“roman_sputnik”]Thanks a lot Lexus45, this is extremely useful! I’m going to give this a go.
Interesting stuff about func_odbc.so, definitely worth checking out too. But I suppose doing it AstDB way will be quicker for now.
Cheers![/quote]
I haven’t tested this . But hope it works.
ODBC is good in large implementations.

Yep, that worked absolutely fine. We are using realtime so I had to write it a little differently, but after seeing your example it clicked in my head and everything came together - it makes sense now.