Ad Widget

Collapse

check for existence of a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • veroli
    Junior Member
    • Mar 2009
    • 7

    #1

    check for existence of a file

    Am happily using zabbix to monitor a very large windows network.
    I've got event log monitoring working but now i need to check for the existence of files in 3 folders. I want to create a trigger that goes to "on" when files are detected in a folder. If all is well there shouldn't be any files in these folders. I've searched around but cant seem to find anything definitive. I'm pretty sure zabbix can do this can anyone help

    regards
    dan
  • jroberson
    Senior Member
    • May 2008
    • 124

    #2
    Sounds like you need a script to check for the existence of files and then return a value. Then just use a trigger to check that items value. If it is "1" then at least one of those files are there. If it is a Windows host you can use the below code (nothing fancy). If it is another OS you can easily create your own. Then either use the system.run key or create a user parameter in the config file. You can find lots of examples in the forums for that.

    Code:
    'Test for empty folders
    
    Dim file(3) 'Put number of files in the ( )
    file(0)="C:\TestFolder1"
    file(1)="C:\TestFolder2"
    file(2)="C:\TestFolder3"
    '...
    'file(x)="Path" 
    '"x is Number of files - 1"
    
    Dim fso, folder
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    Folder_Contents = 0
    
    for i=0 to UBound(file)-1
    	Set folder = fso.GetFolder(file(i))
    	If folder.Files.Count + folder.SubFolders.Count > 0 Then
    		Folder_Contents = 1
    	end if
    Next
    
    WScript.Stdout.WriteLine Folder_Contents
    
    Set folder = Nothing
    Set fso = Nothing
    PS: if you use a Windows host, be sure to execute it with the command "cscript Script_Name.vbs //NOLOGO" or you may have problems.

    Comment

    • veroli
      Junior Member
      • Mar 2009
      • 7

      #3
      thanks this looks ideal and i've tested the script and it works fine.
      Do i need to write the folder contents variable out to a file and have zabbix check that or can i do it some other way. Also i guess i'll need to have the script run as a scheduled task ?

      thanks again
      Dan

      Comment

      • veroli
        Junior Member
        • Mar 2009
        • 7

        #4
        ok i worked it out amazing what a little trial and error can do.
        set up a user defined parameter in the agent. set up an item based on it returning an integer and created the trigger off that. It works great, thanks very much for your help and the script

        Dan

        Comment

        Working...