Added sort option for zabbix_screen module (#56237)
* Added sort option for zabbix_screen module * FIX: sort variable * Added changelog file * Fixed misspelling * Update lib/ansible/modules/monitoring/zabbix/zabbix_screen.py Changed spelling in the documentation Co-Authored-By: flowerysong <junk+github@flowerysong.com>
This commit is contained in:
parent
7b40b569b2
commit
8cf6f56a01
2 changed files with 8 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- "zabbix_screen - added an option to sort hosts on a zabbix screen alphabetically"
|
|
@ -38,6 +38,7 @@ options:
|
|||
- >
|
||||
The available states are: C(present) (default) and C(absent). If the screen already exists, and the state is not C(absent), the screen
|
||||
will be updated as needed.
|
||||
- To sort hosts alphabetically, set the C(sort) option to C(true)
|
||||
required: true
|
||||
|
||||
extends_documentation_fragment:
|
||||
|
@ -150,11 +151,13 @@ class Screen(object):
|
|||
return hostGroup_id
|
||||
|
||||
# get monitored host_id by host_group_id
|
||||
def get_host_ids_by_group_id(self, group_id):
|
||||
def get_host_ids_by_group_id(self, group_id, sort):
|
||||
host_list = self._zapi.host.get({'output': 'extend', 'groupids': group_id, 'monitored_hosts': 1})
|
||||
if len(host_list) < 1:
|
||||
self._module.fail_json(msg="No host in the group.")
|
||||
else:
|
||||
if sort:
|
||||
host_list = sorted(host_list, key=lambda name: name['name'])
|
||||
host_ids = []
|
||||
for i in host_list:
|
||||
host_id = i['hostid']
|
||||
|
@ -348,6 +351,7 @@ def main():
|
|||
screen_name = zabbix_screen['screen_name']
|
||||
screen_id = screen.get_screen_id(screen_name)
|
||||
state = "absent" if "state" in zabbix_screen and zabbix_screen['state'] == "absent" else "present"
|
||||
sort = bool(zabbix_screen.get("sort", False))
|
||||
|
||||
if state == "absent":
|
||||
if screen_id:
|
||||
|
@ -373,7 +377,7 @@ def main():
|
|||
if 'graph_height' in zabbix_screen:
|
||||
graph_height = zabbix_screen['graph_height']
|
||||
host_group_id = screen.get_host_group_id(host_group)
|
||||
hosts = screen.get_host_ids_by_group_id(host_group_id)
|
||||
hosts = screen.get_host_ids_by_group_id(host_group_id, sort)
|
||||
|
||||
screen_item_id_list = []
|
||||
resource_id_list = []
|
||||
|
|
Loading…
Reference in a new issue