rct_sumo 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/sumo +39 -0
  2. data/lib/rct_sumo.rb +125 -0
  3. metadata +70 -0
data/bin/sumo ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # Copyright 2015 Jyri J. Virkki <jyri@virkki.com>
5
+ #
6
+ # This file is part of rct_sumo.
7
+ #
8
+ # rct_sumo is free software: you can redistribute it and/or modify it
9
+ # under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # rct_sumo is distributed in the hope that it will be useful, but
14
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
+ # General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with rct_sumo. If not, see <http://www.gnu.org/licenses/>.
20
+ #
21
+
22
+
23
+ #
24
+ # Convenience script for running sumo CLI directly.
25
+ #
26
+ # Run:
27
+ #
28
+ # sumo OPERATION PARAMS
29
+ #
30
+ # This is equivalent to running rct directly as follows:
31
+ #
32
+ # rct --req rct_sumo Sumo.OPERATION PARAMS
33
+ #
34
+
35
+ require 'rct_sumo'
36
+
37
+ $RCT_CLI_APP_CLASS = "Sumo"
38
+
39
+ require 'rct_cli_app'
data/lib/rct_sumo.rb ADDED
@@ -0,0 +1,125 @@
1
+ #
2
+ # Copyright 2015 Jyri J. Virkki <jyri@virkki.com>
3
+ #
4
+ # This file is part of rct_sumo.
5
+ #
6
+ # rct_sumo is free software: you can redistribute it and/or modify it
7
+ # under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # rct_sumo is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with rct_sumo. If not, see <http://www.gnu.org/licenses/>.
18
+ #
19
+
20
+
21
+ # Implements an rct client for Sumo APIs.
22
+ #
23
+ # Only a tiny subset supported. Expand as needed.
24
+ #
25
+ # https://github.com/SumoLogic/sumo-api-doc/wiki/search-api
26
+ #
27
+
28
+
29
+ require 'rct_client'
30
+
31
+ class Sumo < RCTClient
32
+
33
+ API_HOST = 'api.sumologic.com'
34
+ BASE_PATH = '/api/v1/logs'
35
+
36
+
37
+ #----------------------------------------------------------------------------
38
+ # Class description, for automated help.
39
+ #
40
+ def description
41
+ "The RCT Sumo class implements access to some of the common sumologic\n" +
42
+ "search APIs."
43
+ end
44
+
45
+
46
+ #----------------------------------------------------------------------------
47
+ # CLI definition. Used by the rct framework to determine what CLI commands
48
+ # are available here.
49
+ #
50
+ def cli
51
+ return {
52
+ 'search' => Search
53
+ }
54
+ end
55
+
56
+
57
+ #----------------------------------------------------------------------------
58
+ # General search.
59
+ #
60
+ # Required:
61
+ # username : Authenticate as this user.
62
+ # password : Password of username.
63
+ # query : The search query
64
+ #
65
+ # Optional:
66
+ # from : From time (epoch milliseconds) (default: now-15min)
67
+ # to : End time (epoch milliseconds) (default: now)
68
+ #
69
+ # Saves to state:
70
+ # query_result_json : Full JSON response from sumo
71
+ #
72
+ Search = {
73
+ 'description' => "General synchronous search",
74
+ 'required' => {
75
+ 'username' => [ '-u', '--user', 'User name' ],
76
+ 'password' => [ '-P', '--password', 'Password' ],
77
+ 'query' => [ '-s', '--search', 'Search query' ],
78
+ },
79
+ 'optional' => {
80
+ 'from' => [ '-b', '--begin', 'Start time' ],
81
+ 'to' => [ '-e', '--end', 'End time' ],
82
+ }
83
+ }
84
+
85
+ def search
86
+ user = sget('username')
87
+ password = sget('password')
88
+ query = sget('query')
89
+ start_time = sget('from')
90
+ end_time = sget('to')
91
+
92
+ ssettmp(SERVER_PROTOCOL, 'https')
93
+ ssettmp(SERVER_HOSTNAME, API_HOST)
94
+ ssettmp(SERVER_PORT, 443)
95
+
96
+ ssettmp(REQ_METHOD, 'GET')
97
+ ssettmp(REQ_AUTH_TYPE, REQ_AUTH_TYPE_BASIC)
98
+ ssettmp(REQ_AUTH_NAME, user)
99
+ ssettmp(REQ_AUTH_PWD, password)
100
+ ssettmp(REQ_PATH, "#{BASE_PATH}/search")
101
+
102
+ params = add_param(nil, 'from', start_time)
103
+ params = add_param(params, 'to', end_time)
104
+ params = add_param(params, 'format', 'json')
105
+ params = add_param(params, 'q', query)
106
+ ssettmp(REQ_PARAMS, params)
107
+
108
+ result = yield
109
+
110
+ if (result.ok)
111
+ json = JSON.parse(result.body)
112
+ sset('query_result_json', json)
113
+
114
+ if (is_cli)
115
+ cli_output = ""
116
+ json.each { |h|
117
+ cli_output = cli_output + h['_raw'] + "\n"
118
+ }
119
+ sset(CLI_OUTPUT, cli_output)
120
+ end
121
+ end
122
+ return result
123
+ end
124
+
125
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rct_sumo
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jyri J. Virkki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-02-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rct
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.5'
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: '1.0'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0.5'
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
36
+ description: wip
37
+ email: jyri@virkki.com
38
+ executables:
39
+ - sumo
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - lib/rct_sumo.rb
44
+ - bin/sumo
45
+ homepage: https://github.com/jvirkki/rct_sumo
46
+ licenses:
47
+ - GPLv3
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ requirements: []
65
+ rubyforge_project: nowarning
66
+ rubygems_version: 1.8.23
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: rct client support for sumo
70
+ test_files: []