diff --git a/awx/main/analytics/core.py b/awx/main/analytics/core.py index df13ebd4fa..02a586b7eb 100644 --- a/awx/main/analytics/core.py +++ b/awx/main/analytics/core.py @@ -88,8 +88,8 @@ def gather(dest=None, module=None, collection_type='scheduled'): logger.exception("Invalid License provided, or No License Provided") return "Error: Invalid License provided, or No License Provided" - if not settings.INSIGHTS_TRACKING_STATE: - logger.error("Automation Analytics not enabled") + if collection_type != 'dry-run' and not settings.INSIGHTS_TRACKING_STATE: + logger.error("Automation Analytics not enabled. Use --dry-run to gather locally without sending.") return if module is None: diff --git a/awx/main/management/commands/gather_analytics.py b/awx/main/management/commands/gather_analytics.py index 8f66b6f12a..aa096d6f28 100644 --- a/awx/main/management/commands/gather_analytics.py +++ b/awx/main/management/commands/gather_analytics.py @@ -11,6 +11,8 @@ class Command(BaseCommand): help = 'Gather AWX analytics data' def add_arguments(self, parser): + parser.add_argument('--dry-run', dest='dry-run', action='store_true', + help='Gather analytics without shipping. Works even if analytics are disabled in settings.') parser.add_argument('--ship', dest='ship', action='store_true', help='Enable to ship metrics to the Red Hat Cloud') @@ -23,9 +25,14 @@ class Command(BaseCommand): self.logger.propagate = False def handle(self, *args, **options): - tgz = gather(collection_type='manual') self.init_logging() + opt_ship = options.get('ship') + opt_dry_run = options.get('dry-run') + if opt_ship and opt_dry_run: + self.logger.error('Both --ship and --dry-run cannot be processed at the same time.') + return + tgz = gather(collection_type='manual' if not opt_dry_run else 'dry-run') if tgz: self.logger.debug(tgz) - if options.get('ship'): + if opt_ship: ship(tgz)