Class: AntisyslogPacket

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content.



82
83
84
# File 'lib/antisyslog.rb', line 82

def content
  @content
end

#facilityObject

Returns the value of attribute facility.



81
82
83
# File 'lib/antisyslog.rb', line 81

def facility
  @facility
end

#hostnameObject

Returns the value of attribute hostname.



81
82
83
# File 'lib/antisyslog.rb', line 81

def hostname
  @hostname
end

#severityObject

Returns the value of attribute severity.



81
82
83
# File 'lib/antisyslog.rb', line 81

def severity
  @severity
end

#tagObject

Returns the value of attribute tag.



81
82
83
# File 'lib/antisyslog.rb', line 81

def tag
  @tag
end

#timeObject

Returns the value of attribute time.



82
83
84
# File 'lib/antisyslog.rb', line 82

def time
  @time
end

Instance Method Details

#assembleObject



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}>#{generate_timestamp} #{@hostname} #{@tag}: #{@content}"
end

#facility_nameObject



161
162
163
# File 'lib/antisyslog.rb', line 161

def facility_name
  FACILITY_INDEX[@facility]
end

#generate_timestampObject



181
182
183
184
185
186
187
188
# File 'lib/antisyslog.rb', line 181

def generate_timestamp
  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

#priObject



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_nameObject



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_sObject



84
85
86
# File 'lib/antisyslog.rb', line 84

def to_s
  assemble
end