コード例 #1
0
ファイル: tasks.py プロジェクト: serbant/PHSA-SOC
def raise_site_not_configured_for_bot():
    """
    email alerts if there are exchange bots with mis-configured site info

    :returns: the result of the email send operation
    :rtype: str

    :raises:

        :exc:`Exception` if an exception was thrown while sending the alert

    """
    data = models.MailHost.objects.filter(
        Q(site__isnull=True) | Q(site__site__iexact='site.not.exist')).\
        exclude(host_name__iexact='host.not.exist')

    if data.exists():
        data = base_utils.url_annotate(data)

    if not data and not get_preference('exchange__empty_alerts'):
        return 'all exchange bots are properly configured'
    try:
        ret = base_utils.borgs_are_hailing(
            data=data,
            subscription=base_utils.get_subscription('Exchange bot no site'),
            logger=LOGGER,
            level=get_preference('exchange__server_error'))
    except Exception as error:
        raise error

    if ret:
        return 'emailed alert for mis-configured Exchange bots'

    return 'cannot email alert for mis-configured Exchange bots'
コード例 #2
0
def get_failed_logons(
        now=None, time_delta=None, failed_threshold=None,
        annotate_url=True, annotate_details_url=True, **details):
    """
    get the failed login counts that are raising alerts
    """
    queryset = raise_failed_logins_alarm(now, time_delta, failed_threshold)

    if annotate_url:
        queryset = base_utils.url_annotate(queryset)

    if annotate_details_url:
        queryset = base_utils.details_url_annotate(queryset, **details)

    return queryset
コード例 #3
0
def get_dead_bots(
        now=None, time_delta=None,
        annotate_url=True, annotate_details_url=True, **details):
    """
    get the dead bots and annotate each of them with an url to the
    admin change form for the bot and with the amdin link for the events
    coming from this bot
    """
    queryset = _get_dead_bots(now, time_delta)

    if annotate_url:
        queryset = base_utils.url_annotate(queryset)

    if annotate_details_url:
        queryset = base_utils.details_url_annotate(queryset, **details)

    return queryset
コード例 #4
0
def get_ux_alarms(  # pylint: disable=too-many-arguments
        now=None,  group_by=GroupBy.NONE,
        time_delta=get_preference('citrusborgux__ux_alert_interval'),
        ux_alert_threshold=get_preference('citrusborgux__ux_alert_threshold'),
        annotate_url=True, annotate_details_url=True, **details):
    """
    get the user experience alert data
    """
    queryset = raise_ux_alarm(
        now=now, group_by=group_by, time_delta=time_delta,
        ux_alert_threshold=ux_alert_threshold)

    if annotate_url:
        queryset = base_utils.url_annotate(queryset)

    if annotate_details_url:
        queryset = base_utils.details_url_annotate(queryset, **details)

    return queryset
コード例 #5
0
def get_ssl_base_queryset(app_label,
                          model_name,
                          url_annotate=True,
                          issuer_url_annotate=True):
    """
    :returns:

        a :class:`django.db.models.query.QuerySet` based on the
        :class:`ssl_cert_tracker.models.SslCertificate` and `annotated
        <https://docs.djangoproject.com/en/2.2/ref/models/querysets/"""\
        """#annotate>`__
        with the absolute path of the `URL` for the
        :class:`Django admin <django.contrib.admin.ModelAdmin>` instance based
        on the related entry in
        :class:`ssl_cert_tracker.models.SslCertificateIssuer`

        The annotation is present in a field named `url_issuer`.

    This function cannot be abstracted to generate annotations for one or more
    foreign key fields  because the `annotation` names cannot be passed as
    variables
    """
    queryset = utils.get_base_queryset(f'{app_label}.{model_name}',
                                       enabled=True)
    if url_annotate:
        queryset = utils.url_annotate(queryset)
    if issuer_url_annotate \
            and app_label == 'ssl_cert_tracker' \
            and model_name == 'sslcertificate':
        queryset = queryset.\
            annotate(url_issuer_id=Cast('issuer__id', TextField())).\
            annotate(url_issuer=Concat(
                Value(settings.SERVER_PROTO), Value('://'),
                Value(socket.getfqdn()),
                Value(':'), Value(settings.SERVER_PORT),
                Value('/admin/'),
                Value(app_label), Value('/sslcertificateissuer/'),
                F('url_issuer_id'), Value('/change/'),
                output_field=TextField()))

    return queryset
コード例 #6
0
def raise_site_not_configured_for_bot():
    """
    email alerts if there are exchange bots with mis-configured site info
    """
    data = models.MailHost.objects.filter(
        Q(site__isnull=True) | Q(site__site__iexact='site.not.exist')).\
        exclude(host_name__iexact='host.not.exist')

    if data.exists():
        data = base_utils.url_annotate(data)

    if not data and not get_preference('exchange__empty_alerts'):
        LOG.info('all exchange bots are properly configured')
        return

    if Email.send_email(
            data=data,
            subscription=Subscription.get_subscription('Exchange bot no site'),
            level=get_preference('exchange__server_error')):
        LOG.info('emailed alert for mis-configured Exchange bots')

    LOG.warning('cannot email alert for mis-configured Exchange bots')