<commit_before>from logging import getLogger

from api.decorators import catch_exception
from api.mon.base.tasks import mon_sync_all

logger = getLogger(__name__)


MON_SERVER_RELATED_SETTINGS = (
    'MON_ZABBIX_MONITORING_ENABLED',
    'MON_ZABBIX_SERVER',
    'MON_ZABBIX_SERVER_SSL_VERIFY',
    'MON_ZABBIX_USERNAME',
    'MON_ZABBIX_PASSWORD',
    'MON_ZABBIX_HTTP_USERNAME',
    'MON_ZABBIX_HTTP_PASSWORD',
)

MON_NODE_RELATED_SETTINGS = (
    'MON_ZABBIX_NODE_SYNC',
    'MON_ZABBIX_HOSTGROUP_NODE',
    'MON_ZABBIX_HOSTGROUPS_NODE',
    'MON_ZABBIX_TEMPLATES_NODE',
)

MON_VM_RELATED_SETTINGS = (
    'MON_ZABBIX_VM_SYNC',
    'MON_ZABBIX_HOSTGROUP_VM',
    'MON_ZABBIX_HOSTGROUPS_VM',
    'MON_ZABBIX_TEMPLATES_VM',
    'MON_ZABBIX_TEMPLATES_VM_MAP_TO_TAGS',
    'MON_ZABBIX_TEMPLATES_VM_NIC',
    'MON_ZABBIX_TEMPLATES_VM_DISK',
    'MON_ZABBIX_HOST_VM_PROXY',
)


# noinspection PyUnusedLocal
@catch_exception
def mon_settings_changed_handler(task_id, dc, old_settings, new_settings):
    """
    Handle changes in MON_* DC settings; triggered by dc_settings_changed signal.
    """
    changed_mon_settings = {opt for opt in old_settings if (opt.startswith('MON_ZABBIX') and
                                                            old_settings.get(opt) != new_settings.get(opt))}

    if changed_mon_settings:<commit_msg>Added missing MON_ZABBIX_ENABLED into mon_settings_changed_handler - Issue #210 (PR #311)<commit_after>from logging import getLogger

from api.decorators import catch_exception
from api.mon.base.tasks import mon_sync_all

logger = getLogger(__name__)


MON_SERVER_RELATED_SETTINGS = (
    'MON_ZABBIX_ENABLED',
    'MON_ZABBIX_MONITORING_ENABLED',
    'MON_ZABBIX_SERVER',
    'MON_ZABBIX_SERVER_SSL_VERIFY',
    'MON_ZABBIX_USERNAME',
    'MON_ZABBIX_PASSWORD',
    'MON_ZABBIX_HTTP_USERNAME',
    'MON_ZABBIX_HTTP_PASSWORD',
)

MON_NODE_RELATED_SETTINGS = (
    'MON_ZABBIX_ENABLED',
    'MON_ZABBIX_NODE_SYNC',
    'MON_ZABBIX_HOSTGROUP_NODE',
    'MON_ZABBIX_HOSTGROUPS_NODE',
    'MON_ZABBIX_TEMPLATES_NODE',
)

MON_VM_RELATED_SETTINGS = (
    'MON_ZABBIX_ENABLED',
    'MON_ZABBIX_VM_SYNC',
    'MON_ZABBIX_HOSTGROUP_VM',
    'MON_ZABBIX_HOSTGROUPS_VM',
    'MON_ZABBIX_TEMPLATES_VM',
    'MON_ZABBIX_TEMPLATES_VM_MAP_TO_TAGS',
    'MON_ZABBIX_TEMPLATES_VM_NIC',
    'MON_ZABBIX_TEMPLATES_VM_DISK',
    'MON_ZABBIX_HOST_VM_PROXY',
)


# noinspection PyUnusedLocal
@catch_exception
def mon_settings_changed_handler(task_id, dc, old_settings, new_settings):
    """
    Handle changes in MON_* DC settings; triggered by dc_settings_changed signal.
    """
    mon_zabbix_enabled = new_settings.get('MON_ZABBIX_ENABLED', None)

    if mon_zabbix_enabled is False:
        logger.warning('Monitoring got disabled in DC %s', dc)
        return

    changed_mon_settings = {opt for opt in new_settings if (opt.startswith('MON_ZABBIX') and
                                                            old_settings.get(opt) != new_settings.get(opt))}

    if changed_mon_settings:
{'fraction_non_alphanumeric': 0.08394160583941605, 'fraction_numerical': 0.0019907100199071004, 'mean_word_length': 4.216262975778546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4086235', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1189, 'n_words': 159}