I’m automating a legacy web server. As part of the validation of the webserver, I need to scrape localhost/foobar to see if it contains the html body ‘Alive’
The following works, but:
- feels not very ‘chef-y’, I’d rather not depend on nokogiri.
- throws an ugly error
ruby_block 'validate legacy web health' do
block do
require 'nokogiri'
doc = Nokogiri::HTML(open('http://localhost/foobar.aspx'))
result = doc.at('body').content
if result.strip.chomp != 'Alive'
Chef::Application.fatal!('Web health checked failed')
end
end
action :run
only_if { node['roles'].include?('legacy-web') }
end
A better solution would be to use return codes (e.g 200, 500) however dev says they won’t refactor.
The body that the web server returns on success.
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
Alive
</body>
</html>
I don’t see a way in the Chef::HTML class to parse html and return just the body.
Is there a cleaner way to do this?