Esempio n. 1
0
 /**
  * Return an array of all switch names where the array key is the switch id
  *
  * @param bool          $active If `true`, return only active switches
  * @param int           $type   If `0`, all types otherwise limit to specific type
  * @param \Entities\IXP $ixp    IXP to filter vlan names
  * @return array An array of all switch names with the switch id as the key.
  */
 public function getNames($active = false, $type = 0, $ixp = false)
 {
     $switches = [];
     foreach ($this->getAndCache($active, $type) as $a) {
         if (!$ixp || $ixp->getInfrastructures()->contains($a->getInfrastructure())) {
             $switches[$a->getId()] = $a->getName();
         }
     }
     asort($switches);
     return $switches;
 }
 /**
  * Utility function to slurp all VLAN interfaces ports from the database and arrange them in
  * arrays by infrastructure.
  *
  * @param \Entities\IXP $ixp
  */
 public static function genConf_getTargets($ixp)
 {
     $data = [];
     foreach ($ixp->getInfrastructures() as $infra) {
         $data[$infra->getId()]['name'] = preg_replace('/#/', '', $infra->getName());
         $data[$infra->getId()]['shortname'] = preg_replace('/#/', '', $infra->getShortname());
         $data[$infra->getId()]['vlans'] = [];
         foreach ($infra->getVLANs() as $v) {
             if ($v->getPrivate()) {
                 continue;
             }
             $vlan = [];
             $vlan['name'] = preg_replace('/#/', '', $v->getName());
             $vlan['number'] = preg_replace('/#/', '', $v->getNumber());
             $vlan['ints'] = [];
             foreach ($v->getVlanInterfaces() as $vli) {
                 if ($vli->getVirtualInterface()->getCustomer()->getStatus() != \Entities\Customer::STATUS_NORMAL) {
                     continue;
                 }
                 $havePhysInt = false;
                 foreach ($vli->getVirtualInterface()->getPhysicalInterfaces() as $pi) {
                     if ($pi->getStatus() == \Entities\PhysicalInterface::STATUS_CONNECTED) {
                         $havePhysInt = true;
                         break;
                     }
                 }
                 if (!$havePhysInt) {
                     continue;
                 }
                 $key = $vli->getVirtualInterface()->getCustomer()->getName() . '___' . $vli->getId();
                 $vlan['ints'][$key]['vliid'] = $vli->getId();
                 $vlan['ints'][$key]['name'] = preg_replace('/#/', '', $vli->getVirtualInterface()->getCustomer()->getName());
                 $vlan['ints'][$key]['shortname'] = preg_replace('/#/', '', $vli->getVirtualInterface()->getCustomer()->getShortname());
                 $vlan['ints'][$key]['abbreviatedname'] = preg_replace('/#/', '', $vli->getVirtualInterface()->getCustomer()->getAbbreviatedName());
                 if ($vli->getIpv4enabled() && $vli->getIpv4canping()) {
                     $vlan['ints'][$key]['ipv4'] = $vli->getIpv4Address()->getAddress();
                 } else {
                     $vlan['ints'][$key]['ipv4'] = false;
                 }
                 if ($vli->getIpv6enabled() && $vli->getIpv6canping()) {
                     $vlan['ints'][$key]['ipv6'] = $vli->getIpv6Address()->getAddress();
                 } else {
                     $vlan['ints'][$key]['ipv6'] = false;
                 }
             }
             ksort($vlan['ints'], SORT_STRING | SORT_FLAG_CASE);
             $data[$infra->getId()]['vlans'][$v->getId()] = $vlan;
         }
     }
     return $data;
 }
 public function getSmokeping()
 {
     $this->__load();
     return parent::getSmokeping();
 }
 /**
  * Utility function to slurp all peering VLAN interfaces ports from the database and
  * arrange them in arrays for use by the Nagios config templates
  *
  * @param \Entities\IXP $ixp
  */
 private function genMemberConf_getVlanInterfaces($ixp)
 {
     $custs = [];
     $switches = [];
     $cabinets = [];
     $locations = [];
     $ipv4hosts = [];
     $ipv6hosts = [];
     foreach ($ixp->getCustomers() as $c) {
         if (!$c->isTypeFull() || $c->hasLeft() || $c->getStatus() != \Entities\Customer::STATUS_NORMAL) {
             continue;
         }
         $custs[$c->getId()]['shortname'] = $c->getShortname();
         $custs[$c->getId()]['name'] = $c->getAbbreviatedName();
         $custs[$c->getId()]['hostnames'] = [];
         $custs[$c->getId()]['vints'] = [];
         foreach ($c->getVirtualInterfaces() as $vi) {
             // make sure we have a phsyical connection
             $haveConnection = false;
             foreach ($vi->getPhysicalInterfaces() as $pi) {
                 if ($pi->getStatus() == \Entities\PhysicalInterface::STATUS_CONNECTED) {
                     $haveConnection = true;
                 }
             }
             if (!$haveConnection) {
                 continue;
             }
             foreach ($vi->getVlanInterfaces() as $vli) {
                 if ($vli->getVlan()->getPrivate()) {
                     continue;
                 }
                 foreach (['v4', 'v6'] as $proto) {
                     $getIpEnabled = "getIp{$proto}enabled";
                     $getIpCanping = "getIp{$proto}canping";
                     $getIpAddress = "getIP{$proto}Address";
                     $getIpMonBGP = "getIp{$proto}monitorrcbgp";
                     if ($vli->{$getIpEnabled}() && $vli->{$getIpCanping}()) {
                         if (!$vli->{$getIpAddress}()) {
                             continue;
                         }
                         $hn = "{$c->getShortname()}-ip{$proto}-vlan{$vli->getVlan()->getNumber()}-{$vli->getId()}";
                         $custs[$c->getId()]['hostnames'][] = $hn;
                         $custs[$c->getId()]['vints'][$vli->getId()][$proto]['hostname'] = $hn;
                         $custs[$c->getId()]['vints'][$vli->getId()][$proto]['address'] = $vli->{$getIpAddress}()->getAddress();
                         $custs[$c->getId()]['vints'][$vli->getId()][$proto]['canping'] = $vli->{$getIpCanping}();
                         $custs[$c->getId()]['vints'][$vli->getId()][$proto]['monrc'] = $vli->{$getIpMonBGP}();
                         $custs[$c->getId()]['vints'][$vli->getId()][$proto]['vlan'] = $vli->getVlan()->getName();
                         $custs[$c->getId()]['vints'][$vli->getId()][$proto]['busyhost'] = $vli->getBusyhost();
                         $pi = $vi->getPhysicalInterfaces()[0];
                         $sw = $pi->getSwitchPort()->getSwitcher();
                         if (!isset($switches[$sw->getName()]) || !in_array($hn, $switches[$sw->getName()])) {
                             $switches[$sw->getName()][] = $hn;
                         }
                         if (!isset($cabinets[$sw->getCabinet()->getName()]) || !in_array($hn, $cabinets[$sw->getCabinet()->getName()])) {
                             $cabinets[$sw->getCabinet()->getName()][] = $hn;
                         }
                         if (!isset($locations[$sw->getCabinet()->getLocation()->getShortname()]) || !in_array($hn, $locations[$sw->getCabinet()->getLocation()->getShortname()])) {
                             $locations[$sw->getCabinet()->getLocation()->getShortname()][] = $hn;
                         }
                         if ($proto == 'v4') {
                             $ipv4hosts[] = $hn;
                         } else {
                             $ipv6hosts[] = $hn;
                         }
                         if (!isset($custs[$c->getId()]['vints'][$vli->getId()]['phys'])) {
                             $custs[$c->getId()]['vints'][$vli->getId()]['phys']['switch'] = $sw->getName();
                             $custs[$c->getId()]['vints'][$vli->getId()]['phys']['port'] = $pi->getSwitchPort()->getName();
                             $custs[$c->getId()]['vints'][$vli->getId()]['phys']['lag'] = count($vi->getPhysicalInterfaces()) - 1;
                         }
                     }
                 }
             }
         }
     }
     $this->view->custs = $custs;
     $this->view->switches = $switches;
     $this->view->cabinets = $cabinets;
     $this->view->locations = $locations;
     $this->view->ipv4hosts = $ipv4hosts;
     $this->view->ipv6hosts = $ipv6hosts;
 }
 /**
  * Utility function to slurp all peering ports from the database and arrange them in
  * arrays by infrastructure and switch.
  *
  * @param \Entities\IXP $ixp
  */
 private function genMrtgConf_getPeeringPortsByInfrastructure($ixp)
 {
     $data = [];
     foreach ($ixp->getInfrastructures() as $infra) {
         if (!$infra->getAggregateGraphName()) {
             continue;
         }
         $data[$infra->getId()]['mrtgIds'] = [];
         $data[$infra->getId()]['name'] = $infra->getName();
         $data[$infra->getId()]['aggregate_graph_name'] = $infra->getAggregateGraphName();
         $data[$infra->getId()]['maxbytes'] = 0;
         $data[$infra->getId()]['switches'] = '';
         foreach ($infra->getSwitchers() as $switch) {
             if ($switch->getSwitchtype() != \Entities\Switcher::TYPE_SWITCH || !$switch->getActive()) {
                 continue;
             }
             $data[$infra->getId()]['switches'][$switch->getId()] = [];
             $data[$infra->getId()]['switches'][$switch->getId()]['name'] = $switch->getName();
             $data[$infra->getId()]['switches'][$switch->getId()]['maxbytes'] = 0;
             $data[$infra->getId()]['switches'][$switch->getId()]['mrtgIds'] = [];
             foreach ($switch->getPorts() as $port) {
                 if ($port->getIfName()) {
                     $snmpId = $port->ifnameToSNMPIdentifier();
                     $data[$infra->getId()]['maxbytes'] += $port->getIfHighSpeed() * 1000000 / 8;
                     // Mbps * bps / to bytes
                     $data[$infra->getId()]['switches'][$switch->getId()]['maxbytes'] += $port->getIfHighSpeed() * 1000000 / 8;
                     foreach (IXP_Mrtg::$TRAFFIC_TYPES as $type => $vars) {
                         $id = "{$vars['in']}#{$snmpId}&{$vars['out']}#{$snmpId}:{$switch->getSnmppasswd()}@{$switch->getHostname()}:::::2";
                         if ($port->getType() == \Entities\SwitchPort::TYPE_PEERING) {
                             $data[$infra->getId()]['mrtgIds'][$type][] = $id;
                         }
                         $data[$infra->getId()]['switches'][$switch->getId()]['mrtgIds'][$type][] = $id;
                     }
                 }
             }
         }
     }
     return $data;
 }