function retrieveImageAction() { $this->setIXP(); $monitorindex = $this->getParam('monitorindex', 'aggregate'); $period = $this->getParam('period', IXP_Mrtg::$PERIODS['Day']); $shortname = $this->getParam('shortname'); $category = $this->getParam('category', IXP_Mrtg::$CATEGORIES['Bits']); $graph = $this->getParam('graph', ''); $this->getLogger()->debug("Request for {$shortname}-{$monitorindex}-{$category}-{$period}-{$graph} by {$this->getUser()->getUsername()}"); if ($shortname == 'X_Trunks') { $filename = $this->ixp->getMrtgPath() . '/trunks/' . $graph . '-' . $period . '.png'; } else { if ($shortname == 'X_SwitchAggregate') { $filename = $this->ixp->getMrtgPath() . '/switches/switch-aggregate-' . $graph . '-' . $category . '-' . $period . '.png'; } else { if ($shortname == 'X_Peering') { $filename = $this->ixp->getMrtgPath() . '/ixp_peering-' . $graph . '-' . $category . '-' . $period . '.png'; } else { if ($this->getUser()->getPrivs() != \Entities\User::AUTH_SUPERUSER || !$this->checkShortname($shortname)) { $shortname = $this->getCustomer()->getShortname(); } $filename = IXP_Mrtg::getMrtgFilePath($this->ixp->getMrtgPath() . '/members', 'PNG', $monitorindex, $category, $shortname, $period); } } } $this->getLogger()->debug("Serving {$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 . 'image-missing.png'); } }
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(); } }
/** * 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"; } } } }
public function memberDrilldownAction() { $category = $this->setCategory(); $this->view->monitorindex = $monitorindex = $this->getParam('monitorindex', 1); $cust = $this->view->cust = $this->resolveCustomerByShortnameParam(); // includes security checks $this->setIXP($cust); $this->view->isLAG = false; $this->view->isPort = false; $this->view->isAggregate = false; if (is_numeric($monitorindex)) { $vint = false; $pi = null; foreach ($cust->getVirtualInterfaces() as $vi) { foreach ($vi->getPhysicalInterfaces() as $pi) { if ($pi->getMonitorindex() == $monitorindex) { $this->view->pi = $pi; $this->view->vint = $vint = $vi; break 2; } } } if (!$vint) { throw new IXP_Exception('Member statistics drilldown requested for unknown monitor index'); } $this->view->switchname = $pi->getSwitchPort()->getSwitcher()->getName(); $this->view->portname = $pi->getSwitchPort()->getName(); $this->view->isPort = true; } else { if (substr($monitorindex, 0, 9) == 'lag-viid-') { $viid = substr($monitorindex, 9); $vint = false; $pi = null; foreach ($cust->getVirtualInterfaces() as $vi) { if ($vi->getId() == $viid) { $this->view->vi = $vi; $this->view->vint = $vint = $vi; break; } } if (!$vint) { throw new IXP_Exception('Member statistics drilldown requested for unknown LAG index'); } $this->view->switchname = $vi->getPhysicalInterfaces()[0]->getSwitchPort()->getSwitcher()->getName(); foreach ($vi->getPhysicalInterfaces() as $pi) { $portnames[] = $pi->getSwitchPort()->getName(); } $this->view->portname = implode(', ', $portnames); $this->view->isLAG = true; } else { $this->view->switchname = ''; $this->view->portname = ''; $this->view->isAggregate = true; } } $this->view->periods = IXP_Mrtg::$PERIODS; $stats = array(); foreach (IXP_Mrtg::$PERIODS as $period) { $mrtg = new IXP_Mrtg(IXP_Mrtg::getMrtgFilePath($this->ixp->getMrtgPath() . '/members', 'LOG', $monitorindex, $category, $cust->getShortname())); $stats[$period] = $mrtg->getValues($period, $this->view->category); } $this->view->stats = $stats; if ($this->getParam('mini', false)) { Zend_Controller_Action_HelperBroker::removeHelper('viewRenderer'); $this->view->display('statistics/member-drilldown-mini.phtml'); } }