%PDF- %PDF-
Direktori : /proc/2/root/opt/imunify360/venv/lib/python3.8/site-packages/defence360agent/contracts/ |
Current File : //proc/2/root/opt/imunify360/venv/lib/python3.8/site-packages/defence360agent/contracts/sentry.py |
""" This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see <https://www.imunify360.com/legal/eula> """ from subprocess import DEVNULL, CalledProcessError, check_output from typing import Any from defence360agent.utils import stub_unexpected_error def _run_cmd(cmd): try: out = check_output(cmd, stderr=DEVNULL) except (FileNotFoundError, CalledProcessError): return None return out.decode('utf-8', errors='ignore').strip() @stub_unexpected_error def _get_virtualization_type(): systemd_virt = _run_cmd(['systemd-detect-virt']) if systemd_virt: return systemd_virt virt_what = _run_cmd(['virt-what']) if virt_what: return virt_what demicode = _run_cmd(['dmidecode', '-s', 'system-manufacturer']) if demicode: return demicode return 'fail to detect' @stub_unexpected_error def _get_total_ram(): import psutil return psutil.virtual_memory().total // 2**20 _TAGS = None def _tags(): global _TAGS if _TAGS is None: from defence360agent.utils import OsReleaseInfo _TAGS = { 'version': None, 'os_details': stub_unexpected_error(OsReleaseInfo.pretty_name)(), 'ip': None, 'hosting_panel': None, 'total_ram': _get_total_ram(), 'firewall': None, 'strategy': None, 'virtualization': _get_virtualization_type(), 'server_id': None, 'name': None, } return _TAGS def set_firewall_type(firewall: str) -> None: _tags()['firewall'] = firewall def set_hosting_panel(panel: str) -> None: _tags()['hosting_panel'] = panel def set_strategy(strategy: str) -> None: _tags()['strategy'] = strategy def set_ip(ip: str) -> None: _tags()['ip'] = ip def set_product_name(product: str) -> None: _tags()['name'] = product def set_server_id(id: str) -> None: _tags()['server_id'] = id def set_version(version: str) -> None: _tags()['version'] = version def tags() -> dict: return _tags().copy() def tag(name: str) -> Any: return _tags()[name]