logstash-output-CiscoZeus 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -1
- data/lib/logstash/outputs/CiscoZeus.rb +5 -5
- data/lib/logstash/outputs/CiscoZeusMetrics.rb +51 -0
- data/logstash-output-CiscoZeus.gemspec +6 -4
- data/spec/outputs/CiscoZeusMetrics_spec.rb +66 -0
- metadata +6 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68bf5c8119361241419583ed926cebae9f0b8228
|
4
|
+
data.tar.gz: 9792bbe84a4e2ee5875f011a76c20188dd1036a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bca736aa33f43dde362bc330222edd958259f921dad5044b38d9001e617da470404cca692e334c737939af04b93f8b749ee04907c6402c7787b99dfa4b5aa90
|
7
|
+
data.tar.gz: 273d1de66c68882847320a28e8aab0abf3c76edea5b814223d0349d58cfa6191bd7013c89a0e63b99e20c392199430c8bf0b5ed2baf259bb4ba073d4145c3e1a
|
data/README.md
CHANGED
@@ -20,11 +20,13 @@ jruby -S gem build logstash-output-CiscoZeus.gemspec
|
|
20
20
|
### Installation
|
21
21
|
|
22
22
|
```sh
|
23
|
-
logstash-plugin install logstash-output-CiscoZeus
|
23
|
+
logstash-plugin install logstash-output-CiscoZeus
|
24
24
|
```
|
25
25
|
|
26
26
|
### Configuration
|
27
27
|
|
28
|
+
#### Logs
|
29
|
+
|
28
30
|
Add this configuration to the output section of your logstash configuration file.
|
29
31
|
|
30
32
|
```
|
@@ -37,6 +39,37 @@ output {
|
|
37
39
|
}
|
38
40
|
```
|
39
41
|
|
42
|
+
#### Metrics
|
43
|
+
|
44
|
+
The basic configuration is analogous to the Logs plugin
|
45
|
+
|
46
|
+
```
|
47
|
+
output {
|
48
|
+
CiscoZeusMetrics {
|
49
|
+
token => "my_token"
|
50
|
+
metric_name => "my_desired_log_name"
|
51
|
+
endpoint => "myendpoint.ciscozeus.io"
|
52
|
+
}
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
56
|
+
With this configuration, the plugin will forward all the numeric fields to Zeus as metrics.
|
57
|
+
|
58
|
+
Optionally, you can use `fields` to select a specific set of fields instead. The plugin will try to do a type cast in case you select a non integer field.
|
59
|
+
|
60
|
+
```
|
61
|
+
output {
|
62
|
+
CiscoZeusMetrics {
|
63
|
+
token => "my_token"
|
64
|
+
metric_name => "my_desired_log_name"
|
65
|
+
endpoint => "myendpoint.ciscozeus.io"
|
66
|
+
fields => ["foo","bar"]
|
67
|
+
}
|
68
|
+
}
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
|
40
73
|
## License and copyright
|
41
74
|
|
42
75
|
Copyright(C) 2017 - Cisco Systems, Inc.
|
@@ -7,11 +7,11 @@ require 'zeus/api_client'
|
|
7
7
|
# Outputs events to CiscoZeus
|
8
8
|
class LogStash::Outputs::Ciscozeus < LogStash::Outputs::Base
|
9
9
|
config_name "CiscoZeus"
|
10
|
-
|
11
|
-
config :token, :validate => :string
|
12
|
-
config :endpoint, :validate => :string, :default => "
|
10
|
+
|
11
|
+
config :token, :validate => :string, :required => true
|
12
|
+
config :endpoint, :validate => :string, :default => "api.ciscozeus.io"
|
13
13
|
config :log_name, :validate => :string, :default => "logstash_data"
|
14
|
-
|
14
|
+
|
15
15
|
concurrency :single
|
16
16
|
|
17
17
|
def register
|
@@ -23,7 +23,7 @@ class LogStash::Outputs::Ciscozeus < LogStash::Outputs::Base
|
|
23
23
|
|
24
24
|
def multi_receive(events)
|
25
25
|
result = @zeus_client.send_logs(@log_name, events)
|
26
|
-
if not result.success?
|
26
|
+
if not result.success?
|
27
27
|
STDERR.puts "Failed to send data to zeus: " + result.data.to_s
|
28
28
|
end
|
29
29
|
end # def receive
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/outputs/base"
|
3
|
+
require "logstash/namespace"
|
4
|
+
require "logstash/json"
|
5
|
+
require 'zeus/api_client'
|
6
|
+
|
7
|
+
# Outputs metrics to CiscoZeus
|
8
|
+
class LogStash::Outputs::Ciscozeusmetrics < LogStash::Outputs::Base
|
9
|
+
config_name "CiscoZeusMetrics"
|
10
|
+
|
11
|
+
config :token, :validate => :string, :required => true
|
12
|
+
config :endpoint, :validate => :string, :default => "api.ciscozeus.io"
|
13
|
+
config :metric_name, :validate => :string, :default => "logstash_metric"
|
14
|
+
|
15
|
+
# The plugin forwards all the numeric fields in the event by default.
|
16
|
+
# Use this variable to select a specific set of fields instead,
|
17
|
+
# in such a case, only the selected fields will be forwarded to Zeus.
|
18
|
+
# Besides, even if some field is of a non-numeric type,
|
19
|
+
# the plugin will try to convert it using ruby type casting.
|
20
|
+
config :fields, :validate => :string, :list => true, :default => nil
|
21
|
+
|
22
|
+
concurrency :single
|
23
|
+
|
24
|
+
def register
|
25
|
+
@zeus_client = Zeus::APIClient.new({
|
26
|
+
access_token: @token,
|
27
|
+
endpoint: @endpoint
|
28
|
+
})
|
29
|
+
end # def register
|
30
|
+
|
31
|
+
def multi_receive(events)
|
32
|
+
metrics = events.map{|event| reform(event)}
|
33
|
+
result = @zeus_client.send_metrics(@metric_name, metrics)
|
34
|
+
if not result.success?
|
35
|
+
STDERR.puts "Failed to send data to zeus: " + result.data.to_s
|
36
|
+
end
|
37
|
+
end # def receive
|
38
|
+
|
39
|
+
#Matches Zeus metrics API format
|
40
|
+
def reform(event)
|
41
|
+
datapoint = {}
|
42
|
+
if @fields == nil
|
43
|
+
datapoint = event.to_hash.select{ |k,v| k != "@timestamp" and v.is_a? Numeric }
|
44
|
+
else
|
45
|
+
datapoint = event.to_hash.select{ |k,v| @fields.include? k }
|
46
|
+
datapoint = Hash[datapoint.map{ |k,v| [k,if v.is_a? Numeric then v else v.to_f end]}]
|
47
|
+
end
|
48
|
+
return {timestamp: event.get("@timestamp").to_f, point: datapoint}
|
49
|
+
end # def reform
|
50
|
+
|
51
|
+
end # class LogStash::Outputs::Ciscozeusmetrics
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'logstash-output-CiscoZeus'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.2.0'
|
4
4
|
s.licenses = ['Apache-2.0']
|
5
5
|
s.summary = 'Logstash plugin to talk with the CiscoZeus HTTP API'
|
6
6
|
s.homepage = 'http://ciscozeus.io'
|
@@ -9,13 +9,15 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.require_paths = ['lib']
|
10
10
|
|
11
11
|
# Files
|
12
|
-
s.files = Dir['lib/**/*', 'vendor/**/*','*.gemspec','*.md','Gemfile','LICENSE']
|
13
|
-
|
12
|
+
s.files = Dir['lib/**/*', 'spec/**/*', 'vendor/**/*','*.gemspec','*.md','Gemfile','LICENSE']
|
13
|
+
# Tests
|
14
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
15
|
+
|
14
16
|
# Special flag to let us know this is actually a logstash plugin
|
15
17
|
s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" }
|
16
18
|
|
17
19
|
# Gem dependencies
|
18
|
-
s.add_runtime_dependency "logstash-core", ">= 2.0.0"
|
20
|
+
s.add_runtime_dependency "logstash-core", ">= 2.0.0"
|
19
21
|
s.add_runtime_dependency "logstash-codec-plain"
|
20
22
|
s.add_runtime_dependency "zeusclient", "~> 0"
|
21
23
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "logstash/devutils/rspec/spec_helper"
|
3
|
+
require "logstash/outputs/Ciscozeusmetrics"
|
4
|
+
require "logstash/codecs/plain"
|
5
|
+
require "logstash/event"
|
6
|
+
|
7
|
+
describe LogStash::Outputs::Ciscozeusmetrics do
|
8
|
+
|
9
|
+
def performTest(input, expected_output, configuration)
|
10
|
+
event = LogStash::Event.new(input)
|
11
|
+
|
12
|
+
configuration["token"] = "tk"
|
13
|
+
metrics_plugin = LogStash::Outputs::Ciscozeusmetrics.new(configuration)
|
14
|
+
|
15
|
+
expected_output[:timestamp] = event.get("@timestamp").to_f
|
16
|
+
|
17
|
+
output = metrics_plugin.reform(event)
|
18
|
+
|
19
|
+
#Workaround to convert string keys into symbols
|
20
|
+
output[:point] = output[:point].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
|
21
|
+
|
22
|
+
expect(output).to eq(expected_output)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "Simple message with one metric" do
|
26
|
+
input = {"metric1": 6}
|
27
|
+
output = {"point": {"metric1": 6}}
|
28
|
+
it "works as expected" do
|
29
|
+
performTest(input,output,{})
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "Simple message with several metric" do
|
34
|
+
input = {"metric1": 6, "metric2":7}
|
35
|
+
output = {"point":{"metric1":6, "metric2":7}}
|
36
|
+
it "works as expected" do
|
37
|
+
performTest(input,output,{})
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "Message with non numerical fields" do
|
42
|
+
input = {"message": "hello", "world": "earth", "metric1": 6.5, "metric2":7}
|
43
|
+
output = {"point":{"metric1":6.5, "metric2":7}}
|
44
|
+
it "works as expected" do
|
45
|
+
performTest(input,output,{})
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "Field selection" do
|
50
|
+
input = {"message": "hello", "world": "earth", "metric1": 6.5, "metric2":7}
|
51
|
+
output = {"point":{"metric1":6.5}}
|
52
|
+
conf = {"fields" => "metric1"}
|
53
|
+
it "works as expected" do
|
54
|
+
performTest(input,output,conf)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "Field selection with type cast needed" do
|
59
|
+
input = {"metric1": 6.5, "metric2":7, "metric3":"24"}
|
60
|
+
output = {"point":{"metric1":6.5, "metric3": 24}}
|
61
|
+
conf = {"fields" => ["metric1", "metric3"]}
|
62
|
+
it "works as expected" do
|
63
|
+
performTest(input,output,conf)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: logstash-output-CiscoZeus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoel Cabo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -16,9 +16,6 @@ dependencies:
|
|
16
16
|
- - ">="
|
17
17
|
- !ruby/object:Gem::Version
|
18
18
|
version: 2.0.0
|
19
|
-
- - "<"
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 3.0.0
|
22
19
|
name: logstash-core
|
23
20
|
prerelease: false
|
24
21
|
type: :runtime
|
@@ -27,9 +24,6 @@ dependencies:
|
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 2.0.0
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 3.0.0
|
33
27
|
- !ruby/object:Gem::Dependency
|
34
28
|
requirement: !ruby/object:Gem::Requirement
|
35
29
|
requirements:
|
@@ -68,7 +62,9 @@ files:
|
|
68
62
|
- LICENSE
|
69
63
|
- README.md
|
70
64
|
- lib/logstash/outputs/CiscoZeus.rb
|
65
|
+
- lib/logstash/outputs/CiscoZeusMetrics.rb
|
71
66
|
- logstash-output-CiscoZeus.gemspec
|
67
|
+
- spec/outputs/CiscoZeusMetrics_spec.rb
|
72
68
|
homepage: http://ciscozeus.io
|
73
69
|
licenses:
|
74
70
|
- Apache-2.0
|
@@ -95,4 +91,5 @@ rubygems_version: 2.6.8
|
|
95
91
|
signing_key:
|
96
92
|
specification_version: 4
|
97
93
|
summary: Logstash plugin to talk with the CiscoZeus HTTP API
|
98
|
-
test_files:
|
94
|
+
test_files:
|
95
|
+
- spec/outputs/CiscoZeusMetrics_spec.rb
|