# Path: isserviceup/config/config.py
# def s2l(x):
# def ensure_private_ssh_key():
# def get_status_description():
# DEBUG = config('DEBUG', cast=bool, default=False)
# FRONTEND_URL = config('FRONTEND_URL', default='http://localhost:8000/')
# REDIS_URL = config('REDIS_URL', default='redis://redis:devpassword@redis')
# MONGO_URL = config('MONGO_URL', default='mongodb://mongo/isserviceup')
# STATUS_UPDATE_INTERVAL = config('STATUS_UPDATE_INTERVAL', cast=int, default=30)
# SERVE_STATIC_FILES = config('SERVE_STATIC_FILES', cast=bool, default=True)
# SENTRY_DSN = config('SENTRY_DSN', default=None)
# CELERY_EAGER = config('CELERY_EAGER', cast=bool, default=False)
# CELERY_BROKER = config('CELERY_BROKER', default=REDIS_URL)
# CELERY_BACKEND = config('CELERY_BACKEND', default=REDIS_URL)
# GITHUB_CLIENT_ID = config('GITHUB_CLIENT_ID', default=None)
# GITHUB_CLIENT_SECRET = config('GITHUB_CLIENT_SECRET', default=None)
# SLACK_WEB_HOOK_URL = config('SLACK_WEB_HOOK_URL', default=None)
# NOTIFIERS = [
#     # Slack(SLACK_WEB_HOOK_URL)
# ]
# NOTIFY_ON_STARTUP = config('NOTIFY_ON_STARTUP', default=False, cast=bool)
# CACHET_NOTIFIER = config('CACHET_NOTIFIER', default=False, cast=bool)
# SERVICES = config('SERVICES', cast=s2l, default=None)
# PRIVATE_SSH_KEY = config('PRIVATE_SSH_KEY', default='')
#             PRIVATE_SSH_KEY = ''
# 
# Path: isserviceup/services/models/service.py
# class Service(object):
# 
#     @property
#     def id(self):
#         return self.__class__.__name__
# 
#     @property
#     def status_url(self):
#         raise NotImplemented()
# 
#     @property
#     def icon_url(self):
#         raise NotImplemented()
# 
#     @property
#     def name(self):
#         raise NotImplemented()
# 
#     def get_status(self):
#         raise NotImplemented()
# 
# class Status(Enum):
#     ok = 1              # green
#     maintenance = 2     # blue
#     minor = 3           # yellow
#     major = 4           # orange
#     critical = 5        # red
#     unavailable = 6     # gray


