Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Macro commands uppercasing the context of context macros, e.g. `{$MACRO:"/var/log"}` becoming `{$MACRO:"/VAR/LOG"}`.
- `unlink_template_from_host --no-clear` clearing items and triggers from hosts instead of only unlinking the templates.
- Dependencies affected by compromised eMudhra/emSign certificates.
- Other vulnerable dependencies not related to eMudhra/emSign certificates.
Expand Down
6 changes: 6 additions & 0 deletions tests/commands/test_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
pytest.param("MY_MACRO", "{$MY_MACRO}"),
pytest.param("mY_maCrO", "{$MY_MACRO}"),
pytest.param("foo123", "{$FOO123}"),
pytest.param(
'vfs.fs.pused.max.crit:"/var/Log"', '{$VFS.FS.PUSED.MAX.CRIT:"/var/Log"}'
),
pytest.param('{$my_macro:"Context"}', '{$MY_MACRO:"Context"}'),
pytest.param("my_macro:Context", "{$MY_MACRO:Context}"),
pytest.param('my_macro:regex:"^/Data"', '{$MY_MACRO:regex:"^/Data"}'),
pytest.param(" ", "", marks=MARK_FAIL),
pytest.param("", "", marks=MARK_FAIL),
pytest.param("{$}", "", marks=MARK_FAIL),
Expand Down
10 changes: 7 additions & 3 deletions zabbix_cli/commands/macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@


def fmt_macro_name(macro: str) -> str:
"""Format macro name for use in a query."""
"""Format macro name for use in a query.

Only the name is uppercased. The context of a context macro
(e.g. `{$MACRO:"context"}`) is case-sensitive and kept as-is.
"""
macro = macro.strip()
if not macro:
# TODO: More specific exception class
raise ZabbixCLIError("Macro name cannot be empty.")
if not macro.isupper():
macro = macro.upper()
name, sep, context = macro.partition(":")
macro = name.upper() + sep + context
if not macro.startswith("{"):
macro = "{" + macro
if not macro.endswith("}"):
Expand Down
Loading