ansible-collections / community.zabbix

Zabbix Ansible modules
http://galaxy.ansible.com/community/zabbix
Other
315 stars 265 forks source link

Can't modify the draw style and color of a link when associated trigger activates #1276

Open RoiCanard opened 3 weeks ago

RoiCanard commented 3 weeks ago
SUMMARY

Even though the documentation gives two arguments "zabbix_trigger_draw_style" and "zabbix_trigger_color", the code only uses static values and doesn't recognize them when given as arguments.

ISSUE TYPE
COMPONENT NAME

Module zabbix_map

ADDITIONAL INFORMATION

When describing the graph, you can add arguments to the created links. For example :

node1 -- node2 [zbx_draw_style="dotted" zbx_color="#FFFFFF" zbx_trigger="hostname:triggername"]

You're also supposed to be able to decide the style and color of the link, should the trigger activate, using "zabbix_trigger_draw_style" and "zabbix_trigger_color". However, the code does not take this into account and does not actually offer this possibility (see community.zabbix/plugins/modules/zabbix_map.py) :

def _get_triggers(self, data):
        triggers = []
        for trigger_definition in [remove_quotes(value) for key, value in data.items() if key.startswith("zbx_trigger")]:
            triggerid = self._get_trigger_id(trigger_definition)
            if triggerid:
                triggers.append({
                    "triggerid": triggerid,
                    "color": self._get_color_hex(remove_quotes(data.get("zbx_trigger_color", "red"))),
                    "drawtype": self._get_link_draw_style_id(remove_quotes(data.get("zbx_trigger_draw_style", "bold"))),
                })
            else:
                self._module.fail_json(msg="Failed to find trigger '%s'" % (trigger_definition))
        return triggers

Normally you would add the arguments like this :

node1 -- node2 [zbx_draw_style="dotted" zbx_color="#FFFFFF" zbx_trigger="hostname:triggername" zbx_trigger_color="#FF0000" zbx_trigger_draw_style="bold"]

This does not verify the presence of the arguments, and even worse, recognizes them as possible triggers. Additionnaly, it is unclear how you're supposed to differenciate between two triggers if you want them to have different colors.