Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2021-01-13 Thread Mark Allen
Your right Johan! :-D

For info  - I do see an error in the log...

TIMER_ROUTE: get data
ERROR:core:parse_from_header: bad msg or missing FROM header
ERROR:core:pv_get_from_attr: cannot parse From header
Message info: , , , DUMMY

...where "Message info" comes from: xlog("Message info: $fU, $tU, $td,
$rm");

However, I've had multiple timers kicking off LUA scripts all running for a
while now and I've not seen any problems. YMMV


On Wed, 23 Dec 2020 at 15:17, johan  wrote:

> then you are fine :-)
> On 4/12/2020 09:26, Mark Allen wrote:
>
> Interestingly - TIMER already seems to use some form of dummy message to
> avoid problems. If I add the line...
>
> timer_route[checkNodeCache, 5] {
> xlog("TIMER_ROUTE");
> xlog("Message info: $fU, $tU, $td, $rm");
>
> ...what is logged is...
>
> Message info: , , , DUMMY
>
> ...so LUA will be passed a (very simple) message it seems
>
>
>
> On Thu, 3 Dec 2020 at 15:57, Mark Allen  wrote:
>
>> LOL! Yes, I did understand, but it is an important distinction.
>>
>> On Thu, 3 Dec 2020 at 15:53, Ben Newlin  wrote:
>>
>>> It seems like you read that as I intended, but I want to clarify I meant
>>> to say I *wouldn’t* feel safe assuming that this would work long term.
>>>
>>>
>>>
>>> Ben Newlin
>>>
>>>
>>>
>>> *From: *Users  on behalf of Mark
>>> Allen 
>>> *Date: *Thursday, December 3, 2020 at 10:40 AM
>>> *To: *OpenSIPS users mailling list 
>>> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>>>
>>> > a memory leak or segfault after continued use
>>>
>>>
>>>
>>> Yes - it would be useful to know if this could result in problems down
>>> the road. Not sure how else I can run a timed job if I can't use the TIMER
>>> route though.
>>>
>>>
>>>
>>> On Thu, 3 Dec 2020 at 15:17, Ben Newlin  wrote:
>>>
>>> Mark,
>>>
>>>
>>>
>>> My concern was less about you using the message object in LUA as it was
>>> with how robust OpenSIPS’ handling is if a message if expected to be there
>>> and memory is allocated and passed but there is no actual message due to
>>> this “trick”. Without digging into the actual code, I would feel safe
>>> assuming that this wouldn’t result in a memory leak or segfault after
>>> continued use.
>>>
>>>
>>>
>>> Ben Newlin
>>>
>>>
>>>
>>> *From: *Users  on behalf of Mark
>>> Allen 
>>> *Date: *Thursday, December 3, 2020 at 10:04 AM
>>> *To: *OpenSIPS users mailling list 
>>> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>>>
>>> Thanks, Johan and Ben.
>>>
>>>
>>>
>>> Johan:
>>>
>>> I tried your suggested approach and (much to my surprise) it worked both
>>> for lua_exec and cache_remove_chunk. Thanks for that.
>>>
>>>
>>>
>>> Ben:
>>>
>>> I understand what you are saying for LUA. However, I think that if it's
>>> made clear that you do not have access to (or should not use) the message,
>>> the results should be predictable. It seems to work for me.
>>>
>>>
>>>
>>> My LUA function is reading in external data and doesn't make use of the
>>> message at all. Perhaps there might be a way to provide an empty message to
>>> LUA if it's invoked in TIMER  routes to avoid possible problems? LUA and
>>> Python offer powerful extendablity to OpenSIPS, so it seems to me to be a
>>> bit of a shame to limit their use at startup or in timers if all that's
>>> needed is a tweak - or even just a warning in the documentation.
>>>
>>>
>>>
>>> As for the "cache_remove_chunk" - it's less clear why TIMER couldn't run
>>> this in a straightforward way as it's not dependent on the current message
>>> as far as I understand it.
>>>
>>>
>>>
>>>
>>>
>>> If anybody wants to try doing this - here's an example that worked for
>>> me in OpenSIPS 3.1...
>>>
>>>
>>>
>>> timer_route[refreshNodes, 30] {
>>> route(remove_chunk);
>>> route(cache_reload);
>>>
>>> }
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>   

Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-23 Thread johan
then you are fine :-)

