Ad Widget

Collapse

How to monitoring REST API - Curl result in Zabbix?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Spectator
    Member
    • Sep 2021
    • 71

    #1

    How to monitoring REST API - Curl result in Zabbix?


    I get the following answer to this curl query in CLI:

    curl http://10.10.10.10:8080/monitoring?type=POOLS

    {"severity": "OK", "checks": [{"severity": "OK", "name": "Fastlane pool count", "description": "0"}, {"severity": "OK" , "name": "Slowlane pool count", "description": "0"}]}

    The severity of these is possible:
    "OK"
    "INACTIVE"
    "WARNING"
    "ERROR"

    How can I monitor this in Zabbix without an external script?
    I'm a beginner at Zabbix. Maybe the webcheck would be suitable for this, but could someone describe it step by step how I could solve it?

    For severities, you may want to match a number and display the number value, e.g. thus:
    OK = 0
    INACTIVE = 1
    WARNING = 2
    ERROR = 3
  • ISiroshtan
    Senior Member
    • Nov 2019
    • 324

    #2
    Hi Mate.

    Use HTTP agent item type to collect said data (as you did not specify Zabbix version, please switch to respective version in documentation to get the most appropriate result).

    Now how to proceed from there is up to you. One option is to drop triggers with regexp() function (prior to 5.4) or find() function(5.4) to find state of each specific pool.

    Alternatively you can add dependent items with item pre-processing(JSON-preprocessing specifically) to have separate item for each pool returned and then have triggers aiming on dependent items.

    To a big extend exact approach would depend on your preference, what is easier for you to read/manage or any extra requirements that might be there.

    Comment

    • Spectator
      Member
      • Sep 2021
      • 71

      #3
      Dear ISiroshtan,

      Thank you for your response!

      Can you help with triggers?
      The results of the REST API can be:
      OK
      INACTIVE
      WARNING
      ERROR
      or something else". This is really a problem for me.

      I made three triggers, they work well:
      {testhost_RESTAPI: http_job_count.last ()} = "ERROR"
      {testhost_RESTAPI: http_job_count.last ()} = "INACTIVE"
      {testhost_RESTAPI: http_job_count.last ()} = "WARNING"

      But how can I create a trigger that alerts me if the value is none of the above (something else) and not "OK"?

      I've tried this but it doesn't work:
      {testhost_RESTAPI: http_job_count.last ()} <> "OK" or {testhost_RESTAPI: http_job_count.last ()} <> "INACTIVE" or {testhost_RESTAPI: http_job_count.last ()} <> "WARNING" or {testhost_RESTAPI: http_job_count. last ()} <> "ERROR"

      Comment

      • ISiroshtan
        Senior Member
        • Nov 2019
        • 324

        #4
        Hi there.

        You seemed to made single tiny mistake in your trigger. You used OR. Just as a reminder: logical OR would result TRUE if ANY of the ORed conditions is True. So with your trigger, any value would result Trigger to fire up.

        Example(for simplicity i will call condition <> "OK" as A, <>"INACTIVE" as B, <> "Error" as C)
        Value is "OK"
        A - False, B - True, C - True. Result is True - trigger fired
        Value is "Error"
        A - True, B - True, C - False. Result is True - trigger fired
        Value is "something_else"
        A - True, B - True, C - True. Result is True - trigger fired

        So just replace "or" by "and" in your trigger expression and it should work.

        Hope it helps!

        Comment

        • Spectator
          Member
          • Sep 2021
          • 71

          #5
          Dear ISiroshtan,

          Thanks for the answer! It really was the case, I fixed it to "and" and it works well.

          Thank you!

          Comment

          Working...