From fea8003d643b0e39402c1fcaa624f5ad7072c486 Mon Sep 17 00:00:00 2001 From: Kai Chen Date: Sun, 4 Nov 2018 16:26:04 -0800 Subject: [PATCH 1/2] Add support to check if Gitlab is down Add method to check Gitlab's status. Closes https://github.com/ksdme/org-status/issues/5 --- org_status/org_hosts/gitlab.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/org_status/org_hosts/gitlab.py b/org_status/org_hosts/gitlab.py index 7aafb01..65ac0e9 100644 --- a/org_status/org_hosts/gitlab.py +++ b/org_status/org_hosts/gitlab.py @@ -1,3 +1,6 @@ +import json + +import requests from IGitt.GitLab.GitLab import GitLabPrivateToken from IGitt.GitLab.GitLabOrganization import GitLabOrganization @@ -9,6 +12,9 @@ class GitLabOrg(OrgHost): HostName = 'gitlab' StatusProvider = GitLabCIStatus + HOST_STATUS_URL = ('https://api.status.io/1.0/status' + '/5b36dc6502d06804c08349f7') + def __init__(self, token, group, **kargs): super().__init__(**kargs) @@ -18,6 +24,12 @@ def __init__(self, token, group, **kargs): self._status_provider = self.StatusProvider(self._group) + @classmethod + def get_host_status(cls): + status = requests.get(cls.HOST_STATUS_URL) + status = json.loads(status.text) + return status['result']['status_overall']['status'] == 'Operational' + def process_repository(self, repo, branch='master'): self.print_status(repo.web_url) From 9bb5f804416d265596b2ff99f93d9bc086bf49c5 Mon Sep 17 00:00:00 2001 From: Kai Chen Date: Sun, 4 Nov 2018 16:43:35 -0800 Subject: [PATCH 2/2] Support host checking only and skipping mode Add CLI options --hosts-only and --skip-host-checks which allows users to check for host statuses only or to skip host checks entirely. Closes https://github.com/ksdme/org-status/issues/24 --- org_status/org_status.py | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/org_status/org_status.py b/org_status/org_status.py index 067b371..8b42510 100644 --- a/org_status/org_status.py +++ b/org_status/org_status.py @@ -69,10 +69,12 @@ def present_status(statuses, no_color): def get_argument_parser(): parser = ArgumentParser() - parser.add_argument('orgs', nargs='+', help='host:org') + parser.add_argument('orgs', nargs='*', help='host:org') parser.add_argument('--threads', type=int, default=2) parser.add_argument('--no-color', action='store_true') parser.add_argument('--verbose', '-v', action='store_true') + parser.add_argument('--hosts-only', '-o', action='store_true') + parser.add_argument('--skip-host-checks', action='store_true') return parser @@ -84,17 +86,33 @@ def main(): styled = (lambda l, *_: l) if args.no_color else colored verbose = print if args.verbose else (lambda *_: None) + hosts_only_print = print if args.hosts_only else verbose + + if len(args.orgs) == 0 and args.hosts_only: + args.orgs = ['coala'] + elif len(args.orgs) == 0: + print(styled('no organizations to check', 'red')) + return + for Host, org in generate_fetch_jobs(args.orgs): token = None - try: - if not Host.get_host_status(): - print(styled(f'{Host.HostName} is currently down', 'red')) - continue - else: - verbose(f'{Host.HostName} is up') - except NotImplementedError: - verbose(f'{Host.HostName} does not support checking host status') + if not args.skip_host_checks: + try: + if not Host.get_host_status(): + print(styled(f'{Host.HostName} is currently down', 'red')) + continue + else: + hosts_only_print(f'{Host.HostName} is up') + except NotImplementedError: + verbose( + f'{Host.HostName} does not support checking host status') + + if args.hosts_only and args.skip_host_checks: + verbose('nothing to do') + return + elif args.hosts_only: + continue if (args.verbose): print(f'processing org {Host.HostName}:{org}')