Forum Discussion

jonathan_hillUK's avatar
6 months ago

File Age monitoring - By Type

This may be simple, or not. 

We have a number of SQL servers in our estate which backup via .bak file drops which is then collected by our backup agents. We need to monitor for the age of these files, as on occasion the post backup script in SQL has NOT cleaned up these files, leading to our backup volumes being consumed. 

as the backup name is unique per night, we need to monitor for all backup .bak files, over a certain age, has anyone deployed this form of wildcard monitor (*.bak) and how well did it work?

  • Anonymous's avatar
    Anonymous

    Create a batchscript datasource using active discovery.

    Make the appliesto:
    pathtofiles

    Use the wildvalue as the unique identifier. 

    Use this as both the collection and discovery scripts:

    $hostname = '##SYSTEM.HOSTNAME##'
    $pathToFiles = '##pathtofiles##'
    
    Invoke-Command -ComputerName $hostname -ScriptBlock { 
        $files = Get-ChildItem -Path $pathToFiles -File -Filter '*.bak'
        foreach ($file in $files){
            $wildvalue = $file.Name
            $age = [math]::Round((Get-Date).Subtract($file.CreationTime).TotalHours, 2)
            
            # For discovery
            Write-Host "$wildvalue##$wildvalue"
    
            # For collection
            Write-Host "$wildvalue.age: $age"
        }
    }
    Exit 0

    Change the filter on line 5 if you want to look at other files.

    Make your datapoint called age, use key-value pair, with the key being

    ##WILDVALUE##.age

    Set a property on your device (or group of devices) called pathtofiles where the value is the path to the files you want to include.