Class: LogStash::Inputs::SensorPush
- Inherits:
-
Base
- Object
- Base
- LogStash::Inputs::SensorPush
- Defined in:
- lib/logstash/inputs/sensorpush.rb
Instance Method Summary collapse
- #register ⇒ Object
-
#run(queue) ⇒ Object
def register.
-
#stop ⇒ Object
def run.
Instance Method Details
#register ⇒ Object
140 141 142 143 |
# File 'lib/logstash/inputs/sensorpush.rb', line 140 def register @logger.info("Connecting to SensorPush API", :email => @email) @conn = SensorPushApiConnection.new(@email, @password, @logger) end |
#run(queue) ⇒ Object
def register
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/logstash/inputs/sensorpush.rb', line 145 def run(queue) # we can abort the loop if stop? becomes true time_by_sensor = {} while !stop? now = DateTime.now @logger.debug("Getting sensors from SensorPush API") sensors = @conn.get_sensors_map sensors.each_value { |sensor| sensor_id = sensor["id"] last_read = time_by_sensor[sensor_id] @logger.debug("Getting latest values from SensorPush API", :sensor_id => sensor_id, :since => last_read) if last_read latest_values = @conn.get_latest_values(sensor, now, last_read) else latest_values = @conn.get_latest_values(sensor) end unless latest_values.empty? time_by_sensor[sensor_id] = DateTime.parse(latest_values.map { |v| v["observed"] }.max) latest_values.each { |reading| = reading["observed"] sensorpush = { sensor: sensor, reading: reading } event = LogStash::Event.new("@timestamp" => , "sensorpush" => sensorpush) decorate(event) queue << event } end } # because the sleep interval can be big, when shutdown happens # we want to be able to abort the sleep # Stud.stoppable_sleep will frequently evaluate the given block # and abort the sleep(@interval) if the return value is true Stud.stoppable_sleep(@interval) { stop? } end # loop end |
#stop ⇒ Object
def run
194 195 196 197 198 199 200 |
# File 'lib/logstash/inputs/sensorpush.rb', line 194 def stop # nothing to do in this case so it is not necessary to define stop # examples of common "stop" tasks: # * close sockets (unblocking blocking reads/accepts) # * cleanup temporary files # * terminate spawned threads end |