Exemplo n.º 1
0
 /**
  * Update an existing incident.
  *
  * @param \CachetHQ\Cachet\Models\Inicdent $incident
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function putIncident(Incident $incident)
 {
     $incidentData = array_filter(Binput::only(['name', 'message', 'status', 'component_id', 'notify', 'visible']));
     try {
         $incident->update($incidentData);
     } catch (Exception $e) {
         throw new BadRequestHttpException();
     }
     return $this->item($incident);
 }
 /**
  * Update a model by id.
  *
  * @param int   $id
  * @param array $data
  *
  * @return \Illuminate\Database\Eloquent\Model
  */
 public function update($id, array $data)
 {
     $incident = $this->model->findOrFail($id);
     $incident->fill($data);
     $this->validate($incident);
     if (isset($data['component_id'])) {
         $this->hasRelationship($incident, 'component');
     }
     $incident->update($data);
     return $incident;
 }
 /**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     $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 = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
         $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]);
     }
     // Notify subscribers.
     if ($command->notify) {
         event(new IncidentWasReportedEvent($incident));
     }
     return $incident;
 }
 /**
  * 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;
 }
Exemplo n.º 5
0
 /**
  * Bind data to the view.
  *
  * @param \Illuminate\Contracts\View\View $view
  *
  * @return void
  */
 public function compose(View $view)
 {
     $view->withIncidentCount(Incident::notScheduled()->count());
     $view->withIncidentTemplateCount(IncidentTemplate::count());
     $view->withComponentCount(Component::all()->count());
     $view->withSubscriberCount(Subscriber::isVerified()->count());
 }
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * Index page view composer.
  *
  * @param \Illuminate\Contracts\View\View $view
  *
  * @return void
  */
 public function compose(View $view)
 {
     $totalComponents = Component::enabled()->count();
     $majorOutages = Component::enabled()->status(4)->count();
     $isMajorOutage = $majorOutages / $totalComponents >= 0.5;
     // Default data
     $withData = ['system_status' => 'info', 'system_message' => trans_choice('cachet.service.bad', $totalComponents), 'favicon' => 'favicon-high-alert'];
     if ($isMajorOutage) {
         $withData = ['system_status' => 'danger', 'system_message' => trans_choice('cachet.service.major', $totalComponents), 'favicon' => 'favicon-high-alert'];
     } elseif (Component::enabled()->notStatus(1)->count() === 0) {
         // If all our components are ok, do we have any non-fixed incidents?
         $incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
         $incidentCount = $incidents->count();
         if ($incidentCount === 0 || $incidentCount >= 1 && (int) $incidents->first()->status === 4) {
             $withData = ['system_status' => 'success', 'system_message' => trans_choice('cachet.service.good', $totalComponents), 'favicon' => 'favicon'];
         }
     } else {
         if (Component::enabled()->whereIn('status', [2, 3])->count() > 0) {
             $withData['favicon'] = 'favicon-medium-alert';
         }
     }
     // Scheduled maintenance code.
     $scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
     // Component & Component Group lists.
     $usedComponentGroups = Component::enabled()->where('group_id', '>', 0)->groupBy('group_id')->pluck('group_id');
     $componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
     $ungroupedComponents = Component::enabled()->where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
     $view->with($withData)->withComponentGroups($componentGroups)->withUngroupedComponents($ungroupedComponents)->withScheduledMaintenance($scheduledMaintenance);
 }
