[ZBXNEXT-5183] Allow simple triggers under item attribute in export files Created: 2019 Apr 17  Updated: 2024 Apr 10  Resolved: 2019 Jun 21

Status: Closed
Project: ZABBIX FEATURE REQUESTS
Component/s: API (A)
Affects Version/s: None
Fix Version/s: 4.4.0alpha1, 4.4 (plan)

Type: New Feature Request Priority: Major
Reporter: Rostislav Palivoda Assignee: Martins Valkovskis
Resolution: Fixed Votes: 1
Labels: Import/Export, triggers
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: XML File subissue-3.xml     File zn5183.patch    
Team: Team D
Sprint: Sprint 51 (Apr 2019), Sprint 52 (May 2019), Sprint 53 (Jun 2019)
Story Points: 5

 Description   

Summary

Currently export files contain information about items and triggers separately, which makes editing of triggers related to an item rather difficult.

It would be great to change structure of export files so that item and simple triggers (i.e. triggers having references only to one item) are on the same page, i.e. as close to each other as possible.

Acceptance

Structure of XML/JSON export files must be modified to allow inclusion of triggers also as item attributes. Trigger prototypes will also be allowed to be attributes of item prototypes, same logic must be applied.

  1. <item> will support an optional attribute <triggers>
  2. Triggers can be placed in old location of <triggers> or under <item><triggers>
  3. When exporting:
    1. Old attribute <triggers> will be used only for complex triggers
    2. Simple triggers must be placed only under <item>
    3. No reference to item must be used, just a simple format:
      1. Before {host:item.func(param)} Now: {func(param)}
  4. When importing:
    1. Simple reference to item is allowed
    2. It is allowed to have a trigger from <item><triggers> without any references to <item> attribute

A few examples

Item definition in XML

<item>
  <name>Modification time of /etc/passwd</name>
  <key>vfs.file.time[/etc/passwd]</key>
  <type>ZABBIX_ACTIVE</type>
  <triggers>
    <trigger>
      <name>Some problem</name>
      <expression>{fuzzytime(1h)}=1</expression>
      <priority>HIGH</priority>
    </trigger>
    <trigger>
    ...
    </trigger>
  </triggers>
</item> 

Business Use Cases

  1. I want to see clearly what triggers are defined for each item and edit them in a text editor if needed.


 Comments   
Comment by richlv [ 2019 Apr 17 ]

While it can be sometimes useful to see which items have triggers defined against them in the XML, that might not be a justified rationale for changing the export format.
It adds complexity in the code that handles this, and complexity = increased chance of bugs. It might be better to have the main focus of the XML files to be great storage for the exported data.

The use case of "I want to see clearly what triggers are defined for each item and edit them in a text editor if needed" would still not be solved, as they could not clearly see any trigger that would reference more than one item.
Actually, such a change would make the XML files harder to read and parse - triggers would be all over the place.

Perhaps the functional goal would be better achieved by ways to display and edit the XML files (assuming editing templates in the UI is not deemed easy enough, which might indicate a need for usability improvements there).

One such way could be a solution to summarise Zabbix export XML contents, here's a quick'n'dirty hack to list items with their corresponding triggers:

template-stats.pl
use strict;
use warnings;

use XML::LibXML;

my $dom = XML::LibXML->load_xml(
    location => $ARGV[0],
);

my %triggers;

foreach my $trigger ($dom->findnodes('/zabbix_export/triggers/trigger')) {
    $triggers{$trigger->findvalue('expression')} = $trigger->findvalue('name');
}

foreach my $template ($dom->findnodes('/zabbix_export/templates/template')) {
    my $templatename = $template->findvalue('./template');
    print "$templatename\n";
    foreach my $item ($template->findnodes('./items/item')) {
        my $name = $item->findvalue('name');
        my $key  = $item->findvalue('key');
        print "\t$name - $key\n";
        my (@itemtriggers) = grep {$_ =~ "\Q$templatename:$key.\E" } keys %triggers;
        foreach my $expression (@itemtriggers) {
            print "\t\t$triggers{$expression}   -   $expression\n";
        }
    }
}

The output would look like this:

