1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- from __future__ import unicode_literals
- from django.core.management.base import BaseCommand
- from django.utils import timezone
- from extras.models import ReportResult
- from extras.reports import get_reports
- class Command(BaseCommand):
- help = "Run a report to validate data in NetBox"
- def add_arguments(self, parser):
- parser.add_argument('reports', nargs='+', help="Report(s) to run")
-
- def handle(self, *args, **options):
-
- reports = get_reports()
-
- for module_name, report in reports:
- for report_name, report_cls in report:
- report_name_full = '{}.{}'.format(module_name, report_name)
- if module_name in options['reports'] or report_name_full in options['reports']:
-
- self.stdout.write(
- "[{:%H:%M:%S}] Running {}.{}...".format(timezone.now(), module_name, report_name)
- )
- report = report_cls()
- results = report.run()
-
- status = self.style.ERROR('FAILED') if report.failed else self.style.SUCCESS('SUCCESS')
- for test_name, attrs in results.items():
- self.stdout.write(
- "\t{}: {} success, {} info, {} warning, {} failed".format(
- test_name, attrs['success'], attrs['info'], attrs['warning'], attrs['failed']
- )
- )
- self.stdout.write(
- "[{:%H:%M:%S}] {}.{}: {}".format(timezone.now(), module_name, report_name, status)
- )
-
- self.stdout.write(
- "[{:%H:%M:%S}] Finished".format(timezone.now())
- )
|