/**
  * 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;
 }
 /**
  * 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;
 }
Esempio n. 3
0
 /**
  * Shows the dashboard view.
  *
  * @return \Illuminate\View\View
  */
 public function showDashboard()
 {
     $components = Component::orderBy('order')->get();
     $incidents = $this->getIncidents();
     $subscribers = $this->getSubscribers();
     return View::make('dashboard.index')->withComponents($components)->withIncidents($incidents)->withSubscribers($subscribers);
 }
Esempio n. 4
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());
 }
Esempio n. 5
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);
 }
Esempio n. 6
0
 /**
  * Update an existing component.
  *
  * @param \CachetHQ\Cachet\Models\Component $component
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function putComponent(Component $component)
 {
     try {
         $component->update(Binput::except('tags'));
     } catch (Exception $e) {
         throw new BadRequestHttpException();
     }
     if (Binput::has('tags')) {
         $tags = preg_split('/ ?, ?/', Binput::get('tags'));
         // For every tag, do we need to create it?
         $componentTags = array_map(function ($taggable) use($component) {
             return Tag::firstOrCreate(['name' => $taggable])->id;
         }, $tags);
         $component->tags()->sync($componentTags);
     }
     return $this->item($component);
 }
Esempio n. 7
0
 /**
  * Seed the components table.
  *
  * @return void
  */
 protected function seedComponents()
 {
     $defaultComponents = [['name' => 'API', 'description' => 'Used by third-parties to connect to us', 'status' => 1, 'order' => 0, 'group_id' => 0, 'link' => ''], ['name' => 'Documentation', 'description' => 'Kindly powered by Readme.io', 'status' => 1, 'order' => 0, 'group_id' => 0, 'link' => 'https://docs.cachethq.io'], ['name' => 'Website', 'description' => '', 'status' => 1, 'order' => 0, 'group_id' => 0, 'link' => 'https://cachethq.io'], ['name' => 'Blog', 'description' => 'The Cachet Blog.', 'status' => 1, 'order' => 0, 'group_id' => 0, 'link' => 'https://blog.cachethq.io']];
     Component::truncate();
     foreach ($defaultComponents as $component) {
         Component::create($component);
     }
 }
 /**
  * Handle the add component command.
  *
  * @param \CachetHQ\Cachet\Commands\Component\AddComponentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Component
  */
 public function handle(AddComponentCommand $command)
 {
     $componentData = array_filter(['name' => $command->name, 'description' => $command->description, 'link' => $command->link, 'status' => $command->status, 'order' => $command->order, 'group_id' => $command->group_id]);
     $componentData['enabled'] = $command->enabled;
     $component = Component::create($componentData);
     event(new ComponentWasAddedEvent($component));
     return $component;
 }
 /**
  * Run the database seeding.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $defaultComponents = [["name" => "API", "description" => "Used by third-parties to connect to us", "status" => 1, "user_id" => 1], ["name" => "Payments", "description" => "Backed by Stripe", "status" => 1, "user_id" => 1], ["name" => "Website", "status" => 1, "user_id" => 1]];
     Component::truncate();
     foreach ($defaultComponents as $component) {
         Component::create($component);
     }
 }
Esempio n. 10
0
 /**
  * Updates a component.
  *
  * @param \CachetHQ\Cachet\Models\Component $component
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function updateComponentAction(Component $component)
 {
     $_component = Binput::get('component');
     $tags = array_pull($_component, 'tags');
     try {
         $component->update($_component);
     } catch (ValidationException $e) {
         return Redirect::route('dashboard.components.edit', ['id' => $component->id])->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.components.edit.failure')))->withErrors($e->getMessageBag());
     }
     // The component was added successfully, so now let's deal with the tags.
     $tags = preg_split('/ ?, ?/', $tags);
     // For every tag, do we need to create it?
     $componentTags = array_map(function ($taggable) use($component) {
         return Tag::firstOrCreate(['name' => $taggable])->id;
     }, $tags);
     $component->tags()->sync($componentTags);
     return Redirect::route('dashboard.components.edit', ['id' => $component->id])->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.components.edit.success')));
 }
Esempio n. 11
0
 /**
  * Updates a components ordering.
  *
  * @return array
  */
 public function postUpdateComponentOrder()
 {
     $componentData = Binput::get('ids');
     foreach ($componentData as $order => $componentId) {
         // Ordering should be 1-based, data comes in 0-based
         Component::find($componentId)->update(['order' => $order + 1]);
     }
     return $componentData;
 }
Esempio n. 12
0
 /**
  * Updates a components ordering.
  *
  * @return array
  */
 public function postUpdateComponentOrder()
 {
     $componentData = Binput::all();
     unset($componentData['component'][0]);
     // Remove random 0 index.
     foreach ($componentData['component'] as $componentId => $order) {
         $component = Component::find($componentId);
         $component->update(['order' => $order]);
     }
     return $componentData;
 }
Esempio 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'))]);
 }
 /**
  * Find the status on a component.
  *
  * @param string $componentId
  *
  * @return string
  */
 protected function getComponentStatus($componentId = '')
 {
     if ('' == $componentId) {
         return 'n/a';
     }
     $statuses = trans('cachet.components.status');
     $component = Component::find($componentId);
     if ($component instanceof Component) {
         return $component->name . ': *' . $statuses[$component->status] . '*';
     }
     return 'n/a';
 }
