Skip to content

Commit

Permalink
Add configurable group prefix separator
Browse files Browse the repository at this point in the history
  • Loading branch information
pederhan committed Aug 23, 2024
1 parent 6681dc6 commit 2db685d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Zabbix 7 compatibility
- Configuration option for setting group prefix separator.
- `[zabbix]`
- `prefix_separator`: Separator for group prefixes. Default is `-`.
- Configuration options for each process.
- `[zac.process.garbage_collector]`
- `enabled`: Enable automatic garbage collection.
Expand Down
5 changes: 5 additions & 0 deletions config.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,15 @@ hostgroup_source_prefix = "Source-"
hostgroup_importance_prefix = "Importance-"

# Template group creation
# If we have a host group named `Siteadmin-my-hosts`, ZAC creates a
# template group named `Templates-my-hosts`
# NOTE: will create host groups if enabled on Zabbix <6.2
create_templategroups = true
templategroup_prefix = "Templates-"

# Separator used for group name prefixes
prefix_separator = "-"

extra_siteadmin_hostgroup_prefixes = []

[source_collectors.mysource]
Expand Down
2 changes: 2 additions & 0 deletions zabbix_auto_config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class ZabbixSettings(ConfigBaseModel):
# These groups are not managed by ZAC beyond their creation.
extra_siteadmin_hostgroup_prefixes: Set[str] = set()

prefix_separator: str = "-"

@field_validator("timeout")
@classmethod
def _validate_timeout(cls, v: Optional[int]) -> Optional[int]:
Expand Down
12 changes: 10 additions & 2 deletions zabbix_auto_config/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,7 @@ def create_extra_hostgroups(self, existing_hostgroups: List[HostGroup]) -> None:
mapping = utils.mapping_values_with_prefix(
self.siteadmin_hostgroup_map, # this is copied in the function
prefix=prefix,
separator=self.config.prefix_separator,
)
for hostgroups in mapping.values():
for hostgroup in hostgroups:
Expand Down Expand Up @@ -1658,9 +1659,16 @@ def create_templategroups(self, existing_hostgroups: List[HostGroup]) -> None:
For Zabbix <6.2, host groups are created instead of template groups."""
# Construct a set of all template group names from siteadmin mapping file
# by replacing the host group prefix with the template group prefix
# by replacing the host group prefix with the template group prefix.
# The prefix is determined by the separator defined in the config file.
# If we use the template group prefix `Templates-`, we go from
# `Siteadmin-bob-hosts` to `Templates-bob-hosts`.
tgroups = set(
utils.with_prefix(tg, self.config.templategroup_prefix)
utils.with_prefix(
tg,
self.config.templategroup_prefix,
separator=self.config.prefix_separator,
)
for tg in itertools.chain.from_iterable(
self.siteadmin_hostgroup_map.values()
)
Expand Down

0 comments on commit 2db685d

Please sign in to comment.