Asterisk no longer allow connection via AMI

Hello everyone, I have been connecting to my Asterisk server from a Python script and things work perfectly and suddenly it just stopped yesterday.

Before when I start Asterisk I could see login status of the user that is connected to the Asterisk but now that is no longer present.

I have checked the Asterisk manager.conf file and it is sill there. Also commands such as

manager show user works and display the username I setup in the manager.conf

What do you think I should look at?

Try to connect to Asterisk AMI using telnet, if that doesn’t work then use the netstat application to ensure Asterisk is listening on the port. If telnet does work then the problem is outside of Asterisk.

When you said try to connect to Asterisk AMI using telnet, do you mean I should login to my Asterisk server using Putty? I have not used telnet before or let me say I have no experience in it workaround. Although in my manager.conf file the port is set to 5038 which I found to be default and never changed it. Please be more lenient with me :slight_smile: Thank you.

Ohh my bad. I saw the telnet option in my Putty so since the port in the manager.conf is set to 5038 should I access my Asterisk using that port?

I put the Asterisk address and the port 5038 specified in the manager.conf file and nothing happened. It is not working with that port.

And if you try to connect to it from the machine that Asterisk is running on? Are there any log messages at startup that indicate any issues?

How do I connect it in the Asterisk server, I only run the command “module reload manager” which says it is reload successfully. Is there a command to connect on the Asterisk server?

“telnet 127.0.0.1 5038”

It gives the error “No such command as telnet”

Then you don’t have telnet installed… you could install it to confirm.

Running “netstat -a | grep 5038” would also confirm if Asterisk is listening.

The netstat command list processes of the Asterisk

I have installed telnet. When I “telnet asteriskserveraddress 5038” I get the response “Connection closed by foreign host”

Is that remotely or on the Asterisk system itself? Doing it on the Asterisk system itself narrows it down more.

Running “netstat -a | grep 5038” gives this output

It appears to be listening. You see nothing on the Asterisk console about a connection? And as I asked before - was the telnet on the Asterisk system, or remote?

When I did the telnet, it says connected. So I tried to run “Asterisk Call Manager”. I took a long time to give the error “Connection closed by foreign host”

Couple things;

  1. ‘manager reload’ from the cli.
  2. Check your python config for a max execution timeout. I ran into this with a php script that would disconnect every 60 seconds. I didn’t notice because it was an upstart job.
  3. When you telnet in, you have to run action: login {enter}, then username: user {enter}, then secret: password {enter}{enter}.
  4. If you want to see the connects and disconnects, add this to the general section of manager.conf…
    displayconnects = yes
  1. I have done manager reload before now but it didnt fix it

  2. I am using an Python Asterisk Manager and it has been working fine, suddenly it just stopped. I checked the config.py file but I can’t see anything on max execution time there.

  3. Please after I do the telnet command and it says connected. Which command do I use for logging in?

  4. I already have “displayconnects = yes” in my manager.conf file

From the command prompt on the server:

telnet 127.0.0.1 5038

Action: Login
Username: your_username
Secret: your_password

Then press Enter twice to execute the login.

This is what I did

[root@developer asterisk]# telnet 127.0.0.1 5038
Trying 127.0.0.1…
Connected to 127.0.0.1.
Escape character is ‘^]’.
Action:Login
Username:matthew
Secret:Svenger

Connection closed by foreign host.
[root@developer asterisk]#

I still get connection closed by foreign host error. My manager.conf has my login credential to be like this

[matthew]
secret = Svenger
;deny=0.0.0.0/0.0.0.0
permit=153.162.162.95/255.255.255.0

The 153.162.162.95 is the web application that will be calling the Asterisk AMI.