embulk-input-splunk 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 97cceb8fac1ece34ef872c15aa8861d735d9307c89450ac8ce343a440c855062
4
- data.tar.gz: 896b3b1543169a45aeb94494817b9136064cdb566c72449caf41dca28473a38b
3
+ metadata.gz: c66c1f6d7c39baf9a075c0b872709c995de3177673587687c5d28392a09775ee
4
+ data.tar.gz: 2c99db44781145c10a26ee262f93dcf28028d2ed2e9102cd13d9078bc6b77974
5
5
  SHA512:
6
- metadata.gz: bb553e46a762d8fd09b5655bd1c0621c1d5bf28396c00059cd1a1809cf768d6b70f2dc3bbaf47785899bea94807c73b069bf542bd6b5b47e9ff7494c60a301c0
7
- data.tar.gz: '085667e45da0411d52b783def58e0c5187d337113e6913b37651f9159843fea76d44a573f1be69283d04375d9e54ba25a78656e4d25b45f4eba270a9a9ecb558'
6
+ metadata.gz: f60a1f0af55a4eee9d8c93fdbfa1b0ad39c0081997bc235b8e2ffda8973ac1bc9ab24a8ac37f7f9c7669e84d93f9efe1fb1fa01379fd4bf2e435bd8503e68238
7
+ data.tar.gz: 07701a7b6bd41ed2369df1cac99546dba4840ba1414f6d9a5da4fd3414177cd248a865a38713899648541b0347e17d19b77083cb6b499820274ce9459895dc21
data/README.md CHANGED
@@ -2,23 +2,87 @@
2
2
 
3
3
  A simple plug-in to run a once-off Splunk query and emit the results.
4
4
 
