foreman_expire_hosts 2.0.0 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a7e5fececc8a6357b994cfdf74ea38209c525017
4
- data.tar.gz: aecb6afe763b2133c97d6857aebd17fb81cd6ef4
3
+ metadata.gz: e6fe2409547a823dfd323178e3d0919eac77bebc
4
+ data.tar.gz: 87226ce69f178e588ca451eef22a0d8982bc1f99
5
5
  SHA512:
6
- metadata.gz: 44dadad8e98963b00b856b3e74fbe3cb14ba98c729fa54ad3007dd4c51fcdbcc5f63dfdb58b34693a43b613388d7e0396a7b1c2bce994a27e894bd4780d4b80c
7
- data.tar.gz: e26f4b92ed9d29a45e72e6748b2141b82bb687482b15999474b95fbe1d9e244f74c6d6ba55b54c47751baf11b68bb0a52851a4b2928f290c7c4b5a1a8e471e89
6
+ metadata.gz: 815773fd3b98e15221daca80534cbf0ab0cc376ae4328409df26564a19bcfac2bea34d4aad22095e42439c7273726d909a005b8a6ae70ca7e4ede080e4436eea
7
+ data.tar.gz: e556d4c3b0ff806fd126551cc7af2d36af1bc033e0ed0946cc947f64c8470a87cd3ce60555fd5f14d792bd99139df3c416e44f980df37db1c74dc2d41d4787bf
data/README.md CHANGED
@@ -2,11 +2,17 @@
2
2
 
3
3
  # Context
4
4
 
5
- Foreman makes host creation extremely simple for a sysadmin or a user. However this simplicity lead to wasteful usage of compute resources. foreman_expiry plugin allows to specify an expiry date for the host. On this date the host will be deleted.
5
+ Foreman makes host creation extremely simple for a sysadmin or a user. However this simplicity leads to wasteful usage of compute resources. foreman_expiry plugin allows to specify an expiry date for the host. On this date the host will be deleted.
6
6
 
7
- This plugin add expired on(date) field to host form under Additional Information section. If we create any host with expiry date, then that host will be stopped on given date and then deleted. If host has null/blank for expired on field then that host will be live forever (until it deleted manually).
7
+ This plugin add expired on(date) field to host form under Additional Information section. If we create any host with expiry date, then that host will be stopped on given date and then deleted. If a host has no expiration date set then that host will live forever (until it is deleted manually).
8
8
 
9
- This plugin will send two warning notification before host expiry (see settings.yaml). It also sends notifications when the host stopped on its expiry date and when host is deleted after few days (configured in settings).
9
+ This plugin will send two warning notification before host expiry (see Settings). It also sends notifications when the host stopped on its expiry date and when host is deleted after few days (configured in settings).
10
+
11
+ ## Compatibility
12
+
13
+ | Foreman Version | Plugin Version |
14
+ | --------------- | -------------- |
15
+ | >= 1.11 | ~> 2.0 |
10
16
 
11
17
  # Screenshots
