def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        user = self.get_opt('user')
        password = self.get_opt('password')
        workflow_id = self.get_opt('id')
        workflow_name = self.get_opt('name')
        max_age = self.get_opt('max_age')
        max_runtime = self.get_opt('max_runtime')
        if self.get_opt('ssl'):
            self.protocol = 'https'
        validate_host(host)
        validate_port(port)
        validate_user(user)
        validate_password(password)
        if workflow_id is not None:
            if workflow_name is not None:
                self.usage('cannot specify both --id and --name simultaneously')
            validate_int(workflow_id, 'workflow id', 1)
        elif workflow_name is not None:
            validate_chars(workflow_name, 'workflow name', r'\w-')
        elif self.get_opt('list'):
            pass
        else:
            self.usage('must specify either --name or --id or use --list to find them')
        if max_age is not None:
            validate_float(max_age, 'max age', 1)
            max_age = float(max_age)
        if max_runtime is not None:
            validate_float(max_runtime, 'max runtime', 1)
            max_runtime = float(max_runtime)

        self.url_base = '{protocol}://{host}:{port}/bedrock-app/services/rest'.format(host=host, port=port,
                                                                                      protocol=self.protocol)
        # auth first, get JSESSIONID cookie
        # cookie jar doesn't work in Python or curl, must extract JSESSIONID to header manually
        #self.jar = cookielib.CookieJar()
        log.info('authenticating to Zaloni Bedrock')
        (_, self.auth_time) = self.req(url='{url_base}/admin/getUserRole'.format(url_base=self.url_base),
                                       # using json instead of constructing string manually,
                                       # this correctly escapes backslashes in password
                                       body=json.dumps({"username": user, "password": password}))
        # alternative method
        #session = requests.Session()
        #req = self.req(session,
        #               url='http://%(host)s:%(port)s/bedrock-app/services/rest/%(user)s/getUserRole' % locals(),
        #               method='POST')

        if self.get_opt('list'):
            self.list_workflows()

        self.check_workflow(workflow_name, workflow_id, max_age, max_runtime)
예제 #2
0
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        user = self.get_opt('user')
        password = self.get_opt('password')
        if self.get_opt('ssl'):
            self.protocol = 'https'
        history_mins = self.get_opt('history_mins')
        num = self.get_opt('num')
        #inventory_id = self.get_opt('id')
        source = self.get_opt('source')
        dest = self.get_opt('dest')
        max_age = self.get_opt('max_age')
        max_runtime = self.get_opt('max_runtime')
        validate_host(host)
        validate_port(port)
        validate_user(user)
        validate_password(password)
        validate_float(history_mins, 'history mins')
        self.history_mins = float(history_mins)
        filter_opts = {}
        if self.history_mins:
            now = datetime.now()
            filter_opts['dateRangeStart'] = datetime.strftime(now - timedelta(minutes=self.history_mins), '%F %H:%M:%S')
            filter_opts['dateRangeEnd'] = datetime.strftime(now, '%F %H:%M:%S')
        if num is not None:
            validate_int(num, 'num ingestions', 1)
        #if inventory_id is not None:
        #    validate_chars(inventory_id, 'ingestion id', r'\w-')
        #    filter_opts['inventoryId'] = inventory_id
        if source is not None:
            log_option('source', source)
            filter_opts['fileName'] = source
        if dest is not None:
            log_option('dest', dest)
            filter_opts['destinationPath'] = dest
        if max_age is not None:
            validate_float(max_age, 'max age', 1)
            max_age = float(max_age)
        if max_runtime is not None:
            validate_float(max_runtime, 'max incomplete runtime', 1)
            max_runtime = float(max_runtime)

        self.url_base = '{protocol}://{host}:{port}/bedrock-app/services/rest'.format(host=host,
                                                                                      port=port,
                                                                                      protocol=self.protocol)
        # auth first, get JSESSIONID cookie
        # cookie jar doesn't work in Python or curl, must extract JSESSIONID to header manually
        #self.jar = cookielib.CookieJar()
        log.info('authenticating to Zaloni Bedrock')
        (_, self.auth_time) = self.req(url='{url_base}/admin/getUserRole'.format(url_base=self.url_base),
                                       # using json instead of constructing string manually,
                                       # this correctly escapes backslashes in password
                                       body=json.dumps({"username": user, "password": password}))
        if self.get_opt('list'):
            self.list_ingestions(num=num)

        self.check_ingestion(num=num, filter_opts=filter_opts, max_age=max_age, max_runtime=max_runtime)
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     self._all = self.get_opt('all')
     self.workflow_id = self.get_opt('id')
     self.workflow_name = self.get_opt('name')
     self.max_age = self.get_opt('max_age')
     self.max_runtime = self.get_opt('max_runtime')
     self.min_runtime = self.get_opt('min_runtime')
     if self.get_opt('ssl'):
         self.protocol = 'https'
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     if self._all and (self.workflow_name is not None
                       or self.workflow_id is not None):
         self.usage(
             'cannot specify both --all and --name/--id simultaneously')
     if self.workflow_id is not None:
         if self.workflow_name is not None:
             self.usage(
                 'cannot specify both --id and --name simultaneously')
         validate_int(self.workflow_id, 'workflow id', 1)
         self.workflow_id = int(self.workflow_id)
     elif self.workflow_name is not None:
         validate_chars(self.workflow_name, 'workflow name', r'\w\s-')
     elif self._all:
         pass
     elif self.get_opt('list'):
         pass
     else:
         self.usage(
             'must specify one of --name / --id / --all or use --list to find workflow names/IDs to specify'
         )
     if self.max_age is not None:
         validate_float(self.max_age, 'max age', 1)
         self.max_age = float(self.max_age)
     if self.max_runtime is not None:
         validate_float(self.max_runtime, 'max runtime', 1)
         self.max_runtime = float(self.max_runtime)
     if self.min_runtime is not None:
         validate_float(self.min_runtime, 'min runtime', 0)
         self.min_runtime = float(self.min_runtime)
         if self.max_runtime is not None and self.min_runtime > self.max_runtime:
             self.usage(
                 '--min-runtime cannot be greater than --max-runtime!')
