Class: Gitchefsync::Notification

Inherits:
Object
  • Object
show all
Defined in:
lib/gitchefsync/notify.rb

Instance Method Summary collapse

Constructor Details

#initialize(smtp = "mail.rim.net", from = "[email protected]", to = '[email protected]', msg = "") ⇒ Notification

Returns a new instance of Notification.



9
10
11
12
13
14
# File 'lib/gitchefsync/notify.rb', line 9

def initialize(smtp="mail.rim.net", from="[email protected]",to='[email protected]', msg="")
  @to = to
  @from = from
  @smtp = smtp = Net::SMTP.start(smtp, 25)
  @hostname = FS.cmd "hostname"
end

Instance Method Details

#closeObject



70
71
72
# File 'lib/gitchefsync/notify.rb', line 70

def close
  @smtp.finish
end

#notifyFromAudit(audit_dir, audit_type) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitchefsync/notify.rb', line 16

def notifyFromAudit(audit_dir, audit_type)
  audit = Audit.new(audit_dir,audit_type)
  audit_list = audit.latestAuditItems

  audit_list.each do |audit_item|
    if audit_item.ex != nil
      h = audit_item.to_hash
      msg = "From: gichefsync <[email protected]>\nTo: #{h[:maintainer]} #{h[:maintainer_email]}\nSubject: gitchefsync failure\n"
      msg << "Alert from Hostname: #{@hostname}\n\n"
      msg << "Attention!\n\n"
      msg << "gitchefsync has identified you as the maintainer of this artifact\n"
      msg << "====================================\n"
      msg << "#{h[:name]}:#{h[:version]}\n"
      msg << "====================================\n"
      msg << "#{h[:exception]}"

      sendTo(h[:maintainer_email],msg)
      Gitchefsync.logger.info("event_id=email_sent=#{h[:maintainer_email]} ")
    end
  end
  Gitchefsync.logger.info("event_id=notification_complete:audit_type=#{audit_type}")
end

#send(body) ⇒ Object



62
63
64
# File 'lib/gitchefsync/notify.rb', line 62

def send(body)
  @smtp.send_message body, @from, @to
end

#sendTo(send_to, body) ⇒ Object



66
67
68
# File 'lib/gitchefsync/notify.rb', line 66

def sendTo(send_to, body)
  @smtp.send_message body, @from, send_to
end

#singleNotifyFromAudit(audit_dir, audit_type, to) ⇒ Object

Aggregates a single email to the “to” email parameter



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/gitchefsync/notify.rb', line 40

def singleNotifyFromAudit(audit_dir,audit_type,to)
  audit = Audit.new(audit_dir,audit_type)
  audit_list = audit.latestAuditItems
  msg = "From: gichefsync <[email protected]>\nTo: #{to}\nSubject: gitchefsync failure: summary\n\n"
  msg << "Alert from Hostname: #{@hostname}\n\n"
  audit_list.each do |audit_item|
    h = audit_item.to_hash

    if h[:exception] != nil
      ver = ""
      if !h[:version].empty? then ver = ":" + h[:version] end

      msg << "item: #{h[:name]}#{ver} was NOT processed with status #{h[:action]} "
      msg << "\nERROR #{h[:exception]}"
    else
      msg << "item: #{h[:name]} was NOT processed with status #{h[:action]} "
    end
    msg << "\n\n"
  end
  sendTo(to,msg)
end