class Fluent::Pi
Constants
- DEFAULT_FORMAT_TYPE
Attributes
delayed[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_pi.rb, line 52 def initialize super @delayed = false end
Public Instance Methods
configure(conf)
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_pi.rb, line 57 def configure(conf) if conf['output_type'] && !conf['format'] conf['format'] = conf['output_type'] end compat_parameters_convert(conf, :inject, :formatter) super @formatter = formatter_create(conf: conf.elements('format').first, default_type: DEFAULT_FORMAT_TYPE) #set piwebapi URI information @piwebapiserver = conf['piwebapiserver'] (conf.key?('tagpath')) ? @tagpath = conf['tagpath'] : @tagpath = nil (conf.key?('attpath')) ? @attpath = conf['attpath'] : @attpath = nil if(@tagpath == nil && @attpath == nil) $log.write("Neither a tag nor attribute is specified. Unable to log to PI.\n") return end if(@tagpath != nil && @attpath != nil) $log.write("Both a tag and attribute is specified. Using the attribute.\n") end (conf.key?('valuetag')) ? @valuetag = conf['valuetag'] : @valuetag = 'Value' (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?('webid')) ? @webid = conf['webid'] : @webid = nil if((@username == nil) && !@anon) $log.write("Please specify a username, or specify that anonymous will be used.\n") return end end
format(tag, time, record)
click to toggle source
# File lib/fluent/plugin/out_pi.rb, line 145 def format(tag, time, record) value = record[@valuetag].to_s "{\"Timestamp\":\"#{Time.at(time).localtime}\",\"Value\":\"#{value}\"}," end
prefer_buffered_processing()
click to toggle source
# File lib/fluent/plugin/out_pi.rb, line 42 def prefer_buffered_processing false end
prefer_delayed_commit()
click to toggle source
# File lib/fluent/plugin/out_pi.rb, line 46 def prefer_delayed_commit @delayed end
start()
click to toggle source
Calls superclass method
# File lib/fluent/plugin/out_pi.rb, line 95 def start super # need to populate webid if not provided if(@webid != nil) return end client = nil #PI Web API search doesn't work from basic or anonymous. Kerberos from Ruby isn't working. I think we have to use the absolute path. With Kerberos we could looking based on search and use top result if(@attpath == nil) url = "https://#{@piwebapiserver}/piwebapi/points/?path=#{@tagpath}" if(@anon) client = RestClient::Resource.new(url, :verify_ssl => OpenSSL::SSL::VERIFY_NONE ) else client = RestClient::Resource.new(url, :verify_ssl => OpenSSL::SSL::VERIFY_NONE, :user => @username, :password =>@pwd) end else url = "https://#{@piwebapiserver}/piwebapi/attributes/?path=#{@attpath}" if(@anon) client = RestClient::Resource.new(url, :verify_ssl => OpenSSL::SSL::VERIFY_NONE ) else client = RestClient::Resource.new(url, :verify_ssl => OpenSSL::SSL::VERIFY_NONE, :user => @username, :password =>@pwd) end end response = client.get @webid = (JSON.parse(response.body))['WebId'] if(@webid == nil) $log.write("WedID is lost. Unable to log to PI\n") return end @writeURL = "https://#{@piwebapiserver}/piwebapi/streams/#{@webid}/recorded" if(@anon) @writeclient = RestClient::Resource.new(@writeURL, :verify_ssl => OpenSSL::SSL::VERIFY_NONE) else @writeclient = RestClient::Resource.new(@writeURL, :verify_ssl => OpenSSL::SSL::VERIFY_NONE,:user => @username, :password =>@pwd) end end
write(chunk)
click to toggle source
# File lib/fluent/plugin/out_pi.rb, line 137 def write(chunk) data= chunk.read jsonObj = "[" + data.chop + "]" # removes trailing ',' and makes a valid json object response = @writeclient.post jsonObj, :content_type => 'application/json' $log.write("PI successful writes\n") end