class Fluent::Piin
Public Instance Methods
configure(conf)
click to toggle source
This method is called before starting. 'conf' is a Hash that includes configuration parameters. If the configuration is invalid, raise Fluent::ConfigError.
Calls superclass method
# File lib/fluent/plugin/in_piin.rb, line 35 def configure(conf) super @piwebapiurl = conf['piwebapiurl'] (conf.key?('tagpath')) ? @tagpath = conf['tagpath'] : @tagpath = nil (conf.key?('webid')) ? @webid = conf['webid'] : @webid = nil (conf.key?('username')) ? @username = conf['username'] : @username = nil (conf.key?('pwd')) ? @pwd = conf['pwd'] : @pwd = nil (conf.key?('anon')) ? @anon = conf['anon'] : @anon = false (conf.key?('tag')) ? @tag = conf['tag'] : @tag = 'piin' (conf.key?('regetrate')) ? @regetrate = conf['regetrate'] : @regetrate = 10 end
shutdown()
click to toggle source
This method is called when shutting down. Shutdown the thread and close sockets or files here.
Calls superclass method
# File lib/fluent/plugin/in_piin.rb, line 71 def shutdown super @stop_flag = true $log.debug "Waiting for thread to finish" @thread.join end
start()
click to toggle source
This method is called when starting. Open sockets or files and create a thread here.
Calls superclass method
# File lib/fluent/plugin/in_piin.rb, line 49 def start super if(@webid == nil) url = "https://#{@piwebapiurl}/piwebapi/points/?path=#{@tagpath}" begin client = RestClient::Resource.new(url, :verify_ssl => OpenSSL::SSL::VERIFY_NONE, :user => @username, :password =>@pwd) response = client.get @webid = (JSON.parse(response.body))['WebId'] rescue log.warn "Errors. Web Id not found. Not able to bring in data from the specified address" log.warn url @webid = nil end end @stop_flag = false @thread = Thread.new(&method(:thread_main)) end
thread_main()
click to toggle source
# File lib/fluent/plugin/in_piin.rb, line 78 def thread_main if(@webid == nil) return end url = "https://#{@piwebapiurl}/piwebapi/streams/#{@webid}/value" client = RestClient::Resource.new(url, :verify_ssl => OpenSSL::SSL::VERIFY_NONE,:user => @username, :password =>@pwd) until @stop_flag sleep @regetrate begin response = client.get :content_type => 'application/json' responseObj = JSON.parse(response) time = Time.parse(responseObj['Timestamp']) if (time == nil) time = Engine.now end router.emit(@tag, time, responseObj) rescue => e log.warn "Having problems connecting to PI WebAPI. Will try again." end end end