Skip to content

Commit

Permalink
New function to recover active checks
Browse files Browse the repository at this point in the history
The new function get_active_checks() return a list of active items that
a Zabbix Agent should execute.
  • Loading branch information
adrianlzt committed Jan 25, 2019
1 parent 72ac80f commit 99bee1d
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pyzabbix/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@ def _chunk_send(self, metrics):
"""
messages = self._create_messages(metrics)
request = self._create_request(messages)

return self._send_request(request)

def _send_request(self, request):
"""Send the formated zabbix request to zabbix server.
:type request: str
:param request: formatted zabbix request
:rtype: str
:return: Response from Zabbix Server
"""
packet = self._create_packet(request)

for host_addr in self.zabbix_uri:
Expand Down Expand Up @@ -435,3 +447,22 @@ def send(self, metrics):
for m in range(0, len(metrics), self.chunk_size):
result.parse(self._chunk_send(metrics[m:m + self.chunk_size]))
return result

def get_active_checks(self, host):
"""Send a request to retrieve active checks
Format of returned items:
{'key': 'KEYITEM', 'delay': 30, 'lastlogsize': 0, 'mtime': 0}
:type host: string
:param host: host name to retrive active checks
:rtype: list
:return: List of active checks
"""
request = '{{"request":"active checks","host":"{host}"}}'.format(host=host)
request = request.encode("utf-8")
logger.debug('Request: %s', request)

response = self._send_request(request)
return response.get("data")

0 comments on commit 99bee1d

Please sign in to comment.