Code Monkey home page Code Monkey logo

ari-py's Introduction

The Asterisk(R) Open Source PBX

        By Mark Spencer <[email protected]> and the Asterisk.org developer community.
        Copyright (C) 2001-2021 Sangoma Technologies Corporation and other copyright holders.

SECURITY

It is imperative that you read and fully understand the contents of the security information document before you attempt to configure and run an Asterisk server.

See Important Security Considerations for more information.

WHAT IS ASTERISK ?

Asterisk is an Open Source PBX and telephony toolkit. It is, in a sense, middleware between Internet and telephony channels on the bottom, and Internet and telephony applications at the top. However, Asterisk supports more telephony interfaces than just Internet telephony. Asterisk also has a vast amount of support for traditional PSTN telephony, as well.

For more information on the project itself, please visit the Asterisk home page and the official documentation. In addition you'll find lots of information compiled by the Asterisk community at voip-info.org.

There is a book on Asterisk published by O'Reilly under the Creative Commons License. It is available in book stores as well as in a downloadable version on the asteriskdocs.org web site.

SUPPORTED OPERATING SYSTEMS

Linux

The Asterisk Open Source PBX is developed and tested primarily on the GNU/Linux operating system, and is supported on every major GNU/Linux distribution.

Others

Asterisk has also been 'ported' and reportedly runs properly on other operating systems as well, including Sun Solaris, Apple's Mac OS X, Cygwin, and the BSD variants.

GETTING STARTED

First, be sure you've got supported hardware (but note that you don't need ANY special hardware, not even a sound card) to install and run Asterisk.

Supported telephony hardware includes:

  • All Analog and Digital Interface cards from Sangoma
  • QuickNet Internet PhoneJack and LineJack
  • any full duplex sound card supported by ALSA, OSS, or PortAudio
  • any ISDN card supported by mISDN on Linux
  • The Xorcom Astribank channel bank
  • VoiceTronix OpenLine products

UPGRADING FROM AN EARLIER VERSION

If you are updating from a previous version of Asterisk, make sure you read the UPGRADE.txt file in the source directory. There are some files and configuration options that you will have to change, even though we made every effort possible to maintain backwards compatibility.

In order to discover new features to use, please check the configuration examples in the configs directory of the source code distribution. For a list of new features in this version of Asterisk, see the CHANGES file.

NEW INSTALLATIONS

Ensure that your system contains a compatible compiler and development libraries. Asterisk requires either the GNU Compiler Collection (GCC) version 4.1 or higher, or a compiler that supports the C99 specification and some of the gcc language extensions. In addition, your system needs to have the C library headers available, and the headers and libraries for ncurses.

There are many modules that have additional dependencies. To see what libraries are being looked for, see ./configure --help, or run make menuselect to view the dependencies for specific modules.

On many distributions, these dependencies are installed by packages with names like 'glibc-devel', 'ncurses-devel', 'openssl-devel' and 'zlib-devel' or similar.

So, let's proceed:

  1. Read this file.

There are more documents than this one in the doc directory. You may also want to check the configuration files that contain examples and reference guides in the configs directory.

  1. Run ./configure

Execute the configure script to guess values for system-dependent variables used during compilation. If the script indicates that some required components are missing, you can run ./contrib/scripts/install_prereq install to install the necessary components. Note that this will install all dependencies for every functionality of Asterisk. After running the script, you will need to rerun ./configure.

  1. Run make menuselect [optional]

This is needed if you want to select the modules that will be compiled and to check dependencies for various optional modules.

  1. Run make

Assuming the build completes successfully:

  1. Run make install

If this is your first time working with Asterisk, you may wish to install the sample PBX, with demonstration extensions, etc. If so, run:

  1. Run make samples

Doing so will overwrite any existing configuration files you have installed.

  1. Finally, you can launch Asterisk in the foreground mode (not a daemon) with:
        # asterisk -vvvc

You'll see a bunch of verbose messages fly by your screen as Asterisk initializes (that's the "very very verbose" mode). When it's ready, if you specified the "c" then you'll get a command line console, that looks like this:

        *CLI>

You can type "core show help" at any time to get help with the system. For help with a specific command, type "core show help ". To start the PBX using your sound card, you can type "console dial" to dial the PBX. Then you can use "console answer", "console hangup", and "console dial" to simulate the actions of a telephone. Remember that if you don't have a full duplex sound card (and Asterisk will tell you somewhere in its verbose messages if you do/don't) then it won't work right (not yet).

