Class: Cute::TakTuk::Stream Private
- Inherits:
-
Object
- Object
- Cute::TakTuk::Stream
- 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
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
- #types ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(types = []) ⇒ Stream
constructor
private
A new instance of Stream.
- #parse(string) ⇒ Object private
- #to_cmd ⇒ Object private
-
#treat_value(string) ⇒ Object
private
Return just the value 0:(.*).
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.
146 147 148 |
# File 'lib/cute/taktuk.rb', line 146 def initialize(types=[]) @types = types end |
Instance Attribute Details
#types ⇒ Object (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.
136 137 138 |
# File 'lib/cute/taktuk.rb', line 136 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.
151 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 |
# File 'lib/cute/taktuk.rb', line 151 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_cmd ⇒ 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.
189 190 191 192 193 194 |
# File 'lib/cute/taktuk.rb', line 189 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:(.*)
184 185 186 187 |
# File 'lib/cute/taktuk.rb', line 184 def treat_value(string) tmp = string.split(":",2) return tmp[1].nil? ? "" : tmp[1] end |