/**
  * @param Event $event
  * @return JsonResponse
  */
 public function dayAction(Event $event)
 {
     $events = $this->getDoctrine()->getRepository('BauerIncidentDashboardCoreBundle:Event')->findByRange($event->getEventIdentifier()->getIdentifier(), new \DateTime("- 1 day"));
     $stats = array(Event::STATUS_SUCCESS => array(), Event::STATUS_FAILURE => array());
     foreach ($events as $event) {
         $hour = $event->getCreated()->format('G');
         if (array_key_exists($hour, $stats[$event->getStatus()])) {
             $stats[$event->getStatus()][(int) $hour] = $stats[$event->getStatus()][(int) $hour] + 1;
         } else {
             $stats[$event->getStatus()][(int) $hour] = 1;
         }
     }
     $data = [['Status', 'Failure', 'Success', ['role' => 'annotation']]];
     $currentHour = date('G');
     for ($i = 24; $i > 0; $i--) {
         $theHour = ($currentHour + 24 - $i) % 24 + 1;
         $amPmHour = DateHelper::toAmPm($theHour);
         if ($theHour == 24) {
             $theHour = 0;
         }
         if (!array_key_exists($theHour, $stats[Event::STATUS_FAILURE])) {
             $stats[Event::STATUS_FAILURE][$theHour] = 0;
         }
         if (!array_key_exists($theHour, $stats[Event::STATUS_SUCCESS])) {
             $stats[Event::STATUS_SUCCESS][$theHour] = 0;
         }
         $data[] = array($amPmHour, $stats[Event::STATUS_FAILURE][$theHour], $stats[Event::STATUS_SUCCESS][$theHour], '');
     }
     return new JsonResponse($data);
 }
Ejemplo n.º 2
0
 /**
  * Sends a message to slack created by information given in the event.
  *
  * @param Event $event
  */
 public function send(Event $event)
 {
     $client = new \Maknz\Slack\Client($this->webhookURL, $this->settings);
     $gotoUrl = "<" . $this->router->generate("bauer_incident_dashboard_core_homepage", array('project' => $event->getEventIdentifier()->getProject()->getIdentifier()), true) . "|Go to www.koalamon.com>";
     if ($event->hasUrl()) {
         $gotoUrl .= "\n<" . $event->getUrl() . "|Go to " . $event->getEventIdentifier()->getTool()->getName() . ">";
     }
     if ($event->getStatus() == Event::STATUS_SUCCESS) {
         $color = self::COLOR_SUCCESS;
         $label = "Your test succeeded (" . $event->getSystem() . ")\nIdentifier: " . $event->getEventIdentifier()->getIdentifier() . ")";
         $message = "";
     } else {
         $color = self::COLOR_FAILURE;
         $label = "Your test failed (" . $event->getSystem() . ") \nIdentifier: " . $event->getEventIdentifier()->getIdentifier() . "";
         $message = $this->slackifyText($event->getMessage()) . "\n";
     }
     $client->enableMarkdown()->attach(['text' => $message . $gotoUrl, 'color' => $color])->send($label);
 }