{"record":{"id":"f5bc61e5283a5df6","repo":"ytti/oxidized","slug":"mechanize-not-found-sudo-gem-install-mechanize","errorCode":null,"errorMessage":"mechanize not found: sudo gem install mechanize","messagePattern":"mechanize not found: sudo gem install mechanize","errorType":"exception","errorClass":"OxidizedError","httpStatus":null,"severity":"error","filePath":"lib/oxidized/input/http.rb","lineNumber":20,"sourceCode":"  require \"net/http\"\n  require \"json\"\n  require \"net/http/digest_auth\"\n\n  class HTTP < Input\n    def connect(node)\n      @node = node\n      @secure = false\n      @username = nil\n      @password = nil\n      @headers = {}\n      @node.model.cfg[\"http\"].each { |cb| instance_exec(&cb) }\n\n      return true unless @main_page && defined?(login)\n\n      begin\n        require \"mechanize\"\n      rescue LoadError\n        raise OxidizedError, \"mechanize not found: sudo gem install mechanize\"\n      end\n\n      @m = Mechanize.new\n      url = URI::HTTP.build host: @node.ip, path: @main_page\n      @m_page = @m.get(url.to_s)\n      login\n    end\n\n    def cmd(callback_or_string)\n      return cmd_cb callback_or_string if callback_or_string.is_a?(Proc)\n\n      cmd_str callback_or_string\n    end\n\n    def cmd_cb(callback)\n      instance_exec(&callback)\n    end\n","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/ytti/oxidized/blob/687ed4262d9d21e54662e872e2383386d8498f7b/lib/oxidized/input/http.rb#L2-L38","documentation":"The HTTP input needs mechanize only when the node's model defines main_page together with a login callback (form-based login); connect then lazily requires 'mechanize' and converts LoadError into OxidizedError 'mechanize not found: sudo gem install mechanize' (lib/oxidized/input/http.rb:17-21). Without a login flow the input uses plain Net::HTTP and the gem is never required, so the error only appears for login-protected HTTP models.","triggerScenarios":"Setting input: http on a node whose model has main_page (e.g. main_page '/login.html') and a login block, while the mechanize gem is not installed in the Ruby/gemset that actually runs oxidized (distro package install, bundler project without the gem, or a container image missing it).","commonSituations":"Installing oxidized via apt/deb where mechanize is an optional extra; running under bundler with a Gemfile that omits mechanize; switching a device from ssh/telnet to http input with a login page; CI or docker images built before any http-login model was used.","solutions":["Install the gem into the same Ruby oxidized runs with: sudo gem install mechanize (for distro packages, in the system gem home; for bundler, add gem 'mechanize' to the Gemfile and run bundle install)","Verify with the service context: gem list mechanize and ruby -e \"require 'mechanize'\" using the same RUBY/GEM_HOME oxidized uses (check gem env)","If the device needs no form login, remove main_page/login from the model so the plain Net::HTTP path runs without mechanize","Rebuild docker images to include mechanize when any http model uses login"],"exampleFix":"# before (Gemfile)\ngem 'oxidized'\n# runtime: OxidizedError: mechanize not found: sudo gem install mechanize\n\n# after (Gemfile)\ngem 'oxidized'\ngem 'mechanize'\n# then: bundle install","handlingStrategy":"validation","validationCode":"# fail fast at boot when any http model uses a login flow\nbegin\n  gem 'mechanize'\nrescue Gem::LoadError\n  warn 'mechanize is missing: http input with login will raise OxidizedError'; exit 1\nend","typeGuard":"def mechanize_available?\n  require 'mechanize'\n  true\nrescue LoadError\n  false\nend","tryCatchPattern":"begin\n  input.connect(node)\nrescue OxidizedError => e\n  logger.error \"#{node.name}: #{e.message}\"\n  raise\nend","preventionTips":["Pin mechanize in the same Gemfile/lockfile as oxidized whenever an http model uses login","Bake gem checks into container builds: RUN gem install mechanize","After switching rubies or upgrade paths, run ruby -e \"require 'mechanize'\" as the service user"],"tags":["oxidized","http-input","mechanize","ruby-gem","loaderror","optional-dependency"],"backgroundTag":"missing-gem-dependency","analyzedSha":"687ed4262d9d21e54662e872e2383386d8498f7b","analyzedAt":"2026-08-23T11:19:42.084Z","schemaVersion":2},"datasetVersion":"2026-08-23T16:17:53.355Z"}