Duplication data in Zabbix


(Vladimir) #1

Hello.

I have dir '/tmp/dataForZabbix/'
In that dir i have many files, for example consider 1 file: '/tmp/dataForZabbix/testFile'

In this file written lines, simultaneously, every 15 sec:

ZabbixHost: <ZABBIX_HOST>
<ZABBIX_KEY> <ZABBIX_VALUE>
<ZABBIX_KEY> <ZABBIX_VALUE>
<ZABBIX_KEY> <ZABBIX_VALUE>
<ZABBIX_KEY> <ZABBIX_VALUE>

(in each line ZABBIX_KEY differend)

I have input:

input {
    file {
        path => "/tmp/dataForZabbix/*"
        start_position => "end"
    }
}

Filter:

filter {
    if "/tmp/dataForZabbix" in [path] {
         ruby {
            code => "    
                flag = event.get('message').split()
                event.set('[@metadata][zabbix_send]', 'true')
 
                if flag[0] == 'zabbix_key1'
                    event.set('[@metadata][zabbix_host]', IO.readlines(event.get('path'))[-5].split[1])
                    event.set('[@metadata][zabbix_key]', flag[0])
                    event.set('[@metadata][zabbix_value]', flag[1])
                elsif flag[0] == 'zabbix_key2'
                    event.set('[@metadata][zabbix_host]', IO.readlines(event.get('path'))[-5].split[1])
                    event.set('[@metadata][zabbix_key]', flag[0])
                    event.set('[@metadata][zabbix_value]', flag[1])
                elsif flag[0] == 'zabbix_key3'
                    event.set('[@metadata][zabbix_host]', IO.readlines(event.get('path'))[-5].split[1])
                    event.set('[@metadata][zabbix_key]', flag[0])
                    event.set('[@metadata][zabbix_value]', flag[1])
                elsif flag[0] == 'zabbix_key4'
                    event.set('[@metadata][zabbix_host]', IO.readlines(event.get('path'))[-5].split[1])
                    event.set('[@metadata][zabbix_key]', flag[0])
                    event.set('[@metadata][zabbix_value]', flag[1])
                else
                    event.set('[@metadata][zabbix_send]', 'false')
                end
            "
        }
    }
}

(for zabbix_host read [-5] line, bc line recorded simultaneously)

And output:

output {
    if [@metadata][zabbix_send] == "true" {
        zabbix {
            zabbix_server_host => "zabbix.server"
            zabbix_value => "[@metadata][zabbix_value]"
            zabbix_host => "[@metadata][zabbix_host]"
            zabbix_key => "[@metadata][zabbix_key]"
        }
    }
}

But in zabbix I see dublicate data for every key (zabbix_key1(/2/3/4)... WHY?

image


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.