Module: BrainzLab::Beacon
- Defined in:
- lib/brainzlab/beacon.rb,
lib/brainzlab/beacon/client.rb,
lib/brainzlab/beacon/provisioner.rb
Defined Under Namespace
Classes: Client, Provisioner
Class Method Summary collapse
-
.all_up? ⇒ Boolean
Check if all monitors are up.
- .client ⇒ Object
-
.create_dns_monitor(name, domain, expected_record: nil) ⇒ Object
Create a DNS monitor.
-
.create_http_monitor(name, url, interval: 60) ⇒ Hash?
Create an HTTP monitor.
-
.create_ssl_monitor(name, domain, warn_days: 30) ⇒ Object
Create an SSL certificate monitor.
-
.create_tcp_monitor(name, host, port) ⇒ Object
Create a TCP port monitor.
-
.delete(id) ⇒ Object
Delete a monitor.
-
.ensure_provisioned! ⇒ Object
INTERNAL ===.
-
.get(id) ⇒ Object
Get monitor by ID.
-
.history(monitor_id, limit: 100) ⇒ Object
Get check history for a monitor.
-
.incidents(status: nil) ⇒ Object
List active incidents.
-
.list ⇒ Object
List all monitors.
-
.pause(id) ⇒ Object
Pause a monitor.
- .provisioner ⇒ Object
- .reset! ⇒ Object
-
.resume(id) ⇒ Object
Resume a paused monitor.
-
.status ⇒ Object
Get overall status summary.
-
.update(id, **attributes) ⇒ Object
Update a monitor.
Class Method Details
.all_up? ⇒ Boolean
Check if all monitors are up
168 169 170 171 172 173 |
# File 'lib/brainzlab/beacon.rb', line 168 def all_up? summary = status return false unless summary %w[up operational].include?(summary[:status]) end |
.client ⇒ Object
198 199 200 |
# File 'lib/brainzlab/beacon.rb', line 198 def client @client ||= Client.new(BrainzLab.configuration) end |
.create_dns_monitor(name, domain, expected_record: nil) ⇒ Object
Create a DNS monitor
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/brainzlab/beacon.rb', line 72 def create_dns_monitor(name, domain, expected_record: nil, **) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.beacon_valid? client.create_monitor( name: name, url: domain, type: 'dns', expected_record: expected_record, ** ) end |
.create_http_monitor(name, url, interval: 60) ⇒ Hash?
Create an HTTP monitor
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/brainzlab/beacon.rb', line 25 def create_http_monitor(name, url, interval: 60, **) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.beacon_valid? client.create_monitor( name: name, url: url, type: 'http', interval: interval, ** ) end |
.create_ssl_monitor(name, domain, warn_days: 30) ⇒ Object
Create an SSL certificate monitor
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/brainzlab/beacon.rb', line 41 def create_ssl_monitor(name, domain, warn_days: 30, **) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.beacon_valid? client.create_monitor( name: name, url: "https://#{domain}", type: 'ssl', ssl_warn_days: warn_days, ** ) end |
.create_tcp_monitor(name, host, port) ⇒ Object
Create a TCP port monitor
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/brainzlab/beacon.rb', line 57 def create_tcp_monitor(name, host, port, **) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.beacon_valid? client.create_monitor( name: name, url: "#{host}:#{port}", type: 'tcp', ** ) end |
.delete(id) ⇒ Object
Delete a monitor
118 119 120 121 122 123 124 125 |
# File 'lib/brainzlab/beacon.rb', line 118 def delete(id) return false unless enabled? ensure_provisioned! return false unless BrainzLab.configuration.beacon_valid? client.delete_monitor(id) end |
.ensure_provisioned! ⇒ Object
INTERNAL ===
187 188 189 190 191 192 |
# File 'lib/brainzlab/beacon.rb', line 187 def ensure_provisioned! return if @provisioned @provisioned = true provisioner.ensure_project! end |
.get(id) ⇒ Object
Get monitor by ID
88 89 90 91 92 93 94 95 |
# File 'lib/brainzlab/beacon.rb', line 88 def get(id) return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.beacon_valid? client.get_monitor(id) end |
.history(monitor_id, limit: 100) ⇒ Object
Get check history for a monitor
148 149 150 151 152 153 154 155 |
# File 'lib/brainzlab/beacon.rb', line 148 def history(monitor_id, limit: 100) return [] unless enabled? ensure_provisioned! return [] unless BrainzLab.configuration.beacon_valid? client.check_history(monitor_id, limit: limit) end |
.incidents(status: nil) ⇒ Object
List active incidents
176 177 178 179 180 181 182 183 |
# File 'lib/brainzlab/beacon.rb', line 176 def incidents(status: nil) return [] unless enabled? ensure_provisioned! return [] unless BrainzLab.configuration.beacon_valid? client.list_incidents(status: status) end |
.list ⇒ Object
List all monitors
98 99 100 101 102 103 104 105 |
# File 'lib/brainzlab/beacon.rb', line 98 def list return [] unless enabled? ensure_provisioned! return [] unless BrainzLab.configuration.beacon_valid? client.list_monitors end |
.pause(id) ⇒ Object
Pause a monitor
128 129 130 131 132 133 134 135 |
# File 'lib/brainzlab/beacon.rb', line 128 def pause(id) return false unless enabled? ensure_provisioned! return false unless BrainzLab.configuration.beacon_valid? client.pause_monitor(id) end |
.provisioner ⇒ Object
194 195 196 |
# File 'lib/brainzlab/beacon.rb', line 194 def provisioner @provisioner ||= Provisioner.new(BrainzLab.configuration) end |
.reset! ⇒ Object
202 203 204 205 206 |
# File 'lib/brainzlab/beacon.rb', line 202 def reset! @client = nil @provisioner = nil @provisioned = false end |
.resume(id) ⇒ Object
Resume a paused monitor
138 139 140 141 142 143 144 145 |
# File 'lib/brainzlab/beacon.rb', line 138 def resume(id) return false unless enabled? ensure_provisioned! return false unless BrainzLab.configuration.beacon_valid? client.resume_monitor(id) end |
.status ⇒ Object
Get overall status summary
158 159 160 161 162 163 164 165 |
# File 'lib/brainzlab/beacon.rb', line 158 def status return nil unless enabled? ensure_provisioned! return nil unless BrainzLab.configuration.beacon_valid? client.status_summary end |
.update(id, **attributes) ⇒ Object
Update a monitor
108 109 110 111 112 113 114 115 |
# File 'lib/brainzlab/beacon.rb', line 108 def update(id, **attributes) return false unless enabled? ensure_provisioned! return false unless BrainzLab.configuration.beacon_valid? client.update_monitor(id, **attributes) end |