/**
 *
 */
function smarty_function_mrtgScale($params, &$smarty)
{
    $strFormat = isset($params['format']) ? $params['format'] : 'bits';
    $intDem = isset($params['decimals']) ? $params['decimals'] : 3;
    $intReturn = isset($params['return']) ? $params['return'] : 0;
    return IXP_Mrtg::scale($params['value'], $strFormat, $intDem, $intReturn);
}
/**
 * Generate a URL for an Mrtg image.
 *
 */
function smarty_function_genMrtgGraphBox($params, &$smarty)
{
    $url = IXP_Mrtg::generateZendFrontendUrl($params);
    $box = <<<END_BOX
<table width="506" cellspacing="1" cellpadding="1">
<tr>
    <td colspan="8" style="width: 500; height: 135;">
        <img width="500" height="135" border="0" src="{$url}" />
    </td>
</tr>
<tr>
    <td width="10%">
    </td>
    <td width="25%" align="right">
        <strong>Max&nbsp;&nbsp;&nbsp;&nbsp;</strong>
    </td>
    <td width="25%" align="right">
        <strong>Average&nbsp;&nbsp;&nbsp;&nbsp;</strong>
    </td>
    <td width="25%" align="right">
        <strong>Current&nbsp;&nbsp;&nbsp;&nbsp;</strong>
    </td>
    <td width="15%"></td>
    </tr>
<tr>
    <td style="color: #00cc00; font-weight: bold;"  align="left">
        In
    </td>
    <td align="right">
        {$params['values']['maxin']}
    </td>
    <td align="right">
        {$params['values']['averagein']}
    </td>
    <td align="right">
        {$params['values']['curin']}
    </td>
    <td></td>
</tr>
<tr>
    <td style="color: #0000ff; font-weight: bold;"  align="left">
        Out
    </td>
    <td align="right">
        {$params['values']['maxout']}
    </td>
    <td align="right">
        {$params['values']['averageout']}
    </td>
    <td align="right">
        {$params['values']['curout']}
    </td>
    <td></td>
</tr>
</table>
END_BOX;
    return $box;
}
 /**
  * Get public peering graphs
  *
  */
 private function _publicPeeringGraphs()
 {
     // only do this once every five minutes
     if ($admin_home_stats = $this->getD2Cache()->fetch('admin_home_stats')) {
         $this->view->graphs = $admin_home_stats['graphs'];
         $this->view->stats = $admin_home_stats['stats'];
     } else {
         $admin_home_stats = [];
         $graphs = [];
         $stats = [];
         if ($this->multiIXP()) {
             $ixps = $this->getD2R('\\Entities\\IXP')->findAll();
             foreach ($ixps as $ixp) {
                 if ($ixp->getAggregateGraphName()) {
                     $graphs[$ixp->getId()]['name'] = $ixp->getAggregateGraphName();
                     $graphs[$ixp->getId()]['title'] = $ixp->getName();
                     $mrtg = new IXP_Mrtg($ixp->getMrtgPath() . DIRECTORY_SEPARATOR . 'ixp_peering-' . $ixp->getAggregateGraphName() . '-' . IXP_Mrtg::CATEGORY_BITS . '.log');
                     $stats[$ixp->getId()] = $mrtg->getValues(IXP_Mrtg::PERIOD_MONTH, IXP_Mrtg::CATEGORY_BITS);
                 }
             }
         } else {
             $ixp = $this->getD2R('\\Entities\\IXP')->getDefault();
             if ($ixp->getAggregateGraphName()) {
                 $graphs[$ixp->getId()]['name'] = $ixp->getAggregateGraphName();
                 $graphs[$ixp->getId()]['title'] = 'IXP Aggregate Graph';
                 $mrtg = new IXP_Mrtg($ixp->getMrtgPath() . DIRECTORY_SEPARATOR . 'ixp_peering-' . $ixp->getAggregateGraphName() . '-' . IXP_Mrtg::CATEGORY_BITS . '.log');
                 $stats[$ixp->getId()] = $mrtg->getValues(IXP_Mrtg::PERIOD_MONTH, IXP_Mrtg::CATEGORY_BITS);
             }
             foreach ($ixp->getInfrastructures() as $inf) {
                 if ($inf->getAggregateGraphName()) {
                     $graphs[$ixp->getId() . '-' . $inf->getId()]['name'] = $inf->getAggregateGraphName();
                     $graphs[$ixp->getId() . '-' . $inf->getId()]['title'] = $inf->getName();
                     $mrtg = new IXP_Mrtg($ixp->getMrtgPath() . DIRECTORY_SEPARATOR . 'ixp_peering-' . $inf->getAggregateGraphName() . '-' . IXP_Mrtg::CATEGORY_BITS . '.log');
                     $stats[$ixp->getId() . '-' . $inf->getId()] = $mrtg->getValues(IXP_Mrtg::PERIOD_MONTH, IXP_Mrtg::CATEGORY_BITS);
                 }
             }
         }
         $admin_home_stats['graphs'] = $this->view->graphs = $graphs;
         $admin_home_stats['stats'] = $this->view->stats = $stats;
         $this->getD2Cache()->save('admin_home_stats', $admin_home_stats, 300);
     }
 }
