Class: SyslogSD::Notifier
- Inherits:
-
Object
- Object
- SyslogSD::Notifier
- Defined in:
- lib/syslog-sd/notifier.rb
Overview
syslog notifier.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#collect_file_and_line ⇒ Object
Returns the value of attribute collect_file_and_line.
-
#default_options ⇒ Object
Returns the value of attribute default_options.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#level ⇒ Object
Returns the value of attribute level.
-
#level_mapping ⇒ Object
Returns the value of attribute level_mapping.
-
#rescue_network_errors ⇒ Object
Returns the value of attribute rescue_network_errors.
-
#timestamp_as_float ⇒ Object
Returns the value of attribute timestamp_as_float.
Instance Method Summary collapse
-
#addresses ⇒ Object
Get a list of receivers.
-
#addresses=(addrs) ⇒ Object
Set a list of receivers.
- #disable ⇒ Object
- #enable ⇒ Object
- #host ⇒ Object
-
#initialize(host = 'localhost', port = 514, default_options = {}) ⇒ Notifier
constructor
host
andport
are host/ip and port of syslog server. -
#notify(*args) ⇒ Object
Same as notify!, but rescues all exceptions (including
ArgumentError
) and sends them instead. -
#notify!(*args) ⇒ Object
Sends message to Graylog2 server.
- #port ⇒ Object
Constructor Details
#initialize(host = 'localhost', port = 514, default_options = {}) ⇒ Notifier
host
and port
are host/ip and port of syslog server. default_options
is used in notify!
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/syslog-sd/notifier.rb', line 9 def initialize(host = 'localhost', port = 514, = {}) @enabled = true @collect_file_and_line = true @sd_id = "_@37797" self.level = SyslogSD::DEBUG self. = false self.rescue_network_errors = false self. = self.['host'] ||= Socket.gethostname self.['level'] ||= SyslogSD::UNKNOWN self.['facility'] ||= 'syslog-sd-rb' self.['procid'] ||= Process.pid @sender = RubyUdpSender.new([[host, port]]) self.level_mapping = :logger end |
Instance Attribute Details
#collect_file_and_line ⇒ Object
Returns the value of attribute collect_file_and_line.
4 5 6 |
# File 'lib/syslog-sd/notifier.rb', line 4 def collect_file_and_line @collect_file_and_line end |
#default_options ⇒ Object
Returns the value of attribute default_options.
5 6 7 |
# File 'lib/syslog-sd/notifier.rb', line 5 def @default_options end |
#enabled ⇒ Object
Returns the value of attribute enabled.
4 5 6 |
# File 'lib/syslog-sd/notifier.rb', line 4 def enabled @enabled end |
#level ⇒ Object
Returns the value of attribute level.
5 6 7 |
# File 'lib/syslog-sd/notifier.rb', line 5 def level @level end |
#level_mapping ⇒ Object
Returns the value of attribute level_mapping.
5 6 7 |
# File 'lib/syslog-sd/notifier.rb', line 5 def level_mapping @level_mapping end |
#rescue_network_errors ⇒ Object
Returns the value of attribute rescue_network_errors.
4 5 6 |
# File 'lib/syslog-sd/notifier.rb', line 4 def rescue_network_errors @rescue_network_errors end |
#timestamp_as_float ⇒ Object
Returns the value of attribute timestamp_as_float.
4 5 6 |
# File 'lib/syslog-sd/notifier.rb', line 4 def @timestamp_as_float end |
Instance Method Details
#addresses ⇒ Object
Get a list of receivers.
notifier.addresses # => [['localhost', 12201], ['localhost', 12202]]
30 31 32 |
# File 'lib/syslog-sd/notifier.rb', line 30 def addresses @sender.addresses end |
#addresses=(addrs) ⇒ Object
Set a list of receivers.
notifier.addresses = [['localhost', 12201], ['localhost', 12202]]
36 37 38 |
# File 'lib/syslog-sd/notifier.rb', line 36 def addresses=(addrs) @sender.addresses = addrs end |
#disable ⇒ Object
75 76 77 |
# File 'lib/syslog-sd/notifier.rb', line 75 def disable @enabled = false end |
#enable ⇒ Object
79 80 81 |
# File 'lib/syslog-sd/notifier.rb', line 79 def enable @enabled = true end |
#host ⇒ Object
40 41 42 43 |
# File 'lib/syslog-sd/notifier.rb', line 40 def host warn "SyslogSD::Notifier#host is deprecated. Use #addresses instead." self.addresses.first[0] end |
#notify(*args) ⇒ Object
Same as notify!, but rescues all exceptions (including ArgumentError
) and sends them instead.
85 86 87 |
# File 'lib/syslog-sd/notifier.rb', line 85 def notify(*args) notify_with_level(nil, *args) end |
#notify!(*args) ⇒ Object
Sends message to Graylog2 server. args
can be:
-
hash-like object (any object which responds to
to_hash
, includingHash
instance):notify!(:short_message => 'All your rebase are belong to us', :user => 'AlekSi')
-
exception with optional hash-like object:
notify!(SecurityError.new('ALARM!'), :trespasser => 'AlekSi')
-
string-like object (anything which responds to
to_s
) with optional hash-like object:notify!('Plain olde text message', :scribe => 'AlekSi')
Resulted fields are merged with default_options
, the latter will never overwrite the former. This method will raise ArgumentError
if arguments are wrong. Consider using notify instead.
99 100 101 |
# File 'lib/syslog-sd/notifier.rb', line 99 def notify!(*args) notify_with_level!(nil, *args) end |
#port ⇒ Object
45 46 47 48 |
# File 'lib/syslog-sd/notifier.rb', line 45 def port warn "SyslogSD::Notifier#port is deprecated. Use #addresses instead." self.addresses.first[1] end |