New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evalpy filter issues #196

Closed
farirat opened this Issue Jun 21, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@farirat
Contributor

farirat commented Jun 21, 2015

After creating an evalpy filter and adding it to a route, as soon as the message is sent jcli mtrouter command stops working. if, for example, "mtrouter -l" command is executed, jcli console exits with the "Connection closed by foreign host" message. Then jasmin service needs a restart.

Additionally, message never gets properly routed as neither username nor user_id is successfully matched to the "routable.user".

Speaking of persistence, I also noticed when evalpy filter with corresponding mtrouter is created, if not persisted before leaving jcli, after leaving jcli it's lost and recreation is needed for both filter an mtrouter.

Currently I'm on version b26.

@farirat farirat added the bug label Jun 21, 2015

@farirat farirat self-assigned this Jun 21, 2015

@farirat farirat added this to the v0.6 milestone Jun 21, 2015

@farirat

This comment has been minimized.

Show comment
Hide comment
@farirat

farirat Jun 21, 2015

Contributor

I've tried to reproduce the issue with no success, here's what i did:

sername: jcliadmin
Password: 
Welcome to Jasmin console
Type help or ? to list commands.

Session ref: 2
jcli : filter -l
#Filter id        Type                   Routes Description                     
#fMT1             UserFilter             MT     <UserFilter (uid=u1)>           
Total Filters: 1

jcli : filter -a
Adding a new Filter: (ok: save, ko: exit)
> type EvalPyFilter
jasmin.routing.Filters.EvalPyFilter arguments:
pyCode
> pyCode /tmp/issue-196.py
> fid issue196
> ok
Successfully added Filter [EvalPyFilter] with fid:issue196

jcli : filter -l
#Filter id        Type                   Routes Description                     
#issue196         EvalPyFilter           MO MT  <EvalPyFilter (pyCode=if routabl ..)>
#fMT1             UserFilter             MT     <UserFilter (uid=u1)>           
Total Filters: 2

jcli : mtrouter -l
#Order Type                    Rate       Connector ID(s)                                  Filter(    s)                                                       
#0     DefaultRoute            0.50000    smppc(SMPPSIM)                                                                                                   
Total MT Routes: 1

jcli : mtrouter -a
Adding a new MT Route: (ok: save, ko: exit)
> type StaticMTRoute
jasmin.routing.Routes.StaticMTRoute arguments:
filters, connector, rate
> filters issue196
> connector smppc(SMPPSIM)
> rate 0
> order 200
> ok
Successfully added MTRoute [StaticMTRoute] with order:200

jcli : mtrouter -l
#Order Type                    Rate       Connector ID(s)                                  Filter(    s)                                                       
#200   StaticMTRoute           0.00000    smppc(SMPPSIM)                                   <EvalPyFilter (    pyCode=if routabl ..)>                           
#0     DefaultRoute            0.50000    smppc(SMPPSIM)                                                                                                   
Total MT Routes: 3

And here's the /tmp/issue-196.py file:

if routable.connector.cid == 'abc':
    result = True
else:
    result = False

Please advise if you did anything different ? (using 0.6b26)

Contributor

farirat commented Jun 21, 2015

I've tried to reproduce the issue with no success, here's what i did:

sername: jcliadmin
Password: 
Welcome to Jasmin console
Type help or ? to list commands.

Session ref: 2
jcli : filter -l
#Filter id        Type                   Routes Description                     
#fMT1             UserFilter             MT     <UserFilter (uid=u1)>           
Total Filters: 1

jcli : filter -a
Adding a new Filter: (ok: save, ko: exit)
> type EvalPyFilter
jasmin.routing.Filters.EvalPyFilter arguments:
pyCode
> pyCode /tmp/issue-196.py
> fid issue196
> ok
Successfully added Filter [EvalPyFilter] with fid:issue196

jcli : filter -l
#Filter id        Type                   Routes Description                     
#issue196         EvalPyFilter           MO MT  <EvalPyFilter (pyCode=if routabl ..)>
#fMT1             UserFilter             MT     <UserFilter (uid=u1)>           
Total Filters: 2

jcli : mtrouter -l
#Order Type                    Rate       Connector ID(s)                                  Filter(    s)                                                       
#0     DefaultRoute            0.50000    smppc(SMPPSIM)                                                                                                   
Total MT Routes: 1

jcli : mtrouter -a
Adding a new MT Route: (ok: save, ko: exit)
> type StaticMTRoute
jasmin.routing.Routes.StaticMTRoute arguments:
filters, connector, rate
> filters issue196
> connector smppc(SMPPSIM)
> rate 0
> order 200
> ok
Successfully added MTRoute [StaticMTRoute] with order:200