/**
 * Generate a HTML img tag for an Mrtg image.
 *
 */
function smarty_function_genMrtgImgUrlTag($params, &$smarty)
{
    $url = IXP_Mrtg::generateZendFrontendUrl($params);
    return '<img width="500" height="135" border="0" src="' . $url . '" />';
}
示例#5
0
 function retrieveP2pImageAction()
 {
     $cust = $this->view->cust = $this->resolveCustomerByShortnameParam();
     // includes security checks
     $this->setIXP($cust);
     $category = $this->setCategory('category', false);
     $period = $this->setPeriod();
     $proto = $this->setProtocol();
     // Find the possible VLAN interfaces that this customer has for the given IXP
     // and ensure we have a valid svli
     $srcVlis = $this->getD2R('\\Entities\\VlanInterface')->getForCustomer($cust, $this->ixp);
     if (!($svli = $this->getParam('svli', false)) || !isset($svli, $srcVlis)) {
         $this->getLogger()->alert("P2P file request with illegal svli={$svli} for {$cust->getShortname()}/{$this->getUser()->getUsername()}");
         die;
     }
     // Find the possible interfaces that this customer peers with and ensure we have a valid dvli
     $dstVlis = $this->getD2R('\\Entities\\VlanInterface')->getObjectsForVlan($srcVlis[$svli]->getVlan());
     unset($dstVlis[$svli]);
     if (!($dvli = $this->getParam('dvli', false)) || !isset($dvli, $dstVlis)) {
         $this->getLogger()->alert("P2P file request with illegal dvli={$dvli} for {$cust->getShortname()}/{$this->getUser()->getUsername()}");
         die;
     }
     $filename = IXP_Mrtg::getMrtgP2pFilePath($this->ixp->getMrtgP2pPath(), $svli, $dvli, $category, $period, $proto);
     $this->getLogger()->debug("Serving P2P {$filename} to {$this->getUser()->getUsername()}");
     if (@readfile($filename) === false) {
         $this->getLogger()->notice('Could not load ' . $filename . ' for mrtg/retrieveImageAction');
         @readfile(APPLICATION_PATH . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . '300x1.png');
     }
 }
示例#6
0
 /**
  * With the introduction of LAG graphs in 3.6.14, we wanted to merge past
  * traffic data form individual ports into the new lag files
  *
  * This CLI action just lists the files to merge to and from.
  *
  * Use a merger such as: http://bangbangsoundslikemachinery.blogspot.ie/2012/02/mrtg-log-aggregator.html
  * And set $MERGER and $MRTGPATH accordingly before running the resultant commands.
  */
 public function cliLagHistoryToFromAction()
 {
     // get all active trafficing customers
     $custs = $this->getD2R('\\Entities\\Customer')->getCurrentActive(false, true, false, $this->getD2R('\\Entities\\IXP')->getDefault());
     foreach ($custs as $c) {
         foreach ($c->getVirtualInterfaces() as $vi) {
             if (count($vi->getPhysicalInterfaces()) <= 1) {
                 continue;
             }
             foreach (IXP_Mrtg::$CATEGORIES as $category) {
                 echo '$MERGER';
                 foreach ($vi->getPhysicalInterfaces() as $pi) {
                     echo ' $MRTGPATH/' . IXP_Mrtg::getMrtgFilePath('members', 'LOG', $pi->getMonitorIndex(), $category, $c->getShortname());
                 }
                 echo ' >';
                 echo ' $MRTGPATH/' . IXP_Mrtg::getMrtgFilePath('members', 'LOG', 'lag-viid-' . $vi->getId(), $category, $c->getShortname());
                 echo "\n";
             }
         }
     }
 }
