Class: MetOnTheMiddle::Readers::Base
- Inherits:
-
Object
- Object
- MetOnTheMiddle::Readers::Base
- Extended by:
- SingleForwardable
- Includes:
- Singleton
- Defined in:
- lib/met_on_the_middle/readers/base.rb
Overview
Classe base del reader, la quale deve rispondere con la chiave da utilizzare per dare un label al dato inviato (chiave per zabbix)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key) ⇒ Base
constructor
A new instance of Base.
-
#match_subscription ⇒ Object
Regular expression to match notifications Serve per attivare la subscription a determinati eventi di ActiveSupport::Notifications.
-
#parse(event, request: nil) ⇒ Object
metodo da utilizzare per parsare i dati.
- #register_subscription(tracker) ⇒ Object
- #to_key_value(event, request: nil) ⇒ Object
Constructor Details
#initialize(key) ⇒ Base
Returns a new instance of Base.
14 15 16 |
# File 'lib/met_on_the_middle/readers/base.rb', line 14 def initialize(key) @key = key end |
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
12 13 14 |
# File 'lib/met_on_the_middle/readers/base.rb', line 12 def key @key end |
Instance Method Details
#match_subscription ⇒ Object
Regular expression to match notifications Serve per attivare la subscription a determinati eventi di ActiveSupport::Notifications
22 23 24 |
# File 'lib/met_on_the_middle/readers/base.rb', line 22 def match_subscription '' end |
#parse(event, request: nil) ⇒ Object
metodo da utilizzare per parsare i dati
37 38 39 |
# File 'lib/met_on_the_middle/readers/base.rb', line 37 def parse(event, request: nil) event.name end |
#register_subscription(tracker) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/met_on_the_middle/readers/base.rb', line 46 def register_subscription(tracker) ActiveSupport::Notifications.subscribe match_subscription do |*args| if not tracker.nil? and not tracker.actual_request.nil? event = ActiveSupport::Notifications::Event.new *args tracker.add *self.to_key_value(event, request: tracker.actual_request) end end end |
#to_key_value(event, request: nil) ⇒ Object
41 42 43 |
# File 'lib/met_on_the_middle/readers/base.rb', line 41 def to_key_value(event, request: nil) return @key, parse(event, request: request) end |