Skip to content

Commit

Permalink
JSON parse prometheus_alert client responses
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Oct 3, 2024
1 parent a8437b4 commit 5e94700
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 5e94700

Please sign in to comment.