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.



147
148
149
# File 'lib/cute/taktuk.rb', line 147

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.



137
138
139
# File 'lib/cute/taktuk.rb', line 137

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.



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/cute/taktuk.rb', line 152

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.



190
191
192
193
194
195
# File 'lib/cute/taktuk.rb', line 190

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:(.*)



185
186
187
188
# File 'lib/cute/taktuk.rb', line 185

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