Esempio n. 15
0
 /**
  * Updates a components ordering.
  *
  * @return array
  */
 public function postUpdateComponentOrder()
 {
     $componentData = Binput::get('ids');
     foreach ($componentData as $order => $componentId) {
         try {
             $component = Component::find($componentId);
             dispatch(new UpdateComponentCommand($component, $component->name, $component->description, $component->status, $component->link, $order + 1, $component->group_id, $component->enabled));
         } catch (QueryException $e) {
             throw new BadRequestHttpException();
         }
     }
     return $this->collection(Component::query()->orderBy('order')->get());
 }
 /**
  * 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;
 }
Esempio n. 17
0
 /**
  * Shows the dashboard view.
  *
  * @return \Illuminate\View\View
  */
 public function showDashboard()
 {
     $components = Component::orderBy('order')->get();
     $incidents = $this->getIncidents();
     $subscribers = $this->getSubscribers();
     $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();
     $entries = null;
     if ($feed = $this->feed->latest()) {
         $entries = array_slice($feed->channel->item, 0, 5);
     }
     return View::make('dashboard.index')->withPageTitle(trans('dashboard.dashboard'))->withComponents($components)->withIncidents($incidents)->withSubscribers($subscribers)->withEntries($entries)->withComponentGroups($componentGroups)->withUngroupedComponents($ungroupedComponents);
 }
Esempio n. 18
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);
 }
Esempio n. 19
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']);
 }
 /**
  * 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;
 }
 /**
  * @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();
     });
 }
 /**
  * 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 = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
         $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]);
     }
     // Notify subscribers.
     event(new IncidentWasUpdatedEvent($incident));
     return $incident;
 }
Esempio n. 23
0
 /**
  * Update an existing component.
  *
  * @param \CachetHQ\Cachet\Models\Component $component
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function putComponent(Component $component)
 {
     try {
         dispatch(new UpdateComponentCommand($component, Binput::get('name'), Binput::get('description'), Binput::get('status'), Binput::get('link'), Binput::get('order'), Binput::get('group_id'), (bool) Binput::get('enabled', true)));
     } catch (QueryException $e) {
         throw new BadRequestHttpException();
     }
     if (Binput::has('tags')) {
         $tags = preg_split('/ ?, ?/', Binput::get('tags'));
         // For every tag, do we need to create it?
         $componentTags = array_map(function ($taggable) use($component) {
             return Tag::firstOrCreate(['name' => $taggable])->id;
         }, $tags);
         $component->tags()->sync($componentTags);
     }
     return $this->item($component);
 }
 /**
  * Handle the subscribe subscriber command.
  *
  * @param \CachetHQ\Cachet\Bus\Commands\Subscriber\UpdateSubscriberSubscriptionCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Subscriber
  */
 public function handle(UpdateSubscriberSubscriptionCommand $command)
 {
     $subscriber = $command->subscriber;
     $subscriptions = $command->subscriptions ?: [];
     $components = Component::all();
     $updateSubscriptions = $components->filter(function ($item) use($subscriptions) {
         return in_array($item->id, $subscriptions);
     });
     $subscriber->global = $updateSubscriptions->count() === $components->count();
     $subscriber->subscriptions()->delete();
     if (!$updateSubscriptions->isEmpty()) {
         foreach ($updateSubscriptions as $subscription) {
             Subscription::firstOrCreate(['subscriber_id' => $subscriber->id, 'component_id' => $subscription->id]);
         }
     }
     $subscriber->save();
     event(new SubscriberHasUpdatedSubscriptionsEvent($subscriber));
     return $subscriber;
 }
 /**
  * Handle the subscribe subscriber command.
  *
  * @param \CachetHQ\Cachet\Bus\Commands\Subscriber\SubscribeSubscriberCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Subscriber
  */
 public function handle(SubscribeSubscriberCommand $command)
 {
     if ($subscriber = Subscriber::where('email', $command->email)->first()) {
         return $subscriber;
     }
     $subscriber = Subscriber::firstOrCreate(['email' => $command->email]);
     // Decide what to subscribe the subscriber to.
     if ($subscriptions = $command->subscriptions) {
         $subscriptions = Component::whereIn('id', $subscriptions);
     } else {
         $subscriptions = Component::all();
     }
     foreach ($subscriptions as $component) {
         Subscription::create(['subscriber_id' => $subscriber->id, 'component_id' => $component->id]);
     }
     if ($command->verified) {
         dispatch(new VerifySubscriberCommand($subscriber));
     } else {
         event(new SubscriberHasSubscribedEvent($subscriber));
     }
     return $subscriber;
 }
Esempio n. 26
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;
 }
Esempio n. 27
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'));
 }
Esempio n. 28
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());
 }
Esempio n. 29
0
 /**
  * Shows the edit incident view.
  *
  * @param \CachetHQ\Cachet\Models\Incident $incident
  *
  * @return \Illuminate\View\View
  */
 public function showEditIncidentAction(Incident $incident)
 {
     return View::make('dashboard.incidents.edit')->withPageTitle(trans('dashboard.incidents.edit.title') . ' - ' . trans('dashboard.dashboard'))->withIncident($incident)->withComponentsInGroups(ComponentGroup::with('components')->get())->withComponentsOutGroups(Component::where('group_id', 0)->get());
 }
Esempio n. 30
0
 /**
  * Shows the components view.
  *
  * @return \Illuminate\View\View
  */
 public function showComponents()
 {
     $components = Component::orderBy('order')->orderBy('created_at')->get();
     $this->subMenu['components']['active'] = true;
     return View::make('dashboard.components.index')->withPageTitle(trans_choice('dashboard.components.components', 2) . ' - ' . trans('dashboard.dashboard'))->withComponents($components)->withSubMenu($this->subMenu);
 }