/**
  * Dashboard of Bacula Clients
  * 
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @return Render Twig template
  */
 public function dashboardAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $defaultDefinitions = new DefaultDefinitions();
     $dtNow = new \DateTime('NOW');
     $dt24hours = new \DateTime('NOW');
     $last24hours = new \DateInterval('PT24H');
     $dt24hours->sub($last24hours);
     // get date/time of last 24 hours
     // Get parameters
     $dtIni = $request->query->get('dt_ini', $dt24hours);
     $dtEnd = $request->query->get('dt_end', $dtNow);
     if (!$dtIni instanceof \DateTime) {
         $dtIni = \DateTime::createFromFormat($this->container->getParameter('date_format_php'), $dtIni);
     }
     if (!$dtEnd instanceof \DateTime) {
         $dtEnd = \DateTime::createFromFormat($this->container->getParameter('date_format_php'), $dtEnd);
     }
     $clientRepository = $this->getDoctrine()->getRepository('BaculaStatusBundle:Client');
     $jobRepository = $em->getRepository('BaculaStatusBundle:Job');
     /*
      * ------ Search data for populating the charts ------
      */
     // Get total jobs by client
     $totalJobClient = $jobRepository->getTotalJobsOfClientPeriod($dtIni, $dtEnd);
     foreach ($totalJobClient as $dataTmp) {
         $dataGraphJobClient[] = array(stream_get_contents($dataTmp['name'], -1, 0), (int) $dataTmp['total']);
         $graphJob[] = array('label' => stream_get_contents($dataTmp['name'], -1, 0), 'value' => (int) $dataTmp['total']);
     }
     // Get total files by client
     $totalFilesClient = $jobRepository->getTotalFilesOfClientPeriod($dtIni, $dtEnd);
     foreach ($totalFilesClient as $dataTmp) {
         $dataGraphFileClient[] = array(stream_get_contents($dataTmp['name'], -1, 0), (int) $dataTmp['total']);
         $graphFiles[] = array('label' => stream_get_contents($dataTmp['name'], -1, 0), 'value' => (int) $dataTmp['total']);
     }
     // Get total bytes by client
     $totalBytesClient = $jobRepository->getTotalBytesOfClientPeriod($dtIni, $dtEnd);
     foreach ($totalBytesClient as $dataTmp) {
         $dataGraphBytesClient[] = array(stream_get_contents($dataTmp['name'], -1, 0), (int) $dataTmp['total']);
         $graphSize[] = array('label' => stream_get_contents($dataTmp['name'], -1, 0), 'value' => (int) $dataTmp['total'], 'formatted' => $defaultDefinitions->formatSize($dataTmp['total']));
     }
     return $this->render('BaculaStatusBundle:Client:dashboard.html.twig', array('dt_ini' => $dtIni->format($this->container->getParameter('date_format_php')), 'dt_end' => $dtEnd->format($this->container->getParameter('date_format_php')), 'graphJob' => $graphJob, 'graphFiles' => $graphFiles, 'graphSize' => $graphSize, 'dataGraphJobClient' => json_encode($dataGraphJobClient, JSON_NUMERIC_CHECK), 'dataGraphFileClient' => json_encode($dataGraphFileClient, JSON_NUMERIC_CHECK), 'dataGraphBytesClient' => json_encode($dataGraphBytesClient, JSON_NUMERIC_CHECK)));
 }
 public function listPoolsAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $defaultDefinitions = new DefaultDefinitions();
     $poolRepository = $em->getRepository('BaculaStatusBundle:Pool');
     $mediaRepository = $em->getRepository('BaculaStatusBundle:Media');
     $listPools = $poolRepository->findAll();
     //var_dump($listPools);
     $data = array();
     foreach ($listPools as $pool) {
         $listMedia = $mediaRepository->findBy(array('poolId' => $pool->getPoolId()));
         $dataPool = NULL;
         $dataMedia = NULL;
         if (count($listMedia) > 0) {
             $dataPool['id'] = $pool->getPoolId();
             $dataPool['name'] = $pool->getName();
             $dataMediaTmp = array();
             foreach ($listMedia as $media) {
                 // Get color by status to display in the list
                 $status = $media->getVolStatus();
                 if ($status == "Used") {
                     $statusColor = "label label-warning";
                 } elseif ($status == "Append") {
                     $statusColor = "label label-success";
                 } elseif ($status == "Error") {
                     $statusColor = "label label-danger";
                 } elseif ($status == "Full") {
                     $statusColor = "label label-primary";
                 } else {
                     $statusColor = "label label-default";
                 }
                 $maxVolBytes = $media->getMaxVolBytes();
                 $volBytes = $media->getVolBytes();
                 // Max vol bytes not set
                 if ($maxVolBytes == 0) {
                     $maxVolBytes = $volBytes;
                 }
                 $percent = 0;
                 // Default
                 if ($volBytes > 0) {
                     $percent = floor($volBytes / $maxVolBytes * 100);
                 }
                 $dataMedia['id'] = $media->getMediaId();
                 $dataMedia['name'] = $media->getVolumeName();
                 $dataMedia['status'] = $status;
                 $dataMedia['statusColor'] = $statusColor;
                 $dataMedia['type'] = $media->getMediaType();
                 $dataMedia['size'] = $defaultDefinitions->formatSize($media->getVolBytes());
                 $dataMedia['percent'] = $percent;
                 $dataMedia['jobs'] = $media->getVolJobs();
                 $dataMedia['useDuration'] = $defaultDefinitions->formatTimeStamp($media->getVolUseDuration());
                 $dataMedia['retention'] = $defaultDefinitions->formatTimeStamp($media->getVolRetention());
                 // Use date format 'Y-m-d h:i' to sorter correctly
                 $dataMedia['lastWritten'] = $media->getLastWritten()->format($this->container->getParameter('date_format_php'));
                 //$media->getLastWritten()->format($this->container->getParameter('date_format'));
                 $dataMediaTmp[] = $dataMedia;
             }
             $dataPool['media'] = $dataMediaTmp;
             $data[] = $dataPool;
             //echo stream_get_contents($pool->getName(), -1, 0) . " " . count($listMedia) . "<br />";
         }
     }
     //\Doctrine\Common\Util\Debug::dump($data);
     //var_dump($data);
     return $this->render('BaculaStatusBundle:Pool:listPools.html.twig', array('listPools' => $data));
 }
