Module: Icinga2::Converts

Included in:
Client
Defined in:
lib/icinga2/converts.rb

Overview

many convert functions

Class Method Summary collapse

Class Method Details

.format_service(name) ⇒ String

reformat a service check name

Parameters:

  • name (String)

Returns:

  • (String)


89
90
91
92
# File 'lib/icinga2/converts.rb', line 89

def self.format_service( name )
  service_map = name.split('!', 2)
  service_map.join( ' - ' )
end

.state_to_color(state, is_host = false) ⇒ String

convert a Icinga2 state into a named color

Parameters:

  • state (String)

    the Icinga2 State

  • is_host (Bool) (defaults to: false)

    (false) if this a Host or a Service Check

Returns:

  • (String)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/icinga2/converts.rb', line 54

def self.state_to_color( state, is_host = false )

  state =
  if( is_host == true )
    case state
    when 0
      'green'
    when 1
      'red'
    else
      'blue'
    end
  else
    case state
    when 0
      'green'
    when 1
      'yellow'
    when 2
      'red'
    when 3
      'purple'
    else
      'blue'
    end
  end
  state
end

.state_to_string(state, is_host = false) ⇒ String

convert a Icinga2 state into a human readable state

Parameters:

  • state (String)

    the Icinga2 State

  • is_host (Bool) (defaults to: false)

    (false) if this a Host or a Service Check

Returns:

  • (String)


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
# File 'lib/icinga2/converts.rb', line 18

def self.state_to_string( state, is_host = false )

  state =
  if( is_host == true )
    case state
    when 0
      'Up'
    when 1
      'Down'
    else
      'Undefined'
    end
  else
    case state
    when 0
      'OK'
    when 1
      'Warning'
    when 2
      'Critical'
    when 3
      'Unknown'
    else
      'Undefined'
    end
  end
  state
end