Class: Sumologic::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sumologic/client.rb

Overview

Facade for Sumo Logic API operations Coordinates HTTP, Search, and Metadata components

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Client

rubocop:disable Metrics/MethodLength



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sumologic/client.rb', line 9

def initialize(config = nil) # rubocop:disable Metrics/MethodLength
  @config = config || Configuration.new
  @config.validate!

  # Initialize HTTP layer (v1 API)
  authenticator = Http::Authenticator.new(
    access_id: @config.access_id,
    access_key: @config.access_key
  )
  @http = Http::Client.new(
    base_url: @config.base_url,
    authenticator: authenticator,
    config: @config
  )

  # Initialize HTTP layer for v2 API (Content Library)
  @http_v2 = Http::Client.new(
    base_url: @config.base_url_v2,
    authenticator: authenticator,
    config: @config
  )

  # Initialize domain components
  @search = Search::Job.new(http_client: @http, config: @config)
  @collector = ::Collector.new(http_client: @http)
  @source = ::Source.new(http_client: @http, collector_client: @collector, config: @config)
   = ::SourceMetadataDiscovery.new(
    http_client: @http,
    search_job: @search,
    config: @config
  )
  @monitor = ::Monitor.new(http_client: @http)
  @folder = ::Folder.new(http_client: @http_v2) # Uses v2 API
  @dashboard = ::Dashboard.new(http_client: @http_v2)
  @health_event = ::HealthEvent.new(http_client: @http)
  @field = ::Field.new(http_client: @http)
  @lookup_table = ::LookupTable.new(http_client: @http)
  @app = ::App.new(http_client: @http)
  @content = ::Content.new(http_client: @http_v2) # Uses v2 API
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/sumologic/client.rb', line 7

def config
  @config
end

Instance Method Details

#discover_source_metadata(from_time:, to_time:, time_zone: 'UTC', **options) ⇒ Hash

Discover source metadata from actual log data Useful for CloudWatch/ECS sources with dynamic _sourceName values

Parameters:

  • from_time (String)

    Start time (ISO 8601, unix timestamp, or relative)

  • to_time (String)

    End time

  • time_zone (String) (defaults to: 'UTC')

    Time zone (default: UTC)

  • options (Hash)

    Optional filters — :filter, :keyword, :limit

Returns:

  • (Hash)

    Discovery results with source metadata



122
123
124
125
126
127
128
129
# File 'lib/sumologic/client.rb', line 122

def (from_time:, to_time:, time_zone: 'UTC', **options)
  .discover(
    from_time: from_time,
    to_time: to_time,
    time_zone: time_zone,
    **options
  )
end

#export_content(content_id:) ⇒ Hash

Export a content item as JSON Handles async job lifecycle: start, poll, fetch result

Parameters:

  • content_id (String)

    The content item ID to export

Returns:

  • (Hash)

    Exported content definition



280
281
282
# File 'lib/sumologic/client.rb', line 280

def export_content(content_id:)
  @content.export(content_id)
end

#folder_tree(folder_id: nil, max_depth: 3) ⇒ Hash

Get folder tree starting from a folder

Parameters:

  • folder_id (String, nil) (defaults to: nil)

    Starting folder ID (nil for personal)

  • max_depth (Integer) (defaults to: 3)

    Maximum recursion depth (default: 3)

Returns:

  • (Hash)

    Folder tree with nested children



177
178
179
# File 'lib/sumologic/client.rb', line 177

def folder_tree(folder_id: nil, max_depth: 3)
  @folder.tree(folder_id: folder_id, max_depth: max_depth)
end

#get_content(path:) ⇒ Hash

Get a content item by its library path

Parameters:

  • path (String)

    Content library path (e.g., ‘/Library/Users/me/My Search’)

Returns:

  • (Hash)

    Content item details



271
272
273
# File 'lib/sumologic/client.rb', line 271

def get_content(path:)
  @content.get_by_path(path)
end

#get_dashboard(dashboard_id:) ⇒ Hash

