Class: Kafo::PuppetFailedResource

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/puppet_failed_resource.rb

Instance Method Summary collapse

Constructor Details

#initialize(status, logs) ⇒ PuppetFailedResource

Returns a new instance of PuppetFailedResource.

Parameters:

  • status (Hash)

    The status hash from the report

  • logs (Array[Hash])

    Relevant log lines for this resoure



7
8
9
10
# File 'lib/kafo/puppet_failed_resource.rb', line 7

def initialize(status, logs)
  @status = status
  @logs = logs
end

Instance Method Details

#event_messagesArray[String]

Returns The event messages.

Returns:

  • (Array[String])

    The event messages



38
39
40
# File 'lib/kafo/puppet_failed_resource.rb', line 38

def event_messages
  @status['events'].map { |event| event['message'] }
end

#log_messagesArray[String]

A collection of Puppet log messages

The log messages include detailed information of what failed. Some debug information, such as timing but crucially the command output, both stdout and stderr.

Returns:

  • (Array[String])

    The Puppet log messages for this resource



49
50
51
# File 'lib/kafo/puppet_failed_resource.rb', line 49

def log_messages
  @logs.map { |log| log['message'] }
end

#log_messages_by_sourceHash[String, Array[String]]

A collection of Puppet log messages grouped by source

The log messages include detailed information of what failed. Some debug information, such as timing but crucially the command output, both stdout and stderr.

A resource can have multiple sources. For example, exec can have both unless and returns. Combining the output of those can be confusing, so this presents them separate.

Returns:

  • (Hash[String, Array[String]])

    The Puppet log messages for this resource



64
65
66
# File 'lib/kafo/puppet_failed_resource.rb', line 64

def log_messages_by_source
  @logs.group_by { |log| log['source'] }.transform_values { |logs| logs.map { |log| log['message'] } }
end

#resourceString

Returns A resource.

Examples:

puppet_failed_resource.resource == 'Exec[/bin/true]'

Returns:

  • (String)

    A resource



15
16
17
# File 'lib/kafo/puppet_failed_resource.rb', line 15

def resource
  @status['resource']
end

#titleString

Returns A resource title.

Examples:

puppet_failed_resource.title == '/bin/true'

Returns:

  • (String)

    A resource title



29
30
31
# File 'lib/kafo/puppet_failed_resource.rb', line 29

def title
  @status['title']
end

#to_sObject



33
34
35
# File 'lib/kafo/puppet_failed_resource.rb', line 33

def to_s
  "Puppet #{type} resource '#{title}'"
end

#typeString

Returns A resource type.

Examples:

puppet_failed_resource.type == 'Exec'

Returns:

  • (String)

    A resource type



22
23
24
# File 'lib/kafo/puppet_failed_resource.rb', line 22

def type
  @status['resource_type']
end