CLI way of getting bulk handler information


Another thing you can do is monitor the asterisk full.log file for unreachable messages and alert on that. I use SEC for that, though in my case to watch for multiple phones becoming unreachable or lagged in a 5 minute period so I know if something up on the network.

(United States) #22

Sorry, I think there might be some confusion. I understand that mac-address is baked into the device itself and that DHCP is handing out IP. What I am trying to gather is this information from the CLI instead of using the Bulk Handler Exports.

Clearly, I am using the ClearyIP module which I understand might not be supported on this forum, but the endpoint manager extension mapping is the one that is built into FreePBX v15, and I am hoping there is an easy from the CLI to gather that information

This command shows me the extension under Extension Mapping.

SHOW CREATE TABLE `asterisk`.`endpoint_extensions`;
SELECT * FROM `asterisk`.`endpoint_extensions` LIMIT 1000;

I just need how to figure out how to connect SQL using PowerShell and importing this data. Unless there is a Linux command that will get similar info.


You can gather the current state of sip phones with sip show peers and pjsip show endpoints./aors but if a phone ‘goes away’ there is only historical evidence of where it was in the log files . Further you can never presume it will reappear at that same address, although most likely it will.

I’m not a windoze user but I suspect that the Windows subsystem for Linux is a precursor to windows actualy going to Linux and currently exposes a full on linux shell for you guys.

For linux , apart from the mysql client over ssh, if you want a gooey there is always mysql-workbench which I believe runs on Windoze also.

(United States) #24

I am storing historical information when I’m parse the actual switches for the Mac table I am storing all mac addresses and what ports they are connected to in a simply file (not database or anything fancy). Getting MAC address from Freepbx will allow me to determine what port on the switch that certain extension was connect to.

pjsip show endpoints | egrep 1001

Will ensure that the phone comes back up up and registers properly.

I have some other use case of this too. Sometimes my techs will install a phone but not enter it into Freepbx, this will allow me to tell how many phone are just sitting at the provision screen waiting for registration.


Hmm, maybe I’m missing something but please explain how a passive “pjsip show endpoints | egrep 1001” would ensure anything?

(United States) #26

Maybe I wasn’t clear, the full command I am using this
asterisk -rx 'pjsip show endpoints' | egrep '1000|6200'

In this case, x1000 is currently “offline” or not registered. x6200 (is my extension) is register from 2 locations my desk phone and my softphone.


Exactly, please remind me what we are trying to do here, I thought we are trying to map all MAC’s to the last IP they used , at this point in time, you can only map active endpoints that are available.

Are these phones to be considered ‘local’ or ‘external’ ?

(United States) #28

The phones I am only worried about are the internal phones. Since we are a school district, 911 calling from the classroom is a big safety concern.

I have to manually Bulk Handler Export, Extension and ClearyIP Device. Which will give me

Extension: I am getting Extension, Name and Account code (which I use to input the location of the phone, ie room 1)
ClearyIP Device: will give me Extension and Mac address

I have a nightly process that does the below.

  1. I am parsing all my network switch for the mac address tables to determine which mac-address (not just phones, I am gathering everything) is plugged into what port on the switch. Storing historical data in the event a device goes offline (dies, unplugs, etc)
  2. SSH into the Freepbx box and run asterisk -rx ‘pjsip show endpoints’, which will give me an extension and what IP it has registered.

Then when a user calls and says “My phone doesn’t work”, 90% of the time a reboot will fix the phone. I will run my script that will look up at the extension of the user, which will show the mac address (from ClearyIP Device table). Then it will find where the mac address is plugged into port ## on switch AB. It will then no power the port and repower the port on the switch. Then will rerun step 2, to see if that extension is registered again. (I also can be proactive and look for offline phones and give it a reboot to see if they come back up)

The manual part of the Bulk Handler is what I am trying to solve. Since other people on my team use this script, I do not update the Bulk Handler information to often. So if a tech replaces a phone due to damage or adds a phone. The script will not be able to find any information on it, since the new\replaced mac address is missining. If I can added “Bulk Handler export” part into my nightly script it will take the manual process out of this.

Hope that makes sense.


Personally I would spend my efforts to find out why the phones are going off line, bad firmware, bad hardware whatever , out of many hundreds I have in my purview and , mostly remote, and we are speakinh years here,the only ones that have done that needed either a firmware update or a commit to trash .

(Daniel Friedman) #30

Hello @longqvo,

There is a fwconsole bulkimport option in the fwconsole shell commands. I think it would be a nice feature to add a fwconsole bulkexport optin to it with a slight effort.

This is the Code for the import option:

[root@pbx ~]# cat /var/www/html/admin/modules/bulkhandler/Console/Bulkimport.class.php 
namespace FreePBX\Console\Command;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Bulkimport extends Command {
        protected function configure(){
                $mod_info = module_getinfo('callaccounting', MODULE_STATUS_ENABLED);
                if (!isset($mod_info['callaccounting'])) {
                        $helptext = 'Import a file: fwconsole bulkimport --type=[extensions|dids] filename.csv --replace(Replace the existing values)';
                } else {
                        $helptext = 'Import a file: fwconsole bulkimport --type=[extensions|dids|callaccounting] filename.csv --replace(Replace the existing values)';
                ->setDescription('This command is used to import extensions and dids')
                        new InputOption('type', 't', InputOption::VALUE_REQUIRED, 'Type of file'),
                        new InputArgument('filename', InputArgument::REQUIRED, 'Filename', null),
                        new InputOption('replace', null, InputOption::VALUE_NONE, 'To replace existing values'),))
        protected function execute(InputInterface $input, OutputInterface $output){
                $filename = $input->getArgument('filename');
                $type = $input->getOption('type');
                if ($input->getOption('replace')) {
                        $replace = true;
                if (file_exists($filename)) {
                        $data = \FreePBX::Bulkhandler()->fileToArray($filename);
                } else {
                        $output->writeln('<error>The specified file does not exist or we cannot read it</error>');
                        return false;
                if (!$data) {
                        $output->writeln('<error>The file provided did not process properly. Check the file formatting</error>');
                        return false;

                switch ($type) {
                        case 'dids':
                                $output->writeln('Importing bulk dids');
                                $ret = \FreePBX::Bulkhandler()->import('dids', $data, $replace);
                        case 'extensions':
                                $output->writeln('Importing bulk extensions');
                                $ret = \FreePBX::Bulkhandler()->import('extensions', $data, $replace);
                        case 'callaccounting':
                                $output->writeln('Importing CallDECK Ratepatterns');
                                $ret = \FreePBX::Bulkhandler()->import('callaccounting', $data, $replace);
                                $output->writeln('<error>You must specify the file type of --type=dids or --type=extensions</error>');
                        return false;
                if (!$ret) {
                        $output->writeln('<error>The import failed</error>');
                        return false;
                } else {
                        return true;

Do you think it would be needed? It could be even be contributed to the community.
Can you share your thoughts on that?

Thank you,

Daniel Friedman
Trixton LTD.

(system) closed #31

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