Ad Widget

Collapse

UserParameter for checking the files oldest modify time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zabbixtrainee
    Junior Member
    • Mar 2016
    • 20

    #1

    UserParameter for checking the files oldest modify time

    Hi,

    I am running zabbix 3.0 and the agent on the linux host is 2.0.x

    I need to check if there are files older than one hour in a specific folder.
    Also I need to exclude subfolders from the check and the modify time needs to be in Unix time.

    I did get the job done with this;

    UserParameter=vfs.file.age[*],find $1 -maxdepth 1 -type f -mmin +60 -printf "%TY.%Tm.%Td %TH:%TM:%.2TS %p\n" | sort | head -n 1

    which prints a files modification time and filename, if a file has been modified over an hour ago.
    But the problem with this is that I need this kind of implementation in other hosts as well (with different modify times) and it would be nice that I could use one userparameter for all those.

    So, currently I have userparameter like this;

    UserParameter=vfs.oldest.age[*],find $1 -maxdepth 1 -type f | xargs -i stat -c '%Y' '{}'

    which does the job well, until the folder becomes empty and then the item goes to 'unsupported' because it gets an empty value from the agent.

    Does anybody have any clue about how to modify the command so that even if the folder is empty it returns value '1' for example?

    Many thanks!
    Last edited by Zabbixtrainee; 20-05-2016, 14:13.
  • Zabbixtrainee
    Junior Member
    • Mar 2016
    • 20

    #2
    Hi,

    Soo I tried to compose a script for my task, but as you can probably see it's not very effective. (first time I've done anything like this)
    My goal is to print the command output if the value is anything but an empty value and if the command comes out empty it should just print for example, 0.

    Is there anybody who could help me out with modifying this piece of **** I made?
    Code:
    #!/bin/bash
    
    export fileage 
    fileage=$(find -maxdepth 1 -type f | xargs -i stat -c "%Y" '{}' | sort | head -n 1) 
    if [ $? -eq 0 ]
    then
       echo "0"
    else
       echo "fileage" 
    fi

    Comment

    • Zabbixtrainee
      Junior Member
      • Mar 2016
      • 20

      #3
      if anybody is intrested...

      In case somebody is trying to achieve this aswell, here's the solution I did.
      Put this script to host computer.
      #!/bin/bash

      FOLDER=$1
      now=$(date +%s)
      #Prints out folders oldest modified file's timestamp in unixtime
      fileage=$(find "$FOLDER" -maxdepth 1 -type f -printf "%T@\n" | sort | head -n 1)
      #If folder is empty prints out current time in unixtime
      echo ${fileage:=$now}
      In zabbix conf.
      UserParameter=vfs.oldestfile.age[*],path/to/folder/fileage.bash $1
      PS. this forum is dead.

      Comment

      Working...