/**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     if ($command->template) {
         $command->message = $this->parseIncidentTemplate($command->template, $command->template_vars);
     }
     $data = ['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible];
     // Link with the component.
     if ($command->component_id) {
         $data['component_id'] = $command->component_id;
     }
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = $this->dates->createNormalized('d/m/Y H:i', $command->incident_date);
         $data['created_at'] = $incidentDate;
         $data['updated_at'] = $incidentDate;
     }
     // Create the incident
     $incident = Incident::create($data);
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     $incident->notify = (bool) $command->notify;
     event(new IncidentWasReportedEvent($incident));
     return $incident;
 }
Example #2
0
 /**
  * Index page view composer.
  *
  * @param \Illuminate\Contracts\View\View $view
  *
  * @return void
  */
 public function compose(View $view)
 {
     $view->withAboutApp(Markdown::convertToHtml($this->config->get('setting.app_about')));
     $view->withAppAnalytics($this->config->get('setting.app_analytics'));
     $view->withAppAnalyticsGoSquared($this->config->get('setting.app_analytics_gs'));
     $view->withAppAnalyticsPiwikUrl($this->config->get('setting.app_analytics_piwik_url'));
     $view->withAppAnalyticsPiwikSiteId($this->config->get('setting.app_analytics_piwik_site_id'));
     $view->withAppBanner($this->config->get('setting.app_banner'));
     $view->withAppBannerStyleFullWidth($this->config->get('setting.style_fullwidth_header'));
     $view->withAppBannerType($this->config->get('setting.app_banner_type'));
     $view->withAppDomain($this->config->get('setting.app_domain'));
     $view->withAppGraphs($this->config->get('setting.display_graphs'));
     $view->withAppLocale($this->config->get('setting.app_locale'));
     $view->withAppStylesheet($this->config->get('setting.stylesheet'));
     $view->withAppUrl($this->config->get('app.url'));
     $view->withAppHeader($this->config->get('setting.header'));
     $view->withAppFooter($this->config->get('setting.footer'));
     $view->withAppName($this->config->get('setting.app_name'));
     $view->withShowSupport($this->config->get('setting.show_support'));
     $view->withAutomaticLocalization($this->config->get('setting.automatic_localization'));
     $view->withEnableExternalDependencies($this->config->get('setting.enable_external_dependencies'));
     $view->withShowTimezone($this->config->get('setting.show_timezone'));
     $view->withTimezone($this->dates->getTimezone());
     $view->withSiteTitle($this->config->get('setting.app_name'));
     $view->withFontSubset($this->config->get('langs.' . $this->config->get('app.locale') . '.subset', 'latin'));
 }
 /**
  * Handle the report maintenance command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportMaintenanceCommand $command)
 {
     $scheduledAt = $this->dates->createNormalized('d/m/Y H:i', $command->timestamp);
     $maintenanceEvent = Incident::create(['name' => $command->name, 'message' => $command->message, 'scheduled_at' => $scheduledAt, 'status' => 0, 'visible' => 1]);
     event(new MaintenanceWasScheduledEvent($maintenanceEvent));
     return $maintenanceEvent;
 }
 /**
  * Handle the add metric point command.
  *
  * @param \CachetHQ\Cachet\Commands\Metric\AddMetricPointCommand $command
  *
  * @return \CachetHQ\Cachet\Models\MetricPoint
  */
 public function handle(AddMetricPointCommand $command)
 {
     $metric = $command->metric;
     $createdAt = $command->created_at;
     $data = ['metric_id' => $metric->id, 'value' => $command->value];
     if ($createdAt) {
         $data['created_at'] = $this->dates->create('U', $createdAt)->format('Y-m-d H:i:s');
     }
     $metricPoint = MetricPoint::create($data);
     event(new MetricPointWasAddedEvent($metricPoint));
     return $metricPoint;
 }
 protected function findOrCreatePoint(AddMetricPointCommand $command)
 {
     $buffer = Carbon::now()->subMinutes($command->metric->threshold);
     $point = MetricPoint::where('metric_id', $command->metric->id)->where('value', $command->value)->where('created_at', '>=', $buffer)->first();
     if ($point) {
         return $point;
     }
     $data = ['metric_id' => $command->metric->id, 'value' => $command->value, 'counter' => 0];
     if ($command->created_at) {
         $data['created_at'] = $this->dates->create('U', $command->created_at)->format('Y-m-d H:i:s');
     }
     return MetricPoint::create($data);
 }
 /**
  * Handle the update metric point command.
  *
  * @param \CachetHQ\Cachet\Bus\Commands\Metric\UpdateMetricPointCommand $command
  *
  * @return \CachetHQ\Cachet\Models\MetricPoint
  */
 public function handle(UpdateMetricPointCommand $command)
 {
     $point = $command->point;
     $metric = $command->metric;
     $createdAt = $command->created_at;
     $data = ['metric_id' => $metric->id, 'value' => (double) $command->value];
     if ($createdAt) {
         $data['created_at'] = $this->dates->create('U', $createdAt)->format('Y-m-d H:i:s');
     }
     $point->update($data);
     event(new MetricPointWasUpdatedEvent($point));
     return $point;
 }
 /**
  * Handle the update incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(UpdateIncidentCommand $command)
 {
     $incident = $command->incident;
     $incident->update($this->filterIncidentData($command));
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = $this->dates->createNormalized('d/m/Y H:i', $command->incident_date);
         $incident->update(['created_at' => $incidentDate, 'updated_at' => $incidentDate]);
     }
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     event(new IncidentWasUpdatedEvent($incident));
     return $incident;
 }
Example #8
0
 /**
  * Returns all points as an array, in the last month.
  *
  * @param \CachetHQ\Cachet\Models\Metric $metric
  *
  * @return array
  */
 public function listPointsForMonth(Metric $metric)
 {
     $dateTime = $this->dates->make();
     $daysInMonth = $dateTime->format('t');
     $points = [];
     $pointKey = $dateTime->format('jS M');
     for ($i = 0; $i <= $daysInMonth; $i++) {
         $points[$pointKey] = $this->repository->getPointsForDayInWeek($metric, $i);
         $pointKey = $dateTime->sub(new DateInterval('P1D'))->format('jS M');
     }
     return array_reverse($points);
 }
Example #9
0
 /**
  * Updates the given incident.
  *
  * @param \CachetHQ\Cachet\Models\Incident   $schedule
  * @param \CachetHQ\Cachet\Dates\DateFactory $dates
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function editScheduleAction(Incident $schedule, DateFactory $dates)
 {
     $scheduleData = Binput::get('incident');
     // Parse the schedule date.
     $scheduledAt = $dates->createNormalized('d/m/Y H:i', $scheduleData['scheduled_at']);
     if ($scheduledAt->isPast()) {
         $messageBag = new MessageBag();
         $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied']));
         return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withErrors($messageBag);
     }
     $scheduleData['scheduled_at'] = $scheduledAt;
     // Bypass the incident.status field.
     $scheduleData['status'] = 0;
     try {
         $schedule->update($scheduleData);
     } catch (ValidationException $e) {
         return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.edit.failure')))->withErrors($e->getMessageBag());
     }
     return Redirect::route('dashboard.schedule.edit', ['id' => $schedule->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.edit.success')));
 }