Class: SyslogTls::Header

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

Overview

All headers by specification wrapped in single object

Constant Summary collapse

FACILITIES =
{}
SEVERITIES =
{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHeader

Returns a new instance of Header.



37
38
39
40
41
42
43
44
45
46
# File 'lib/syslog_tls/protocol.rb', line 37

def initialize
  @timestamp = Time.now
  @severity = 'INFO'
  @facility = 'LOCAL0'
  @version = 1
  @hostname = NIL_VALUE
  @app_name = NIL_VALUE
  @procid = NIL_VALUE
  @msgid = NIL_VALUE
end

Instance Attribute Details

#app_nameObject

Returns the value of attribute app_name.



28
29
30
# File 'lib/syslog_tls/protocol.rb', line 28

def app_name
  @app_name
end

#facilityObject

Returns the value of attribute facility.



29
30
31
# File 'lib/syslog_tls/protocol.rb', line 29

def facility
  @facility
end

#hostnameObject

Returns the value of attribute hostname.



28
29
30
# File 'lib/syslog_tls/protocol.rb', line 28

def hostname
  @hostname
end

#msgidObject

Returns the value of attribute msgid.



28
29
30
# File 'lib/syslog_tls/protocol.rb', line 28

def msgid
  @msgid
end

#procidObject

Returns the value of attribute procid.



28
29
30
# File 'lib/syslog_tls/protocol.rb', line 28

def procid
  @procid
end

#severityObject

Returns the value of attribute severity.



29
30
31
# File 'lib/syslog_tls/protocol.rb', line 29

def severity
  @severity
end

#timestampObject

Returns the value of attribute timestamp.



29
30
31
# File 'lib/syslog_tls/protocol.rb', line 29

def timestamp
  @timestamp
end

#versionObject

Returns the value of attribute version.



28
29
30
# File 'lib/syslog_tls/protocol.rb', line 28

def version
  @version
end

Instance Method Details

#assembleObject



69
70
71
72
73
74
75
# File 'lib/syslog_tls/protocol.rb', line 69

def assemble
  [
    "<#{pri}>#{timestamp.to_datetime.strftime("%b %d %H:%M:%S")}",
    hostname,
    app_name
  ].join(' ')
end

#priObject

Priority value is calculated by first multiplying the Facility number by 8 and then adding the numerical value of the Severity.



65
66
67
# File 'lib/syslog_tls/protocol.rb', line 65

def pri
  FACILITIES[facility] * 8 + SEVERITIES[severity]
end

#to_sObject



77
78
79
# File 'lib/syslog_tls/protocol.rb', line 77

def to_s
  assemble
end