首页 > 解决方案 > 在 ArchivesSpace 中编写简单的插件

问题描述

我正在以归档空间插件的形式为我们的归档空间实例编写一个健康检查插件。它是一个 Jruby 应用程序,插件的说明类似于 Ruby on Rails。在 rails 应用程序上似乎很简单但是当我按照插件文档但它仍然无法正常工作时,有人能指出我正确的方向吗,我基本上只需要存档空间 Url :/plugins/healthcheck/ 来点击存档空间接口 url,如果它响应 200 响应,则让页面在 html 中指示成功消息。以下是代码片段,感谢任何帮助!

-plugins
    -healthcheck
        -backend
            -healthcheck. rb
       -frontend
             -controller
                - healthcheck_controller.rb

健康检查.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

标签: rubyjruby

解决方案


推荐阅读