From 6b6f5abe692e3a41b4ff9b6869a23ccae47a367a Mon Sep 17 00:00:00 2001 From: Max Linke Date: Wed, 4 Dec 2024 17:45:30 +0100 Subject: [PATCH] disable network scan feature in the CSE Change-Id: I687376d5973b9631b5879ece223ef70c2e21a010 JIRA-Ref: SAASDEV-2711 --- cmk/gui/cre/registration.py | 2 ++ cmk/gui/watolib/network_scan.py | 31 ++++++++++++++++++++++++++++--- cmk/gui/watolib/registration.py | 11 ----------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/cmk/gui/cre/registration.py b/cmk/gui/cre/registration.py index a03755300ab..caa5053215e 100644 --- a/cmk/gui/cre/registration.py +++ b/cmk/gui/cre/registration.py @@ -52,6 +52,7 @@ NotificationParameterMail, ) from cmk.gui.wato import registration as wato_registration +from cmk.gui.watolib import network_scan from cmk.gui.watolib.activate_changes import ( activation_features_registry, ActivationFeatures, @@ -109,6 +110,7 @@ def register_painters() -> None: def register(edition: Edition) -> None: autocomplete.register(endpoint_registry) + network_scan.register(host_attribute_registry, automation_command_registry, cron_job_registry) common_registration( mega_menu_registry, job_registry, diff --git a/cmk/gui/watolib/network_scan.py b/cmk/gui/watolib/network_scan.py index c98663d70f2..c9513135390 100644 --- a/cmk/gui/watolib/network_scan.py +++ b/cmk/gui/watolib/network_scan.py @@ -11,6 +11,7 @@ import time import traceback from collections.abc import Sequence +from datetime import timedelta from typing import Literal, NamedTuple, TypeGuard from cmk.ccc import store @@ -22,6 +23,7 @@ from cmk.utils.user import UserId from cmk.gui import userdb +from cmk.gui.cron import CronJob, CronJobRegistry from cmk.gui.http import request from cmk.gui.i18n import _ from cmk.gui.log import logger @@ -29,10 +31,16 @@ from cmk.gui.site_config import get_site_config, is_wato_slave_site, site_is_local from ..config import active_config -from . import bakery -from .automation_commands import AutomationCommand +from . import bakery, builtin_attributes +from .automation_commands import AutomationCommand, AutomationCommandRegistry from .automations import do_remote_automation -from .host_attributes import ExcludeIPRange, HostAttributes, IPRange, NetworkScanResult +from .host_attributes import ( + ExcludeIPRange, + HostAttributeRegistry, + HostAttributes, + IPRange, + NetworkScanResult, +) from .hosts_and_folders import Folder, folder_tree, Host, update_metadata NetworkScanFoundHosts = list[tuple[HostName, HostAddress]] @@ -191,6 +199,23 @@ def execute(self, api_request: NetworkScanRequest) -> list[tuple[HostName, HostA return _do_network_scan(folder) +def register( + host_attribute_registry: HostAttributeRegistry, + automation_command_registry: AutomationCommandRegistry, + cron_job_registry: CronJobRegistry, +) -> None: + host_attribute_registry.register(builtin_attributes.HostAttributeNetworkScan) + host_attribute_registry.register(builtin_attributes.HostAttributeNetworkScanResult) + automation_command_registry.register(AutomationNetworkScan) + cron_job_registry.register( + CronJob( + name="execute_network_scan_job", + callable=execute_network_scan_job, + interval=timedelta(minutes=1), + ) + ) + + # This is executed in the site the host is assigned to. def _do_network_scan(folder: Folder) -> list[tuple[HostName, HostAddress]]: ip_addresses = _ip_addresses_to_scan(folder) diff --git a/cmk/gui/watolib/registration.py b/cmk/gui/watolib/registration.py index 45adf5525d3..012a0c9b39b 100644 --- a/cmk/gui/watolib/registration.py +++ b/cmk/gui/watolib/registration.py @@ -76,7 +76,6 @@ MatchItemGeneratorHosts, rebuild_folder_lookup_cache, ) -from .network_scan import AutomationNetworkScan, execute_network_scan_job from .notifications import ( find_timeperiod_usage_in_notification_rules, find_usages_of_contact_group_in_notification_rules, @@ -153,7 +152,6 @@ def register( automation_command_registry.register(AutomationRemoveTLSRegistration) automation_command_registry.register(AutomationCheckAnalyzeConfig) automation_command_registry.register(AutomationDiscoveredHostLabelSync) - automation_command_registry.register(AutomationNetworkScan) automation_command_registry.register(AutomationCheckmkAutomationStart) automation_command_registry.register(AutomationCheckmkAutomationGetStatus) sample_config_generator_registry.register(ConfigGeneratorBasicWATOConfig) @@ -226,8 +224,6 @@ def _register_host_attribute(host_attribute_registry: HostAttributeRegistry) -> builtin_attributes.HostAttributeAdditionalIPv6Addresses, builtin_attributes.HostAttributeSNMPCommunity, builtin_attributes.HostAttributeParents, - builtin_attributes.HostAttributeNetworkScan, - builtin_attributes.HostAttributeNetworkScanResult, builtin_attributes.HostAttributeManagementAddress, builtin_attributes.HostAttributeManagementProtocol, builtin_attributes.HostAttributeManagementSNMPCommunity, @@ -267,13 +263,6 @@ def _register_cronjobs(cron_job_registry: CronJobRegistry) -> None: run_in_thread=True, ) ) - cron_job_registry.register( - CronJob( - name="execute_network_scan_job", - callable=execute_network_scan_job, - interval=timedelta(minutes=1), - ) - ) cron_job_registry.register( CronJob( name="rebuild_folder_lookup_cache",