Commit 4e8aee083583a422130c8f88228590a0fe2cd08b

Authored by Eduardo Santos
2 parents 21222d80 b1e539c8
Exists in master and in 2 other branches 3,1, 3.1

Corrige erro nas impressoras e bug da coleta

Showing 1 changed file with 38 additions and 2 deletions   Show diff stats
Controller/PrinterController.php
... ... @@ -603,12 +603,47 @@ class PrinterController extends Controller
603 603 ->getForm();
604 604 }
605 605  
  606 + /**
  607 + * Totalize results by limit and offset parameters
  608 + *
  609 + * @return Response
  610 + */
606 611 public function totalizer()
607 612 {
  613 + $n_printers = $this->em->createQuery('SELECT count(p) FROM CocarBundle:Printer p')->getSingleScalarResult();
  614 +
  615 + $limit = 1000;
  616 + $iterations = (int)($n_printers / 1000);
  617 + $iterations = $iterations + 1;
  618 +
  619 + $i = 0;
  620 + while ($i < $iterations) {
  621 + // O objetivo é executar a coleta a cada 1000 impressoras
  622 + $offset = $limit * $i;
  623 + $this->selectPrinters($limit, $offset);
  624 + $i = $i + 1;
  625 + }
  626 +
  627 +
  628 + return new Response();
  629 + }
  630 +
  631 + /**
  632 + * Select printers by offset and limit
  633 + */
  634 + private function selectPrinters($limit, $offset) {
608 635 ini_set('memory_limit', '1024M');
609 636 gc_enable();
610 637  
611   - $printers = $this->em->getRepository('CocarBundle:Printer')->findAll();
  638 + $printers = $this->em
  639 + ->createQuery('SELECT p FROM CocarBundle:Printer p ORDER BY p.id desc')
  640 + ->setMaxResults($limit)
  641 + ->setFirstResult($offset)
  642 + ->getResult();
  643 +
  644 + //$printers = $this->em->getRepository('CocarBundle:Printer')->findAll();
  645 +
  646 + $this->get('logger')->info("Executando coleta de $limit impressoras começando no número $offset");
612 647  
613 648 foreach($printers as $printer)
614 649 {
... ... @@ -617,6 +652,8 @@ class PrinterController extends Controller
617 652 $community = $printer->getCommunitySnmpPrinter();
618 653 $host = $printer->getHost();
619 654  
  655 + $this->get('logger')->info("Coletando impressora $host");
  656 +
620 657 $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1";
621 658  
622 659 if($outPut = shell_exec($com))
... ... @@ -631,7 +668,6 @@ class PrinterController extends Controller
631 668 $this->get('logger')->error("Erro na coleta da impressora $host \n".$e->getMessage());
632 669 }
633 670 }
634   - return new Response();
635 671 }
636 672  
637 673 /**
... ...