On 4/12/2020 09:26, Mark Allen wrote:
> Interestingly - TIMER already seems to use some form of dummy message
> to avoid problems. If I add the line...
>
>     timer_route[checkNodeCache, 5] {
>         xlog("TIMER_ROUTE");
>         xlog("Message info: $fU, $tU, $td, $rm");
>
> ...what is logged is...
>
>     Message info: , , , DUMMY
>
> ...so LUA will be passed a (very simple) message it seems
>
>
>
> On Thu, 3 Dec 2020 at 15:57, Mark Allen  <mailto:m...@allenclan.co.uk>> wrote:
>
> LOL! Yes, I did understand, but it is an important distinction.
>
> On Thu, 3 Dec 2020 at 15:53, Ben Newlin  <mailto:ben.new...@genesys.com>> wrote:
>
> It seems like you read that as I intended, but I want to
> clarify I meant to say I /wouldn’t/ feel safe assuming that
> this would work long term.
>
>  
>
> Ben Newlin
>
>  
>
> *From: *Users  <mailto:users-boun...@lists.opensips.org>> on behalf of Mark
> Allen mailto:m...@allenclan.co.uk>>
> *Date: *Thursday, December 3, 2020 at 10:40 AM
> *To: *OpenSIPS users mailling list  <mailto:users@lists.opensips.org>>
> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route -
> OpenSIPS 3.1
>
> > a memory leak or segfault after continued use
>
>  
>
> Yes - it would be useful to know if this could result in
> problems down the road. Not sure how else I can run a timed
> job if I can't use the TIMER route though.
>
>  
>
> On Thu, 3 Dec 2020 at 15:17, Ben Newlin
> mailto:ben.new...@genesys.com>> wrote:
>
> Mark,
>
>  
>
> My concern was less about you using the message object in
> LUA as it was with how robust OpenSIPS’ handling is if a
> message if expected to be there and memory is allocated
> and passed but there is no actual message due to this
> “trick”. Without digging into the actual code, I would
> feel safe assuming that this wouldn’t result in a memory
> leak or segfault after continued use.
>
>  
>
> Ben Newlin
>
>  
>
> *From: *Users  <mailto:users-boun...@lists.opensips.org>> on behalf of
> Mark Allen      <mailto:m...@allenclan.co.uk>>
> *Date: *Thursday, December 3, 2020 at 10:04 AM
> *To: *OpenSIPS users mailling list
> mailto:users@lists.opensips.org>>
> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route -
> OpenSIPS 3.1
>
> Thanks, Johan and Ben.
>
>  
>
> Johan:
>
> I tried your suggested approach and (much to my surprise)
> it worked both for lua_exec and cache_remove_chunk. Thanks
> for that.
>
>  
>
> Ben:
>
> I understand what you are saying for LUA. However, I think
> that if it's made clear that you do not have access to (or
> should not use) the message, the results should be
> predictable. It seems to work for me.
>
>  
>
> My LUA function is reading in external data and doesn't
> make use of the message at all. Perhaps there might be a
> way to provide an empty message to LUA if it's invoked in
> TIMER  routes to avoid possible problems? LUA and Python
> offer powerful extendablity to OpenSIPS, so it seems to me
> to be a bit of a shame to limit their use at startup or in
> timers if all that's needed is a tweak - or even just a
> warning in the documentation.
>
>  
>
> As for the "cache_remove_chunk" - it's less clear why
> TIMER couldn't run this in a straightforward way as it's
> not dependent on the current message as far as I
> understand it.
>
>  
>
>  
>
> If anybody wants to try doing this - here's an example
> that worked for me in OpenSIPS 3.1...
>
>  
>
>     timer_route[refreshNodes, 30] {
>         route(remove_chunk);
>         route(cache_reload);
>
>     }
>
>  
>
>  
>
>  
>
&g

Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-04 Thread Mark Allen
Interestingly - TIMER already seems to use some form of dummy message to
avoid problems. If I add the line...

