我正在以archivespace插件的形式为我们的archivesspace实例编写一个运行状况检查插件。这是一个Jruby应用程序,其插件说明类似于Ruby on Rails。在Rails应用程序上看起来足够简单,但是当我遵循插件文档但仍然无法正常工作时,有人可以向我指出正确的方向,我基本上只需要拥有archivespace Url:/ plugins / healthcheck /来访问archivespace接口网址,如果它响应200,则该页面以html表示成功消息。下面是代码片段,感谢您的任何帮助!
-plugins
-healthcheck
-backend
-healthcheck. rb
-frontend
-controller
- healthcheck_controller.rb
healthcheck.rb
class ArchivesSpaceService < Sinatra::Base
Endpoint.get('/healthcheck')
.returns([200, "{'reply', 'status:ok'}"]) \
end
healthcheck_controller.rb
require 'net/http'
require 'socket'
class ApplicationController < ActionController::Base
def healthcheck
hostname = "status of server " + Socket.gethostname
uri = 'http://example.com/index.html'
status_message = "System OK"
datetime = Time.now
begin
res = Net::HTTP.get_response(URI(uri))
status_code = res.code.to_i
if status_code > 399
status_code = 424
status_message = "One or more services are currently impacted"
img = "/img/fail.png"
else
img = "/img/pass.png"
end
render text: "<h>#{hostname} #{status_code} </h>ArchivesSpace Ok?:<br><img src='#{img}'> #{uri}<br><br>status:ok<br>" , status: status_code
end
end
end