Commit e85d96aeceb13d4e2eb3df861d1649709276af29

Authored by fellipevasconcelos
1 parent 6a90ac63
Exists in master and in 2 other branches 3,1, 3.1

Correcoes monitoramento impressoras

Command/CronCommand.php
@@ -2,13 +2,13 @@ @@ -2,13 +2,13 @@
2 2
3 namespace Swpb\Bundle\CocarBundle\Command; 3 namespace Swpb\Bundle\CocarBundle\Command;
4 4
5 -use Symfony\Component\Console\Command\Command;  
6 use Symfony\Component\Console\Input\InputArgument; 5 use Symfony\Component\Console\Input\InputArgument;
7 use Symfony\Component\Console\Input\InputInterface; 6 use Symfony\Component\Console\Input\InputInterface;
8 use Symfony\Component\Console\Input\InputOption; 7 use Symfony\Component\Console\Input\InputOption;
9 use Symfony\Component\Console\Output\OutputInterface; 8 use Symfony\Component\Console\Output\OutputInterface;
  9 +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
10 10
11 -class CronCommand extends Command 11 +class CronCommand extends ContainerAwareCommand
12 { 12 {
13 /** 13 /**
14 * 14 *
@@ -109,29 +109,29 @@ class CronCommand extends Command @@ -109,29 +109,29 @@ class CronCommand extends Command
109 { 109 {
110 try 110 try
111 { 111 {
112 - $r = file_get_contents($this->getApplication()->getKernel()->getContainer()->get('router')  
113 - ->generate("cocar_$task", array(), true)); 112 + #$r = file_get_contents($this->getApplication()->getKernel()->getContainer()->get('router')
  113 + # ->generate("cocar_$task", array(), true));
114 114
115 - /* 115 +
116 if($task == 'monitor') 116 if($task == 'monitor')
117 - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/monitor"); 117 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/monitor");
118 elseif($task == 'status') 118 elseif($task == 'status')
119 - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/status"); 119 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/status");
120 elseif($task == 'reliability') 120 elseif($task == 'reliability')
121 - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/reliability"); 121 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/reliability");
122 elseif($task == 'rrdlog') 122 elseif($task == 'rrdlog')
123 - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/rrdlog"); 123 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/rrdlog");
124 elseif($task == 'dailyperform') 124 elseif($task == 'dailyperform')
125 - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/dailyperform"); 125 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/dailyperform");
126 elseif($task == 'generatealarm') 126 elseif($task == 'generatealarm')
127 - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/generatealarm"); 127 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/generatealarm");
128 elseif($task == 'endalarm') 128 elseif($task == 'endalarm')
129 - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/endalarm"); 129 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/endalarm");
130 elseif($task == 'graphdailyperform') 130 elseif($task == 'graphdailyperform')
131 - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/graphdailyperform"); 131 + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/graphdailyperform");
132 elseif($task == 'printer') 132 elseif($task == 'printer')
133 - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/totalizer/info");  
134 - */ 133 + $this->getContainer()->get('printer')->totalizer();
  134 +
135 } 135 }
136 catch(Exception $e) 136 catch(Exception $e)
137 { 137 {
Controller/PrinterController.php
@@ -15,6 +15,8 @@ use Swpb\Bundle\CocarBundle\Entity\Printer; @@ -15,6 +15,8 @@ use Swpb\Bundle\CocarBundle\Entity\Printer;
15 use Swpb\Bundle\CocarBundle\Entity\PrinterCounter; 15 use Swpb\Bundle\CocarBundle\Entity\PrinterCounter;
16 use Swpb\Bundle\CocarBundle\Form\PrinterType; 16 use Swpb\Bundle\CocarBundle\Form\PrinterType;
17 17
  18 +use Doctrine\ORM\EntityManager;
  19 +
18 /** 20 /**
19 * Printer controller. 21 * Printer controller.
20 * 22 *
@@ -23,6 +25,13 @@ use Swpb\Bundle\CocarBundle\Form\PrinterType; @@ -23,6 +25,13 @@ use Swpb\Bundle\CocarBundle\Form\PrinterType;
23 class PrinterController extends Controller 25 class PrinterController extends Controller
24 { 26 {
25 27
  28 + private $em;
  29 +
  30 + public function __construct(EntityManager $em = null)
  31 + {
  32 + $this->em = $em;
  33 + }
  34 +
26 /** 35 /**
27 * Lists all Printer entities. 36 * Lists all Printer entities.
28 * 37 *
@@ -377,15 +386,9 @@ class PrinterController extends Controller @@ -377,15 +386,9 @@ class PrinterController extends Controller
377 ->getForm(); 386 ->getForm();
378 } 387 }
379 388
380 - /**  
381 - * @Route("/totalizer/info", name="cocar_printer")  
382 - * @Template()  
383 - */  
384 - public function totalizerAction() 389 + public function totalizer()
385 { 390 {
386 - $em = $this->getDoctrine()->getManager();  
387 -  
388 - $printers = $em->getRepository('CocarBundle:Printer')->findAll(); 391 + $printers = $this->em->getRepository('CocarBundle:Printer')->findAll();
389 392
390 foreach($printers as $printer) 393 foreach($printers as $printer)
391 { 394 {
@@ -395,16 +398,16 @@ class PrinterController extends Controller @@ -395,16 +398,16 @@ class PrinterController extends Controller
395 $host = $printer->getHost(); 398 $host = $printer->getHost();
396 399
397 $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1"; 400 $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1";
398 - 401 + $this->updateCounter($printer, '122');
399 if($outPut = shell_exec($com)) 402 if($outPut = shell_exec($com))
400 { 403 {
401 $this->updateCounter($printer, $outPut); 404 $this->updateCounter($printer, $outPut);
402 - $this->createOrUpdateGraph($printer, $outPut); 405 + #$this->createOrUpdateGraph($printer, $outPut);
403 } 406 }
404 } 407 }
405 catch(Exception $e) 408 catch(Exception $e)
406 { 409 {
407 - return new Response($e->getMessage()); 410 + #return new Response($e->getMessage());
408 } 411 }
409 } 412 }
410 return new Response(); 413 return new Response();
@@ -417,16 +420,14 @@ class PrinterController extends Controller @@ -417,16 +420,14 @@ class PrinterController extends Controller
417 { 420 {
418 try 421 try
419 { 422 {
420 - $em = $this->getDoctrine()->getManager();  
421 -  
422 $counter = new PrinterCounter; 423 $counter = new PrinterCounter;
423 424
424 $counter->setPrinter($printer); 425 $counter->setPrinter($printer);
425 $counter->setPrints($prints); 426 $counter->setPrints($prints);
426 $counter->setDate(time()); 427 $counter->setDate(time());
427 428
428 - $em->persist($counter);  
429 - $em->flush(); 429 + $this->em->persist($counter);
  430 + $this->em->flush();
430 } 431 }
431 catch(\Exception $e) 432 catch(\Exception $e)
432 { 433 {
Resources/config/services.yml
@@ -14,3 +14,6 @@ services: @@ -14,3 +14,6 @@ services:
14 class: Swpb\Bundle\CocarBundle\Controller\MonitorController 14 class: Swpb\Bundle\CocarBundle\Controller\MonitorController
15 circuit: 15 circuit:
16 class: Swpb\Bundle\CocarBundle\Entity\Circuits 16 class: Swpb\Bundle\CocarBundle\Entity\Circuits
  17 + printer:
  18 + class: Swpb\Bundle\CocarBundle\Controller\PrinterController
  19 + arguments: ["@doctrine.orm.entity_manager"]
17 \ No newline at end of file 20 \ No newline at end of file
1 -30 06 * * * php /var/www/cocar/app/console perform:task --graphdailyperform  
2 -0 06 * * * php /var/www/cocar/app/console perform:task --rrdlog  
3 -0 5 * * * php /var/www/cocar/app/console perform:task --dailyperform  
4 -*/5 * * * * php /var/www/cocar/app/console perform:task --reliability 1 +30 06 * * * php /srv/gerente/app/console perform:task --graphdailyperform
  2 +0 06 * * * php /srv/gerente/app/console perform:task --rrdlog
  3 +0 5 * * * php /srv/gerente/app/console perform:task --dailyperform
  4 +*/5 * * * * php /srv/gerente/app/console perform:task --reliability
5 0,5,10,15,20,25,30,35,40,45,50,55 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --generatealarm 5 0,5,10,15,20,25,30,35,40,45,50,55 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --generatealarm
6 -0 20 * * * php /var/www/cocar/app/console perform:task --endalarm 6 +0 20 * * * php /srv/gerente/app/console perform:task --endalarm
7 1,6,11,16,21,26,31,36,41,46,51,56 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --status 7 1,6,11,16,21,26,31,36,41,46,51,56 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --status
8 -* * * * * php /var/www/cocar/app/console perform:task --monitor  
9 -0 20 * * * php /var/www/cocar/app/console perform:task --printer  
10 \ No newline at end of file 8 \ No newline at end of file
  9 +* * * * * php /srv/gerente/app/console perform:task --monitor
  10 +0 20 * * * php /srv/gerente/app/console perform:task --printer
11 \ No newline at end of file 11 \ No newline at end of file