Class: Fluent::Plugin::SslFileCheckInput

Inherits:
Input
  • Object
show all
Includes:
Fluent::Plugin::SslCheck::SslInputEmit
Defined in:
lib/fluent/plugin/in_ssl_file_check.rb

Constant Summary collapse

NAME =
'ssl_file_check'
DEFAULT_TAG =
NAME
DEFAULT_INTERVAL =
600
DEFAULT_LOG_EVENTS =
true
DEFAULT_METRIC_EVENTS =
false
DEFAULT_EVENT_PREFIX =
''
DEFAULT_TIMESTAMP_FORMAT =
:iso

Instance Method Summary collapse

Methods included from Fluent::Plugin::SslCheck::SslInputEmit

#emit_logs, #emit_metric_expirency, #emit_metric_status, #emit_metrics

Instance Method Details

#checkObject



87
88
89
90
91
92
93
94
95
# File 'lib/fluent/plugin/in_ssl_file_check.rb', line 87

def check
  paths.each do |cert_path|
    ssl_info = fetch_ssl_info(cert_path)
    emit_logs(ssl_info) if log_events
    emit_metrics(ssl_info) if metric_events
  rescue StandardError => e
    log.warn "#{NAME}#check: #{e}"
  end
end

#configure(conf) ⇒ Object

rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity

Raises:

  • (Fluent::ConfigError)


66
67
68
69
70
71
72
73
74
75
76
# File 'lib/fluent/plugin/in_ssl_file_check.rb', line 66

def configure(conf)
  super

  raise Fluent::ConfigError, 'tag can not be empty.' if !tag || tag.empty?
  raise Fluent::ConfigError, 'paths can not be empty.' unless paths
  raise Fluent::ConfigError, 'interval can not be < 1.' if !interval || interval < 1
  raise Fluent::ConfigError, 'ca_path should be a dir.' if ca_path && !File.directory?(ca_path)
  raise Fluent::ConfigError, 'ca_file should be a file.' if ca_file && !File.file?(ca_file)

  log.warn("#{NAME}: paths is empty, nothing to process") if paths.empty?
end

#fetch_ssl_info(filepath) ⇒ Object



97
98
99
100
# File 'lib/fluent/plugin/in_ssl_file_check.rb', line 97

def fetch_ssl_info(filepath)
  ssl_file = Fluent::Plugin::SslCheck::FileChecker.new(filepath, ca_path: ca_path, ca_file: ca_file)
  ssl_file.ssl_info
end

#startObject

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



79
80
81
82
83
84
85
# File 'lib/fluent/plugin/in_ssl_file_check.rb', line 79

def start
  super

  timer_execute(:ssl_file_check_timer, 1, repeat: false, &method(:check)) if interval > 60

  timer_execute(:ssl_file_check_timer, interval, repeat: true, &method(:check))
end