Class: AiRootShield::Enterprise::SlackChannel
- Inherits:
-
Object
- Object
- AiRootShield::Enterprise::SlackChannel
- Defined in:
- lib/ai_root_shield/enterprise/alert_system.rb
Overview
Slack channel implementation
Instance Method Summary collapse
-
#initialize(config) ⇒ SlackChannel
constructor
A new instance of SlackChannel.
- #send_alert(alert) ⇒ Object
Constructor Details
#initialize(config) ⇒ SlackChannel
Returns a new instance of SlackChannel.
459 460 461 |
# File 'lib/ai_root_shield/enterprise/alert_system.rb', line 459 def initialize(config) @config = config end |
Instance Method Details
#send_alert(alert) ⇒ Object
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/ai_root_shield/enterprise/alert_system.rb', line 463 def send_alert(alert) return { success: false, error: "No Slack webhook URL configured" } unless @config[:webhook_url] payload = format_slack_payload(alert) uri = URI(@config[:webhook_url]) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri) request['Content-Type'] = 'application/json' request.body = payload.to_json response = http.request(request) if response.code == '200' { success: true, channel: 'slack' } else { success: false, error: "Slack API error: #{response.body}", channel: 'slack' } end rescue StandardError => e { success: false, error: e., channel: 'slack' } end |