예제 #4
0
    def process_options(self):
        super(CheckPrestoWorker, self).process_options()
        self.node = self.get_opt('node')
        self.list_nodes = self.get_opt('list_nodes')
        if not self.node and not self.list_nodes:
            self.usage('--node not defined')
        self.max_age = self.get_opt('max_age')
        validate_float(self.max_age, 'max age', 0, 3600)
        self.max_age = int(self.max_age)

        self.max_requests = self.get_opt('max_requests')
        if self.max_requests is not None:
            validate_float(self.max_requests, 'max recent requests', 0, None)
            self.max_requests = float('{0:.2f}'.format(float(self.max_requests)))

        self.max_failures = self.get_opt('max_failures')
        validate_float(self.max_failures, 'max recent failures', 0, None)
        self.max_failures = float('{0:.2f}'.format(float(self.max_failures)))

        self.max_ratio = self.get_opt('max_ratio')
        validate_float(self.max_ratio, 'max recent failure ratio', 0, 1.0)
        self.max_ratio = float('{0:.2f}'.format(float(self.max_ratio)))
 def process_options(self):
     self.no_args()
     self.host = self.get_opt('host')
     self.port = self.get_opt('port')
     self.user = self.get_opt('user')
     self.password = self.get_opt('password')
     self._all = self.get_opt('all')
     self.workflow_id = self.get_opt('id')
     self.workflow_name = self.get_opt('name')
     self.max_age = self.get_opt('max_age')
     self.max_runtime = self.get_opt('max_runtime')
     self.min_runtime = self.get_opt('min_runtime')
     if self.get_opt('ssl'):
         self.protocol = 'https'
     validate_host(self.host)
     validate_port(self.port)
     validate_user(self.user)
     validate_password(self.password)
     if self._all and (self.workflow_name is not None or self.workflow_id is not None):
         self.usage('cannot specify both --all and --name/--id simultaneously')
     if self.workflow_id is not None:
         if self.workflow_name is not None:
             self.usage('cannot specify both --id and --name simultaneously')
         validate_int(self.workflow_id, 'workflow id', 1)
         self.workflow_id = int(self.workflow_id)
     elif self.workflow_name is not None:
         validate_chars(self.workflow_name, 'workflow name', r'\w\s-')
     elif self._all:
         pass
     elif self.get_opt('list'):
         pass
     else:
         self.usage('must specify one of --name / --id / --all or use --list to find workflow names/IDs to specify')
     if self.max_age is not None:
         validate_float(self.max_age, 'max age', 1)
         self.max_age = float(self.max_age)
     if self.max_runtime is not None:
         validate_float(self.max_runtime, 'max runtime', 1)
         self.max_runtime = float(self.max_runtime)
     if self.min_runtime is not None:
         validate_float(self.min_runtime, 'min runtime', 0)
         self.min_runtime = float(self.min_runtime)
         if self.max_runtime is not None and self.min_runtime > self.max_runtime:
             self.usage('--min-runtime cannot be greater than --max-runtime!')
예제 #6
0
 def process_options(self):
     super(CheckPrestoWorkersFailures, self).process_options()
     self.max_failures = self.get_opt('max_failures')
     validate_float(self.max_failures, 'max recent failures', 0, 1000)
     self.max_failures = float('{0:.2f}'.format(float(self.max_failures)))
     self.validate_thresholds()
