Module: Awspec::Helper::Finder::CloudwatchLogs

Included in:
Awspec::Helper::Finder
Defined in:
lib/awspec/helper/finder/cloudwatch_logs.rb

Instance Method Summary collapse

Instance Method Details

#find_cloudwatch_logs_group(id) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/awspec/helper/finder/cloudwatch_logs.rb', line 4

def find_cloudwatch_logs_group(id)
  cloudwatch_logs_client.describe_log_groups({
                                               log_group_name_prefix: id
                                             }).log_groups.find do |log_group|
    log_group.log_group_name == id
  end
end

#find_cloudwatch_logs_metric_fileter_by_log_group_name(id, filter_name) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/awspec/helper/finder/cloudwatch_logs.rb', line 37

def find_cloudwatch_logs_metric_fileter_by_log_group_name(id, filter_name)
  cloudwatch_logs_client.describe_metric_filters({
                                                   log_group_name: id,
                                                   filter_name_prefix: filter_name
                                                 }).metric_filters.find do |filter|
    filter.filter_name == filter_name
  end
end

#find_cloudwatch_logs_stream_by_log_group_name(id, stream_name) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/awspec/helper/finder/cloudwatch_logs.rb', line 16

def find_cloudwatch_logs_stream_by_log_group_name(id, stream_name)
  req = {
    log_group_name: id,
    log_stream_name_prefix: stream_name
  }
  ret = nil
  loop do
    res = cloudwatch_logs_client.describe_log_streams(req)
    res.log_streams.find do |log_stream|
      if log_stream[:log_stream_name] == stream_name
        ret = log_stream[:log_stream_name]
        break
      end
    end
    break if ret.present?
    break if res.next_token.nil?
    req[:next_token] = res.next_token
  end
  ret
end

#find_cloudwatch_logs_subscription_fileter_by_log_group_name(id, filter_name) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/awspec/helper/finder/cloudwatch_logs.rb', line 46

def find_cloudwatch_logs_subscription_fileter_by_log_group_name(id, filter_name)
  cloudwatch_logs_client.describe_subscription_filters({
                                                         log_group_name: id,
                                                         filter_name_prefix: filter_name
                                                       }).subscription_filters.find do |filter|
    filter.filter_name == filter_name
  end
end

#find_tags_by_log_group_name(id) ⇒ Object



67
68
69
# File 'lib/awspec/helper/finder/cloudwatch_logs.rb', line 67

def find_tags_by_log_group_name(id)
  cloudwatch_logs_client.list_tags_log_group(log_group_name: id)[:tags]
end

#last_cloudwatch_logs_stream_by_log_group_name(id) ⇒ Object



12
13
14
# File 'lib/awspec/helper/finder/cloudwatch_logs.rb', line 12

def last_cloudwatch_logs_stream_by_log_group_name(id)
  cloudwatch_logs_client.describe_log_streams({ log_group_name: id }).log_streams.last
end

#select_all_cloudwatch_logs_log_groupsObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/awspec/helper/finder/cloudwatch_logs.rb', line 55

def select_all_cloudwatch_logs_log_groups
  req = {}
  log_groups = []
  loop do
    res = cloudwatch_logs_client.describe_log_groups(req)
    log_groups.push(*res.log_groups)
    break if res.next_token.nil?
    req[:next_token] = res.next_token
  end
  log_groups
end