/**
 * Generate a URL for an Mrtg image.
 *
 */
function smarty_function_genMrtgImgUrl($params, &$smarty)
{
    return IXP_Mrtg::generateZendFrontendUrl($params);
}
 private function emailPortsWithCounts($type, $category, $inField, $outField)
 {
     $this->view->day = $day = date('Y-m-d', strtotime('-1 days'));
     $data = $this->getD2R('\\Entities\\TrafficDaily')->load($day, $category);
     $mail = $this->getMailer();
     $mail->setFrom($this->_options['cli']['ports_with_counts']['from_email'], $this->_options['cli']['ports_with_counts']['from_name'])->setSubject(sprintf($this->_options['cli']['ports_with_counts']['subject'], $type))->setType(Zend_Mime::MULTIPART_RELATED);
     foreach ($this->_options['cli']['ports_with_counts']['recipients'] as $r) {
         $mail->addTo($r);
     }
     $this->view->type = $type;
     $mailHtml = $this->view->render('statistics-cli/email/counts-header.phtml');
     $numWithCounts = 0;
     foreach ($data as $d) {
         if ($d[$inField] == 0 && $d[$outField] == 0) {
             continue;
         }
         $numWithCounts++;
         if ($this->isVerbose() || $this->isDebug()) {
             echo "{$d['Customer']['name']}\t\tIN / OUT: {$d[$inField]} / {$d[$outField]}\n";
         }
         $mrtg = $mail->createAttachment(file_get_contents(IXP_Mrtg::getMrtgFilePath($this->getD2R('\\Entities\\IXP')->getDefault()->getMrtgPath() . '/members', 'PNG', 'aggregate', $category, $d['Customer']['shortname'], IXP_Mrtg::PERIOD_DAY)), "image/png", Zend_Mime::DISPOSITION_INLINE, Zend_Mime::ENCODING_BASE64, "{$d['Customer']['shortname']}-aggregate.png");
         $this->view->mrtg_id = $mrtg->id = "{$d['Customer']['shortname']}-aggregate";
         $this->view->ecust = $d['Customer'];
         $this->view->in = $d[$inField];
         $this->view->out = $d[$outField];
         $mailHtml .= $this->view->render('statistics-cli/email/counts-member.phtml');
     }
     if ($numWithCounts) {
         $this->view->numWithCounts = $numWithCounts;
         $mailHtml .= $this->view->render('statistics-cli/email/counts-footer.phtml');
         $mail->setBodyHtml($mailHtml);
         $mail->send();
     }
 }
 public function switchesAction()
 {
     $eSwitches = $this->getD2EM()->getRepository('\\Entities\\Switcher')->getAndCache(true, \Entities\Switcher::TYPE_SWITCH);
     $switches = [];
     foreach ($eSwitches as $s) {
         // if we're not doing infrastructure aggregates, we're probably not doing swicth aggregates:
         if ($s->getInfrastructure()->getAggregateGraphName()) {
             $switches[$s->getId()]['name'] = $s->getName();
             $switches[$s->getId()]['mrtg'] = $s->getInfrastructure()->getIXP()->getMrtgPath();
         }
     }
     $this->view->switches = $switches;
     $switch = $this->getParam('switch', array_keys($switches)[0]);
     if (!in_array($switch, array_keys($switches))) {
         $switch = array_keys($switches)[0];
     }
     $this->view->switch = $switch;
     $category = $this->setCategory();
     // override allowed categories as some aren't available here
     $this->view->categories = IXP_Mrtg::$CATEGORIES_AGGREGATE;
     $this->setPeriod();
     $stats = array();
     foreach (IXP_Mrtg::$PERIODS as $period) {
         $mrtg = new IXP_Mrtg($switches[$switch]['mrtg'] . '/switches/' . 'switch-aggregate-' . $switches[$switch]['name'] . '-' . $category . '.log');
         $stats[$period] = $mrtg->getValues($period, $category);
     }
     $this->view->stats = $stats;
 }
/**
 * Generate a URL for an Mrtg image.
 *
 */
function smarty_function_genMrtgP2pImgUrl($params, &$smarty)
{
    $params['p2p'] = true;
    return IXP_Mrtg::generateZendFrontendUrl($params);
}