chef-handler-users 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "chef-handler-users"
6
- gem.version = "0.0.2"
6
+ gem.version = "0.0.3"
7
7
  gem.authors = ["Heavy Water Operations, LLC. (OR)"]
8
8
  gem.email = ["ops@hw-ops.com"]
9
9
  gem.homepage = "http://github.com/heavywater/chef-handler-users"
@@ -14,5 +14,7 @@ Gem::Specification.new do |gem|
14
14
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
15
  gem.require_paths = ["lib"]
16
16
 
17
+ gem.add_runtime_dependency "pony"
18
+
17
19
  gem.add_development_dependency "rake"
18
20
  end
@@ -18,35 +18,51 @@
18
18
 
19
19
  require 'rubygems'
20
20
  require 'chef/handler'
21
- # require 'pony'
21
+ require 'pony'
22
22
 
23
23
  class Chef::Handler::Users < Chef::Handler
24
24
  attr_reader :config
25
+
25
26
  def initialize(config={})
26
27
  @config = config
28
+ @config[:to_address] ||= "no@email.com"
29
+ @config[:from_address] ||= "yomommas@house.com"
27
30
  @config[:path] ||= "/var/chef/reports/users"
28
31
  @config
29
32
  end
30
33
 
31
34
  def report
32
- build_report_dir
33
- savetime = Time.now.strftime("%Y%m%d%H%M%S")
34
-
35
- updated_users = run_status.updated_resources.inject([]) do |updated_users, resource|
36
- updated_users << resource if resource.resource_name =~ /user/i
37
- updated_users
35
+ updated_users = run_status.updated.resources.find do |resource|
36
+ resource.resource_name == "user"
38
37
  end
39
38
 
40
- File.open(File.join(config[:path], "chef-run-report-#{savetime}.json"), "w") do |file|
41
- file.puts Chef::JSONCompat.to_json_pretty(updated_users)
42
- end
39
+ subject = "Chef run on #{node.name} at #{Time.now.asctime} resulted in change of #{updated_users.length} users"
40
+ message = generate_email_body(updated_users)
41
+
42
+ Pony.mail(:to => @config[:to_address],
43
+ :from => @config[:from_address],
44
+ :subject => subject,
45
+ :body => message)
43
46
  end
44
47
 
45
- def build_report_dir
46
- unless File.exists?(config[:path])
47
- FileUtils.mkdir_p(config[:path])
48
- File.chmod(00700, config[:path])
49
- end
48
+ def generate_email_body users
49
+ users.inject([]) do |body, user|
50
+ body << summary_for_user(user)
51
+ body
52
+ end.join("\n")
53
+ end
54
+
55
+ def summary_for_user user
56
+ <<-EOH
57
+ User #{user.name} updated:
58
+ - resource action: #{user.action}
59
+ - comment (GECOS): #{user.comment}
60
+ - system username: #{user.username}
61
+ - system uid: #{user.uid}
62
+ - system gid: #{user.gid}
63
+ - system shell: #{user.shell}
64
+ - system user: #{user.system}
65
+ EOH
50
66
  end
51
67
 
52
68
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-handler-users
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,24 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-06 00:00:00.000000000 Z
12
+ date: 2012-12-07 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: pony
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
14
30
  - !ruby/object:Gem::Dependency
15
31
  name: rake
16
32
  requirement: !ruby/object:Gem::Requirement