예제 #3
0
 /**
  * Display job details
  * 
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param integer $jobId
  * @return Render twig template
  */
 public function displayJobAction(Request $request, $jobId)
 {
     $em = $this->getDoctrine()->getManager();
     $defaultDefinitions = new DefaultDefinitions();
     $jobRepository = $em->getRepository('BaculaStatusBundle:Job');
     $logRepository = $em->getRepository('BaculaStatusBundle:Log');
     $clientRepository = $em->getRepository('BaculaStatusBundle:Client');
     $poolRepository = $em->getRepository('BaculaStatusBundle:Pool');
     $fileRepository = $em->getRepository('BaculaStatusBundle:File');
     $job = $jobRepository->find($jobId);
     $log = $logRepository->displayLogByJob($jobId);
     $client = $clientRepository->find($job->getClientId());
     $pool = $poolRepository->find($job->getPoolId());
     $files = $fileRepository->listFilesOfJob($jobId);
     $dataJob['jobId'] = $job->getJobId();
     $dataJob['name'] = $job->getName();
     $dataJob['client'] = $client->getName();
     if ($pool instanceof \Bacula\StatusBundle\Entity\Pool) {
         $dataJob['pool'] = $pool->getName();
     } else {
         $dataJob['pool'] = '--';
     }
     $dataJob['startTime'] = $job->getStartTime()->format($this->container->getParameter('date_format_php'));
     $dataJob['endTime'] = $job->getEndTime()->format($this->container->getParameter('date_format_php'));
     $dtIni = $job->getStartTime();
     $dtEnd = $job->getEndTime();
     $intervalTotalTime = $dtEnd->diff($dtIni);
     $totalTime = $intervalTotalTime->format("%dd %H:%I");
     $dataJob['totalTime'] = $totalTime;
     $dataJob['class'] = $defaultDefinitions->getJobTypeIcon($job->getJobStatus());
     $dataJob['status'] = $defaultDefinitions->getJobStatus($job->getJobStatus());
     $dataJob['level'] = $defaultDefinitions->getJobLevel($job->getLevel());
     $dataJob['files'] = number_format($job->getJobFiles());
     $bytes = $job->getJobBytes();
     $totalSize = $defaultDefinitions->formatSize($bytes);
     $dataJob['size'] = $totalSize;
     return $this->render('BaculaStatusBundle:Job:displayJob.html.twig', array('job' => $dataJob, 'logJob' => $log, 'listFiles' => $files));
 }
 public function indexAction()
 {
     $em = $this->getDoctrine()->getManager();
     $defaultDefinitions = new DefaultDefinitions();
     $jobRepository = $em->getRepository('BaculaStatusBundle:Job');
     // ----------------------------------------------------------------------
     //
     // Shows the current status of bacula
     //
     // ----------------------------------------------------------------------
     $dtNow = new \DateTime('NOW');
     $dtIni = new \DateTime('NOW');
     $dtIniTrb = new \DateInterval('P7D');
     $dtIni->sub($dtIniTrb);
     $dt24hours = new \DateTime('NOW');
     $last24hours = new \DateInterval('PT24H');
     $dt24hours->sub($last24hours);
     // get date/time of last 24 hours
     //
     // Total by status
     $running = $jobRepository->getTotalByStatusPeriod('R', $dtIni, $dtNow);
     $cancelled = $jobRepository->getTotalByStatusPeriod('A', $dt24hours, $dtNow);
     $success = $jobRepository->getTotalByStatusPeriod('T', $dt24hours, $dtNow);
     $errorTmp = $jobRepository->getTotalByStatusPeriod('E', $dt24hours, $dtNow);
     $error = $errorTmp;
     if ($errorTmp > 0) {
         $flagError = 'E';
     }
     $errorTmp = $jobRepository->getTotalByStatusPeriod('e', $dt24hours, $dtNow);
     $error += $errorTmp;
     if ($errorTmp > 0) {
         $flagError = 'e';
     }
     $errorTmp = $jobRepository->getTotalByStatusPeriod('f', $dt24hours, $dtNow);
     $error += $errorTmp;
     if ($errorTmp > 0) {
         $flagError = 'f';
     }
     $listWaiting = array('F', 'S', 'm', 'M', 's', 'j', 'c', 'd', 't', 'p', 'C');
     $waiting = 0;
     $dtIniWaiting = \DateTime::createFromFormat('Y-m-d h:i:s', '0000-00-00 00:00:00');
     foreach ($listWaiting as $st) {
         //echo $st . ' ';
         $waiting += $jobRepository->getTotalByStatusPeriod($st, NULL, NULL);
     }
     // ----------------------------------------------------------------------
     //
     // Get Last 24 hours statistics
     //
     // ----------------------------------------------------------------------
     // ....................................................................
     // Graph total bytes per hour
     // ....................................................................
     $OneHourInterval = new \DateInterval('PT1H');
     $dataGraph24Hours = array();
     $dtTmp24hours = new \DateTime('NOW');
     $dtTmp24hours->sub($last24hours);
     // get date/time of last 24 hours
     while ($dtTmp24hours <= $dtNow) {
         $dtIniTmp = \DateTime::createFromFormat('Y-m-d H:i:s', $dtTmp24hours->format('Y-m-d H:00:00'));
         $dtFimTmp = \DateTime::createFromFormat('Y-m-d H:i:s', $dtTmp24hours->format('Y-m-d H:59:59'));
         $totalBytes = $jobRepository->getTotalJobBytesPeriod($dtIniTmp, $dtFimTmp);
         $graph24Hour[] = array('label' => (string) $dtTmp24hours->format('H:00'), 'value' => $totalBytes, 'formatted' => $defaultDefinitions->formatSize($totalBytes));
         $dtTmp24hours->add($OneHourInterval);
     }
     // ....................................................................
     // Total of files
     // ....................................................................
     $totalFiles = $jobRepository->getTotalJobFilesPeriod($dt24hours, $dtNow);
     // ....................................................................
     // Total of bytes
     // ....................................................................
     $totalBytes = $jobRepository->getTotalJobBytesPeriod($dt24hours, $dtNow);
     // ....................................................................
     // Total Jobs by Pool
     // ....................................................................
     $totalJobsPool = $jobRepository->getJobsByPoolPeriod($dt24hours, $dtNow);
     foreach ($totalJobsPool as $dataTmp) {
         $graphPool[] = array('label' => stream_get_contents($dataTmp['name']), 'value' => $dataTmp['total']);
     }
     $units = array('B', 'KB', 'MB', 'GB', 'TB');
     $base = log($totalBytes) / log(1024);
     $totalSize = round(pow(1024, $base - floor($base)), 2) . ' ' . $units[floor($base)];
     // ----------------------------------------------------------------------
     //
     // Get this month statistcs
     //
     // ----------------------------------------------------------------------
     // ....................................................................
     // Volume bytes per day
     // Graph total bytes per day
     // ....................................................................
     $OneDayInterval = new \DateInterval('P1D');
     $strDtIni = date('Y') . '-' . date('m') . '-01 00:00:00';
     $dtTrb = \DateTime::createFromFormat('Y-m-d H:i:s', $strDtIni);
     $dataTmp = array();
     $dataGraphPerDay = array();
     while ($dtTrb->format('Ymd') <= $dtNow->format('Ymd')) {
         $dtIniTmp = \DateTime::createFromFormat('Y-m-d H:i:s', $dtTrb->format('Y-m-d 00:00:00'));
         $dtFimTmp = \DateTime::createFromFormat('Y-m-d H:i:s', $dtTrb->format('Y-m-d 23:59:59'));
         $totalBytes = $jobRepository->getTotalJobBytesPeriod($dtIniTmp, $dtFimTmp);
         $graphBytesDay[] = array('label' => (string) $dtTrb->format('d'), 'value' => $totalBytes, 'formatted' => $defaultDefinitions->formatSize($totalBytes));
         $dtTrb->add($OneDayInterval);
     }
     // ....................................................................
     // Total bytes stored during by day in the month
     // ....................................................................
     $OneDayInterval = new \DateInterval('P1D');
     $strDtIni = date('Y') . '-' . date('m') . '-01 00:00:00';
     $strStartDate = '1970-' . date('m') . '-01 00:00:00';
     $dtIni = \DateTime::createFromFormat('Y-m-d H:i:s', $strStartDate);
     $dtTrb = \DateTime::createFromFormat('Y-m-d H:i:s', $strDtIni);
     $dataTmp = array();
     $dataGraphStoredPerDay = array();
     while ($dtTrb->format('Ymd') <= $dtNow->format('Ymd')) {
         // $dtIniTmp = \DateTime::createFromFormat('Y-m-d H:i:s', $dtTrb->format('Y-m-d 00:00:00'));
         $dtFimTmp = \DateTime::createFromFormat('Y-m-d H:i:s', $dtTrb->format('Y-m-d 23:59:59'));
         $totalBytes = $jobRepository->getTotalJobBytesPeriod($dtIni, $dtFimTmp);
         $graphTotalStored[] = array('label' => (string) $dtTrb->format('d'), 'value' => $totalBytes, 'formatted' => $defaultDefinitions->formatSize($totalBytes));
         $dtTrb->add($OneDayInterval);
     }
     return $this->render('BaculaStatusBundle:Default:index.html.twig', array('running' => $running, 'success' => $success, 'cancelled' => $cancelled, 'error' => $error, 'waiting' => $waiting, 'flagError' => $flagError, 'graph24Hour' => json_encode($graph24Hour, JSON_NUMERIC_CHECK), 'graphPool' => json_encode($graphPool, JSON_NUMERIC_CHECK), 'graphBytesDay' => json_encode($graphBytesDay, JSON_NUMERIC_CHECK), 'graphTotalStored' => json_encode($graphTotalStored, JSON_NUMERIC_CHECK), 'totalFiles' => $totalFiles, 'totalSize' => $totalSize));
 }