5
+ This plugin loads events as two columns: `time` and `event`. `event` is JSON contain the results of your query. You can use filter plugins such as [embulk-filter-expand_json](https://github.com/civitaspo/embulk-filter-expand_json) or [embulk-filter-add_time](https://github.com/treasure-data/embulk-filter-add_time) to convert the json column to typed columns. [Rename filter](http://www.embulk.org/docs/built-in.html#rename-filter-plugin) is also useful to rename the typed columns.
6
+
7
+ Note that the time is fetched from Splunk's `_time` field. It is possible to rename or reformat this field in the query in a such a way that this plugin will fail or have unexpected results. It is recommended you do not alter the `_time` in the query unless you know what you're doing.
8
+
5
9
  ## Overview
6
10
 
7
- * **Plugin type**: input
8
- * **Resume supported**: no
9
- * **Cleanup supported**: no
10
- * **Guess supported**: no
11
+ - **Plugin type**: input
12
+ - **Resume supported**: no
13
+ - **Cleanup supported**: no
14
+ - **Guess supported**: no
11
15
 
12
16
  ## Configuration
13
17
 
14
- - **type**: splunk
15
- - **host**: host of your splunk server (string, required)
16
- - **username**: splunk username (string, required)
17
- - **password**: splunk password (string, required)
18
- - **port**: splunk API port (integer, default: 8089)
19
- - **query**: the query you wish to run. It should be prefixed with "search" (string required)
18
+ - **type**: splunk
19
+ - **scheme**: HTTP scheme for using the Splunk API (string, default: https)
20
+ - **host**: host of your splunk server (string, required)
21
+ - **username**: splunk username (string, required)
22
+ - **password**: splunk password (string, required)
23
+ - **port**: splunk API port (integer, default: 8089)
24
+ - **query**: the query you wish to run. It should be prefixed with "search" (string required)
25
+ - **earliest_time**: the earliest time for the splunk search. (string, default: nil, which is unbounded)
26
+ - **latest_time**: the latest time for the splunk search. (string, default: nil, which is unbounded)
27
+
28
+ ### Earliest and latest times
29
+
30
+ Splunk's required data format is `%Y-%m-%dT%H:%M:%S.%L%:z` which is the required format for `earliest_time` and `latest_time`.
31
+ In addition, Splunk relative time operations are also accepted, such as -1d@d. For more information, see the [Splunk documentation](https://docs.splunk.com/Documentation/Splunk/7.0.2/SearchReference/SearchTimeModifiers)
32
+
33
+ ### Number of returned results
34
+
35
+ The default Splunk API limits resuts to 100. In this plugin, the limit is not set, so it is possible to generate very large result sets. To limit the number of results, use the `head` or `tail` command in your query.
36
+
37
+
38
+ ## Examples
39
+
40
+ Remember the queries much be prefixed with the search command or they are unlikely not to work.
41
+
42
+ ### Unbounded time range
43
+
44
+ ```yaml
45
+ in:
46
+ type: splunk
47
+ host: splunk.example.com
48
+ username: splunk_user
49
+ password: abc123
50
+ port: 8089
51
+ query: search index="main"
52
+ ```
53
+
54
+ ### Relative time range
55
+
56
+ ```yaml
57
+ in:
58
+ type: splunk
59
+ host: splunk.example.com
60
+ username: splunk_user
61
+ password: abc123
62
+ port: 8089
63
+ query: search index="main"
64
+ earliest_time: -1m@m
65
+ ```
66
+
67
+ ### Absolute time range
68
+
69
+ ```yaml
70
+ in:
71
+ type: splunk
72
+ host: splunk.example.com
73
+ username: splunk_user
74
+ password: abc123
75
+ port: 8089
76
+ query: search index="main"
77
+ earliest_time: 2017-01-18T19:23:08.237+11:00
78
+ latest_time: 2018-01-18T19:23:08.237+11:00
79
+ ```
80
+
81
+ ### Complex Searches
82
+
83
+ For those unfamiliar with YAML, the pipe (|) indicates a multiline value. In Splunk the pipe operator is used for creating multi-step processing.
20
84
 
21
- ## Example
85
+ For non-trivial Splunk queries, you should leverage the YAML pipe alongside Splunk pipes for easier to read queries.
22
86
 
23
87
  ```yaml
24
88
  in:
@@ -27,9 +91,13 @@ in:
27
91
  username: splunk_user
28
92
  password: abc123
29
93
  port: 8089
30
- query: "search index="main" | head 10"
31
- out:
32
- type: stdout
94
+ query: |
95
+ search index="main" |
96
+ eval foo=bar |
97
+ where like(bar, "%baz%" |
98
+ head 100
99
+ earliest_time: 2017-01-18T19:23:08.237+11:00
100
+ latest_time: 2018-01-18T19:23:08.237+11:00
33
101
  ```
34
102
 
35
103
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  Gem::Specification.new do |spec|
3
3
  spec.name = "embulk-input-splunk"
4
- spec.version = "0.1.1"
4
+ spec.version = "0.1.2"
5
5
  spec.authors = ["Scott Arbeitman"]
6
6
  spec.summary = "Splunk input plugin for Embulk"
7
7
  spec.description = "Loads records from a Splunk query."
@@ -16,20 +16,23 @@ module Embulk
16
16
  def self.transaction(config, &control)
17
17
  # configuration code:
18
18
  task = {
19
+ "scheme" => config.param("scheme", :string, default: "https"),
19
20
  "host" => config.param("host", :string),
20
21
  "port" => config.param("port", :integer, default: 8089),
21
22
  "username" => config.param("username", :string),
22
23
  "password" => config.param("password", :string),
24
+
23
25
  "query" => config.param("query", :string),
24
- "incremental" => config.param("incremental", :bool, default: false),
25
- "time_format" => config.param("time_format", :string, default: SPLUNK_TIME_FORMAT),
26
26
 
27
- "earliest_time" => config.param(:earliest_time, :string, default: "2010-01-01T00:00:00.000"),
27
+ "earliest_time" => config.param(:earliest_time, :string, default: nil),
28
+ "latest_time" => config.param(:latest_time, :string, default: nil),
29
+
30
+ "incremental" => config.param("incremental", :bool, default: false),
28
31
  }
29
32
 
30
33
  columns = [
31
34
  Column.new(0, "time", :timestamp),
32
- Column.new(1, "result", :json),
35
+ Column.new(1, "event", :json),
33
36
  ]
34
37
 
35
38
  resume(task, columns, 1, &control)
@@ -50,7 +53,7 @@ module Embulk
50
53
  def init
51
54
  # initialization code:
52
55
  splunk_config = {
53
- :scheme => :https,
56
+ :scheme => task[:scheme],
54
57
  :host => task[:host],
55
58
  :port => task[:port],
56
59
  :username => task[:username],
@@ -59,20 +62,21 @@ module Embulk
59
62
 
60
63
  @service = ::Splunk::connect(splunk_config)
61
64
  @query = task["query"]
62
- @earliest_time = task[:earliest_time]
65
+ @earliest_time, @latest_time = task[:earliest_time], task[:latest_time]
63
66
  end
64
67
 
65
68
  def run
66
69
  stream = @service.create_oneshot(@query,
67
70
  count: SPLUNK_UNLIMITED_RESULTS,
68
- earliest_time: @earliest_time)
71
+ earliest_time: @earliest_time,
72
+ latest_time: @latest_time)
69
73
 
70
74
  reader = ::Splunk::ResultsReader.new(stream)
71
75
 
72
76
  latest_time_in_results = Time.at(0)
73
77
 
74
78
  reader.each do |result|
75
- event_time = Time.strptime( result["_time"], task[:time_format] )
79
+ event_time = Time.strptime( result["_time"], SPLUNK_TIME_FORMAT )
76
80
  latest_time_in_results = [latest_time_in_results, event_time].max
77
81
 
78
82
  page_builder.add( [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: embulk-input-splunk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Arbeitman