|
@@ -1,179 +0,0 @@
|
|
|
-<?php
|
|
|
-
|
|
|
-namespace FiberlinkBundle\Command;
|
|
|
-
|
|
|
-use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
|
|
|
-use Symfony\Component\Console\Input\InputOption;
|
|
|
-use Symfony\Component\Console\Input\InputInterface;
|
|
|
-use Symfony\Component\Console\Output\OutputInterface;
|
|
|
-
|
|
|
-abstract class BaseCommand extends ContainerAwareCommand
|
|
|
-{
|
|
|
- /**
|
|
|
- * @var CollectorInterface
|
|
|
- */
|
|
|
- protected $collector;
|
|
|
-
|
|
|
- /**
|
|
|
- * @var string
|
|
|
- */
|
|
|
- protected $pathLock = "/var/run/flowdat3/stats";
|
|
|
-
|
|
|
- protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
- {
|
|
|
- $this->output = $output;
|
|
|
- $this->setCollector();
|
|
|
-
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- protected function setCollector()
|
|
|
- {
|
|
|
- $this->collector = $this->getContainer()->get("redis");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param string $key
|
|
|
- * @return array
|
|
|
- */
|
|
|
- protected function getData($key, $output = false)
|
|
|
- {
|
|
|
- return $this->collector->get($key, $output);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param string $key
|
|
|
- * @param array $data
|
|
|
- */
|
|
|
- protected function setData($key, $data, $output = false)
|
|
|
- {
|
|
|
- $this->collector->set($key, $data, $output);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param string $key
|
|
|
- * @param string $data
|
|
|
- */
|
|
|
- protected function getString($key, $output = false)
|
|
|
- {
|
|
|
- return $this->collector->getString($key, $output);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param array $queries
|
|
|
- * @return
|
|
|
- */
|
|
|
- protected function executeQueries($queries)
|
|
|
- {
|
|
|
- $result = null;
|
|
|
- $conn = $this->getContainer()->get('database_connection');
|
|
|
- foreach ($queries as $query)
|
|
|
- {
|
|
|
- $result = $conn->query($query);
|
|
|
- }
|
|
|
- $conn->close();
|
|
|
-
|
|
|
- return $result;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param string $flag
|
|
|
- * @return boolean
|
|
|
- *
|
|
|
- * Description: Retorna true si existe el bloqueo. False si no existe bloqueo o no puede determinar la existencia.
|
|
|
- */
|
|
|
-
|
|
|
- protected function lock($flag) {
|
|
|
-
|
|
|
- $mypid = getmypid();
|
|
|
- $file = $this->pathLock. "/" . $flag;
|
|
|
-
|
|
|
- if (!is_dir($this->pathLock)) {mkdir($this->pathLock, 0777, true);}
|
|
|
-
|
|
|
- if (is_null($flag)) return false;
|
|
|
-
|
|
|
- if (file_exists($file)) {
|
|
|
-
|
|
|
- $handle = fopen($file, "r");
|
|
|
- $contenido = fread($handle, filesize($file));
|
|
|
- fclose($handle);
|
|
|
- $data = explode("\n", $contenido);
|
|
|
-
|
|
|
- if(count($data) == 2) {
|
|
|
- if (isset($data[0]) && isset($data[1])) {
|
|
|
-
|
|
|
- $pid = explode("=",$data[0]);
|
|
|
- $time = explode("=",$data[1]);
|
|
|
-
|
|
|
- $pid_flag = (int) $pid[1];
|
|
|
- $time_flag = (int) $time[1];
|
|
|
-
|
|
|
- if (posix_kill($pid_flag, 0)) {
|
|
|
- $now = time();
|
|
|
- $lapse = $now - $time_flag;
|
|
|
-
|
|
|
- $limit_time = 60 * 15;
|
|
|
- if($lapse > $limit_time) {
|
|
|
- print_r("Superado 15 min de ejecución, finalizamos proceso anterior(pid: {$pid_flag}).".PHP_EOL);
|
|
|
- if (posix_kill($pid_flag, 9)) {
|
|
|
- print_r("Finalizado con éxito".PHP_EOL);
|
|
|
- } else {
|
|
|
- print_r("Ocurrió un problema, no pudo finalizarse el proceso".PHP_EOL);
|
|
|
- }
|
|
|
- } else {
|
|
|
- print_r("Esperamos el proceso anterior(pid: {$pid_flag}) a que finalice. Tiempo actual de ejecución: {$lapse} segundos.".PHP_EOL);
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- @unlink($file);
|
|
|
- }
|
|
|
-
|
|
|
- $time = time();
|
|
|
- $data = "pid={$mypid}\ntime={$time}";
|
|
|
- $handle = fopen($file, "w+");
|
|
|
- fwrite($handle, $data);
|
|
|
- fclose($handle);
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param string $flag
|
|
|
- * @return boolean
|
|
|
- *
|
|
|
- * Description: Retorna true si pudo borrarse el archivo de bloqueo. False en cualquier otro caso.
|
|
|
- */
|
|
|
-
|
|
|
- protected function removeLock($flag) {
|
|
|
-
|
|
|
- if (is_null($flag)) return false;
|
|
|
-
|
|
|
- $file = $this->pathLock . "/" . $flag;
|
|
|
- unlink($file);
|
|
|
-
|
|
|
- if(!file_exists($file)) return true;
|
|
|
-
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- *
|
|
|
- * @param string $v
|
|
|
- * @return array
|
|
|
- *
|
|
|
- * Description: Retorna el tipo de valor y el valor mismo de una respuesta SNMP para Octets
|
|
|
- */
|
|
|
- protected function parseSnmpOctetsValue($v) {
|
|
|
-
|
|
|
- if( $v == '""' || $v == '' ) return array();
|
|
|
-
|
|
|
- $type = substr( $v, 0, strpos( $v, ':' ) );
|
|
|
- $value = trim( substr( $v, strpos( $v, ':' ) + 1 ) );
|
|
|
-
|
|
|
- return array(0=>$type,1=>(int)$value);
|
|
|
- }
|
|
|
-}
|