sumologic-query 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 045b4c6496e38a665e48c98c37beb3fbf95477f8af17f507725ccf882dc63076
4
- data.tar.gz: fb5d931c84e347065ee258d0da508eaf3d2ab847dd978b33dd33151ee544939e
3
+ metadata.gz: ec844dca9513804180d8e25badb43d663e46467d9683366750131d1c6acc42f7
4
+ data.tar.gz: 0e5dc7f91e61572866e817ea9c6db84112d1cca3d5156826bfc71d829359f3fb
5
5
  SHA512:
6
- metadata.gz: 8f943fba2e5cb46fff13aaec60c1a898284ca745f2e357cafb88b68c6d55e8fae29fcb617761c18da7898ef27e1903185b50c076052b33b2b0a1249459caecda
7
- data.tar.gz: 77c6f9270a9874a442749834c7f89e3ced18769ec89735ceba3746e1a2d2bb37541d32a752f186b673b01e6da67ae82ed67eaa60804255494913d120d1ea19e2
6
+ metadata.gz: 1dbd2cf57b915d5a4e4bd0a43b2f911089087e906a4b01cab318dd3901c3d1645271718c1ff112a7d14769074e7a6dc5f4751001538f72ac703c23b4cb58c505
7
+ data.tar.gz: 20481e3c0b0f2c86b5b06f4f1fc5d32f4753e96defc6cd4f9a35e671666b28e24c1c388390cddb56443c6020c33123e40cdb93424ae25179bb0bafcd825ac60c
data/README.md CHANGED
@@ -1,19 +1,20 @@
1
1
  # Sumo Logic Query Tool
2
2
 
