Class: Fluent::Plugin::SslCheckInput

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

Defined Under Namespace

Classes: SslClient

Constant Summary collapse

NAME =
'ssl_check'
DEFAULT_TAG =
NAME
DEFAULT_PORT =
443
DEFAULT_INTERVAL =
600
DEFAULT_SNI =
true
DEFAULT_VERIFY_MODE =
:peer
DEFAULT_TIMEOUT =
5
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



106
107
108
109
110
111
112
113
114
115
116
# File 'lib/fluent/plugin/in_ssl_check.rb', line 106

def check
  hosts.each do |host_full|
    host, port = host_full.split(':')
    port = (port || DEFAULT_PORT).to_i
    ssl_info = fetch_ssl_info(host, port)
    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, Metrics/AbcSize, Style/DoubleNegation

Raises:

  • (Fluent::ConfigError)


82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/fluent/plugin/in_ssl_check.rb', line 82

def configure(conf)
  super

  raise Fluent::ConfigError, 'tag can not be empty.' if !tag || tag.empty?
  raise Fluent::ConfigError, 'hosts can not be empty.' unless hosts
  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)
  raise Fluent::ConfigError, 'cert should be a file.' if cert && !File.file?(cert)
  raise Fluent::ConfigError, 'key should be a file.' if key && !File.file?(key)
  raise Fluent::ConfigError, 'cert and key should be specified.' if !!cert ^ !!key

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

#fetch_ssl_info(host, port) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/fluent/plugin/in_ssl_check.rb', line 118

def fetch_ssl_info(host, port)
  ssl_client = SslClient.new(
    host: host, port: port,
    ca_path: ca_path, ca_file: ca_file,
    sni: sni, verify_mode: ssl_verify_mode,
    cert: cert, key: key,
    timeout: timeout
  )
  ssl_client.ssl_info
end

#startObject

rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize, Style/DoubleNegation



98
99
100
101
102
103
104
# File 'lib/fluent/plugin/in_ssl_check.rb', line 98

def start
  super

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

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