Ad Widget

Collapse

User Defined Macro in external script discovery rule

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • skorpioskorpio
    Junior Member
    • Jul 2016
    • 3

    #1

    User Defined Macro in external script discovery rule

    Maybe I'm asking too much, but here is what I am trying to do:

    I want to monitor a, or actually multiple, Silicon Dust HDHomerun Prime network tuners. I simply installed their agent (hdhomerun_config) through apt-get, as it's in the repository for Ubuntu (this is an appliance install). I simply created a symbolic link to the program in the default external scripts directory, and it works, I can create simple external script items against the agent directly on the zabbix server.

    So now I want to create a discovery rule using a user defined macro to define the individual tuners within each device. The goal is to create something as a useful starting point for anybody that may want to use zabbix to monitor these devices, and different models have different numbers of tuners.

    Near as I can figure there is really only one way on these devices to get the number of tuners and that is through a /sys/debug command which also returns some other info that is not of interest and returns the tuner numbers but in a longer string than what I actually want, which is simply a number. Here is a bit more detail...

    In the discovery rule I want to send the command

    "hdhomerun_config["{HOST.IP}","get /sys/debug"]

    Which will return

    mem: nbm=776919/6822 npf=40878 dmf=1519968
    loop: pkt=0
    t0: pt=11 cal=-537
    t1: pt=11 cal=-534
    t2: pt=11 cal=-539
    eth: link=1000f


    I only really want the "t?:" lines which I can limit through a simple regular expression, but then I want to assign just the number in the 2nd position of the string into a reusable user defined macro similar to how the filesystem and network discovery rules work so I can just create universal prototypes.

    So the question is how does one chop up a string to assign it to a user defined macro?

    Do I have to predefine the macro someplace other than in the discovery rule filter first in order to use it?

    ...or am I not understanding the concept at all and need to complicate things by writing a script that returns exactly what I need?

    It's not difficult to do, I would just rather not make the process slower on the polling side by introducing a script that calls a program when I could just call the program directly. Also if I can define it all through a template this process becomes as simple as install this, link it here, and use this template.
  • valegator
    Junior Member
    • Jul 2016
    • 18

    #2
    Need to JSON format it

    I am not entirely sure if I got your question right, but the problem I see is that a Low Level Discovery cannot work with such an output. LLD only accepts JSON-formatted usermacro-value pairs. E.g.:
    {
    "data":[

    { "{#NAME}":"loop", "{#PT}":"11" },
    { "{#NAME}":"t2", "{#PT}":"11" },

    ]
    }
    Where you then can filter the value {#NAME} in Zabbix e.g. with regex "^t".

    So you won't come around writing an external script. An example of such a script:

    Comment

    • skorpioskorpio
      Junior Member
      • Jul 2016
      • 3

      #3
      Yea, I wasn't sure whether an external adhered to the same rules as an agent check. Anyway, being a newbie to this forum, my initial posts are delayed by a day so by the time my post actually appeared, I'd written a script already that outputs JSON for the discovery.

      Brings up another question though, how do you define an received item value as a macro? ...or can you? ...and if so can you use that macro as a link label in a map?

      Comment

      • valegator
        Junior Member
        • Jul 2016
        • 18

        #4
        Limits

        Originally posted by skorpioskorpio
        Brings up another question though, how do you define an received item value as a macro? ...and if so can you use that macro as a link label in a map?
        You cannot define a return value of an item as a user-macro. You can however, refer to it as if you are building a trigger expression. You can refer to an item in a map label like this:
        Code:
        {host:key.func(param)}
        LLD macros ({#XXX}) can be used for:
        for item prototypes
        for trigger prototypes
        for graph prototypes
        for host prototypes (supported since 2.2.0)

        Go to https://www.zabbix.com/documentation...ed_by_location and search for "Map labels" to see which macros are supported in Maps.

        Comment

        • skorpioskorpio
          Junior Member
          • Jul 2016
          • 3

          #5
          Yea, I tried that, both as the format that the trigger prototype constructor tool creates and as the format listed in latest data, neither expands, it just labels it literally.

          Seems that even if, perhaps, I've missed something small syntactically, I don't think it'd do what I want even if it did work. Back to the original objective, this is for network attached cable card tuners, and what I was hoping to accomplish was to label a link with the tuned channel, if the tuner from the pool was actually tuned to a channel, which it isn't necessarily. In my configuration I have 4 devices each with 3 tuners each, for a total of 12 which at any one time somewhere between 4 and all of them are signal locked to any one of around 500 channels. These are inturn sending these streams to any one of 6 video renderers. The signals are locked to the source (the channel) and to the recipient (the renderer) and I have all that data via the discovery rule I created, so I have an item data point for the video channel number as well as a listing string (ie: CNN-HD) and I also have a data point to the recipient lock IP (ie: 192.168.1.50 as the IP of the target system).

          What I would really like is to have an Ethernet network link label with the channel name at the target system, and a resolved target name link label at the link representing the source tuner link. This way visually you could see which physical tuner is sending it's stream where and what it is sending.

          In a sense it's kind of like monitoring which WiFi devices are connected to which access point, which I'd also like to do BTW, but in the same vein my access points do not have MIB data as to what devices it is talking to, it only knows MACs so backtracking that to something meaningful is not so easy even if you can get all the data points from controlled sources.... unless there is some way to take one data point and use it as criteria to discover another and then represent that resulting data point somewhere else.

          Comment

          Working...