def __init__(self, core, datastore): Bcfg2.Server.Plugin.Plugin.__init__(self, core, datastore) Bcfg2.Server.Plugin.ThreadedStatistics.__init__(self, core, datastore) Bcfg2.Server.Plugin.PullSource.__init__(self) self.cpath = "%s/Metadata/clients.xml" % datastore self.core = core logger.debug("Searching for new models to " "add to the statistics database") try: update_database() except UpdaterError: raise Bcfg2.Server.Plugin.PluginInitError except Exception: inst = sys.exc_info()[1] logger.debug(str(inst)) logger.debug(str(type(inst)))
if not statpath: try: statpath = "%s/etc/statistics.xml" % cf.get('server', 'repository') except (ConfigParser.NoSectionError, ConfigParser.NoOptionError): print("Could not read bcfg2.conf; exiting") raise SystemExit(1) try: statsdata = XML(open(statpath).read()) except (IOError, XMLSyntaxError): print("StatReports: Failed to parse %s" % (statpath)) raise SystemExit(1) try: encoding = cf.get('components', 'encoding') except: encoding = 'UTF-8' q = '-O3' in sys.argv # Be sure the database is ready for new schema try: update_database() except UpdaterError: raise SystemExit(1) load_stats(statsdata, encoding, verb, logger, quick=q, location=platform.node())
def __call__(self, args): Bcfg2.Server.Admin.Mode.__call__(self, args) if len(args) == 0 or args[0] == '-h': print(self.__usage__) raise SystemExit(0) # FIXME - dry run if args[0] in self.django_commands: self.django_command_proxy(args[0]) elif args[0] == 'scrub': self.scrub() elif args[0] in ['init', 'update']: try: update_database() except UpdaterError: print "Update failed" raise SystemExit(-1) elif args[0] == 'load_stats': quick = '-O3' in args stats_file = None i = 1 while i < len(args): if args[i] == '-s' or args[i] == '--stats': stats_file = args[i + 1] if stats_file[0] == '-': self.errExit("Invalid statistics file: %s" % stats_file) elif args[i] == '-c' or args[i] == '--clients-file': print "DeprecationWarning: %s is no longer used" % args[i] i = i + 1 self.load_stats(stats_file, self.log.getEffectiveLevel() > logging.WARNING, quick) elif args[0] == 'purge': expired = False client = None maxdate = None state = None i = 1 while i < len(args): if args[i] == '-c' or args[i] == '--client': if client: self.errExit("Only one client per run") client = args[i + 1] print(client) i = i + 1 elif args[i] == '--days': if maxdate: self.errExit("Max date specified multiple times") try: maxdate = datetime.datetime.now() - datetime.timedelta(days=int(args[i + 1])) except: self.log.error("Invalid number of days: %s" % args[i + 1]) raise SystemExit(-1) i = i + 1 elif args[i] == '--expired': expired = True i = i + 1 if expired: if state: self.log.error("--state is not valid with --expired") raise SystemExit(-1) self.purge_expired(maxdate) else: self.purge(client, maxdate, state) else: print("Unknown command: %s" % args[0])