Skip to content

Commit

Permalink
fixes for linter and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Lathrop committed May 9, 2024
1 parent 7bb6132 commit 9a418eb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 27 deletions.
16 changes: 9 additions & 7 deletions plugins/modules/zabbix_discoveryrule.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@
description:
- Parameters to create/update discovery rule with.
- Required if state is "present".
- Parameters as defined in: https://www.zabbix.com/documentation/current/en/manual/api/reference/discoveryrule/object
- Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/discoveryrule/object
- Additionally supported parameters are below
required: false
type: dict
suboptions:
key:
description:
- LLD rule key.
- LLD rule key.
- Alias for "key_" in API docs
required: false
type: str
Expand All @@ -75,7 +75,7 @@
choices: [ "enabled", "disabled" ]
enabled:
description:
- Status of the LLD rule.
- Status of the LLD rule.
- Overrides "status" in API docs
required: false
type: bool
Expand Down Expand Up @@ -107,7 +107,7 @@
preprocessing:
description:
- discovery rules preprocessing options.
- Parameters as defined in: https://www.zabbix.com/documentation/current/en/manual/api/reference/discoveryrule/object#lld-rule-preprocessing
- Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/discoveryrule/object#lld-rule-preprocessing
- Additionally supported parameters are below
required: false
type: list
Expand Down Expand Up @@ -252,6 +252,7 @@
from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


class Discoveryrule(ZabbixBase):
ITEM_TYPES = {'zabbix_agent': 0,
'zabbix_trapper': 2,
Expand Down Expand Up @@ -296,7 +297,7 @@ class Discoveryrule(ZabbixBase):
'set_custom_error_message': 3}

def get_hosts_templates(self, host_name, template_name):
if host_name != None:
if host_name is not None:
try:
return self._zapi.host.get({"filter": {"host": host_name}})
except Exception as e:
Expand All @@ -307,9 +308,8 @@ def get_hosts_templates(self, host_name, template_name):
except Exception as e:
self._module.fail_json(msg="Failed to get template: %s" % e)


def get_discoveryrules(self, discoveryrule_name, host_name, template_name):
if host_name != None:
if host_name is not None:
host = host_name
else:
host = template_name
Expand Down Expand Up @@ -387,6 +387,7 @@ def delete_discoveryrule(self, discoveryrule_id):
self._module.fail_json(msg="Failed to delete discoveryrule: %s" % e)
return results


