Class: LogStash::Inputs::OpenWhisk

Inherits:
Base
  • Object
show all
Includes:
PluginMixins::HttpClient
Defined in:
lib/logstash/inputs/openwhisk.rb

Overview

This Logstash input plugin allows you to drain OpenWhisk Activation logs, decoding the output into event(s), and send them on their merry way. Using the OpenWhisk platform API, we poll the activation logs API according to the config schedule. This plugin borrows heavily from the HTTP Poller input plugin.

Example

Drain logs from an OpenWhisk platform instance. The config should look like this:

source,ruby

input

openwhisk {
  # Mandatory Configuration Parameters
  hostname => "openwhisk.ng.bluemix.net"
  username => "[email protected]"
  password => "some_password"
  # Supports "cron", "every", "at" and "in" schedules by rufus scheduler
  schedule => { cron => "* * * * * UTC"

  # Optional Configuration Parameters
  # Namespace is optional, defaults to user's default namespace.
  namespace => ""
  request_timeout => 60
  codec => "json"
  # A hash of request metadata info (timing, response headers, etc.) will be sent here
  metadata_target => "http_poller_metadata"
}

}

output {

stdout {
  codec => rubydebug
}

}


Constant Summary collapse

Schedule_types =
%w(cron every at in)

Instance Method Summary collapse

Instance Method Details

#registerObject



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/logstash/inputs/openwhisk.rb', line 88

def register
  @host = Socket.gethostname.force_encoding(Encoding::UTF_8)

  @logger.info("Registering openwhisk Input", :type => @type,
               :hostname=> @hostname, :interval => @interval, :schedule => @schedule, :timeout => @timeout)

  # we will start polling for logs since the current epoch
  @logs_since = Time.now.to_i * 1000

  # activation ids from previous poll used to control what is indexed,
  # we might have overlapping results and don't want to index the same
  # activations twice.
  @activation_ids = Set.new
end

#run(queue) ⇒ Object

Raises:

  • (LogStash::ConfigurationError)


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/logstash/inputs/openwhisk.rb', line 118

def run(queue)
  #interval or schedule must be provided. Must be exclusively either one. Not neither. Not both.
  raise LogStash::ConfigurationError, "Invalid config. Neither interval nor schedule was specified." \
    unless @interval ||  @schedule
  raise LogStash::ConfigurationError, "Invalid config. Specify only interval or schedule. Not both." \
    if @interval && @schedule

  if @interval
    setup_interval(queue)
  elsif @schedule
    setup_schedule(queue)
  else
    #should not reach here
    raise LogStash::ConfigurationError, "Invalid config. Neither interval nor schedule was specified."
  end
end

#stopObject



103
104
105
106
# File 'lib/logstash/inputs/openwhisk.rb', line 103

def stop
  Stud.stop!(@interval_thread) if @interval_thread
  @scheduler.stop if @scheduler
end