ZABBIX Forums  
  #1  
Old 02-12-2016, 16:27
dontsov dontsov is offline
Junior Member
 
Join Date: Dec 2016
Posts: 4
Unhappy LLD setup for python trappers

I have simple question. As I don't work with Zabbix, it's difficult to undertand the simplest way of LLD setup . There are a lot of additional features shown in manual, that can be wrong for my case.

The problem: 1 have 10 tests in python. I want to monitor test complete time. So, I need to send 10 structures with fields: 'test_title', 'test_time' to Zabbix.

As I have a lot of tests, I think, that using LLD is right way.

Question: How can I do this?

If I setup 1 item manually it works perfect. I see data from zabbix_sender.exe.

I see a lot of manual about LLD, but nothing with user data. There are a lot of terrible examples with "title.type.name[{#SOME_NAME},something_else]" fields.

First of all I can't understand, should I setup Templates | Discovery, or only Host - Discovery rules ?

Thanks for help!
Reply With Quote
  #2  
Old 06-12-2016, 02:41
nobodysu nobodysu is offline
Member
 
Join Date: Sep 2016
Posts: 81
Default

You explicitly need LLD only when you don't know how many item you will have. If you are sure you'll be having 10 items (or less) - you don't necessary need LLD.

For LLD you need to create 'Discovery rule' in you template with, I guess, 'Zabbix agent' type, and assign an item key to it.
https://www.zabbix.com/documentation...650&tok=8cfbbb
Propagate this item in your zabbix agent userparameter config on a host - it must print JSON with desirable items, but not its values.
Then you can create items prototypes based on '#SOME_NAME' macro which will expand in 'something_else' in item's name.
These items also can be gathered with zabbix agent userparameter or sent with zabbix sender as trapper.

Real examples:

https://github.com/grundic/zabbix-disk-performance - separate LLD printing and agent items retrieving.
Code:
{
    "data": [
        {
            "{#DEVICENAME}": "sda",
            "{#DEVICE}": "sda"
        },
        {
            "{#DEVICENAME}": "sda1",
            "{#DEVICE}": "sda1"
        },
        {
            "{#DEVICENAME}": "sda2",
            "{#DEVICE}": "sda2"
        },
        {
            "{#DEVICENAME}": "sda3",
            "{#DEVICE}": "sda3"
        },
        {
            "{#DEVICENAME}": "sdb",
            "{#DEVICE}": "sdb"
        },
        {
            "{#DEVICENAME}": "sdb1",
            "{#DEVICE}": "sdb1"
        },
        {
            "{#DEVICENAME}": "sdb2",
            "{#DEVICE}": "sdb2"
        },
        {
            "{#DEVICENAME}": "sdb3",
            "{#DEVICE}": "sdb3"
        },
        {
            "{#DEVICENAME}": "md127",
            "{#DEVICE}": "md127"
        },
        {
            "{#DEVICENAME}": "md126",
            "{#DEVICE}": "md126"
        },
        {
            "{#DEVICENAME}": "md125",
            "{#DEVICE}": "md125"
        }
    ]
}
https://github.com/nobodysu/zabbix-smartmontools - LLD printing and trapper sending.
Code:
{
    "data": [
        {
            "{#DSERIAL}": "sda"
        },
        {
            "{#DNAME}": "sda"
        },
        {
            "{#DMODEL}": "sda"
        },
        {
            "{#DFIRMWARE}": "sda"
        },
        {
            "{#DCAPACITY}": "sda"
        },
        {
            "{#DSELFTEST}": "sda"
        },
        {
            "{#SMARTID}": "1",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Raw_Read_Error_Rate"
        },
        {
            "{#SMARTID}": "3",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Spin_Up_Time"
        },
        {
            "{#SMARTID}": "4",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Start_Stop_Count"
        },
        {
            "{#DVALUE5}": "sda"
        },
        {
            "{#SMARTID}": "7",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Seek_Error_Rate"
        },
        {
            "{#SMARTID}": "9",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Power_On_Hours"
        },
        {
            "{#SMARTID}": "10",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Spin_Retry_Count"
        },
        {
            "{#SMARTID}": "11",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Calibration_Retry_Count"
        },
        {
            "{#SMARTID}": "12",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Power_Cycle_Count"
        },
        {
            "{#SMARTID}": "192",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Power-Off_Retract_Count"
        },
        {
            "{#SMARTID}": "193",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Load_Cycle_Count"
        },
        {
            "{#SMARTID}": "194",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Temperature_Celsius"
        },
        {
            "{#SMARTID}": "196",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Reallocated_Event_Count"
        },
        {
            "{#DVALUE197}": "sda"
        },
        {
            "{#DVALUE198}": "sda"
        },
        {
            "{#DVALUE199}": "sda"
        },
        {
            "{#SMARTID}": "200",
            "{#DVALUE}": "sda",
            "{#SMARTNAME}": "Multi_Zone_Error_Rate"
        },
        {
            "{#DSERIAL}": "sdb"
        },
        {
            "{#DNAME}": "sdb"
        },
        {
            "{#DMODEL}": "sdb"
        },
        {
            "{#DFIRMWARE}": "sdb"
        },
        {
            "{#DCAPACITY}": "sdb"
        },
        {
            "{#DSELFTEST}": "sdb"
        },
        {
            "{#SMARTID}": "1",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Raw_Read_Error_Rate"
        },
        {
            "{#SMARTID}": "3",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Spin_Up_Time"
        },
        {
            "{#SMARTID}": "4",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Start_Stop_Count"
        },
        {
            "{#DVALUE5}": "sdb"
        },
        {
            "{#SMARTID}": "7",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Seek_Error_Rate"
        },
        {
            "{#SMARTID}": "9",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Power_On_Hours"
        },
        {
            "{#SMARTID}": "10",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Spin_Retry_Count"
        },
        {
            "{#SMARTID}": "11",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Calibration_Retry_Count"
        },
        {
            "{#SMARTID}": "12",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Power_Cycle_Count"
        },
        {
            "{#SMARTID}": "192",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Power-Off_Retract_Count"
        },
        {
            "{#SMARTID}": "193",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Load_Cycle_Count"
        },
        {
            "{#SMARTID}": "194",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Temperature_Celsius"
        },
        {
            "{#SMARTID}": "196",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Reallocated_Event_Count"
        },
        {
            "{#DVALUE197}": "sdb"
        },
        {
            "{#DVALUE198}": "sdb"
        },
        {
            "{#DVALUE199}": "sdb"
        },
        {
            "{#SMARTID}": "200",
            "{#DVALUE}": "sdb",
            "{#SMARTNAME}": "Multi_Zone_Error_Rate"
        }
    ]
}
Reply With Quote
  #3  
