smart_proxy_host_reports 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -3
- data/lib/smart_proxy_host_reports/ansible_processor.rb +13 -1
- data/lib/smart_proxy_host_reports/host_reports.rb +1 -1
- data/lib/smart_proxy_host_reports/processor.rb +3 -4
- data/lib/smart_proxy_host_reports/puppet_processor.rb +16 -1
- data/lib/smart_proxy_host_reports/version.rb +1 -1
- data/settings.d/{host_reports.yml.example → reports.yml.example} +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 420e319032a6847e1c551cb77ba7e973e3ebf2a06382cd20f5ff7ac69bea9845
|
4
|
+
data.tar.gz: 2a4a082c0c60b70362dcf6966aebf4cb10ca2e7133bfb29587319c5f35a74b82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23b7897c6ea66c90183cf31484b93bfb6b342e907ae5a3397c84055488e8c6ea8e41cefa16d0a9d275dee0e99fd075d83ce0bc48bf51a45b36038599e80e29bb
|
7
|
+
data.tar.gz: c61f0a3f6ec03f189ed5a54777324d1dd27b7bf8f57082faa57fedb2ad7c41a62e3ac6240938ef6f8b09e8f36430b2bcebe2649d1f791d5fca45a14ba97a57c1
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
Smart Proxy Host Reports
|
2
2
|
|
3
3
|
Transforms configuration and security management reports into Foreman-friendly
|
4
4
|
JSON and sends them to a Foreman instance. For more information about Foreman
|
@@ -29,7 +29,8 @@ Ansible collection path to the build directory:
|
|
29
29
|
collection_path = /home/lzap/work/foreman-ansible-modules/build
|
30
30
|
callback_whitelist = foreman
|
31
31
|
[callback_foreman]
|
32
|
-
|
32
|
+
report_type = proxy
|
33
|
+
proxy_url = http://localhost:8000/host_reports
|
33
34
|
verify_certs = 0
|
34
35
|
client_cert = /home/lzap/DummyX509/client-one.crt
|
35
36
|
client_key = /home/lzap/DummyX509/client-one.key
|
@@ -48,7 +49,7 @@ For testing, there are several example data. Before importing them into Foreman,
|
|
48
49
|
$ contrib/upload-fixture
|
49
50
|
Usage:
|
50
51
|
contrib/upload-fixture -h Display this help message
|
51
|
-
contrib/upload-fixture -u URL Proxy URL (http://localhost:
|
52
|
+
contrib/upload-fixture -u URL Proxy URL (http://localhost:8000)
|
52
53
|
contrib/upload-fixture -f FILE Fixture to upload
|
53
54
|
contrib/upload-fixture -a Upload all fixtures
|
54
55
|
|
@@ -119,10 +120,46 @@ puppet config set server $HOSTNAME
|
|
119
120
|
|
120
121
|
You can manually trigger a puppet run by using `puppet agent -t`. You may need to look at `/var/log/puppetlabs/puppetserver/puppetserver.log` to see errors.
|
121
122
|
|
123
|
+
## Status mapping
|
124
|
+
|
125
|
+
### Puppet
|
126
|
+
|
127
|
+
* changed -> applied
|
128
|
+
* corrective_change -> applied
|
129
|
+
* failed -> failed
|
130
|
+
* failed_to_restart -> failed
|
131
|
+
* scheduled -> pending
|
132
|
+
* restarted -> other
|
133
|
+
* skipped -> other
|
134
|
+
* out_of_sync
|
135
|
+
* total
|
136
|
+
|
137
|
+
### Ansible
|
138
|
+
|
139
|
+
* applied -> applied
|
140
|
+
* failed -> failed
|
141
|
+
* skipped -> other
|
142
|
+
* pending -> pending
|
143
|
+
|
122
144
|
## Contributing
|
123
145
|
|
124
146
|
Fork and send a Pull Request. Thanks!
|
125
147
|
|
148
|
+
### Unit tests
|
149
|
+
|
150
|
+
To run unit tests:
|
151
|
+
|
152
|
+
bundle exec rake test
|
153
|
+
|
154
|
+
There are few snapshot tests which compare input JSON/YAML with snapshot fixtures. When they fail, you are asked to delete those fixtures, re-run tests, review and push the changes into git:
|
155
|
+
|
156
|
+
```
|
157
|
+
rm test/snapshots/*
|
158
|
+
bundle exec rake test
|
159
|
+
git diff
|
160
|
+
git commit
|
161
|
+
```
|
162
|
+
|
126
163
|
## License
|
127
164
|
|
128
165
|
GNU GPLv3, see LICENSE file for more information.
|
@@ -57,7 +57,7 @@ class AnsibleProcessor < Processor
|
|
57
57
|
version: 1,
|
58
58
|
host: @body["host"],
|
59
59
|
reported_at: @body["reported_at"],
|
60
|
-
|
60
|
+
statuses: process_statuses,
|
61
61
|
proxy: @body["proxy"],
|
62
62
|
body: @body,
|
63
63
|
keywords: @body["keywords"],
|
@@ -132,4 +132,16 @@ class AnsibleProcessor < Processor
|
|
132
132
|
ensure
|
133
133
|
result["friendly_message"] = msg
|
134
134
|
end
|
135
|
+
|
136
|
+
def process_statuses
|
137
|
+
{
|
138
|
+
"applied" => @body["status"]["applied"],
|
139
|
+
"failed" => @body["status"]["failed"],
|
140
|
+
"pending" => @body["status"]["pending"] || 0, # It's only present in check mode
|
141
|
+
"other" => @body["status"]["skipped"],
|
142
|
+
}
|
143
|
+
rescue StandardError => e
|
144
|
+
logger.error "Unable to process statuses", e
|
145
|
+
{ "applied" => 0, "failed" => 0, "pending" => 0, "other" => 0 }
|
146
|
+
end
|
135
147
|
end
|
@@ -32,18 +32,17 @@ class Processor
|
|
32
32
|
@hostname_from_config ||= Proxy::HostReports::Plugin.settings.override_hostname
|
33
33
|
end
|
34
34
|
|
35
|
-
def build_report_root(format:, version:, host:, reported_at:,
|
35
|
+
def build_report_root(format:, version:, host:, reported_at:, statuses:, proxy:, body:, keywords:)
|
36
36
|
{
|
37
37
|
"host_report" => {
|
38
38
|
"format" => format,
|
39
39
|
"version" => version,
|
40
40
|
"host" => host,
|
41
41
|
"reported_at" => reported_at,
|
42
|
-
"status" => status,
|
43
42
|
"proxy" => proxy,
|
44
43
|
"body" => @json_body ? body.to_json : body,
|
45
44
|
"keywords" => keywords,
|
46
|
-
},
|
45
|
+
}.merge(statuses),
|
47
46
|
}
|
48
47
|
# TODO add metric with total time
|
49
48
|
end
|
@@ -86,7 +85,7 @@ class Processor
|
|
86
85
|
ensure
|
87
86
|
t2 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
88
87
|
@telemetry ||= {}
|
89
|
-
@telemetry[metric] = (t2 - t1) * 1000
|
88
|
+
@telemetry[metric.to_s] = (t2 - t1) * 1000
|
90
89
|
end
|
91
90
|
|
92
91
|
def telemetry_as_string
|
@@ -107,7 +107,7 @@ class PuppetProcessor < Processor
|
|
107
107
|
version: 1,
|
108
108
|
host: @body["host"],
|
109
109
|
reported_at: @body["reported_at"],
|
110
|
-
|
110
|
+
statuses: process_statuses,
|
111
111
|
proxy: @body["proxy"],
|
112
112
|
body: @body,
|
113
113
|
keywords: @body["keywords"],
|
@@ -122,4 +122,19 @@ class PuppetProcessor < Processor
|
|
122
122
|
end
|
123
123
|
SpooledHttpClient.instance.spool(report_id, payload)
|
124
124
|
end
|
125
|
+
|
126
|
+
private
|
127
|
+
|
128
|
+
def process_statuses
|
129
|
+
stats = @body["metrics"]["resources"]["values"].collect { |s| [s[0], s[2]] }.to_h
|
130
|
+
{
|
131
|
+
"applied" => stats["changed"] + stats["corrective_change"],
|
132
|
+
"failed" => stats["failed"] + stats["failed_to_restart"],
|
133
|
+
"pending" => stats["scheduled"],
|
134
|
+
"other" => stats["restarted"] + stats["skipped"] + stats["out_of_sync"],
|
135
|
+
}
|
136
|
+
rescue StandardError => e
|
137
|
+
logger.error "Unable to process statuses", e
|
138
|
+
{ "applied" => 0, "failed" => 0, "pending" => 0, "other" => 0 }
|
139
|
+
end
|
125
140
|
end
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_proxy_host_reports
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lukas Zapletal
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-10-
|
11
|
+
date: 2021-10-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -58,7 +58,7 @@ files:
|
|
58
58
|
- lib/smart_proxy_host_reports/puppet_processor.rb
|
59
59
|
- lib/smart_proxy_host_reports/spooled_http_client.rb
|
60
60
|
- lib/smart_proxy_host_reports/version.rb
|
61
|
-
- settings.d/
|
61
|
+
- settings.d/reports.yml.example
|
62
62
|
homepage: http://github.com/theforeman/smart_proxy_host_reports
|
63
63
|
licenses:
|
64
64
|
- GPL-3.0-or-later
|