ncio 0.2.2 → 1.0.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 +4 -4
- data/README.md +27 -0
- data/lib/ncio/app.rb +21 -5
- data/lib/ncio/support.rb +58 -4
- data/lib/ncio/support/option_parsing.rb +5 -1
- data/lib/ncio/version.rb +1 -1
- data/ncio.gemspec +3 -2
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a605a5b8f5fe218bf929a616865beefdee6e498
|
4
|
+
data.tar.gz: 64f6c604eead3c2f171b4e257aefafd6557284fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bda029e4149c95969a8ab4692a955f2d2fd16fbb53d649bbcc95371dc16acf9d7adbf9545308c466aa6a7d1f2566f9f0b1fb8b72cb65f7532cdd13fa28451ba7
|
7
|
+
data.tar.gz: 65f027f5b97bb2b57e5869340ce61b23d40030495b0e79b7d5094bc9682e819eac9572c0fd01c7c71a8088f95296a1858e277e20c9d37eb9051c74d217ca4743
|
data/README.md
CHANGED
@@ -84,6 +84,33 @@ white-list of certificates is located at
|
|
84
84
|
backup > /var/tmp/backup.json
|
85
85
|
I, [2016-06-28T19:28:48.236257 #3148] INFO -- : Backup completed successfully!
|
86
86
|
|
87
|
+
## Logging
|
88
|
+
|
89
|
+
The status of backup and restore operations are logged to the syslog by default.
|
90
|
+
The `daemon` facility is used to ensure messages are written to files on a wide
|
91
|
+
variety of systems that log daemon messages by default. A general exception
|
92
|
+
handler will log a backtrace in JSON format to help log processors and
|
93
|
+
notification systems like Splunk and Logstash.
|
94
|
+
|
95
|
+
Here's an example of a failed restore triggering the catch all handler:
|
96
|
+
|
97
|
+
Jun 29 12:12:21 Jeff-McCune ncio[51474]: ERROR Restoring backup: {
|
98
|
+
"error": "RuntimeError",
|
99
|
+
"message": "Some random error",
|
100
|
+
"backtrace": [
|
101
|
+
"/Users/jeff/projects/puppet/ncio/lib/ncio/app.rb:94:in `restore_groups'",
|
102
|
+
"/Users/jeff/projects/puppet/ncio/lib/ncio/app.rb:59:in `run'",
|
103
|
+
"/Users/jeff/projects/puppet/ncio/exe/ncio:5:in `<top (required)>'"
|
104
|
+
]
|
105
|
+
}
|
106
|
+
|
107
|
+
Log to the console using the `--no-syslog` command line option.
|
108
|
+
|
109
|
+
ncio --no-syslog restore --file backup.json
|
110
|
+
|
111
|
+
The tool can only log to either syslog or the console at this time. Multiple
|
112
|
+
log destinations are not currently supported.
|
113
|
+
|
87
114
|
## Contributing
|
88
115
|
|
89
116
|
Bug reports and pull requests are welcome on GitHub at
|
data/lib/ncio/app.rb
CHANGED
@@ -69,26 +69,42 @@ class App
|
|
69
69
|
# Backup all groups in a manner suitable for the node classification hierarchy
|
70
70
|
# import. See:
|
71
71
|
# [NC Groups](https://docs.puppet.com/pe/2016.1/nc_groups.html#get-v1groups)
|
72
|
+
# rubocop:disable Metrics/AbcSize
|
72
73
|
def backup_groups
|
73
|
-
|
74
|
-
|
75
|
-
debug "
|
74
|
+
warn "Starting Node Classification Backup using GET #{uri}/groups"
|
75
|
+
groups = api.groups
|
76
|
+
debug "Number of groups retrieved: #{groups.size}"
|
77
|
+
str = JSON.pretty_generate(groups)
|
78
|
+
debug "Write #{str.bytesize} bytes of JSON to #{file} ..."
|
76
79
|
write_output(str, map_file_option(file))
|
77
|
-
|
80
|
+
warn 'Finished Node Classification Backup '\
|
81
|
+
"STATUS=OK BYTESIZE=#{str.bytesize} GROUPCOUNT=#{groups.size} "\
|
82
|
+
"OUTPUT=#{file}"
|
83
|
+
rescue Exception => e
|
84
|
+
fatal "ERROR Obtaining backup: #{format_error e}"
|
85
|
+
raise e
|
78
86
|
end
|
87
|
+
# rubocop:enable Metrics/AbcSize
|
79
88
|
|
80
89
|
##
|
81
90
|
# Restore all groups in a manner suitable for the node classification
|
82
91
|
# hierarchy import. See: [NC Import
|
83
92
|
# Hierarchy](https://docs.puppet.com/pe/2016.1/nc_import-hierarchy.html)
|
84
93
|
def restore_groups
|
94
|
+
raise "Some random error"
|
95
|
+
warn 'Starting Node Classification Restore using '\
|
96
|
+
"POST #{uri}/import-hierarchy"
|
85
97
|
api = self.api
|
86
98
|
debug "Open #{file} for streaming ..."
|
87
99
|
input_stream(map_file_option(file)) do |stream|
|
88
100
|
debug "POST #{uri}/import-hierarchy"
|
89
101
|
api.import_hierarchy(stream)
|
90
102
|
end
|
91
|
-
|
103
|
+
warn 'Finished Node Classification Restore '\
|
104
|
+
"STATUS=OK INPUT=#{file}"
|
105
|
+
rescue Exception => e
|
106
|
+
fatal "ERROR Restoring backup: #{format_error e}"
|
107
|
+
raise e
|
92
108
|
end
|
93
109
|
|
94
110
|
##
|
data/lib/ncio/support.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'syslog/logger'
|
3
|
+
require 'json'
|
4
|
+
|
1
5
|
module Ncio
|
2
6
|
##
|
3
7
|
# Support module to mix into other classes, particularly the application and
|
@@ -8,10 +12,26 @@ module Ncio
|
|
8
12
|
attr_reader :opts
|
9
13
|
|
10
14
|
def self.reset_logging!(opts)
|
15
|
+
logger = opts[:syslog] ? syslog_logger : stream_logger(opts)
|
16
|
+
@log = logger
|
17
|
+
end
|
18
|
+
|
19
|
+
##
|
20
|
+
# Return a new Syslog::Logger instance configured for syslog output
|
21
|
+
def self.syslog_logger
|
22
|
+
# Use the daemon facility, matching Puppet behavior.
|
23
|
+
Syslog::Logger.new('ncio', Syslog::LOG_DAEMON)
|
24
|
+
end
|
25
|
+
|
26
|
+
##
|
27
|
+
# Return a new Logger instance configured for file output
|
28
|
+
def self.stream_logger(opts)
|
11
29
|
out = map_file_option(opts[:logto])
|
12
30
|
logger = Logger.new(out)
|
13
|
-
logger.level =
|
14
|
-
|
31
|
+
logger.level = Logger::WARN
|
32
|
+
logger.level = Logger::INFO if opts[:verbose]
|
33
|
+
logger.level = Logger::DEBUG if opts[:debug]
|
34
|
+
logger
|
15
35
|
end
|
16
36
|
|
17
37
|
##
|
@@ -62,13 +82,37 @@ module Ncio
|
|
62
82
|
end
|
63
83
|
|
64
84
|
##
|
65
|
-
#
|
85
|
+
# Logs a message at the fatal (syslog err) log level
|
86
|
+
def fatal(msg)
|
87
|
+
log.fatal msg
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Logs a message at the error (syslog warning) log level.
|
92
|
+
# i.e. May indicate that an error will occur if action is not taken.
|
93
|
+
# e.g. A non-root file system has only 2GB remaining.
|
94
|
+
def error(msg)
|
95
|
+
log.error msg
|
96
|
+
end
|
97
|
+
|
98
|
+
##
|
99
|
+
# Logs a message at the warn (syslog notice) log level.
|
100
|
+
# e.g. Events that are unusual, but not error conditions.
|
101
|
+
def warn(msg)
|
102
|
+
log.warn msg
|
103
|
+
end
|
104
|
+
|
105
|
+
##
|
106
|
+
# Logs a message at the info (syslog info) log level
|
107
|
+
# i.e. Normal operational messages that require no action.
|
108
|
+
# e.g. An application has started, paused or ended successfully.
|
66
109
|
def info(msg)
|
67
110
|
log.info msg
|
68
111
|
end
|
69
112
|
|
70
113
|
##
|
71
|
-
#
|
114
|
+
# Logs a message at the debug (syslog debug) log level
|
115
|
+
# i.e. Information useful to developers for debugging the application.
|
72
116
|
def debug(msg)
|
73
117
|
log.debug msg
|
74
118
|
end
|
@@ -105,6 +149,16 @@ module Ncio
|
|
105
149
|
end
|
106
150
|
end
|
107
151
|
|
152
|
+
##
|
153
|
+
# Format an exception for logging. JSON is used to aid centralized log
|
154
|
+
# systems such as Logstash and Splunk
|
155
|
+
#
|
156
|
+
# @param [Exception] e the exception to format
|
157
|
+
def format_error(e)
|
158
|
+
data = { error: "#{e.class}", message: e.message, backtrace: e.backtrace }
|
159
|
+
JSON.pretty_generate(data)
|
160
|
+
end
|
161
|
+
|
108
162
|
##
|
109
163
|
# Return the application version as a Semantic Version encoded string
|
110
164
|
#
|
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'ncio/version'
|
2
|
+
require 'socket'
|
3
|
+
|
2
4
|
# rubocop:disable Metrics/ModuleLength
|
3
5
|
module Ncio
|
4
6
|
module Support
|
@@ -70,7 +72,9 @@ module Ncio
|
|
70
72
|
log_msg = 'Log file to write to or keywords '\
|
71
73
|
'STDOUT, STDERR {NCIO_LOGTO}'
|
72
74
|
opt :logto, log_msg, default: env['NCIO_LOGTO'] || 'STDERR'
|
73
|
-
opt :
|
75
|
+
opt :syslog, 'Log to syslog', default: true, conflicts: :logto
|
76
|
+
opt :verbose, 'Set log level to INFO'
|
77
|
+
opt :debug, 'Set log level to DEBUG'
|
74
78
|
end
|
75
79
|
end
|
76
80
|
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
data/lib/ncio/version.rb
CHANGED
data/ncio.gemspec
CHANGED
@@ -9,8 +9,9 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Jeff McCune"]
|
10
10
|
spec.email = ["jeff@openinfrastructure.co"]
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
12
|
+
spec.summary = 'Puppet Node Classifier backup / restore / transform'
|
13
|
+
spec.description = 'ncio is a small command line utility to backup, '\
|
14
|
+
'restore, and transform Puppet Enterprise Node Classification groups.'
|
14
15
|
spec.homepage = "https://www.openinfrastructure.co"
|
15
16
|
spec.license = "MIT"
|
16
17
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ncio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff McCune
|
@@ -122,7 +122,8 @@ dependencies:
|
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: 0.11.2
|
125
|
-
description:
|
125
|
+
description: ncio is a small command line utility to backup, restore, and transform
|
126
|
+
Puppet Enterprise Node Classification groups.
|
126
127
|
email:
|
127
128
|
- jeff@openinfrastructure.co
|
128
129
|
executables:
|
@@ -176,6 +177,6 @@ rubyforge_project:
|
|
176
177
|
rubygems_version: 2.4.5.1
|
177
178
|
signing_key:
|
178
179
|
specification_version: 4
|
179
|
-
summary: Puppet Node Classifier
|
180
|
+
summary: Puppet Node Classifier backup / restore / transform
|
180
181
|
test_files: []
|
181
182
|
has_rdoc: yard
|