Class: Fluent::Piin
- Inherits:
-
Input
- Object
- Input
- Fluent::Piin
- Defined in:
- lib/fluent/plugin/in_piin.rb
Instance Method Summary collapse
-
#configure(conf) ⇒ Object
This method is called before starting.
-
#shutdown ⇒ Object
This method is called when shutting down.
-
#start ⇒ Object
This method is called when starting.
- #thread_main ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
This method is called before starting. ‘conf’ is a Hash that includes configuration parameters. If the configuration is invalid, raise Fluent::ConfigError.
35 36 37 38 39 40 41 42 43 44 45 |
# 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 ⇒ Object
This method is called when shutting down. Shutdown the thread and close sockets or files here.
71 72 73 74 75 76 |
# 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 ⇒ Object
This method is called when starting. Open sockets or files and create a thread here.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# 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 |