11#!/usr/bin/env python
2- ##
3- ## This file is part of the OpenSIPS Python Package
4- ## (see https://github.com/OpenSIPS/python-opensips).
5- ##
6- ## This program is free software: you can redistribute it and/or modify
7- ## it under the terms of the GNU General Public License as published by
8- ## the Free Software Foundation, either version 3 of the License, or
9- ## (at your option) any later version.
10- ##
11- ## This program is distributed in the hope that it will be useful,
12- ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13- ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14- ## GNU General Public License for more details.
15- ##
16- ## You should have received a copy of the GNU General Public License
17- ## along with this program. If not, see <http://www.gnu.org/licenses/>.
18- ##
2+ #
3+ # This file is part of the OpenSIPS Python Package
4+ # (see https://github.com/OpenSIPS/python-opensips).
5+ #
6+ # This program is free software: you can redistribute it and/or modify
7+ # it under the terms of the GNU General Public License as published by
8+ # the Free Software Foundation, either version 3 of the License, or
9+ # (at your option) any later version.
10+ #
11+ # This program is distributed in the hope that it will be useful,
12+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ # GNU General Public License for more details.
15+ #
16+ # You should have received a copy of the GNU General Public License
17+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18+ #
1919
2020""" OpenSIPS Event script """
2121
3232communication = parser .add_argument_group ('communication' )
3333
3434communication .add_argument ('-t' , '--type' ,
35- type = str ,
36- default = 'fifo' ,
37- choices = ['fifo' , 'http' , 'datagram' ],
38- help = 'OpenSIPS MI Communication Type' )
35+ type = str ,
36+ default = 'fifo' ,
37+ choices = ['fifo' , 'http' , 'datagram' ],
38+ help = 'OpenSIPS MI Communication Type' )
3939communication .add_argument ('-i' , '--ip' ,
40- type = str ,
41- help = 'OpenSIPS MI IP Address' ,
42- default = '127.0.0.1' )
40+ type = str ,
41+ help = 'OpenSIPS MI IP Address' ,
42+ default = '127.0.0.1' )
4343communication .add_argument ('-p' , '--port' ,
44- type = int ,
45- help = 'OpenSIPS MI Port' ,
46- default = 8888 )
44+ type = int ,
45+ help = 'OpenSIPS MI Port' ,
46+ default = 8888 )
4747communication .add_argument ('-f' , '--fifo-file' ,
48- metavar = 'FIFO_FILE' ,
49- type = str ,
50- help = 'OpenSIPS MI FIFO File' )
48+ metavar = 'FIFO_FILE' ,
49+ type = str ,
50+ help = 'OpenSIPS MI FIFO File' )
5151communication .add_argument ('-fb' , '--fifo-fallback' ,
52- metavar = 'FIFO_FALLBACK_FILE' ,
53- type = str ,
54- help = 'OpenSIPS MI Fallback FIFO File' )
52+ metavar = 'FIFO_FALLBACK_FILE' ,
53+ type = str ,
54+ help = 'OpenSIPS MI Fallback FIFO File' )
5555communication .add_argument ('-fd' , '--fifo-reply-dir' ,
56- metavar = 'FIFO_DIR' ,
57- type = str ,
58- help = 'OpenSIPS MI FIFO Reply Directory' )
56+ metavar = 'FIFO_DIR' ,
57+ type = str ,
58+ help = 'OpenSIPS MI FIFO Reply Directory' )
5959
6060event = parser .add_argument_group ('event' )
6161
6262event .add_argument ('event' ,
63- type = str ,
64- help = 'OpenSIPS Event Name' )
63+ type = str ,
64+ help = 'OpenSIPS Event Name' )
6565
6666event .add_argument ('-T' , '--transport' ,
67- type = str ,
68- choices = ['datagram' , 'stream' ],
69- help = 'OpenSIPS Event Transport' ,
70- default = 'datagram' )
67+ type = str ,
68+ choices = ['datagram' , 'stream' ],
69+ help = 'OpenSIPS Event Transport' ,
70+ default = 'datagram' )
7171event .add_argument ('-li' , '--listen-ip' ,
72- type = str ,
73- help = 'OpenSIPS Event Listen IP Address' ,
74- default = '0.0.0.0' )
72+ type = str ,
73+ help = 'OpenSIPS Event Listen IP Address' ,
74+ default = '0.0.0.0' )
7575event .add_argument ('-lp' , '--listen-port' ,
76- type = int ,
77- help = 'OpenSIPS Event Listen Port' ,
78- default = 0 )
76+ type = int ,
77+ help = 'OpenSIPS Event Listen Port' ,
78+ default = 0 )
7979event .add_argument ('-e' , '--expire' ,
80- type = int ,
81- help = 'OpenSIPS Event Expire Time' ,
82- default = None )
80+ type = int ,
81+ help = 'OpenSIPS Event Expire Time' ,
82+ default = None )
83+
8384
8485def main ():
8586 """ Main function of the opensips-event script """
@@ -98,12 +99,16 @@ def main():
9899 elif args .type == 'http' :
99100 mi = OpenSIPSMI ('http' , url = f'http://{ args .ip } :{ args .port } /mi' )
100101 elif args .type == 'datagram' :
101- mi = OpenSIPSMI ('datagram' , datagram_ip = args .ip , datagram_port = args .port )
102+ mi = OpenSIPSMI ('datagram' ,
103+ datagram_ip = args .ip ,
104+ datagram_port = args .port )
102105 else :
103106 print (f'Unknown type: { args .type } ' )
104107 sys .exit (1 )
105108
106- hdl = OpenSIPSEventHandler (mi , args .transport , ip = args .listen_ip , port = args .listen_port )
109+ hdl = OpenSIPSEventHandler (mi , args .transport ,
110+ ip = args .listen_ip ,
111+ port = args .listen_port )
107112
108113 def event_handler (message ):
109114 """ Event handler callback """
@@ -121,7 +126,7 @@ def event_handler(message):
121126 def timer (* _ ):
122127 """ Timer to notify when the event expires """
123128 ev .unsubscribe ()
124- sys .exit (0 ) # successful
129+ sys .exit (0 ) # successful
125130
126131 if args .expire :
127132 signal .signal (signal .SIGALRM , timer )
@@ -139,5 +144,6 @@ def timer(*_):
139144 while True :
140145 time .sleep (1 )
141146
147+
142148if __name__ == "__main__" :
143149 main ()
0 commit comments