Skip to content

Commit 4db1c76

Browse files
committed
add --rules option
1 parent d6029d2 commit 4db1c76

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

etc/redhat-access-insights.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Name: redhat-access-insights
55
Summary: Uploads Insights information to Red Hat on a periodic basis
66
Version: 1.0.8
7-
Release: 0%{?dist}
7+
Release: 1%{?dist}
88
Source0: https://github.com/redhataccess/insights-client/archive/redhat-access-insights-%{version}.tar.gz
99
Epoch: 0
1010
License: GPLv2+

redhat_access_insights/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def collect_data_and_upload(config, options, rc=0):
176176
except LookupError:
177177
branch_info = handle_branch_info_error(
178178
"Could not determine branch information", options)
179-
pc = InsightsConfig(config, pconn)
179+
pc = InsightsConfig(config, pconn, custom_rules=options.rules)
180180
archive = InsightsArchive(compressor=options.compressor)
181181
dc = DataCollector(archive)
182182

@@ -186,7 +186,7 @@ def collect_data_and_upload(config, options, rc=0):
186186
stdin_config = json.load(sys.stdin) if options.from_stdin else {}
187187

188188
start = time.clock()
189-
collection_rules, rm_conf = pc.get_conf(options.update, stdin_config)
189+
collection_rules, rm_conf = pc.get_conf(options.update, stdin_config=stdin_config)
190190
elapsed = (time.clock() - start)
191191
logger.debug("Collection Rules Elapsed Time: %s", elapsed)
192192

@@ -359,6 +359,10 @@ def set_up_options(parser):
359359
help="Pass a custom config file",
360360
dest="conf",
361361
default=constants.default_conf_file)
362+
parser.add_option('-r', '--rules',
363+
help="Pass a custom rules json file",
364+
dest="rules",
365+
default=None)
362366
parser.add_option('--to-stdout',
363367
help='print archive to stdout; '
364368
'sets --silent and --no-upload',

redhat_access_insights/collection_rules.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ class InsightsConfig(object):
2020
Insights configuration
2121
"""
2222

23-
def __init__(self, config, conn):
23+
def __init__(self, config, conn, custom_rules=None):
2424
"""
2525
Load config from parent
2626
"""
2727
self.fallback_file = constants.collection_fallback_file
2828
self.remove_file = constants.collection_remove_file
2929
self.collection_rules_file = constants.collection_rules_file
30+
self.custom_rules = custom_rules
3031
protocol = "https://"
3132
insecure_connection = config.getboolean(APP_NAME, "insecure_connection")
3233
if insecure_connection:
@@ -181,6 +182,14 @@ def get_conf(self, update, stdin_config=None):
181182
else:
182183
logger.error("Unable to validate GPG signature in from_stdin mode.")
183184
raise Exception("from_stdin mode failed to validate GPG sig")
185+
elif self.custom_rules:
186+
logger.debug('Using custom rules file...')
187+
if os.path.isfile(self.custom_rules):
188+
with open(self.custom_rules) as rule_json:
189+
return json.load(rule_json), rm_conf
190+
else:
191+
logger.error('File %s does not exist' % self.custom_rules)
192+
sys.exit(1)
184193
elif update:
185194
dyn_conf = self.get_collection_rules()
186195
version = dyn_conf.get('version', None)

0 commit comments

Comments
 (0)