diff --git a/src/vpoller/agent.py b/src/vpoller/agent.py index dc66ef0..92c8bd9 100644 --- a/src/vpoller/agent.py +++ b/src/vpoller/agent.py @@ -151,6 +151,29 @@ def _get_object_properties(self, properties, obj_type, obj_property_name, obj_pr return result + def event_latest(self, msg): + """ + Get the latest event registered + + Example client message would be: + + { + "method": "event.latest", + "hostname": "vc01.example.org", + } + + Returns: + The discovered objects in JSON format + + """ + result = { + 'msg': 'Successfully retrieved event', + 'success': 0, + 'result': self.si.content.eventManager.latestEvent.fullFormattedMessage, + } + + return result + def datacenter_discover(self, msg): """ Discover all pyVmomi.vim.Datacenter managed objects diff --git a/src/vpoller/worker.py b/src/vpoller/worker.py index 425383d..1d8a477 100644 --- a/src/vpoller/worker.py +++ b/src/vpoller/worker.py @@ -290,6 +290,10 @@ def process_client_msg(self, msg): # tuple/list of required attributes the message must have in order for this # request to be passed to and processed by the vSphere Agent methods = { + 'event.latest': { + 'method': self.agents[vsphere_host].event_latest, + 'msg_attr': ('method', 'hostname'), + }, 'datacenter.discover': { 'method': self.agents[vsphere_host].datacenter_discover, 'msg_attr': ('method', 'hostname'),