Create a custom probe type
mainTo extend Upright with a new probe type (e.g., ping), follow these four steps:
- Register the type: Add the name and icon to the initializer.
- Create the probe class: Create a file in
probes/extendingFrozenRecord::Baseand includingUpright::ProbeableandUpright::ProbeYamlSource. Implementcheck(returns truthy/falsy),probe_type, andprobe_target. - Define probes in YAML: Create a file named
probes/{type}_probes.yml(e.g.,probes/ping_probes.yml) containing the probe configurations. - Schedule it: Add a recurring job in
config/recurring.ymlusing Solid Queue.
# 1. Register in config/initializers/upright.rb
Upright.configure do |config|
config.probe_types.register :ping, name: "Ping", icon: "📶"
end
# 2. Create probes/ping_probe.rb
class PingProbe < FrozenRecord::Base
include Upright::Probeable
include Upright::ProbeYamlSource
stagger_by_site 3.seconds
def check
@ping_output, status = Open3.capture2e("ping", "-c", "1", "-W", "5", host)
status.success?
end
def on_check_recorded(probe_result)
if @ping_output.present?
Upright::Artifact.new(name: "ping.log", content: @ping_output).attach_to(probe_result)
end
end
def probe_type = "ping"
def probe_target = host
end
# 3. Define probes/ping_probes.yml
- name: "Cloudflare DNS"
host: "1.1.1.1"
# 4. Schedule in config/recurring.yml
production:
ping_probes:
command: "PingProbe.check_and_record_all_later"
schedule: every 30 seconds