Introduce incidenti con dedup, job Sidekiq ogni 3 min, scan log cron, /up/deep, dashboard /admin/ops e push ntfy; include Sentry opzionale e fix test suite. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.4 KiB
Ruby
44 lines
1.4 KiB
Ruby
require "rails_helper"
|
|
|
|
RSpec.describe Ops::Notifier do
|
|
let(:incident) do
|
|
Ops::Incident.create!(
|
|
kind: "test",
|
|
severity: "critical",
|
|
status: "open",
|
|
title: "Test alert",
|
|
message: "Messaggio di prova",
|
|
metadata: {},
|
|
fingerprint: "test:#{SecureRandom.hex(4)}",
|
|
occurrence_count: 1,
|
|
first_seen_at: Time.current,
|
|
last_seen_at: Time.current
|
|
)
|
|
end
|
|
|
|
describe "#notify" do
|
|
it "invia POST a ntfy quando configurato" do
|
|
conn = instance_double(Faraday::Connection)
|
|
response = instance_double(Faraday::Response, success?: true, status: 200, body: "")
|
|
allow(Faraday).to receive(:new).and_return(conn)
|
|
allow(conn).to receive(:post).and_return(response)
|
|
allow(ENV).to receive(:[]).and_call_original
|
|
allow(ENV).to receive(:[]).with("OPS_NTFY_URL").and_return("https://ntfy.example/ops")
|
|
|
|
described_class.new.notify(incident)
|
|
|
|
expect(conn).to have_received(:post).with("https://ntfy.example/ops", anything, hash_including("Title"))
|
|
end
|
|
end
|
|
|
|
describe ".notify_severity?" do
|
|
it "rispetta OPS_NOTIFY_SEVERITIES" do
|
|
allow(ENV).to receive(:fetch).and_call_original
|
|
allow(ENV).to receive(:fetch).with("OPS_NOTIFY_SEVERITIES", "critical").and_return("critical,warning")
|
|
|
|
expect(described_class.notify_severity?("critical")).to be(true)
|
|
expect(described_class.notify_severity?("info")).to be(false)
|
|
end
|
|
end
|
|
end
|