コード例 #1
0
 /**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Bus\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     $data = ['name' => $command->name, 'status' => $command->status, 'visible' => $command->visible];
     if ($command->template) {
         $data['message'] = $this->parseIncidentTemplate($command->template, $command->template_vars);
     } else {
         $data['message'] = $command->message;
     }
     // 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->create('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;
 }
コード例 #2
0
 /**
  * Handle the report maintenance command.
  *
  * @param \CachetHQ\Cachet\Bus\Commands\Incident\ReportMaintenanceCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportMaintenanceCommand $command)
 {
     $scheduledAt = $this->dates->create('d/m/Y H:i', $command->timestamp);
     $maintenanceEvent = Incident::create(['name' => $command->name, 'message' => $command->message, 'scheduled_at' => $scheduledAt, 'status' => 0, 'visible' => 1]);
     $maintenanceEvent->notify = (bool) $command->notify;
     event(new MaintenanceWasScheduledEvent($maintenanceEvent));
     return $maintenanceEvent;
 }
コード例 #3
0
 /**
  * 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;
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 /**
  * 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;
 }
コード例 #6
0
 /**
  * Handle the update incident command.
  *
  * @param \CachetHQ\Cachet\Bus\Commands\Incident\UpdateIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(UpdateIncidentCommand $command)
 {
     if ($command->template) {
         $command->message = $this->parseIncidentTemplate($command->template, $command->template_vars);
     }
     $incident = $command->incident;
     $incident->update($this->filter($command));
     // The incident occurred at a different time.
     if ($command->incident_date) {
         $incidentDate = $this->dates->create('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;
 }