From 5e9470021bd72cf47fda31aa839d7f536b8ed07a Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Thu, 3 Oct 2024 10:10:45 -0400 Subject: [PATCH] JSON parse prometheus_alert client responses --- .../manageiq/providers/kubernetes/monitoring_manager.rb | 8 ++++++-- .../kubernetes/monitoring_manager/event_catcher/stream.rb | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/models/manageiq/providers/kubernetes/monitoring_manager.rb b/app/models/manageiq/providers/kubernetes/monitoring_manager.rb index 13e93db054..da87015701 100644 --- a/app/models/manageiq/providers/kubernetes/monitoring_manager.rb +++ b/app/models/manageiq/providers/kubernetes/monitoring_manager.rb @@ -38,7 +38,9 @@ def self.event_monitor_class end def self.verify_credentials(options) - raw_connect(options)&.get&.key?('generationID') + response = raw_connect(options)&.get + response = JSON.parse(response) if response.kind_of?(String) + response.key?('generationID') if response rescue OpenSSL::X509::CertificateError => err raise MiqException::MiqInvalidCredentialsError, "SSL Error: #{err.message}" rescue Faraday::ParsingError @@ -60,7 +62,9 @@ def prometheus_alerts_endpoint def verify_credentials(_auth_type = nil, _options = {}) with_provider_connection do |conn| - conn.get.key?('generationID') + response = conn.get + response = JSON.parse(response) if response.kind_of?(String) + response.key?('generationID') end rescue OpenSSL::X509::CertificateError => err raise MiqException::MiqInvalidCredentialsError, "SSL Error: #{err.message}" diff --git a/app/models/manageiq/providers/kubernetes/monitoring_manager/event_catcher/stream.rb b/app/models/manageiq/providers/kubernetes/monitoring_manager/event_catcher/stream.rb index bc1572412b..cbaf48fde7 100644 --- a/app/models/manageiq/providers/kubernetes/monitoring_manager/event_catcher/stream.rb +++ b/app/models/manageiq/providers/kubernetes/monitoring_manager/event_catcher/stream.rb @@ -42,6 +42,7 @@ def fetch # } alert_list = @ems.connect.get(:generation_id => @current_generation, :from_index => @current_index) alerts = [] + alert_list = JSON.parse(alert_list) if alert_list.kind_of?(String) @current_generation = alert_list["generationID"] return alerts if alert_list['messages'].blank? alert_list["messages"].each do |message|