sumologic-query 1.3.2 โ 1.3.4
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 +4 -4
- data/CHANGELOG.md +164 -5
- data/README.md +77 -35
- data/lib/sumologic/cli/commands/base_command.rb +57 -0
- data/lib/sumologic/cli/commands/list_collectors_command.rb +22 -0
- data/lib/sumologic/cli/commands/list_sources_command.rb +53 -0
- data/lib/sumologic/cli/commands/search_command.rb +107 -0
- data/lib/sumologic/cli.rb +34 -158
- data/lib/sumologic/http/client.rb +27 -50
- data/lib/sumologic/http/connection_pool.rb +14 -0
- data/lib/sumologic/http/cookie_jar.rb +52 -0
- data/lib/sumologic/http/debug_logger.rb +46 -0
- data/lib/sumologic/http/request_builder.rb +63 -0
- data/lib/sumologic/http/response_handler.rb +42 -0
- data/lib/sumologic/utils/time_parser.rb +147 -0
- data/lib/sumologic/version.rb +1 -1
- metadata +11 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 72c4c0c9c57655df15506b9be19a21de47398ba2a2aedaae8e8d22d3efbd0873
|
|
4
|
+
data.tar.gz: 9cd38107b915187cb699e32305c8af8e6a970c2ea24c2b2340a443cc0a0e2637
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a073e490f4714e8f11c8c495775937dd42bb420535c38d82137a71a940b4b9db2b9fe33d4e6ec4b7745385a7661ec657db5472b9761dbecc110fb473efca757f
|
|
7
|
+
data.tar.gz: 3a9aa83222b99b34fbcdceb45f2e1cdd126c29d28ba4a93db818ea34438b366f7a7b5eb0290f7986e0a9ef9d5deaed95465cca45a72468ec432ec5d6d97a29f4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,28 +1,187 @@
|
|
|
1
|
-
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
3
4
|
|
|
5
|
+
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
8
|
+
and release notes are automatically generated from commit messages.
|
|
9
|
+
## [1.3.4](https://github.com/patrick204nqh/sumologic-query/compare/v1.3.3...v1.3.4) (2025-11-19)
|
|
10
|
+
|
|
11
|
+
### ๐ New Features
|
|
12
|
+
|
|
13
|
+
- add time parsing utility and enhance CLI time options for flexible querying
|
|
14
|
+
- enhance debug logging to include request headers for better traceability
|
|
15
|
+
|
|
16
|
+
### ๐ Bug Fixes
|
|
17
|
+
|
|
18
|
+
- freeze regex for relative time parsing and improve error message formatting
|
|
19
|
+
|
|
20
|
+
### ๐ Documentation
|
|
21
|
+
|
|
22
|
+
- update README and examples to enhance time format usage and add new time format examples
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
## [1.3.3](https://github.com/patrick204nqh/sumologic-query/compare/v1.3.2...v1.3.3) (2025-11-17)
|
|
27
|
+
|
|
28
|
+
### ๐ New Features
|
|
29
|
+
|
|
30
|
+
- implement modular HTTP client components for improved organization and functionality
|
|
31
|
+
- refactor CLI structure to modular commands and remove deprecated modules
|
|
32
|
+
- update CHANGELOG entry creation to include changelog content directly
|
|
33
|
+
- bump version to 1.3.3
|
|
34
|
+
- add ADR for SSL certificate verification to address connection issues with Sumo Logic API
|
|
35
|
+
- refactor CLI structure into modular components for improved organization and maintainability
|
|
36
|
+
- implement debug logging for HTTP requests and responses
|
|
37
|
+
- enhance release notes generation and update CHANGELOG format for better clarity
|
|
4
38
|
|
|
5
|
-
## [1.2.1](https://github.com/patrick204nqh/sumologic-query/compare/v1.2.0...v1.2.1) (2025-11-14)
|
|
6
39
|
|
|
7
40
|
|
|
8
41
|
|
|
9
42
|
## [1.3.2](https://github.com/patrick204nqh/sumologic-query/compare/v1.3.1...v1.3.2) (2025-11-16)
|
|
10
43
|
|
|
11
|
-
|
|
44
|
+
### ๐ New Features
|
|
45
|
+
|
|
46
|
+
- Refactor FzfViewer with modular configuration, formatting, and header building for better maintainability
|
|
47
|
+
- Add modular file structure with separate concerns (Config, Formatter, SearchableBuilder, FzfConfig, HeaderBuilder)
|
|
48
|
+
- Implement module_function for better encapsulation in all FzfViewer modules
|
|
49
|
+
- Add RubyGems download badge to README
|
|
12
50
|
|
|
51
|
+
### ๐ Bug Fixes
|
|
13
52
|
|
|
53
|
+
- Update source field reference in FzfViewer for consistency (use lowercase `_source` field)
|
|
54
|
+
- Fix RuboCop offenses across all FzfViewer modules
|
|
14
55
|
|
|
15
|
-
|
|
56
|
+
### ๐ง Refactoring
|
|
57
|
+
|
|
58
|
+
- Extract searchable builder methods to reduce complexity
|
|
59
|
+
- Separate FzfViewer into 6 focused modules (~50-100 lines each)
|
|
60
|
+
- Use constants for display configuration (widths, colors, padding)
|
|
61
|
+
- Improve code organization with clear section headers
|
|
62
|
+
|
|
63
|
+
### ๐งน Maintenance
|
|
64
|
+
|
|
65
|
+
- Update release notes generation and changelog management in CI pipeline
|
|
66
|
+
|
|
67
|
+
## [1.3.1](https://github.com/patrick204nqh/sumologic-query/compare/v1.3.0...v1.3.1) (2025-11-15)
|
|
68
|
+
|
|
69
|
+
### ๐งน Maintenance
|
|
70
|
+
|
|
71
|
+
- Automated version bump and release preparation
|
|
72
|
+
|
|
73
|
+
## [1.3.0](https://github.com/patrick204nqh/sumologic-query/compare/v1.2.1...v1.3.0) (2025-11-15)
|
|
74
|
+
|
|
75
|
+
### ๐ Documentation
|
|
76
|
+
|
|
77
|
+
- Establish commit message convention using Conventional Commits
|
|
78
|
+
- Update CONTRIBUTING.md for clarity and best practices
|
|
79
|
+
|
|
80
|
+
### ๐งน Maintenance
|
|
81
|
+
|
|
82
|
+
- Remove path restriction for version file in release workflow
|
|
83
|
+
- Improve CI/CD pipeline configuration
|
|
84
|
+
|
|
85
|
+
## [1.2.1](https://github.com/patrick204nqh/sumologic-query/compare/v1.2.0...v1.2.1) (2025-11-14)
|
|
16
86
|
|
|
17
|
-
|
|
87
|
+
### ๐ New Features
|
|
18
88
|
|
|
89
|
+
- Add interactive mode with FZF for enhanced log exploration
|
|
90
|
+
- Support real-time log browsing and filtering
|
|
91
|
+
- Add keyboard shortcuts for common operations
|
|
19
92
|
|
|
93
|
+
### ๐ Documentation
|
|
94
|
+
|
|
95
|
+
- Update CLI and documentation to support new interactive feature
|
|
96
|
+
- Add usage examples for interactive mode
|
|
97
|
+
|
|
98
|
+
## [1.2.0](https://github.com/patrick204nqh/sumologic-query/compare/v1.1.2...v1.2.0) (2025-11-14)
|
|
99
|
+
|
|
100
|
+
### ๐ New Features
|
|
101
|
+
|
|
102
|
+
- Add ADR 004 for enhanced progress tracking and user experience
|
|
103
|
+
- Implement real-time visibility with callbacks in CLI and fetcher classes
|
|
104
|
+
- Add comprehensive progress indicators for long-running operations
|
|
105
|
+
|
|
106
|
+
### ๐ง Refactoring
|
|
107
|
+
|
|
108
|
+
- Implement reusable Worker utility for parallel execution
|
|
109
|
+
- Refactor metadata and search fetching classes to utilize Worker
|
|
110
|
+
- Remove deprecated ParallelFetcher and Paginator
|
|
111
|
+
- Simplify pagination logic
|
|
112
|
+
- Remove streaming APIs for better maintainability
|
|
113
|
+
- Update configuration defaults for optimal performance
|
|
114
|
+
|
|
115
|
+
### ๐ Documentation
|
|
116
|
+
|
|
117
|
+
- Reorganize architecture documentation files
|
|
118
|
+
- Add architectural overview and decision records
|
|
20
119
|
|
|
21
120
|
## [1.1.2](https://github.com/patrick204nqh/sumologic-query/compare/v1.1.1...v1.1.2) (2025-11-14)
|
|
22
121
|
|
|
122
|
+
### ๐ Bug Fixes
|
|
123
|
+
|
|
124
|
+
- Fix command syntax in tldr.md for listing collectors and sources
|
|
125
|
+
|
|
126
|
+
### ๐ New Features
|
|
23
127
|
|
|
128
|
+
- Add version command to CLI
|
|
129
|
+
|
|
130
|
+
### ๐ Documentation
|
|
131
|
+
|
|
132
|
+
- Add quick reference documentation (tldr.md)
|
|
133
|
+
- Refactor documentation structure
|
|
134
|
+
- Remove examples.md and consolidate content
|
|
135
|
+
- Streamline troubleshooting.md
|
|
136
|
+
- Consolidate queries.md with improved examples
|
|
24
137
|
|
|
25
138
|
## [1.1.1](https://github.com/patrick204nqh/sumologic-query/compare/v1.1.0...v1.1.1) (2025-11-14)
|
|
26
139
|
|
|
140
|
+
### ๐ง Refactoring
|
|
141
|
+
|
|
142
|
+
- Refactor search logging in CLI and Poller classes for improved readability
|
|
143
|
+
- Consolidate attribute accessors in Configuration class
|
|
144
|
+
- Improve CLI options structure
|
|
145
|
+
|
|
146
|
+
## [1.1.0](https://github.com/patrick204nqh/sumologic-query/compare/v1.0.1...v1.1.0) (2025-11-13)
|
|
147
|
+
|
|
148
|
+
### ๐ New Features
|
|
149
|
+
|
|
150
|
+
- Add CLI support with Thor framework
|
|
151
|
+
- Refactor Sumo Logic client for better usability
|
|
152
|
+
|
|
153
|
+
### ๐ง Refactoring
|
|
154
|
+
|
|
155
|
+
- Refine polling logic in Sumo Logic client
|
|
156
|
+
- Improve overall code structure and organization
|
|
157
|
+
|
|
158
|
+
### ๐งน Maintenance
|
|
159
|
+
|
|
160
|
+
- Refactor CI and release workflows
|
|
161
|
+
- Streamline version checking and build process
|
|
162
|
+
- Improve release tagging automation
|
|
163
|
+
|
|
164
|
+
## [1.0.1](https://github.com/patrick204nqh/sumologic-query/compare/v1.0.0...v1.0.1) (2025-11-13)
|
|
165
|
+
|
|
166
|
+
### ๐ New Features
|
|
167
|
+
|
|
168
|
+
- Add CODEOWNERS file for repository management
|
|
169
|
+
|
|
170
|
+
### ๐งน Maintenance
|
|
171
|
+
|
|
172
|
+
- Refactor release workflow to generate release notes using GitHub API
|
|
173
|
+
- Update CHANGELOG.md format for better clarity
|
|
174
|
+
- Add changelog extraction for automated versioning
|
|
175
|
+
|
|
176
|
+
## [1.0.0](https://github.com/patrick204nqh/sumologic-query/releases/tag/v1.0.0) (2025-11-13)
|
|
27
177
|
|
|
178
|
+
### ๐ Initial Release
|
|
28
179
|
|
|
180
|
+
- Initial release of Sumo Logic Query Tool
|
|
181
|
+
- Core search functionality
|
|
182
|
+
- Metadata querying (collectors, sources)
|
|
183
|
+
- Basic CLI interface
|
|
184
|
+
- HTTP client with authentication
|
|
185
|
+
- Automated pagination
|
|
186
|
+
- Search job polling
|
|
187
|
+
- JSON output support
|
data/README.md
CHANGED
|
@@ -8,8 +8,11 @@
|
|
|
8
8
|
|
|
9
9
|
## Why This Tool?
|
|
10
10
|
|
|
11
|
+
- **Intuitive time parsing**: Use relative times like `-1h`, `-30m`, or `now` - no more calculating timestamps!
|
|
12
|
+
- **Flexible timezone support**: US, Australian, and IANA timezone formats supported
|
|
11
13
|
- **Minimal dependencies**: Uses only Ruby stdlib + Thor for CLI
|
|
12
14
|
- **Fast queries**: Efficient polling and automatic pagination
|
|
15
|
+
- **Interactive mode**: Explore logs with FZF-powered fuzzy search and preview
|
|
13
16
|
- **Simple interface**: Just query, get results, done
|
|
14
17
|
- **Read-only**: No write operations, perfect for safe log access
|
|
15
18
|
- **Modular architecture**: Clean separation of concerns (HTTP, Search, Metadata)
|
|
@@ -62,7 +65,13 @@ export SUMO_DEPLOYMENT="us2" # Optional: us1, us2 (default), eu, au, etc.
|
|
|
62
65
|
### 2. Run Your First Query
|
|
63
66
|
|
|
64
67
|
```bash
|
|
65
|
-
# Search logs
|
|
68
|
+
# Search logs from last hour (easy!)
|
|
69
|
+
sumo-query search --query 'error' --from '-1h' --to 'now' --limit 10
|
|
70
|
+
|
|
71
|
+
# Search logs from last 30 minutes
|
|
72
|
+
sumo-query search --query 'error' --from '-30m' --to 'now'
|
|
73
|
+
|
|
74
|
+
# Or use ISO 8601 format
|
|
66
75
|
sumo-query search --query 'error' \
|
|
67
76
|
--from '2025-11-13T14:00:00' \
|
|
68
77
|
--to '2025-11-13T15:00:00' \
|
|
@@ -108,13 +117,13 @@ sumo-query search --query "YOUR_QUERY" \
|
|
|
108
117
|
Explore your logs interactively with a powerful FZF-based interface:
|
|
109
118
|
|
|
110
119
|
```bash
|
|
111
|
-
# Launch interactive mode
|
|
112
|
-
sumo-query search --query 'error'
|
|
113
|
-
--from '2025-11-13T14:00:00' \
|
|
114
|
-
--to '2025-11-13T15:00:00' \
|
|
115
|
-
--interactive
|
|
120
|
+
# Launch interactive mode - last hour
|
|
121
|
+
sumo-query search --query 'error' --from '-1h' --to 'now' --interactive
|
|
116
122
|
|
|
117
|
-
#
|
|
123
|
+
# Last 30 minutes with shorthand
|
|
124
|
+
sumo-query search -q 'error' -f '-30m' -t 'now' -i
|
|
125
|
+
|
|
126
|
+
# Or use ISO 8601 format
|
|
118
127
|
sumo-query search -q 'error' -f '2025-11-13T14:00:00' -t '2025-11-13T15:00:00' -i
|
|
119
128
|
```
|
|
120
129
|
|
|
@@ -141,6 +150,27 @@ sumo-query search -q 'error' -f '2025-11-13T14:00:00' -t '2025-11-13T15:00:00' -
|
|
|
141
150
|
- Install FZF: `brew install fzf` (macOS) or `apt-get install fzf` (Linux)
|
|
142
151
|
- See: https://github.com/junegunn/fzf#installation
|
|
143
152
|
|
|
153
|
+
### Time Format Examples
|
|
154
|
+
|
|
155
|
+
Combine relative times with timezones for powerful queries:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
# Last hour in Sydney time
|
|
159
|
+
sumo-query search -q 'error' -f '-1h' -t 'now' -z AEST
|
|
160
|
+
|
|
161
|
+
# Last 30 minutes in US Eastern time
|
|
162
|
+
sumo-query search -q 'error' -f '-30m' -t 'now' -z EST
|
|
163
|
+
|
|
164
|
+
# Last 7 days with output to file (directories auto-created)
|
|
165
|
+
sumo-query search -q 'error' -f '-7d' -t 'now' -o logs/weekly/errors.json
|
|
166
|
+
|
|
167
|
+
# Mix relative and ISO 8601 formats
|
|
168
|
+
sumo-query search -q 'error' -f '-24h' -t '2025-11-19T12:00:00'
|
|
169
|
+
|
|
170
|
+
# Unix timestamps from last hour to now
|
|
171
|
+
sumo-query search -q 'error' -f '1700000000' -t 'now'
|
|
172
|
+
```
|
|
173
|
+
|
|
144
174
|
### List Collectors
|
|
145
175
|
|
|
146
176
|
```bash
|
|
@@ -157,12 +187,9 @@ sumo-query sources [--output FILE]
|
|
|
157
187
|
|
|
158
188
|
Lists all sources from active collectors.
|
|
159
189
|
|
|
160
|
-
**See [examples/queries.md](examples/queries.md) for more query patterns and examples.**
|
|
161
190
|
|
|
162
191
|
## Ruby Library Usage
|
|
163
192
|
|
|
164
|
-
Use the library directly in your Ruby code:
|
|
165
|
-
|
|
166
193
|
```ruby
|
|
167
194
|
require 'sumologic'
|
|
168
195
|
|
|
@@ -182,35 +209,48 @@ results = client.search(
|
|
|
182
209
|
limit: 1000
|
|
183
210
|
)
|
|
184
211
|
|
|
185
|
-
|
|
186
|
-
puts message['map']['message']
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
# List collectors
|
|
212
|
+
# List collectors and sources
|
|
190
213
|
collectors = client.list_collectors
|
|
191
|
-
|
|
192
|
-
# List all sources
|
|
193
214
|
sources = client.list_all_sources
|
|
194
215
|
```
|
|
195
216
|
|
|
196
|
-
**
|
|
217
|
+
**Time parsing utilities:**
|
|
218
|
+
|
|
219
|
+
```ruby
|
|
220
|
+
require 'sumologic/utils/time_parser'
|
|
221
|
+
|
|
222
|
+
# Parse relative times and timezones
|
|
223
|
+
from_time = Sumologic::Utils::TimeParser.parse('-1h')
|
|
224
|
+
timezone = Sumologic::Utils::TimeParser.parse_timezone('AEST')
|
|
225
|
+
```
|
|
226
|
+
|
|
197
227
|
|
|
198
228
|
## Time Formats
|
|
199
229
|
|
|
200
|
-
|
|
230
|
+
Multiple time formats are supported:
|
|
201
231
|
|
|
202
232
|
```bash
|
|
203
|
-
#
|
|
204
|
-
|
|
233
|
+
# Relative time (easiest!)
|
|
234
|
+
sumo-query search -q 'error' -f '-1h' -t 'now'
|
|
235
|
+
sumo-query search -q 'error' -f '-30m' -t 'now'
|
|
236
|
+
|
|
237
|
+
# ISO 8601
|
|
238
|
+
sumo-query search -q 'error' -f '2025-11-13T14:00:00' -t '2025-11-13T15:00:00'
|
|
205
239
|
|
|
206
|
-
#
|
|
207
|
-
|
|
240
|
+
# Unix timestamps
|
|
241
|
+
sumo-query search -q 'error' -f '1700000000' -t 'now'
|
|
208
242
|
|
|
209
|
-
#
|
|
210
|
-
|
|
211
|
-
|
|
243
|
+
# With timezones
|
|
244
|
+
sumo-query search -q 'error' -f '-1h' -t 'now' -z 'AEST'
|
|
245
|
+
sumo-query search -q 'error' -f '-1h' -t 'now' -z 'America/New_York'
|
|
212
246
|
```
|
|
213
247
|
|
|
248
|
+
**Supported time units:** `s`, `m`, `h`, `d`, `w`, `M`, `now`
|
|
249
|
+
|
|
250
|
+
**Supported timezones:** IANA names (`UTC`, `America/New_York`, `Australia/Sydney`), US abbreviations (`EST`, `PST`), Australian abbreviations (`AEST`, `ACST`, `AWST`), UTC offsets (`+10:00`)
|
|
251
|
+
|
|
252
|
+
See [examples/time-formats.md](examples/time-formats.md) for comprehensive examples.
|
|
253
|
+
|
|
214
254
|
## Output Format
|
|
215
255
|
|
|
216
256
|
Results are returned as JSON:
|
|
@@ -253,11 +293,10 @@ Query execution time depends on data volume:
|
|
|
253
293
|
|
|
254
294
|
## Documentation
|
|
255
295
|
|
|
256
|
-
- **[Quick Reference (tldr)](docs/tldr.md)** - Concise command examples
|
|
257
|
-
- **[Query Examples](examples/queries.md)** - Common query patterns
|
|
258
|
-
- **[
|
|
259
|
-
- **[Architecture](docs/architecture/)** -
|
|
260
|
-
- **[Troubleshooting](docs/troubleshooting.md)** - Common issues and solutions
|
|
296
|
+
- **[Quick Reference (tldr)](docs/tldr.md)** - Concise command examples
|
|
297
|
+
- **[Query Examples](examples/queries.md)** - Common query patterns
|
|
298
|
+
- **[Time Format Examples](examples/time-formats.md)** - Time parsing and timezone options
|
|
299
|
+
- **[Architecture](docs/architecture/)** - Design and architecture decisions
|
|
261
300
|
|
|
262
301
|
## Development
|
|
263
302
|
|
|
@@ -271,16 +310,19 @@ git clone https://github.com/patrick204nqh/sumologic-query.git
|
|
|
271
310
|
cd sumologic-query
|
|
272
311
|
bundle install
|
|
273
312
|
|
|
274
|
-
# Run tests
|
|
313
|
+
# Run tests (73+ specs including time parser tests)
|
|
275
314
|
bundle exec rspec
|
|
276
315
|
|
|
277
316
|
# Run linter
|
|
278
317
|
bundle exec rubocop
|
|
279
318
|
|
|
280
|
-
# Test locally
|
|
319
|
+
# Test locally with new time formats
|
|
320
|
+
bundle exec bin/sumo-query search --query "error" \
|
|
321
|
+
--from "-1h" --to "now"
|
|
322
|
+
|
|
323
|
+
# Test with timezone support
|
|
281
324
|
bundle exec bin/sumo-query search --query "error" \
|
|
282
|
-
--from "
|
|
283
|
-
--to "2025-11-13T15:00:00"
|
|
325
|
+
--from "-30m" --to "now" --time-zone "AEST"
|
|
284
326
|
```
|
|
285
327
|
|
|
286
328
|
## Contributing
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
module Sumologic
|
|
6
|
+
class CLI < Thor
|
|
7
|
+
module Commands
|
|
8
|
+
# Base class for all CLI commands
|
|
9
|
+
# Provides common functionality like client creation, output handling, and formatting
|
|
10
|
+
class BaseCommand
|
|
11
|
+
attr_reader :options, :client
|
|
12
|
+
|
|
13
|
+
def initialize(options, client)
|
|
14
|
+
@options = options
|
|
15
|
+
@client = client
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def output_json(data)
|
|
21
|
+
json_output = JSON.pretty_generate(data)
|
|
22
|
+
|
|
23
|
+
if options[:output]
|
|
24
|
+
# Create parent directories if they don't exist
|
|
25
|
+
output_dir = File.dirname(options[:output])
|
|
26
|
+
FileUtils.mkdir_p(output_dir) unless output_dir == '.'
|
|
27
|
+
|
|
28
|
+
File.write(options[:output], json_output)
|
|
29
|
+
warn "\nResults saved to: #{options[:output]}"
|
|
30
|
+
else
|
|
31
|
+
puts json_output
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def format_collector(collector)
|
|
36
|
+
{
|
|
37
|
+
id: collector['id'],
|
|
38
|
+
name: collector['name'],
|
|
39
|
+
collectorType: collector['collectorType'],
|
|
40
|
+
alive: collector['alive'],
|
|
41
|
+
category: collector['category']
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def format_source(source)
|
|
46
|
+
{
|
|
47
|
+
id: source['id'],
|
|
48
|
+
name: source['name'],
|
|
49
|
+
category: source['category'],
|
|
50
|
+
sourceType: source['sourceType'],
|
|
51
|
+
alive: source['alive']
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_command'
|
|
4
|
+
|
|
5
|
+
module Sumologic
|
|
6
|
+
class CLI < Thor
|
|
7
|
+
module Commands
|
|
8
|
+
# Handles the list-collectors command execution
|
|
9
|
+
class ListCollectorsCommand < BaseCommand
|
|
10
|
+
def execute
|
|
11
|
+
warn 'Fetching collectors...'
|
|
12
|
+
collectors = client.list_collectors
|
|
13
|
+
|
|
14
|
+
output_json(
|
|
15
|
+
total: collectors.size,
|
|
16
|
+
collectors: collectors.map { |c| format_collector(c) }
|
|
17
|
+
)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_command'
|
|
4
|
+
|
|
5
|
+
module Sumologic
|
|
6
|
+
class CLI < Thor
|
|
7
|
+
module Commands
|
|
8
|
+
# Handles the list-sources command execution
|
|
9
|
+
class ListSourcesCommand < BaseCommand
|
|
10
|
+
def execute
|
|
11
|
+
if options[:collector_id]
|
|
12
|
+
list_sources_for_collector
|
|
13
|
+
else
|
|
14
|
+
list_all_sources
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def list_sources_for_collector
|
|
21
|
+
warn "Fetching sources for collector: #{options[:collector_id]}"
|
|
22
|
+
sources = client.list_sources(collector_id: options[:collector_id])
|
|
23
|
+
|
|
24
|
+
output_json(
|
|
25
|
+
collector_id: options[:collector_id],
|
|
26
|
+
total: sources.size,
|
|
27
|
+
sources: sources.map { |s| format_source(s) }
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def list_all_sources
|
|
32
|
+
warn 'Fetching all sources from all collectors...'
|
|
33
|
+
warn 'This may take a minute...'
|
|
34
|
+
|
|
35
|
+
all_sources = client.list_all_sources
|
|
36
|
+
|
|
37
|
+
output_json(
|
|
38
|
+
total_collectors: all_sources.size,
|
|
39
|
+
total_sources: all_sources.sum { |c| c['sources'].size },
|
|
40
|
+
data: all_sources.map { |item| format_collector_with_sources(item) }
|
|
41
|
+
)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def format_collector_with_sources(item)
|
|
45
|
+
{
|
|
46
|
+
collector: item['collector'],
|
|
47
|
+
sources: item['sources'].map { |s| format_source(s) }
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'base_command'
|
|
4
|
+
require_relative '../../utils/time_parser'
|
|
5
|
+
|
|
6
|
+
module Sumologic
|
|
7
|
+
class CLI < Thor
|
|
8
|
+
module Commands
|
|
9
|
+
# Handles the search command execution
|
|
10
|
+
class SearchCommand < BaseCommand
|
|
11
|
+
def execute
|
|
12
|
+
parse_time_options
|
|
13
|
+
log_search_info
|
|
14
|
+
results = perform_search
|
|
15
|
+
|
|
16
|
+
display_results_summary(results)
|
|
17
|
+
|
|
18
|
+
if options[:interactive]
|
|
19
|
+
launch_interactive_mode(results)
|
|
20
|
+
else
|
|
21
|
+
output_search_results(results)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
def parse_time_options
|
|
28
|
+
# Parse time formats and store both original and parsed values
|
|
29
|
+
@original_from = options[:from]
|
|
30
|
+
@original_to = options[:to]
|
|
31
|
+
@parsed_from = Utils::TimeParser.parse(options[:from])
|
|
32
|
+
@parsed_to = Utils::TimeParser.parse(options[:to])
|
|
33
|
+
@parsed_timezone = Utils::TimeParser.parse_timezone(options[:time_zone])
|
|
34
|
+
rescue Utils::TimeParser::ParseError => e
|
|
35
|
+
warn "Error parsing time: #{e.message}"
|
|
36
|
+
exit 1
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def log_search_info
|
|
40
|
+
warn '=' * 60
|
|
41
|
+
warn 'Sumo Logic Search Query'
|
|
42
|
+
warn '=' * 60
|
|
43
|
+
warn "Time Range: #{@original_from} to #{@original_to}"
|
|
44
|
+
if @original_from != @parsed_from || @original_to != @parsed_to
|
|
45
|
+
warn " (Parsed: #{@parsed_from} to #{@parsed_to})"
|
|
46
|
+
end
|
|
47
|
+
warn "Query: #{options[:query]}"
|
|
48
|
+
warn "Limit: #{options[:limit] || 'unlimited'}"
|
|
49
|
+
warn '-' * 60
|
|
50
|
+
warn 'Creating search job...'
|
|
51
|
+
$stderr.puts
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def perform_search
|
|
55
|
+
client.search(
|
|
56
|
+
query: options[:query],
|
|
57
|
+
from_time: @parsed_from,
|
|
58
|
+
to_time: @parsed_to,
|
|
59
|
+
time_zone: @parsed_timezone,
|
|
60
|
+
limit: options[:limit]
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def display_results_summary(results)
|
|
65
|
+
warn '=' * 60
|
|
66
|
+
warn "Results: #{results.size} messages"
|
|
67
|
+
warn '=' * 60
|
|
68
|
+
$stderr.puts
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def output_search_results(results)
|
|
72
|
+
output_json(
|
|
73
|
+
query: options[:query],
|
|
74
|
+
from: @parsed_from,
|
|
75
|
+
to: @parsed_to,
|
|
76
|
+
from_original: @original_from,
|
|
77
|
+
to_original: @original_to,
|
|
78
|
+
time_zone: @parsed_timezone,
|
|
79
|
+
message_count: results.size,
|
|
80
|
+
messages: results
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def launch_interactive_mode(results)
|
|
85
|
+
require_relative '../../interactive'
|
|
86
|
+
|
|
87
|
+
formatted_results = build_formatted_results(results)
|
|
88
|
+
Sumologic::Interactive.launch(formatted_results)
|
|
89
|
+
rescue Sumologic::Interactive::Error => e
|
|
90
|
+
warn e.message
|
|
91
|
+
exit 1
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def build_formatted_results(results)
|
|
95
|
+
{
|
|
96
|
+
'query' => options[:query],
|
|
97
|
+
'from' => @parsed_from,
|
|
98
|
+
'to' => @parsed_to,
|
|
99
|
+
'time_zone' => @parsed_timezone,
|
|
100
|
+
'message_count' => results.size,
|
|
101
|
+
'messages' => results
|
|
102
|
+
}
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|