Ad Widget

Collapse

Compare string with returns

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bertterbeest
    Junior Member
    • Mar 2017
    • 10

    #1

    Compare string with returns

    Hi all,

    I am running into an issue I cannot seem to solve and would like your help on it.

    I have a robots.txt file on a website that I'd like to check with Zabbix. To that end I have created an item that pulls this file via a custom/userparameter key. So far so good, the itemdata looks like this:
    User-agent: *

    Disallow: /
    Sitemap: https://www.someurlhere.com/sitemap.xml

    Now I'd like to make sure this data stays the same forever (sometimes people accidentally overwrite it) so I have created a trigger like this:
    {Host:robots.check[https://www.someurlhere.com/robots.txt].regexp("User-agent: Disallow: / Sitemap: https://www.someurlhere.com/sitemap.xml")}=0

    But that does not work. So I need to trigger this when the item text is not the same as this static text. I have tried adding returns, escaping characters and many different things, but it does not trigger correctly.

    Can someone point me in the right direction?

    Many thanks in advance.
  • duncan9562
    Member
    • Jan 2017
    • 46

    #2
    Hi,

    You could try using the diff function, as this will compare the two values as strings.

    Code:
    {Host:robots.check[https://www.someurlhere.com/robots.txt].diff()}=0

    Comment

    • bertterbeest
      Junior Member
      • Mar 2017
      • 10

      #3
      Hi Duncan,

      Thanks for your reply. In this case your solution is not workable as diff compares the last value with the previous value. I need to compare the last value with static text, the robots.txt may never ever change.

      Comment

      • bertterbeest
        Junior Member
        • Mar 2017
        • 10

        #4
        Is this simply something that cannot be done? I can't really find anything about it so perhaps it is just impossible.

        Comment

        • duncan9562
          Member
          • Jan 2017
          • 46

          #5
          What about doing:-

          This will compare the last and previous values, so ..... if the differ, it will trigger.
          Code:
          ({Host:robots.check[https://www.someurlhere.com/robots.txt].last()} not {Host:robots.check[https://www.someurlhere.com/robots.txt].prev()}) =1

          Comment

          • bertterbeest
            Junior Member
            • Mar 2017
            • 10

            #6
            The problem with that is that once it is updated (every 30 seconds) the trigger disappears as the new and previous value are the same again. I need to to stay triggered until it reverts back to the original state. For example, I have it configured with abschange() now. That does work, just not in the way I need it to.

            So you are telling me there is no way to check a trigger against static text?

            Comment

            • bertterbeest
              Junior Member
              • Mar 2017
              • 10

              #7
              Nobody can tell me how to check an item against static text then?

              Comment

              • ovas
                Senior Member
                Zabbix Certified Trainer
                Zabbix Certified SpecialistZabbix Certified Professional
                • Apr 2017
                • 138

                #8
                Hello!

                Another option for you:
                Make an md5sum of a correct robots.txt value, then add an SSH check item to download robots.txt from website, make an md5sum out of it and compare to the correct one.
                If there is no difference, return "1". If there is difference, return "0". Store this data in a Zabbix item with necessary trigger upon change.
                Would this meet your requirements?

                Comment

                • bertterbeest
                  Junior Member
                  • Mar 2017
                  • 10

                  #9
                  Ah yes MD5 checksum. Didn't think of that. I did the following now that works:

                  Created a user parameter:
                  UserParameter=robots.check[*], curl -B -s $1 | md5sum | cut -d' ' -f1

                  The item like so:
                  robots.check[https://www.someurlhere.com/robots.txt]

                  And the trigger like this:
                  {Server:robots.check[https://www.someurlhere.com/robots.txt].regexp(f8108907f20e3864314fabd715363eb1)}=0

                  Obviously with an MD5 checksum grabbed from a file that is known to be correct.

                  Many thanks for pointing me in the right direction!

                  Comment

                  Working...