> perl template-stats.pl zbx_export_templates-linux.xml
HS Template OS Linux
        Maximum number of opened files - kernel.maxfiles
                Configured max number of opened files is too low on {HOST.NAME}   -   {HS Template OS Linux:kernel.maxfiles.last(0)}<1024
        Maximum number of processes - kernel.maxproc
                Configured max number of processes is too low on {HOST.NAME}   -   {HS Template OS Linux:kernel.maxproc.last(0)}<256
        Memory used by sssd_nss - proc.mem[sssd_nss]
                Memory usage of sssd_nss suspiciously high   -   {HS Template OS Linux:proc.mem[sssd_nss].avg(5m)}>400M
        Number of running processes - proc.num[,,run]
                Too many processes running on {HOST.NAME}   -   {HS Template OS Linux:proc.num[,,run].avg(5m)}>30
        Count of $1 processes running as $2 - proc.num[java,root]
                There are java processes running as root   -   {HS Template OS Linux:proc.num[java,root].max(600)}>0
        Number of processes - proc.num[]
                Too many processes on {HOST.NAME}   -   {HS Template OS Linux:proc.num[].avg(5m)}>{$TRG_PROCNUM_THRESH}
        Host boot time - system.boottime
        Interrupts per second - system.cpu.intr
        Processor load (1 min average per core) - system.cpu.load[percpu,avg1]
                Processor load is too high on {HOST.NAME}   -   {HS Template OS Linux:system.cpu.load[percpu,avg1].avg({$TRG_CPULOAD_PERIOD})}>{$TRG_CPULOAD_THRESH}
                Active Zabbix agent is unreachable for 10 minutes   -   {HS Template OS Linux:system.cpu.load[percpu,avg1].nodata(10m)}=1
        Processor load (5 min average per core) - system.cpu.load[percpu,avg5]
        Processor load (15 min average per core) - system.cpu.load[percpu,avg15]
        Context switches per second - system.cpu.switches
        CPU $2 time - system.cpu.util[,idle]
        CPU $2 time - system.cpu.util[,interrupt]
        CPU $2 time - system.cpu.util[,iowait]
                Disk I/O is overloaded on {HOST.NAME}   -   {HS Template OS Linux:system.cpu.util[,iowait].avg(5m)}>20
        CPU $2 time - system.cpu.util[,nice]
        CPU $2 time - system.cpu.util[,softirq]
        CPU $2 time - system.cpu.util[,steal]
        CPU $2 time - system.cpu.util[,system]
        CPU $2 time - system.cpu.util[,user]
        Host name - system.hostname
                Hostname was changed on {HOST.NAME}   -   {HS Template OS Linux:system.hostname.diff(0)}>0
        Host local time - system.localtime
        Permissions of / - system.run[stat -c "%a" "/"]
                Permissions on / unexpected   -   {HS Template OS Linux:system.run[stat -c "%a" "/"].last()}<>{$PERMISSIONS_ROOT}
        Permissions of /home - system.run[stat -c "%a" "/home"]
                Permissions on /home unexpected   -   {HS Template OS Linux:system.run[stat -c "%a" "/home"].last()}<>755
        Owner of / - system.run[stat -c "%u" "/"]
                Owner of / not root   -   {HS Template OS Linux:system.run[stat -c "%u" "/"].last()}<>0
        Owner of /home - system.run[stat -c "%u" "/home"]
                Owner of /home not root   -   {HS Template OS Linux:system.run[stat -c "%u" "/home"].last()}<>0
        Free swap space - system.swap.size[,free]
        Free swap space in % - system.swap.size[,pfree]
                Lack of free swap space on {HOST.NAME}   -   {HS Template OS Linux:system.swap.size[,pfree].last(0)}<50
        Total swap space - system.swap.size[,total]
        System information - system.uname
                Host information was changed on {HOST.NAME}   -   {HS Template OS Linux:system.uname.diff(0)}>0
        System uptime - system.uptime
                {HOST.NAME} has just been restarted   -   {HS Template OS Linux:system.uptime.change(0)}<0
        Number of logged in users - system.users.num
        Checksum of $1 - vfs.file.cksum[/etc/passwd]
                /etc/passwd has been changed on {HOST.NAME}   -   {HS Template OS Linux:vfs.file.cksum[/etc/passwd].diff(0)}>0
        Last modification time of logrotate status file - vfs.file.time[/var/lib/logrotate.status]
                Logrotate status file not updated for two days   -   {HS Template OS Linux:vfs.file.time[/var/lib/logrotate.status].fuzzytime(2d)}=0
        Available memory - vm.memory.size[available]
                Lack of available memory on server {HOST.NAME}   -   {HS Template OS Linux:vm.memory.size[available].last(0)}<20M
        Total memory - vm.memory.size[total]
Comment by Glebs Ivanovskis [ 2019 Apr 19 ]

I agree with richlv, XML files are for programs. Proposed changes make these programs more complicated. For "Business Use Cases" there is an open source enterprise level GUI tool to edit templates. It's called Zabbix frontend.

Comment by Andrejs Griščenko [ 2019 May 16 ]

Implemented in development branch feature/ZBXNEXT-5183-4.3

Comment by Andrejs Griščenko [ 2019 Jun 13 ]

Implemented in 4.4.0alpha1 (master) ddb3dad1935a61

Comment by Alexander Vladishev [ 2019 Jun 20 ]

Updated documentation:

Comment by richlv [ 2019 Jun 20 ]

Thank you for listing this in the upgrade notes.

While the what'snew section does not explicitly mention formats, it does show an example of XML.
Presumably, the JSON export format changes the same way. If that is correct, it might be worth explicitly mentioning that this affects both XML and JSON export.

Comment by Martins Valkovskis [ 2019 Jun 21 ]

Yes, now both XML and JSON are mentioned in 'what's new' and the upgrade notes. Thanks.

Generated at Fri Apr 26 14:32:36 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.