diff --git a/b2b/02.marketing/scenario.yml b/b2b/02.marketing/scenario.yml index 44fa0da..7cfc677 100644 --- a/b2b/02.marketing/scenario.yml +++ b/b2b/02.marketing/scenario.yml @@ -28,10 +28,8 @@ tasks: port: {{ operator_port }} - name: Place Call - type: opensips-cli + type: opensips-mi args: - - -x - - mi - b2b_trigger_scenario - marketing - customer,sip:customer@{{ caller_ip }}:{{ caller_port }} diff --git a/b2b/17.refer-unattended-uac-mi/scenario.yml b/b2b/17.refer-unattended-uac-mi/scenario.yml index cb3a4e4..e114d73 100644 --- a/b2b/17.refer-unattended-uac-mi/scenario.yml +++ b/b2b/17.refer-unattended-uac-mi/scenario.yml @@ -35,7 +35,7 @@ tasks: wait: 0.5 - name: MI transfer - type: opensips-cli + type: opensips-mi script: scripts/transfer.py args: sip:transfer@{{ transfer_ip }}:{{ transfer_port }} 1 require: diff --git a/b2b/17.refer-unattended-uac-mi/scripts/transfer.py b/b2b/17.refer-unattended-uac-mi/scripts/transfer.py index 4c74e5a..66faa84 100644 --- a/b2b/17.refer-unattended-uac-mi/scripts/transfer.py +++ b/b2b/17.refer-unattended-uac-mi/scripts/transfer.py @@ -1,7 +1,17 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 3: print("Usage: {} URI entity".format(sys.argv[0])) @@ -11,9 +21,9 @@ entity = sys.argv[2] prov_media_uri = sys.argv[3] if len(sys.argv) > 3 else None -dialogs = handler.mi("b2b_list") +dialogs = handler.execute("b2b_list") logic = dialogs['Tuples'][0]['key'] # we are only interested in the first dialog params = {'dialog_id':logic, 'new_uri':uri, 'flag':entity} if prov_media_uri: params['prov_media_uri'] = prov_media_uri -handler.mi("b2b_bridge", params) +handler.execute("b2b_bridge", params) diff --git a/b2b/18.refer-unattended-uas-mi/scenario.yml b/b2b/18.refer-unattended-uas-mi/scenario.yml index 1ac2e3f..d3710e7 100644 --- a/b2b/18.refer-unattended-uas-mi/scenario.yml +++ b/b2b/18.refer-unattended-uas-mi/scenario.yml @@ -35,7 +35,7 @@ tasks: wait: 0.5 - name: MI transfer - type: opensips-cli + type: opensips-mi script: scripts/transfer.py args: sip:transfer@{{ transfer_ip }}:{{ transfer_port }} 0 require: diff --git a/b2b/18.refer-unattended-uas-mi/scripts/transfer.py b/b2b/18.refer-unattended-uas-mi/scripts/transfer.py index 4c74e5a..66faa84 100644 --- a/b2b/18.refer-unattended-uas-mi/scripts/transfer.py +++ b/b2b/18.refer-unattended-uas-mi/scripts/transfer.py @@ -1,7 +1,17 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 3: print("Usage: {} URI entity".format(sys.argv[0])) @@ -11,9 +21,9 @@ entity = sys.argv[2] prov_media_uri = sys.argv[3] if len(sys.argv) > 3 else None -dialogs = handler.mi("b2b_list") +dialogs = handler.execute("b2b_list") logic = dialogs['Tuples'][0]['key'] # we are only interested in the first dialog params = {'dialog_id':logic, 'new_uri':uri, 'flag':entity} if prov_media_uri: params['prov_media_uri'] = prov_media_uri -handler.mi("b2b_bridge", params) +handler.execute("b2b_bridge", params) diff --git a/b2b/19.refer-unattended-uac-prov-mi/scenario.yml b/b2b/19.refer-unattended-uac-prov-mi/scenario.yml index dd584f6..966c9cb 100644 --- a/b2b/19.refer-unattended-uac-prov-mi/scenario.yml +++ b/b2b/19.refer-unattended-uac-prov-mi/scenario.yml @@ -42,7 +42,7 @@ tasks: wait: 0.5 - name: MI transfer - type: opensips-cli + type: opensips-mi script: scripts/transfer.py args: - sip:transfer@{{ transfer_ip }}:{{ transfer_port }} diff --git a/b2b/19.refer-unattended-uac-prov-mi/scripts/transfer.py b/b2b/19.refer-unattended-uac-prov-mi/scripts/transfer.py index 4c74e5a..66faa84 100644 --- a/b2b/19.refer-unattended-uac-prov-mi/scripts/transfer.py +++ b/b2b/19.refer-unattended-uac-prov-mi/scripts/transfer.py @@ -1,7 +1,17 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 3: print("Usage: {} URI entity".format(sys.argv[0])) @@ -11,9 +21,9 @@ entity = sys.argv[2] prov_media_uri = sys.argv[3] if len(sys.argv) > 3 else None -dialogs = handler.mi("b2b_list") +dialogs = handler.execute("b2b_list") logic = dialogs['Tuples'][0]['key'] # we are only interested in the first dialog params = {'dialog_id':logic, 'new_uri':uri, 'flag':entity} if prov_media_uri: params['prov_media_uri'] = prov_media_uri -handler.mi("b2b_bridge", params) +handler.execute("b2b_bridge", params) diff --git a/b2b/20.refer-unattended-uas-prov-mi/scenario.yml b/b2b/20.refer-unattended-uas-prov-mi/scenario.yml index 01e1588..519c97a 100644 --- a/b2b/20.refer-unattended-uas-prov-mi/scenario.yml +++ b/b2b/20.refer-unattended-uas-prov-mi/scenario.yml @@ -42,7 +42,7 @@ tasks: wait: 0.5 - name: MI transfer - type: opensips-cli + type: opensips-mi script: scripts/transfer.py args: - sip:transfer@{{ transfer_ip }}:{{ transfer_port }} diff --git a/b2b/20.refer-unattended-uas-prov-mi/scripts/transfer.py b/b2b/20.refer-unattended-uas-prov-mi/scripts/transfer.py index 4c74e5a..66faa84 100644 --- a/b2b/20.refer-unattended-uas-prov-mi/scripts/transfer.py +++ b/b2b/20.refer-unattended-uas-prov-mi/scripts/transfer.py @@ -1,7 +1,17 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 3: print("Usage: {} URI entity".format(sys.argv[0])) @@ -11,9 +21,9 @@ entity = sys.argv[2] prov_media_uri = sys.argv[3] if len(sys.argv) > 3 else None -dialogs = handler.mi("b2b_list") +dialogs = handler.execute("b2b_list") logic = dialogs['Tuples'][0]['key'] # we are only interested in the first dialog params = {'dialog_id':logic, 'new_uri':uri, 'flag':entity} if prov_media_uri: params['prov_media_uri'] = prov_media_uri -handler.mi("b2b_bridge", params) +handler.execute("b2b_bridge", params) diff --git a/config.yml b/config.yml index cb538f4..9a66db3 100644 --- a/config.yml +++ b/config.yml @@ -29,6 +29,8 @@ defaults: domain: {{ opensips_ip }} opensips-cli: mi_ip: {{ opensips_ip }} + opensips-mi: + mi_ip: {{ opensips_ip }} opensips: ip: {{ opensips_ip }} image: opensips/opensips:sipssert{% if opensips_version is defined %}-{{ opensips_version }}{% endif %} diff --git a/dialog/01.dialog/scenario.yml b/dialog/01.dialog/scenario.yml index a5b3c65..3d412ae 100644 --- a/dialog/01.dialog/scenario.yml +++ b/dialog/01.dialog/scenario.yml @@ -33,7 +33,7 @@ tasks: wait: 0.5 - name: MI check active - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: active require: @@ -53,7 +53,7 @@ tasks: # dialog should be deleted after SIPP finishes - name: MI check deleted - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: deleted require: SIPP UAC diff --git a/dialog/01.dialog/scripts/check-dialog.py b/dialog/01.dialog/scripts/check-dialog.py index d45b1fd..805bd56 100644 --- a/dialog/01.dialog/scripts/check-dialog.py +++ b/dialog/01.dialog/scripts/check-dialog.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: sys.exit(-1) -dialogs = handler.mi("dlg_list")['Dialogs'] +dialogs = handler.execute("dlg_list")['Dialogs'] if sys.argv[1] == "active": - out = handler.mi("get_statistics", {"statistics" : ["active_dialogs"]}) + out = handler.execute("get_statistics", {"statistics" : ["active_dialogs"]}) if out["dialog:active_dialogs"] != 1: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(11) @@ -16,7 +26,7 @@ print("Number of dialogs: {}".format(len(dialogs))) sys.exit(12) elif sys.argv[1] == "deleted": - out = handler.mi("get_statistics", {"statistics" : ["dialog:"]}) + out = handler.execute("get_statistics", {"statistics" : ["dialog:"]}) if out["dialog:active_dialogs"] != 0: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(21) diff --git a/dialog/02.pinging/scenario.yml b/dialog/02.pinging/scenario.yml index ade9c3e..d1b80ac 100644 --- a/dialog/02.pinging/scenario.yml +++ b/dialog/02.pinging/scenario.yml @@ -33,7 +33,7 @@ tasks: wait: 0.5 - name: MI check active - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: active require: @@ -53,7 +53,7 @@ tasks: # dialog should be deleted after SIPP finishes - name: MI check deleted - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: deleted require: SIPP UAC diff --git a/dialog/02.pinging/scripts/check-dialog.py b/dialog/02.pinging/scripts/check-dialog.py index d45b1fd..805bd56 100644 --- a/dialog/02.pinging/scripts/check-dialog.py +++ b/dialog/02.pinging/scripts/check-dialog.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: sys.exit(-1) -dialogs = handler.mi("dlg_list")['Dialogs'] +dialogs = handler.execute("dlg_list")['Dialogs'] if sys.argv[1] == "active": - out = handler.mi("get_statistics", {"statistics" : ["active_dialogs"]}) + out = handler.execute("get_statistics", {"statistics" : ["active_dialogs"]}) if out["dialog:active_dialogs"] != 1: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(11) @@ -16,7 +26,7 @@ print("Number of dialogs: {}".format(len(dialogs))) sys.exit(12) elif sys.argv[1] == "deleted": - out = handler.mi("get_statistics", {"statistics" : ["dialog:"]}) + out = handler.execute("get_statistics", {"statistics" : ["dialog:"]}) if out["dialog:active_dialogs"] != 0: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(21) diff --git a/dialog/03.reinvite-pinging/scenario.yml b/dialog/03.reinvite-pinging/scenario.yml index ade9c3e..d1b80ac 100644 --- a/dialog/03.reinvite-pinging/scenario.yml +++ b/dialog/03.reinvite-pinging/scenario.yml @@ -33,7 +33,7 @@ tasks: wait: 0.5 - name: MI check active - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: active require: @@ -53,7 +53,7 @@ tasks: # dialog should be deleted after SIPP finishes - name: MI check deleted - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: deleted require: SIPP UAC diff --git a/dialog/03.reinvite-pinging/scripts/check-dialog.py b/dialog/03.reinvite-pinging/scripts/check-dialog.py index d45b1fd..805bd56 100644 --- a/dialog/03.reinvite-pinging/scripts/check-dialog.py +++ b/dialog/03.reinvite-pinging/scripts/check-dialog.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: sys.exit(-1) -dialogs = handler.mi("dlg_list")['Dialogs'] +dialogs = handler.execute("dlg_list")['Dialogs'] if sys.argv[1] == "active": - out = handler.mi("get_statistics", {"statistics" : ["active_dialogs"]}) + out = handler.execute("get_statistics", {"statistics" : ["active_dialogs"]}) if out["dialog:active_dialogs"] != 1: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(11) @@ -16,7 +26,7 @@ print("Number of dialogs: {}".format(len(dialogs))) sys.exit(12) elif sys.argv[1] == "deleted": - out = handler.mi("get_statistics", {"statistics" : ["dialog:"]}) + out = handler.execute("get_statistics", {"statistics" : ["dialog:"]}) if out["dialog:active_dialogs"] != 0: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(21) diff --git a/dialog/04.expire/scenario.yml b/dialog/04.expire/scenario.yml index 6b21af5..9d0d92f 100644 --- a/dialog/04.expire/scenario.yml +++ b/dialog/04.expire/scenario.yml @@ -32,7 +32,7 @@ tasks: wait: 0.5 - name: MI check active - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: active require: @@ -52,7 +52,7 @@ tasks: # dialog should be deleted after SIPP finishes - name: MI check deleted - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: deleted require: diff --git a/dialog/04.expire/scripts/check-dialog.py b/dialog/04.expire/scripts/check-dialog.py index 2e109c1..49b9424 100644 --- a/dialog/04.expire/scripts/check-dialog.py +++ b/dialog/04.expire/scripts/check-dialog.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: sys.exit(-1) -dialogs = handler.mi("dlg_list")['Dialogs'] +dialogs = handler.execute("dlg_list")['Dialogs'] if sys.argv[1] == "active": - out = handler.mi("get_statistics", {"statistics" : ["active_dialogs"]}) + out = handler.execute("get_statistics", {"statistics" : ["active_dialogs"]}) if out["dialog:active_dialogs"] != 1: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(11) @@ -16,7 +26,7 @@ print("Number of dialogs: {}".format(len(dialogs))) sys.exit(12) elif sys.argv[1] == "expired": - out = handler.mi("get_statistics", {"statistics" : ["dialog:"]}) + out = handler.execute("get_statistics", {"statistics" : ["dialog:"]}) if out["dialog:active_dialogs"] != 0: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(21) diff --git a/dialog/05.reinvite-auth/scenario.yml b/dialog/05.reinvite-auth/scenario.yml index f8b2df7..d7f5aa2 100644 --- a/dialog/05.reinvite-auth/scenario.yml +++ b/dialog/05.reinvite-auth/scenario.yml @@ -34,7 +34,7 @@ tasks: wait: 0.5 - name: MI check active - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: active require: @@ -44,7 +44,7 @@ tasks: # dialog should be deleted after SIPP finishes - name: MI check deleted - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: deleted require: SIPP UAC diff --git a/dialog/05.reinvite-auth/scripts/check-dialog.py b/dialog/05.reinvite-auth/scripts/check-dialog.py index d45b1fd..805bd56 100644 --- a/dialog/05.reinvite-auth/scripts/check-dialog.py +++ b/dialog/05.reinvite-auth/scripts/check-dialog.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: sys.exit(-1) -dialogs = handler.mi("dlg_list")['Dialogs'] +dialogs = handler.execute("dlg_list")['Dialogs'] if sys.argv[1] == "active": - out = handler.mi("get_statistics", {"statistics" : ["active_dialogs"]}) + out = handler.execute("get_statistics", {"statistics" : ["active_dialogs"]}) if out["dialog:active_dialogs"] != 1: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(11) @@ -16,7 +26,7 @@ print("Number of dialogs: {}".format(len(dialogs))) sys.exit(12) elif sys.argv[1] == "deleted": - out = handler.mi("get_statistics", {"statistics" : ["dialog:"]}) + out = handler.execute("get_statistics", {"statistics" : ["dialog:"]}) if out["dialog:active_dialogs"] != 0: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(21) diff --git a/registration/01.no-db/check-register.py b/registration/01.no-db/check-register.py index 30819b7..5d863fb 100644 --- a/registration/01.no-db/check-register.py +++ b/registration/01.no-db/check-register.py @@ -1,11 +1,22 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) unregister = True if len(sys.argv) > 1 and sys.argv[1] == "unregister" else False -out = handler.mi("ul_dump") +out = handler.execute("ul_dump") +print(out) l = len(out['Domains'][0]['AORs']) if unregister: diff --git a/registration/01.no-db/scenario.yml b/registration/01.no-db/scenario.yml index 8b157de..9c28c76 100644 --- a/registration/01.no-db/scenario.yml +++ b/registration/01.no-db/scenario.yml @@ -15,8 +15,9 @@ tasks: wait: 1 - name: MI check Register - type: opensips-cli + type: opensips-mi script: check-register.py + mi_type: http require: Register - name: Unregister @@ -29,7 +30,7 @@ tasks: wait: 3 - name: MI check Unregister - type: opensips-cli + type: opensips-mi script: check-register.py require: Unregister args: unregister diff --git a/registration/02.db/scenario.yml b/registration/02.db/scenario.yml index 784adf3..dae371e 100644 --- a/registration/02.db/scenario.yml +++ b/registration/02.db/scenario.yml @@ -20,7 +20,7 @@ tasks: wait: 0.5 - name: MI check Register - type: opensips-cli + type: opensips-mi script: scripts/check-register.py require: after: @@ -42,7 +42,7 @@ tasks: require: MySQL check Register - name: MI check Unregister - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: unregister require: diff --git a/registration/02.db/scripts/check-register.py b/registration/02.db/scripts/check-register.py index b1b84ad..62e0f9a 100644 --- a/registration/02.db/scripts/check-register.py +++ b/registration/02.db/scripts/check-register.py @@ -1,11 +1,21 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) unregister = True if len(sys.argv) > 1 and sys.argv[1] == "unregister" else False -out = handler.mi("ul_dump") +out = handler.execute("ul_dump") l = len(out['Domains'][0]['AORs']) if unregister: diff --git a/registration/03.expire/scenario.yml b/registration/03.expire/scenario.yml index ef3e815..c8a7193 100644 --- a/registration/03.expire/scenario.yml +++ b/registration/03.expire/scenario.yml @@ -20,7 +20,7 @@ tasks: wait: 0.5 - name: MI check Register - type: opensips-cli + type: opensips-mi script: scripts/check-register.py require: started: @@ -36,7 +36,7 @@ tasks: wait: 3 - name: MI check Expired - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: expired require: diff --git a/registration/03.expire/scripts/check-register.py b/registration/03.expire/scripts/check-register.py index e741583..e7e672a 100644 --- a/registration/03.expire/scripts/check-register.py +++ b/registration/03.expire/scripts/check-register.py @@ -1,11 +1,21 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) expired = True if len(sys.argv) > 1 and sys.argv[1] == "expired" else False -out = handler.mi("ul_dump") +out = handler.execute("ul_dump") l = len(out['Domains'][0]['AORs']) if expired: diff --git a/registration/04.expire-min/scenario.yml b/registration/04.expire-min/scenario.yml index 6523fbf..1851e95 100644 --- a/registration/04.expire-min/scenario.yml +++ b/registration/04.expire-min/scenario.yml @@ -20,7 +20,7 @@ tasks: wait: 0.5 - name: MI check Register - type: opensips-cli + type: opensips-mi script: scripts/check-register.py require: started: @@ -36,7 +36,7 @@ tasks: wait: 3 - name: MI check Alive - type: opensips-cli + type: opensips-mi script: scripts/check-register.py require: started: @@ -44,7 +44,7 @@ tasks: wait: 5 - name: MI check Expired - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: expired require: diff --git a/registration/04.expire-min/scripts/check-register.py b/registration/04.expire-min/scripts/check-register.py index be02828..bd090a7 100644 --- a/registration/04.expire-min/scripts/check-register.py +++ b/registration/04.expire-min/scripts/check-register.py @@ -1,11 +1,21 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) expired = True if len(sys.argv) > 1 and sys.argv[1] == "expired" else False -out = handler.mi("ul_dump") +out = handler.execute("ul_dump") l = len(out['Domains'][0]['AORs']) if expired: diff --git a/registration/05.expire-max/scenario.yml b/registration/05.expire-max/scenario.yml index ef3e815..c8a7193 100644 --- a/registration/05.expire-max/scenario.yml +++ b/registration/05.expire-max/scenario.yml @@ -20,7 +20,7 @@ tasks: wait: 0.5 - name: MI check Register - type: opensips-cli + type: opensips-mi script: scripts/check-register.py require: started: @@ -36,7 +36,7 @@ tasks: wait: 3 - name: MI check Expired - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: expired require: diff --git a/registration/05.expire-max/scripts/check-register.py b/registration/05.expire-max/scripts/check-register.py index be02828..bd090a7 100644 --- a/registration/05.expire-max/scripts/check-register.py +++ b/registration/05.expire-max/scripts/check-register.py @@ -1,11 +1,21 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) expired = True if len(sys.argv) > 1 and sys.argv[1] == "expired" else False -out = handler.mi("ul_dump") +out = handler.execute("ul_dump") l = len(out['Domains'][0]['AORs']) if expired: diff --git a/registration/06.reregister-expire/scenario.yml b/registration/06.reregister-expire/scenario.yml index 814c766..4afe205 100644 --- a/registration/06.reregister-expire/scenario.yml +++ b/registration/06.reregister-expire/scenario.yml @@ -20,7 +20,7 @@ tasks: wait: 0.5 - name: MI check Register - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: initial require: @@ -37,7 +37,7 @@ tasks: wait: 3 - name: MI check Reregister - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: reregister require: @@ -46,7 +46,7 @@ tasks: wait: 6 - name: MI check Expired - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: expired require: diff --git a/registration/06.reregister-expire/scripts/check-register.py b/registration/06.reregister-expire/scripts/check-register.py index d690d53..2a9eb9f 100644 --- a/registration/06.reregister-expire/scripts/check-register.py +++ b/registration/06.reregister-expire/scripts/check-register.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: print("no action specified") sys.exit(-1) action = sys.argv[1] -out = handler.mi("ul_dump") +out = handler.execute("ul_dump") l = len(out['Domains'][0]['AORs']) if action == "expired": diff --git a/registration/07.limit/scenario.yml b/registration/07.limit/scenario.yml index 9445b35..26d2043 100644 --- a/registration/07.limit/scenario.yml +++ b/registration/07.limit/scenario.yml @@ -21,7 +21,7 @@ tasks: wait: 0.5 - name: MI check Register UAC 1 - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: 1 require: @@ -47,7 +47,7 @@ tasks: wait: 5 - name: MI check Register UAC 2 - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: 2 require: @@ -73,7 +73,7 @@ tasks: wait: 10 - name: MI check Register UAC 3 - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: 2 require: @@ -89,7 +89,7 @@ tasks: wait: 3 - name: MI check Expired UAC 1 - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: 1 require: @@ -98,7 +98,7 @@ tasks: wait: 21 - name: MI check Expired UAC 2 - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: 0 require: diff --git a/registration/07.limit/scripts/check-register.py b/registration/07.limit/scripts/check-register.py index fb8ac56..5b90bd6 100644 --- a/registration/07.limit/scripts/check-register.py +++ b/registration/07.limit/scripts/check-register.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv[1]) < 1: print("Number of contacts not specified!") sys.exit(-1) contacts = int(sys.argv[1]) -aors = handler.mi("ul_dump")['Domains'][0]['AORs'] +aors = handler.execute("ul_dump")['Domains'][0]['AORs'] l = len(aors) if l != 1: if l == 0 and contacts == 0: diff --git a/registration/08.overwrite/scenario.yml b/registration/08.overwrite/scenario.yml index 5281e76..2574b26 100644 --- a/registration/08.overwrite/scenario.yml +++ b/registration/08.overwrite/scenario.yml @@ -21,7 +21,7 @@ tasks: wait: 0.5 - name: MI check Register UAC 1 - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: {{ uac_port + 1 }} require: @@ -47,7 +47,7 @@ tasks: wait: 5 - name: MI check Register UAC 2 - type: opensips-cli + type: opensips-mi script: scripts/check-register.py args: {{ uac_port + 2 }} require: @@ -63,7 +63,7 @@ tasks: wait: 3 - name: MI check Expired UAC - type: opensips-cli + type: opensips-mi script: scripts/check-register.py require: started: diff --git a/registration/08.overwrite/scripts/check-register.py b/registration/08.overwrite/scripts/check-register.py index ec38c8d..191e1f0 100644 --- a/registration/08.overwrite/scripts/check-register.py +++ b/registration/08.overwrite/scripts/check-register.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) == 1: port = None else: port = ":{}".format(sys.argv[1]) -aors = handler.mi("ul_dump")['Domains'][0]['AORs'] +aors = handler.execute("ul_dump")['Domains'][0]['AORs'] l = len(aors) if l != 1: if l == 0 and not port: diff --git a/startup/01.default-cfg/check-ps.py b/startup/01.default-cfg/check-ps.py index de9c24f..df1b7dc 100644 --- a/startup/01.default-cfg/check-ps.py +++ b/startup/01.default-cfg/check-ps.py @@ -1,9 +1,19 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') -out = handler.mi("ps") +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) + +out = handler.execute("ps") if out: sys.exit(0) diff --git a/startup/01.default-cfg/scenario.yml b/startup/01.default-cfg/scenario.yml index aab5f53..18be088 100644 --- a/startup/01.default-cfg/scenario.yml +++ b/startup/01.default-cfg/scenario.yml @@ -6,7 +6,7 @@ tasks: type: opensips - name: MI check PS - type: opensips-cli + type: opensips-mi script: check-ps.py require: after: diff --git a/startup/02.gen-residential-cfg/check-ps.py b/startup/02.gen-residential-cfg/check-ps.py index de9c24f..df1b7dc 100644 --- a/startup/02.gen-residential-cfg/check-ps.py +++ b/startup/02.gen-residential-cfg/check-ps.py @@ -1,9 +1,19 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') -out = handler.mi("ps") +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) + +out = handler.execute("ps") if out: sys.exit(0) diff --git a/startup/02.gen-residential-cfg/scenario.yml b/startup/02.gen-residential-cfg/scenario.yml index 7b69412..e773258 100644 --- a/startup/02.gen-residential-cfg/scenario.yml +++ b/startup/02.gen-residential-cfg/scenario.yml @@ -11,7 +11,7 @@ tasks: healthy: mysql - name: MI check PS - type: opensips-cli + type: opensips-mi script: check-ps.py require: after: diff --git a/startup/03.gen-trunking-cfg/check-ps.py b/startup/03.gen-trunking-cfg/check-ps.py index de9c24f..df1b7dc 100644 --- a/startup/03.gen-trunking-cfg/check-ps.py +++ b/startup/03.gen-trunking-cfg/check-ps.py @@ -1,9 +1,19 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') -out = handler.mi("ps") +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) + +out = handler.execute("ps") if out: sys.exit(0) diff --git a/startup/03.gen-trunking-cfg/scenario.yml b/startup/03.gen-trunking-cfg/scenario.yml index dc0e8bf..458f2db 100644 --- a/startup/03.gen-trunking-cfg/scenario.yml +++ b/startup/03.gen-trunking-cfg/scenario.yml @@ -12,7 +12,7 @@ tasks: healthy: mysql - name: MI check PS - type: opensips-cli + type: opensips-mi script: check-ps.py require: after: diff --git a/startup/04.gen-loadbalancer-cfg/check-ps.py b/startup/04.gen-loadbalancer-cfg/check-ps.py index de9c24f..df1b7dc 100644 --- a/startup/04.gen-loadbalancer-cfg/check-ps.py +++ b/startup/04.gen-loadbalancer-cfg/check-ps.py @@ -1,9 +1,19 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') -out = handler.mi("ps") +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) + +out = handler.execute("ps") if out: sys.exit(0) diff --git a/startup/04.gen-loadbalancer-cfg/scenario.yml b/startup/04.gen-loadbalancer-cfg/scenario.yml index 7b69412..e773258 100644 --- a/startup/04.gen-loadbalancer-cfg/scenario.yml +++ b/startup/04.gen-loadbalancer-cfg/scenario.yml @@ -11,7 +11,7 @@ tasks: healthy: mysql - name: MI check PS - type: opensips-cli + type: opensips-mi script: check-ps.py require: after: diff --git a/stir-shaken/01.auth-simple/scenario.yml b/stir-shaken/01.auth-simple/scenario.yml index 54ee839..0c413e2 100644 --- a/stir-shaken/01.auth-simple/scenario.yml +++ b/stir-shaken/01.auth-simple/scenario.yml @@ -30,8 +30,7 @@ tasks: # check identity header after call - name: MI check identity header - type: opensips-cli - image: allomediadocker/opensips-cli:3.3.4 + type: opensips-mi script: scripts/check-identity.py require: after: diff --git a/stir-shaken/01.auth-simple/scripts/check-identity.py b/stir-shaken/01.auth-simple/scripts/check-identity.py index c7932f5..b51a721 100644 --- a/stir-shaken/01.auth-simple/scripts/check-identity.py +++ b/stir-shaken/01.auth-simple/scripts/check-identity.py @@ -1,9 +1,34 @@ -from opensipscli import cli -import jwt import sys import json +from opensips.mi import OpenSIPSMI +import os +import importlib +import subprocess -handler = cli.OpenSIPSCLI() + +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) + + +def install_and_import(package, import_name=None): + try: + module = importlib.import_module(import_name if import_name else package) + print(f"{package} is already installed") + except ImportError: + print(f"{package} is not installed, installing...") + subprocess.check_call([sys.executable, "-m", "pip", "install", package]) + print(f"{package} installed successfully") + module = importlib.import_module(import_name if import_name else package) + return module def check_list(list, id, log): @@ -17,8 +42,9 @@ def check_list(list, id, log): if __name__ == "__main__": + jwt = install_and_import("PyJWT", "jwt") - dialogs = handler.mi("dlg_list_ctx")['Dialogs'] + dialogs = handler.execute("dlg_list_ctx")['Dialogs'] json_dlg = json.loads(json.dumps(dialogs)) # catch identity header in dialogs identity_cache = json_dlg[0]['context']['values'][0]['identity_cache'] diff --git a/stir-shaken/02.auth-diverted-cached/scenario.yml b/stir-shaken/02.auth-diverted-cached/scenario.yml index e546aab..a613586 100644 --- a/stir-shaken/02.auth-diverted-cached/scenario.yml +++ b/stir-shaken/02.auth-diverted-cached/scenario.yml @@ -36,8 +36,7 @@ tasks: # check identity header after call - name: MI check identity header - type: opensips-cli - image: allomediadocker/opensips-cli:3.3.4 + type: opensips-mi script: scripts/check-identity.py require: after: diff --git a/stir-shaken/02.auth-diverted-cached/scripts/check-identity.py b/stir-shaken/02.auth-diverted-cached/scripts/check-identity.py index c7932f5..b51a721 100644 --- a/stir-shaken/02.auth-diverted-cached/scripts/check-identity.py +++ b/stir-shaken/02.auth-diverted-cached/scripts/check-identity.py @@ -1,9 +1,34 @@ -from opensipscli import cli -import jwt import sys import json +from opensips.mi import OpenSIPSMI +import os +import importlib +import subprocess -handler = cli.OpenSIPSCLI() + +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) + + +def install_and_import(package, import_name=None): + try: + module = importlib.import_module(import_name if import_name else package) + print(f"{package} is already installed") + except ImportError: + print(f"{package} is not installed, installing...") + subprocess.check_call([sys.executable, "-m", "pip", "install", package]) + print(f"{package} installed successfully") + module = importlib.import_module(import_name if import_name else package) + return module def check_list(list, id, log): @@ -17,8 +42,9 @@ def check_list(list, id, log): if __name__ == "__main__": + jwt = install_and_import("PyJWT", "jwt") - dialogs = handler.mi("dlg_list_ctx")['Dialogs'] + dialogs = handler.execute("dlg_list_ctx")['Dialogs'] json_dlg = json.loads(json.dumps(dialogs)) # catch identity header in dialogs identity_cache = json_dlg[0]['context']['values'][0]['identity_cache'] diff --git a/topology-hiding/03.th-dialog/scenario.yml b/topology-hiding/03.th-dialog/scenario.yml index a5b3c65..3d412ae 100644 --- a/topology-hiding/03.th-dialog/scenario.yml +++ b/topology-hiding/03.th-dialog/scenario.yml @@ -33,7 +33,7 @@ tasks: wait: 0.5 - name: MI check active - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: active require: @@ -53,7 +53,7 @@ tasks: # dialog should be deleted after SIPP finishes - name: MI check deleted - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: deleted require: SIPP UAC diff --git a/topology-hiding/03.th-dialog/scripts/check-dialog.py b/topology-hiding/03.th-dialog/scripts/check-dialog.py index d45b1fd..805bd56 100644 --- a/topology-hiding/03.th-dialog/scripts/check-dialog.py +++ b/topology-hiding/03.th-dialog/scripts/check-dialog.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: sys.exit(-1) -dialogs = handler.mi("dlg_list")['Dialogs'] +dialogs = handler.execute("dlg_list")['Dialogs'] if sys.argv[1] == "active": - out = handler.mi("get_statistics", {"statistics" : ["active_dialogs"]}) + out = handler.execute("get_statistics", {"statistics" : ["active_dialogs"]}) if out["dialog:active_dialogs"] != 1: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(11) @@ -16,7 +26,7 @@ print("Number of dialogs: {}".format(len(dialogs))) sys.exit(12) elif sys.argv[1] == "deleted": - out = handler.mi("get_statistics", {"statistics" : ["dialog:"]}) + out = handler.execute("get_statistics", {"statistics" : ["dialog:"]}) if out["dialog:active_dialogs"] != 0: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(21) diff --git a/topology-hiding/04.th-dialog-username/scenario.yml b/topology-hiding/04.th-dialog-username/scenario.yml index a5b3c65..3d412ae 100644 --- a/topology-hiding/04.th-dialog-username/scenario.yml +++ b/topology-hiding/04.th-dialog-username/scenario.yml @@ -33,7 +33,7 @@ tasks: wait: 0.5 - name: MI check active - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: active require: @@ -53,7 +53,7 @@ tasks: # dialog should be deleted after SIPP finishes - name: MI check deleted - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: deleted require: SIPP UAC diff --git a/topology-hiding/04.th-dialog-username/scripts/check-dialog.py b/topology-hiding/04.th-dialog-username/scripts/check-dialog.py index d45b1fd..805bd56 100644 --- a/topology-hiding/04.th-dialog-username/scripts/check-dialog.py +++ b/topology-hiding/04.th-dialog-username/scripts/check-dialog.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: sys.exit(-1) -dialogs = handler.mi("dlg_list")['Dialogs'] +dialogs = handler.execute("dlg_list")['Dialogs'] if sys.argv[1] == "active": - out = handler.mi("get_statistics", {"statistics" : ["active_dialogs"]}) + out = handler.execute("get_statistics", {"statistics" : ["active_dialogs"]}) if out["dialog:active_dialogs"] != 1: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(11) @@ -16,7 +26,7 @@ print("Number of dialogs: {}".format(len(dialogs))) sys.exit(12) elif sys.argv[1] == "deleted": - out = handler.mi("get_statistics", {"statistics" : ["dialog:"]}) + out = handler.execute("get_statistics", {"statistics" : ["dialog:"]}) if out["dialog:active_dialogs"] != 0: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(21) diff --git a/topology-hiding/05.th-dialog-did/scenario.yml b/topology-hiding/05.th-dialog-did/scenario.yml index a5b3c65..3d412ae 100644 --- a/topology-hiding/05.th-dialog-did/scenario.yml +++ b/topology-hiding/05.th-dialog-did/scenario.yml @@ -33,7 +33,7 @@ tasks: wait: 0.5 - name: MI check active - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: active require: @@ -53,7 +53,7 @@ tasks: # dialog should be deleted after SIPP finishes - name: MI check deleted - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: deleted require: SIPP UAC diff --git a/topology-hiding/05.th-dialog-did/scripts/check-dialog.py b/topology-hiding/05.th-dialog-did/scripts/check-dialog.py index d45b1fd..805bd56 100644 --- a/topology-hiding/05.th-dialog-did/scripts/check-dialog.py +++ b/topology-hiding/05.th-dialog-did/scripts/check-dialog.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: sys.exit(-1) -dialogs = handler.mi("dlg_list")['Dialogs'] +dialogs = handler.execute("dlg_list")['Dialogs'] if sys.argv[1] == "active": - out = handler.mi("get_statistics", {"statistics" : ["active_dialogs"]}) + out = handler.execute("get_statistics", {"statistics" : ["active_dialogs"]}) if out["dialog:active_dialogs"] != 1: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(11) @@ -16,7 +26,7 @@ print("Number of dialogs: {}".format(len(dialogs))) sys.exit(12) elif sys.argv[1] == "deleted": - out = handler.mi("get_statistics", {"statistics" : ["dialog:"]}) + out = handler.execute("get_statistics", {"statistics" : ["dialog:"]}) if out["dialog:active_dialogs"] != 0: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(21) diff --git a/topology-hiding/06.th-dialog-callid/scenario.yml b/topology-hiding/06.th-dialog-callid/scenario.yml index a5b3c65..3d412ae 100644 --- a/topology-hiding/06.th-dialog-callid/scenario.yml +++ b/topology-hiding/06.th-dialog-callid/scenario.yml @@ -33,7 +33,7 @@ tasks: wait: 0.5 - name: MI check active - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: active require: @@ -53,7 +53,7 @@ tasks: # dialog should be deleted after SIPP finishes - name: MI check deleted - type: opensips-cli + type: opensips-mi script: scripts/check-dialog.py args: deleted require: SIPP UAC diff --git a/topology-hiding/06.th-dialog-callid/scripts/check-dialog.py b/topology-hiding/06.th-dialog-callid/scripts/check-dialog.py index d45b1fd..805bd56 100644 --- a/topology-hiding/06.th-dialog-callid/scripts/check-dialog.py +++ b/topology-hiding/06.th-dialog-callid/scripts/check-dialog.py @@ -1,14 +1,24 @@ -from opensipscli import cli +from opensips.mi import OpenSIPSMI import sys +import os -handler = cli.OpenSIPSCLI() +mi_type = os.getenv('MI_TYPE', 'http') +mi_ip = os.getenv('MI_IP', '127.0.0.1') +mi_port = os.getenv('MI_PORT', '8888') + +if mi_type == 'http': + handler = OpenSIPSMI(conn='http', url='http://{}:{}/mi'.format(mi_ip, mi_port)) +elif mi_type == 'datagram': + handler = OpenSIPSMI(conn='datagram', datagram_ip=mi_ip, datagram_port=mi_port) +else: + sys.exit(1) if len(sys.argv) < 1: sys.exit(-1) -dialogs = handler.mi("dlg_list")['Dialogs'] +dialogs = handler.execute("dlg_list")['Dialogs'] if sys.argv[1] == "active": - out = handler.mi("get_statistics", {"statistics" : ["active_dialogs"]}) + out = handler.execute("get_statistics", {"statistics" : ["active_dialogs"]}) if out["dialog:active_dialogs"] != 1: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(11) @@ -16,7 +26,7 @@ print("Number of dialogs: {}".format(len(dialogs))) sys.exit(12) elif sys.argv[1] == "deleted": - out = handler.mi("get_statistics", {"statistics" : ["dialog:"]}) + out = handler.execute("get_statistics", {"statistics" : ["dialog:"]}) if out["dialog:active_dialogs"] != 0: print("Active dialogs: {}".format(out["dialog:active_dialogs"])) sys.exit(21)