Ejemplo n.º 1
0
def main(argv=sys.argv):
    """Main function called from console command
    """
    logging.basicConfig(filename='.accounting.log', level=logging.INFO,
                        format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    exit_code = 1
    try:
        app = Application(argv)
        app.run()
        exit_code = 0
    except KeyboardInterrupt:
        exit_code = 0
    except Exception as exc:
        LOG.exception(exc)
    sys.exit(exit_code)
def main(argv=sys.argv):
    logging.basicConfig(filename='.accounting.log',
                        level=logging.INFO,
                        format='%(asctime)s - %(name)s \
                        - %(levelname)s - %(message)s')
    exit_code = 1
    try:
        app = Application(argv)
        app.run()
        exit_code = 0
    except KeyboardInterrupt:
        exit_code = 0
    except Exception as exc:
        LOG.exception(exc)
    sys.exit(exit_code)
    def run(self):
        LOG.info("B2SHAREcollector called with: " + str(self.args))
        print("B2SHAREcollector called with: %s" % str(self.args))

        fileparser = SafeConfigParser()
        fileparser.read(self.args.configpath)

        logger = logging.getLogger('StorageAccounting')
        logger.setLevel(logging.INFO)

        configuration = Configuration(self.args.configpath, logger, fileparser)
        configuration.parseConf()

        eurep = EUDATAccounting(configuration, logger)
        logger.info("Accounting starting ...")
        eurep.reportStatistics(self.args)
        logger.info("Accounting finished")
    def run(self):
        LOG.info("iRODScollector called with: " + str(self.args))
        print("iRODScollector called with: %s" % str(self.args))

        fileparser = SafeConfigParser()
        fileparser.read(self.args.configpath)

        logger = logging.getLogger('StorageAccounting')
        logger.setLevel(logging.INFO)

        configuration = Configuration(self.args.configpath, 
                                      logger, fileparser)
        configuration.parseConf()

        eurep = EUDATAccounting(configuration, logger)
        logger.info("Accounting starting ...")
        eurep.reportStatistics(self.args)
        logger.info("Accounting finished")
Ejemplo n.º 5
0
    def run(self):
        LOG.info("iRODScollector called with: " + str(self.args))
        print("iRODScollector called with: %s" % str(self.args))

        fileparser = SafeConfigParser()
        fileparser.read(self.args.configpath)

        logger = logging.getLogger('StorageAccounting')
        logger.setLevel(logging.INFO)
        ###
        configuration = Configuration(self.args.configpath, logger, fileparser)
        configuration.parseConf()

        eurep = EUDATAccounting(configuration, logger)
        logger.info("Accounting starting ...")
        eurep.reportStatistics(self.args)
        # ierate between instituteds and report statistics for each one separately
        while configuration.setNextInstitute():
            eurep.reportStatistics(self.args)
        logger.info("Accounting finished")
Ejemplo n.º 6
0
def getData(args):
    """builds a query string including the data"""
    core_pattern = "core.%s:record=%s"
    meta_pattern = "meta.%s:record=%s"
    vars = []
    vars.append('account=%s' % args.account)
    if args.key:
        vars.append('key=%s' % args.key)
    for k in ['type', 'value', 'unit']:
        vars.append(core_pattern % (k, getattr(args, k)))
    hasNumber = False
    for k in ['service', 'number', 'object_type', 'measure_time', 'comment']:
        value = getattr(args, k)
        if k == 'number' and value:
            hasNumber = True
        if value:
            if k == 'object_type' and not hasNumber:
                continue
            vars.append(meta_pattern % (k, value))
    qstring = '&'.join(vars)
    LOG.info("query string: " + qstring)
    return qstring
Ejemplo n.º 7
0
def getData(args):
    """builds a query string including the data"""
    core_pattern = "core.%s:record=%s"
    meta_pattern = "meta.%s:record=%s"
    vars = []
    vars.append('account=%s' % args.account)
    if args.key:
        vars.append('key=%s' % args.key)
    for k in ['type', 'value', 'unit']:
        vars.append(core_pattern % (k, getattr(args, k)))
    hasNumber = False
    for k in ['service', 'number', 'object_type', 'measure_time', 'comment']:
        value = getattr(args, k)
        if k=='number' and value:
            hasNumber = True
        if value:
            if k=='object_type' and not hasNumber:
                continue
            vars.append(meta_pattern % (k, value))
    qstring = '&'.join(vars)
    LOG.info("query string: " + qstring)
    return qstring
Ejemplo n.º 8
0
 def run(self):
     LOG.info("addRecord called with: " + str(self.args))
     credentials = utils.getCredentials(self.args)
     url = utils.getUrl(self.args)
     data = utils.getData(self.args)
     if not self.args.test:
         response = utils.call(credentials, url, data)
         if self.args.verbose:
             print(response.text)
         if not response.ok:
             LOG.error("status: %s" % response.status_code)
             sys.exit(str(response.status_code))
         LOG.info("status: %s -- record key: %s" %
                  (response.status_code, response.text))
     else:
         print("Dry run; would call %s with %s" % (url, data))
Ejemplo n.º 9
0
 def run(self):
     LOG.info("addRecord called with: " + str(self.args))
     credentials = utils.getCredentials(self.args)
     url = utils.getUrl(self.args)
     data = utils.getData(self.args)
     if not self.args.test:
         response = utils.call(credentials, url, data)
         if self.args.verbose:
             print(response.text)
         if not response.ok:
             LOG.error("status: %s" % response.status_code)
             sys.exit(str(response.status_code))
         LOG.info("status: %s -- record key: %s" % (response.status_code,
                                                    response.text))
     else:
         print("Dry run; would call %s with %s" % (url, data))
Ejemplo n.º 10
0
def getCredentials(args):
    """Extracts and returns (username, password) from args.
    Looks into environment varaibles ACCOUNTING_USER and
    ACCOUNTING_PW respectively if not found in args.
    Terminates if not found"""

    user = args.user
    if not user:
        user = os.getenv(USERKEY)
    pw = args.password
    if not pw:
        pw = os.getenv(PWKEY)

    if not user:
        msg = "No user id provided"
        LOG.error(msg)
        sys.exit(msg)
    if not pw:
        msg = "No password provided"
        LOG.error(msg)
        sys.exit(msg)
    LOG.info("Credentials found")
    return (user, pw)
Ejemplo n.º 11
0
def getCredentials(args):
    """Extracts and returns (username, password) from args.
    Looks into environment varaibles ACCOUNTING_USER and
    ACCOUNTING_PW respectively if not found in args.
    Terminates if not found"""

    user = args.user
    if not user:
        user = os.getenv(USERKEY)
    pw = args.password
    if not pw:
        pw = os.getenv(PWKEY)

    if not user:
        msg = "No user id provided"
        LOG.error(msg)
        sys.exit(msg)
    if not pw:
        msg = "No password provided"
        LOG.error(msg)
        sys.exit(msg)
    LOG.info("Credentials found")
    return (user, pw)
Ejemplo n.º 12
0
def getUrl(args):
    """Constructs the URL to call based on the parameters provided"""
    url = URL_PATTERN % (args.base_url, args.domain, args.account)
    LOG.info("URL: " + url)
    return url
Ejemplo n.º 13
0
def getUrl(args):
    """Constructs the URL to call based on the parameters provided"""
    url = URL_PATTERN % (args.base_url, args.domain, args.account)
    LOG.info("URL: " + url)
    return url