jeisenbath / ansible-collection-solarwinds-orion

An Ansible collection for managing nodes in Solarwinds Orion
10 stars 1 forks source link

polling_enginein get_least_used_polling_engine\nIndexError: list index out of range #7

Closed Andyjb8 closed 10 months ago

Andyjb8 commented 10 months ago

I get the below "get_least_used_polling_engine\nIndexError: list index out of range error" on with standalone solarwinds server. Here my playbook task:

TASK [Add SNMP node to Solarwinds] ***** task path: /home/andrewba/automation/playbooks/orion_add_node.yml:44 Trying secret FileVaultSecret(filename='/home/andrewba/vault.pass') for vault_id=default Trying secret FileVaultSecret(filename='/home/andrewba/vault.pass') for vault_id=default

ESTABLISH LOCAL CONNECTION FOR USER: root EXEC /bin/sh -c 'echo ~root && sleep 0' EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/runner/.ansible/tmp `"&& mkdir "` echo /home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559 `" && echo ansible-tmp-1692374443.8826163-28-151656626757559="` echo /home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559 `" ) && sleep 0' Trying secret FileVaultSecret(filename='/home/andrewba/vault.pass') for vault_id=default Using module file /usr/share/ansible/collections/ansible_collections/solarwinds/orion/plugins/modules/orion_node.py PUT /home/runner/.ansible/tmp/ansible-local-23cznkubuh/tmpvncihqj4 TO /home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/AnsiballZ_orion_node.py EXEC /bin/sh -c 'chmod u+x /home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/ /home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/AnsiballZ_orion_node.py && sleep 0' EXEC /bin/sh -c '/usr/bin/python3.8 /home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/AnsiballZ_orion_node.py && sleep 0' Trying secret FileVaultSecret(filename='/home/andrewba/vault.pass') for vault_id=default EXEC /bin/sh -c 'rm -f -r /home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/ > /dev/null 2>&1 && sleep 0' The full traceback is: Traceback (most recent call last): File "/home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/AnsiballZ_orion_node.py", line 107, in _ansiballz_main() File "/home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/AnsiballZ_orion_node.py", line 99, in _ansiballz_main invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS) File "/home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/AnsiballZ_orion_node.py", line 47, in invoke_module runpy.run_module(mod_name='ansible_collections.solarwinds.orion.plugins.modules.orion_node', init_globals=dict(_module_fqn='ansible_collections.solarwinds.orion.plugins.modules.orion_node', _modlib_path=modlib_path), File "/usr/lib64/python3.8/runpy.py", line 207, in run_module return _run_module_code(code, init_globals, run_name, mod_spec) File "/usr/lib64/python3.8/runpy.py", line 97, in _run_module_code _run_code(code, mod_globals, init_globals, File "/usr/lib64/python3.8/runpy.py", line 87, in _run_code exec(code, run_globals) File "/tmp/ansible_solarwinds.orion.orion_node_payload_d439z16s/ansible_solarwinds.orion.orion_node_payload.zip/ansible_collections/solarwinds/orion/plugins/modules/orion_node.py", line 531, in File "/tmp/ansible_solarwinds.orion.orion_node_payload_d439z16s/ansible_solarwinds.orion.orion_node_payload.zip/ansible_collections/solarwinds/orion/plugins/modules/orion_node.py", line 494, in main File "/tmp/ansible_solarwinds.orion.orion_node_payload_d439z16s/ansible_solarwinds.orion.orion_node_payload.zip/ansible_collections/solarwinds/orion/plugins/modules/orion_node.py", line 288, in add_node File "/tmp/ansible_solarwinds.orion.orion_node_payload_d439z16s/ansible_solarwinds.orion.orion_node_payload.zip/ansible_collections/solarwinds/orion/plugins/module_utils/orion.py", line 296, in get_least_used_polling_engine IndexError: list index out of range fatal: [RT-01 -> localhost]: FAILED! => { "changed": false, "module_stderr": "Traceback (most recent call last):\n File \"/home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/AnsiballZ_orion_node.py\", line 107, in \n _ansiballz_main()\n File \"/home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/AnsiballZ_orion_node.py\", line 99, in _ansiballz_main\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n File \"/home/runner/.ansible/tmp/ansible-tmp-1692374443.8826163-28-151656626757559/AnsiballZ_orion_node.py\", line 47, in invoke_module\n runpy.run_module(mod_name='ansible_collections.solarwinds.orion.plugins.modules.orion_node', init_globals=dict(_module_fqn='ansible_collections.solarwinds.orion.plugins.modules.orion_node', _modlib_path=modlib_path),\n File \"/usr/lib64/python3.8/runpy.py\", line 207, in run_module\n return _run_module_code(code, init_globals, run_name, mod_spec)\n File \"/usr/lib64/python3.8/runpy.py\", line 97, in _run_module_code\n _run_code(code, mod_globals, init_globals,\n File \"/usr/lib64/python3.8/runpy.py\", line 87, in _run_code\n exec(code, run_globals)\n File \"/tmp/ansible_solarwinds.orion.orion_node_payload_d439z16s/ansible_solarwinds.orion.orion_node_payload.zip/ansible_collections/solarwinds/orion/plugins/modules/orion_node.py\", line 531, in \n File \"/tmp/ansible_solarwinds.orion.orion_node_payload_d439z16s/ansible_solarwinds.orion.orion_node_payload.zip/ansible_collections/solarwinds/orion/plugins/modules/orion_node.py\", line 494, in main\n File \"/tmp/ansible_solarwinds.orion.orion_node_payload_d439z16s/ansible_solarwinds.orion.orion_node_payload.zip/ansible_collections/solarwinds/orion/plugins/modules/orion_node.py\", line 288, in add_node\n File \"/tmp/ansible_solarwinds.orion.orion_node_payload_d439z16s/ansible_solarwinds.orion.orion_node_payload.zip/ansible_collections/solarwinds/orion/plugins/module_utils/orion.py\", line 296, in get_least_used_polling_engine\nIndexError: list index out of range\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1 }
jeisenbath commented 10 months ago

I don't have an environment with only one poller to test on, can you try some things out and provide the results?

I'd like to know what these queries return: SELECT count(EngineId) as NumEngines FROM Orion.Engines SELECT Nodes, EngineID FROM Orion.Engines ORDER BY Nodes asc

I'm probably not doing the logic the best there, but it sounds like the count query is returning something other than 1 (possibly 0?) which puts the index out of range on "queryengines['results'][0]['NumEngines']"

Andyjb8 commented 10 months ago

It looks like it was returning nothing. which explains why I got the "list index out of range" error. I am not sure if this is the best way to do it, but updated to this and it works with one poller, but I haven't tested it with multiple pollers yet.

    def get_least_used_polling_engine(self):
        queryengines = self.swis.query("SELECT count(EngineId) as NumEngines FROM Orion.Engines")
        totalpollingengines = queryengines['results'][0]['NumEngines']

        if totalpollingengines != 1:
            queryleast = self.swis.query("SELECT TOP 1 Nodes, EngineID FROM Orion.Engines WHERE EngineID != 1 ORDER BY Nodes asc")
            if queryleast['results']:  # Check if results are not empty
                leastusedpollingengine = queryleast['results'][0]['EngineID']
                return leastusedpollingengine
            else:
                return "1"  # Replace with an appropriate default EngineID if necessary
        else:
            return "1"  # Default value when there's only one engine
jeisenbath commented 10 months ago

yep this is similar to what I planned to do, just needed you to confirm my suspicions. I guess Orion.Engines just doesn't get populated at all in a single-poller environment. I'll push out a bugfix this weekend, thanks!

jeisenbath commented 10 months ago

I pushed 1.0.3 to update the logic for get_least_used_polling_engine. Converting the count to an int and using a greater than comparison should handle the 0 count. Let me know if this doesn't work for you, tested OK on my multiple poller env.