Exemplo n.º 8
0
 /**
  * Seed the incidents table.
  *
  * @return void
  */
 protected function seedIncidents()
 {
     $defaultIncidents = [['name' => 'Awesome', 'message' => 'We totally nailed the fix :smile:', 'status' => 4, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Monitoring the fix', 'message' => "We're checking that our fix will first work.", 'status' => 3, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Update', 'message' => "We've found the problem, so we're looking at it.", 'status' => 2, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Test Incident', 'message' => 'Something went wrong, oh noes.', 'status' => 1, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1]];
     Incident::truncate();
     foreach ($defaultIncidents as $incident) {
         Incident::create($incident);
     }
 }
 /**
  * Handle the report maintenance command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportMaintenanceCommand $command)
 {
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
     $maintenanceEvent = Incident::create(['name' => $command->name, 'message' => $command->message, 'scheduled_at' => $scheduledAt, 'status' => 0, 'visible' => 1]);
     // Notify subscribers.
     event(new MaintenanceWasScheduledEvent($maintenanceEvent));
     return $maintenanceEvent;
 }
Exemplo n.º 10
0
 /**
  * Run the database seeding.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $defaultIncidents = [["name" => "Awesome", "message" => "We totally nailed the fix.", "status" => 4, "component_id" => 0, "user_id" => 1], ["name" => "Monitoring the fix", "message" => "We're checking that our fix will first work.", "status" => 3, "component_id" => 0, "user_id" => 1], ["name" => "Update", "message" => "We've found the problem, so we're looking at it.", "status" => 2, "component_id" => 0, "user_id" => 1], ["name" => "Test Incident", "message" => "Something went wrong, oh noes.", "component_id" => 0, "user_id" => 1]];
     Incident::truncate();
     foreach ($defaultIncidents as $incident) {
         Incident::create($incident);
     }
 }
 /**
  * Handle the report maintenance command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportMaintenanceCommand $command)
 {
     // TODO: Add validation to scheduledAt
     $scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
     $maintenanceEvent = Incident::create(['name' => $command->name, 'message' => $command->message, 'scheduled_at' => $scheduledAt, 'status' => 0, 'visible' => 1]);
     // Notify subscribers.
     if ($command->notify) {
         event(new MaintenanceWasScheduledEvent($maintenanceEvent));
     }
     return $maintenanceEvent;
 }
Exemplo n.º 12
0
 /**
  * Get all incidents.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function getIncidents()
 {
     $incidentVisibility = app(Guard::class)->check() ? 0 : 1;
     $incidents = Incident::where('visible', '>=', $incidentVisibility);
     $incidents->search(Binput::except(['sort', 'order', 'per_page']));
     if ($sortBy = Binput::get('sort')) {
         $direction = Binput::has('order') && Binput::get('order') == 'desc';
         $incidents->sort($sortBy, $direction);
     }
     $incidents = $incidents->paginate(Binput::get('per_page', 20));
     return $this->paginator($incidents, Request::instance());
 }
Exemplo n.º 13
0
 /**
  * Returns the rendered Blade templates.
  *
  * @return \Illuminate\View\View
  */
 public function showIndex()
 {
     $components = Component::orderBy('order')->orderBy('created_at')->get();
     $allIncidents = [];
     $incidentDays = Setting::get('app_incident_days') ?: 7;
     foreach (range(0, $incidentDays) as $i) {
         $date = Carbon::now()->subDays($i);
         $incidents = Incident::whereBetween('created_at', [$date->format('Y-m-d') . ' 00:00:00', $date->format('Y-m-d') . ' 23:59:59'])->orderBy('created_at', 'desc')->get();
         $allIncidents[] = ['date' => $date->format('jS F Y'), 'incidents' => $incidents];
     }
     return View::make('index', ['components' => $components, 'allIncidents' => $allIncidents, 'pageTitle' => Setting::get('app_name'), 'aboutApp' => Markdown::render(Setting::get('app_about'))]);
 }
 /**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     $incident = Incident::create(['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible, 'component' => $command->component_id]);
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     // Notify subscribers.
     if ($command->notify) {
         event(new IncidentWasReportedEvent($incident));
     }
     return $incident;
 }
Exemplo n.º 15
0
 /**
  * Returns the rendered Blade templates.
  *
  * @return \Illuminate\View\View
  */
 public function showIndex()
 {
     $today = Date::now();
     $startDate = Date::now();
     segment_page('Status Page');
     // Check if we have another starting date
     if (Binput::has('start_date')) {
         try {
             // If date provided is valid
             $oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
             segment_track('Status Page', ['start_date' => $oldDate->format('Y-m-d')]);
             // If trying to get a future date fallback to today
             if ($today->gt($oldDate)) {
                 $startDate = $oldDate;
             }
         } catch (Exception $e) {
             // Fallback to today
         }
     }
     $metrics = null;
     if ($displayMetrics = Setting::get('display_graphs')) {
         $metrics = Metric::where('display_chart', 1)->get();
     }
     $daysToShow = Setting::get('app_incident_days') ?: 7;
     $incidentDays = range(0, $daysToShow - 1);
     $dateTimeZone = Setting::get('app_timezone');
     $incidentVisiblity = Auth::check() ? 0 : 1;
     $allIncidents = Incident::notScheduled()->where('visible', '>=', $incidentVisiblity)->whereBetween('created_at', [$startDate->copy()->subDays($daysToShow)->format('Y-m-d') . ' 00:00:00', $startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use($dateTimeZone) {
         return (new Date($incident->created_at))->setTimezone($dateTimeZone)->toDateString();
     });
     // Add in days that have no incidents
     foreach ($incidentDays as $i) {
         $date = (new Date($startDate))->setTimezone($dateTimeZone)->subDays($i);
         if (!isset($allIncidents[$date->toDateString()])) {
             $allIncidents[$date->toDateString()] = [];
         }
     }
     // Sort the array so it takes into account the added days
     $allIncidents = $allIncidents->sortBy(function ($value, $key) {
         return strtotime($key);
     }, SORT_REGULAR, true)->all();
     // Scheduled maintenance code.
     $scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
     // Component & Component Group lists.
     $usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
     $componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
     $ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
     $canPageBackward = Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() != 0;
     return View::make('index', ['componentGroups' => $componentGroups, 'ungroupedComponents' => $ungroupedComponents, 'displayMetrics' => $displayMetrics, 'metrics' => $metrics, 'allIncidents' => $allIncidents, 'scheduledMaintenance' => $scheduledMaintenance, 'aboutApp' => Markdown::convertToHtml(Setting::get('app_about')), 'canPageForward' => (bool) $today->gt($startDate), 'canPageBackward' => $canPageBackward, 'previousDate' => $startDate->copy()->subDays($daysToShow)->toDateString(), 'nextDate' => $startDate->copy()->addDays($daysToShow)->toDateString(), 'pageTitle' => Setting::get('app_name') . ' Status']);
 }
Exemplo n.º 16
0
 /**
  * Index page view composer.
  *
  * @param \Illuminate\Contracts\View\View $view
  */
 public function compose(View $view)
 {
     // Default data
     $withData = ['systemStatus' => 'danger', 'systemMessage' => trans('cachet.service.bad')];
     if (Component::notStatus(1)->count() === 0) {
         // If all our components are ok, do we have any non-fixed incidents?
         $incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
         $incidentCount = $incidents->count();
         if ($incidentCount === 0 || $incidentCount >= 1 && (int) $incidents->first()->status === 4) {
             $withData = ['systemStatus' => 'success', 'systemMessage' => trans('cachet.service.good')];
         }
     }
     $view->with($withData);
 }
Exemplo n.º 17
0
 /**
  * Generates an RSS feed of all incidents.
  *
  * @return \Illuminate\Http\Response
  */
 public function feedAction()
 {
     $feed = RssFacade::feed('2.0', 'UTF-8');
     $feed->channel(['title' => Setting::get('app_name'), 'description' => 'Status Feed', 'link' => Setting::get('app_domain')]);
     Incident::get()->map(function ($incident) use($feed) {
         if ($incident->component) {
             $componentName = $incident->component->name;
         } else {
             $componentName = null;
         }
         $feed->item(['title' => $incident->name, 'message' => $incident->message, 'component' => $componentName, 'status' => $incident->humanStatus, 'created_at' => $incident->created_at, 'updated_at' => $incident->updated_at]);
     });
     return Response::make($feed, 200, ['Content-Type' => 'text/xml']);
 }
Exemplo n.º 18
0
 /**
  * Generates a Rss feed of all incidents.
  *
  * @param \CachetHQ\Cachet\Models\ComponentGroup|null $group
  * @param bool                                        $isRss
  *
  * @return \Illuminate\Http\Response
  */
 private function feedAction(ComponentGroup &$group, $isRss)
 {
     if ($group->exists) {
         $group->components->map(function ($component) {
             $component->incidents()->visible()->orderBy('created_at', 'desc')->get()->map(function ($incident) use($isRss) {
                 $this->feedAddItem($incident, $isRss);
             });
         });
     } else {
         Incident::visible()->orderBy('created_at', 'desc')->get()->map(function ($incident) use($isRss) {
             $this->feedAddItem($incident, $isRss);
         });
     }
     return $this->feed->render($isRss ? 'rss' : 'atom');
 }
 /**
  * @param DispatcherContract $events
  */
 public function boot(DispatcherContract $events)
 {
     if (false === config('slack.endpoint', false)) {
         return;
     }
     $this->loadTranslationsFrom(__DIR__ . '/resources/lang', 'slack');
     /**
      * To get the actual changes we need to record the
      * changes before the Cachet event is fired.
      */
     Incident::updating(function (Incident $incident) {
         $dirty = [];
         foreach ($incident->getDirty() as $key => $v) {
             $dirty[$key] = $incident->getOriginal($key);
         }
         self::registerChanges('incident', $dirty);
     });
     Component::updating(function (Component $component) {
         $dirty = [];
         foreach ($component->getDirty() as $key => $v) {
             $dirty[$key] = $component->getOriginal($key);
         }
         self::registerChanges('component', $dirty);
     });
     /**
      * Send Slack notification on new incidents.
      */
     $events->listen('CachetHQ\\Cachet\\Bus\\Events\\Incident\\IncidentWasReportedEvent', function (IncidentWasReportedEvent $event) {
         $handler = new IncidentWasReportedHandler($event->incident->status, $event->incident->name, $event->incident->message, $event->incident['component_id']);
         return $handler->send();
     });
     /**
      * Send Slack notification on incident updates.
      */
     $events->listen('CachetHQ\\Cachet\\Bus\\Events\\Incident\\IncidentWasUpdatedEvent', function (IncidentWasUpdatedEvent $event) {
         $handler = new IncidentWasUpdatedHandler($event->incident->id, $event->incident->status, $event->incident->name, $event->incident->message, $event->incident['component_id'], self::getChanges('incident'));
         return $handler->send();
     });
     /**
      * Send Slack notification on component updates.
      * Note these are not send when a component is updated as part of an incident update.
      */
     $events->listen('CachetHQ\\Cachet\\Bus\\Events\\Component\\ComponentWasUpdatedEvent', function (ComponentWasUpdatedEvent $event) {
         $handler = new ComponentWasUpdatedHandler($event->component->status, $event->component->name);
         return $handler->send();
     });
 }
Exemplo n.º 20
0
 /**
  * Displays the status page.
  *
  * @return \Illuminate\View\View
  */
 public function showIndex()
 {
     $today = Date::now();
     $startDate = Date::now();
     // Check if we have another starting date
     if (Binput::has('start_date')) {
         try {
             // If date provided is valid
             $oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date'));
             // If trying to get a future date fallback to today
             if ($today->gt($oldDate)) {
                 $startDate = $oldDate;
             }
         } catch (Exception $e) {
             // Fallback to today
         }
     }
     $daysToShow = Config::get('setting.app_incident_days', 0) - 1;
     if ($daysToShow < 0) {
         $daysToShow = 0;
         $incidentDays = [];
     } else {
         $incidentDays = range(0, $daysToShow);
     }
     $dateTimeZone = Config::get('cachet.timezone');
     $incidentVisibility = Auth::check() ? 0 : 1;
     $allIncidents = Incident::notScheduled()->where('visible', '>=', $incidentVisibility)->whereBetween('created_at', [$startDate->copy()->subDays($daysToShow)->format('Y-m-d') . ' 00:00:00', $startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('scheduled_at', 'desc')->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) use($dateTimeZone) {
         // If it's scheduled, get the scheduled at date.
         if ($incident->is_scheduled) {
             return (new Date($incident->scheduled_at))->setTimezone($dateTimeZone)->toDateString();
         }
         return (new Date($incident->created_at))->setTimezone($dateTimeZone)->toDateString();
     });
     // Add in days that have no incidents
     foreach ($incidentDays as $i) {
         $date = (new Date($startDate))->setTimezone($dateTimeZone)->subDays($i);
         if (!isset($allIncidents[$date->toDateString()])) {
             $allIncidents[$date->toDateString()] = [];
         }
     }
     // Sort the array so it takes into account the added days
     $allIncidents = $allIncidents->sortBy(function ($value, $key) {
         return strtotime($key);
     }, SORT_REGULAR, true)->all();
     return View::make('index')->withDaysToShow($daysToShow)->withAllIncidents($allIncidents)->withCanPageForward((bool) $today->gt($startDate))->withCanPageBackward(Incident::notScheduled()->where('created_at', '<', $startDate->format('Y-m-d'))->count() > 0)->withPreviousDate($startDate->copy()->subDays($daysToShow)->toDateString())->withNextDate($startDate->copy()->addDays($daysToShow)->toDateString());
 }
Exemplo n.º 21
0
 /**
  * Generates an Atom feed of all incidents.
  *
  * @return \Illuminate\Http\Response
  */
 public function feedAction()
 {
     $feed = Feed::make();
     $feed->title = Setting::get('app_name');
     $feed->description = 'Status Feed';
     $feed->link = Setting::get('app_domain');
     $feed->setDateFormat('datetime');
     Incident::get()->map(function ($incident) use($feed) {
         if ($incident->component) {
             $componentName = $incident->component->name;
         } else {
             $componentName = null;
         }
         $feed->add($incident->name, Setting::get('app_name'), Setting::get('app_domain'), $incident->created_at, $componentName === null ? $incident->humanStatus : $componentName . " " . $incident->humanStatus, $incident->message);
     });
     return $feed->render('atom');
 }
Exemplo n.º 22
0
 /**
  * Fetches all of the incidents over the last 30 days.
  *
  * @return \Illuminate\Support\Collection
  */
 protected function getIncidents()
 {
     $allIncidents = Incident::notScheduled()->whereBetween('created_at', [$this->startDate->copy()->subDays(30)->format('Y-m-d') . ' 00:00:00', $this->startDate->format('Y-m-d') . ' 23:59:59'])->orderBy('created_at', 'desc')->get()->groupBy(function (Incident $incident) {
         return (new Date($incident->created_at))->setTimezone($this->dateTimeZone)->toDateString();
     });
     // Add in days that have no incidents
     foreach (range(0, 30) as $i) {
         $date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
         if (!isset($allIncidents[$date->toDateString()])) {
             $allIncidents[$date->toDateString()] = [];
         }
     }
     // Sort the array so it takes into account the added days
     $allIncidents = $allIncidents->sortBy(function ($value, $key) {
         return strtotime($key);
     }, SORT_REGULAR, false);
     return $allIncidents;
 }
Exemplo n.º 23
0
 /**
  * Generates an Atom feed of all incidents.
  *
  * @param \CachetHQ\Cachet\Models\ComponentGroup|null $group
  *
  * @return \Illuminate\Http\Response
  */
 public function feedAction(ComponentGroup $group = null)
 {
     $feed = Feed::make();
     $feed->title = Setting::get('app_name');
     $feed->description = trans('cachet.feed');
     $feed->link = Str::canonicalize(Setting::get('app_domain'));
     $feed->setDateFormat('datetime');
     if ($group->exists) {
         $group->components->map(function ($component) use($feed) {
             $component->incidents()->visible()->orderBy('created_at', 'desc')->get()->map(function ($incident) use($feed) {
                 $this->feedAddItem($feed, $incident);
             });
         });
     } else {
         Incident::visible()->orderBy('created_at', 'desc')->get()->map(function ($incident) use($feed) {
             $this->feedAddItem($feed, $incident);
         });
     }
     return $feed->render('atom');
 }
Exemplo n.º 24
0
 /**
  * Get the entire system status.
  *
  * @return array
  */
 public function getStatus()
 {
     $enabledScope = Component::enabled();
     $totalComponents = Component::enabled()->count();
     $majorOutages = Component::enabled()->status(4)->count();
     $isMajorOutage = $totalComponents ? $majorOutages / $totalComponents >= 0.5 : false;
     // Default data
     $status = ['system_status' => 'info', 'system_message' => trans_choice('cachet.service.bad', $totalComponents), 'favicon' => 'favicon-high-alert'];
     if ($isMajorOutage) {
         $status = ['system_status' => 'danger', 'system_message' => trans_choice('cachet.service.major', $totalComponents), 'favicon' => 'favicon-high-alert'];
     } elseif (Component::enabled()->notStatus(1)->count() === 0) {
         // If all our components are ok, do we have any non-fixed incidents?
         $incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get()->filter(function ($incident) {
             return $incident->status > 0;
         });
         $incidentCount = $incidents->count();
         if ($incidentCount === 0 || $incidentCount >= 1 && (int) $incidents->first()->status === 4) {
             $status = ['system_status' => 'success', 'system_message' => trans_choice('cachet.service.good', $totalComponents), 'favicon' => 'favicon'];
         }
     } elseif (Component::enabled()->whereIn('status', [2, 3])->count() > 0) {
         $status['favicon'] = 'favicon-medium-alert';
     }
     return $status;
 }
Exemplo n.º 25
0
 /**
  * Index page view composer.
  *
  * @param \Illuminate\Contracts\View\View $view
  */
 public function compose(View $view)
 {
     // Default data
     $withData = ['systemStatus' => 'danger', 'systemMessage' => trans('cachet.service.bad'), 'favicon' => 'favicon-high-alert'];
     if (Component::notStatus(1)->count() === 0) {
         // If all our components are ok, do we have any non-fixed incidents?
         $incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
         $incidentCount = $incidents->count();
         if ($incidentCount === 0 || $incidentCount >= 1 && (int) $incidents->first()->status === 4) {
             $withData = ['systemStatus' => 'success', 'systemMessage' => trans('cachet.service.good'), 'favicon' => 'favicon'];
         }
     } else {
         if (Component::whereIn('status', [2, 3])->count() > 0) {
             $withData['favicon'] = 'favicon-medium-alert';
         }
     }
     // Scheduled maintenance code.
     $scheduledMaintenance = Incident::scheduled()->orderBy('scheduled_at')->get();
     // Component & Component Group lists.
     $usedComponentGroups = Component::where('group_id', '>', 0)->groupBy('group_id')->lists('group_id');
     $componentGroups = ComponentGroup::whereIn('id', $usedComponentGroups)->orderBy('order')->get();
     $ungroupedComponents = Component::where('group_id', 0)->orderBy('order')->orderBy('created_at')->get();
     $view->with($withData)->withComponentGroups($componentGroups)->withUngroupedComponents($ungroupedComponents)->withScheduledMaintenance($scheduledMaintenance)->withPageTitle(Setting::get('app_name'));
 }
Exemplo n.º 26
0
 /**
  * Bind data to the view.
  *
  * @param \Illuminate\Contracts\View\View $view
  */
 public function compose(View $view)
 {
     $view->withIncidentCount(Incident::notScheduled()->count());
     $view->withComponentCount(Component::all()->count());
 }
Exemplo n.º 27
0
 /**
  * Delete an existing incident.
  *
  * @param \CachetHQ\Cachet\Models\Inicdent $incident
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function deleteIncident(Incident $incident)
 {
     $incident->delete();
     return $this->noContent();
 }
Exemplo n.º 28
0
 /**
  * Get all incidents.
  *
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @param \Illuminate\Contracts\Auth\Guard          $auth
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function getIncidents(Request $request, Guard $auth)
 {
     $incidentVisiblity = $auth->check() ? 0 : 1;
     $incidents = Incident::where('visible', '>=', $incidentVisiblity)->paginate(Binput::get('per_page', 20));
     return $this->paginator($incidents, $request);
 }
Exemplo n.º 29
0
 /**
  * Edit an incident.
  *
  * @param \CachetHQ\Cachet\Models\Incident $incident
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function editIncidentAction(Incident $incident)
 {
     $incidentData = Binput::get('incident');
     if (array_has($incidentData, 'created_at') && $incidentData['created_at']) {
         $incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
         $incidentData['created_at'] = $incidentDate;
         $incidentData['updated_at'] = $incidentDate;
     } else {
         unset($incidentData['created_at']);
     }
     try {
         $incident->update($incidentData);
     } catch (ValidationException $e) {
         return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.templates.edit.failure')))->withErrors($e->getMessageBag());
     }
     $componentStatus = array_pull($incidentData, 'component_status');
     if ($incident->component) {
         $incident->component->update(['status' => $componentStatus]);
     }
     return Redirect::route('dashboard.incidents.edit', ['id' => $incident->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.edit.success')));
 }
Exemplo n.º 30
0
 /**
  * Shows the incidents view.
  *
  * @return \Illuminate\View\View
  */
 public function showIncidents()
 {
     $incidents = Incident::notScheduled()->orderBy('created_at', 'desc')->get();
     return View::make('dashboard.incidents.index')->withPageTitle(trans('dashboard.incidents.incidents') . ' - ' . trans('dashboard.dashboard'))->withIncidents($incidents);
 }