smart_proxy_salt 3.1.0 → 3.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3ac4ad731748d62d1ec922520aa60ce1a7db4b001b2aeaabfe9c2e0709e3f9e
4
- data.tar.gz: b345c0ae059918e924a6ec771664a38e687d3b8a288559cd48274e271f69c551
3
+ metadata.gz: 6e76b784ec95950584ee9dc9601fd4b16502d24e948570f5c2e5cca2fc37cf48
4
+ data.tar.gz: be2a3a41b1bda928582f8f3f97b47e2fe544272efdba65ae11ca06d937b44551
5
5
  SHA512:
6
- metadata.gz: 20b39c0f2ef2a6ea13cf94d996141ee1e28ff542fd8def32275560085b8f6c31e57d0d834e6179744c98a4eccfcb3efa4dc8ce74e178b0751103933253d1c465
7
- data.tar.gz: d1dd34e0c168829fe049c8db0bb751782b3548a39566c530d148a00485fcf0c96c2fd52b96a7bb71b7a0ac3b9e5ea74629ab39e7b4ef166b1f0ba1163aa6fbd7
6
+ metadata.gz: 3ae10fb0bc8ca6451ef5c519fa9a229d34cb72e4fa06a4c1446e286bfb3f7abebb3019e0d8ad0911efee1304104d369da7214698716f285bfc011acc6c5b2adc
7
+ data.tar.gz: b1414a95f7fa718cf1b8720b5e592ab23177ff60c7180df87e9d928b6629925343276bb057e26ac56da4e77bf34826f7079f7daebb3bd6af910243d7abd0a80c
@@ -3,6 +3,6 @@
3
3
  module Proxy
4
4
  # Salt module
5
5
  module Salt
6
- VERSION = '3.1.0'
6
+ VERSION = '3.1.1'
7
7
  end
8
8
  end