3
- > A lightweight Ruby CLI for querying Sumo Logic logs quickly. Simple, fast, read-only access to your logs.
3
+ > A lightweight Ruby CLI for querying Sumo Logic logs and metadata. Simple, fast, read-only access to your logs.
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/sumologic-query.svg)](https://badge.fury.io/rb/sumologic-query)
6
6
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
7
 
8
8
  ## Why This Tool?
9
9
 
10
- - **Zero dependencies**: Uses only Ruby stdlib - no external gems required
10
+ - **Minimal dependencies**: Uses only Ruby stdlib + Thor for CLI
11
11
  - **Fast queries**: Efficient polling and automatic pagination
12
12
  - **Simple interface**: Just query, get results, done
13
13
  - **Read-only**: No write operations, perfect for safe log access
14
- - **Lightweight**: ~300 lines of code total
14
+ - **Modular architecture**: Clean separation of concerns (HTTP, Search, Metadata)
15
+ - **Metadata support**: List collectors and sources alongside log queries
15
16
 
16
- All existing Ruby Sumo Logic gems are unmaintained (2-9 years dormant). This tool provides a fresh, minimal approach focused solely on querying logs.
17
+ All existing Ruby Sumo Logic gems are unmaintained (2-9 years dormant). This tool provides a fresh, minimal approach focused on querying logs and metadata.
17
18
 
18
19
  ## Installation
19
20
 
@@ -48,7 +49,7 @@ Export your Sumo Logic API credentials:
48
49
  ```bash
49
50
  export SUMO_ACCESS_ID="your_access_id"
50
51
  export SUMO_ACCESS_KEY="your_access_key"
51
- export SUMO_DEPLOYMENT="us2" # Optional: us1, us2 (default), eu, au
52
+ export SUMO_DEPLOYMENT="us2" # Optional: us1, us2 (default), eu, au, etc.
52
53
  ```
53
54
 
54
55
  **Getting credentials:**
@@ -60,18 +61,27 @@ export SUMO_DEPLOYMENT="us2" # Optional: us1, us2 (default), eu, au
60
61
  ### 2. Run Your First Query
61
62
 
62
63
  ```bash
63
- sumo-query --query 'error' \
64
+ # Search logs
65
+ sumo-query search --query 'error' \
64
66
  --from '2025-11-13T14:00:00' \
65
67
  --to '2025-11-13T15:00:00' \
66
68
  --limit 10
69
+
70
+ # List collectors
71
+ sumo-query collectors
72
+
73
+ # List sources
74
+ sumo-query sources
67
75
  ```
68
76
 
69
77
  ## Usage
70
78
 
71
- ### Basic Command Structure
79
+ The CLI provides three main commands:
80
+
81
+ ### Search Logs
72
82
 
73
83
  ```bash
74
- sumo-query --query "YOUR_QUERY" \
84
+ sumo-query search --query "YOUR_QUERY" \
75
85
  --from "START_TIME" \
76
86
  --to "END_TIME" \
77
87
  [--output FILE] \
@@ -79,87 +89,85 @@ sumo-query --query "YOUR_QUERY" \
79
89
  [--time-zone TZ]
80
90
  ```
81
91
 
82
- ### Required Options
83
-
92
+ **Required options:**
84
93
  - `-q, --query QUERY` - Sumo Logic query string
85
- - `-f, --from TIME` - Start time in ISO 8601 format
86
- - `-t, --to TIME` - End time in ISO 8601 format
87
-
88
- ### Optional Options
94
+ - `-f, --from TIME` - Start time (ISO 8601 format)
95
+ - `-t, --to TIME` - End time (ISO 8601 format)
89
96
 
97
+ **Optional options:**
90
98
  - `-z, --time-zone TZ` - Time zone (default: UTC)
91
99
  - `-l, --limit N` - Limit number of messages
92
- - `-o, --output FILE` - Save results to file (default: stdout)
100
+ - `-o, --output FILE` - Save to file (default: stdout)
93
101
  - `-d, --debug` - Enable debug output
94
- - `-h, --help` - Show help message
95
- - `-v, --version` - Show version
96
102
 
97
- ## Common Query Patterns
98
-
99
- ### Error Analysis
103
+ ### List Collectors
100
104
 
101
105
  ```bash
102
- # Find all errors in a time window
103
- sumo-query --query 'error' \
104
- --from '2025-11-13T14:00:00' \
105
- --to '2025-11-13T15:00:00' \
106
- --output errors.json
107
-
108
- # Error timeline with 5-minute buckets
109
- sumo-query --query 'error | timeslice 5m | count by _timeslice' \
110
- --from '2025-11-13T14:00:00' \
111
- --to '2025-11-13T15:00:00'
106
+ sumo-query collectors [--output FILE]
112
107
  ```
113
108
 
114
- ### Text Search
109
+ Lists all collectors in your account with status and metadata.
115
110
 
116
- ```bash
117
- # Search for specific text
118
- sumo-query --query '"connection timeout"' \
119
- --from '2025-11-13T14:00:00' \
120
- --to '2025-11-13T15:00:00'
111
+ ### List Sources
121
112
 
122
- # Case-insensitive search
123
- sumo-query --query 'timeout OR failure OR exception' \
124
- --from '2025-11-13T14:00:00' \
125
- --to '2025-11-13T15:00:00'
113
+ ```bash
114
+ sumo-query sources [--output FILE]
126
115
  ```
127
116
 
128
- ### Filtering by Source
117
+ Lists all sources from active collectors.
129
118
 
130
- ```bash
131
- # Filter by source category
132
- sumo-query --query '_sourceCategory=prod/api error' \
133
- --from '2025-11-13T14:00:00' \
134
- --to '2025-11-13T15:00:00'
119
+ **See [examples/queries.md](examples/queries.md) for more query patterns and examples.**
135
120
 
136
- # Multiple sources
137
- sumo-query --query '(_sourceCategory=prod/api OR _sourceCategory=prod/web) AND error' \
138
- --from '2025-11-13T14:00:00' \
139
- --to '2025-11-13T15:00:00'
140
- ```
121
+ ## Ruby Library Usage
141
122
 
142
- ### Aggregation Queries
123
+ Use the library directly in your Ruby code:
143
124
 
144
- ```bash
145
- # Count by field
146
- sumo-query --query '* | count by status_code' \
147
- --from '2025-11-13T14:00:00' \
148
- --to '2025-11-13T15:00:00'
125
+ ```ruby
126
+ require 'sumologic'
149
127
 
150
- # Top 10 slowest requests
151
- sumo-query --query 'duration_ms > 1000 | sort by duration_ms desc | limit 10' \
152
- --from '2025-11-13T14:00:00' \
153
- --to '2025-11-13T15:00:00'
128
+ # Initialize client
129
+ client = Sumologic::Client.new(
130
+ access_id: ENV['SUMO_ACCESS_ID'],
131
+ access_key: ENV['SUMO_ACCESS_KEY'],
132
+ deployment: 'us2'
133
+ )
134
+
135
+ # Search logs
136
+ results = client.search(
137
+ query: 'error',
138
+ from_time: '2025-11-13T14:00:00',
139
+ to_time: '2025-11-13T15:00:00',
140
+ time_zone: 'UTC',
141
+ limit: 1000
142
+ )
143
+
144
+ results.each do |message|
145
+ puts message['map']['message']
146
+ end
147
+
148
+ # List collectors
149
+ collectors = client.list_collectors
150
+
151
+ # List all sources
152
+ sources = client.list_all_sources
154
153
  ```
155
154
 
156
- ### Parsing and Field Extraction
155
+ **See [docs/api-reference.md](docs/api-reference.md) for complete API documentation.**
156
+
157
+ ## Time Formats
158
+
159
+ Use ISO 8601 format for timestamps:
157
160
 
158
161
  ```bash
159
- # Parse specific fields
160
- sumo-query --query '* | parse "user_id=* " as user_id | count by user_id' \
161
- --from '2025-11-13T14:00:00' \
162
- --to '2025-11-13T15:00:00'
162
+ # UTC timestamps (default)
163
+ --from "2025-11-13T14:30:00" --to "2025-11-13T15:00:00"
164
+
165
+ # With timezone
166
+ --from "2025-11-13T14:30:00" --time-zone "America/New_York"
167
+
168
+ # Using shell helpers
169
+ --from "$(date -u -v-1H '+%Y-%m-%dT%H:%M:%S')" # 1 hour ago
170
+ --to "$(date -u '+%Y-%m-%dT%H:%M:%S')" # now
163
171
  ```
164
172
 
165
173
  ## Output Format
@@ -186,157 +194,54 @@ Results are returned as JSON:
186
194
  }
