Module: ILO_SDK::LogEntryHelper

Included in:
Client
Defined in:
lib/ilo-sdk/helpers/log_entry_helper.rb

Overview

Contains helper methods for Log Entry actions

Instance Method Summary collapse

Instance Method Details

#clear_logs(log_type) ⇒ Object

Clear the specified logs

Parameters:

  • log_type (String, Symbol)

Returns:

  • true

Raises:

  • (RuntimeError)

    if the request failed



34
35
36
37
38
39
# File 'lib/ilo-sdk/helpers/log_entry_helper.rb', line 34

def clear_logs(log_type)
  new_action = { 'Action' => 'ClearLog' }
  response = rest_post(uri_for_log_type(log_type), body: new_action)
  response_handler(response)
  true
end

#get_logs(severity_level, duration, log_type) ⇒ Array

Get the specified logs

Parameters:

  • severity_level (String, Symbol, NilClass)

    Set to nil to get all logs

  • duration (String, Symbol)

    Up to this many hours ago

  • log_type (String, Symbol)

    IEL or IML

Returns:

  • (Array)

    log entries

Raises:

  • (RuntimeError)

    if the request failed



56
57
58
59
60
61
62
63
64
65
# File 'lib/ilo-sdk/helpers/log_entry_helper.rb', line 56

def get_logs(severity_level, duration, log_type)
  response = rest_get("#{uri_for_log_type(log_type)}Entries/")
  entries = response_handler(response)['Items']
  start_time = Time.now.utc - (duration * 3600)
  if severity_level.nil?
    entries.select { |e| Time.parse(e['Created']) > start_time }
  else
    entries.select { |e| severity_level.to_s.casecmp(e['Severity']) == 0 && Time.parse(e['Created']) > start_time }
  end
end

#logs_empty?(log_type) ⇒ TrueClass, FalseClass

Check to see if the specified logs are empty

Parameters:

  • log_type (String, Symbol)

Returns:

  • (TrueClass, FalseClass)

    logs_empty

Raises:

  • (RuntimeError)

    if the request failed



45
46
47
48
# File 'lib/ilo-sdk/helpers/log_entry_helper.rb', line 45

def logs_empty?(log_type)
  response = rest_get("#{uri_for_log_type(log_type)}Entries/")
  response_handler(response)['Items'].empty?
end

#uri_for_log_type(log_type, id = 1) ⇒ String

Get the URI for the specified log type

Parameters:

  • log_type (String, Symbol)

Returns:

  • (String)

    URI of log service

Raises:

  • (RuntimeError)

    if type is invalid



21
22
23
24
25
26
27
28
# File 'lib/ilo-sdk/helpers/log_entry_helper.rb', line 21

def uri_for_log_type(log_type, id = 1)
  resource = case log_type.to_s.upcase
             when 'IEL' then 'Managers'
             when 'IML' then 'Systems'
             else raise "Invalid log_type '#{log_type}'. Valid options are IEL and IML"
             end
  "/redfish/v1/#{resource}/#{id}/LogServices/#{log_type.upcase}/"
end