Ejemplo n.º 1
0
 private function translate(Event $event)
 {
     $translations = $this->getDoctrine()->getRepository('BauerIncidentDashboardCoreBundle:Translation')->findBy(array('project' => $event->getEventIdentifier()->getProject()));
     foreach ($translations as $translation) {
         if (preg_match('^' . $translation->getIdentifier() . '^', $event->getEventIdentifier()->getIdentifier())) {
             return $translation->translate($event);
         }
     }
     return $event;
 }
Ejemplo n.º 2
0
 private static function notify(Router $router, EntityManager $doctrineManager, Event $event)
 {
     $configs = $doctrineManager->getRepository('KoalamonNotificationEngineBundle:NotificationConfiguration')->findBy(['project' => $event->getEventIdentifier()->getProject()]);
     /** @var NotificationConfiguration[] $configs */
     foreach ($configs as $config) {
         if ($config->isNotifyAll() || $config->isConnectedTool($event->getEventIdentifier()->getTool())) {
             $sender = SenderFactory::getSender($config->getSenderType());
             $sender->init($router, $config->getOptions());
             $sender->send($event);
         }
     }
 }
 public function closeAction(Event $event)
 {
     $closeEvent = new Event();
     $closeEvent->setIdentifier($event->getIdentifier());
     $closeEvent->setSystem($event->getSystem());
     $closeEvent->setStatus('success');
     $closeEvent->setMessage('manually closed');
     $em = $this->getDoctrine()->getEntityManager();
     $em->persist($closeEvent);
     $em->flush();
     return $this->redirect($this->generateUrl("bauer_incident_dashboard_core_admin"));
 }
 /**
  * @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);
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $em = $this->getContainer()->get('doctrine')->getManager();
     $tools = $em->getRepository('BauerIncidentDashboardCoreBundle:Tool')->findBy(["active" => true]);
     foreach ($tools as $tool) {
         if (!is_null($tool->getInterval()) && $tool->getInterval() != 0) {
             $eventIdentifier = $em->getRepository('BauerIncidentDashboardCoreBundle:EventIdentifier')->findOneBy(["project" => $tool->getProject(), "tool" => $tool], ['lastEvent' => 'desc']);
             if (is_null($eventIdentifier)) {
                 continue;
             }
             $event = $eventIdentifier->getLastEvent();
             $interval = $tool->getInterval() + 1;
             $now = new \DateTime();
             $lastEventLimit = $now->sub(new \DateInterval("PT" . $interval . "M"));
             $newEvent = new Event();
             $identifierString = 'koalamon_tool_intervalcheck_' . $tool->getIdentifier();
             $identifier = $em->getRepository('BauerIncidentDashboardCoreBundle:EventIdentifier')->findOneBy(array("project" => $tool->getProject(), "identifier" => $identifierString));
             if (is_null($identifier)) {
                 $identifier = new EventIdentifier();
                 $identifier->setProject($tool->getProject());
                 $identifier->setIdentifier($identifierString);
                 $em->persist($identifier);
                 $em->flush();
             }
             $newEvent->setEventIdentifier($identifier);
             $newEvent->setSystem('Koalamon');
             $newEvent->setType('koalamon_intervalcheck');
             $newEvent->setUnique(false);
             if ($event->getCreated() < $lastEventLimit) {
                 $newEvent->setStatus(Event::STATUS_FAILURE);
                 $message = "The tool '" . $tool->getName() . "' did not send any events since " . $event->getCreated()->format("d.m.Y H:i:m") . ".";
                 $newEvent->setMessage($message);
                 $output->writeln("project_id: " . $event->getEventIdentifier()->getProject()->getId() . " -- " . $message);
             } else {
                 $newEvent->setStatus(Event::STATUS_SUCCESS);
                 $newEvent->setMessage("");
             }
             ProjectHelper::addEvent($this->getContainer()->get("Router"), $em, $newEvent);
         }
     }
 }
 public function closeAction(Event $event)
 {
     $this->assertUserRights(UserRole::ROLE_COLLABORATOR);
     $closeEvent = new Event();
     $closeEvent->setEventIdentifier($event->getEventIdentifier());
     $closeEvent->setSystem($event->getSystem());
     $closeEvent->setStatus(Event::STATUS_SUCCESS);
     $closeEvent->setIsStatusChange(true);
     $closeEvent->setUnique($event->isUnique());
     $closeEvent->setType($event->getType());
     $closeEvent->setMessage('Manually closed by ' . $this->getUser()->getUsername() . '.');
     ProjectHelper::addEvent($this->get("Router"), $this->getDoctrine()->getEntityManager(), $closeEvent);
     return $this->redirect($this->generateUrl("bauer_incident_dashboard_core_homepage", array("project" => $event->getEventIdentifier()->getProject()->getIdentifier())));
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
 public function translate(Event $event)
 {
     if (!is_null($this->getUrl())) {
         $event->setUrl($this->getUrl());
     }
     if (!is_null($this->getType())) {
         $event->setType($this->getType());
     }
     if (!is_null($this > $this->getSystem())) {
         $event->setSystem($this->getSystem());
     }
     if (!is_null($this->getMessage())) {
         $event->setMessage($this->getMessage());
     }
     return $event;
 }
 public function jenkinsAction()
 {
     $rawContent = file_get_contents('php://input');
     $newEvent = json_decode($rawContent);
     file_put_contents("/tmp/jenkins.log", json_encode($newEvent));
     $event = new Event();
     if ($newEvent->build->status == "SUCCESS") {
         $status = "success";
         $message = "";
     } else {
         $status = "failure";
         $message = $this->getMessage($newEvent->name, "Jenkins \"" . $newEvent->name . "\" failed");
     }
     $event->setMessage($message);
     $event->setStatus($status);
     $event->setSystem($this->translate($newEvent->name));
     $event->setIdentifier($newEvent->name);
     $event->setUrl($newEvent->build->full_url);
     $this->storeEvent($event);
     return new JsonResponse(array('success' => true));
 }