/** * 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 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; }
/** * Creates a new scheduled maintenance "incident". * * @return \Illuminate\Http\RedirectResponse */ public function addScheduleAction() { $scheduleData = Binput::get('incident'); // Parse the schedule date. $scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone')); if ($scheduledAt->isPast()) { $messageBag = new MessageBag(); $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied'])); return Redirect::back()->withErrors($messageBag); } $scheduleData['scheduled_at'] = $scheduledAt; // Bypass the incident.status field. $scheduleData['status'] = 0; $incident = Incident::create($scheduleData); if (!$incident->isValid()) { segment_track('Dashboard', ['event' => 'Created Scheduled Maintenance', 'success' => false]); return Redirect::back()->withInput(Binput::all())->with('success', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.add.failure')))->with('errors', $incident->getErrors()); } segment_track('Dashboard', ['event' => 'Created Scheduled Maintenance', 'success' => true]); $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.add.success')); $isEnabled = (bool) Setting::get('enable_subscribers', false); $mailAddress = env('MAIL_ADDRESS', false); $mailFrom = env('MAIL_NAME', false); $subscribersEnabled = $isEnabled && $mailAddress && $mailFrom; if (array_get($scheduleData, 'notify') && $subscribersEnabled) { event(new MaintenanceHasScheduledEvent($incident)); } return Redirect::back()->with('success', $successMsg); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Create a new incident. * * @param \Illuminate\Contracts\Auth\Guard $auth * * @return \Illuminate\Http\JsonResponse */ public function postIncidents(Guard $auth) { $incidentData = Binput::all(); if (!array_has($incidentData, 'visible')) { $incidentData['visible'] = 1; } try { $incident = Incident::create($incidentData); } catch (Exception $e) { throw new BadRequestHttpException(); } if (array_get($incidentData, 'notify') && subscribers_enabled()) { event(new IncidentHasReportedEvent($incident)); } return $this->item($incident); }
/** * Create a new incident. * * @param \Illuminate\Contracts\Auth\Guard $auth * * @return \Illuminate\Http\JsonResponse */ public function postIncidents(Guard $auth) { $incidentData = array_filter(Binput::only(['name', 'message', 'status', 'component_id', 'notify', 'visible'])); // Default visibility is 1. if (!array_has($incidentData, 'visible')) { $incidentData['visible'] = 1; } try { $incident = Incident::create($incidentData); } catch (Exception $e) { throw new BadRequestHttpException(); } if (array_get($incidentData, 'notify') && subscribers_enabled()) { event(new IncidentHasReportedEvent($incident)); } return $this->item($incident); }
/** * Create a new incident. * * @param \Illuminate\Contracts\Auth\Guard $auth * * @return \CachetHQ\Cachet\Models\Incident */ public function postIncidents(Guard $auth) { $incidentData = Binput::all(); try { $incident = Incident::create($incidentData); } catch (Exception $e) { throw new BadRequestHttpException(); } $isEnabled = (bool) Setting::get('enable_subscribers', false); $mailAddress = env('MAIL_ADDRESS', false); $mailFrom = env('MAIL_NAME', false); $subscribersEnabled = $isEnabled && $mailAddress && $mailFrom; if (array_get($incidentData, 'notify') && $subscribersEnabled) { event(new IncidentHasReportedEvent($incident)); } if ($incident->isValid()) { return $this->item($incident); } throw new BadRequestHttpException(); }
/** * Creates a new scheduled maintenance "incident". * * @return \Illuminate\Http\RedirectResponse */ public function addScheduleAction() { $scheduleData = Binput::get('incident'); // Parse the schedule date. $scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone')); if ($scheduledAt->isPast()) { $messageBag = new MessageBag(); $messageBag->add('scheduled_at', trans('validation.date', ['attribute' => 'scheduled time you supplied'])); return Redirect::back()->withErrors($messageBag); } $scheduleData['scheduled_at'] = $scheduledAt; // Bypass the incident.status field. $scheduleData['status'] = 0; try { Incident::create($scheduleData); } catch (ValidationException $e) { return Redirect::back()->withInput(Binput::all())->withSuccess(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.schedule.add.failure')))->withErrors($e->getMessageBag()); } if (array_get($scheduleData, 'notify') && subscribers_enabled()) { event(new MaintenanceHasScheduledEvent($incident)); } return Redirect::back()->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.schedule.add.success'))); }
/** * Seed the incidents table. * * @return void */ protected function seedIncidents() { $incidentMessage = <<<'EINCIDENT' # Of course it does! What kind of web application doesn't these days? ## Headers are fun aren't they It's _exactly_ why we need Markdown. For **emphasis** and such. EINCIDENT; $defaultIncidents = [['name' => 'Cachet supports Markdown!', 'message' => $incidentMessage, 'status' => 4, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Awesome', 'message' => ':+1: We totally nailed the fix.', 'status' => 4, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Monitoring the fix', 'message' => ":ship: We've deployed a fix.", 'status' => 3, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Update', 'message' => "We've identified the problem. Our engineers are currently looking at it.", 'status' => 2, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Test Incident', 'message' => 'Something went wrong, with something or another.', 'status' => 1, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Investigating the API', 'message' => ':zap: We\'ve seen high response times from our API. It looks to be fixing itself as time goes on.', 'status' => 1, 'component_id' => 1, 'scheduled_at' => null, 'visible' => 1]]; Incident::truncate(); foreach ($defaultIncidents as $incident) { Incident::create($incident); } }
/** * Creates a new incident. * * @return \Illuminate\Http\RedirectResponse */ public function createIncidentAction() { $incidentData = Binput::get('incident'); $componentStatus = array_pull($incidentData, 'component_status'); 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']); } $incident = Incident::create($incidentData); if (!$incident->isValid()) { segment_track('Dashboard', ['event' => 'Created Incident', 'success' => false]); return Redirect::back()->withInput(Binput::all())->with('title', sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))->with('errors', $incident->getErrors()); } // Update the component. if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) { Component::find($incidentData['component_id'])->update(['status' => $componentStatus]); } segment_track('Dashboard', ['event' => 'Created Incident', 'success' => true]); $successMsg = sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success')); $isEnabled = (bool) Setting::get('enable_subscribers', false); $mailAddress = env('MAIL_ADDRESS', false); $mailFrom = env('MAIL_NAME', false); $subscribersEnabled = $isEnabled && $mailAddress && $mailFrom; if (array_get($incidentData, 'notify') && $subscribersEnabled) { event(new IncidentHasReportedEvent($incident)); } return Redirect::back()->with('success', $successMsg); }
/** * Creates a new incident. * * @return \Illuminate\Http\RedirectResponse */ public function createIncidentAction() { $incidentData = Binput::get('incident'); $componentStatus = array_pull($incidentData, 'component_status'); 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 = Incident::create($incidentData); } catch (ValidationException $e) { return Redirect::route('dashboard.incidents.add')->withInput(Binput::all())->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.incidents.add.failure')))->withErrors($e->getMessageBag()); } // Update the component. if (isset($incidentData['component_id']) && (int) $incidentData['component_id'] > 0) { Component::find($incidentData['component_id'])->update(['status' => $componentStatus]); } if (array_get($incidentData, 'notify') && subscribers_enabled()) { event(new IncidentHasReportedEvent($incident)); } return Redirect::route('dashboard.incidents.add')->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.incidents.add.success'))); }
/** * Seed the incidents table. * * @return void */ protected function seedIncidents() { $defaultIncidents = [['name' => 'Awesome', 'message' => ':+1: We totally nailed the fix.', 'status' => 4, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Monitoring the fix', 'message' => ":ship: We've deployed a fix.", 'status' => 3, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Update', 'message' => "We've identified the problem. Our engineers are currently looking at it.", 'status' => 2, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Test Incident', 'message' => 'Something went wrong, with something or another.', 'status' => 1, 'component_id' => 0, 'scheduled_at' => null, 'visible' => 1], ['name' => 'Investigating the API', 'message' => ':zap: We\'ve seen high response times from our API. It looks to be fixing itself as time goes on.', 'status' => 1, 'component_id' => 1, 'scheduled_at' => null, 'visible' => 1]]; Incident::truncate(); foreach ($defaultIncidents as $incident) { Incident::create($incident); } }
/** * Creates a new incident. * * @return \Illuminate\Http\RedirectResponse */ public function createIncidentAction() { $_incident = Binput::get('incident'); $incident = Incident::create($_incident); return Redirect::back()->with('incident', $incident); }