Ad Widget

Collapse

Compare the today date with a date inside a txt file (Windows Server)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GDT
    Junior Member
    • Jan 2023
    • 9

    #1

    Compare the today date with a date inside a txt file (Windows Server)

    I need to create a check that compares the today date with a date string inside a txt file for a bunch of Windows Servers, this is an example of the TXT file, I need to compare the date in the line which starts with "Expires" :

    Code:
    [Main]
    ComputerID=xxxxx
    HardwareID=xxxxx
    
    [Product.Remote]
    Edition=xxxxx
    Users=xxx
    
    [Support.Remote]
    Expires=2023/02/27 00:00:00​
    
    [Other data]
    Any idea?

    Thank you.​
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    Create an item of the zabbix_agent type and the vfs.file.contents key - gets the contents of the file.
    There are two steps in preprocessing:
    1) regexp ^Expires=(.*)$ and output /1
    2) JavaScript - convert date from string to unixtime (like (new Date("2023/02/27 00:00:00").getTime()/1000)​ ) and compare with now.

    Comment

    • GDT
      Junior Member
      • Jan 2023
      • 9

      #3
      Ok, I grabbed the file with vfs.file.contents key. It's not clear to me how to set up the preprocessing steps: shoud I use "Regular Expression" for first step? And how to set up the javascript?

      Comment

      • GDT
        Junior Member
        • Jan 2023
        • 9

        #4
        I did some progress: I was able to estract date with this key expression: vfs.file.regexp["c:\program files (x86)\tsplus\userdesktop\files\license.lic","^Expi res=(.*)",,,,\1]
        Now I need to convert to epoch (UnixTime) but I don't know how to do it.

        Then I need an alert which triggers warning when the extracted date is under 30 days ad turns critical when 7 days. Do I need a trigger? How can I set it up?

        Comment

        • GDT
          Junior Member
          • Jan 2023
          • 9

          #5
          More progress: I got the extrated date in UnixTime format now I need the compare check.
          Please help me!

          Comment

          • Hamardaban
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • May 2019
            • 2713

            #6
            I meant “Regular Expression” https://www.zabbix.com/documentation.../preprocessing But how did you do it is also fine
            JavaScript - https://www.zabbix.com/documentation...ing/javascript

            The idea was to convert the string to unixtime in the preprocessing step using JS and calculate the difference from now there. Then the item will store exactly the date difference. And based on this difference, you can create simple triggers (with various severity) that respond to raising thresholds.

            Comment

            Working...