Old 06-12-2016, 03:38
dontsov dontsov is offline
Junior Member
 
Join Date: Dec 2016
Posts: 4
Default

Thanks for the answer.

1. Now I have 10 tests, next month I will have 20 tests. I don't want to setup Zabbix after test count changes. LLD was made for this case?


2. I don't use Zabbix agent. I will send data from Python script (or zabbix_sender)

a. create 'Discovery rule' in template with, I guess, 'Zabbix trapper' type, and assign an item key to it. (will this key be in sender JSON?)

b. create items prototypes based on '#SOME_NAME' macro which will expand in 'something_else' in item's name.

c. send 'data' from zabbix_sender:

"data": [
{
"{#TEST_NAME}": "Test1",
"{#TEST_TIME}": "5"
},
{
"{#TEST_NAME}": "Test2",
"{#TEST_TIME}": "10"
}
]


I can't understand what macros I should setup to harvest "test time" value as value for "Test1"

I see only 'key' field in Item prototype.
It should be #TEST_NAME ?
Reply With Quote
  #4  
Old 06-12-2016, 17:29
nobodysu nobodysu is offline
Member
 
Join Date: Sep 2016
Posts: 81
Default

1. That's right.
2. Then you probably need 'External check' type in Discovery:
https://www.zabbix.com/documentation...types/external



something like tests.discovery.py[{HOST.IP},{HOST.HOST}] macro info

{HOST.HOST} is necessary for sender - it will tell for which host the data is.

Lets say you have JSON like:
Code:
"data": [
    {
        "{#TESTNAME}": "Test1",  # you can't submit item's data with LLD, only names!
        "{#TESTNUMBER}": "1"     # keep an eye for the commas (json.dumps will do that for you). 
    },
    {
        "{#TESTNAME}": "Test2",
        "{#TESTNUMBER}": "2"
    }
]
For that you will need one item prototype:
'{#TESTNAME}' with key 'test.number[*]'
which will expand into:
'Test1' with key 'test.number[1]'
'Test2' with key 'test.number[2]'

And for that keys sender can send data (items must be a trapper type). Finally, assign resulted template to a host, zabbix will run specified script on the server with host's arguments (IP and name in zabbix) and sender will send the items data. I have almost exactly your case, you can explore the code.
Reply With Quote
  #5  
Old 06-12-2016, 18:25
dontsov dontsov is offline
Junior Member
 
Join Date: Dec 2016
Posts: 4
Default

2. I mean 'not using Zabbix agent' = I think, that I need't use Zabbix agent, because my data returned from Python script. I have 3 PC with tests that should send data to 1 Zabbix server.

'you can't submit item's data with LLD, only names!' - thanks, it was a problem for understaing.

3. Why I need {#TESTNUMBER}? Can I use test name for item prototype?

4. 'And for that keys sender can send data (items must be a trapper type).'
It means this request?

./zabbix_sender.exe -z 192.168.1.2 -p 10051 -s "HOME_PC" -k "test.number[2]" -o "3"

Thanks a lot for you help!
Reply With Quote
  #6  
Old 07-12-2016, 16:05
nobodysu nobodysu is offline
Member
 
Join Date: Sep 2016
Posts: 81
Default

2. Then agent check is better, its also simpler to implement.
3. You can use single macro in this case. There's a slight correction: not 'test.number[*]' item in prototype, but 'test.number[{#TESTNUMBER}]' (or {#TESTNAME}).
4. That's correct.
Reply With Quote
  #7  
Old 08-12-2016, 17:11
dontsov dontsov is offline
Junior Member
 
Join Date: Dec 2016
Posts: 4
Default

Thank you very much! It works!

The main problem was to understand, that LLD only add item titles to server, but pushing data of items is the same with common items.

Now I try to make 1 graph with all test items.
Reply With Quote
Reply

Tags
lld, trapper

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:54.