"man asterisk" at the Unix/Linux command prompt will give you detailed information on how to start and stop Asterisk, as well as all the command line options for starting Asterisk.

Feel free to look over the configuration files in /etc/asterisk, where you will find a lot of information about what you can do with Asterisk.

ABOUT CONFIGURATION FILES

All Asterisk configuration files share a common format. Comments are delimited by ';' (since '#' of course, being a DTMF digit, may occur in many places). A configuration file is divided into sections whose names appear in []'s. Each section typically contains two types of statements, those of the form 'variable = value', and those of the form 'object => parameters'. Internally the use of '=' and '=>' is exactly the same, so they're used only to help make the configuration file easier to understand, and do not affect how it is actually parsed.

Entries of the form 'variable=value' set the value of some parameter in asterisk. For example, in chan_dahdi.conf, one might specify:

	switchtype=national

In order to indicate to Asterisk that the switch they are connecting to is of the type "national". In general, the parameter will apply to instantiations which occur below its specification. For example, if the configuration file read:

	switchtype = national
	channel => 1-4
	channel => 10-12
	switchtype = dms100
	channel => 25-47

The "national" switchtype would be applied to channels one through four and channels 10 through 12, whereas the "dms100" switchtype would apply to channels 25 through 47.

The "object => parameters" instantiates an object with the given parameters. For example, the line "channel => 25-47" creates objects for the channels 25 through 47 of the card, obtaining the settings from the variables specified above.

SPECIAL NOTE ON TIME

Those using SIP phones should be aware that Asterisk is sensitive to large jumps in time. Manually changing the system time using date(1) (or other similar commands) may cause SIP registrations and other internal processes to fail. If your system cannot keep accurate time by itself use NTP to keep the system clock synchronized to "real time". NTP is designed to keep the system clock synchronized by speeding up or slowing down the system clock until it is synchronized to "real time" rather than by jumping the time and causing discontinuities. Most Linux distributions include precompiled versions of NTP. Beware of some time synchronization methods that get the correct real time periodically and then manually set the system clock.

Apparent time changes due to daylight savings time are just that, apparent. The use of daylight savings time in a Linux system is purely a user interface issue and does not affect the operation of the Linux kernel or Asterisk. The system clock on Linux kernels operates on UTC. UTC does not use daylight savings time.

Also note that this issue is separate from the clocking of TDM channels, and is known to at least affect SIP registrations.

FILE DESCRIPTORS

Depending on the size of your system and your configuration, Asterisk can consume a large number of file descriptors. In UNIX, file descriptors are used for more than just files on disk. File descriptors are also used for handling network communication (e.g. SIP, IAX2, or H.323 calls) and hardware access (e.g. analog and digital trunk hardware). Asterisk accesses many on-disk files for everything from configuration information to voicemail storage.

Most systems limit the number of file descriptors that Asterisk can have open at one time. This can limit the number of simultaneous calls that your system can handle. For example, if the limit is set at 1024 (a common default value) Asterisk can handle approximately 150 SIP calls simultaneously. To change the number of file descriptors follow the instructions for your system below:

PAM-BASED LINUX SYSTEM

If your system uses PAM (Pluggable Authentication Modules) edit /etc/security/limits.conf. Add these lines to the bottom of the file:

root            soft    nofile          4096
root            hard    nofile          8196
asterisk        soft    nofile          4096
asterisk        hard    nofile          8196

(adjust the numbers to taste). You may need to reboot the system for these changes to take effect.

GENERIC UNIX SYSTEM

If there are no instructions specifically adapted to your system above you can try adding the command ulimit -n 8192 to the script that starts Asterisk.

MORE INFORMATION

See the doc directory for more documentation on various features. Again, please read all the configuration samples that include documentation on the configuration options.

Finally, you may wish to visit the support site and join the mailing list if you're interested in getting more information.

Welcome to the growing worldwide community of Asterisk users!

        Mark Spencer, and the Asterisk.org development community

Asterisk is a trademark of Sangoma Technologies Corporation

ari-py's People

Contributors

leedm777 avatar matt-jordan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ari-py's Issues

