added software field encoded with base64 and zlib
This commit is contained in:
parent
500567a0b0
commit
c3abb1e6eb
|
|
@ -3,6 +3,7 @@ import json
|
|||
from telegraf.client import TelegrafClient
|
||||
import yaml
|
||||
from logging import log
|
||||
from codecs import encode, decode
|
||||
|
||||
with open('config.yaml') as f:
|
||||
config = yaml.load(f, Loader=yaml.FullLoader)
|
||||
|
|
@ -34,6 +35,11 @@ class Api(object):
|
|||
response = json.load(urllib.urlopen(self.get_request(url)))
|
||||
return response
|
||||
|
||||
def get_software_list(self):
|
||||
url = self.url + 'software'
|
||||
response = json.load(urllib.urlopen(self.get_request(url)))
|
||||
return response
|
||||
|
||||
|
||||
class Agent(object):
|
||||
|
||||
|
|
@ -49,6 +55,7 @@ class Agent(object):
|
|||
self.status = agent_json['status']
|
||||
self.details = self.download_agent_details()
|
||||
self.wmi_details = self.extract_wmi_details()
|
||||
self.software = Software(self.agent_id,self.api).software_json
|
||||
|
||||
def download_agent_details(self):
|
||||
url = self.api.url + 'agents' + '/' + str(self.agent_id)
|
||||
|
|
@ -85,6 +92,9 @@ class Agent(object):
|
|||
new_values = self.prefix_keys(v, k)
|
||||
new_values = self.delete_conflict_characters(new_values)
|
||||
new_dict[k] = new_values
|
||||
# Let's add software as a dict(json) not a string
|
||||
software_string = json.dumps(self.software).encode('utf-8')
|
||||
new_dict['agent_info']['agent_info_software'] = encode(encode(software_string, "zlib"), "base64").decode('ascii')
|
||||
return new_dict
|
||||
|
||||
@staticmethod
|
||||
|
|
@ -117,6 +127,15 @@ class Agent(object):
|
|||
return str(params)
|
||||
|
||||
|
||||
class Software(object):
|
||||
def __init__(self, agent_id, api_object):
|
||||
self.software_json = self.get_json(agent_id, api_object)
|
||||
|
||||
def get_json(self, agent_id, api_object):
|
||||
url = api_object.url + '/' + 'software' + '/' + agent_id
|
||||
response = urllib.urlopen(api_object.get_request(url))
|
||||
return json.load(response)
|
||||
|
||||
api = Api(URL, TOKEN)
|
||||
agent_list = api.get_agent_list()
|
||||
telegraf_client = TelegrafClient(host=config['telegraf']['host'], port=config['telegraf']['port'])
|
||||
|
|
|
|||
Loading…
Reference in New Issue