Class: Sumologic::Metadata::Source

Inherits:
Object
  • Object
show all
Includes:
Loggable
Defined in:
lib/sumologic/metadata/source.rb

Overview

Handles source metadata operations

Instance Method Summary collapse

Constructor Details

#initialize(http_client:, collector_client:, config: nil) ⇒ Source

Returns a new instance of Source.



12
13
14
15
16
17
# File 'lib/sumologic/metadata/source.rb', line 12

def initialize(http_client:, collector_client:, config: nil)
  @http = http_client
  @collector_client = collector_client
  @config = config
  @fetcher = CollectorSourceFetcher.new(config: @config)
end

Instance Method Details

#list(collector_id:) ⇒ Object

List sources for a specific collector Returns array of source objects with metadata



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sumologic/metadata/source.rb', line 21

def list(collector_id:)
  data = @http.request(
    method: :get,
    path: "/collectors/#{collector_id}/sources"
  )

  sources = data['sources'] || []
  log_info "Found #{sources.size} sources for collector #{collector_id}"
  sources
rescue StandardError => e
  raise Error, "Failed to list sources for collector #{collector_id}: #{e.message}"
end

#list_all(collector: nil, name: nil, category: nil, limit: nil) ⇒ Object

List all sources from all collectors with optional filtering Returns array of hashes with collector info and their sources Uses parallel fetching with thread pool for better performance

Parameters:

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

    Filter collectors by name (case-insensitive substring)

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

    Filter sources by name (case-insensitive substring)

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

    Filter sources by category (case-insensitive substring)

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

    Maximum total sources to return



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sumologic/metadata/source.rb', line 42

def list_all(collector: nil, name: nil, category: nil, limit: nil)
  collectors = @collector_client.list
  active_collectors = collectors.select { |c| c['alive'] }
  active_collectors = filter_collectors(active_collectors, collector) if collector

  log_info "Fetching sources for #{active_collectors.size} active collectors in parallel..."

  result = @fetcher.fetch_all(active_collectors) do |c|
    fetch_collector_sources(c)
  end

  result = filter_sources(result, name: name, category: category)
  result = apply_source_limit(result, limit) if limit

  log_info "Total: #{result.size} collectors with sources"
  result
rescue StandardError => e
  raise Error, "Failed to list all sources: #{e.message}"
end