Library doesn't allow async processes

Hi

I have noticed that once run is called the library goes into a loop of reading/blocking on websocket. This means that you lose control on your process after calling run.
This makes building multiprocessing/multithreaded applications impossible.

I suggest a way to make the reading part non-blocking so that app can do other things like use queues for multiprocessing. I suspect this library will not work very well on high loads where ARI apps has to do DB queries or making other HTTP API calls that can take a few seconds to respond.

No module named 'client'

Getting this error on Ubuntu 14.04LTS running Python 3.4.0 in a virtual environment.
Traceback is:

>>> import ari
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/project/env/lib/python3.4/site-packages/ari-0.1.3-py3.4.egg/ari/__init__.py", line 8, in <module>
ImportError: No module named 'client'

This occurs whether installing from source/setup.py or PyPi.

Suggestion for Error Handling

Hey,

Currently, if a channel has gone away and we attempt to send an action for that channel it'll throw a requests.exceptions.HTTPError (404).

That's fine and I understand why that is thrown. However, it would be nice to have the ari client catch the raw HTTPErrors and have its own exceptions (ari.exceptions).

This way, when using the client, we can catch exceptions like ari.exceptions.ChannelNotFoundException or however you want to name it and not have to catch the underlying requests.exceptions.

Ryan

Proper handle unicode connection string

When you store ari connection info in database it is usually returned as python unicode string and ari-py fails to manage it:

>>> client = ari.connect(u'http://localhost:8088', u'dialer', u'test')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/ari/__init__.py", line 26, in connect
    return Client(base_url, http_client)
  File "/usr/local/lib/python2.7/dist-packages/ari/client.py", line 29, in __init__
    url, http_client=http_client)
  File "/usr/local/lib/python2.7/dist-packages/swaggerpy/client.py", line 180, in __init__
    log.debug("Loading from %s" % url_or_resource.get('basePath'))
AttributeError: 'unicode' object has no attribute 'get'

>>> client = ari.connect('http://localhost:8088', 'dialer', 'test')
>>> 

ChannelDestroyed Event is not triggered when outgoing channel does not pickup the call

Hello,

I am using Asterisk 18.9.0 and this example to originate a call in my ARI application: https://github.com/asterisk/ari-py/blob/master/examples/originate_example.py

When the outgoing channel rejects the call, I don't receive the ChannelDestroyed event, and even worse, I receive the following events as if the call was answered:

ChannelStateChange

{u'timestamp': u'2023-03-13T14:51:13.519+0100', u'application': u'stt', u'type': u'ChannelStateChange', u'channel': {u'accountcode': u'', u'name': u'SIP/sogedes_plusserver-00000060', u'language': u'en', u'caller': {u'name': u'', u'number': u''}, u'creationtime': u'2023-03-13T14:51:06.294+0100', u'state': u'Up', u'connected': {u'name': u'4915238573267', u'number': u'4915238573267'}, u'dialplan': {u'priority': 1, u'exten': u'', u'app_data': u'stt,outgoing', u'app_name': u'Stasis', u'context': u'from-voip-provider'}, u'id': u'1678715466.488'}, u'asterisk_id': u'00:50:56:3f:5c:3a'}


Dial

{u'application': u'stt', u'timestamp': u'2023-03-13T14:51:13.520+0100', u'dialstatus': u'ANSWER', u'peer': {u'accountcode': u'', u'name': u'SIP/sogedes_plusserver-00000060', u'language': u'en', u'caller': {u'name': u'', u'number': u''}, u'creationtime': u'2023-03-13T14:51:06.294+0100', u'state': u'Up', u'connected': {u'name': u'4915238573267', u'number': u'4915238573267'}, u'dialplan': {u'priority': 1, u'exten': u'', u'app_data': u'stt,outgoing', u'app_name': u'Stasis', u'context': u'from-voip-provider'}, u'id': u'1678715466.488'}, u'dialstring': u'', u'forward': u'', u'type': u'Dial', u'asterisk_id': u'00:50:56:3f:5c:3a'}

After this, the incoming channel stays in a limbo and nothing happens because I receive dialstatus = ANSWER and ChannelState = Up. What am I missing? Is there some problem in the Asterisk 18?

stop a playback by id !?

