# -*- coding: UTF-8 -*-
"""
Surveillance du service Dansguardian
"""
from zephir.monitor.agentmanager.config import ACTIVER_FILTRAGE_PROXY, \
                                               CONTAINER_IP_PROXY, \
                                               DANSGUARDIAN_ETH, \
                                               ADRESSE_IP_SERVICE_PROXY, \
                                               NOM_MACHINE_ETH, \
                                               NOMBRE_INTERFACES

INSTANCE=1
PORT=1340 + INSTANCE - 1

if ACTIVER_FILTRAGE_PROXY:
    instance_activate = False
    prct_name = 'e2guardian'
    for idx, dansguardian_eth in enumerate(DANSGUARDIAN_ETH):
        if int(dansguardian_eth) == INSTANCE:
            instance_activate = True
            test = '%s:%s' % (ADRESSE_IP_SERVICE_PROXY[idx], PORT)
            if NOMBRE_INTERFACES == 0:
                desc1 = 'Filtrage web'
                desc2 = 'eth0'
            else:
                desc1 = 'Filtrage web sur %s' % NOM_MACHINE_ETH[idx]
                desc2 = 'eth' + str(idx + 1)
            break
    if instance_activate:
        from zephir.monitor.agents.services import TCPServices
        AGENTS.append(TCPServices('dans%s' % INSTANCE, {test:desc1}, period=115, container_ip=CONTAINER_IP_PROXY,
                      description="Etat du service {0} sur {1}".format(prct_name, desc2)))