187
195
  ```
188
196
 
189
- ## Time Formats
190
-
191
- Use ISO 8601 format for timestamps:
192
-
193
- ```bash
194
- # UTC timestamps (default)
195
- --from "2025-11-13T14:30:00"
196
- --to "2025-11-13T15:00:00"
197
-
198
- # With timezone
199
- --from "2025-11-13T14:30:00" --time-zone "America/New_York"
200
-
201
- # Alternative: Relative times (in your shell)
202
- --from "$(date -u -v-1H '+%Y-%m-%dT%H:%M:%S')" # 1 hour ago
203
- --to "$(date -u '+%Y-%m-%dT%H:%M:%S')" # now
204
- ```
205
-
206
197
  ## Performance
207
198
 
208
199
  Query execution time depends on data volume:
209
200
 
210
- - **Small queries** (<10K messages): ~30-60 seconds
211
- - **Medium queries** (10K-100K): ~1-2 minutes
212
- - **Large queries** (100K+): ~2-5 minutes
201
+ | Messages | Typical Time |
202
+ |----------|--------------|
203
+ | < 10K | 30-60 seconds |
204
+ | 10K-100K | 1-2 minutes |
205
+ | 100K+ | 2-5 minutes |
213
206
 
214
- Default timeout: 5 minutes
215
-
216
- To improve performance:
207
+ **Tips for faster queries:**
217
208
  - Narrow your time range
218
- - Add specific `_sourceCategory` filters
209
+ - Add `_sourceCategory` filters
219
210
  - Use `--limit` to cap results
220
- - Use aggregation queries instead of fetching raw messages
221
-
222
- ## Troubleshooting
211
+ - Use aggregation queries instead of raw messages
223
212
 
224
- ### Authentication Error
213
+ ## Documentation
225
214
 
226
- ```
227
- Error: SUMO_ACCESS_ID not set
228
- ```
229
-
230
- **Solution**: Export your credentials:
231
- ```bash
232
- export SUMO_ACCESS_ID="your_access_id"
233
- export SUMO_ACCESS_KEY="your_access_key"
234
- ```
235
-
236
- ### Timeout Error
237
-
238
- ```
239
- Timeout Error: Search job timed out after 300 seconds
240
- ```
241
-
242
- **Solutions**:
243
- - Reduce time range
244
- - Add more specific filters (`_sourceCategory`, `_sourceName`)
245
- - Use `--limit` to cap results
246
- - Consider using aggregation instead of raw messages
247
-
248
- ### Empty Results
249
-
250
- ```json
251
- {
252
- "message_count": 0,
253
- "messages": []
254
- }
255
- ```
256
-
257
- **Check**:
258
- - Time range matches your expected data
259
- - Query syntax is valid (test in Sumo Logic UI first)
260
- - Source categories are correct
261
- - Time zone is correct (default is UTC)
262
-
263
- ### Rate Limit Error
264
-
265
- ```
266
- HTTP 429: Rate limit exceeded
267
- ```
268
-
269
- **Solution**: Wait 1-2 minutes between queries. Sumo Logic enforces rate limits per account.
215
+ - **[Quick Reference (tldr)](docs/tldr.md)** - Concise command examples in tldr format
216
+ - **[Query Examples](examples/queries.md)** - Common query patterns and use cases
217
+ - **[API Reference](docs/api-reference.md)** - Complete Ruby library documentation
218
+ - **[Architecture](docs/architecture.md)** - How the tool works internally
219
+ - **[Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions
270
220
 
271
221
  ## Development
272
222
 
273
- ### Running Tests
223
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, testing, and contribution guidelines.
224
+
225
+ Quick start:
274
226
 
275
227
  ```bash