import requests
import subprocess
from decouple import config
from isserviceup.config import config as isu_config
from isserviceup.services.models.service import Service, Status
    from urlparse import urlparse
    from urllib.parse import urlparse
        # Will check if the GitLab JSON API is OK.
        self.check_json = config('GITLAB_CHECK_JSON', default=True, cast=bool)
        # Will check if the SSH connections to git@{gitlab_url} are OK.
        # To use this you need to set the PRIVATE_SSH_KEY option in the config.
        self.check_ssh = config('GITLAB_CHECK_SSH', default=False, cast=bool)
        # If you need to monitor multiple GitLab instances and need each one to
        # have a different behaviour: extend this class, override the __init__
        # function, call super, and then override these properties.

    def _check_http(self):
        request = requests.get(self.status_url)
        return request.ok

    def _check_json(self):
        request = requests.get('{base}/api/v4/projects'.format(
            base=self.status_url.strip('/')
        ))
        try:
            if request.json():
                return True
        except ValueError as error:
            print('Value error: {msg}'.format(msg=error.message))
        return False

    def _check_private_ssh_key(self):
        if not isu_config.ensure_private_ssh_key():
            print('GitLab SSH error for {url}: {error}'.format(
                url=self.status_url,
                error='No private SSH key found. Make sure the file path you '
                      'set in option PRIVATE_SSH_KEY is correct. If it is a '

# Path: isserviceup/config/config.py
# def s2l(x):
# def ensure_private_ssh_key():
# def get_status_description():
# DEBUG = config('DEBUG', cast=bool, default=False)
# FRONTEND_URL = config('FRONTEND_URL', default='http://localhost:8000/')
# REDIS_URL = config('REDIS_URL', default='redis://redis:devpassword@redis')
# MONGO_URL = config('MONGO_URL', default='mongodb://mongo/isserviceup')
# STATUS_UPDATE_INTERVAL = config('STATUS_UPDATE_INTERVAL', cast=int, default=30)
# SERVE_STATIC_FILES = config('SERVE_STATIC_FILES', cast=bool, default=True)
# SENTRY_DSN = config('SENTRY_DSN', default=None)
# CELERY_EAGER = config('CELERY_EAGER', cast=bool, default=False)
# CELERY_BROKER = config('CELERY_BROKER', default=REDIS_URL)
# CELERY_BACKEND = config('CELERY_BACKEND', default=REDIS_URL)
# GITHUB_CLIENT_ID = config('GITHUB_CLIENT_ID', default=None)
# GITHUB_CLIENT_SECRET = config('GITHUB_CLIENT_SECRET', default=None)
# SLACK_WEB_HOOK_URL = config('SLACK_WEB_HOOK_URL', default=None)
# NOTIFIERS = [
#     # Slack(SLACK_WEB_HOOK_URL)
# ]
# NOTIFY_ON_STARTUP = config('NOTIFY_ON_STARTUP', default=False, cast=bool)
# CACHET_NOTIFIER = config('CACHET_NOTIFIER', default=False, cast=bool)
# SERVICES = config('SERVICES', cast=s2l, default=None)
# PRIVATE_SSH_KEY = config('PRIVATE_SSH_KEY', default='')
#             PRIVATE_SSH_KEY = ''
# 
# Path: isserviceup/services/models/service.py
# class Service(object):
# 
#     @property
#     def id(self):
#         return self.__class__.__name__
# 
#     @property
#     def status_url(self):
#         raise NotImplemented()
# 
#     @property
#     def icon_url(self):
#         raise NotImplemented()
# 
#     @property
#     def name(self):
#         raise NotImplemented()
# 
#     def get_status(self):
#         raise NotImplemented()
# 
# class Status(Enum):
#     ok = 1              # green
#     maintenance = 2     # blue
#     minor = 3           # yellow
#     major = 4           # orange
#     critical = 5        # red
#     unavailable = 6     # gray


# Path: isserviceup/services/models/gitlab.py
import requests
import subprocess
from decouple import config
from isserviceup.config import config as isu_config
from isserviceup.services.models.service import Service, Status
    from urlparse import urlparse
    from urllib.parse import urlparse

        # Will check if the GitLab JSON API is OK.
        self.check_json = config('GITLAB_CHECK_JSON', default=True, cast=bool)
        # Will check if the SSH connections to git@{gitlab_url} are OK.
        # To use this you need to set the PRIVATE_SSH_KEY option in the config.
        self.check_ssh = config('GITLAB_CHECK_SSH', default=False, cast=bool)
        # If you need to monitor multiple GitLab instances and need each one to
        # have a different behaviour: extend this class, override the __init__
        # function, call super, and then override these properties.

    def _check_http(self):
        request = requests.get(self.status_url)
        return request.ok

    def _check_json(self):
        request = requests.get('{base}/api/v4/projects'.format(
            base=self.status_url.strip('/')
        ))
        try:
            if request.json():
                return True
        except ValueError as error:
            print('Value error: {msg}'.format(msg=error.message))
        return False

    def _check_private_ssh_key(self):
        if not isu_config.ensure_private_ssh_key():
            print('GitLab SSH error for {url}: {error}'.format(
                url=self.status_url,
                error='No private SSH key found. Make sure the file path you '
                      'set in option PRIVATE_SSH_KEY is correct. If it is a '

                      'shared file, make sure it has permissions to be read '