# Path: web/siteup_api/validators.py
# class ValidateAnyOf(object):
#     def __init__(self, validators, message=None):
#     def __call__(self, value):
# def validate_hostname(hostname):
# 
# Path: web/siteup_api/utils.py
# def timedelta_to_string(td):
#     total_seconds = int(td.total_seconds())
#     days, remainder = divmod(total_seconds, 24 * 60 * 60)
#     hours, remainder = divmod(remainder, 60 * 60)
#     minutes, seconds = divmod(remainder, 60)
# 
#     if days:
#         return (_("{} days, {} hours and {} minutes").format(days, hours, minutes))
#     elif hours:
#         return (_("{} hours and {} minutes").format(hours, minutes))
#     else:
#         return (_("{} minutes").format(minutes))


import logging
import managers
from itertools import chain
from datetime import datetime, timedelta
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.core import validators
from siteup_checker import monitoring
from siteup_checker.tasks_notification import enqueue_notification
from .validators import ValidateAnyOf, validate_ip_or_hostname, validate_hostname
from .utils import timedelta_to_string
from django.db.models.signals import pre_delete
from django.dispatch import receiver
                log.status = 1
                log.status_extra = 'Most packets were lost'

        # Ping could not be launched
        else:
            log.status = 2

            # Check for most common type of error
            log.status_extra = check_result['error']

        logger.info('Save CheckLog, status %i, response_time %i, status_extra "%s"' % (log.status, log.response_time, log.status_extra))
        log.save()

    def __unicode__(self):
        if self.should_check_timeout:
            return _("Ping check to {}, timeout limit {}ms").format(self.target, self.timeout_value)
        else:
            return _("Ping check to {}").format(self.target)

    class Meta:
        verbose_name = _("ping check")
        verbose_name_plural = _("ping checks")


class PortCheck(BaseCheck):

    target = models.CharField(
        max_length=255,
        blank=False,
        help_text=_("Should be a hostname or an IP"),

# Path: web/siteup_api/validators.py
# class ValidateAnyOf(object):
#     def __init__(self, validators, message=None):
#     def __call__(self, value):
# def validate_hostname(hostname):
# 
# Path: web/siteup_api/utils.py
# def timedelta_to_string(td):
#     total_seconds = int(td.total_seconds())
#     days, remainder = divmod(total_seconds, 24 * 60 * 60)
#     hours, remainder = divmod(remainder, 60 * 60)
#     minutes, seconds = divmod(remainder, 60)
# 
#     if days:
#         return (_("{} days, {} hours and {} minutes").format(days, hours, minutes))
#     elif hours:
#         return (_("{} hours and {} minutes").format(hours, minutes))
#     else:
#         return (_("{} minutes").format(minutes))


# Path: web/siteup_api/models.py
import logging
import managers
from itertools import chain
from datetime import datetime, timedelta
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from django.utils.translation import ugettext_lazy as _
from django.core.urlresolvers import reverse
from django.core import validators
from siteup_checker import monitoring
from siteup_checker.tasks_notification import enqueue_notification
from .validators import ValidateAnyOf, validate_ip_or_hostname, validate_hostname
from .utils import timedelta_to_string
from django.db.models.signals import pre_delete
from django.dispatch import receiver

                log.status = 1
                log.status_extra = 'Most packets were lost'

        # Ping could not be launched
        else:
            log.status = 2

            # Check for most common type of error
            log.status_extra = check_result['error']

        logger.info('Save CheckLog, status %i, response_time %i, status_extra "%s"' % (log.status, log.response_time, log.status_extra))
        log.save()

    def __unicode__(self):
        if self.should_check_timeout:
            return _("Ping check to {}, timeout limit {}ms").format(self.target, self.timeout_value)
        else:
            return _("Ping check to {}").format(self.target)

    class Meta:
        verbose_name = _("ping check")
        verbose_name_plural = _("ping checks")


class PortCheck(BaseCheck):

    target = models.CharField(
        max_length=255,
        blank=False,
        help_text=_("Should be a hostname or an IP"),

        validators=[validate_ip_or_hostname]