Edit File: tags.py
import subprocess from defence360agent.application import tags as base_tags from defence360agent.contracts import sentry from defence360agent.utils import stub_unexpected_error from im360.internals import strategy def _set_additional_tags(): def _is_firewalld_running() -> bool: try: subprocess.check_output( ["firewall-cmd", "--state"], timeout=5, stderr=subprocess.DEVNULL, ) return True except ( IOError, subprocess.CalledProcessError, subprocess.TimeoutExpired, ): return False def _is_csf_running() -> bool: try: out = subprocess.check_output( ["/usr/sbin/csf", "--status"], stderr=subprocess.DEVNULL ) except (FileNotFoundError, subprocess.CalledProcessError): return False return (b"have been disabled" not in out) and ( b"You have an unresolved error when starting csf:" not in out ) @stub_unexpected_error def _get_current_firewall(): if _is_csf_running(): return "csf" if _is_firewalld_running(): return "firewalld" return "iptables" fw = _get_current_firewall() sentry.set_firewall_type(fw) if fw == "csf": sentry.set_strategy(strategy.Strategy.CSF_COOP_STRATEGY) else: sentry.set_strategy(strategy.Strategy.PRIMARY_IDS_STRATEGY) def fill() -> None: base_tags.fill() _set_additional_tags()
Back to File Manager