Create own AMI command?

Hi, is there a way to create my own AMI command? What I want to achieve is to get a list of all my pjsip endpoints with their current device state and the user agent by sending just one AMI command. Is there any solution?

Yes, of course. The source code is available, but if “pjsip show endpoints” has all the information you need, then the ami command “Command” to execute a cli command with some text processing might be easier.

Thanks for your reply. So I found two different AMI commands yet, which gives me the information I want. These are Action: DeviceStateList and Action: PJSIPShowContacts.
Do you have an idea how I can grep the informations I want from these two commands and put it together to a single response? Maybe by creating an AGI script which I can execute via AMI or is there a better solution?

Why do you want to use AGI, when your are trying to use AMI (from outside Asterisk)? Get the reply and handle the output. You can give DeviceStateList and PJSIPShowContacts a try and see what you get. The Asterisk wiki seems to be down at the moment, so I can’t say anything about the details and I haven’t used these actions myself so far.

That’s what I do already but I have a lot of Asterisk instances and I want to implement more logic to the instances itself than handle the output centralized to reduce the load of the centralized system. So do you have any other idea?

It seems to me that, once you rule out customising the Asterisk source code, this is no longer really an Asterisk question, but rather a general Linux programming one.

You didn’t say exactly where you want to have the information. There’s also the REST API with various language bindings.

I want to show the information at a web frontend which hasn’t direct connection to the Asterisk instances but to a centralized server and this server can do ssh and AMI connections to the instances (about 3000). So if there are multiple loads of the frontend the centralized server has to do a lot of AMI connections, grepping the correct information and putting it into the right format which creates a lot of load and the loading time of the frontend also increases. That’s why I try to find a solution to get only the necessary information (device status and user agent) from an Asterisk instances so that the centralized server just can format that to json and returning it to the frontend. That’s why I hoped that there is an AMI solution.
I hope it’s understandable… :slight_smile:

But I’ll have a look into the REST API and if that doesn’t work I have to create a script on each instance. Thanks so far!

I had a chat application that was monitored by a bunch of supervisors. The web page was very resource intensive, gathering data from Asterisk and MySQL and lots of formatting. And the web page auto-refreshed every 2 seconds. The first instance of the web page was quick, but each additional supervisor contributed to the painful wait for the status page to refresh.

My solution was a daemon that created a ‘static’ status page every 2 seconds. Having dozens of supervisors refreshing the page was now a trivial load.

In fact, the daemon/static page was faster than a single old dynamic page because the daemon didn’t have to connect to Asterisk and MySQL for every refresh.

The OP seems to have multiple sources and a single consumer. Your static page seems to be for a single source, multiple consumer environment.

That’s right.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.