Class: AntisyslogPacket
- Inherits:
-
Object
- Object
- AntisyslogPacket
- Defined in:
- lib/antisyslog.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#facility ⇒ Object
Returns the value of attribute facility.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#severity ⇒ Object
Returns the value of attribute severity.
-
#tag ⇒ Object
Returns the value of attribute tag.
-
#time ⇒ Object
Returns the value of attribute time.
Instance Method Summary collapse
- #assemble ⇒ Object
- #facility_name ⇒ Object
- #generate_timestamp ⇒ Object
- #pri ⇒ Object
- #pri=(p) ⇒ Object
- #severity_name ⇒ Object
- #string_bytesize(string) ⇒ Object
- #to_s ⇒ Object
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
82 83 84 |
# File 'lib/antisyslog.rb', line 82 def content @content end |
#facility ⇒ Object
Returns the value of attribute facility.
81 82 83 |
# File 'lib/antisyslog.rb', line 81 def facility @facility end |
#hostname ⇒ Object
Returns the value of attribute hostname.
81 82 83 |
# File 'lib/antisyslog.rb', line 81 def hostname @hostname end |
#severity ⇒ Object
Returns the value of attribute severity.
81 82 83 |
# File 'lib/antisyslog.rb', line 81 def severity @severity end |
#tag ⇒ Object
Returns the value of attribute tag.
81 82 83 |
# File 'lib/antisyslog.rb', line 81 def tag @tag end |
#time ⇒ Object
Returns the value of attribute time.
82 83 84 |
# File 'lib/antisyslog.rb', line 82 def time @time end |
Instance Method Details
#assemble ⇒ Object
88 89 90 91 92 93 |
# File 'lib/antisyslog.rb', line 88 def assemble() unless @hostname and @facility and @severity and @tag raise "Could not assemble packet without hostname, tag, facility, and severity" end "<#{pri}>#{} #{@hostname} #{@tag}: #{@content}" end |
#facility_name ⇒ Object
161 162 163 |
# File 'lib/antisyslog.rb', line 161 def facility_name FACILITY_INDEX[@facility] end |
#generate_timestamp ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/antisyslog.rb', line 181 def time = @time || Time.now # The timestamp format requires that a day with fewer than 2 digits have # what would normally be a preceding zero, be instead an extra space. day = time.strftime("%d") day = day.sub(/^0/, ' ') if day =~ /^0\d/ time.strftime("%b #{day} %H:%M:%S") end |
#pri ⇒ Object
169 170 171 |
# File 'lib/antisyslog.rb', line 169 def pri (@facility * 8) + @severity end |
#pri=(p) ⇒ Object
173 174 175 176 177 178 179 |
# File 'lib/antisyslog.rb', line 173 def pri=(p) unless p.is_a? Integer and (0..191).include?(p) raise ArgumentError.new "PRI must be a number between 0 and 191" end @facility = p / 8 @severity = p - (@facility * 8) end |
#severity_name ⇒ Object
165 166 167 |
# File 'lib/antisyslog.rb', line 165 def severity_name SEVERITY_INDEX[@severity] end |
#string_bytesize(string) ⇒ Object
191 192 193 |
# File 'lib/antisyslog.rb', line 191 def string_bytesize(string) string.bytesize end |
#to_s ⇒ Object
84 85 86 |
# File 'lib/antisyslog.rb', line 84 def to_s assemble end |