hi thanks for your efforts
i would like to stop a playback by id
multiple channels in a single stasis app have playbacks which is generated by id .
but on an event i want to stop a specific playback.
how can i achieve that ?
thanks

queues manager

I'ts possible a Agent in queue do login, logout and pause using ARI and your library??

No handlers could be found for logger "ari.client"

1.I have using ari-py lib. for making call application in asterisk.
I that i use bridge-dial.py filefrom example folder in Ari-py lib. for playing IVR in asterisk but got this kind of error "No handlers could be found for logger "ari.client" " show on terminal.
how to solve this??

2.And another thing i want to know how to get header details in statis python-ari application.
Is there any method or api for that??

channel_obj.get('channel') - wrong code


def stasis_start_cb(channel_obj, ev):
    """Handler for StasisStart event"""
 
    channel = channel_obj.get('channel')
    print "Channel %s has entered the application" % channel.json.get('name')

channel = channel_obj.get('channel')
TypeError: enrich_operation() takes exactly 0 arguments (1 given)
Also there is no such attribute.

Please update the documentation here - https://wiki.asterisk.org/wiki/display/AST/ARI+and+Channels%3A+Handling+DTMF#ARIandChannels:HandlingDTMF-Playingthemenu
and all other examples :-)

Channel data is not shown in asterisk CLI

Hello sir,
I have used this library and its working great,make strong concept.But i have one question which is shown below
how to take channel data in asterisk cli terminal through Python-ARI?
is there any method to get channel data with out this method:
channel = client.channels.get(channelId=channel_id)
this works fine,display channel details on terminal but i want details on asterisk cli .
Is there any method for this??
please give replay as soon as possible.

ari-py does not work with requests > 2.0.1 and websocket-client > 0.12.0

In a fresh virtual environment using the default versions that pip installs of requests and websocket-client, the websocket fails to connect and returns the following error:

Traceback (most recent call last):
  File "example.py", line 25, in <module>
    client.run(apps="hello")
  File "/private/tmp/goo/env/lib/python2.7/site-packages/ari/client.py", line 115, in run
    self.__run(ws)
  File "/private/tmp/goo/env/lib/python2.7/site-packages/ari/client.py", line 88, in __run
    msg_json = json.loads(msg_str)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Output of pip freeze that fails

ari==0.1.1
backports.ssl-match-hostname==3.4.0.2
requests==2.3.0
six==1.7.2
swaggerpy==0.2.0
websocket-client==0.15.0
wsgiref==0.1.2

Error determining real directory for rest-api

After installing "ari-api" i try to run this example.

import ari

client = ari.connect('http://localhost:8088/', 'asterisk', 'asterisk')

def on_dtmf(channel, event):
    digit = event['digit']
    if digit == '#':
        channel.play(media='sound:goodbye')
        channel.continueInDialplan()
    elif digit == '*':
        channel.play(media='sound:asterisk-friend')
    else:
        channel.play(media='sound:digits/%s' % digit)


def on_start(channel, event):
    channel.on_event('ChannelDtmfReceived', on_dtmf)
    channel.answer()
    channel.play(media='sound:hello-world')


client.on_channel_event('StasisStart', on_start)
client.run(apps="hello-world")

Immediately i get this error:

ERROR[7041]: res_ari.c:605 ast_ari_get_docs: Error determining real directory for rest-api.

asterisk version: 13.7.2

Maybe something related with "swaggerpy" ??

-Thanks

404 Not Found

I'm sure I just havent properly configured asterisk but for some reason I am not able to call any of the API's.

Testing the examples on the documentation all return 404. The resources.json url returns a 404.

wscat -c "ws://127.0.0.1:8088/ari/events?api_key=asterisk:asterisk&app=hello-world"

error: Unexpected server response: 404

I followed the instructions at this website for enabling ari.
https://wiki.asterisk.org/wiki/display/AST/Getting+Started+with+ARI#GettingStartedwithARI-ConfiguringAsterisk

  1. Enabled http.conf and binding
  2. Enabled ari.conf and created a user
  3. Setup a dialplan
  4. Restarted asterisk

I do get responses on port 8088 but none of the URL's I try to hit work.

[Events] Failed to generate an user event

Hello folks,

When I generate an user event I receive the following error:
"AttributeError: 'dict' object has no attribute 'paramType'" , raised on swaggerpy/client.py line 73. (more details here [1]).

