ZABBIX Forums  
  #1  
Old 30-12-2013, 15:15
Cloud8x4 Cloud8x4 is offline
Junior Member
 
Join Date: Dec 2013
Posts: 8
Default Items return multiple values?

Hi,

I would like to know if it's possible to return multiple values from a custom zabbix check.

Let's say I want to monitor fields A, B and C.

At the moment, I achieve my goals as follows:.

- I create a script for each field "zabbix.get_A.php", "zabbix.get_B.php" and "zabbix.get_C.php". Each script connects to the database and returns 1 zabbix_value.
- For each value, I add a line to zabbix_agentd.conf:
UserParameter=get_A,/usr/local/bin/php /checks/zabbix.get_A.php
UserParameter=get_B,/usr/local/bin/php /checks/zabbix.get_B.php
UserParameter=get_C,/usr/local/bin/php /checks/zabbix.get_C.php

Result: 3 values A, B, C are monitored and I can see actual and historical values in Zabbix. After that I can do anything else I want with the items.


But isn't there a more easy way?

My goal is to be able to view multiple items for different hosts in one overview screen, but I'd like to just configure once: get values from query from host and then the result should be displayed. I don't know if this is possible in Zabbix though ...

Thanks in advance for advice.
Reply With Quote
  #2  
Old 31-12-2013, 02:13
steveboyson steveboyson is offline
Senior Member
 
Join Date: Jul 2013
Location: Germany
Posts: 581
Default

You would do it that way:

1) create your different items, use trapper as type
2) create one item as "control item" which accepts 0|1 (true|false) as return values

Now have a script on your agent(s) which has "control-item" defined as a user parameter and is executable via the zabbix agent.

"control-item" is a script which just returns "true" on success (or "false" on error).
Then it checks all your in 1) defined parameters and sends the results via "zabbix_send" (that is: trapper items) back to your zabbix server.

Basically that means that with one item call (your control-item) you will get back different item values (sent as trapper items).

After that you can do what you want with your items:

"select h.name, i.key, i.lastvalue from items i, hosts h where i.temid = h.itemid and h.name = "$HOST" and i.key_ like "%your_item_keys%"

This, of course, will be a "char" or "text" value item since results are sent in ASCII. "char" is <256 bytes while "text" is ~4096 bytes IIRC.

Recently I've done some more work on that by extracting and aggregating several collected items into HTML tables (that is: HP Proliant SNMP, VMWare ESXi SNMP and API, other stuff).

https://www.netzwerk-aktiv.com/owncl...147db7348f4319
Reply With Quote
  #3  
Old 02-01-2014, 13:38
Cloud8x4 Cloud8x4 is offline
Junior Member
 
Join Date: Dec 2013
Posts: 8
Default

Hi Steveboyson,

Thanks for your reply.

Your solution seems like an alternative way to display host data in Zabbix.

It is similar to the solution in my first post that:
  • you have to define an item for each value
  • you have to create a script for each user parameter
  • The result is that different items (values) are being monitored in Zabbix and you can do whatever you want with them after that.
The difference is that my solution uses php calls for each item of type Zabbix agent; your solution calls a script 'control-item' which then users zabbix-send to send values to trapper items in Zabbix.

Please correct me if I'm wrong but this doesn't seem like a faster way to get the desired result though it may be a better solution.


My goal is to be able to view the current status for different values on a host, like in the link you posted but I'd like it if I don't have to create 10 scripts for 10 items.

My ideal solution would be if I could create 1 script which returns 1 resultset (array) of x values; then Zabbix can take care of the rest. So the steps to take would be:
  • Create item:
    • A php script is called which gets values from the database and returns the values (comma separated for example)
    • Description: 'example_resultset'
    • type: 'Zabbix-agent'
    • type of information: resultset (array?)
    • data type: string
  • Create php script 'zabbix.example_resultset'
    • connect to database
    • select concat(a,b,c,d,e,f,g,h) from table LIMIT 1;
    • return values in a string (assuming Zabbix requires a string though any return type is ok as long as Zabbix understands).
  • Create Zabbix screen
    • show resultset for each host

So I think I can summarise my question in a different way: is it possible in an easy way to zend a resultset (array) and display the resultset in Zabbix without creating an item for each returned field?


I 'm still going to try your solution though; probably things will become more clear after that.

Again, thanks for any advice / suggestions.
Reply With Quote
  #4  
Old 03-01-2014, 01:15
steveboyson steveboyson is offline
Senior Member
 
Join Date: Jul 2013
Location: Germany
Posts: 581
Default

What I've seen so far is that zabbix always expects ONE (and exactly ONE) result per item.

There is only one exception: LLD (discovery items).
But these do not deliver item values but macros to create new item definitions (in zabbix slang: they are "item prototypes").

Means, it will not help you very much in your approach.

Surely you can use LLD to "autocreate" your different items. But again, you need to run these auto-defined items "one-per-one" to get back the proper results into the corresponding database fields (unless you feed the database directly which I would strictly not recommend as you will quite definitely break things more or less badly).
Reply With Quote
  #5  
Old 03-01-2014, 01:23
steveboyson steveboyson is offline
Senior Member
 
Join Date: Jul 2013
Location: Germany
Posts: 581
Default

Oh, and you don't have to create 10 scripts for 10 items. You will just have 10 "item fetches" for 10 items. They all written into the database and you can "extract" their lastvalue via one (specific and elaborate) script.

You may want to have a look here:
https://www.netzwerk-aktiv.com/owncl...5a293890ebbb03
Reply With Quote
  #6  
Old 03-01-2014, 15:48
Cloud8x4 Cloud8x4 is offline
Junior Member
 
Join Date: Dec 2013
Posts: 8
Default

I tried your solution. A big improvement compared to the solution from my first post is, like you said, that I can now fetch all my values together and zend them to Zabbix. Instead of x times executing the same query for x fields in the same table (or some query), now I execute the query only once and then send the different fields to Zabbix. For large queries this is ofcourse very good for the performance.

Thanks again.
Reply With Quote
  #7  
Old 03-01-2014, 15:52
steveboyson steveboyson is offline
Senior Member
 
Join Date: Jul 2013
Location: Germany
Posts: 581
Default

Cheers, U R welcome.
Reply With Quote
  #8  
Old 13-03-2014, 16:29
gyldenro gyldenro is offline
Junior Member
 
Join Date: Mar 2014
Posts: 2
Default I am looking for a similar solution

Quote:
Originally Posted by steveboyson View Post
Oh, and you don't have to create 10 scripts for 10 items. You will just have 10 "item fetches" for 10 items. They all written into the database and you can "extract" their lastvalue via one (specific and elaborate) script
Your link is no longer active, any change you would share your knowledge once more. Thanks in advance for sharing your knowledge.
Reply With Quote
  #9  
Old 13-03-2014, 16:57
steveboyson steveboyson is offline
Senior Member
 
Join Date: Jul 2013
Location: Germany
Posts: 581
Default

What *exactly* are you interested in?
Im not too sure what scripts I had in the owncloud. Pls. describe what you're trying to achive.
Reply With Quote
  #10  
Old 13-03-2014, 23:18
gyldenro gyldenro is offline
Junior Member
 
Join Date: Mar 2014
Posts: 2
Default

I have the zabbix agent run a script, that take a while to run, it will result in multiple interesting numbers (actually 3 different values).

So i would want to run the script and return 3 values that can be graphed in zabbix.

From the context of the thread, it looked to me as that was something similar that you had responded to in this thread.
Reply With Quote
Reply

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 22:19.