added agent version info and added agent_info command for updated agent properties

This commit is contained in:
Tuncay ÇOLAK 2020-10-27 14:11:57 +03:00
parent 7f70966cc4
commit 696373d358
4 changed files with 68 additions and 0 deletions

View file

@ -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(']', ''))

View file

@ -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)

View file

@ -488,3 +488,13 @@ class Util:
return pwd.getpwnam(username).pw_gid
except:
raise
@staticmethod
def get_agent_version():
result_code, result, p_err = Util.execute('dpkg -s {} | grep Version'.format("ahenk"))
data = result.split(': ')
if data[0] == 'Version':
version = data[1].strip('\n')
return version
else:
return None

View file

@ -0,0 +1,56 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Author: Tuncay ÇOLAK <tuncay.colak@tubitak.gov.tr>
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()