jcli : mtrouter -l
#Order Type                    Rate       Connector ID(s)                                  Filter(    s)                                                       
#200   StaticMTRoute           0.00000    smppc(SMPPSIM)                                   <EvalPyFilter (    pyCode=if routabl ..)>                           
#0     DefaultRoute            0.50000    smppc(SMPPSIM)                                                                                                   
Total MT Routes: 3

And here's the /tmp/issue-196.py file:

if routable.connector.cid == 'abc':
    result = True
else:
    result = False

Please advise if you did anything different ? (using 0.6b26)

@ed-irwane

This comment has been minimized.

Show comment
Hide comment
@ed-irwane

ed-irwane Jun 22, 2015

I suppose the best is to provide entire configuration causing the described issue.

Username: jcliadmin
Password:
Welcome to Jasmin console
Type help or ? to list commands.

Session ref: 2
jcli : user
Missing required option
jcli : user -l
Total Users: 0

jcli : group -a
Adding a new Group: (ok: save, ko: exit)
> gid TEST
> ok
Successfully added Group [TEST]

jcli : user -a
Adding a new User: (ok: save, ko: exit)
> uid EPY-USER
> gid TEST
> username Evalpyusr
> password Evalpy12
> ok
Successfully added User [EPY-USER] to Group [TEST]

jcli : user -a
Adding a new User: (ok: save, ko: exit)
> uid EPY-USER2
> gid TEST
> username Evalpyusr2
> password Evalpy12
> ok
Successfully added User [EPY-USER2] to Group [TEST]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT01
> host 127.0.0.1
> port 27751
> username user1
> password pass1
> submit_throughput 20
> ok
Successfully added connector [CONNECT01]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT02
> host 127.0.0.1
> port 27752
> username user2
> password pass2
> submit_throughput 20
> ok
Successfully added connector [CONNECT02]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT03
> host 127.0.0.1
> port 27753
> username user3
> password pass3
> submit_throughput 20
> ok
Successfully added connector [CONNECT03]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT04
> host 127.0.0.1
> port 27754
> username user4
> password pass4
> submit_throughput 20
> ok
Successfully added connector [CONNECT04]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT05
> host 127.0.0.1
> port 27755
> username user5
> password pass5
> submit_throughput 20
> ok
Successfully added connector [CONNECT05]

jcli : smppccm -1 CONNECT01
smppccm -1 CONNECT02
smppccm -1 CONNECT03
smppccm -1 CONNECT04
smppccm -1 CONNECT05
Successfully started connector id:CONNECT01
jcli : Successfully started connector id:CONNECT02
jcli : Successfully started connector id:CONNECT03
jcli : Successfully started connector id:CONNECT04
jcli : Successfully started connector id:CONNECT05

jcli : filter -a
Adding a new Filter: (ok: save, ko: exit)
> type EvalPyFilter
jasmin.routing.Filters.EvalPyFilter arguments:
pyCode
> pyCode /tmp/evalpy-test.py
> fid EVALPY-TEST
> ok
Successfully added Filter [EvalPyFilter] with fid:EVALPY-TEST

jcli : mtrouter -a
Adding a new MT Route: (ok: save, ko: exit)
> type StaticMTRoute
jasmin.routing.Routes.StaticMTRoute arguments:
filters, connector, rate
> filters EVALPY-TEST
> connector smppc(CONNECT04)
> rate 0.00
> order 2000
> ok
Successfully added MTRoute [StaticMTRoute] with order:2000

jcli : filter -a
Adding a new Filter: (ok: save, ko: exit)
> type DestinationAddrFilter
jasmin.routing.Filters.DestinationAddrFilter arguments:
destination_addr
> destination_addr ^([+]?|00)(1234).*$
> fid DESTNUM-TEST
> ok
Successfully added Filter [DestinationAddrFilter] with fid:DESTNUM-TEST

jcli : mtrouter -a
Adding a new MT Route: (ok: save, ko: exit)
> type RandomRoundrobinMTRoute
jasmin.routing.Routes.RandomRoundrobinMTRoute arguments:
filters, connectors, rate
> filters DESTNUM-TEST
> connectors smppc(CONNECT01);smppc(CONNECT02);smppc(CONNECT03)
> rate 0.00
> order 1000
> ok
Successfully added MTRoute [RandomRoundrobinMTRoute] with order:1000

jcli : persist
mtrouter configuration persisted (profile:jcli-prod)
smppcc configuration persisted (profile:jcli-prod)
group configuration persisted (profile:jcli-prod)
user configuration persisted (profile:jcli-prod)
httpcc configuration persisted (profile:jcli-prod)
filter configuration persisted (profile:jcli-prod)
morouter configuration persisted (profile:jcli-prod)

