puppet-herald 0.1.0
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 +15 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +5 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/bin/puppet-herald +13 -0
- data/config.ru +2 -0
- data/db/migrate/20141211165540_create_nodes.rb +10 -0
- data/db/migrate/20141211171305_create_reports.rb +16 -0
- data/db/migrate/20141211171326_create_log_entries.rb +13 -0
- data/db/schema.rb +47 -0
- data/db/seeds.rb +0 -0
- data/lib/puppet-herald.rb +37 -0
- data/lib/puppet-herald/app.rb +112 -0
- data/lib/puppet-herald/cli.rb +53 -0
- data/lib/puppet-herald/database.rb +50 -0
- data/lib/puppet-herald/javascript.rb +34 -0
- data/lib/puppet-herald/models/log-entry.rb +3 -0
- data/lib/puppet-herald/models/node.rb +7 -0
- data/lib/puppet-herald/models/report.rb +78 -0
- data/lib/puppet-herald/public/.bowerrc +3 -0
- data/lib/puppet-herald/public/app.js +27 -0
- data/lib/puppet-herald/public/bower.json +15 -0
- data/lib/puppet-herald/public/components/artifact/artifact-directive.js +12 -0
- data/lib/puppet-herald/public/components/artifact/artifact-directive_test.js +17 -0
- data/lib/puppet-herald/public/components/artifact/artifact.js +31 -0
- data/lib/puppet-herald/public/components/directives/directives.js +5 -0
- data/lib/puppet-herald/public/components/directives/status-button.html +7 -0
- data/lib/puppet-herald/public/components/directives/status-button.js +54 -0
- data/lib/puppet-herald/public/components/filters/filters.js +12 -0
- data/lib/puppet-herald/public/css/herald.css +38 -0
- data/lib/puppet-herald/public/img/shield97.svg +17 -0
- data/lib/puppet-herald/public/node/node.html +30 -0
- data/lib/puppet-herald/public/node/node.js +24 -0
- data/lib/puppet-herald/public/nodes/nodes.html +29 -0
- data/lib/puppet-herald/public/nodes/nodes.js +24 -0
- data/lib/puppet-herald/public/report/report.html +24 -0
- data/lib/puppet-herald/public/report/report.js +24 -0
- data/lib/puppet-herald/stubs/puppet.rb +29 -0
- data/lib/puppet-herald/version.rb +20 -0
- data/lib/puppet-herald/views/app.erb +42 -0
- data/lib/puppet-herald/views/err500.erb +31 -0
- data/puppet-herald.gemspec +62 -0
- data/spec/model_helper.rb +2 -0
- data/spec/spec_helper.rb +37 -0
- data/spec/support/active_record.rb +17 -0
- data/spec/unit/fixtures/changed-notify.yaml +278 -0
- data/spec/unit/models/report_spec.rb +38 -0
- metadata +331 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YWNhZTUzMzk1M2ExNzcwNGFiZDVkNTNmNDBkZGYxNmQxNzUyYjg2MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZjBjNjQyMjYzMjc2ZGU0Y2Y4MTA3NWQyMTI1NzIxNGIxMDMwNGQzOA==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZjVhZjY1ZGYwOGE1ODc1YjcxYzNjMDhjYzFlNTIwY2E1M2VkYjgzNWZkYWQ0
|
10
|
+
NTY4N2M2ZmUxNmVlZDMzN2U0MTZjMDg2MDMzZWI4MjNmY2FhYzNmOTZhMTJl
|
11
|
+
YjZmMTA4MjVlZDk1OTFmNzM2YzM0Yjk0ZWZhMzEyOWIyZjAyMzU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
NzhhZGI2ZDhmYzFiY2I4MzYzMmY3YzMwMDM1ZTRlM2YwYzU4NWEzNDFhNWE3
|
14
|
+
ZDEzOWU1YmFiNjZhNjE3NDQyNzY0ZmIwYTY0OGExNTc4OTUzZWNlZmE1ZTI0
|
15
|
+
YzFlNDI4NDk4YjExODViYjUzYjZkMDJjZjg0YWMxMTUwODM1YWM=
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore bundle .vendor dir
|
11
|
+
/.vendor
|
12
|
+
/coverage
|
13
|
+
|
14
|
+
/Gemfile.lock
|
15
|
+
|
16
|
+
# Ignore the default SQLite database.
|
17
|
+
/db/*.sqlite3
|
18
|
+
/db/*.sqlite3-journal
|
19
|
+
|
20
|
+
# Ignore all logfiles and tempfiles.
|
21
|
+
/log/*.log
|
22
|
+
/tmp
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
puppet-herald gem
|
2
|
+
========
|
3
|
+
|
4
|
+
Overview
|
5
|
+
--------
|
6
|
+
|
7
|
+
Herald is a puppet report processor. He provides a gateway for consuming puppet reports, a REST API and a simple Web app to display reports.
|
8
|
+
|
9
|
+
Puppet module
|
10
|
+
-----
|
11
|
+
|
12
|
+
There is/will be a puppet module that handle installation and configuration of Herald and prerequisites. Check that out: https://github.com/wavesoftware/puppet-herald
|
13
|
+
|
14
|
+
Prerequisites
|
15
|
+
-----
|
16
|
+
|
17
|
+
* `libpq-dev`
|
18
|
+
|
19
|
+
On Ubuntu/Debian system install them with:
|
20
|
+
|
21
|
+
```shell
|
22
|
+
sudo apt-get install libpq-dev
|
23
|
+
```
|
24
|
+
|
25
|
+
Installation
|
26
|
+
-----
|
27
|
+
|
28
|
+
Install Herald and all dependencies from http://rubygems.org:
|
29
|
+
```shell
|
30
|
+
sudo gem install puppet-herald
|
31
|
+
```
|
32
|
+
|
33
|
+
Configuration
|
34
|
+
-----
|
35
|
+
|
36
|
+
If you like to use PostgreSQL database to hold reports, you will need to configure it. By default, Herald will use a sqlite file that he tries to create in your home directory. Check out `puppet-herald --help` for description.
|
37
|
+
|
38
|
+
###Create a database
|
39
|
+
|
40
|
+
Just create a database for Herald (this is just a sample):
|
41
|
+
```sql
|
42
|
+
CREATE ROLE pherald LOGIN PASSWORD '<YOUR PASSWORD>' NOSUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;
|
43
|
+
CREATE DATABASE "pherald" WITH OWNER = pherald
|
44
|
+
ENCODING = 'UTF8'
|
45
|
+
TABLESPACE = pg_default;
|
46
|
+
```
|
47
|
+
|
48
|
+
Usage
|
49
|
+
-----
|
50
|
+
|
51
|
+
```shell
|
52
|
+
$ puppet-herald --help
|
53
|
+
```
|
54
|
+
|
55
|
+
Example of running a server with using sqlite and binding to other host and port:
|
56
|
+
|
57
|
+
```shell
|
58
|
+
puppet-herald --dbconn sqlite:///var/lib/puppet/reports/pherald.db --bind master.cluster.vm --port 8081
|
59
|
+
```
|
60
|
+
|
61
|
+
###Contributing
|
62
|
+
|
63
|
+
Contributions are welcome!
|
64
|
+
|
65
|
+
To contribute, follow the standard [git flow](http://danielkummer.github.io/git-flow-cheatsheet/) of:
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
1. Create your feature branch (`git checkout -b feature/my-new-feature`)
|
69
|
+
1. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
1. Push to the branch (`git push origin feature/my-new-feature`)
|
71
|
+
1. Create new Pull Request
|
72
|
+
|
73
|
+
Even if you can't contribute code, if you have an idea for an improvement please open an [issue](https://github.com/wavesoftware/gem-puppet-herald/issues).
|
data/Rakefile
ADDED
data/bin/puppet-herald
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
$0 = 'puppet-herald'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'puppet-herald/cli'
|
7
|
+
rescue LoadError
|
8
|
+
require 'rubygems'
|
9
|
+
require 'puppet-herald/cli'
|
10
|
+
end
|
11
|
+
|
12
|
+
# Process command line options and run Puppet Herald
|
13
|
+
PuppetHerald::CLI.parse_options
|
data/config.ru
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateReports < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :reports do |t|
|
4
|
+
t.string :status
|
5
|
+
t.string :environment
|
6
|
+
t.string :transaction_uuid
|
7
|
+
t.string :configuration_version
|
8
|
+
t.string :puppet_version
|
9
|
+
t.string :kind
|
10
|
+
t.string :host
|
11
|
+
t.datetime :time
|
12
|
+
|
13
|
+
t.references :node
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/db/schema.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended that you check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(version: 20141211171326) do
|
15
|
+
|
16
|
+
# These are extensions that must be enabled in order to support this database
|
17
|
+
enable_extension "plpgsql"
|
18
|
+
|
19
|
+
create_table "log_entries", force: true do |t|
|
20
|
+
t.datetime "time"
|
21
|
+
t.string "level"
|
22
|
+
t.string "source"
|
23
|
+
t.integer "line"
|
24
|
+
t.text "message"
|
25
|
+
t.integer "report_id"
|
26
|
+
end
|
27
|
+
|
28
|
+
create_table "nodes", force: true do |t|
|
29
|
+
t.string "name"
|
30
|
+
t.string "status"
|
31
|
+
t.integer "no_of_reports"
|
32
|
+
t.datetime "last_run"
|
33
|
+
end
|
34
|
+
|
35
|
+
create_table "reports", force: true do |t|
|
36
|
+
t.string "status"
|
37
|
+
t.string "environment"
|
38
|
+
t.string "transaction_uuid"
|
39
|
+
t.string "configuration_version"
|
40
|
+
t.string "puppet_version"
|
41
|
+
t.string "kind"
|
42
|
+
t.string "host"
|
43
|
+
t.datetime "time"
|
44
|
+
t.integer "node_id"
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/db/seeds.rb
ADDED
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
begin
|
2
|
+
require 'pry'
|
3
|
+
rescue LoadError
|
4
|
+
# Do nothing here
|
5
|
+
end
|
6
|
+
|
7
|
+
module PuppetHerald
|
8
|
+
|
9
|
+
@@root = File.dirname(File.dirname(File.realpath(__FILE__)))
|
10
|
+
|
11
|
+
def self.relative_dir dir
|
12
|
+
File.join @@root, dir
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.port
|
16
|
+
@@port
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.environment
|
20
|
+
env = :production
|
21
|
+
unless ENV['PUPPET_HERALD_ENV'].nil?
|
22
|
+
env = ENV['PUPPET_HERALD_ENV'].to_sym
|
23
|
+
end
|
24
|
+
return env
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.is_in_dev?
|
28
|
+
return [:development, :dev, :test, :ci].include? environment
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.is_in_prod?
|
32
|
+
return !is_in_dev?
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'puppet-herald/database'
|
37
|
+
require 'puppet-herald/app'
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require "sinatra/namespace"
|
3
|
+
require 'sinatra/activerecord'
|
4
|
+
require 'puppet-herald'
|
5
|
+
require 'puppet-herald/javascript'
|
6
|
+
require 'puppet-herald/models/node'
|
7
|
+
require 'puppet-herald/models/report'
|
8
|
+
|
9
|
+
module PuppetHerald
|
10
|
+
class App < Sinatra::Base
|
11
|
+
register Sinatra::Namespace
|
12
|
+
register Sinatra::ActiveRecordExtension
|
13
|
+
configure [:production, :development] do
|
14
|
+
enable :logging
|
15
|
+
PuppetHerald::Database.setup self
|
16
|
+
end
|
17
|
+
if PuppetHerald::is_in_dev?
|
18
|
+
set :environment, :development
|
19
|
+
else
|
20
|
+
set :environment, :production
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.bug ex
|
24
|
+
file = Tempfile.new(['puppet-herald-bug', '.log'])
|
25
|
+
filepath = file.path
|
26
|
+
file.close
|
27
|
+
file.unlink
|
28
|
+
message = "v#{PuppetHerald::VERSION}-#{ex.class.to_s}: #{ex.message}"
|
29
|
+
contents = message + "\n\n" + ex.backtrace.join("\n") + "\n"
|
30
|
+
File.write(filepath, contents)
|
31
|
+
bugo = {
|
32
|
+
:message => message,
|
33
|
+
:homepage => PuppetHerald::HOMEPAGE,
|
34
|
+
:bugfile => filepath,
|
35
|
+
:help => "Please report this bug to #{PuppetHerald::HOMEPAGE} by passing contents of bug file: #{filepath}"
|
36
|
+
}
|
37
|
+
return bugo
|
38
|
+
end
|
39
|
+
|
40
|
+
error do
|
41
|
+
@bug = PuppetHerald::App.bug(env['sinatra.error'])
|
42
|
+
erb :err500
|
43
|
+
end
|
44
|
+
|
45
|
+
get %r{/app\.min\.(js\.map|js)} do |ext|
|
46
|
+
content_type 'application/javascript'
|
47
|
+
ugly = PuppetHerald::Javascript::uglify '/app.min.js.map'
|
48
|
+
ugly[ext]
|
49
|
+
end
|
50
|
+
|
51
|
+
get '/' do
|
52
|
+
redirect "/app.html", 301
|
53
|
+
end
|
54
|
+
|
55
|
+
get '/index.html' do
|
56
|
+
redirect "/app.html", 301
|
57
|
+
end
|
58
|
+
|
59
|
+
get '/app.html' do
|
60
|
+
if PuppetHerald::is_in_prod?
|
61
|
+
@minified = '.min'
|
62
|
+
@files = ['/app.min.js']
|
63
|
+
else
|
64
|
+
@minified = ''
|
65
|
+
@files = PuppetHerald::Javascript::files
|
66
|
+
end
|
67
|
+
erb :app
|
68
|
+
end
|
69
|
+
|
70
|
+
get '/version.json' do
|
71
|
+
content_type 'application/json'
|
72
|
+
ver = {}
|
73
|
+
[:VERSION, :LICENSE, :NAME, :PACKAGE, :SUMMARY, :DESCRIPTION, :HOMEPAGE].each do |const|
|
74
|
+
ver[const.downcase] = PuppetHerald::const_get const
|
75
|
+
end
|
76
|
+
ver.to_json
|
77
|
+
end
|
78
|
+
|
79
|
+
namespace '/api' do
|
80
|
+
namespace '/v1' do
|
81
|
+
|
82
|
+
put '/provide-log' do
|
83
|
+
content_type 'application/json'
|
84
|
+
yaml = request.body.read
|
85
|
+
report = Report.create_from_yaml yaml
|
86
|
+
|
87
|
+
{:status => :ok}.to_json
|
88
|
+
end
|
89
|
+
|
90
|
+
get '/nodes' do
|
91
|
+
content_type 'application/json'
|
92
|
+
nodes = Node.all
|
93
|
+
nodes.to_json
|
94
|
+
end
|
95
|
+
|
96
|
+
get '/node/:id' do
|
97
|
+
content_type 'application/json'
|
98
|
+
id = params[:id]
|
99
|
+
Node.get_with_reports(id).
|
100
|
+
to_json(:include => :reports)
|
101
|
+
end
|
102
|
+
|
103
|
+
get '/report/:id' do
|
104
|
+
content_type 'application/json'
|
105
|
+
id = params[:id]
|
106
|
+
Report.get_with_log_entries(id).
|
107
|
+
to_json(:include => :log_entries)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'micro-optparse'
|
2
|
+
require 'puppet-herald'
|
3
|
+
require 'puppet-herald/version'
|
4
|
+
require 'puppet-herald/database'
|
5
|
+
|
6
|
+
module PuppetHerald
|
7
|
+
class CLI
|
8
|
+
|
9
|
+
def self.parse_options
|
10
|
+
usage = ""
|
11
|
+
banner = <<-eos
|
12
|
+
#{PuppetHerald::NAME} v#{PuppetHerald::VERSION} - #{PuppetHerald::SUMMARY}
|
13
|
+
|
14
|
+
#{PuppetHerald::DESCRIPTION}
|
15
|
+
|
16
|
+
Usage: #{$0} [options]
|
17
|
+
|
18
|
+
For --dbconn option you can use both PostgreSQL and SQLite3 (postgresql://host/db, sqlite://file/path).
|
19
|
+
CAUTION! For security reasons, don't pass password in connection string, use --passfile option!
|
20
|
+
|
21
|
+
eos
|
22
|
+
home = File.expand_path('~')
|
23
|
+
defaultdb = "sqlite://#{home}/pherald.db"
|
24
|
+
defaultdbpass = "#{home}/.pherald.pass"
|
25
|
+
parser = Parser.new do |p|
|
26
|
+
p.banner = banner
|
27
|
+
p.version = PuppetHerald::VERSION
|
28
|
+
p.option :bind, "Hostname to bind to", :default => 'localhost'
|
29
|
+
p.option :port, "Port to use", :default => 11303, :value_satisfies => lambda {|x| x >= 100 && x <= 65000}
|
30
|
+
p.option :dbconn, "Connection string to database, see info above", :default => defaultdb
|
31
|
+
p.option :passfile, "If using postgresql, this file will be read for password to database", :default => defaultdbpass
|
32
|
+
end
|
33
|
+
options = parser.process!
|
34
|
+
|
35
|
+
puts "Starting #{PuppetHerald::NAME} v#{PuppetHerald::VERSION}..."
|
36
|
+
PuppetHerald::Database.dbconn = options[:dbconn]
|
37
|
+
PuppetHerald::Database.passfile = options[:passfile]
|
38
|
+
begin
|
39
|
+
PuppetHerald::Database.validate! :echo => true
|
40
|
+
rescue Exception => ex
|
41
|
+
STDERR.puts "FATAL ERROR - Database configuration is invalid!\n\n#{ex.message}"
|
42
|
+
exit 2
|
43
|
+
end
|
44
|
+
begin
|
45
|
+
PuppetHerald::App.run! options
|
46
|
+
rescue Exception => ex
|
47
|
+
bug = PuppetHerald::App.bug(ex)
|
48
|
+
STDERR.puts "FATAL ERROR - Unexpected error occured, mayby a bug?\n\n#{bug[:message]}\n\n#{bug[:help]}"
|
49
|
+
exit 1
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|