Class: OpenVPNStatusWeb::Parser::ModernStateless

Inherits:
Object
  • Object
show all
Defined in:
lib/openvpn-status-web/parser/modern_stateless.rb

Class Method Summary collapse

Class Method Details

.parse_status_log(text, sep) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/openvpn-status-web/parser/modern_stateless.rb', line 6

def self.parse_status_log(text, sep)
  status = Status.new
  status.client_list_headers = []
  status.client_list = []
  status.routing_table_headers = []
  status.routing_table = []
  status.global_stats = []

  text.lines.each do |line|
    parts = line.strip.split(sep)
    status.client_list_headers = parts[2..] if parts[0] == 'HEADER' && parts[1] == 'CLIENT_LIST'
    status.client_list << parse_client(parts[1..], status.client_list_headers) if parts[0] == 'CLIENT_LIST'
    status.routing_table_headers = parts[2..] if parts[0] == 'HEADER' && parts[1] == 'ROUTING_TABLE'
    status.routing_table << parse_route(parts[1..], status.routing_table_headers) if parts[0] == 'ROUTING_TABLE'
    status.global_stats << parse_global(parts[1..2]) if parts[0] == 'GLOBAL_STATS'
  end

  status
end