theforeman / smart_proxy_monitoring

Smart proxy plugin for monitoring system integration
GNU General Public License v3.0
7 stars 10 forks source link

Integration with Icingadirector flaky on Host rebuild #19

Closed mattiascockburn closed 6 years ago

mattiascockburn commented 6 years ago

Heya, experiencing the following with Foreman 1.17.1 and smart_proxy_monitoring-0.1.1: Upon host rebuild, the smart proxy tries to update host attributes in Icinga. If nothing changed between the initial creation of the host and the rebuild icinga-director will return HTTP 304 Not Modified. This leads to an exception in the smart proxy which prevents the rebuild of the host:

D, [2018-06-11T05:21:53.690435 ] DEBUG -- : close: PUPPETIP:32794
D, [2018-06-11T05:21:53.733873 ] DEBUG -- : accept: PUPPETIP:32804
D, [2018-06-11T05:21:53.734999 ] DEBUG -- : Rack::Handler::WEBrick is invoked.
D, [2018-06-11T05:21:53.738141 2475659a] DEBUG -- : verifying remote client PUPPETIP against trusted_hosts ["puppet.mydomain.tld"]
D, [2018-06-11T05:21:53.738473 2475659a] DEBUG -- : Updating host myhost-sle12sp2.mydomain.tld object with attributes {"ip"=>"HOSTIP", "ip6"=>nil, "architecture"=>"x86_64", "os"=>"SLES 12 SP2", "osfamily"=>"Suse", "virtual"=>"true", "provider"=>"VMware", "compute_resource"=>"Blade.cloud (VMware)", "hostgroup"=>"Baseline/Testsystems", "organization"=>nil, "location"=>nil, "comment"=>"", "environment"=>"ansible", "owner_name"=>"Configurationmanagement"}
D, [2018-06-11T05:21:53.738583 2475659a] DEBUG -- : IcingaDirector: GET request to host?name=foreman_host
D, [2018-06-11T05:21:53.951173 2475659a] DEBUG -- : IcingaDirector: PUT request to host?name=myhost-sle12sp2.mydomain.tld with payload: {"object_name":"myhost-sle12sp2.mydomain.tld","object_type":"object","address":"HOSTIP","address6":null,"imports":["foreman_host"],"vars":{"architecture":"x86_64","os":"SLES 12 SP2","osfamily":"Suse","virtual":"true","provider":"VMware","compute_resource":"Blade.cloud (VMware)","hostgroup":"Baseline/Testsystems","organization":null,"location":null,"comment":"","environment":"ansible","owner_name":"Configurationmanagement"}}
E, [2018-06-11T05:21:54.171104 2475659a] ERROR -- : Error connecting to Icinga Director at http://icinga.mydomain.tld/icingaweb2/director/host?name=myhost-sle12sp2.mydomain.tld: 304 Not Modified
D, [2018-06-11T05:21:54.171214 2475659a] DEBUG -- : Error connecting to Icinga Director at http://icinga.mydomain.tld/icingaweb2/director/host?name=myhost-sle12sp2.mydomain.tld: 304 Not Modified (Proxy::Monitoring::Error)

The smart proxy will succeed if i change or add any attribute in icinga-director before initiating the rebuild

Hacky workaround which surely introduces other issues:

--- /usr/share/gems/gems/smart_proxy_monitoring-0.1.1/lib/smart_proxy_monitoring_icingadirector/director_client.rb      2018-06-11 05:47:25.471955728 +0000
+++ /usr/share/gems/gems/smart_proxy_monitoring-0.1.1/lib/smart_proxy_monitoring_icingadirector/director_client_patched.rb      2018-06-11 05:46:52.666137786 +0000
@@ -38,7 +38,8 @@
       logger.debug "IcingaDirector: PUT request to #{url} with payload: #{payload}"
       client(url).put(payload).body
     rescue StandardError => e
-      raise handle_http_exception(e, url)
+      # HACKHACKHACK
+      raise handle_http_exception(e, url) unless e.http_code == 304
     end

     def delete(url)
timogoebel commented 6 years ago

@mattiasgiese: Thanks, that almost looks like a ready to use bugfix. I'd suggest to rescue the exception like this, though: https://github.com/theforeman/smart_proxy_monitoring/blob/578168a9b29575b797b1ee67350cf6347021b86d/lib/smart_proxy_monitoring_icingadirector/monitoring_icingadirector_main.rb#L22-L23

Do you feel comfortable opening a PR with these changes?

mattiascockburn commented 6 years ago

@timogoebel Yup, i'll prepare that in the morning. Cheers!

mattiascockburn commented 6 years ago

@timogoebel I guess there is no need for that. It seems you already fixed it in 3792137f88854e84638ae02aab2af21f7e14865d

timogoebel commented 6 years ago

@mattiasgiese: Perfect, thanks for your time. I just released 0.1.2 that includes the latest fixes.