Is it possible to export all the extensions list as a CSV or other format???
I can see all the extensions list from asterisk CLI by using the following command
sip show peers
But i need to export the list to keep inventory. Can anyone help?
Is it possible to export all the extensions list as a CSV or other format???
I can see all the extensions list from asterisk CLI by using the following command
sip show peers
But i need to export the list to keep inventory. Can anyone help?
sip show peers doesn’t show you extensions; it shows you devices that can accept calls from Asterisk (although you can also have ones that do this but aren’t in sip.conf. It has no concept of extension versus trunk, so will show all the peers.
There is no direct support to export as CSV. Why do you believe you need it in CSV format.
Typically, you would go the other way; you would generate the Asterisk configuration from a database, if you wanted it to be very structured.
It is posible to it, running sip show peers from an external script written on Python and PHP for example and it generate the CSV file. Also sip show peers. Also they are sip peers not extensions
Then what is the command for seeing only the extensions list?? @ambiorixg12 can you please refer me any blog or something from where i can learn how to write script for exporting extensions list and CDR for a specific duration?
You can use the ‘dialplan show’ command on the console to get a output of what your extensions have compiled to.
This should handle lua, ael and standard extensions.conf
Pattern matches won’t be expanded but they will show up
[ Context 'speeddial' created by 'pbx_config' ]
'_*1XX' => 1. NoOP() [pbx_config]
2. Set(NumberToCall=${DB(systemspeeddial/${EXTEN:2})}) [pbx_config]
3. GotoIf(${DB_EXISTS(${systemspeeddial/${EXTEN:2})}?SET:NOTSET) [pbx_config]
[SET] 4. Goto(${NumberToCall},1) [pbx_config]
[NOTSET] 5. Answer() [pbx_config]
6. Playback(silence/1&speed-dial) [pbx_config]
7. SayDigits(${EXTEN:2}) [pbx_config]
8. Playback(is-not-set) [pbx_config]
9. Hangup() [pbx_config]
'_*75XX0' => 1. NoOP() [pbx_config]
2. Answer() [pbx_config]
3. Set(SpeedDial=${DB_DELETE(systemspeeddial/${EXTEN:3:2})}) [pbx_config]
4. Playback(silence/1&speed-dial) [pbx_config]
5. SayDigits(digits/${EXTEN:3:2}) [pbx_config]
6. Playback(has-been-cleared) [pbx_config]
7. Hangup() [pbx_config]
You’ll have to write your own parser.
Perhaps something as simple as:
asterisk -x "dialplan show" | grep -E -e "'.*'[[:space:]]+=>[[:space:]]+" | cut -d "'" -f 2
May suffice to give you an overview of what actually is in your dialplan. To list where each entry goes, however, will require you to spend some time studying how stuff works in Asterisk.
I made this quick sample how to save peers list on txt file
using php
<?php
$file="/var/www/html/peers.txt";
$peers=shell_exec("asterisk -x \"sip show peers \" | grep -v \"sip peers\" | grep -v \"Name/username\" | awk '{print $1}'");
$peers=explode('\n',$peers);
foreach($peers as $value) {
if($value!=''){
$data=$value;
$data.="\n";
file_put_contents("$file", $data,FILE_APPEND);
}
}
?>
If you want to use csv usefputcsv function
On Python you can use the csv module
Neat use of Grep, I’ve not used the [[:space:]] syntax before.