From 0a655e544146d3a58ff03e7fb9bcfcdbf6be643f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tuncay=20=C3=87OLAK?= Date: Tue, 27 Oct 2020 14:40:52 +0300 Subject: [PATCH] Syncing /usr/share/ahenk to src and recreating ahenk.install --- debian/ahenk.install | 2 + .../ahenk/base/command/command_runner.py | 5 +- usr/share/ahenk/base/messaging/messaging.py | 1 + .../ahenk/base/registration/registration.py | 1 + .../ahenk/base/registration/scripts/ad.sh | 4 +- usr/share/ahenk/base/util/util.py | 10 ++++ usr/share/ahenk/plugins/ldap/rename_entry.py | 30 +++++++++- .../plugins/remote-access/setup-vnc-server.py | 36 ++++++------ .../ahenk/plugins/resource-usage/agent_info | 0 .../plugins/resource-usage/agent_info.py | 56 +++++++++++++++++++ 10 files changed, 121 insertions(+), 24 deletions(-) create mode 100644 usr/share/ahenk/plugins/resource-usage/agent_info create mode 100644 usr/share/ahenk/plugins/resource-usage/agent_info.py diff --git a/debian/ahenk.install b/debian/ahenk.install index d7b0462..152476c 100644 --- a/debian/ahenk.install +++ b/debian/ahenk.install @@ -166,6 +166,8 @@ usr/share/ahenk/plugins/service/service_list.py usr/share/ahenk/plugins/service/main.py usr/share/ahenk/plugins/service/get_services.py usr/share/ahenk/plugins/service +usr/share/ahenk/plugins/resource-usage/agent_info.py +usr/share/ahenk/plugins/resource-usage/agent_info usr/share/ahenk/plugins/resource-usage/main.py usr/share/ahenk/plugins/resource-usage/resource_info_alert.py usr/share/ahenk/plugins/resource-usage/send_mail.py diff --git a/usr/share/ahenk/base/command/command_runner.py b/usr/share/ahenk/base/command/command_runner.py index 25a1ef6..8165cc4 100644 --- a/usr/share/ahenk/base/command/command_runner.py +++ b/usr/share/ahenk/base/command/command_runner.py @@ -45,8 +45,9 @@ class CommandRunner(object): self.logger.info('Ahenk polkit file not found') else: Util.delete_file(ahenk_policy_file) - Util.write_file(ahenk_policy_file, content) - self.logger.info('Root added ahenk polkit file') + self.logger.info("Delete polkit file") + # Util.write_file(ahenk_policy_file, content) + # self.logger.info('Root added ahenk polkit file') def run_command_from_fifo(self, num, stack): """ docstring""" diff --git a/usr/share/ahenk/base/messaging/messaging.py b/usr/share/ahenk/base/messaging/messaging.py index dca6a1a..caa239d 100644 --- a/usr/share/ahenk/base/messaging/messaging.py +++ b/usr/share/ahenk/base/messaging/messaging.py @@ -78,6 +78,7 @@ class Messaging(object): data['diskFree'] = System.Hardware.Disk.free() data['memory'] = System.Hardware.Memory.total() data['hostname'] = str(System.Os.hostname()) + data['agentVersion'] = str(Util.get_agent_version()) self.logger.debug('USER IP : '+ str(ip)+ ' IPADDRESSES : '+ str(System.Hardware.Network.ip_addresses()).replace('[', '').replace(']', '')) diff --git a/usr/share/ahenk/base/registration/registration.py b/usr/share/ahenk/base/registration/registration.py index 8058e25..cc1fcda 100644 --- a/usr/share/ahenk/base/registration/registration.py +++ b/usr/share/ahenk/base/registration/registration.py @@ -281,6 +281,7 @@ class Registration: 'hardware.baseboard.serialNumber': System.Hardware.BaseBoard.serial_number()[1].replace('\n', '') if System.Hardware.BaseBoard.serial_number()[0] == 0 else 'n/a', 'processor': System.Hardware.Cpu.brand(), + 'agentVersion': Util.get_agent_version(), } return json.dumps(params) diff --git a/usr/share/ahenk/base/registration/scripts/ad.sh b/usr/share/ahenk/base/registration/scripts/ad.sh index 2298d05..413cb06 100644 --- a/usr/share/ahenk/base/registration/scripts/ad.sh +++ b/usr/share/ahenk/base/registration/scripts/ad.sh @@ -7,8 +7,8 @@ ad_host_name=$2 echo "samba-common samba-common/workgroup string WORKGROUP" | sudo debconf-set-selections echo "samba-common samba-common/dhcp boolean false" | sudo debconf-set-selections echo "samba-common samba-common/do_debconf boolean true" | sudo debconf-set-selections -apt-get -y install samba-common - +#apt-get -y install samba-common +DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::="--force-confold" samba-common cat > /root/debconf-krb5.conf < + +from base.plugin.abstract_plugin import AbstractPlugin +import json + + +class AgentInfo(AbstractPlugin): + def __init__(self, data, context): + super(AbstractPlugin, self).__init__() + self.data = data + self.context = context + self.logger = self.get_logger() + self.message_code = self.get_message_code() + + def handle_task(self): + try: + device = "" + self.logger.debug("Gathering resource usage for disk, memory and CPU.") + for part in self.Hardware.Disk.partitions(): + if len(device) != 0: + device += ", " + device = device + part.device + + data = {'System': self.Os.name(), 'Release': self.Os.kernel_release(), + 'agentVersion': self.get_agent_version(), + 'hostname': self.Os.hostname(), + 'ipAddresses': str(self.Hardware.Network.ip_addresses()).replace('[', '').replace(']', ''), + 'os.name': self.Os.name(), + 'osVersion': self.Os.version(), + 'macAddresses': str(self.Hardware.Network.mac_addresses()).replace('[', '').replace(']', ''), + 'hardware.systemDefinitions': self.Hardware.system_definitions(), + 'hardware.monitors': self.Hardware.monitors(), + 'hardware.screens': self.Hardware.screens(), + 'hardware.usbDevices': self.Hardware.usb_devices(), + 'hardware.printers': self.Hardware.printers(), + 'diskTotal': self.Hardware.Disk.total(), + 'diskUsed': self.Hardware.Disk.used(), + 'diskFree': self.Hardware.Disk.free(), + 'memory': self.Hardware.Memory.total(), + 'Device': device, + } + self.logger.debug("Agent info gathered.") + self.context.create_response(code=self.message_code.TASK_PROCESSED.value, + message='Ahenk bilgileri başarıyla güncellendi.', + data=json.dumps(data), content_type=self.get_content_type().APPLICATION_JSON.value) + except Exception as e: + self.logger.error(str(e)) + self.context.create_response(code=self.message_code.TASK_ERROR.value, + message='Ahenk bilgileri güncellenirken hata oluştu: {0}'.format(str(e))) + + +def handle_task(task, context): + plugin = AgentInfo(task, context) + plugin.handle_task()