Get a specific dashboard by ID

Parameters:

  • dashboard_id (String)

    The dashboard ID

Returns:

  • (Hash)

    Dashboard hash including panels



197
198
199
# File 'lib/sumologic/client.rb', line 197

def get_dashboard(dashboard_id:)
  @dashboard.get(dashboard_id)
end

#get_folder(folder_id:) ⇒ Hash

Get a specific folder by ID

Parameters:

  • folder_id (String)

    The folder ID

Returns:

  • (Hash)

    Folder hash with children



168
169
170
# File 'lib/sumologic/client.rb', line 168

def get_folder(folder_id:)
  @folder.get(folder_id)
end

#get_lookup(lookup_id:) ⇒ Hash

Get a specific lookup table by ID

Parameters:

  • lookup_id (String)

    The lookup table ID

Returns:

  • (Hash)

    Lookup table details



248
249
250
# File 'lib/sumologic/client.rb', line 248

def get_lookup(lookup_id:)
  @lookup_table.get(lookup_id)
end

#get_monitor(monitor_id:) ⇒ Hash

Get a specific monitor by ID

Parameters:

  • monitor_id (String)

    The monitor ID

Returns:

  • (Hash)

    Monitor details



149
150
151
# File 'lib/sumologic/client.rb', line 149

def get_monitor(monitor_id:)
  @monitor.get(monitor_id)
end

#list_all_sources(collector: nil, name: nil, category: nil, limit: nil) ⇒ Array<Hash>

List all sources from all collectors with optional filtering

Parameters:

  • collector (String, nil) (defaults to: nil)

    Filter collectors by name

  • name (String, nil) (defaults to: nil)

    Filter sources by name

  • category (String, nil) (defaults to: nil)

    Filter sources by category

  • limit (Integer, nil) (defaults to: nil)

    Maximum total sources to return

Returns:

  • (Array<Hash>)

    Array of { ‘collector’ => Hash, ‘sources’ => Array<Hash> }



110
111
112
# File 'lib/sumologic/client.rb', line 110

def list_all_sources(collector: nil, name: nil, category: nil, limit: nil)
  @source.list_all(collector: collector, name: name, category: category, limit: limit)
end

#list_appsArray<Hash>

List available apps from the Sumo Logic app catalog

Returns:

  • (Array<Hash>)

    Array of app hashes



259
260
261
# File 'lib/sumologic/client.rb', line 259

def list_apps
  @app.list
end

#list_builtin_fieldsArray<Hash>

List built-in fields

Returns:

  • (Array<Hash>)

    Array of built-in field hashes



236
237
238
# File 'lib/sumologic/client.rb', line 236

def list_builtin_fields
  @field.list_builtin
end

#list_collectors(query: nil, limit: nil) ⇒ Array<Hash>

List collectors with optional filtering

Parameters:

  • query (String, nil) (defaults to: nil)

    Filter by name or category (case-insensitive)

  • limit (Integer, nil) (defaults to: nil)

    Maximum number of collectors to return

Returns:

  • (Array<Hash>)

    Array of collector hashes



91
92
93
# File 'lib/sumologic/client.rb', line 91

def list_collectors(query: nil, limit: nil)
  @collector.list(query: query, limit: limit)
end

#list_dashboards(limit: 100) ⇒ Array<Hash>

List all dashboards

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum dashboards to return (default: 100)

Returns:

  • (Array<Hash>)

    Array of dashboard hashes



189
190
191
# File 'lib/sumologic/client.rb', line 189

def list_dashboards(limit: 100)
  @dashboard.list(limit: limit)
end

#list_fieldsArray<Hash>

List custom fields

Returns:

  • (Array<Hash>)

    Array of field hashes



229
230
231
# File 'lib/sumologic/client.rb', line 229

def list_fields
  @field.list
end

#list_health_events(limit: 100) ⇒ Array<Hash>

List health events for collectors, sources, and ingest budgets