228
+ # Clone and install
229
+ git clone https://github.com/patrick204nqh/sumologic-query.git
230
+ cd sumologic-query
276
231
  bundle install
277
- bundle exec rake spec
278
- ```
279
232
 
280
- ### Code Quality
233
+ # Run tests
234
+ bundle exec rspec
281
235
 
282
- ```bash
236
+ # Run linter
283
237
  bundle exec rubocop
284
- bundle exec rubocop -A # Auto-fix issues
285
- ```
286
238
 
287
- ### Running Locally
288
-
289
- ```bash
290
- # Without installing
291
- bundle exec bin/sumo-query --query "error" \
292
- --from "2025-11-13T14:00:00" \
293
- --to "2025-11-13T15:00:00"
294
-
295
- # With debug output
296
- SUMO_DEBUG=1 bundle exec bin/sumo-query --query "error" \
239
+ # Test locally
240
+ bundle exec bin/sumo-query search --query "error" \
297
241
  --from "2025-11-13T14:00:00" \
298
242
  --to "2025-11-13T15:00:00"
299
243
  ```
300
244
 
301
- ## How It Works
302
-
303
- This tool uses the Sumo Logic Search Job API:
304
-
305
- 1. **Create Job** - POST to `/api/v1/search/jobs` with your query
306
- 2. **Poll Status** - GET `/api/v1/search/jobs/:id` every 20 seconds until complete
307
- 3. **Fetch Messages** - GET `/api/v1/search/jobs/:id/messages` (automatically paginated)
308
- 4. **Clean Up** - DELETE `/api/v1/search/jobs/:id`
309
-
310
- All steps are handled automatically. You just provide the query and get results.
311
-
312
- ## API Reference
313
-
314
- ### Ruby Library Usage
315
-
316
- You can also use the library directly in your Ruby code:
317
-
318
- ```ruby
319
- require 'sumologic'
320
-
321
- client = Sumologic::Client.new(
322
- access_id: 'your_access_id',
323
- access_key: 'your_access_key',
324
- deployment: 'us2'
325
- )
326
-
327
- results = client.search(
328
- query: 'error',
329
- from_time: '2025-11-13T14:00:00',
330
- to_time: '2025-11-13T15:00:00',
331
- time_zone: 'UTC',
332
- limit: 1000
333
- )
334
-
335
- results.each do |message|
336
- puts message['map']['message']
337
- end
338
- ```
339
-
340
245
  ## Contributing
341
246
 
342
247
  Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
@@ -351,17 +256,17 @@ Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for det
351
256
 
352
257
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
353
258
 
259
+ ## Support
260
+
261
+ - **Issues**: [GitHub Issues](https://github.com/patrick204nqh/sumologic-query/issues)
262
+ - **Discussions**: [GitHub Discussions](https://github.com/patrick204nqh/sumologic-query/discussions)
263
+ - **Documentation**: [docs/](docs/)
264
+
354
265
  ## Resources
355
266
 
356
267
  - **Sumo Logic API Docs**: https://help.sumologic.com/docs/api/search-job/
357
268
  - **Query Language**: https://help.sumologic.com/docs/search/
358
269
  - **Bug Reports**: https://github.com/patrick204nqh/sumologic-query/issues
359
- - **Feature Requests**: https://github.com/patrick204nqh/sumologic-query/issues
360
-
361
- ## Support
362
-
363
- - **Issues**: [GitHub Issues](https://github.com/patrick204nqh/sumologic-query/issues)
364
- - **Discussions**: [GitHub Discussions](https://github.com/patrick204nqh/sumologic-query/discussions)
365
270
 
366
271
  ---
367
272
 
data/bin/sumo-query CHANGED
@@ -1,110 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- # Simple CLI wrapper for querying Sumo Logic logs
5
- # Usage: sumo-query --query "error" --from "2025-11-13T14:00:00" --to "2025-11-13T15:00:00"
6
-
7
4
  require_relative '../lib/sumologic'
8
- require 'optparse'
9
- require 'json'
10
-
11
- options = {
12
- time_zone: 'UTC'
13
- }
14
-
15
- OptionParser.new do |opts|
16
- opts.banner = <<~BANNER
17
- Sumo Logic Query Tool - Fast, read-only log access
18
-
19
- Usage: sumo-query [options]
20
-
21
- Examples:
22
- # Error timeline with 5-minute buckets
23
- sumo-query --query 'error | timeslice 5m | count' \\
24
- --from '2025-11-13T14:00:00' --to '2025-11-13T15:00:00'
25
-
26
- # Search for specific text
27
- sumo-query --query '"connection timeout"' \\
28
- --from '2025-11-13T14:00:00' --to '2025-11-13T15:00:00' \\
29
- --limit 100
30
-
31
- # Filter by source category
32
- sumo-query --query '_sourceCategory=prod/api error' \\
33
- --from '2025-11-13T14:00:00' --to '2025-11-13T15:00:00' \\
34
- --output results.json
35
-
36
- Options:
37
- BANNER
38
-
39
- opts.on('-q', '--query QUERY', 'Search query (required)') { |v| options[:query] = v }
40
- opts.on('-f', '--from TIME', 'Start time in ISO 8601 format (required)') { |v| options[:from] = v }
41
- opts.on('-t', '--to TIME', 'End time in ISO 8601 format (required)') { |v| options[:to] = v }
42
- opts.on('-z', '--time-zone TZ', 'Time zone (default: UTC)') { |v| options[:time_zone] = v }
43
- opts.on('-l', '--limit N', Integer, 'Limit number of messages') { |v| options[:limit] = v }
44
- opts.on('-o', '--output FILE', 'Output file (default: stdout)') { |v| options[:output] = v }
45
- opts.on('-d', '--debug', 'Enable debug output') { $DEBUG = true }
46
- opts.on('-h', '--help', 'Show this help') do
47
- puts opts
48
- exit
49
- end
50
- opts.on('-v', '--version', 'Show version') do
51
- puts "sumologic-query v#{Sumologic::VERSION}"
52
- exit
53
- end
54
- end.parse!
55
-
56
- # Validate required options
57
- unless options[:query] && options[:from] && options[:to]
58
- warn 'Error: --query, --from, and --to are required'
59
- warn 'Run with --help for usage information'
60
- exit 1
61
- end
62
5
 
63
6
  begin
64
- # Create client
65
- client = Sumologic::Client.new
66
-
67
- warn "Querying Sumo Logic: #{options[:from]} to #{options[:to]}"
68
- warn "Query: #{options[:query]}"
69
- warn 'This may take 1-3 minutes depending on data volume...'
70
- $stderr.puts
71
-
72
- # Execute search
73
- results = client.search(
74
- query: options[:query],
75
- from_time: options[:from],
76
- to_time: options[:to],
77
- time_zone: options[:time_zone],
78
- limit: options[:limit]
79
- )
80
-
81
- # Format output
82
- output = {
83
- query: options[:query],
84
- from: options[:from],
85
- to: options[:to],
86
- time_zone: options[:time_zone],
87
- message_count: results.size,
88
- messages: results
89
- }
90
-
91
- json_output = JSON.pretty_generate(output)
92
-
93
- # Write to file or stdout
94
- if options[:output]
95
- File.write(options[:output], json_output)
96
- warn "\nResults saved to: #{options[:output]}"
97
- warn "Message count: #{results.size}"
98
- else
99
- puts json_output
100
- end
101
- rescue Sumologic::AuthenticationError => e
102
- warn "\nAuthentication Error: #{e.message}"
103
- warn "\nPlease set environment variables:"
104
- warn " export SUMO_ACCESS_ID='your_access_id'"
105
- warn " export SUMO_ACCESS_KEY='your_access_key'"
106
- warn " export SUMO_DEPLOYMENT='us2' # Optional, defaults to us2"
107
- exit 1
7
+ Sumologic::CLI.start(ARGV)
108
8
  rescue Sumologic::TimeoutError => e
109
9
  warn "\nTimeout Error: #{e.message}"
110
10
  warn "\nTry:"
@@ -115,6 +15,10 @@ rescue Sumologic::TimeoutError => e
115
15
  rescue Sumologic::Error => e
116
16
  warn "\nError: #{e.message}"
117
17
  exit 1
18
+ rescue StandardError => e
19
+ warn "\nUnexpected Error: #{e.message}"
20
+ warn e.backtrace.first(5).join("\n") if $DEBUG
21
+ exit 1
118
22
  rescue Interrupt
119
23
  warn "\nInterrupted by user"
120
24
  exit 130