%PDF- %PDF-
Direktori : /opt/imunify360/venv/lib/python3.8/site-packages/defence360agent/plugins/ |
Current File : //opt/imunify360/venv/lib/python3.8/site-packages/defence360agent/plugins/backup_info_sender.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> """ import asyncio from datetime import timedelta from logging import getLogger from defence360agent.contracts.messages import MessageType from defence360agent.contracts.plugins import MessageSource from defence360agent.subsys.backup_systems import ( get_current_backend, get_last_backup_timestamp, ) from defence360agent.utils import Scope logger = getLogger(__name__) SEND_INTERVAL = int(timedelta(hours=24).total_seconds()) class BackupInfoSender(MessageSource): SCOPE = Scope.IM360 async def create_source(self, loop, sink): self._loop = loop self._sink = sink self._task = self._loop.create_task(self._recurring_check()) async def shutdown(self): self._task.cancel() await self._task async def _recurring_check(self): while True: try: await asyncio.sleep(SEND_INTERVAL) await self._send_server_config() except asyncio.CancelledError: break except Exception as e: logger.exception("Failed to collect backup info: %s", e) async def _send_server_config(self): confg_msg = MessageType.BackupInfo( backup_provider_type=get_current_backend(), last_backup_timestamp=await get_last_backup_timestamp(), ) await self._sink.process_message(confg_msg)