2

I have a problem with using a predefined macro in Zabbix. I have defined two macros as following:

{$HOSTNAME}=2008-windows-server {$IPADDRESS}=192.168.1.1

I want to use them in the item name and item key. macro {$HOSTNAME} maps to its value correctly when it is using in the Name section of the item. But when I used the {$IPADDRESS} in the key of that item, it does not convert to the ip address so I get Not Supported error !! I use it like following: getNetFlowProto[{$IPADDRESS},udp]

getNetFlowProto is a UserParameter which I defined in the zabbix_agend.conf file.

Any help appreciated.

Sinai
  • 620
  • 1
  • 14
  • 36
  • If you replace the usermacro with the literal IP address, does it work? If not, that's a problem with your userparameter, not with the macro usage. – Richlv Jun 09 '16 at 12:36
  • Thanks Richlv. yep if I put the ip address it works. But because I want to create a template I need to use macros instead of literal IP address.By the way I am using Zabbix 3.0 – Sinai Jun 09 '16 at 18:00
  • Show your userparameter definition from the agent config file. Could it be that you omitted [*] after the item key ? – Richlv Jun 09 '16 at 22:01
  • Here is the UserParameter I defined: UserParameter=getNetFlowProto[*], /bin/bash /zascripts/getNetFlowInfo.sh $1 $2
    test
    – Sinai Jun 10 '16 at 05:50
  • Dear @Richlv it seems to be working!!! One question: When I put the $HOSTNAME in the name of the Item it immediately changed to its literal value but this is not happening in the Item key!!! but it is working and I can get the result both from zabbix latest data and zabbix_get!!! Perhaps macros are not changed to their literal values?? – Sinai Jun 10 '16 at 06:02
  • i didn't understand that question. what is not happening ? – Richlv Jun 10 '16 at 09:32
  • Dear @Richlv, I said when I use $HOSTNAME in the name of an item, $HOSTNAME is changed to its literal "2008-windows-server" after I save the item and I can see it in the Items section of my host. But when I use the macro $IPADDRESS as I mentioned in my question in the item key, it is not changed to its literal which is "192.168.1.1" after I save the item and I see that item like this "getNetFlowProto[{$IPADDRESS},udp]" in the Item list of my host!! – Sinai Jun 10 '16 at 18:02
  • continue from previous comment: But it works and I can get my desired results through the latest data from zabbix front end and zabbix_get via the shell. I think macros which are used in item key are changed into their correspondent literals in the background and are not shown in the item lists, am I right? I mean when you create an item like getNetFlowProto[{$IPADDRESS},udp] when that item is checked by zabbix, it is changed to 192.168.1.1 in the background but if you see it in the item list you will see it like getNetFlowProto[{$IPADDRESS},udp]. – Sinai Jun 10 '16 at 18:07
  • which zabbix version are you using ? which exact page are you looking at and seeing those results ? – Richlv Jun 11 '16 at 18:50
  • I am using Zabbix 3.0. I can see the result in zabbix from monitoring--> latest data--> key name and, inside shell through zabbix_get command. – Sinai Jun 12 '16 at 15:37
  • ok, i think i finally have a guess at what happened there - will add that as an answer :) – Richlv Jun 12 '16 at 19:40

1 Answers1

1

Based on a rather lengthy communication, looks like the following happened :

  • you used Zabbix macros (variables) in both item name and key
  • you checked that the macro in the item name resolved in the monitoring and configuration section, but the macro in the item key did not resolve (in the configuration section)

That might be caused by the fact that Zabbix does not resolve all macros in all of the configuration pages. That's not very consistent and not clearly documented.

  • you saw the item not working

That could be caused by a typo and possibly by a delay of the configuration cache - as you make changes to items, Zabbix server might still operate with the previous configuration for up to a minute. You might have seen the previous error, but thought that it was generated by the latest configuration. This guess is supported by the fact that it eventually worked you with what was supposedly the same macro.

Richlv
  • 3,954
  • 1
  • 17
  • 21
  • It seems it is as you described @Richlav. The item is working when I use the desired macro like this:getNetFlowProto[[{$IPADDRESS}],udp] and it does not resolve to the literal value but it works. I know I should use HOST.IP and HOST.NAME but these macros uses the host name and ip address which is defined for a host. But I want to use an IP address which is different with the host's main ip address so, I have to create my own macros. – Sinai Jun 15 '16 at 04:55
  • ah, thanks for clarifying - i misread macro names a bit. i removed the suggestion about HOST.IP/NAME as that could have been misleading and was not relevant. – Richlv Jun 15 '16 at 07:44