Class: Gitchefsync::Notification
- Inherits:
-
Object
- Object
- Gitchefsync::Notification
- Defined in:
- lib/gitchefsync/notify.rb
Instance Method Summary collapse
- #close ⇒ Object
- #hasDelta(item1, item2) ⇒ Object
-
#initialize(smtp = "mail.rim.net", from = "[email protected]", to = '[email protected]', msg = "") ⇒ Notification
constructor
A new instance of Notification.
- #notifyFromAudit(audit_dir, audit_type) ⇒ Object
- #send(body) ⇒ Object
- #sendTo(send_to, body) ⇒ Object
-
#singleNotifyFromAudit(audit_dir, audit_type, to) ⇒ Object
Aggregates a single email to the “to” email parameter.
Constructor Details
#initialize(smtp = "mail.rim.net", from = "[email protected]", to = '[email protected]', msg = "") ⇒ Notification
Returns a new instance of Notification.
25 26 27 28 29 30 |
# File 'lib/gitchefsync/notify.rb', line 25 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
#close ⇒ Object
126 127 128 |
# File 'lib/gitchefsync/notify.rb', line 126 def close @smtp.finish end |
#hasDelta(item1, item2) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/gitchefsync/notify.rb', line 55 def hasDelta(item1,item2) if item1.nil? || item2.nil? return true end i1 = item1.to_hash i2 = item2.to_hash if !i1[:extra_info].nil? && !i2[:extra_info].nil? if !i1[:extra_info]['digest'].nil? && !i1[:extra_info]['digest'].eql?(i2[:extra_info]['digest']) then return true end if !i1[:extra_info]['sha'].nil? && !i1[:extra_info]['sha'].eql?(i2[:extra_info]['sha']) then return true end end return false end |
#notifyFromAudit(audit_dir, audit_type) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gitchefsync/notify.rb', line 32 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
118 119 120 |
# File 'lib/gitchefsync/notify.rb', line 118 def send(body) @smtp. body, @from, @to end |
#sendTo(send_to, body) ⇒ Object
122 123 124 |
# File 'lib/gitchefsync/notify.rb', line 122 def sendTo(send_to, body) @smtp. body, @from, send_to end |
#singleNotifyFromAudit(audit_dir, audit_type, to) ⇒ Object
Aggregates a single email to the “to” email parameter
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/gitchefsync/notify.rb', line 72 def singleNotifyFromAudit(audit_dir,audit_type,to) audit = Audit.new(audit_dir,audit_type) audit_list = audit.latestAuditItems prev_audit = audit.auditItems(-2) if audit_list.nil? Gitchefsync.logger.warn "event_id=unable_to_notify:msg=audit_list_isnull:type=#{audit_type}" return end empty = true msg = "From: gitchefsync <[email protected]>\nTo: #{to}\nSubject: gitchefsync failure: summary\n\n" msg << "Alert from Hostname: #{@hostname}\n" type = "Environment" if audit_type.eql?("cb") type = "Cookbooks" end msg << "Notification Type: #{type}\n\n" audit_list.each do |audit_item| h = audit_item.to_hash Gitchefsync.logger.debug "processing item: #{h} ex=#{h[:exception]} #{!h[:exception].nil? && !h[:exception].empty?}" if !h[:exception].nil? && !h[:exception].empty? if !prev_audit.nil? && hasDelta(audit_item,audit.itemByNameVersion(h[:name],h[:version],prev_audit)) Gitchefsync.logger.debug "item_has_exception=#{h}" msg << "item: #{h[:name]}:#{h[:version]} was NOT processed with status #{h[:action]}\n" msg << "audit_json= #{h}" msg << "ERROR #{h[:exception]}\n\n" empty = false end end end if !empty Gitchefsync.logger.debug "sending msg=#{msg}" sendTo(to,msg) else Gitchefsync.logger.info "event_id=no_message_sent" end end |