Пример #1
0
def run_check(service, collector, since=None, until=None, force_check=None, format=None):
    from geonode.monitoring.service_handlers import get_for_service

    utc = pytz.utc
    try:
        local_tz = pytz.timezone(datetime.now(tzlocal()).tzname())
    except Exception:
        local_tz = pytz.timezone(settings.TIME_ZONE)
    now = datetime.utcnow().replace(tzinfo=utc)
    Handler = get_for_service(service.service_type.name)
    try:
        service.last_check = service.last_check.astimezone(utc)
    except Exception:
        service.last_check = service.last_check.replace(tzinfo=utc) if service.last_check else now

    if not until:
        until = now
    else:
        until = local_tz.localize(until).astimezone(utc).replace(tzinfo=utc)

    last_check = local_tz.localize(since).astimezone(utc).replace(tzinfo=utc) if since else service.last_check
    _monitoring_ttl_max = timedelta(days=365) if force_check else settings.MONITORING_DATA_TTL
    if not last_check or last_check > until or (until - last_check) > _monitoring_ttl_max:
        last_check = (until - _monitoring_ttl_max)
        service.last_check = last_check

    # print('[',now ,'] checking', service.name, 'since', last_check, 'until', until)
    data_in = None
    h = Handler(service, force_check=force_check)
    data_in = h.collect(since=last_check, until=until, format=format)
    if data_in:
        try:
            return collector.process(service, data_in, last_check, until)
        finally:
            h.mark_as_checked()
Пример #2
0
    def run_check(self,
                  service,
                  collector,
                  since=None,
                  until=None,
                  force_check=None,
                  format=None):
        utc = pytz.utc
        try:
            local_tz = pytz.timezone(datetime.now(tzlocal()).tzname())
        except:
            local_tz = pytz.timezone(settings.TIME_ZONE)
        now = datetime.utcnow().replace(tzinfo=utc)
        Handler = get_for_service(service.service_type.name)
        try:
            service.last_check = service.last_check.astimezone(utc)
        except:
            service.last_check = service.last_check.replace(
                tzinfo=utc) if service.last_check else now

        if not until:
            until = now
        else:
            until = local_tz.localize(until).astimezone(utc).replace(
                tzinfo=utc)

        last_check = local_tz.localize(since).astimezone(utc).replace(
            tzinfo=utc) if since else service.last_check
        if not last_check or last_check > until or (
                until - last_check) > settings.MONITORING_DATA_TTL:
            last_check = (until - settings.MONITORING_DATA_TTL)
            service.last_check = last_check

        print('[', now, '] checking', service.name, 'since', last_check,
              'until', until)
        data_in = None
        h = Handler(service, force_check=force_check)
        data_in = h.collect(since=last_check, until=until, format=format)
        if data_in:
            try:
                return collector.process(service, data_in, last_check, until)
            finally:
                h.mark_as_checked()