Brief intro of Asterisk Manager
Tags: asterisk, ami, beginners, pbx
Published: 2021-05-14 04:02:57

## Weekly sharing

Hi everyone, I am Ekim, a fresh Bootcamp graduate and an IT helper (I don't dare to call myself a programmer yet). Every Friday, I will share some of the work that I've done over the last week in a bid to get feedbacks from you guys and record my journey to become a programmer. 

### Previously
<a href="https://dev.to/ekim34351855/make-calls-through-asterisk-cli-45ba">Make calls through Asterisk CLI</a>

### Introduction

After being able to make calls and play around with playback and record dialplan applications, it's time to prepare ourselves for using those functions through codes. But before that, we need to know what Asterisk Manager Interface is. 

**Warning: **Only try the following within your own local network. 



### What is Asterisk Manager Interface ?

- It is like a remote control of the asterisk. 
- Unlike running asterisk commands on the CLI, the state and process of which cannot be seen and controlled, the asterisk manager interface resolves those issues and helps monitor the operation of the asterisk. 
- Since AMI allows you to remotely control the asterisk, it is advised that you do not use AMI directly with a public IP address without protection like SSL connection or a VPN tunnel.



### Steps using AMI 

- Check if port 5038 is available as we are going to use it. 

  ```bash
    netstat -lpn
```

- Configure the manager.conf

  ```conf
    [general]
    enabled = yes		;by default, it is "no" for security reason.
    port = 5038
    bindaddr = 0.0.0.0	;bind the ip address to localhost for lcoal testing, need to change when remote control it
    [ekim]				;login username, often for CRM, ERP or dialer 
    secret=xxxxxxxx		;login password, should be complex
    deny=0.0.0.0/0.0.0.0		;deny everything --> much safer to permit each ip address we trust
    permit=XXX.XXX.XX.XX/255.255.255.0		;permit local network after an entire denial, this can also be done in acl.conf
    read=all		;read all logs
    write=all		;write all logs
```

- Restart asterisk after **IP and port changes**

  ```bash
    sudo service asterisk restart
```

- Use `telnet` to connect to AMI

  - `telnet` allows access to remote servers, which is based on the TELNET protocol. **Only recommend you use `telnet` to connect within your own network.**

  ```bash
    # telnet <permitted IP address> <port>
    telnet XXX.XXX.XX.XX 5038
```

  ```bash
    # after that, tab "enter" once as we need to continue to login
    Action:login
    Username:ekim
    Secret:xxxxxxxx
    # when finish registering, tab "enter" twice for signaling you're done
    
    
```

- After that, you should see the `Response: Success` and could see all actions in the asterisk.

  ```bash
    Response: Success
    Message: Authentication accepted
    
    Event: FullyBooted
    Privilege: system,all
    Uptime: 67
    LastReload: 67
    Status: Fully Booted
```

![ami](https://drive.google.com/uc?export=view&id=1hCWDgeStQqCyAnChB-HfK954FPdsQRSg)




- Now, you have accessed to your own asterisk server and entered the AMI. That means you are no longer playing on the CLI. You are 'remotely controlling' your asterisk pbx. 

- So, why not we try to originate a call (make a call) and see what would happen ?

- The below is based on our <a href="https://dev.to/ekim34351855/asterisk-basic-set-up-4ple">first tutorial</a> pjsip and dialplan settings

```bash
      Action:Originate
      Channel:PJSIP/7000
      Exten:7100
      Context:interaction
      Priority:1
# remember to tab 'enter' twice to signal that you are finished


```

      
      

![7000](https://drive.google.com/uc?export=view&id=17w7FzjIP0a_WCs4K-ajHEwZIMkGNl7OS)

![7000](https://drive.google.com/uc?export=view&id=14Twg0hJY5rfP6v7n04biwSdJK28B3sKL)

Mine is working now, how about yours ? Btw, if you want to leave the AMI, you could do this


```bash
      Action:logoff
      # remember to tab 'enter' twice to signal that you are finished
      
      
```

      



### Conclusion

You might want to keep your eyes close to the log data shown in AMI since those are the things we might need if we touch on the coding part. That's all for today. In the meantime, stay healthy and stay tuned for more content !!!