예제 #7
0
 def process_args(self):
     self.no_args()
     self.only_active_keys = self.get_opt('only_active')
     self.age = self.get_opt('age')
     validate_float(self.age, 'age')
     self.age = int(self.age)
 def process_args(self):
     self.age = self.get_opt('age')
     if self.age:
         validate_float(self.age, 'age')
         self.age = float(self.age)
 def process_options(self):
     super(CheckPrestoWorkersFailures, self).process_options()
     self.max_failures = self.get_opt('max_failures')
     validate_float(self.max_failures, 'max recent failures', 0, 1000)
     self.max_failures = float('{0:.2f}'.format(float(self.max_failures)))
     self.validate_thresholds()
 def process_args(self):
     self.no_args()
     self.age = self.get_opt('age')
     validate_float(self.age, 'age')
     self.age = int(self.age)
예제 #11
0
 def process_options(self):
     super(CheckPrestoWorkersFailureRatio, self).process_options()
     self.max_ratio = self.get_opt('max_ratio')
     validate_float(self.max_ratio, 'max recent failure ratio', 0, 1.0)
     self.max_ratio = float('{0:.2f}'.format(float(self.max_ratio)))
     self.validate_thresholds()
예제 #12
0
 def sleep_secs(self, secs):
     validate_float(secs, 'sleep_secs')
     log.debug('setting sleep secs to %s secs', secs)
     self.__sleep_secs = float(secs)
 def process_options(self):
     super(CheckPrestoWorkersFailureRatio, self).process_options()
     self.max_ratio = self.get_opt('max_ratio')
     validate_float(self.max_ratio, 'max recent failure ratio', 0, 1.0)
     self.max_ratio = float('{0:.2f}'.format(float(self.max_ratio)))
     self.validate_thresholds()
 def process_args(self):
     self.only_active_keys = self.get_opt('only_active')
     self.age = self.get_opt('age')
     if self.age:
         validate_float(self.age, 'age')
         self.age = float(self.age)
    def run(self):
        self.no_args()
        host = self.get_opt('host')
        port = self.get_opt('port')
        user = self.get_opt('user')
        password = self.get_opt('password')
        self._all = self.get_opt('all')
        workflow_id = self.get_opt('id')
        workflow_name = self.get_opt('name')
        max_age = self.get_opt('max_age')
        max_runtime = self.get_opt('max_runtime')
        if self.get_opt('ssl'):
            self.protocol = 'https'
        validate_host(host)
        validate_port(port)
        validate_user(user)
        validate_password(password)
        if workflow_id is not None:
            if workflow_name is not None:
                self.usage(
                    'cannot specify both --id and --name simultaneously')
            validate_int(workflow_id, 'workflow id', 1)
            workflow_id = int(workflow_id)
        elif workflow_name is not None:
            validate_chars(workflow_name, 'workflow name', r'\w\s-')
        elif self.get_opt('list'):
            pass
        else:
            self.usage(
                'must specify one of --name / --id / --all or use --list to find workflow names/IDs to specify'
            )
        if max_age is not None:
            validate_float(max_age, 'max age', 1)
            max_age = float(max_age)
        if max_runtime is not None:
            validate_float(max_runtime, 'max runtime', 1)
            max_runtime = float(max_runtime)

        self.url_base = '{protocol}://{host}:{port}/bedrock-app/services/rest'.format(
            host=host, port=port, protocol=self.protocol)
        # auth first, get JSESSIONID cookie
        # cookie jar doesn't work in Python or curl, must extract JSESSIONID to header manually
        #self.jar = cookielib.CookieJar()
        log.info('authenticating to Zaloni Bedrock')
        (_, self.auth_time) = self.req(
            url='{url_base}/admin/getUserRole'.format(url_base=self.url_base),
            # using json instead of constructing string manually,
            # this correctly escapes backslashes in password
            body=json.dumps({
                "username": user,
                "password": password
            }))
        # alternative method
        #session = requests.Session()
        #req = self.req(session,
        #               url='http://%(host)s:%(port)s/bedrock-app/services/rest/%(user)s/getUserRole' % locals(),
        #               method='POST')

        if self.get_opt('list'):
            self.list_workflows()

        if self._all:
            workflows = self.get_workflows()
            if not workflows or len(workflows) == 0:
                qquit('UNKNOWN', 'no workflows found')
            results = {}
            try:
                for workflow in workflows:
                    result = self.check_workflow(workflow['wfName'], None)
                    if result is None:
                        results['No Runs'] = results.get('None', 0)
                        results['No Runs'] += 1
                        continue
                    results[result] = results.get(result, 0)
                    results[result] += 1
                self.msg = 'Zaloni workflows: '
                for result in results:
                    self.msg += "'{0}' = {1}, ".format(result, results[result])
                self.msg = self.msg.rstrip(', ')
            except KeyError as _:
                qquit(
                    'UNKNOWN',
                    'parsing workflows for --all failed: {0}. '.format(_) +
                    support_msg_api())
        else:
            self.check_workflow(workflow_name, workflow_id, max_age,
                                max_runtime)