Ad Widget

Collapse

Macro substitution not working with the API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cdslaughter
    Member
    • Jun 2018
    • 69

    #1

    Macro substitution not working with the API

    I have an odd thing that I noticed in 3.4. when my LLD creates a trigger, I have it automatically populate the URL field for me. In the URL it uses the {HOST.NAME} macro.
    When I send out a notification via the alerts, I see that the URL does get included in the message with the actual hostname (not the text "{HOST.NAME") as expected.
    However, when I pull the same template.url value via the API trigger.get function, it doesn't do the macro substitution and instead gives me the same url, but with "{HOST>NAME}" instead of the actual hostname.

    Is this a bug or functioning as designed?

    Carl
  • cdslaughter
    Member
    • Jun 2018
    • 69

    #2
    Looks like it is the same way in 4.0

    Here is an example of the output.

    I would think that you would want to do the macro substitution as the expression that is provided is just a partial expression and (table row number and formula) and not the full expression as you would see in the GUI

    {
    "jsonrpc": "2.0",
    "result": [
    {
    "triggerid": "14192",
    "expression": "{13852}>300",
    "description": "Too many processes on {HOST.NAME}",
    "url": "http://fo.bar/{HOST.NAME}",
    "status": "0",
    "value": "1",
    "priority": "2",
    "lastchange": "1529686219",
    "comments": "Testing macros here - {HOST.NAME}\r\n{ITEM.VALUE}",
    "error": "",
    "templateid": "0",
    "type": "0",
    "state": "0",
    "flags": "0",
    "recovery_mode": "0",
    "recovery_expression": "",
    "correlation_mode": "0",
    "correlation_tag": "",
    "manual_close": "0",
    "tags": []
    }
    ],
    "id": 0
    }

    Comment

    • cdslaughter
      Member
      • Jun 2018
      • 69

      #3
      I was able to correct this by updating the API code

      Comment

      • cdslaughter
        Member
        • Jun 2018
        • 69

        #4
        I ran an update and lost the fix.. Now I cant find what I had done to correct it

        Comment

        • cdslaughter
          Member
          • Jun 2018
          • 69

          #5
          Found it.

          Here is the fix

          I am running 4.0.3 and have fixed it by modifying the following file as below

          include/classes/api/services/CTrigger.php

          Added to following to the parameters section
          Line 99
          Code:
                                  'expandURL'                                     => true,     // Added so that the API returns translated URLs
          Inserted at line 467 (Between "expandComment" and "expand expression"

          Code:
                          // expandURL                    Added to ensure that the API returns URLs with correct value and not the macro placeholder
                          if (!is_null($options['expandURL']) && $result && array_key_exists('url', reset($result))) {
                                  $result = CMacrosResolverHelper::resolveTriggerUrls($result);
                          }
          Carl

          Comment

          • porkcharsui
            Junior Member
            • May 2012
            • 15

            #6
            Hello Carl,

            I seem to have run into the same problem you have, none off the built in macro's are resolved when using the api. Your solution does not seem to work for me though. Does it still work for you? I'm running zabbix-server-pgsql version 4.0.17 on Debian 10.

            Chris

            Comment

            • cdslaughter
              Member
              • Jun 2018
              • 69

              #7
              Greetings Chris. It was working for me on 4.0 and 4.2 when I made those changes.
              If you want to send me your CTrigger.php file, I can take a look and see if it looks like mine. Currently I am running 4.4

              Carl

              Comment

              • porkcharsui
                Junior Member
                • May 2012
                • 15

                #8
                Hello Carl,
                Thank you for the super quick response. I've attached my current CTrigger.php file (with your changes applied). I hope you can find something wrong in there. Many much thanks for the assistance.
                Chris
                Attached Files

                Comment

                • porkcharsui
                  Junior Member
                  • May 2012
                  • 15

                  #9
                  Figured out what the problem was. I needed to use the "expandDescription": "1" flag.

                  Comment

                  Working...