Class: Riemann::Tools::SyslogNg

Inherits:
Object
  • Object
show all
Includes:
Riemann::Tools
Defined in:
lib/riemann/tools/syslog_ng.rb,
lib/riemann/tools/syslog_ng/version.rb

Constant Summary collapse

VERSION =
'1.0.1'

Instance Method Summary collapse

Instance Method Details

#dropped_statistic_state(metric) ⇒ Object



100
101
102
# File 'lib/riemann/tools/syslog_ng.rb', line 100

def dropped_statistic_state(metric)
  metric == 0.0 ? 'ok' : 'critical'
end

#force_reconnectObject



28
29
30
# File 'lib/riemann/tools/syslog_ng.rb', line 28

def force_reconnect
  @socket = nil
end

#queued_statistic_state(metric) ⇒ Object



104
105
106
107
108
109
110
111
112
# File 'lib/riemann/tools/syslog_ng.rb', line 104

def queued_statistic_state(metric)
  if metric >= opts[:queued_critical]
    'critical'
  elsif metric >= opts[:queued_warning]
    'warning'
  else
    'ok'
  end
end

#rejected_source_id?(source_id) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/riemann/tools/syslog_ng.rb', line 76

def rejected_source_id?(source_id)
  opts[:source_id] && !opts[:source_id].include?(source_id)
end

#rejected_source_instance?(source_instance) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/riemann/tools/syslog_ng.rb', line 80

def rejected_source_instance?(source_instance)
  opts[:source_instance] && !opts[:source_instance].include?(source_instance)
end

#rejected_source_name?(source_name) ⇒ Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/riemann/tools/syslog_ng.rb', line 72

def rejected_source_name?(source_name)
  opts[:source_name] && !opts[:source_name].include?(source_name)
end

#rejected_state?(state) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/riemann/tools/syslog_ng.rb', line 84

def rejected_state?(state)
  opts[:state] && !opts[:state].include?(state)
end

#rejected_type?(type) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/riemann/tools/syslog_ng.rb', line 88

def rejected_type?(type)
  opts[:type] && !opts[:type].include?(type)
end

#socketObject



24
25
26
# File 'lib/riemann/tools/syslog_ng.rb', line 24

def socket
  @socket ||= UNIXSocket.new(opts[:socket])
end

#statistic_state(type, metric) ⇒ Object



92
93
94
95
96
97
98
# File 'lib/riemann/tools/syslog_ng.rb', line 92

def statistic_state(type, metric)
  if type == 'dropped'
    dropped_statistic_state(metric)
  elsif type == 'queued'
    queued_statistic_state(metric)
  end
end

#statisticsObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/riemann/tools/syslog_ng.rb', line 45

def statistics
  res = []

  socket.puts 'STATS CSV'
  socket.gets # discard header
  while (line = socket.gets.chomp) != '.'
    source_name, source_id, source_instance, state, type, metric = line.split(';')

    next if rejected_source_name?(source_name)
    next if rejected_source_id?(source_id)
    next if rejected_source_instance?(source_instance)
    next if rejected_state?(state)
    next if rejected_type?(type)

    res << {
      source_name: source_name,
      source_id: source_id,
      source_instance: source_instance,
      state: state,
      type: type,
      metric: metric.to_f,
    }
  end

  res
end

#tickObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/riemann/tools/syslog_ng.rb', line 32

def tick
  statistics.each do |statistic|
    report({
             service: format(opts[:format], statistic),
             metric: statistic[:metric],
             state: statistic_state(statistic[:type], statistic[:metric]),
           })
  end
rescue Errno::EPIPE
  force_reconnect
  retry
end