saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.11k stars 5.47k forks source link

[FEATURE REQUEST] Allow appending instead of replacing zabbix templates #60434

Open colttt opened 3 years ago

colttt commented 3 years ago

Is your feature request related to a problem? Please describe. It would be very nice if we can add the possibility to just add a new template to zabbix in the module states.zabbix_host. Currently, it is not possible to just add a new template, I must call all templates.

Describe the solution you'd like We've a state that install the zabbix-agent and create this host in zabbix and add a template (mostly the Linux-Template) and if this server also have additional services like apache, we call also the apache-install-state which also add the Zabbix-Template "App Apache", but instead of using just assign the new template like:

apache_template_to_host:
  zabbix_host.assign_templates:
    - host: {{ grains['host'] }}
    - templates:
      - "Template App Apache by Zabbix agent"

we must call all templates that we want:

apache_template_to_host:
  zabbix_host.assign_templates:
    - host: {{ grains['host'] }}
    - templates:
      - "Template App Apache by Zabbix agent"
      - "Template OS Linux"

the state could be called the current templates and in the second call it could be add the current templates + new templates

OrangeDog commented 3 years ago

Can you edit the title to e.g. [FEATURE REQUEST] Allow appending instead of replacing zabbix templates

In the meantime, you can build the list of templates with jinja and set them with a single state. It could be done with merged/aggregate pillar data or map.jinja.

I'm not sure if there's a way to accumulate values from other states to be used in this state. Perhaps something with slots.

colttt commented 3 years ago

I'm not sure if there's a way to accumulate values from other states to be used in this state.

It's not need, it's "just" need more logic, we can check via API what of templates are already assigned and if it missing just add this

I'm not sure if there's a way to accumulate values from other states to be used in this state.

OK but then I should check if it somehow defined in the top.sls, etc.. I prefer the logic per state ;-)

OrangeDog commented 3 years ago

However, with this feature either you can't easily remove unused templates, or you'd be removing and re-adding every run.

OrangeDog commented 3 years ago

we can check via API what of templates are already assigned

No, I meant a way for the apache state to add to a list that the zabbix state can then use to set all the templates as now.

OrangeDog commented 3 years ago

It looks like there is a way. The list could be stored via data or the cache, and retrieved with a slot.

reedacus25 commented 2 years ago

I don't have much to add to this, other than that I too would love to see states.zabbix_host.assign_templates change from a "clean inventory" method to an "append" method.

I only mention clean inventory specifically, because that is how states.zabbix_host.present works, with the inventory_clean option.

inventory_clean -- Optional - Boolean value that selects if the current inventory will be cleaned and overwritten by the declared inventory list (True); or if the inventory will be kept and only updated with inventory list contents (False). Defaults to True

I think that if states.zabbix_host.assign_templates were able to have the inventory_clean option added, that it would be able to maintain current functionality, as well as add the append functionality to those that want it, myself being one of those.

Ie I have a zabbix-agent state that installs and configures the agent and adds the host and assigns "base level" templates, but then I have other states that come along after and configure different applications based on other conditions, and what I would ideally like is for the application states to be able to handle setting up the monitoring for themselves at the same time as the application bootstrap.

I know its not a PR, but I figured that keeping the discussion alive and giving it direction might be useful.

OrangeDog commented 1 year ago

@nicolas-janzen that's a completely different system