[ZBXNEXT-5184] Regex on global macros Created: 2019 Apr 17 Updated: 2019 Apr 19 Resolved: 2019 Apr 18 |
|
Status: | Closed |
Project: | ZABBIX FEATURE REQUESTS |
Component/s: | Server (S) |
Affects Version/s: | None |
Fix Version/s: | None |
Type: | Change Request | Priority: | Minor |
Reporter: | Twan K. | Assignee: | Andris Zeila |
Resolution: | Duplicate | Votes: | 0 |
Labels: | expressions, macro, macrocontext, trigger | ||
Remaining Estimate: | Not Specified | ||
Time Spent: | Not Specified | ||
Original Estimate: | Not Specified | ||
Environment: |
Redhat VM |
Description |
Scenario I want to add a new trigger for some security reasons. The trigger will be true when a network device configuration has occurred outside of working hours. To make things flexible and not hard-coded in the trigger expression i want to use a global / user macro to indicate the working hour window for this host. This is also easier for my non-technical Zabbix colleagues who find a time format like 09:00-20:00 much easier to work with. Idea
This is where the problem starts. The time() function requires a HHMMSS format. No problem, we can do some nice regex to fix that: {$WORKING_HOURS} = "09:00-20:30h" .time() < {{$WORKING_HOURS}.regsub("^([0-9]{2})[0-9]{2})-([0-9]{2})[0-9]{2})h", "\1\200") or In my example, this would result in: .time() < 090000 or .time() > 203000 The problem This nice piece of Regex won't work because user macro's are not supported with the regsub function (https://www.zabbix.com/documentation/4.0/manual/config/macros/macro_functions#supported_macro_functions) Solution Implement the Regsub functionality on user / global macro's. Workaround For now i use 2 separate macro's ({$WORKING_HOUR_START} and {$WORKING_HOUR_END}). It works but the values are for example 073000 which is much harder to read for people who use Zabbix less than for example 07:30h. Thanks in advance. I understand that this scenario is quite niece and not a deal breaker. However there might be more users who are facing this issue for other purposes. |
Comments |
Comment by Glebs Ivanovskis [ 2019 Apr 17 ] |
|
Comment by Twan K. [ 2019 Apr 18 ] |
Agreed, closing this one and since this is a duplicate of |
Comment by Glebs Ivanovskis [ 2019 Apr 19 ] |
However, ZBXNEXT-2468/ZBXNEXT-2469 seems to be closer to your use case. Zabbix has a concept of time periods. Unfortunately, they are not universally supported, not in trigger expressions at least. |