pyTenable icon indicating copy to clipboard operation
pyTenable copied to clipboard

limit parameter in the list method in agents API for Nessus not work as expected

Open Barnoux opened this issue 3 years ago • 2 comments

Describe the bug A clear and concise description of what the bug is. The parameter 'limit' of the method 'list' related to agents API in Nessus.agents is not implementd as expected.

In the documentation, when you use the limit parameter to get a list of agents, If you want only one result to return after you made q query you have to put a limit of 1. Today, it's seems that you have one agent per page?

To Reproduce Steps to reproduce the behavior:

  1. Have 5 group of agents with the respective name ['Group_A', 'Group_B', 'Group_C', 'Group_D', 'Group_E'] and one instance of nessus manager,
  2. Have a list 10 agents,
  3. Each agents linked to nessus manager should be assigned to only one group,
  4. execute the code bellow:
from tenable.nessus import Nessus
AGENT_GROUP_NAME = ['Group_A', 'Group_B', 'Group_C', 'Group_D', 'Group_E']
nessus = Nessus(username='username', password='password', url='url')
chosen_groups = [group for group in nessus.agent_groups.list() if group.get('name') in AGENT_GROUP_NAME]
for group in agent_groups:
  filtered_agents = nessus.agents.list(limit=1, filters=[('groups', 'eq', group.get('name'))])
    for agent in filtered_agents:
    print(agent)

Expected behavior After executing the code bellow, i expect to have in the variable filtered_agents: list[dict] a lenght of 1. And it's not the case...

Screenshots Difference from the PyTenable documentation and the API documentation in Nessus Manager from the GUI. image image

System Information:

  • OS: Windows 10 20H2 (19042.1826)
  • Architecture : 64 bit
  • Version: Python 3.9.6
  • Memory: 8G

Barnoux avatar Jul 29 '22 13:07 Barnoux

Limit refers to the number of elements per page. as an iterator object is returned, its referring to the number of elements that are loaded into the iterator before it needs to query the API again. If you turn on the debug logging you'll notice this behavior.

SteveMcGrath avatar Aug 09 '22 14:08 SteveMcGrath

Thank for the answer, do you know how can i do then to have only the exact number of agents based on the limit parameter ? if i still for exemple want only one agent.

Barnoux avatar Aug 09 '22 17:08 Barnoux

With some time, i finally find a solution. I just have to use the break statement to exit the loop when i have the number of agents that i want. I simply use an index and keep the count.

Barnoux avatar Sep 13 '22 09:09 Barnoux

Closing.

aseemsavio avatar Sep 29 '22 09:09 aseemsavio