Class: Katello::UINotifications::Hosts::LifecycleExpireSoon
- Inherits:
-
Object
- Object
- Katello::UINotifications::Hosts::LifecycleExpireSoon
- Defined in:
- app/services/katello/ui_notifications/hosts/lifecycle_expire_soon.rb
Class Method Summary collapse
- .blueprint ⇒ Object
- .deliver! ⇒ Object
- .existing_notification(release) ⇒ Object
- .hosts_with_index(release) ⇒ Object
- .message(options) ⇒ Object
Class Method Details
.blueprint ⇒ Object
52 53 54 |
# File 'app/services/katello/ui_notifications/hosts/lifecycle_expire_soon.rb', line 52 def self.blueprint @blueprint ||= NotificationBlueprint.find_by(name: 'host_lifecycle_expire_soon') end |
.deliver! ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/services/katello/ui_notifications/hosts/lifecycle_expire_soon.rb', line 5 def self.deliver! ::Katello::RhelLifecycleStatus.lifecycles_expire_soon.each do |release, schedule| schedule.each do |lifecycle, end_date| count = hosts_with_index(release).count next if count == 0 = (count: count, release: release, lifecycle: lifecycle, end_date: end_date) if (notification = existing_notification(release)) /[^:]+: (?<number_of_hosts>\d+) hosts/ =~ notification. next if number_of_hosts == count.to_s notification.update(message: ) else ::Notification.create!( :initiator => User.anonymous_admin, :audience => Notification::AUDIENCE_GLOBAL, :message => , :expired_at => end_date.strftime('%Y-%m-%d'), :notification_blueprint => blueprint ) end end end end |
.existing_notification(release) ⇒ Object
29 30 31 |
# File 'app/services/katello/ui_notifications/hosts/lifecycle_expire_soon.rb', line 29 def self.existing_notification(release) blueprint.notifications.where("message like ?", "#{release}%").first end |
.hosts_with_index(release) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/services/katello/ui_notifications/hosts/lifecycle_expire_soon.rb', line 44 def self.hosts_with_index(release) /RHEL(?<major>\d+)/ =~ release ::Host::Managed.joins(:operatingsystem, :fact_values, :fact_names) .where(fact_names: {name: "distribution::name"}) .where("fact_values.value like ?", "Red Hat Enterprise Linux%") .where(operatingsystem: {major: major}) end |
.message(options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'app/services/katello/ui_notifications/hosts/lifecycle_expire_soon.rb', line 33 def self.() ::UINotifications::StringParser.new( blueprint., :number_of_hosts => [:count], :release => [:release], :lifecycle => [:lifecycle].gsub(/_/, " "), :end_date => [:end_date].strftime('%Y-%m-%d'), :audience => Notification::AUDIENCE_GLOBAL ) end |