@@ -0,0 +1,31 @@
1
+ # Foreman Salt Report Upload
2
+
3
+ Currently, there are two possibilites to upload the salt report to Foreman:
4
+ 1. Use /usr/sbin/upload-salt-reports which is called by a cron job every 10 minutes by default
5
+ 2. Upload the report immediately by using a Salt Reactor.
6
+
7
+ This README, handles the second option and how to configure it
8
+
9
+ ## Setup
10
+ Add the content of 'master.snippet' to '/etc/salt/master' which configures a reactor.
11
+ In case there is already a reactor configured, you need to adapt it using the options mentioned in 'master.snippet'.
12
+
13
+ In case '/srv/salt' is configured as 'file_roots' in your '/etc/salt/master' config, setup the necessary salt state file and Salt runner functions:
14
+
15
+ ```
16
+ /srv/salt/foreman_report_upload.sls
17
+ /srv/salt/_runners/foreman_report_upload.py
18
+ ```
19
+
20
+ After changing the salt master run:
21
+
22
+ ```
23
+ systemctl restart salt-master
24
+ ```
25
+
26
+ After adding the foreman_report_upload.sls and foreman_report_upload.py, run the following:
27
+
28
+ ```
29
+ salt-run saltutil.sync_all
30
+ ```
31
+
@@ -0,0 +1,3 @@
1
+ reactor:
2
+ - 'salt/job/*/ret/*':
3
+ - /srv/salt/foreman_report_upload.sls
@@ -0,0 +1,92 @@
1
+ # -*- coding: utf-8 -*-
2
+ '''
3
+ Uploads reports from the Salt job cache to Foreman
4
+ '''
5
+ from __future__ import absolute_import, print_function, unicode_literals
6
+
7
+ FOREMAN_CONFIG = '/etc/salt/foreman.yaml'
8
+
9
+ try:
10
+ from http.client import HTTPConnection, HTTPSConnection
11
+ except ImportError:
12
+ from httplib import HTTPSConnection, HTTPSConnection
13
+
14
+ import ssl
15
+ import json
16
+ import yaml
17
+ import os
18
+ import sys
19
+ import base64
20
+
21
+ # Import python libs
22
+ import logging
23
+
24
+ log = logging.getLogger(__name__)
25
+
26
+
27
+ def salt_config():
28
+ with open(FOREMAN_CONFIG, 'r') as f:
29
+ config = yaml.load(f.read())
30
+ return config
31
+
32
+
33
+ def upload(report):
34
+ config = salt_config()
35
+ headers = {'Accept': 'application/json',
36
+ 'Content-Type': 'application/json'}
37
+
38
+ if config[':proto'] == 'https':
39
+ ctx = ssl.create_default_context()
40
+ ctx.load_cert_chain(certfile=config[':ssl_cert'], keyfile=config[':ssl_key'])
41
+ if config[':ssl_ca']:
42
+ ctx.load_verify_locations(cafile=config[':ssl_ca'])
43
+ connection = HTTPSConnection(config[':host'],
44
+ port=config[':port'], context=ctx)
45
+ else:
46
+ connection = HTTPConnection(config[':host'],
47
+ port=config[':port'])
48
+ if ':username' in config and ':password' in config:
49
+ token = base64.b64encode('{}:{}'.format(config[':username'],
50
+ config[':password']))
51
+ headers['Authorization'] = 'Basic {}'.format(token)
52
+
53
+ connection.request('POST', '/salt/api/v2/jobs/upload',
54
+ json.dumps(report), headers)
55
+ response = connection.getresponse()
56
+
57
+ if response.status == 200:
58
+ info_msg = 'Success {0}: {1}'.format(report['job']['job_id'], response.read())
59
+ log.info(info_msg)
60
+ else:
61
+ log.error("Unable to upload job - aborting report upload")
62
+ log.error(response.read())
63
+
64
+
65
+ def create_report(json_str):
66
+ msg = json.loads(json_str)
67
+
68
+ return {'job':
69
+ {
70
+ 'result': {
71
+ msg['id']: msg['return'],
72
+ },
73
+ 'function': 'state.highstate',
74
+ 'job_id': msg['jid']
75
+ }
76
+ }
77
+
78
+
79
+ def now(highstate):
80
+ '''
81
+ Upload a highstate to Foreman
82
+ highstate :
83
+ dictionary containing a highstate (generated by a Salt reactor)
84
+ '''
85
+ log.debug('Upload highstate to Foreman')
86
+
87
+ try:
88
+ report = create_report(highstate)
89
+ upload(report)
90
+ except Exception as exc:
91
+ log.error('Exception encountered: %s', exc)
92
+
@@ -0,0 +1,6 @@
1
+ {% if 'cmd' in data and data['cmd'] == '_return' and 'fun' in data and data['fun'] == 'state.highstate' %}
2
+ foreman_report_upload:
3
+ runner.foreman_report_upload.now:
4
+ - args:
5
+ - highstate: '{{data|json}}'
6
+ {% endif %}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_salt
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Moll
@@ -9,64 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-10-31 00:00:00.000000000 Z
12
+ date: 2019-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: json
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - ">="
19
- - !ruby/object:Gem::Version
20
- version: '0'
21
- type: :runtime
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: rack
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '1.1'
35
- type: :runtime
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '1.1'
42
- - !ruby/object:Gem::Dependency
43
- name: sinatra
44
- requirement: !ruby/object:Gem::Requirement
45
- requirements:
46
- - - ">="
47
- - !ruby/object:Gem::Version
48
- version: '0'
49
- type: :runtime
50
- prerelease: false
51
- version_requirements: !ruby/object:Gem::Requirement
52
- requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- version: '0'
56
- - !ruby/object:Gem::Dependency
57
- name: logging
58
- requirement: !ruby/object:Gem::Requirement
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- version: '0'
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
14
  - !ruby/object:Gem::Dependency
71
15
  name: test-unit
72
16
  requirement: !ruby/object:Gem::Requirement
@@ -178,6 +122,10 @@ files:
178
122
  - lib/smart_proxy_salt_core/salt_runner.rb
179
123
  - lib/smart_proxy_salt_core/salt_task_launcher.rb
180
124
  - lib/smart_proxy_salt_core/version.rb
125
+ - salt/report_upload/README.md
126
+ - salt/report_upload/master.snippet
127
+ - salt/report_upload/srv/salt/_runners/foreman_report_upload.py
128
+ - salt/report_upload/srv/salt/foreman_report_upload.sls
181
129
  - sbin/upload-salt-reports
182
130
  - settings.d/salt.saltfile.example
183
131
  - settings.d/salt.yml.example