Class: Cute::TakTuk::Stream Private

Inherits:
Object
  • Object
show all
Defined in:
lib/cute/taktuk.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Parses the output generated by taktuk

Direct Known Subclasses

StateStream

Constant Summary collapse

SEPARATOR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'/'
SEPESCAPED =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Regexp.escape(SEPARATOR)
IP_REGEXP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"(?:(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}"\
"(?:[0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"
DOMAIN_REGEXP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"(?:(?:[a-zA-Z]|[a-zA-Z][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*"\
"(?:[A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])"
HOSTNAME_REGEXP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

"#{IP_REGEXP}|#{DOMAIN_REGEXP}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(types = []) ⇒ Stream

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Stream.



89
90
91
# File 'lib/cute/taktuk.rb', line 89

def initialize(types=[])
  @types = types
end

Instance Attribute Details

#typesObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



79
80
81
# File 'lib/cute/taktuk.rb', line 79

def types
  @types
end

Instance Method Details

#parse(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/cute/taktuk.rb', line 94

def parse(string)

  results = {}
  if string and !string.empty?
#          regexp = /^(output)#{SEPESCAPED}(#{HOSTNAME_REGEXP})#{SEPESCAPED}(.+)$/
    regexp = /^(#{HOSTNAME_REGEXP})#{SEPESCAPED}(.[a-z]*)#{SEPESCAPED}(.+)$/
    string.each_line do |line|
      if regexp =~ line
        hostname = Regexp.last_match(1)
        stream_type = Regexp.last_match(2).to_sym
        value_tmp = treat_value(Regexp.last_match(3))
        value =  value_tmp.is_i? ? value_tmp.to_i : value_tmp
        results[hostname] ||= {}
        if results[hostname][stream_type].nil? then
          results[hostname][stream_type] =  value
        else
          if value.is_a?(String) then
            results[hostname][stream_type]+="\n" + value
          else
            # This is for adding status codes
            results[hostname][stream_type]= [results[hostname][stream_type], value]
            results[hostname][stream_type].flatten!

          end
        end
      end
    end
  end
  return results

end

#to_cmdObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



132
133
134
135
136
137
# File 'lib/cute/taktuk.rb', line 132

def to_cmd
  # "\"$type#{SEPARATOR}$host#{SEPARATOR}$start_date#{SEPARATOR}$line\\n\""
  # We put "0:" before $line only for performance issues when executing the regex
  "\"$host#{SEPARATOR}$type#{SEPARATOR}0:$line\\n\""

end

#treat_value(string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Return just the value 0:(.*)



127
128
129
130
# File 'lib/cute/taktuk.rb', line 127

def treat_value(string)
  tmp = string.split(":",2)
  value = tmp[1].nil? ? "" : tmp[1]
end