Class: Notifu::Actors::GammuSmsBridge

Inherits:
Notifu::Actor show all
Defined in:
lib/notifu/actors/gammu_sms_bridge.rb

Instance Attribute Summary

Attributes inherited from Notifu::Actor

#contacts, #issue

Instance Method Summary collapse

Methods inherited from Notifu::Actor

#load_data, #perform

Methods included from Util

option

Instance Method Details

#actObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/notifu/actors/gammu_sms_bridge.rb', line 9

def act
  data = OpenStruct.new({
    notifu_id: self.issue.notifu_id,
    host: self.issue.host,
    message: self.issue.message,
    service: self.issue.service,
    status: self.issue.code.to_state,
    first_event: Time.at(self.issue.time_created.to_i),
    duration: (Time.now.to_i - self.issue.time_created.to_i).duration,
    occurrences_count: self.issue.occurrences_count,
    occurrences_trigger: self.issue.occurrences_trigger
  })
  message = ERB.new(self.template).result(data.instance_eval {binding})

  self.contacts.each do |contact|
    cell = contact.cell
    template = ERB.new File.new("sms.erb").read, nil, "%"
    message = "template.result(self.issue)"

    # send message to sms-bridge
    socket = TCPSocket.new Notifu::CONFIG[:actors][:gammu_sms_bridge][:host], Notifu::CONFIG[:actors][:gammu_sms_bridge][port]
    socket.send contact.cell.to_s + "--" + message
    socket.close
    socket = nil
  end
end

#templateObject



36
37
38
# File 'lib/notifu/actors/gammu_sms_bridge.rb', line 36

def template
    "<%= data[:status] %> [<%= data[:host] %>/<%= data[:service] %>]: (<%= data[:message] %>) <%= data[:duration] %> [<%= data[:notifu_id] %>]"
end