Cannot load such file -- chef-handler-httpapi

I want to add httpapi handler
Here is my cookbook

chef_gem 'chef-handler-httpapi'

template "/etc/chef/client.d/httpapi_handler.rb" do
  source "httpapi_handler.rb.erb"
  mode '0644'
  notifies :create, "ruby_block[reload_client_config]"
end

include_recipe 'chef-client::config'

/etc/chef/client.d/httpapi_handler.rb

require "chef-handler-httpapi"

api_url = "http://example.com/api/alerts"
api_user = admin
api_pass = pass

# ssl tweaks
(api_ssl_version = :SSLv3)
(api_ssl_verify = "none")

# name for data_message KEY
api_data_message = "message"

# keys and values for successful run
api_data_success = {
	"state" => "INFO",
	"class" => "chef-client"
}

# keys and values for failed run
api_data_failed = {
	"state" => "FAILED",
	"class" => "chef-client"
}

Httpapi_handler = Httpapi.new(api_url, api_user, api_pass, api_ssl_verify, api_ssl_version, api_data_message, api_data_success, api_data_failed)
report_handlers << Httpapi_handler            # run at the end of a successful run
exception_handlers << Httpapi_handler         # run at the end of a failed run

When I run chef-client I get

[2018-02-06T09:47:11+00:00] FATAL: Configuration error LoadError: cannot load such file -- chef-handler-httpapi
[2018-02-06T09:47:11+00:00] FATAL:   /etc/chef/client.d/httpapi_handler.rb:1:in `from_string'
[2018-02-06T09:47:11+00:00] FATAL: Aborting due to error in '/etc/chef/client.d/httpapi_handler.rb'

chef_gem is installed

/opt/chef/embedded/bin/gem list | grep http
chef-handler-httpapi (0.0.2)

Chef Client, version 12.21.31

  • chef-client (9.0.5)
  • chef_handler (3.0.2)

The require method in ruby refers to the paths to the ruby files, which for plugin-y gems can be a bit different than the gem name. I looked at the repo in question, and while their README says require "chef-handler-httpapi", based on the paths in the repo it looks like it would instead be require "chef/handler/Httpapi"

You might want to file an issue for that one.

Thanks, it was the point. I’ll post the issue.

Just saw, that we use require 'Httpapi.rb' in our setup, which works out.
Are you fine with me updating the README like this?

I fixed this in https://github.com/b1-systems/chef-handler-httpapi/commit/d8b362315a5d19175c4f0665a63fed80c8fccc70