Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ta agents polling #116

Merged
merged 3 commits into from
Aug 31, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improving pagination method
  • Loading branch information
root authored and root committed Jun 20, 2018
commit c5933c23c9eaae365689a6dbe20f6ce6e6d6191c
22 changes: 11 additions & 11 deletions TA-wazuh-api-connector/bin/input_module_wazuh_api_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ def collect_events(helper, ew):
opt_base_url = helper.get_arg('base_url')
auth = requests.auth.HTTPBasicAuth(opt_username, opt_password)
verify = False

request = requests.get(opt_base_url + '/agents?limit=0', auth=auth, verify=verify)
total_agents = json.loads(request.text)["data"]["totalItems"]
limit = 10
limit = 500
offset = 0

request = requests.get(opt_base_url + '/agents?offset='+str(offset)+'&limit=' + str(limit), auth=auth, verify=verify)
agents = json.loads(request.text)["data"]["items"]
total_agents = json.loads(request.text)["data"]["totalItems"]

for agent in agents:
event = helper.new_event(source=helper.get_input_type(), index=helper.get_output_index(), sourcetype=helper.get_sourcetype(), data=json.dumps(agent))
ew.write_event(event)
while (offset <= total_agents-limit):
offset+=limit
request = requests.get(opt_base_url + '/agents?offset='+str(offset)+'&limit=' + str(limit), auth=auth, verify=verify)
agents = json.loads(request.text)["data"]["items"]
for agent in agents:
event = helper.new_event(source=helper.get_input_type(), index=helper.get_output_index(), sourcetype=helper.get_sourcetype(), data=json.dumps(agent))
ew.write_event(event)
if (total_agents > limit):
while (offset <= total_agents-limit):
offset+=limit
request = requests.get(opt_base_url + '/agents?offset='+str(offset)+'&limit=' + str(limit), auth=auth, verify=verify)
agents = json.loads(request.text)["data"]["items"]
for agent in agents:
event = helper.new_event(source=helper.get_input_type(), index=helper.get_output_index(), sourcetype=helper.get_sourcetype(), data=json.dumps(agent))
ew.write_event(event)