Skip to content

Commit

Permalink
Verify prometheus_alerts credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Aug 3, 2020
1 parent 9679f7f commit 2edc625
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,7 @@ def verify_credentials(args)
when 'prometheus'
verify_prometheus_credentials(hostname, port, options)
when 'prometheus_alerts'
# TODO: implement validation calls for these endpoint types
return true
verify_prometheus_alerts_credentials(hostname, port, options)
else
# TODO: maybe we need an error message here
return false
Expand Down Expand Up @@ -768,6 +767,18 @@ def prometheus_connect(hostname, port, options)
def verify_prometheus_credentials(hostname, port, options)
!!prometheus_connect(hostname, port, options)&.query(:query => "ALL")&.kind_of?(Hash)
end

def verify_prometheus_alerts_credentials(hostname, port, options)
!!self.parent::MonitoringManager.verify_credentials(
:url => raw_api_endpoint(hostname, port),
:path => options[:path] || "/topics/alerts",
:credentials => {:token => options[:bearer]},
:ssl => {
:verify => options.dig(:ssl_options, :verify_ssl) != OpenSSL::SSL::VERIFY_NONE,
:cert_store => options.dig(:ssl_options, :ca_file)
}
)
end
end

PERF_ROLLUP_CHILDREN = [:container_nodes]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,18 @@ def self.hostname_required?
end

module ClassMethods
def verify_credentials(options)
raw_connect(options)&.get&.key?('generationID')
rescue OpenSSL::X509::CertificateError => err
raise MiqException::MiqInvalidCredentialsError, "SSL Error: #{err.message}"
rescue Faraday::ParsingError
raise MiqException::MiqUnreachableError, 'Unexpected Response'
rescue Faraday::ClientError => err
raise MiqException::MiqUnreachableError, err.message
rescue StandardError => err
raise MiqException::MiqUnreachableError, err.message, err.backtrace
end

def raw_connect(options)
Prometheus::AlertBufferClient::Client.new(options)
end
Expand Down

0 comments on commit 2edc625

Please sign in to comment.