Parameters:

  • limit (Integer) (defaults to: 100)

    Maximum events to return (default: 100)

Returns:

  • (Array<Hash>)

    Array of health event hashes



218
219
220
# File 'lib/sumologic/client.rb', line 218

def list_health_events(limit: 100)
  @health_event.list(limit: limit)
end

#list_monitors(query: nil, status: nil, limit: 100) ⇒ Array<Hash>

List monitors with optional status and query filters

Parameters:

  • query (String, nil) (defaults to: nil)

    Search query to filter by name/description

  • status (String, nil) (defaults to: nil)

    Filter by status (Normal, Critical, Warning, MissingData, Disabled, AllTriggered)

  • limit (Integer) (defaults to: 100)

    Maximum monitors to return (default: 100)

Returns:

  • (Array<Hash>)

    Array of monitor hashes



141
142
143
# File 'lib/sumologic/client.rb', line 141

def list_monitors(query: nil, status: nil, limit: 100)
  @monitor.list(query: query, status: status, limit: limit)
end

#list_sources(collector_id:) ⇒ Array<Hash>

List sources for a specific collector

Parameters:

  • collector_id (String)

    The collector ID

Returns:

  • (Array<Hash>)

    Array of source hashes



99
100
101
# File 'lib/sumologic/client.rb', line 99

def list_sources(collector_id:)
  @source.list(collector_id: collector_id)
end

#personal_folderHash

Get the personal folder for current user

Returns:

  • (Hash)

    Folder hash with children



160
161
162
# File 'lib/sumologic/client.rb', line 160

def personal_folder
  @folder.personal
end

#search(query:, from_time:, to_time:, time_zone: 'UTC', limit: nil) ⇒ Array<Hash>

Search logs with query

Parameters:

  • query (String)

    Sumo Logic query

  • from_time (String)

    Start time (ISO 8601, unix timestamp, or relative)

  • to_time (String)

    End time

  • time_zone (String) (defaults to: 'UTC')

    Time zone (default: UTC)

  • limit (Integer, nil) (defaults to: nil)

    Maximum number of messages to return (stops fetching after limit)

Returns:

  • (Array<Hash>)

    Array of message hashes



58
59
60
61
62
63
64
65
66
# File 'lib/sumologic/client.rb', line 58

def search(query:, from_time:, to_time:, time_zone: 'UTC', limit: nil)
  @search.execute(
    query: query,
    from_time: from_time,
    to_time: to_time,
    time_zone: time_zone,
    limit: limit
  )
end

#search_aggregation(query:, from_time:, to_time:, time_zone: 'UTC', limit: nil) ⇒ Array<Hash>

Search with aggregation query (count by, group by, etc.)

Parameters:

  • query (String)

    Sumo Logic aggregation query (must include count, sum, avg, etc.)

  • from_time (String)

    Start time (ISO 8601, unix timestamp, or relative)

  • to_time (String)

    End time

  • time_zone (String) (defaults to: 'UTC')

    Time zone (default: UTC)

  • limit (Integer, nil) (defaults to: nil)

    Maximum number of records to return

Returns:

  • (Array<Hash>)

    Array of aggregation record hashes



76
77
78
79
80
81
82
83
84
# File 'lib/sumologic/client.rb', line 76

def search_aggregation(query:, from_time:, to_time:, time_zone: 'UTC', limit: nil)
  @search.execute_aggregation(
    query: query,
    from_time: from_time,
    to_time: to_time,
    time_zone: time_zone,
    limit: limit
  )
end

#search_dashboards(query:, limit: 100) ⇒ Array<Hash>

Search dashboards by title or description

Parameters:

  • query (String)

    Search query

  • limit (Integer) (defaults to: 100)

    Maximum results

Returns:

  • (Array<Hash>)

    Array of matching dashboard hashes



206
207
208
# File 'lib/sumologic/client.rb', line 206

def search_dashboards(query:, limit: 100)
  @dashboard.search(query: query, limit: limit)
end