def process_options(self): self.job_id = self.get_opt('job_id') self.travis_token = self.get_opt('travis_token') self.repo = self.get_opt('repo') #if travis_token is None: # self.usage('--travis-token option or ' + # '$TRAVIS_TOKEN environment variable required to authenticate to the API') if self.args: # assume arg is a repo in form of HariSekhon/nagios-plugins but do not use url which we are more likely to # have pasted a travis-ci url to a job, see a few lines further down if '/' in self.args[0] and '://' not in self.args[0]: if not self.repo: log.info('using argument as --repo') self.repo = self.args[0] elif not self.job_id: log.info('using argument as --job-id') self.job_id = self.args[0] if self.job_id: # convenience to be able to lazily paste a URL like the following and still have it extract the job_id # https://travis-ci.org/HariSekhon/nagios-plugins/jobs/283840596#L1079 self.job_id = self.job_id.split('/')[-1].split('#')[0] validate_chars(self.job_id, 'job id', '0-9') elif self.repo: validate_chars(self.repo, 'repo', r'\/\w\.-') else: self.usage('--job-id / --repo not specified') validate_alnum(self.travis_token, 'travis token') self.headers['Authorization'] = 'token {0}'.format(self.travis_token)
def process_options(self): self.travis_token = self.get_opt('travis_token') self.repo = self.get_opt('repo') self.job_id = self.get_opt('job_id') if self.args: if '/' in self.args[0] and '://' not in self.args[0]: if not self.repo: log.info('using argument as --repo') self.repo = self.args[0] elif not self.job_id: log.info('using argument as --job-id') self.job_id = self.args[0] if self.job_id: # convenience to be able to lazily paste a URL like the following and still have it extract the job_id # https://travis-ci.org/HariSekhon/nagios-plugins/jobs/283840596#L1079 self.job_id = self.job_id.split('/')[-1].split('#')[0] validate_chars(self.job_id, 'job id', '0-9') elif self.repo: travis_user = os.getenv('TRAVIS_USER') if '/' not in self.repo: self.repo = '/' + self.repo if self.repo[0] == '/' and travis_user: self.repo = travis_user + self.repo validate_chars(self.repo, 'repo', r'\/\w\.-') else: self.usage('--job-id / --repo not specified') validate_alnum(self.travis_token, 'travis token') self.headers['Authorization'] = 'token {0}'.format(self.travis_token) self.num = self.get_opt('num') validate_int(self.num, 'num', 1) self.num = int(self.num) self.completed = self.get_opt('completed') self.failed = self.get_opt('failed')
def process_options(self): super(CheckSeleniumHubBrowser, self).process_options() self.hub_url = self.get_opt('hub_url') if self.hub_url: validate_url(self.hub_url, 'hub') else: self.host = self.get_opt('host') self.port = self.get_opt('port') validate_host(self.host) validate_port(self.port) if self.get_opt('ssl') or int(self.port) == 443: self.protocol = 'https' self.hub_url = '{protocol}://{host}:{port}/{path}'\ .format(protocol=self.protocol, \ host=self.host, \ port=self.port, \ path=self.path) self.url = self.get_opt('url') if ':' not in self.url: self.url = 'http://' + self.url validate_url(self.url) self.browser = self.get_opt('browser') if self.browser: self.browser = self.browser.upper() validate_alnum(self.browser, 'browser') self.expected_content = self.get_opt('content') self.expected_regex = self.get_opt('regex') if self.expected_regex: validate_regex(self.expected_regex) self.expected_regex = re.compile(self.expected_regex) elif self.url == self.url_default: self.expected_content = self.expected_content_default
def process_options(self): self.job_id = self.get_opt('job_id') self.travis_token = self.get_opt('travis_token') self.repo = self.get_opt('repo') #if travis_token is None: # self.usage('--travis-token option or ' + # '$TRAVIS_TOKEN environment variable required to authenticate to the API') if self.args: if '/' in self.args[0]: if not self.repo: log.info('using argument as --repo') self.repo = self.args[0] elif not self.job_id: log.info('using argument as --job-id') self.job_id = self.args[0] if self.job_id: validate_chars(self.job_id, 'job id', '0-9') elif self.repo: validate_chars(self.repo, 'repo', r'\/\w\.-') else: self.usage('--job-id / --repo not specified') validate_alnum(self.travis_token, 'travis token') self.headers['Authorization'] = 'token {0}'.format(self.travis_token)
def run(self): job_id = self.get_opt('job_id') travis_token = self.get_opt('travis_token') if job_id is None: travis_token = os.getenv('JOB_ID') if travis_token is None: travis_token = os.getenv('TRAVIS_TOKEN') #if travis_token is None: # self.usage('--travis-token option or ' + # '$TRAVIS_TOKEN environment variable required to authenticate to the API') validate_chars(job_id, 'job id', '0-9') validate_alnum(travis_token, 'travis token') headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Travis-API-Version': '3', 'Authorization': 'token {0}'.format(travis_token) } log.info('triggering debug job {job_id}'.format(job_id=job_id)) url = 'https://api.travis-ci.org/job/{job_id}/debug'.format(job_id=job_id) log.debug('POST %s' % url) try: req = requests.post(url, headers=headers) except requests.exceptions.RequestException as _: raise CriticalError(_) log.debug("response: %s %s", req.status_code, req.reason) log.debug("content:\n%s\n%s\n%s", '='*80, req.content.strip(), '='*80) if req.status_code == 409: error_message = '' try: _ = json.loads(req.content) error_message = _['error_message'] except ValueError: pass error_message += (" (if you've just retriggered this you can avoid this error " + "using the --ignore-running switch)") if self.get_opt('ignore_running'): log.info('job already running (ignoring)') else: log.info('job already running') raise CriticalError('{0} {1}: {2}'.format(req.status_code, req.reason, error_message)) elif req.status_code != 202: raise CriticalError("%s %s" % (req.status_code, req.reason)) # don't need to query this if using the API address rather than the web UI address # as we don't need to figure out the repo name, just use the job id by itself # url = 'https://api.travis-ci.org/job/{job_id}'.format(job_id=job_id) # log.debug('GET %s' % url) # try: # req = requests.get(url, headers=headers) # except requests.exceptions.RequestException as _: # raise CriticalError(_) # log.debug("response: %s %s", req.status_code, req.reason) # log.debug("content:\n%s\n%s\n%s", '='*80, req.content.strip(), '='*80) # if req.status_code != 200: # raise CriticalError("%s %s" % (req.status_code, req.reason)) # # repo = None # try: # repo = json.loads(req.content)['repository']['slug'] # except ValueError as _: # raise ssh_address = self.get_ssh_address(job_id=job_id) log.info('Executing: ssh -- {0}'.format(ssh_address)) sys.stdout.flush() sys.stderr.flush() self.disable_timeout() os.execvp('ssh', ['--', ssh_address])
def process_options(self): super(CheckElasticsearchXPackFeatureEnabled, self).process_options() self.feature = self.get_opt('feature') if not self.get_opt('list_features'): validate_alnum(self.feature, 'feature')
def run(self): job_id = self.get_opt('job_id') travis_token = self.get_opt('travis_token') if job_id is None: travis_token = os.getenv('JOB_ID') if travis_token is None: travis_token = os.getenv('TRAVIS_TOKEN') #if travis_token is None: # self.usage('--travis-token option or ' + # '$TRAVIS_TOKEN environment variable required to authenticate to the API') validate_chars(job_id, 'job id', '0-9') validate_alnum(travis_token, 'travis token') headers = { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Travis-API-Version': '3', 'Authorization': 'token {0}'.format(travis_token) } log.info('triggering debug job {job_id}'.format(job_id=job_id)) url = 'https://api.travis-ci.org/job/{job_id}/debug'.format( job_id=job_id) log.debug('POST %s' % url) try: req = requests.post(url, headers=headers) except requests.exceptions.RequestException as _: raise CriticalError(_) log.debug("response: %s %s", req.status_code, req.reason) log.debug("content:\n%s\n%s\n%s", '=' * 80, req.content.strip(), '=' * 80) if req.status_code == 409: error_message = '' try: _ = json.loads(req.content) error_message = _['error_message'] except ValueError: pass error_message += ( " (if you've just retriggered this you can avoid this error " + "using the --ignore-running switch)") if self.get_opt('ignore_running'): log.info('job already running (ignoring)') else: log.info('job already running') raise CriticalError('{0} {1}: {2}'.format( req.status_code, req.reason, error_message)) elif req.status_code != 202: raise CriticalError("%s %s" % (req.status_code, req.reason)) # don't need to query this if using the API address rather than the web UI address # as we don't need to figure out the repo name, just use the job id by itself # url = 'https://api.travis-ci.org/job/{job_id}'.format(job_id=job_id) # log.debug('GET %s' % url) # try: # req = requests.get(url, headers=headers) # except requests.exceptions.RequestException as _: # raise CriticalError(_) # log.debug("response: %s %s", req.status_code, req.reason) # log.debug("content:\n%s\n%s\n%s", '='*80, req.content.strip(), '='*80) # if req.status_code != 200: # raise CriticalError("%s %s" % (req.status_code, req.reason)) # # repo = None # try: # repo = json.loads(req.content)['repository']['slug'] # except ValueError as _: # raise ssh_address = self.get_ssh_address(job_id=job_id) log.info('Executing: ssh -- {0}'.format(ssh_address)) sys.stdout.flush() sys.stderr.flush() self.disable_timeout() os.execvp('ssh', ['--', ssh_address])