Class: Fail2Ban

Inherits:
Component show all
Defined in:
lib/panda_motd/components/fail_2_ban.rb

Instance Attribute Summary

Attributes inherited from Component

#config, #errors, #name, #results

Instance Method Summary collapse

Methods inherited from Component

#lines_after, #lines_before

Constructor Details

#initialize(motd) ⇒ Fail2Ban

Returns a new instance of Fail2Ban.



4
5
6
# File 'lib/panda_motd/components/fail_2_ban.rb', line 4

def initialize(motd)
  super(motd, "fail_2_ban")
end

Instance Method Details

#processObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/panda_motd/components/fail_2_ban.rb', line 8

def process
  @results = {
    jails: {},
  }

  @config["jails"].each do |jail|
    status = jail_status(jail)
    @results[:jails][jail] = {
      total: status[:total],
      current: status[:current],
    }
  end
end

#to_sObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/panda_motd/components/fail_2_ban.rb', line 22

def to_s
  result = +"Fail2Ban:\n"
  @results[:jails].each do |name, stats|
    result << "  #{name}:\n"
    result << "    Total bans:   #{stats[:total]}\n"
    result << "    Current bans: #{stats[:current]}\n"
  end

  result.gsub!(/\s$/, "")
end