Getting list of all endpoints in Asterisk command line

asterisk
Tags: #<Tag:0x00007fafc311afd8>

(Haohmaru) #1

Hi, I’m working on writing a script to restart all active endpoints and I need a way to get a list of them.

“pjsip show endpoints” gives me alot of detail and I just need to create a basic list like

111
112
114

Thanks!


#2

Try “list” instead of “show”:

pjsip list endpoints

use grep / cut / awk / perl to trim the list.


(TheJames) #3

https://gist.github.com/jfinstrom/71a4d8a5dbcb7110940e3bbeb080fad8 just because


(Haohmaru) #4

Awesome, thanks. Here is the mess I came up with:

asterisk -rx "pjsip list endpoints" | grep -Ev "Unavailable|found|CID|=" | cut -f 1 -d "/" | cut -b 13-16

It produces the list I was looking for.


(Joshua C. Colp) #5

Speaking from an Asterisk perspective the CLI commands are really meant for human consumption, not machine, so they reflect that. You generally have to parse and extract accordingly.


(Haohmaru) #6

Here’s the whole thing, works great actually:

asterisk -rx "pjsip list endpoints" | grep -Ev "Unavailable|found|CID|=" | grep "\S" | cut -f 1 -d "/" | cut -b 13-16 > endpoints.txt
while read LINE; do asterisk -rx "pjsip send notify restart-yealink endpoint $LINE"; done < endpoints.txt

I have all Yealink phones so I had to add the following to sip_notify_custom.conf

[restart-yealink]
Event=>check-sync\;reboot=true

(Lorne Gaetz) #7

If you’re using Endpoint Manager, some of that functionality if baked into fwconsole:

[root@lorne14-pro 0]# fwconsole  endpoint
Usage: fwconsole endpoint action [arg arg...]
addmapping : Add extension to extension mapping.
Options:
        --brand     = Brand for extension ie: sangoma
        --mac       = MAC Address for extension.
        --template  = Template for extension.
        --model     = Model for extension.
        --account   = Account for extension.
        --accessory = Accessory setting for extension.
        --vpn       = VPN ID for extension.
listextensions : List extension(s) by order. Argument 1: Extension or ALL, Argument 2: Column to order by. Option --detail = All mapping information.
listtemplates : List all templates.
reboot : Request phone to reboot.  SANGOMA PHONES ONLY
rebuild : Rebuild the config files for an extension/template/all
rebuildupdate : Rebuild the config files for an extension/template/all and tell phone(s) to check config.
remove : Remove an extension. Specify extension.
update : Send a notify to an extension/template/all to check its the config.  Will cause most phones to reboot.

[root@lorne14-pro 0]# fwconsole endpoint listextensions ALL
+-----------+---------+--------------+-----------------+----------+----------+-------------+---------+-----+---+
| Extension | Brand   | MAC          | Template        | Model    | Account  | Expansion 1 | Rebuild | VPN |   |
+-----------+---------+--------------+-----------------+----------+----------+-------------+---------+-----+---+
| 5003      | Digium  | 000FD308410F | digium_default  | D50      | account1 |             | 0       |     | 0 |
| 5005      | Yealink | 0015657BA729 | yealink         | SIP-T41P | account1 |             | 1       |     | 0 |
| 5007      | Sangoma | 00505850014B | sangoma_default | S700     | account1 |             | 1       |     |   |
| 5013      | Snom    | 000413620AB2 | snom            | M700     | account2 |             | 1       |     |   |
| 5014      | Sangoma | 0050585000c0 | sangoma_default | S500     | account1 |             | 1       |     | 0 |
| 5016      | Sangoma | 00505851644B | sangoma_default | S305     | account1 |             | 1       |     |   |
| 5017      | Sangoma |              | sangoma_default | DB20     | account1 |             | 1       |     | 2 |
+-----------+---------+--------------+-----------------+----------+----------+-------------+---------+-----+---+

[root@lorne14-pro 0]# fwconsole endpoint rebuildupdate 5003
Extension 5003 rebuilt
Update command sent to 5003

(Haohmaru) #9

It would be nice if the “human” output required a “verbose” or “full” option and default output was stripped down.


(Dave Burgess) #10

I actually agree with you on this, except that I’m 180 the other way. Anything that returns a table should have a “CSV” or “TSV” to allow for the “pushing” of the data to a script through a comma or tab-separated mechanism. Actually, the “export” part of the bulk-handler does this, but to a file. Allowing this to go to standard out instead would make creating interactive scripts pretty powerful.

Of course, there are issues with even that. For example, should there be headers? Should the order be immutable? As I often point out, the system is Open Source, so if you really need something like this added, you have the tools (even if that tool is a checkbook).


#11

@jfinstrom’s hint shows you how to get the list from the REST interface as structured data so that you don’t have to worry about parsing through human-readable output.


(Jared Busch) #12

Except that the Yealink notify command reboot-yealink no longer reboots them. Because when I submitted a request to get the EPM to not force Yealink phones to reboot, all that was done was that the notify had the reboot=true changed to reboot=false Made it work like asked in EPM, but it broke the built in ability to actually reboot Yealink phones.
https://issues.freepbx.org/browse/FREEPBX-18131


(system) closed #13

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