jcli : smppccm -l
#Connector id                        Service Session          Starts Stops
#CONNECT01                           started BOUND_TRX        1      0
#CONNECT02                           started BOUND_TRX        1      0
#CONNECT03                           stopped UNBOUND          1      1
#CONNECT04                           started BOUND_TRX        1      0
#CONNECT05                           stopped UNBOUND          1      1
Total connectors: 5

Smppc list is provided to show which one was actually connected.

Script file /tmp/evalpy-test.py looks like this:

if routable.user == 'Evalpyusr2':
    result = False
else:
    result = True

I've established SMPP connection and sent the message using the following details:

SystemID: Evalpyusr2
Password: Evalpy12

Destination number: 123455555555

Given the username, message was NOT supposed to end up on smppc(CONNECT04), but that wasn't the case. Message log as follows:

/var/log/jasmin$ tail messages.log

2015-06-22 07:49:28 INFO     23700 SMS-MT [cid:CONNECT04] [queue-msgid:9c965a02-b9d4-47b3-900d-6b47d55636cd] [smpp-msgid:0] [status:ESME_ROK] [prio:0] [dlr:SMSC_DELIVERY_RECEIPT_REQUESTED] [validity:none] [from:222222222222] [to:123455555555] [content:This is mtroute test 01.]
2015-06-22 07:49:33 INFO     23700 DLR [cid:CONNECT04] [smpp-msgid:0] [status:DELIVRD] [submit date:1506220749] [done date:1506220749] [submitted/delivered messages:001/001] [err:000] [content:This is mtroute test]

And finally, when wanted to check mtrouter configuration, the following happened:

jcli : mtrouter -lConnection closed by foreign host.

ed-irwane commented Jun 22, 2015

I suppose the best is to provide entire configuration causing the described issue.

Username: jcliadmin
Password:
Welcome to Jasmin console
Type help or ? to list commands.

Session ref: 2
jcli : user
Missing required option
jcli : user -l
Total Users: 0

jcli : group -a
Adding a new Group: (ok: save, ko: exit)
> gid TEST
> ok
Successfully added Group [TEST]

jcli : user -a
Adding a new User: (ok: save, ko: exit)
> uid EPY-USER
> gid TEST
> username Evalpyusr
> password Evalpy12
> ok
Successfully added User [EPY-USER] to Group [TEST]

jcli : user -a
Adding a new User: (ok: save, ko: exit)
> uid EPY-USER2
> gid TEST
> username Evalpyusr2
> password Evalpy12
> ok
Successfully added User [EPY-USER2] to Group [TEST]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT01
> host 127.0.0.1
> port 27751
> username user1
> password pass1
> submit_throughput 20
> ok
Successfully added connector [CONNECT01]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT02
> host 127.0.0.1
> port 27752
> username user2
> password pass2
> submit_throughput 20
> ok
Successfully added connector [CONNECT02]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT03
> host 127.0.0.1
> port 27753
> username user3
> password pass3
> submit_throughput 20
> ok
Successfully added connector [CONNECT03]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT04
> host 127.0.0.1
> port 27754
> username user4
> password pass4
> submit_throughput 20
> ok
Successfully added connector [CONNECT04]

jcli : smppccm -a
Adding a new connector: (ok: save, ko: exit)
> cid CONNECT05
> host 127.0.0.1
> port 27755
> username user5
> password pass5
> submit_throughput 20
> ok
Successfully added connector [CONNECT05]

jcli : smppccm -1 CONNECT01
smppccm -1 CONNECT02
smppccm -1 CONNECT03
smppccm -1 CONNECT04
smppccm -1 CONNECT05
Successfully started connector id:CONNECT01
jcli : Successfully started connector id:CONNECT02
jcli : Successfully started connector id:CONNECT03
jcli : Successfully started connector id:CONNECT04
jcli : Successfully started connector id:CONNECT05

jcli : filter -a
Adding a new Filter: (ok: save, ko: exit)
> type EvalPyFilter
jasmin.routing.Filters.EvalPyFilter arguments:
pyCode
> pyCode /tmp/evalpy-test.py
> fid EVALPY-TEST
> ok
Successfully added Filter [EvalPyFilter] with fid:EVALPY-TEST

jcli : mtrouter -a
Adding a new MT Route: (ok: save, ko: exit)
> type StaticMTRoute
jasmin.routing.Routes.StaticMTRoute arguments:
filters, connector, rate
> filters EVALPY-TEST
> connector smppc(CONNECT04)
> rate 0.00
> order 2000
> ok
Successfully added MTRoute [StaticMTRoute] with order:2000

jcli : filter -a
Adding a new Filter: (ok: save, ko: exit)
> type DestinationAddrFilter
jasmin.routing.Filters.DestinationAddrFilter arguments:
destination_addr
> destination_addr ^([+]?|00)(1234).*$
> fid DESTNUM-TEST
> ok
Successfully added Filter [DestinationAddrFilter] with fid:DESTNUM-TEST

