Skip to main content
Version: 0.1.0

The UptimeCheck Model

The entity of UptimeCheck is represented as a model in MoonGuard, and it has the following definition:

Fillable Fields

Field NameDescription
site_idThe ID of the site associated with the uptime check.

Casts

NameDescription
statusThe status of the uptime check, casted to the UptimeStatus enum
status_last_change_dateThe date and time when the status of the uptime check was last changed, casted to an immutable datetime object
last_check_dateThe date and time when the last check was performed, casted to an immutable datetime object
check_failed_event_fired_on_dateThe date and time when the check failed event was fired, casted to an immutable datetime object
request_duration_msThe duration of the last request in milliseconds, casted using the RequestDurationCast class

Methods

Method NameReturn TypeDescription
site()BelongsToReturns a BelongsTo relationship between the UptimeCheck model and the Site model. This method allows you to retrieve the site associated with the uptime check.
saveSuccessfulCheck(Response $response)voidSaves the result of a successful uptime check. This method sets the status of the uptime check to "UP", updates the last check date, and saves the request duration.
saveSuccessfulCheck(Response $response)voidSaves the result of a failed uptime check. This method sets the status of the uptime check to "DOWN", increments the number of times the check has failed in a row, updates the last check date, saves the failure reason, and sets the request duration to null.
requestTookTooLong()boolReturns a boolean indicating whether the last request took longer than the maximum allowed duration for the site.
wasFailing()AttributeReturns an Attribute instance that indicates whether the uptime check was failing.
isEnabled()AttributeReturns an Attribute instance that indicates whether the uptime check is enabled.
booted()voidOverrides the booted method to add a callback that sets the status last change date when the status of the uptime check changes.

Using a custom UptimeCheck model

If you wish to create a custom UptimeCheck model or extend its capabilities, we recommend following these steps:

  1. Create a new UptimeCheck class that extends from Illuminate\Database\Eloquent\Model and implements the Taecontrol\MoonGuard\Contracts\MoonGuardUptimeCheck interface.
<?php

use Illuminate\Database\Eloquent\Model;
use Taecontrol\MoonGuard\Contracts\MoonGuardUptimeCheck;

class UptimeCheck extends Model implements MoonGuardUptimeCheck
{
//Contract implementation
}
  1. Implement all the properties and methods required, you can guide yourself with the original UptimeCheck.php model from Moonguard but here a resume.

  2. Replace the new Uptime Check model class in the configuration file.

[
'uptime_check' => [
'enabled' => true,
'model' => \Taecontrol\MoonGuard\Models\UptimeCheck::class, -> //replace model
'notify_failed_check_after_consecutive_failures' => 1,
'resend_uptime_check_failed_notification_every_minutes' => 5,
],
]