Class: AiRootShield::Enterprise::WebhookChannel
- Inherits:
-
Object
- Object
- AiRootShield::Enterprise::WebhookChannel
- Defined in:
- lib/ai_root_shield/enterprise/alert_system.rb
Overview
Webhook channel implementation
Instance Method Summary collapse
-
#initialize(config) ⇒ WebhookChannel
constructor
A new instance of WebhookChannel.
- #send_alert(alert) ⇒ Object
Constructor Details
#initialize(config) ⇒ WebhookChannel
Returns a new instance of WebhookChannel.
407 408 409 |
# File 'lib/ai_root_shield/enterprise/alert_system.rb', line 407 def initialize(config) @config = config end |
Instance Method Details
#send_alert(alert) ⇒ Object
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/ai_root_shield/enterprise/alert_system.rb', line 411 def send_alert(alert) return { success: false, error: "No webhook URL configured" } unless @config[:url] uri = URI(@config[:url]) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = uri.scheme == 'https' http.read_timeout = @config[:timeout] || 30 request = Net::HTTP::Post.new(uri) request['Content-Type'] = 'application/json' # Add custom headers @config[:headers]&.each do |key, value| request[key] = value end request.body = format_webhook_payload(alert) response = http.request(request) if response.code.to_i.between?(200, 299) { success: true, channel: 'webhook', response_code: response.code } else { success: false, error: "HTTP #{response.code}: #{response.body}", channel: 'webhook' } end rescue StandardError => e { success: false, error: e., channel: 'webhook' } end |