12
18
  ![Expiry date field in host form](https://raw.githubusercontent.com/ingenico-group/screenshots/master/foreman_host_expiry/expiry-date-field-in-host-form.png)
@@ -21,42 +27,43 @@ Please see the Foreman manual for appropriate instructions:
21
27
 
22
28
  * [Foreman: How to Install a Plugin](http://theforeman.org/manuals/latest/index.html#6.Plugins)
23
29
 
24
- Example installation from source.
25
- Require foreman_expire_hosts gem installation (edit `~foreman/bundler.d/Gemfile.local.rb`):
26
-
27
- ```yaml
28
- gem 'foreman_expire_hosts', :git => "https://github.com/ingenico-group/foreman_expire_hosts.git"
29
- ```
30
+ The gem name is "foreman_expire_hosts".
30
31
 
31
- Update Foreman with the new gems:
32
+ RPM users can install the "tfm-rubygem-foreman_expire_hosts" or
33
+ "rubygem-foreman_expire_hosts" packages.
32
34
 
33
- bundle update foreman_expire_hosts
35
+ This plugin has not been packeged for Debian, yet.
34
36
 
35
- # Dependency
36
-
37
- This gem required uglifier, execjs and therubyracer gems to load assets. If you install this plugin through RPM package, please install ruby193-rubygem-uglifier, ruby193-rubygem-execjs and ruby193-rubygem-therubyracer rpm package before installing this plugin RPM package
38
37
 
39
38
  # Post installation
40
39
 
41
40
  This plugin needs additional column in hosts table. Please run migration with below command
42
41
 
43
42
  ```yaml
44
- VERSION=20150427101516 RAILS_ENV=production rake db:migrate:up
43
+ VERSION=20150427101516 foreman-rake db:migrate:up
45
44
  ```
46
45
 
47
- Add below line to crontab under root user to take appropriate action on expiring/expired hosts and notify user about those hosts. This cronjob will run at 11:30 PM(Midnight)
46
+ If you have not installed this plugin through os packages, add below line to crontab to take appropriate action on expiring/expired hosts and notify user about those hosts. This cronjob will run at 07:45 AM.
48
47
 
49
48
 
50
49
  ```
51
- 30 23 * * * /usr/sbin/foreman-rake expired_hosts:deliver_notifications >> /var/log/foreman/expired_hosts.log 2>&1
50
+ # /etc/cron.d/foreman_expire_hosts
51
+ SHELL=/bin/sh
52
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
53
+
54
+ RAILS_ENV=production
55
+ FOREMAN_HOME=/usr/share/foreman
56
+
57
+ # Send out notifications about expired hosts
58
+ 45 7 * * * foreman /usr/sbin/foreman-rake expired_hosts:deliver_notifications >>/var/log/foreman/expired_hosts.log 2>&1
52
59
  ```
53
60
 
54
61
  # Pre remove
55
62
 
56
- If we want to remove this feature and remove expired_on column from hosts table, please run below rake task and remove this gem from the Gemfile
63
+ If we want to remove this feature and remove the expired_on column from hosts table, please run below rake task and either remove this gem from the Gemfile or uninstall the os package.
57
64
 
58
65
  ```yaml
59
- VERSION=20150427101516 RAILS_ENV=production rake db:migrate:down
66
+ VERSION=20150427101516 foreman-rake db:migrate:down
60
67
  ```
61
68
 
62
69
  # Configuration
@@ -65,7 +72,7 @@ This plugin will add configurations to settings table and are editable from sett
65
72
 
66
73
  ![Plugin Settings](https://raw.githubusercontent.com/ingenico-group/screenshots/master/foreman_host_expiry/settings.png)
67
74
 
68
- NOTE: After installing this plugin, please update administrator email in Foreman Web UI (More -> Settings -> General) with valid email. This can be used to send notification when plugin failed to deliver notifications to its owner.
75
+ NOTE: After installing this plugin, please update administrator email in Foreman Web UI (More -> Settings -> General) with valid email. This can be used to send notifications when the plugin failed to deliver notifications to its owner.
69
76
 
70
77
 
71
78
  # Foreman API to add expiry date to host
@@ -74,8 +81,8 @@ Existing foreman host create/edit API can be used to add/update host's expiry da
74
81
 
75
82
  Create host with expiry date
76
83
 
77
- ```yaml
78
- POST /api/hosts
84
+ ```ruby
85
+ # POST /api/hosts
79
86
  {
80
87
  "host": {
81
88
  "name": "testhost11",
@@ -99,13 +106,15 @@ POST /api/hosts
99
106
 
100
107
  curl command example
101
108
 
102
- ```yaml
109
+ ```sh
103
110
  curl -u admin:changeme 'https://your-foreman-url.com/api/hosts' -d 'host[name]=testhost11&host[expired_on]=30/12/2014&......' -X POST
111
+
104
112
  ```
113
+
105
114
  Update host expiry date
106
115
 
107
- ```yaml
108
- POST /api/hosts/testhost11
116
+ ```ruby
117
+ # POST /api/hosts/testhost11
109
118
  {
110
119
  "host": {
111
120
  "expired_on": "30/12/2014" # dd/mm/yyyy format
@@ -115,10 +124,23 @@ POST /api/hosts/testhost11
115
124
 
116
125
  curl command example
117
126
 
118
- ```yaml
127
+ ```sh
119
128
  curl -u admin:changeme 'https://your-foreman-url.com/api/hosts/testhost11' -d 'host[expired_on]=30/12/2014' -X PUT
120
129
  ```
121
130
 
122
- ## License
131
+ # Copyright
132
+
133
+ Copyright (c) 2016 The Foreman developers
134
+
135
+ This program is free software: you can redistribute it and/or modify
136
+ it under the terms of the GNU General Public License as published by
137
+ the Free Software Foundation, either version 3 of the License, or
138
+ (at your option) any later version.
139
+
140
+ This program is distributed in the hope that it will be useful,
141
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
142
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
143
+ GNU General Public License for more details.
123
144
 
124
- GPLv3
145
+ You should have received a copy of the GNU General Public License
146
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
@@ -4,8 +4,9 @@ module ForemanExpireHosts
4
4
 
5
5
  included do
6
6
  before_filter :validate_multiple_expiration, :only => :update_multiple_expiration
7
- before_filter :find_multiple, :only => [:select_multiple_expiration, :update_multiple_expiration]
7
+ before_filter :find_multiple_with_expire_hosts, :only => [:select_multiple_expiration, :update_multiple_expiration]
8
8
  alias_method_chain :action_permission, :expire_hosts
9
+ alias_method :find_multiple_with_expire_hosts, :find_multiple
9
10
  end
10
11
 
11
12
  def select_multiple_expiration
@@ -0,0 +1,15 @@
1
+ module ForemanExpireHosts
2
+ module AuditsHelperExtensions
3
+ extend ActiveSupport::Concern
4
+
5
+ def destroyed_expired_host_audit_comment_in_list(audit)
6
+ return unless audit.auditable_type.to_s == 'Host' && audit.action == 'destroy' && !audit.comment.blank?
7
+ "<div style='color: #737373;font-size: 14px'>Comment: #{audit.comment}</div>".html_safe
8
+ end
9
+
10
+ def destroyed_expired_host_audit_comment_in_show(audit)
11
+ return unless audit.auditable_type.to_s == 'Host' && audit.action == 'destroy' && !audit.comment.blank?
12
+ "<tr><td>Comment</td><td>#{audit.comment}</td></tr>".html_safe
13
+ end
14
+ end
15
+ end
@@ -24,18 +24,23 @@ module ForemanExpireHosts
24
24
  message
25
25
  end
26
26
 
27
- def destroyed_expired_host_audit_comment_in_list(audit)
28
- return unless audit.auditable_type.to_s == 'Host' && audit.action == 'destroy' && !audit.comment.blank?
29
- "<div style='color: #737373;font-size: 14px'>Comment: #{audit.comment}</div>".html_safe
27
+ def future_time_in_words(to_time, options = {})
28
+ distance_of_time_in_words(to_time, Time.current, options)
30
29
  end
31
30
 
32
- def destroyed_expired_host_audit_comment_in_show(audit)
33
- return unless audit.auditable_type.to_s == 'Host' && audit.action == 'destroy' && !audit.comment.blank?
34
- "<tr><td>Comment</td><td>#{audit.comment}</td></tr>".html_safe
31
+ def input_group_addon(content, options = {})
32
+ content_tag :span, class: 'input-group-addon' do
33
+ content_tag :span, content, options
34
+ end
35
35
  end
36
36
 
37
- def future_time_in_words(to_time, options = {})
38
- distance_of_time_in_words(to_time, Time.current, options)
37
+ def datepicker_f(f, attr, options = {})
38
+ field(f, attr, options) do
39
+ addClass options, "form-control"
40
+ date = f.text_field attr, options
41
+ addon = input_group_addon('', :class => 'glyphicon glyphicon-calendar')
42
+ input_group date, addon
43
+ end
39
44
  end
40
45
  end
41
46
  end
@@ -18,7 +18,7 @@ module ForemanExpireHosts
18
18
  scope :expiring_today, -> { expiring.with_expire_date(Date.today) }
19
19
  scope :expired_past_grace_period, -> { expiring.where('expired_on < ?', Date.today + Setting[:days_to_delete_after_host_expiration].to_i) }
20
20
 
21
- scoped_search :on => :expired_on, :complete_value => :true, :rename => :expires
21
+ scoped_search :on => :expired_on, :complete_value => :true, :rename => :expires, :only_explicit => true
22
22
  end
23
23
 
24
24
  def validate_expired_on
@@ -2,7 +2,7 @@
2
2
  <%= stylesheet 'foreman_expire_hosts/application' %>
3
3
  <%= javascript 'foreman_expire_hosts/application' %>
4
4
  <% end %>
5
- <%= text_f f, :expired_on,
5
+ <%= datepicker_f f, :expired_on,
6
6
  :value => @host.expired_on.try(:strftime, '%d/%m/%Y'),
7
7
  :data => { provide: @host.can_modify_expiry_date? ? 'datepicker' : 'readonly',
8
8
  orientation: 'top left',
@@ -6,7 +6,7 @@
6
6
 
7
7
  <%= _('Host will be deleted automatically on given expired date. Leave blank to clear expiration date.') %>
8
8
 
9
- <%= text_f f, :expired_on,
9
+ <%= datepicker_f f, :expired_on,
10
10
  :value => (Date.today + 14).strftime('%d/%m/%Y'),
11
11
  :data => { provide: 'datepicker',
12
12
  orientation: 'top left',
@@ -33,13 +33,13 @@ module ExpireHostsNotifications
33
33
  unless deleted_hosts.empty?
34
34
  ExpireHostsNotifications.hosts_by_user(deleted_hosts).each do |user_id, hosts_hash|
35
35
  catch_delivery_errors(_('Failed to deliver deleted hosts notification'), deleted_hosts) do
36
- ExpireHostsMailer.deleted_hosts_notification(hosts_hash['email'], hosts_hash['hosts']).deliver_now
36
+ ExpireHostsMailer.deleted_hosts_notification(hosts_hash['email'], hosts_hash['hosts']).deliver
37
37
  end
38
38
  end
39
39
  end
40
40
  return if failed_delete_hosts.empty?
41
41
  catch_delivery_errors(_('Failed to deliver deleted hosts notification failed status'), failed_delete_hosts) do
42
- ExpireHostsMailer.failed_to_delete_hosts_notification(self.admin_email, failed_delete_hosts).deliver_now
42
+ ExpireHostsMailer.failed_to_delete_hosts_notification(self.admin_email, failed_delete_hosts).deliver
43
43
  end
44
44
  end
45
45
 
@@ -65,13 +65,13 @@ module ExpireHostsNotifications
65
65
  delete_date = (Date.today + self.days_to_delete_after_expired.to_i)
66
66
  hosts_by_user(stopped_hosts).each do |user_id, hosts_hash|
67
67
  catch_delivery_errors(_('Failed to deliver stopped hosts notification'), stopped_hosts) do
68
- ExpireHostsMailer.stopped_hosts_notification(hosts_hash['email'], delete_date, hosts_hash['hosts']).deliver_now
68
+ ExpireHostsMailer.stopped_hosts_notification(hosts_hash['email'], delete_date, hosts_hash['hosts']).deliver
69
69
  end
70
70
  end
71
71
  end
72
72
  return if failed_stop_hosts.empty?
73
73
  catch_delivery_errors(_('Failed to deliver stopped hosts notification failed status'), failed_stop_hosts) do
74
- ExpireHostsMailer.failed_to_stop_hosts_notification(self.admin_email, failed_stop_hosts).deliver_now
74
+ ExpireHostsMailer.failed_to_stop_hosts_notification(self.admin_email, failed_stop_hosts).deliver
75
75
  end
76
76
  end
77
77
 
@@ -83,7 +83,7 @@ module ExpireHostsNotifications
83
83
  unless notifiable_hosts.empty?
84
84
  hosts_by_user(notifiable_hosts).each do |user_id, hosts_hash|
85
85
  catch_delivery_errors(_('Failed to deliver expiring hosts notification'), notifiable_hosts) do
86
- ExpireHostsMailer.expiry_warning_notification(hosts_hash['email'], expiry_date, hosts_hash['hosts']).deliver_now
86
+ ExpireHostsMailer.expiry_warning_notification(hosts_hash['email'], expiry_date, hosts_hash['hosts']).deliver
87
87
  end
88
88
  end
89
89
  end
@@ -37,6 +37,7 @@ module ForemanExpireHosts
37
37
  Host::Managed.send :include, ForemanExpireHosts::HostExt
38
38
  HostsHelper.send :include, ForemanExpireHosts::HostsHelperExtensions
39
39
  HostsController.send :include, ForemanExpireHosts::HostControllerExtensions
40
+ AuditsHelper.send :include, ForemanExpireHosts::AuditsHelperExtensions
40
41
  rescue => e
41
42
  Rails.logger.warn "ForemanExpireHosts: skipping engine hook (#{e})"
42
43
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanExpireHosts
2
- VERSION = '2.0.0'.freeze
2
+ VERSION = '2.0.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_expire_hosts
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nagarjuna Rachaneni
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-06-10 00:00:00.000000000 Z
12
+ date: 2016-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: deface
@@ -88,6 +88,7 @@ files:
88
88
  - app/assets/javascripts/foreman_expire_hosts/datepicker_for_host_expired_on_field.js
89
89
  - app/assets/stylesheets/foreman_expire_hosts/application.scss
90
90
  - app/controllers/concerns/foreman_expire_hosts/host_controller_extensions.rb
91
+ - app/helpers/concerns/foreman_expire_hosts/audits_helper_extensions.rb
91
92
  - app/helpers/concerns/foreman_expire_hosts/hosts_helper_extensions.rb
92
93
  - app/helpers/expire_hosts_mailer_helper.rb
93
94
  - app/mailers/expire_hosts_mailer.rb