timer_route[checkNodeCache, 5] {
xlog("TIMER_ROUTE");
xlog("Message info: $fU, $tU, $td, $rm");

...what is logged is...

Message info: , , , DUMMY

...so LUA will be passed a (very simple) message it seems



On Thu, 3 Dec 2020 at 15:57, Mark Allen  wrote:

> LOL! Yes, I did understand, but it is an important distinction.
>
> On Thu, 3 Dec 2020 at 15:53, Ben Newlin  wrote:
>
>> It seems like you read that as I intended, but I want to clarify I meant
>> to say I *wouldn’t* feel safe assuming that this would work long term.
>>
>>
>>
>> Ben Newlin
>>
>>
>>
>> *From: *Users  on behalf of Mark Allen
>> 
>> *Date: *Thursday, December 3, 2020 at 10:40 AM
>> *To: *OpenSIPS users mailling list 
>> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>>
>> > a memory leak or segfault after continued use
>>
>>
>>
>> Yes - it would be useful to know if this could result in problems down
>> the road. Not sure how else I can run a timed job if I can't use the TIMER
>> route though.
>>
>>
>>
>> On Thu, 3 Dec 2020 at 15:17, Ben Newlin  wrote:
>>
>> Mark,
>>
>>
>>
>> My concern was less about you using the message object in LUA as it was
>> with how robust OpenSIPS’ handling is if a message if expected to be there
>> and memory is allocated and passed but there is no actual message due to
>> this “trick”. Without digging into the actual code, I would feel safe
>> assuming that this wouldn’t result in a memory leak or segfault after
>> continued use.
>>
>>
>>
>> Ben Newlin
>>
>>
>>
>> *From: *Users  on behalf of Mark Allen
>> 
>> *Date: *Thursday, December 3, 2020 at 10:04 AM
>> *To: *OpenSIPS users mailling list 
>> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>>
>> Thanks, Johan and Ben.
>>
>>
>>
>> Johan:
>>
>> I tried your suggested approach and (much to my surprise) it worked both
>> for lua_exec and cache_remove_chunk. Thanks for that.
>>
>>
>>
>> Ben:
>>
>> I understand what you are saying for LUA. However, I think that if it's
>> made clear that you do not have access to (or should not use) the message,
>> the results should be predictable. It seems to work for me.
>>
>>
>>
>> My LUA function is reading in external data and doesn't make use of the
>> message at all. Perhaps there might be a way to provide an empty message to
>> LUA if it's invoked in TIMER  routes to avoid possible problems? LUA and
>> Python offer powerful extendablity to OpenSIPS, so it seems to me to be a
>> bit of a shame to limit their use at startup or in timers if all that's
>> needed is a tweak - or even just a warning in the documentation.
>>
>>
>>
>> As for the "cache_remove_chunk" - it's less clear why TIMER couldn't run
>> this in a straightforward way as it's not dependent on the current message
>> as far as I understand it.
>>
>>
>>
>>
>>
>> If anybody wants to try doing this - here's an example that worked for me
>> in OpenSIPS 3.1...
>>
>>
>>
>> timer_route[refreshNodes, 30] {
>> route(remove_chunk);
>> route(cache_reload);
>>
>> }
>>
>>
>>
>>
>>
>>
>>
>> route[remove_chunk] {
>> cache_remove_chunk("validNodes", "*");
>> }
>>
>> route[cache_reload] {
>> lua_exec("getValidNodes");
>> for ($var(node) in $(avp(validNodes)[*])) {
>> cache_store("local:validNodes", "$var(node)", "true");
>> }
>> }
>>
>>
>>
>>
>>
>>
>>
>> On Thu, 3 Dec 2020 at 14:20, Ben Newlin  wrote:
>>
>> I wouldn’t recommend trying to bypass the restriction in this way. Both
>> the lua and python exec modules were designed to operate on a SIP message,
>> which is why they can only be called from routes that process messages.
>> Calling it from time_route where there is no message, even if you could get
>> it to work, could have unexpected and unpleasant results.
>>
>>
>>
>> From LUA module doc for lua_exec: “Calls a Lua function with passing it
>> the current SIP message” [

Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Mark Allen
LOL! Yes, I did understand, but it is an important distinction.

On Thu, 3 Dec 2020 at 15:53, Ben Newlin  wrote:

> It seems like you read that as I intended, but I want to clarify I meant
> to say I *wouldn’t* feel safe assuming that this would work long term.
>
>
>
> Ben Newlin
>
>
>
> *From: *Users  on behalf of Mark Allen <
> m...@allenclan.co.uk>
> *Date: *Thursday, December 3, 2020 at 10:40 AM
> *To: *OpenSIPS users mailling list 
> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>
> > a memory leak or segfault after continued use
>
>
>
> Yes - it would be useful to know if this could result in problems down the
> road. Not sure how else I can run a timed job if I can't use the TIMER
> route though.
>
>
>
> On Thu, 3 Dec 2020 at 15:17, Ben Newlin  wrote:
>
> Mark,
>
>
>
> My concern was less about you using the message object in LUA as it was
> with how robust OpenSIPS’ handling is if a message if expected to be there
> and memory is allocated and passed but there is no actual message due to
> this “trick”. Without digging into the actual code, I would feel safe
> assuming that this wouldn’t result in a memory leak or segfault after
> continued use.
>
>
>
> Ben Newlin
>
>
>
> *From: *Users  on behalf of Mark Allen <
> m...@allenclan.co.uk>
> *Date: *Thursday, December 3, 2020 at 10:04 AM
> *To: *OpenSIPS users mailling list 
> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>
> Thanks, Johan and Ben.
>
>
>
> Johan:
>
> I tried your suggested approach and (much to my surprise) it worked both
> for lua_exec and cache_remove_chunk. Thanks for that.
>
>
>
> Ben:
>
> I understand what you are saying for LUA. However, I think that if it's
> made clear that you do not have access to (or should not use) the message,
> the results should be predictable. It seems to work for me.
>
>
>
> My LUA function is reading in external data and doesn't make use of the
> message at all. Perhaps there might be a way to provide an empty message to
> LUA if it's invoked in TIMER  routes to avoid possible problems? LUA and
> Python offer powerful extendablity to OpenSIPS, so it seems to me to be a
> bit of a shame to limit their use at startup or in timers if all that's
> needed is a tweak - or even just a warning in the documentation.
>
>
>
> As for the "cache_remove_chunk" - it's less clear why TIMER couldn't run
> this in a straightforward way as it's not dependent on the current message
> as far as I understand it.
>
>
>
>
>
> If anybody wants to try doing this - here's an example that worked for me
> in OpenSIPS 3.1...
>
>
>
> timer_route[refreshNodes, 30] {
> route(remove_chunk);
> route(cache_reload);
>
> }
>
>
>
>
>
>
>
> route[remove_chunk] {
> cache_remove_chunk("validNodes", "*");
> }
>
> route[cache_reload] {
> lua_exec("getValidNodes");
> for ($var(node) in $(avp(validNodes)[*])) {
> cache_store("local:validNodes", "$var(node)", "true");
> }
> }
>
>
>
>
>
>
>
> On Thu, 3 Dec 2020 at 14:20, Ben Newlin  wrote:
>
> I wouldn’t recommend trying to bypass the restriction in this way. Both
> the lua and python exec modules were designed to operate on a SIP message,
> which is why they can only be called from routes that process messages.
> Calling it from time_route where there is no message, even if you could get
> it to work, could have unexpected and unpleasant results.
>
>
>
> From LUA module doc for lua_exec: “Calls a Lua function with passing it
> the current SIP message” [1].
>
>
>
> [1] https://opensips.org/docs/modules/3.1.x/lua.html#idp5933680
>
>
>
> Ben Newlin
>
>
>
> *From: *Users  on behalf of Johan De
> Clercq 
> *Date: *Thursday, December 3, 2020 at 6:55 AM
> *To: *OpenSIPS users mailling list 
> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>
> what you can try, is to call another route in the time route.
>
> And then in that route, you execute the lua script.
>
> maybe (just a myabe) that will work.
>
>
>
> wkr,
>
>
>
> Op do 3 dec. 2020 om 12:23 schreef Mark Allen :
>
> Hi Johan
>
>
>
> In the documentation for 3.1 lua module - TIMER_ROUTE is not one of the
> routes available to lua_exec. If I include it in a TIMER route, OpenSIPS
> fails to start with syntax error and the log error is:
>
>
>
> CRITICAL

Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Ben Newlin
It seems like you read that as I intended, but I want to clarify I meant to say 
I wouldn’t feel safe assuming that this would work long term.

Ben Newlin

From: Users  on behalf of Mark Allen 

Date: Thursday, December 3, 2020 at 10:40 AM
To: OpenSIPS users mailling list 
Subject: Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
> a memory leak or segfault after continued use

Yes - it would be useful to know if this could result in problems down the 
road. Not sure how else I can run a timed job if I can't use the TIMER route 
though.

On Thu, 3 Dec 2020 at 15:17, Ben Newlin 
mailto:ben.new...@genesys.com>> wrote:
Mark,

My concern was less about you using the message object in LUA as it was with 
how robust OpenSIPS’ handling is if a message if expected to be there and 
memory is allocated and passed but there is no actual message due to this 
“trick”. Without digging into the actual code, I would feel safe assuming that 
this wouldn’t result in a memory leak or segfault after continued use.

Ben Newlin

From: Users 
mailto:users-boun...@lists.opensips.org>> on 
behalf of Mark Allen mailto:m...@allenclan.co.uk>>
Date: Thursday, December 3, 2020 at 10:04 AM
To: OpenSIPS users mailling list 
mailto:users@lists.opensips.org>>
Subject: Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
Thanks, Johan and Ben.

Johan:
I tried your suggested approach and (much to my surprise) it worked both for 
lua_exec and cache_remove_chunk. Thanks for that.

Ben:
I understand what you are saying for LUA. However, I think that if it's made 
clear that you do not have access to (or should not use) the message, the 
results should be predictable. It seems to work for me.

My LUA function is reading in external data and doesn't make use of the message 
at all. Perhaps there might be a way to provide an empty message to LUA if it's 
invoked in TIMER  routes to avoid possible problems? LUA and Python offer 
powerful extendablity to OpenSIPS, so it seems to me to be a bit of a shame to 
limit their use at startup or in timers if all that's needed is a tweak - or 
even just a warning in the documentation.

As for the "cache_remove_chunk" - it's less clear why TIMER couldn't run this 
in a straightforward way as it's not dependent on the current message as far as 
I understand it.


If anybody wants to try doing this - here's an example that worked for me in 
OpenSIPS 3.1...

timer_route[refreshNodes, 30] {
route(remove_chunk);
route(cache_reload);
}



route[remove_chunk] {
cache_remove_chunk("validNodes", "*");
}

route[cache_reload] {
lua_exec("getValidNodes");
for ($var(node) in $(avp(validNodes)[*])) {
cache_store("local:validNodes", "$var(node)", "true");
}
}



On Thu, 3 Dec 2020 at 14:20, Ben Newlin 
mailto:ben.new...@genesys.com>> wrote:
I wouldn’t recommend trying to bypass the restriction in this way. Both the lua 
and python exec modules were designed to operate on a SIP message, which is why 
they can only be called from routes that process messages. Calling it from 
time_route where there is no message, even if you could get it to work, could 
have unexpected and unpleasant results.

>From LUA module doc for lua_exec: “Calls a Lua function with passing it the 
>current SIP message” [1].

[1] 
https://opensips.org/docs/modules/3.1.x/lua.html#idp5933680<https://opensips.org/docs/modules/3.1.x/lua.html#idp5933680>

Ben Newlin

From: Users 
mailto:users-boun...@lists.opensips.org>> on 
behalf of Johan De Clercq mailto:jo...@democon.be>>
Date: Thursday, December 3, 2020 at 6:55 AM
To: OpenSIPS users mailling list 
mailto:users@lists.opensips.org>>
Subject: Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
what you can try, is to call another route in the time route.
And then in that route, you execute the lua script.
maybe (just a myabe) that will work.

wkr,

Op do 3 dec. 2020 om 12:23 schreef Mark Allen 
mailto:m...@allenclan.co.uk>>:
Hi Johan

In the documentation for 3.1 lua module - TIMER_ROUTE is not one of the routes 
available to lua_exec. If I include it in a TIMER route, OpenSIPS fails to 
start with syntax error and the log error is:

CRITICAL:core:yyerror: parse error in /etc/opensips/opensips.cfg:265:19-20: 
Command  cannot be used in the block#012

If I move the lua_exec command into main route{ it works fine

I also encounter the problem running a cache_remove_chunk in a TIMER route 
although the documentation doesn't say that it's not valid for TIMER route. It 
fails on startup with the error:

CRITICAL:core:yyerror: parse error in /etc/opensips/opensips.cfg:266:33-34: 
Command  cannot be used in the block#012

Again - if I run the command in main route{ the command works fine


cheers,

Mark

O

Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Mark Allen
> a memory leak or segfault after continued use

Yes - it would be useful to know if this could result in problems down the
road. Not sure how else I can run a timed job if I can't use the TIMER
route though.

On Thu, 3 Dec 2020 at 15:17, Ben Newlin  wrote:

> Mark,
>
>
>
> My concern was less about you using the message object in LUA as it was
> with how robust OpenSIPS’ handling is if a message if expected to be there
> and memory is allocated and passed but there is no actual message due to
> this “trick”. Without digging into the actual code, I would feel safe
> assuming that this wouldn’t result in a memory leak or segfault after
> continued use.
>
>
>
> Ben Newlin
>
>
>
> *From: *Users  on behalf of Mark Allen <
> m...@allenclan.co.uk>
> *Date: *Thursday, December 3, 2020 at 10:04 AM
> *To: *OpenSIPS users mailling list 
> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>
> Thanks, Johan and Ben.
>
>
>
> Johan:
>
> I tried your suggested approach and (much to my surprise) it worked both
> for lua_exec and cache_remove_chunk. Thanks for that.
>
>
>
> Ben:
>
> I understand what you are saying for LUA. However, I think that if it's
> made clear that you do not have access to (or should not use) the message,
> the results should be predictable. It seems to work for me.
>
>
>
> My LUA function is reading in external data and doesn't make use of the
> message at all. Perhaps there might be a way to provide an empty message to
> LUA if it's invoked in TIMER  routes to avoid possible problems? LUA and
> Python offer powerful extendablity to OpenSIPS, so it seems to me to be a
> bit of a shame to limit their use at startup or in timers if all that's
> needed is a tweak - or even just a warning in the documentation.
>
>
>
> As for the "cache_remove_chunk" - it's less clear why TIMER couldn't run
> this in a straightforward way as it's not dependent on the current message
> as far as I understand it.
>
>
>
>
>
> If anybody wants to try doing this - here's an example that worked for me
> in OpenSIPS 3.1...
>
>
>
> timer_route[refreshNodes, 30] {
> route(remove_chunk);
> route(cache_reload);
>
> }
>
>
>
>
>
>
>
> route[remove_chunk] {
> cache_remove_chunk("validNodes", "*");
> }
>
> route[cache_reload] {
> lua_exec("getValidNodes");
> for ($var(node) in $(avp(validNodes)[*])) {
> cache_store("local:validNodes", "$var(node)", "true");
> }
> }
>
>
>
>
>
>
>
> On Thu, 3 Dec 2020 at 14:20, Ben Newlin  wrote:
>
> I wouldn’t recommend trying to bypass the restriction in this way. Both
> the lua and python exec modules were designed to operate on a SIP message,
> which is why they can only be called from routes that process messages.
> Calling it from time_route where there is no message, even if you could get
> it to work, could have unexpected and unpleasant results.
>
>
>
> From LUA module doc for lua_exec: “Calls a Lua function with passing it
> the current SIP message” [1].
>
>
>
> [1] https://opensips.org/docs/modules/3.1.x/lua.html#idp5933680
>
>
>
> Ben Newlin
>
>
>
> *From: *Users  on behalf of Johan De
> Clercq 
> *Date: *Thursday, December 3, 2020 at 6:55 AM
> *To: *OpenSIPS users mailling list 
> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>
> what you can try, is to call another route in the time route.
>
> And then in that route, you execute the lua script.
>
> maybe (just a myabe) that will work.
>
>
>
> wkr,
>
>
>
> Op do 3 dec. 2020 om 12:23 schreef Mark Allen :
>
> Hi Johan
>
>
>
> In the documentation for 3.1 lua module - TIMER_ROUTE is not one of the
> routes available to lua_exec. If I include it in a TIMER route, OpenSIPS
> fails to start with syntax error and the log error is:
>
>
>
> CRITICAL:core:yyerror: parse error in
> /etc/opensips/opensips.cfg:265:19-20: Command  cannot be used in
> the block#012
>
>
>
> If I move the lua_exec command into main route{ it works fine
>
>
>
> I also encounter the problem running a cache_remove_chunk in a TIMER route
> although the documentation doesn't say that it's not valid for TIMER route.
> It fails on startup with the error:
>
>
>
> CRITICAL:core:yyerror: parse error in
> /etc/opensips/opensips.cfg:266:33-34: Command  cannot
> be used in the block#012
>
>
>
> Again - if I run the c

Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Ben Newlin
Mark,

My concern was less about you using the message object in LUA as it was with 
how robust OpenSIPS’ handling is if a message if expected to be there and 
memory is allocated and passed but there is no actual message due to this 
“trick”. Without digging into the actual code, I would feel safe assuming that 
this wouldn’t result in a memory leak or segfault after continued use.

Ben Newlin

From: Users  on behalf of Mark Allen 

Date: Thursday, December 3, 2020 at 10:04 AM
To: OpenSIPS users mailling list 
Subject: Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
Thanks, Johan and Ben.

Johan:
I tried your suggested approach and (much to my surprise) it worked both for 
lua_exec and cache_remove_chunk. Thanks for that.

Ben:
I understand what you are saying for LUA. However, I think that if it's made 
clear that you do not have access to (or should not use) the message, the 
results should be predictable. It seems to work for me.

My LUA function is reading in external data and doesn't make use of the message 
at all. Perhaps there might be a way to provide an empty message to LUA if it's 
invoked in TIMER  routes to avoid possible problems? LUA and Python offer 
powerful extendablity to OpenSIPS, so it seems to me to be a bit of a shame to 
limit their use at startup or in timers if all that's needed is a tweak - or 
even just a warning in the documentation.

As for the "cache_remove_chunk" - it's less clear why TIMER couldn't run this 
in a straightforward way as it's not dependent on the current message as far as 
I understand it.


If anybody wants to try doing this - here's an example that worked for me in 
OpenSIPS 3.1...

timer_route[refreshNodes, 30] {
route(remove_chunk);
route(cache_reload);
}



route[remove_chunk] {
cache_remove_chunk("validNodes", "*");
}

route[cache_reload] {
lua_exec("getValidNodes");
for ($var(node) in $(avp(validNodes)[*])) {
cache_store("local:validNodes", "$var(node)", "true");
}
}



On Thu, 3 Dec 2020 at 14:20, Ben Newlin 
mailto:ben.new...@genesys.com>> wrote:
I wouldn’t recommend trying to bypass the restriction in this way. Both the lua 
and python exec modules were designed to operate on a SIP message, which is why 
they can only be called from routes that process messages. Calling it from 
time_route where there is no message, even if you could get it to work, could 
have unexpected and unpleasant results.

>From LUA module doc for lua_exec: “Calls a Lua function with passing it the 
>current SIP message” [1].

[1] 
https://opensips.org/docs/modules/3.1.x/lua.html#idp5933680<https://opensips.org/docs/modules/3.1.x/lua.html#idp5933680>

Ben Newlin

From: Users 
mailto:users-boun...@lists.opensips.org>> on 
behalf of Johan De Clercq mailto:jo...@democon.be>>
Date: Thursday, December 3, 2020 at 6:55 AM
To: OpenSIPS users mailling list 
mailto:users@lists.opensips.org>>
Subject: Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
what you can try, is to call another route in the time route.
And then in that route, you execute the lua script.
maybe (just a myabe) that will work.

wkr,

Op do 3 dec. 2020 om 12:23 schreef Mark Allen 
mailto:m...@allenclan.co.uk>>:
Hi Johan

In the documentation for 3.1 lua module - TIMER_ROUTE is not one of the routes 
available to lua_exec. If I include it in a TIMER route, OpenSIPS fails to 
start with syntax error and the log error is:

CRITICAL:core:yyerror: parse error in /etc/opensips/opensips.cfg:265:19-20: 
Command  cannot be used in the block#012

If I move the lua_exec command into main route{ it works fine

I also encounter the problem running a cache_remove_chunk in a TIMER route 
although the documentation doesn't say that it's not valid for TIMER route. It 
fails on startup with the error:

CRITICAL:core:yyerror: parse error in /etc/opensips/opensips.cfg:266:33-34: 
Command  cannot be used in the block#012

Again - if I run the command in main route{ the command works fine


cheers,

Mark

On Thu, 3 Dec 2020 at 11:01, Johan De Clercq 
mailto:jo...@democon.be>> wrote:
It for sure does not run in async mode.
Did you try executing a script in timer route ?
What's the output in the log ?

Op do 3 dec. 2020 om 11:56 schreef Mark Allen 
mailto:m...@allenclan.co.uk>>:
Is there a way to run a lua_exec from a timer route?
___
Users mailing list
Users@lists.opensips.org<mailto:Users@lists.opensips.org>
http://lists.opensips.org/cgi-bin/mailman/listinfo/users<http://lists.opensips.org/cgi-bin/mailman/listinfo/users>
___
Users mailing list
Users@lists.opensips.org<mailto:Users@lists.opensips.org>
http://lists.opensips.org/cgi-bin/mailman

Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Mark Allen
Thanks, Johan and Ben.

Johan:
I tried your suggested approach and (much to my surprise) it worked both
for lua_exec and cache_remove_chunk. Thanks for that.

Ben:
I understand what you are saying for LUA. However, I think that if it's
made clear that you do not have access to (or should not use) the message,
the results should be predictable. It seems to work for me.

My LUA function is reading in external data and doesn't make use of the
message at all. Perhaps there might be a way to provide an empty message to
LUA if it's invoked in TIMER  routes to avoid possible problems? LUA and
Python offer powerful extendablity to OpenSIPS, so it seems to me to be a
bit of a shame to limit their use at startup or in timers if all that's
needed is a tweak - or even just a warning in the documentation.

As for the "cache_remove_chunk" - it's less clear why TIMER couldn't run
this in a straightforward way as it's not dependent on the current message
as far as I understand it.


If anybody wants to try doing this - here's an example that worked for me
in OpenSIPS 3.1...

timer_route[refreshNodes, 30] {
route(remove_chunk);
route(cache_reload);
}



route[remove_chunk] {
cache_remove_chunk("validNodes", "*");
}

route[cache_reload] {
lua_exec("getValidNodes");
for ($var(node) in $(avp(validNodes)[*])) {
cache_store("local:validNodes", "$var(node)", "true");
}
}



On Thu, 3 Dec 2020 at 14:20, Ben Newlin  wrote:

> I wouldn’t recommend trying to bypass the restriction in this way. Both
> the lua and python exec modules were designed to operate on a SIP message,
> which is why they can only be called from routes that process messages.
> Calling it from time_route where there is no message, even if you could get
> it to work, could have unexpected and unpleasant results.
>
>
>
> From LUA module doc for lua_exec: “Calls a Lua function with passing it
> the current SIP message” [1].
>
>
>
> [1] https://opensips.org/docs/modules/3.1.x/lua.html#idp5933680
>
>
>
> Ben Newlin
>
>
>
> *From: *Users  on behalf of Johan De
> Clercq 
> *Date: *Thursday, December 3, 2020 at 6:55 AM
> *To: *OpenSIPS users mailling list 
> *Subject: *Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
>
> what you can try, is to call another route in the time route.
>
> And then in that route, you execute the lua script.
>
> maybe (just a myabe) that will work.
>
>
>
> wkr,
>
>
>
> Op do 3 dec. 2020 om 12:23 schreef Mark Allen :
>
> Hi Johan
>
>
>
> In the documentation for 3.1 lua module - TIMER_ROUTE is not one of the
> routes available to lua_exec. If I include it in a TIMER route, OpenSIPS
> fails to start with syntax error and the log error is:
>
>
>
> CRITICAL:core:yyerror: parse error in
> /etc/opensips/opensips.cfg:265:19-20: Command  cannot be used in
> the block#012
>
>
>
> If I move the lua_exec command into main route{ it works fine
>
>
>
> I also encounter the problem running a cache_remove_chunk in a TIMER route
> although the documentation doesn't say that it's not valid for TIMER route.
> It fails on startup with the error:
>
>
>
> CRITICAL:core:yyerror: parse error in
> /etc/opensips/opensips.cfg:266:33-34: Command  cannot
> be used in the block#012
>
>
>
> Again - if I run the command in main route{ the command works fine
>
>
>
>
>
> cheers,
>
>
>
> Mark
>
>
>
> On Thu, 3 Dec 2020 at 11:01, Johan De Clercq  wrote:
>
> It for sure does not run in async mode.
>
> Did you try executing a script in timer route ?
>
> What's the output in the log ?
>
>
>
> Op do 3 dec. 2020 om 11:56 schreef Mark Allen :
>
> Is there a way to run a lua_exec from a timer route?
>
> ___
> Users mailing list
> Users@lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
> ___
> Users mailing list
> Users@lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
> ___
> Users mailing list
> Users@lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
> ___
> Users mailing list
> Users@lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Ben Newlin
I wouldn’t recommend trying to bypass the restriction in this way. Both the lua 
and python exec modules were designed to operate on a SIP message, which is why 
they can only be called from routes that process messages. Calling it from 
time_route where there is no message, even if you could get it to work, could 
have unexpected and unpleasant results.

>From LUA module doc for lua_exec: “Calls a Lua function with passing it the 
>current SIP message” [1].

[1] https://opensips.org/docs/modules/3.1.x/lua.html#idp5933680

Ben Newlin

From: Users  on behalf of Johan De Clercq 

Date: Thursday, December 3, 2020 at 6:55 AM
To: OpenSIPS users mailling list 
Subject: Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1
what you can try, is to call another route in the time route.
And then in that route, you execute the lua script.
maybe (just a myabe) that will work.

wkr,

Op do 3 dec. 2020 om 12:23 schreef Mark Allen 
mailto:m...@allenclan.co.uk>>:
Hi Johan

In the documentation for 3.1 lua module - TIMER_ROUTE is not one of the routes 
available to lua_exec. If I include it in a TIMER route, OpenSIPS fails to 
start with syntax error and the log error is:

CRITICAL:core:yyerror: parse error in /etc/opensips/opensips.cfg:265:19-20: 
Command  cannot be used in the block#012

If I move the lua_exec command into main route{ it works fine

I also encounter the problem running a cache_remove_chunk in a TIMER route 
although the documentation doesn't say that it's not valid for TIMER route. It 
fails on startup with the error:

CRITICAL:core:yyerror: parse error in /etc/opensips/opensips.cfg:266:33-34: 
Command  cannot be used in the block#012

Again - if I run the command in main route{ the command works fine


cheers,

Mark

On Thu, 3 Dec 2020 at 11:01, Johan De Clercq 
mailto:jo...@democon.be>> wrote:
It for sure does not run in async mode.
Did you try executing a script in timer route ?
What's the output in the log ?

Op do 3 dec. 2020 om 11:56 schreef Mark Allen 
mailto:m...@allenclan.co.uk>>:
Is there a way to run a lua_exec from a timer route?
___
Users mailing list
Users@lists.opensips.org<mailto:Users@lists.opensips.org>
http://lists.opensips.org/cgi-bin/mailman/listinfo/users<http://lists.opensips.org/cgi-bin/mailman/listinfo/users>
___
Users mailing list
Users@lists.opensips.org<mailto:Users@lists.opensips.org>
http://lists.opensips.org/cgi-bin/mailman/listinfo/users<http://lists.opensips.org/cgi-bin/mailman/listinfo/users>
___
Users mailing list
Users@lists.opensips.org<mailto:Users@lists.opensips.org>
http://lists.opensips.org/cgi-bin/mailman/listinfo/users<http://lists.opensips.org/cgi-bin/mailman/listinfo/users>
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Johan De Clercq
what you can try, is to call another route in the time route.
And then in that route, you execute the lua script.
maybe (just a myabe) that will work.

wkr,

Op do 3 dec. 2020 om 12:23 schreef Mark Allen :

> Hi Johan
>
> In the documentation for 3.1 lua module - TIMER_ROUTE is not one of the
> routes available to lua_exec. If I include it in a TIMER route, OpenSIPS
> fails to start with syntax error and the log error is:
>
> CRITICAL:core:yyerror: parse error in
> /etc/opensips/opensips.cfg:265:19-20: Command  cannot be used in
> the block#012
>
> If I move the lua_exec command into main route{ it works fine
>
> I also encounter the problem running a cache_remove_chunk in a TIMER route
> although the documentation doesn't say that it's not valid for TIMER route.
> It fails on startup with the error:
>
> CRITICAL:core:yyerror: parse error in
> /etc/opensips/opensips.cfg:266:33-34: Command  cannot
> be used in the block#012
>
> Again - if I run the command in main route{ the command works fine
>
>
> cheers,
>
> Mark
>
> On Thu, 3 Dec 2020 at 11:01, Johan De Clercq  wrote:
>
>> It for sure does not run in async mode.
>> Did you try executing a script in timer route ?
>> What's the output in the log ?
>>
>> Op do 3 dec. 2020 om 11:56 schreef Mark Allen :
>>
>>> Is there a way to run a lua_exec from a timer route?
>>> ___
>>> Users mailing list
>>> Users@lists.opensips.org
>>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>>
>> ___
>> Users mailing list
>> Users@lists.opensips.org
>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>
> ___
> Users mailing list
> Users@lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Mark Allen
Hi Johan

In the documentation for 3.1 lua module - TIMER_ROUTE is not one of the
routes available to lua_exec. If I include it in a TIMER route, OpenSIPS
fails to start with syntax error and the log error is:

CRITICAL:core:yyerror: parse error in
/etc/opensips/opensips.cfg:265:19-20: Command  cannot be used in
the block#012

If I move the lua_exec command into main route{ it works fine

I also encounter the problem running a cache_remove_chunk in a TIMER route
although the documentation doesn't say that it's not valid for TIMER route.
It fails on startup with the error:

CRITICAL:core:yyerror: parse error in
/etc/opensips/opensips.cfg:266:33-34: Command  cannot
be used in the block#012

Again - if I run the command in main route{ the command works fine


cheers,

Mark

On Thu, 3 Dec 2020 at 11:01, Johan De Clercq  wrote:

> It for sure does not run in async mode.
> Did you try executing a script in timer route ?
> What's the output in the log ?
>
> Op do 3 dec. 2020 om 11:56 schreef Mark Allen :
>
>> Is there a way to run a lua_exec from a timer route?
>> ___
>> Users mailing list
>> Users@lists.opensips.org
>> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>
> ___
> Users mailing list
> Users@lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


Re: [OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Johan De Clercq
It for sure does not run in async mode.
Did you try executing a script in timer route ?
What's the output in the log ?

Op do 3 dec. 2020 om 11:56 schreef Mark Allen :

> Is there a way to run a lua_exec from a timer route?
> ___
> Users mailing list
> Users@lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users


[OpenSIPS-Users] lua_exec in timer route - OpenSIPS 3.1

2020-12-03 Thread Mark Allen
Is there a way to run a lua_exec from a timer route?
___
Users mailing list
Users@lists.opensips.org
http://lists.opensips.org/cgi-bin/mailman/listinfo/users