diff --git a/Command/CronCommand.php b/Command/CronCommand.php index 473ee1b..38dc6c7 100755 --- a/Command/CronCommand.php +++ b/Command/CronCommand.php @@ -2,13 +2,13 @@ namespace Swpb\Bundle\CocarBundle\Command; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; -class CronCommand extends Command +class CronCommand extends ContainerAwareCommand { /** * @@ -109,29 +109,29 @@ class CronCommand extends Command { try { - $r = file_get_contents($this->getApplication()->getKernel()->getContainer()->get('router') - ->generate("cocar_$task", array(), true)); + #$r = file_get_contents($this->getApplication()->getKernel()->getContainer()->get('router') + # ->generate("cocar_$task", array(), true)); - /* + if($task == 'monitor') - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/monitor"); + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/monitor"); elseif($task == 'status') - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/status"); + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/status"); elseif($task == 'reliability') - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/reliability"); + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/reliability"); elseif($task == 'rrdlog') - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/rrdlog"); + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/rrdlog"); elseif($task == 'dailyperform') - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/dailyperform"); + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/dailyperform"); elseif($task == 'generatealarm') - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/generatealarm"); + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/generatealarm"); elseif($task == 'endalarm') - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/endalarm"); + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/endalarm"); elseif($task == 'graphdailyperform') - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/graphdailyperform"); + file_get_contents("http://localhost/cocar/web/app_dev.php/cocar/graphdailyperform"); elseif($task == 'printer') - file_get_contents("http://localhost/projeto-cocar/web/app_dev.php/cocar/totalizer/info"); - */ + $this->getContainer()->get('printer')->totalizer(); + } catch(Exception $e) { diff --git a/Controller/PrinterController.php b/Controller/PrinterController.php index 1a2752c..6c57209 100755 --- a/Controller/PrinterController.php +++ b/Controller/PrinterController.php @@ -15,6 +15,8 @@ use Swpb\Bundle\CocarBundle\Entity\Printer; use Swpb\Bundle\CocarBundle\Entity\PrinterCounter; use Swpb\Bundle\CocarBundle\Form\PrinterType; +use Doctrine\ORM\EntityManager; + /** * Printer controller. * @@ -23,6 +25,13 @@ use Swpb\Bundle\CocarBundle\Form\PrinterType; class PrinterController extends Controller { + private $em; + + public function __construct(EntityManager $em = null) + { + $this->em = $em; + } + /** * Lists all Printer entities. * @@ -377,15 +386,9 @@ class PrinterController extends Controller ->getForm(); } - /** - * @Route("/totalizer/info", name="cocar_printer") - * @Template() - */ - public function totalizerAction() + public function totalizer() { - $em = $this->getDoctrine()->getManager(); - - $printers = $em->getRepository('CocarBundle:Printer')->findAll(); + $printers = $this->em->getRepository('CocarBundle:Printer')->findAll(); foreach($printers as $printer) { @@ -395,16 +398,16 @@ class PrinterController extends Controller $host = $printer->getHost(); $com = "snmpwalk -O qv -v 1 -c $community $host 1.3.6.1.2.1.43.10.2.1.4.1.1"; - + $this->updateCounter($printer, '122'); if($outPut = shell_exec($com)) { $this->updateCounter($printer, $outPut); - $this->createOrUpdateGraph($printer, $outPut); + #$this->createOrUpdateGraph($printer, $outPut); } } catch(Exception $e) { - return new Response($e->getMessage()); + #return new Response($e->getMessage()); } } return new Response(); @@ -417,16 +420,14 @@ class PrinterController extends Controller { try { - $em = $this->getDoctrine()->getManager(); - $counter = new PrinterCounter; $counter->setPrinter($printer); $counter->setPrints($prints); $counter->setDate(time()); - $em->persist($counter); - $em->flush(); + $this->em->persist($counter); + $this->em->flush(); } catch(\Exception $e) { diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 6bbe0d9..a5fa6af 100755 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -14,3 +14,6 @@ services: class: Swpb\Bundle\CocarBundle\Controller\MonitorController circuit: class: Swpb\Bundle\CocarBundle\Entity\Circuits + printer: + class: Swpb\Bundle\CocarBundle\Controller\PrinterController + arguments: ["@doctrine.orm.entity_manager"] \ No newline at end of file diff --git a/schedules.txt b/schedules.txt index 0173f1b..b2e98de 100755 --- a/schedules.txt +++ b/schedules.txt @@ -1,9 +1,9 @@ -30 06 * * * php /var/www/cocar/app/console perform:task --graphdailyperform -0 06 * * * php /var/www/cocar/app/console perform:task --rrdlog -0 5 * * * php /var/www/cocar/app/console perform:task --dailyperform -*/5 * * * * php /var/www/cocar/app/console perform:task --reliability +30 06 * * * php /srv/gerente/app/console perform:task --graphdailyperform +0 06 * * * php /srv/gerente/app/console perform:task --rrdlog +0 5 * * * php /srv/gerente/app/console perform:task --dailyperform +*/5 * * * * php /srv/gerente/app/console perform:task --reliability 0,5,10,15,20,25,30,35,40,45,50,55 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --generatealarm -0 20 * * * php /var/www/cocar/app/console perform:task --endalarm +0 20 * * * php /srv/gerente/app/console perform:task --endalarm 1,6,11,16,21,26,31,36,41,46,51,56 7-19 * * * php /var/www/projeto-cocar/app/console perform:task --status -* * * * * php /var/www/cocar/app/console perform:task --monitor -0 20 * * * php /var/www/cocar/app/console perform:task --printer \ No newline at end of file +* * * * * php /srv/gerente/app/console perform:task --monitor +0 20 * * * php /srv/gerente/app/console perform:task --printer \ No newline at end of file -- libgit2 0.21.2