def main():
argument_spec = zabbix_utils.zabbix_common_argument_spec()
argument_spec.update(dict(
Expand Down Expand Up @@ -454,5 +455,6 @@ def main():
changed = True
module.exit_json(changed=changed, result=results)


if __name__ == '__main__':
main()
10 changes: 6 additions & 4 deletions plugins/modules/zabbix_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
description:
- Parameters to create/update item with.
- Required if state is "present".
- Parameters as defined in: https://www.zabbix.com/documentation/current/en/manual/api/reference/item/object
- Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/item/object
- Additionally supported parameters are below
required: false
type: dict
Expand Down Expand Up @@ -119,7 +119,7 @@
preprocessing:
description:
- Item preprocessing options.
- Parameters as defined in: https://www.zabbix.com/documentation/current/en/manual/api/reference/item/object#item-preprocessing
- Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/item/object#item-preprocessing
- Additionally supported parameters are below
required: false
type: list
Expand Down Expand Up @@ -281,6 +281,7 @@
from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


class Item(ZabbixBase):
ITEM_TYPES = {'zabbix_agent': 0,
'zabbix_trapper': 2,
Expand Down Expand Up @@ -349,7 +350,7 @@ class Item(ZabbixBase):
'set_custom_error_message': 3}

def get_hosts_templates(self, host_name, template_name):
if host_name != None:
if host_name is not None:
try:
return self._zapi.host.get({"filter": {"host": host_name}})
except Exception as e:
Expand All @@ -361,7 +362,7 @@ def get_hosts_templates(self, host_name, template_name):
self._module.fail_json(msg="Failed to get template: %s" % e)

def get_items(self, item_name, host_name, template_name):
if host_name != None:
if host_name is not None:
host = host_name
else:
host = template_name
Expand Down Expand Up @@ -442,6 +443,7 @@ def delete_item(self, item_id):
self._module.fail_json(msg="Failed to delete item: %s" % e)
return results


def main():
argument_spec = zabbix_utils.zabbix_common_argument_spec()
argument_spec.update(dict(
Expand Down
16 changes: 9 additions & 7 deletions plugins/modules/zabbix_itemprototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
description:
- Parameters to create/update item prototype with.
- Required if state is "present".
- Parameters as defined in: https://www.zabbix.com/documentation/current/en/manual/api/reference/itemprototype/object
- Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/itemprototype/object
- Additionally supported parameters are below
required: false
type: dict
Expand Down Expand Up @@ -124,7 +124,7 @@
preprocessing:
description:
- Item preprocessing options.
- Parameters as defined in: https://www.zabbix.com/documentation/current/en/manual/api/reference/itemprototype/object#item-prototype-preprocessing
- Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/itemprototype/object#item-prototype-preprocessing
- Additionally supported parameters are below
required: false
type: list
Expand Down Expand Up @@ -293,6 +293,7 @@
from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


class Itemprototype(ZabbixBase):
ITEM_TYPES = {'zabbix_agent': 0,
'zabbix_trapper': 2,
Expand Down Expand Up @@ -361,7 +362,7 @@ class Itemprototype(ZabbixBase):
'set_custom_error_message': 3}

def get_hosts_templates(self, host_name, template_name):
if host_name != None:
if host_name is not None:
try:
return self._zapi.host.get({"filter": {"host": host_name}})
except Exception as e:
Expand All @@ -372,9 +373,8 @@ def get_hosts_templates(self, host_name, template_name):
except Exception as e:
self._module.fail_json(msg="Failed to get template: %s" % e)


def get_discoveryrules(self, discoveryrule_name, host_name, template_name):
if host_name != None:
if host_name is not None:
host = host_name
else:
host = template_name
Expand All @@ -386,7 +386,7 @@ def get_discoveryrules(self, discoveryrule_name, host_name, template_name):
return discoveryrules

def get_itemprototypes(self, itemprototype_name, discoveryrule_name, host_name, template_name):
if host_name != None:
if host_name is not None:
host = host_name
else:
host = template_name
Expand All @@ -396,7 +396,7 @@ def get_itemprototypes(self, itemprototype_name, discoveryrule_name, host_name,
rule_ids.append(d['itemid'])
itemprototypes = []
try:
itemprototypes = self._zapi.itemprototype.get({'filter': {'name': itemprototype_name, 'host': host, 'discoveryids': rule_ids }})
itemprototypes = self._zapi.itemprototype.get({'filter': {'name': itemprototype_name, 'host': host, 'discoveryids': rule_ids}})
except Exception as e:
self._module.fail_json(msg="Failed to get item: %s" % e)
return itemprototypes
Expand Down Expand Up @@ -464,6 +464,7 @@ def delete_itemprototype(self, itemprototype_id):
self._module.fail_json(msg="Failed to delete itemprototype: %s" % e)
return results


def main():
argument_spec = zabbix_utils.zabbix_common_argument_spec()
argument_spec.update(dict(
Expand Down Expand Up @@ -534,5 +535,6 @@ def main():
changed = True
module.exit_json(changed=changed, result=results)


if __name__ == '__main__':
main()
11 changes: 7 additions & 4 deletions plugins/modules/zabbix_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
description:
- Parameters to create/update trigger with.
- Required if state is "present".
- Parameters as defined in: https://www.zabbix.com/documentation/current/en/manual/api/reference/trigger/object
- Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/trigger/object
- Additionally supported parameters are below.
required: false
type: dict
Expand Down Expand Up @@ -251,6 +251,7 @@
from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


class Trigger(ZabbixBase):

PRIORITY_TYPES = {'not_classified': 0,
Expand All @@ -265,7 +266,7 @@ class Trigger(ZabbixBase):
'none': 2}

def get_triggers(self, trigger_name, host_name, template_name):
if host_name != None:
if host_name is not None:
host = host_name
else:
host = template_name
Expand All @@ -278,7 +279,7 @@ def get_triggers(self, trigger_name, host_name, template_name):

def sanitize_params(self, name, params, desc=None, dependencies=None):
params['description'] = name
if desc != None:
if desc is not None:
params['comments'] = desc
if 'severity' in params:
params['priority'] = params['severity']
Expand Down Expand Up @@ -323,7 +324,7 @@ def sanitize_params(self, name, params, desc=None, dependencies=None):
params['manual_close'] = 1
else:
params['manual_close'] = 0
if dependencies != None:
if dependencies is not None:
params['dependencies'] = []
for dependency in dependencies:
host_name = None
Expand Down Expand Up @@ -372,6 +373,7 @@ def delete_trigger(self, trigger_id):
self._module.fail_json(msg="Failed to delete trigger: %s" % e)
return results


def main():
argument_spec = zabbix_utils.zabbix_common_argument_spec()
argument_spec.update(dict(
Expand Down Expand Up @@ -436,5 +438,6 @@ def main():
changed = True
module.exit_json(changed=changed, result=results)


if __name__ == '__main__':
main()
12 changes: 7 additions & 5 deletions plugins/modules/zabbix_triggerprototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
description:
- Parameters to create/update trigger prototype with.
- Required if state is "present".
- Parameters as defined in: https://www.zabbix.com/documentation/current/en/manual/api/reference/triggerprototype/object
- Parameters as defined at https://www.zabbix.com/documentation/current/en/manual/api/reference/triggerprototype/object
- Additionally supported parameters are below.
required: false
type: dict
Expand Down Expand Up @@ -255,6 +255,7 @@
from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils


class Triggerprototype(ZabbixBase):

PRIORITY_TYPES = {'not_classified': 0,
Expand All @@ -269,7 +270,7 @@ class Triggerprototype(ZabbixBase):
'none': 2}

def get_triggerprototypes(self, triggerprototype_name, host_name, template_name):
if host_name != None:
if host_name is not None:
host = host_name
else:
host = template_name
Expand All @@ -282,7 +283,7 @@ def get_triggerprototypes(self, triggerprototype_name, host_name, template_name)

def sanitize_params(self, name, params, desc=None, dependencies=None):
params['description'] = name
if desc != None:
if desc is not None:
params['comments'] = desc
if 'severity' in params:
params['priority'] = params['severity']
Expand Down Expand Up @@ -327,7 +328,7 @@ def sanitize_params(self, name, params, desc=None, dependencies=None):
params['manual_close'] = 1
else:
params['manual_close'] = 0
if dependencies != None:
if dependencies is not None:
params['dependencies'] = []
for dependency in dependencies:
host_name = None
Expand All @@ -342,7 +343,6 @@ def sanitize_params(self, name, params, desc=None, dependencies=None):
for trigger in triggers:
params['dependencies'].append({'triggerid': trigger['triggerid']})


def add_triggerprototype(self, params):
if self._module.check_mode:
self._module.exit_json(changed=True)
Expand Down Expand Up @@ -377,6 +377,7 @@ def delete_triggerprototype(self, trigger_id):
self._module.fail_json(msg="Failed to delete triggerprototype: %s" % e)
return results


def main():
argument_spec = zabbix_utils.zabbix_common_argument_spec()
argument_spec.update(dict(
Expand Down Expand Up @@ -441,5 +442,6 @@ def main():
changed = True
module.exit_json(changed=changed, result=results)


if __name__ == '__main__':
main()

0 comments on commit 9a418eb

Please sign in to comment.