pupmin 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4927470f62bbad5510c489d24a494773d8a1f5d8bed9a4ab38faf9afce981282
4
+ data.tar.gz: 5a71fcc8ccd90adff46495e869c341033c4b4eba62f52405ded740b1199da73a
5
+ SHA512:
6
+ metadata.gz: 37b7c451d2ba2acdf15d37231e923f491753c5ff70d850251e1212a0cd0b820dfaf70144dc9e110a2bfa971c19e8efb336515f966b61624eea3274c87a52f695
7
+ data.tar.gz: 316e87415fe24eb5547b03bafaef27c7f03e5689d68dd09ab72b61e3d0338060f9f8a9795c487e46c02c1aa101bfa5325046242e428347fd827ab20e12d24bd5
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /vendor/
10
+ /*.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pupit.gemspec
4
+ gemspec
5
+
6
+ gem 'puppetdb-ruby'
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ pupmin (1.0.1)
5
+ puppetdb-ruby (~> 1.2)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ httparty (0.17.1)
11
+ mime-types (~> 3.0)
12
+ multi_xml (>= 0.5.2)
13
+ mime-types (3.3)
14
+ mime-types-data (~> 3.2015)
15
+ mime-types-data (3.2019.1009)
16
+ multi_xml (0.6.0)
17
+ puppetdb-ruby (1.2.0)
18
+ httparty
19
+ rake (10.5.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 2.0)
26
+ pupmin!
27
+ puppetdb-ruby
28
+ rake (~> 10.0)
29
+
30
+ BUNDLED WITH
31
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Stephen Dunne
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # Pupmin
2
+
3
+ Pupmin is a toolkit and utility collection for working with a Puppet cluster. Most options will require a working PuppetDB server. This gem isn't meant to replace or be an alternative to other Puppet/PuppetDB gems, but rather just serve to be a shortcut and interface into some common administrative and management tasks.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pupmin'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pupmin
20
+
21
+ ## Usage
22
+
23
+ ### In Script/Application
24
+
25
+ Include the gem, then set the configuration before calling any of the classes/methods. At minimum, you need the PuppetDB server that you'll query:
26
+
27
+ ```ruby
28
+ Pupmin.configure({:puppetdb_url => 'http://puppetdb.yourdomain.tld:8080'})
29
+ ```
30
+ The PuppetDB class essentially just wraps the [VoxPupuli PuppetDB Gem](https://github.com/voxpupuli/puppetdb-ruby), so the same configuration block for SSL connections can be used here.
31
+
32
+ ## License
33
+
34
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pupmin"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/pupmin.rb ADDED
@@ -0,0 +1,20 @@
1
+ require_relative 'pupmin/version'
2
+ require_relative 'pupmin/util'
3
+ require_relative 'pupmin/puppetdb'
4
+ require_relative 'pupmin/reports'
5
+ require_relative 'pupmin/nodes'
6
+
7
+ ## main module file and configuration initialization
8
+ module Pupmin
9
+ class << self
10
+ attr_accessor :puppetdb_url, :puppetca_host, :puppet_certs
11
+
12
+ def configure(puppetdb_url: nil, puppetca_host: nil, puppet_certs: {})
13
+ @puppetdb_url = puppetdb_url
14
+ @puppetca_host = puppetca_host
15
+ @puppet_certs = puppet_certs
16
+ end
17
+ end
18
+
19
+ class Error < StandardError; end
20
+ end
@@ -0,0 +1,31 @@
1
+ module Pupmin
2
+ ## Node/Agent grouping and other informational helpers
3
+ class Nodes
4
+ ## Simple list all nodes by fqdn values
5
+ def self.all
6
+ puppetdb = Pupmin::PuppetDB.build
7
+ nodes = []
8
+ puppetdb.request('facts', ['=', 'name', 'fqdn']).data.each do |x|
9
+ nodes.push(x['value'])
10
+ end
11
+ nodes
12
+ end
13
+
14
+ ## Display a random number of hosts
15
+ def self.random(num = 5)
16
+ rand_hosts = []
17
+ all_hosts = all().shuffle!
18
+ # hosts.shuffle!
19
+ num.to_i.times do
20
+ rand_hosts.push(all_hosts.shift)
21
+ end
22
+ rand_hosts
23
+ end
24
+
25
+ def self.deactivate(certname)
26
+ pdb = Pupmin::PuppetDB.build
27
+ rsp = pdb.command('deactivate node', {'certname' => $certname, 'producer_timestamp' => Pupmin::Util.make_timestamp}, 3)
28
+ rsp.data
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,10 @@
1
+ require 'puppetdb'
2
+
3
+ module Pupmin
4
+ ## wrapper for the VoxPupuli PuppetDB gem.
5
+ class PuppetDB < PuppetDB::Client
6
+ def self.build
7
+ ::PuppetDB::Client.new(server: Pupmin.puppetdb_url, pem: Pupmin.puppet_certs)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ module Pupmin
2
+ ## shortcuts for some useful report information
3
+ class Reports
4
+ def self.call_query(query, options = {}, endpoint = 'reports')
5
+ puppetdb = Pupmin::PuppetDB.build
6
+ puppetdb.request(endpoint, query, options)
7
+ end
8
+
9
+ ## Get a list of reports by their status; defaults to just latest report
10
+ def self.by_status(status: 'changed', latest: true, options: {})
11
+ query = [
12
+ 'AND',
13
+ ['=', 'status', status.to_s],
14
+ ['=', 'latest_report?', latest.to_s]
15
+ ]
16
+
17
+ call_query(query, options)
18
+ end
19
+
20
+ ## Get a list of "aged" agents, i.e servers that last submitted a
21
+ ## report > threshold
22
+ def self.get_aged(threshold: 3600, options: {})
23
+ query = [
24
+ '<',
25
+ 'catalog_timestamp',
26
+ Pupmin::Util.make_timestamp(threshold.to_i)
27
+ ]
28
+
29
+ call_query(query, options, 'nodes')
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,12 @@
1
+ module Pupmin
2
+ ## Utilities/helpers for various things
3
+ class Util
4
+ ## PuppetDB seems to use a timestamp that isn't quite standard, so this
5
+ ## takes an offset, and creates the time used in reports
6
+ def self.make_timestamp(offset = 0)
7
+ current_time = Time.new.utc
8
+ adjusted_time = current_time - offset
9
+ adjusted_time.strftime('%FT%TZ')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Pupmin
2
+ VERSION = '1.0.1'
3
+ end
data/pupmin.gemspec ADDED
@@ -0,0 +1,42 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "pupmin/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pupmin"
8
+ spec.version = Pupmin::VERSION
9
+ spec.authors = ["Stephen Dunne"]
10
+ spec.email = ["stephen@icanhazmail.net"]
11
+
12
+ spec.summary = 'Puppet administrative and information toolkit'
13
+ spec.description = 'Collection of methods and bindings for quick access to various puppet administrative tasks'
14
+ spec.homepage = 'https://github.com/sedunne/pupmin.git'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = 'https://rubygems.org'
21
+
22
+ spec.metadata["homepage_uri"] = spec.homepage
23
+ spec.metadata["source_code_uri"] = 'https://github.com/sedunne/pupmin.git'
24
+ spec.metadata["changelog_uri"] = 'https://github.com/sedunne/pupmin.git/CHANGELOG.md'
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ # Specify which files should be added to the gem when it is released.
31
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
33
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
34
+ end
35
+ spec.bindir = "exe"
36
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ spec.require_paths = ["lib"]
38
+
39
+ spec.add_development_dependency "bundler", "~> 2.0"
40
+ spec.add_development_dependency "rake", "~> 10.0"
41
+ spec.add_dependency 'puppetdb-ruby', "~> 1.2"
42
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pupmin
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Stephen Dunne
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: puppetdb-ruby
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ description: Collection of methods and bindings for quick access to various puppet
56
+ administrative tasks
57
+ email:
58
+ - stephen@icanhazmail.net
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/pupmin.rb
72
+ - lib/pupmin/nodes.rb
73
+ - lib/pupmin/puppetdb.rb
74
+ - lib/pupmin/reports.rb
75
+ - lib/pupmin/util.rb
76
+ - lib/pupmin/version.rb
77
+ - pupmin.gemspec
78
+ homepage: https://github.com/sedunne/pupmin.git
79
+ licenses:
80
+ - MIT
81
+ metadata:
82
+ allowed_push_host: https://rubygems.org
83
+ homepage_uri: https://github.com/sedunne/pupmin.git
84
+ source_code_uri: https://github.com/sedunne/pupmin.git
85
+ changelog_uri: https://github.com/sedunne/pupmin.git/CHANGELOG.md
86
+ post_install_message:
87
+ rdoc_options: []
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ requirements: []
101
+ rubygems_version: 3.0.6
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Puppet administrative and information toolkit
105
+ test_files: []