I believe that this is a swagger-py limitation since the parameter type is expected to be 'path' or 'query' and when you generate an user event the type of 'variables' parameter will be 'body' .

Below you can find the code which generates the error:

connection = ari.connect('http://localhost:8088', 'user', 'password') # connect to the ARI server
connection.events.userEvent(eventName="NewEvent", 
                            application='Test', 
                            variables={"variables" : {"var1":"value1"}}) # generate the user event

[1]
error

All the best,
Claudiu

Error: AttributeError: 'dict' object has no attribute 'answer'

I installed the ari-py from source with sudo ./setup.py install on a raspberry pi 2.

I use example.py and just added logging in order to see the error:

import logging
logging.basicConfig()

The client registers with asterisk and then receives an event. But then i get the error message:

ERROR:ari.client:Event listener threw exception
Traceback (most recent call last):
  File "build/bdist.linux-armv7l/egg/ari/client.py", line 100, in __run
    callback(msg_json, *args, **kwargs)
  File "build/bdist.linux-armv7l/egg/ari/client.py", line 198, in extract_objects
    event_cb(obj, event, *args, **kwargs)
  File "<stdin>", line 2, in on_start
AttributeError: 'dict' object has no attribute 'answer'

Same result with release 0.1.3

when I print the channel type and object i get:

{u'channel': Channel(1445097806.30)}
{u'timestamp': u'2015-10-17T18:03:26.842+0200', u'args': [], u'type': u'StasisStart', u'channel': {u'accountcode': u'', u'name': u'SIP/softphone-0000000f', u'language': u'en', u'caller': {u'name': u'softphone', u'number': u'+41790000003'}, u'creationtime': u'2015-10-17T18:03:26.837+0200', u'state': u'Ring', u'connected': {u'name': u'', u'number': u''}, u'dialplan': {u'priority': 3, u'exten': u'100', u'context': u'incoming'}, u'id': u'1445097806.30'}, u'application': u'hello'}

Thanks

Implement ari.connect timeout

Hi guys!
I miss timeout parameter in ari.connect method.
In case of routing issues connect takes too much time.
Is it possible to have a timeout=x param?
Thanks.

Selector library problem

I run python playback_example.py but I have this error:

Traceback (most recent call last):
  File "playback_example.py", line 13, in <module>
    import ari
  File "build/bdist.linux-x86_64/egg/ari/__init__.py", line 8, in <module>
  File "build/bdist.linux-x86_64/egg/ari/client.py", line 11, in <module>
  File "build/bdist.linux-x86_64/egg/swaggerpy/__init__.py", line 13, in <module>
  File "build/bdist.linux-x86_64/egg/swaggerpy/swagger_model.py", line 13, in <module>
  File "build/bdist.linux-x86_64/egg/swaggerpy/http_client.py", line 14, in <module>
  File "/usr/local/lib/python2.7/dist-packages/websocket_client-1.2.3-py2.7.egg/websocket/__init__.py", line 20, in <module>
    from ._app import WebSocketApp
  File "/usr/local/lib/python2.7/dist-packages/websocket_client-1.2.3-py2.7.egg/websocket/_app.py", line 23, in <module>
    import selectors
ImportError: No module named selectors

What is problem ?

ari-py application/callback not receiving StasisStart and StasisEnd events

Hello,

I am following the tutorial in https://wiki.asterisk.org/wiki/display/AST/Introduction+to+ARI+and+Channels and have downloaded and installed https://github.com/asterisk/ari-py in my system. I am able to interact with ARI using wscat per https://wiki.asterisk.org/wiki/display/AST/Getting+Started+with+ARI and I see channel creation/state change/deletion notifications that in the wscat log. However, when I run channel-dump.py in another terminal in the same machine (connecting to http://localhost:8088 like the tutorial), I do not see the channel creation, deletion and state modification messages. The only message I see are either No channels currently :-( or, if I have a current channel running, and then I fire up channel-dump.py, I see the current channel information. However, I do not see the notification when I hang up the same call. I think this is due to the fact that the event callbacks in ari-py, specifically the lines:

client.on_channel_event('StasisStart', stasis_start_cb)
client.on_channel_event('StasisEnd', stasis_end_cb)[/code]

don't seem to work.

Any ideas on how to fix this is appreciated.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.