logstash-input-google_pubsub 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/CONTRIBUTING.md +9 -0
- data/Gemfile +2 -0
- data/LICENSE +13 -0
- data/NOTICE.TXT +13 -0
- data/README.md +199 -0
- data/lib/logstash/inputs/google_pubsub.rb +185 -0
- data/logstash-input-google_pubsub.gemspec +29 -0
- data/spec/inputs/google_pubsub_spec.rb +45 -0
- metadata +145 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5833affff693fc86005d9fd0f29215e8eeb9f154
|
4
|
+
data.tar.gz: f65d91acd4a6c805a3587558a7ef8c252c1435ed
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96b4e044b16625abc380a4372da3b3c63dd856b7070c7e11ff255a73acdc586054be168d3cd7f66e53a7ca352c2663bf29989c850e00a535ea4472cedceda87b
|
7
|
+
data.tar.gz: 2ee4c5fc0519b9689618b5dfab52232389e4e6c900d4ea632dff96577f948e84b411c7b9f04a68222a2d47aec8be22868bd196456c7c23c67bfdd07d95543d14
|
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
# Contributing
|
2
|
+
|
3
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
4
|
+
|
5
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
6
|
+
|
7
|
+
It is more important to the community that you are able to contribute.
|
8
|
+
|
9
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file.
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/NOTICE.TXT
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright 2016 Google Inc. All Rights Reserved.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
# Logstash Plugin
|
2
|
+
|
3
|
+
[![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-input-google_pubsub.svg)](https://travis-ci.org/logstash-plugins/logstash-input-google_pubsub)
|
4
|
+
|
5
|
+
This is a [Logstash](https://github.com/elastic/logstash) input plugin for
|
6
|
+
[Google Pub/Sub](https://cloud.google.com/pubsub/). The plugin can subscribe
|
7
|
+
to a topic and ingest messages.
|
8
|
+
|
9
|
+
The main motivation behind the development of this plugin was to ingest
|
10
|
+
[Stackdriver Logging](https://cloud.google.com/logging/) messages via the
|
11
|
+
[Exported Logs](https://cloud.google.com/logging/docs/export/using_exported_logs)
|
12
|
+
feature of Stackdriver Logging.
|
13
|
+
|
14
|
+
It is fully free and fully open source. The license is Apache 2.0, meaning you
|
15
|
+
are pretty much free to use it however you want in whatever way.
|
16
|
+
|
17
|
+
## Documentation
|
18
|
+
|
19
|
+
### Prerequisites
|
20
|
+
|
21
|
+
You must first create a Google Cloud Platform project and enable the the
|
22
|
+
Google Pub/Sub API. If you intend to use the plugin ingest Stackdriver Logging
|
23
|
+
messages, you must also enable the Stackdriver Logging API and configure log
|
24
|
+
exporting to Pub/Sub. There is plentiful information on
|
25
|
+
https://cloud.google.com/ to get started,
|
26
|
+
|
27
|
+
- Google Cloud Platform Projects and [Overview](https://cloud.google.com/docs/overview/)
|
28
|
+
- Goolge Cloud Pub/Sub [documentation](https://cloud.google.com/pubsub/)
|
29
|
+
- Stackdriver Logging [documentation](https://cloud.google.com/logging/)
|
30
|
+
|
31
|
+
### Cloud Pub/Sub
|
32
|
+
|
33
|
+
Currently, this module requires you to create a `topic` manually and specify
|
34
|
+
it in the logstash config file. You must also specify a `subscription`, but
|
35
|
+
the plugin will attempt to create the pull-based `subscription` on its own.
|
36
|
+
|
37
|
+
All messages received from Pub/Sub will be converted to a logstash `event`
|
38
|
+
and added to the processing pipeline queue. All Pub/Sub messages will be
|
39
|
+
`acknowledged` and removed from the Pub/Sub `topic` (please see more about
|
40
|
+
[Pub/Sub concepts](https://cloud.google.com/pubsub/overview#concepts)).
|
41
|
+
|
42
|
+
It is generally assumed that incoming messages will be in JSON and added to
|
43
|
+
the logstash `event` as-is. However, if a plain text message is received, the
|
44
|
+
plugin will return the raw text in as `raw_message` in the logstash `event`.
|
45
|
+
|
46
|
+
#### Authentication
|
47
|
+
|
48
|
+
You have two options for authentication depending on where you run Logstash.
|
49
|
+
|
50
|
+
1. If you are running Logstash outside of Google Cloud Platform, then you will
|
51
|
+
need to create a Google Cloud Platform Service Account and specify the full
|
52
|
+
path to the JSON private key file in your config. You must assign sufficient
|
53
|
+
roles to the Service Account to create a subscription and to pull messages
|
54
|
+
from the subscription. Learn more about GCP Service Accounts and IAM roles
|
55
|
+
here:
|
56
|
+
|
57
|
+
- Google Cloud Platform IAM [overview](https://cloud.google.com/iam/)
|
58
|
+
- Creating Service Accounts [overview](https://cloud.google.com/iam/docs/creating-managing-service-accounts)
|
59
|
+
- Granting Roles [overview](https://cloud.google.com/iam/docs/granting-roles-to-service-accounts)
|
60
|
+
|
61
|
+
1. If you are running Logstash on a Google Compute Engine instance, you may opt
|
62
|
+
to use Application Default Credentials. In this case, you will not need to
|
63
|
+
specify a JSON private key file in your config.
|
64
|
+
|
65
|
+
### Stackdriver Logging (optional)
|
66
|
+
|
67
|
+
If you intend to use the logstash plugin for Stackdriver Logging message
|
68
|
+
ingestion, you must first manually set up the Export option to Coud Pub/Sub and
|
69
|
+
the manually create the `topic`. Please see the more detailed instructions at,
|
70
|
+
[Exported Logs](https://cloud.google.com/logging/docs/export/using_exported_logs)
|
71
|
+
and ensure that the [necessary permissions](https://cloud.google.com/logging/docs/export/configure_export#manual-access-pubsub)
|
72
|
+
have also been manually configured.
|
73
|
+
|
74
|
+
Logging messages from Stackdriver Logging exported to Pub/Sub are received as
|
75
|
+
JSON and converted to a logstash `event` as-is in
|
76
|
+
[this format](https://cloud.google.com/logging/docs/export/using_exported_logs#log_entries_in_google_pubsub_topics).
|
77
|
+
|
78
|
+
### Sample Configuration
|
79
|
+
|
80
|
+
Below is a copy of the included `example.conf-tmpl` file that shows a basic
|
81
|
+
configuration for this plugin.
|
82
|
+
|
83
|
+
```
|
84
|
+
input {
|
85
|
+
google_pubsub {
|
86
|
+
# Your GCP project id (name)
|
87
|
+
project_id => "my-project-1234"
|
88
|
+
|
89
|
+
# The topic name below is currently hard-coded in the plugin. You
|
90
|
+
# must first create this topic by hand and ensure you are exporting
|
91
|
+
# logging to this pubsub topic.
|
92
|
+
topic => "logstash-input-dev"
|
93
|
+
|
94
|
+
# The subscription name is customizeable. The plugin will attempt to
|
95
|
+
# create the subscription (but use the hard-coded topic name above).
|
96
|
+
subscription => "logstash-sub"
|
97
|
+
|
98
|
+
# If you are running logstash within GCE, it will use
|
99
|
+
# Application Default Credentials and use GCE's metadata
|
100
|
+
# service to fetch tokens. However, if you are running logstash
|
101
|
+
# outside of GCE, you will need to specify the service account's
|
102
|
+
# JSON key file below.
|
103
|
+
#json_key_file => "/home/erjohnso/pkey.json"
|
104
|
+
}
|
105
|
+
}
|
106
|
+
|
107
|
+
output { stdout { codec => rubydebug } }
|
108
|
+
```
|
109
|
+
|
110
|
+
## (stock) Documentation
|
111
|
+
|
112
|
+
Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elastic.co/guide/en/logstash/current/).
|
113
|
+
|
114
|
+
- For formatting code or config example, you can use the asciidoc `[source,ruby]` directive
|
115
|
+
- For more asciidoc formatting tips, see the excellent reference here https://github.com/elastic/docs#asciidoc-guide
|
116
|
+
|
117
|
+
## Need Help?
|
118
|
+
|
119
|
+
Need help? Try #logstash on freenode IRC or the https://discuss.elastic.co/c/logstash discussion forum.
|
120
|
+
|
121
|
+
## Developing
|
122
|
+
|
123
|
+
### 1. Plugin Developement and Testing
|
124
|
+
|
125
|
+
#### Code
|
126
|
+
- To get started, you'll need JRuby with the Bundler gem installed.
|
127
|
+
|
128
|
+
- Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. We also provide [example plugins](https://github.com/logstash-plugins?query=example).
|
129
|
+
|
130
|
+
- Install dependencies
|
131
|
+
```sh
|
132
|
+
bundle install
|
133
|
+
```
|
134
|
+
|
135
|
+
#### Test
|
136
|
+
|
137
|
+
- Update your dependencies
|
138
|
+
|
139
|
+
```sh
|
140
|
+
bundle install
|
141
|
+
```
|
142
|
+
|
143
|
+
- Run tests
|
144
|
+
|
145
|
+
```sh
|
146
|
+
bundle exec rspec
|
147
|
+
```
|
148
|
+
|
149
|
+
### 2. Running your unpublished Plugin in Logstash
|
150
|
+
|
151
|
+
#### 2.1 Run in a local Logstash clone
|
152
|
+
|
153
|
+
- Edit Logstash `Gemfile` and add the local plugin path, for example:
|
154
|
+
```ruby
|
155
|
+
gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome"
|
156
|
+
```
|
157
|
+
- Install plugin
|
158
|
+
```sh
|
159
|
+
# Logstash 2.3 and higher
|
160
|
+
bin/logstash-plugin install --no-verify
|
161
|
+
|
162
|
+
# Prior to Logstash 2.3
|
163
|
+
bin/plugin install --no-verify
|
164
|
+
|
165
|
+
```
|
166
|
+
- Run Logstash with your plugin
|
167
|
+
```sh
|
168
|
+
bin/logstash -e 'filter {awesome {}}'
|
169
|
+
```
|
170
|
+
At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash.
|
171
|
+
|
172
|
+
#### 2.2 Run in an installed Logstash
|
173
|
+
|
174
|
+
You can use the same **2.1** method to run your plugin in an installed Logstash by editing its `Gemfile` and pointing the `:path` to your local plugin development directory or you can build the gem and install it using:
|
175
|
+
|
176
|
+
- Build your plugin gem
|
177
|
+
```sh
|
178
|
+
gem build logstash-filter-awesome.gemspec
|
179
|
+
```
|
180
|
+
- Install the plugin from the Logstash home
|
181
|
+
```sh
|
182
|
+
# Logstash 2.3 and higher
|
183
|
+
bin/logstash-plugin install --no-verify
|
184
|
+
|
185
|
+
# Prior to Logstash 2.3
|
186
|
+
bin/plugin install --no-verify
|
187
|
+
|
188
|
+
```
|
189
|
+
- Start Logstash and proceed to test the plugin
|
190
|
+
|
191
|
+
## Contributing
|
192
|
+
|
193
|
+
All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin.
|
194
|
+
|
195
|
+
Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here.
|
196
|
+
|
197
|
+
It is more important to the community that you are able to contribute.
|
198
|
+
|
199
|
+
For more information about contributing, see the [CONTRIBUTING](https://github.com/elastic/logstash/blob/master/CONTRIBUTING.md) file
|
@@ -0,0 +1,185 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
# Author: Eric Johnson <erjohnso@google.com>
|
4
|
+
# Date: 2016-06-01
|
5
|
+
#
|
6
|
+
# Copyright 2016 Google Inc.
|
7
|
+
#
|
8
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
17
|
+
# See the License for the specific language governing permissions and
|
18
|
+
# limitations under the License.
|
19
|
+
require "logstash/inputs/base"
|
20
|
+
require "logstash/namespace"
|
21
|
+
|
22
|
+
# Google deps
|
23
|
+
require "google/api_client"
|
24
|
+
|
25
|
+
# Generate a repeating message.
|
26
|
+
#
|
27
|
+
# This plugin is intented only as an example.
|
28
|
+
|
29
|
+
class LogStash::Inputs::GooglePubSub < LogStash::Inputs::Base
|
30
|
+
config_name "google_pubsub"
|
31
|
+
|
32
|
+
# Google Cloud Project ID (name, not number)
|
33
|
+
config :project_id, :validate => :string, :required => true
|
34
|
+
|
35
|
+
# Google Cloud Pub/Sub Topic and Subscription.
|
36
|
+
# Note that the topic must be created manually with Cloud Logging
|
37
|
+
# pre-configured export to PubSub configured to use the defined topic.
|
38
|
+
# The subscription will be created automatically by the plugin.
|
39
|
+
config :topic, :validate => :string, :required => true
|
40
|
+
config :subscription, :validate => :string, :required => true
|
41
|
+
config :max_messages, :validate => :number, :required => true, :default => 5
|
42
|
+
|
43
|
+
# If logstash is running within Google Compute Engine, the plugin will use
|
44
|
+
# GCE's Application Default Credentials. Outside of GCE, you will need to
|
45
|
+
# specify a Service Account JSON key file.
|
46
|
+
config :json_key_file, :validate => :path, :required => false
|
47
|
+
|
48
|
+
# If undefined, Logstash will complain, even if codec is unused.
|
49
|
+
default :codec, "plain"
|
50
|
+
|
51
|
+
private
|
52
|
+
def request(options)
|
53
|
+
begin
|
54
|
+
@logger.info("Sending an API request")
|
55
|
+
result = @client.execute(options)
|
56
|
+
rescue ArgumentError => e
|
57
|
+
@logger.info("Authorizing...")
|
58
|
+
@client.authorization.fetch_access_token!
|
59
|
+
@logger.info("...authorized")
|
60
|
+
request(options)
|
61
|
+
rescue Faraday::TimeoutError => e
|
62
|
+
@logger.info("Request timeout, re-trying request")
|
63
|
+
request(options)
|
64
|
+
end
|
65
|
+
end # def request
|
66
|
+
|
67
|
+
public
|
68
|
+
def register
|
69
|
+
@logger.info("Registering Google PubSub Input: project_id=#{@project_id}, topic=#{@topic}, subscription=#{@subscription}")
|
70
|
+
@topic = "projects/#{@project_id}/topics/#{@topic}"
|
71
|
+
@subscription = "projects/#{@project_id}/subscriptions/#{@subscription}"
|
72
|
+
@subscription_exists = false
|
73
|
+
|
74
|
+
# TODO(erjohnso): read UA data from the gemspec
|
75
|
+
@client = Google::APIClient.new(
|
76
|
+
:application_name => 'logstash-input-google_pubsub',
|
77
|
+
:application_version => '0.9.0'
|
78
|
+
)
|
79
|
+
|
80
|
+
# Initialize the pubsub API client
|
81
|
+
@pubsub = @client.discovered_api('pubsub', 'v1')
|
82
|
+
|
83
|
+
# Handle various kinds of auth (JSON or Application Default Creds)
|
84
|
+
# NOTE: Cannot use 'googleauth' gem since there are dependency conflicts
|
85
|
+
# - googleauth ~> 0.5 requires mime-data-types that requires ruby2
|
86
|
+
# - googleauth ~> 0.3 requires multi_json 1.11.0 that conflicts
|
87
|
+
# with logstash-2.3.2's multi_json 1.11.3
|
88
|
+
if @json_key_file
|
89
|
+
@logger.info("Authorizing with JSON key file: #{@json_key_file}")
|
90
|
+
file_path = File.expand_path(@json_key_file)
|
91
|
+
key_json = File.open(file_path, "r", &:read)
|
92
|
+
key_json = JSON.parse(key_json)
|
93
|
+
unless key_json.key?("client_email") || key_json.key?("private_key")
|
94
|
+
raise Google::APIClient::ClientError, "Invalid JSON credentials data."
|
95
|
+
end
|
96
|
+
signing_key = ::Google::APIClient::KeyUtils.load_from_pem(key_json["private_key"], "notasecret")
|
97
|
+
@client.authorization = Signet::OAuth2::Client.new(
|
98
|
+
:audience => "https://accounts.google.com/o/oauth2/token",
|
99
|
+
:auth_provider_x509_cert_url => "https://www.googleapis.com/oauth2/v1/certs",
|
100
|
+
:client_x509_cert_url => "https://www.googleapis.com/robot/v1/metadata/x509/#{key_json['client_email']}",
|
101
|
+
:issuer => "#{key_json['client_email']}",
|
102
|
+
:scope => %w(https://www.googleapis.com/auth/cloud-platform),
|
103
|
+
:signing_key => signing_key,
|
104
|
+
:token_credential_uri => "https://accounts.google.com/o/oauth2/token"
|
105
|
+
)
|
106
|
+
@logger.info("Client authorizataion with JSON key ready")
|
107
|
+
else
|
108
|
+
# Assume we're running in GCE and can use metadata tokens, if the host
|
109
|
+
# GCE instance was not created with the PubSub scope, then the plugin
|
110
|
+
# will not be authorized to read from pubsub.
|
111
|
+
@logger.info("Authorizing with application default credentials")
|
112
|
+
@client.authorization = :google_app_default
|
113
|
+
end # if @json_key_file...
|
114
|
+
end # def register
|
115
|
+
|
116
|
+
def run(queue)
|
117
|
+
# Attempt to create the subscription
|
118
|
+
if !@subscription_exists
|
119
|
+
@logger.info("Creating subscription #{subscription}")
|
120
|
+
result = request(
|
121
|
+
:api_method => @pubsub.projects.subscriptions.create,
|
122
|
+
:parameters => {'name' => @subscription},
|
123
|
+
:body_object => {
|
124
|
+
:topic => @topic,
|
125
|
+
:ackDeadlineSeconds => 15
|
126
|
+
}
|
127
|
+
)
|
128
|
+
if result.error? and result.status != 409
|
129
|
+
raise Google::APIClient::ClientError, "Error #{result.status}: #{result.error_message}"
|
130
|
+
end
|
131
|
+
@subscription_exists = true
|
132
|
+
end # if !@subscription
|
133
|
+
|
134
|
+
@logger.info("Pulling messages from sub '#{subscription}'")
|
135
|
+
while !stop?
|
136
|
+
# Pull and queue messages
|
137
|
+
messages = []
|
138
|
+
result = request(
|
139
|
+
:api_method => @pubsub.projects.subscriptions.pull,
|
140
|
+
:parameters => {'subscription' => @subscription},
|
141
|
+
:body_object => {
|
142
|
+
:returnImmediately => false,
|
143
|
+
:maxMessages => @max_messages
|
144
|
+
}
|
145
|
+
)
|
146
|
+
|
147
|
+
if !result.error?
|
148
|
+
messages = JSON.parse(result.body)
|
149
|
+
if messages.key?("receivedMessages")
|
150
|
+
messages = messages["receivedMessages"]
|
151
|
+
end
|
152
|
+
else
|
153
|
+
@logger.info("Error pulling messages:'#{result.error_message}'")
|
154
|
+
end
|
155
|
+
|
156
|
+
if messages
|
157
|
+
messages.each do |msg|
|
158
|
+
if msg.key?("message") and msg["message"].key?("data")
|
159
|
+
decoded_msg = Base64.decode64(msg["message"]["data"])
|
160
|
+
begin
|
161
|
+
parsed_msg = JSON.parse(decoded_msg)
|
162
|
+
rescue
|
163
|
+
parsed_msg = { :raw_message => decoded_msg }
|
164
|
+
end
|
165
|
+
event = LogStash::Event.new(parsed_msg)
|
166
|
+
decorate(event)
|
167
|
+
queue << event
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
ack_ids = messages.map{ |msg| msg["ackId"] }
|
172
|
+
result = request(
|
173
|
+
:api_method => @pubsub.projects.subscriptions.acknowledge,
|
174
|
+
:parameters => {'subscription' => @subscription},
|
175
|
+
:body_object => {
|
176
|
+
:ackIds => ack_ids
|
177
|
+
}
|
178
|
+
)
|
179
|
+
if result.error?
|
180
|
+
@logger.info("Error #{result.status}: #{result.error_message}")
|
181
|
+
end
|
182
|
+
end # if messages
|
183
|
+
end # loop
|
184
|
+
end # def run
|
185
|
+
end # class LogStash::Inputs::GooglePubSub
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'logstash-input-google_pubsub'
|
3
|
+
s.version = '0.9.0'
|
4
|
+
s.licenses = ['Apache-2.0']
|
5
|
+
s.summary = "Logstash input plugin for Google Cloud Pub/Sub."
|
6
|
+
s.description = "This gem is a Logstash input plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program."
|
7
|
+
s.authors = ["Eric Johnson"]
|
8
|
+
s.email = 'erjohnso@google.com'
|
9
|
+
s.homepage = "https://cloud.google.com/pubsub/overview"
|
10
|
+
s.require_paths = ["lib"]
|
11
|
+
|
12
|
+
# Files
|
13
|
+
s.files = Dir['lib/**/*','spec/**/*','vendor/**/*','*.gemspec','*.md','CONTRIBUTORS','Gemfile','LICENSE','NOTICE.TXT']
|
14
|
+
# Tests
|
15
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
16
|
+
|
17
|
+
# Special flag to let us know this is actually a logstash plugin
|
18
|
+
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "input" }
|
19
|
+
|
20
|
+
# Gem dependencies
|
21
|
+
s.add_runtime_dependency "logstash-core", ">= 2.0.0", "< 3.0.0"
|
22
|
+
s.add_runtime_dependency 'logstash-codec-plain'
|
23
|
+
s.add_runtime_dependency 'stud', '>= 0.0.22'
|
24
|
+
# Google dependencies
|
25
|
+
# google-api-client >= 0.9 requires ruby2 which is not currently compatible
|
26
|
+
# with JRuby
|
27
|
+
s.add_runtime_dependency 'google-api-client', '~> 0.8.6', '< 0.9'
|
28
|
+
s.add_development_dependency 'logstash-devutils', '~>0.0', '>= 0.0.16'
|
29
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# Copyright 2016 Google Inc.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
require "logstash/devutils/rspec/spec_helper"
|
17
|
+
require "logstash/inputs/google_pubsub"
|
18
|
+
|
19
|
+
describe LogStash::Inputs::GooglePubSub do
|
20
|
+
|
21
|
+
let(:bad1) { { 'topic' => 'foo', 'subscription' => 'bar' } }
|
22
|
+
let(:bad2) { { 'project_id' => 'foo', 'subscription' => 'bar' } }
|
23
|
+
let(:bad3) { { 'project_id' => 'foo', 'topic' => 'bar' } }
|
24
|
+
let(:config) { { 'project_id' => 'myproj', 'subscription' => 'foo', 'topic' => 'bar', 'json_key_file' => '/home/erjohnso/fake.json' } }
|
25
|
+
|
26
|
+
it "ensures required config options are present" do
|
27
|
+
expect {
|
28
|
+
plugin = LogStash::Inputs::GooglePubSub.new(bad1)
|
29
|
+
}.to raise_error(LogStash::ConfigurationError)
|
30
|
+
expect {
|
31
|
+
plugin = LogStash::Inputs::GooglePubSub.new(bad2)
|
32
|
+
}.to raise_error(LogStash::ConfigurationError)
|
33
|
+
expect {
|
34
|
+
plugin = LogStash::Inputs::GooglePubSub.new(bad3)
|
35
|
+
}.to raise_error(LogStash::ConfigurationError)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "validates register vars" do
|
39
|
+
plugin = LogStash::Inputs::GooglePubSub.new(config)
|
40
|
+
plugin.register
|
41
|
+
expect(plugin.topic).to eq("projects/myproj/topics/bar")
|
42
|
+
expect(plugin.subscription).to eq("projects/myproj/subscriptions/foo")
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: logstash-input-google_pubsub
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Johnson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: logstash-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 3.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 3.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: logstash-codec-plain
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: stud
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.0.22
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 0.0.22
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: google-api-client
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: 0.8.6
|
68
|
+
- - "<"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0.9'
|
71
|
+
type: :runtime
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.8.6
|
78
|
+
- - "<"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0.9'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: logstash-devutils
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.0'
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.0.16
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "~>"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0.0'
|
98
|
+
- - ">="
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 0.0.16
|
101
|
+
description: This gem is a Logstash input plugin required to be installed on top of
|
102
|
+
the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
|
103
|
+
gem is not a stand-alone program.
|
104
|
+
email: erjohnso@google.com
|
105
|
+
executables: []
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- CHANGELOG.md
|
110
|
+
- CONTRIBUTING.md
|
111
|
+
- Gemfile
|
112
|
+
- LICENSE
|
113
|
+
- NOTICE.TXT
|
114
|
+
- README.md
|
115
|
+
- lib/logstash/inputs/google_pubsub.rb
|
116
|
+
- logstash-input-google_pubsub.gemspec
|
117
|
+
- spec/inputs/google_pubsub_spec.rb
|
118
|
+
homepage: https://cloud.google.com/pubsub/overview
|
119
|
+
licenses:
|
120
|
+
- Apache-2.0
|
121
|
+
metadata:
|
122
|
+
logstash_plugin: 'true'
|
123
|
+
logstash_group: input
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.5.1
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Logstash input plugin for Google Cloud Pub/Sub.
|
144
|
+
test_files:
|
145
|
+
- spec/inputs/google_pubsub_spec.rb
|