jcli : mtrouter -a
Adding a new MT Route: (ok: save, ko: exit)
> type RandomRoundrobinMTRoute
jasmin.routing.Routes.RandomRoundrobinMTRoute arguments:
filters, connectors, rate
> filters DESTNUM-TEST
> connectors smppc(CONNECT01);smppc(CONNECT02);smppc(CONNECT03)
> rate 0.00
> order 1000
> ok
Successfully added MTRoute [RandomRoundrobinMTRoute] with order:1000

jcli : persist
mtrouter configuration persisted (profile:jcli-prod)
smppcc configuration persisted (profile:jcli-prod)
group configuration persisted (profile:jcli-prod)
user configuration persisted (profile:jcli-prod)
httpcc configuration persisted (profile:jcli-prod)
filter configuration persisted (profile:jcli-prod)
morouter configuration persisted (profile:jcli-prod)

jcli : smppccm -l
#Connector id                        Service Session          Starts Stops
#CONNECT01                           started BOUND_TRX        1      0
#CONNECT02                           started BOUND_TRX        1      0
#CONNECT03                           stopped UNBOUND          1      1
#CONNECT04                           started BOUND_TRX        1      0
#CONNECT05                           stopped UNBOUND          1      1
Total connectors: 5

Smppc list is provided to show which one was actually connected.

Script file /tmp/evalpy-test.py looks like this:

if routable.user == 'Evalpyusr2':
    result = False
else:
    result = True

I've established SMPP connection and sent the message using the following details:

SystemID: Evalpyusr2
Password: Evalpy12

Destination number: 123455555555

Given the username, message was NOT supposed to end up on smppc(CONNECT04), but that wasn't the case. Message log as follows:

/var/log/jasmin$ tail messages.log

2015-06-22 07:49:28 INFO     23700 SMS-MT [cid:CONNECT04] [queue-msgid:9c965a02-b9d4-47b3-900d-6b47d55636cd] [smpp-msgid:0] [status:ESME_ROK] [prio:0] [dlr:SMSC_DELIVERY_RECEIPT_REQUESTED] [validity:none] [from:222222222222] [to:123455555555] [content:This is mtroute test 01.]
2015-06-22 07:49:33 INFO     23700 DLR [cid:CONNECT04] [smpp-msgid:0] [status:DELIVRD] [submit date:1506220749] [done date:1506220749] [submitted/delivered messages:001/001] [err:000] [content:This is mtroute test]

And finally, when wanted to check mtrouter configuration, the following happened:

jcli : mtrouter -lConnection closed by foreign host.

@farirat farirat closed this in eb5cd4e Jun 23, 2015

@farirat

This comment has been minimized.

Show comment
Hide comment
@farirat

farirat Jun 23, 2015

Contributor

@ed-irwane this issue is closed in v0.6b27 so please update to get rid of it.

You have two issues:

  • There's a pickling bug fixed in the v0.6b27, this will get rid of the "Connection closed ..." error
  • Your filter will still not work because it is not due to the bug, you are getting it wrong when comparing routable.user to a string 'Evalpyusr2' !

Explanation:
As described in http://docs.jasminsms.com/en/latest/routing/index.html#routable the RoutableSubmitSm holds a user attribute of type jasmin.routing.jasminApi.User, and in your filter you're comparing it to a string.
The FAQ post were also wrong, i've just fixed it so the right comparison must be:

if routable.user.username == 'Evalpyusr2'

Additionally, you can enable logging inside your filter in order to debug what's going on there when you send a message to the filter, checkout this: http://docs.jasminsms.com/en/latest/faq/developers.html#how-to-log-events-inside-an-evalpyfilter

Contributor

farirat commented Jun 23, 2015

@ed-irwane this issue is closed in v0.6b27 so please update to get rid of it.

You have two issues:

  • There's a pickling bug fixed in the v0.6b27, this will get rid of the "Connection closed ..." error
  • Your filter will still not work because it is not due to the bug, you are getting it wrong when comparing routable.user to a string 'Evalpyusr2' !

Explanation:
As described in http://docs.jasminsms.com/en/latest/routing/index.html#routable the RoutableSubmitSm holds a user attribute of type jasmin.routing.jasminApi.User, and in your filter you're comparing it to a string.
The FAQ post were also wrong, i've just fixed it so the right comparison must be:

if routable.user.username == 'Evalpyusr2'

Additionally, you can enable logging inside your filter in order to debug what's going on there when you send a message to the filter, checkout this: http://docs.jasminsms.com/en/latest/faq/developers.html#how-to-log-events-inside-an-evalpyfilter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment