Skip to content

Commit 183d8ff

Browse files
committed
Added convert from <> to # in trigger expressions
1 parent b49a43f commit 183d8ff

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

zabbix-template-convertor

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class FixDiscoveryRuleFilters(ConversionRule):
158158
# check if multi-filter can be downgraded to filter expression
159159
if (
160160
node.find('evaltype').text == '0'
161-
and node.find('formula').text is None
161+
and node.find('formula').text in ('1', None)
162162
):
163163
conditions = node.find('conditions')
164164

@@ -256,12 +256,18 @@ class FixTriggerPrototypesDependencies(ConversionRule):
256256

257257
class FixTriggerOperators(ConversionRule):
258258
"""
259-
Rule to ensure logical operators in trigger expressions s use ampersand (&)
260-
and pipe (|) instead of 'and' and 'or' before 2.4.
259+
Rule to ensure trigger expressions use old style operators before 2.4.
260+
The following conversions are made:
261+
262+
* and -> &
263+
* or -> |
264+
* <> -> #
265+
266+
See: https://www.zabbix.com/documentation/2.2/manual/config/triggers/expression
261267
"""
262268

263269
def __str__(self):
264-
return 'Logical operators in triggers must use ampersand and pipe before 2.4.0'
270+
return 'Triggers must use old style operators before 2.4.0'
265271

266272
def apply(self):
267273
if self.versioncmp('2.4') >= 0:
@@ -276,6 +282,7 @@ class FixTriggerOperators(ConversionRule):
276282
):
277283
node.text = re.sub(r"\s+and\s+", '&', node.text)
278284
node.text = re.sub(r"\s+or\s+", '|', node.text)
285+
node.text = re.sub(r"<>", "#", node.text)
279286

280287
class FixLastTriggerFunction(ConversionRule):
281288
"""
@@ -295,7 +302,7 @@ class FixLastTriggerFunction(ConversionRule):
295302
node is not None
296303
and node.text is not None
297304
):
298-
node.text = re.sub(r"\.last\(\)", '.last(#1)', node.text)
305+
node.text = re.sub(r"\.last\(\)", '.last(0)', node.text)
299306

300307
# read xml template
301308
doc = ET.parse(args.file)

0 commit comments

Comments
 (0)