Windows Folder Monitorng -SCOM

Fadil Ck 381 Reputation points
2022-11-22T06:54:15.637+00:00

Hi All,

We have a requirement to monitor folder in one of the windows server, If the folder is having any files for more than 5 minutes it should generate alert. I tried to setup this using Savision community file monitoring MP. But after setting using Savision, the folder is not getting monitor. Please see the attached snip. Kindly let me know what is the reason for this "Not monitored" condition. Please suggest any alternate methods to monitor the same.

Thanks in advance

Regards
Fadil

System Center Operations Manager
System Center Operations Manager
A family of System Center products that provide infrastructure monitoring, help ensure the predictable performance and availability of vital applications, and offer comprehensive monitoring for datacenters and cloud, both private and public.
1,603 questions
0 comments No comments
{count} votes

Accepted answer
  1. SChalakov 10,576 Reputation points MVP Volunteer Moderator
    2022-11-22T09:45:11.8+00:00

    Hi Fadil,

    not quite sure why the folder does nto get monitored and as it seems the picture didn't get attached.
    My advice to you would be to simpy use PowerShell and the PowerShell MP of Cookdown to configure a PowerShell based monitor for that.

    You need a script like that:

    #Warning (or error) threshold regarding the file age  
    [int]$Minutes = "-5"  
    [string]$FolderName = "C:\FolderName"  
    #Prepare dates  
    $CurrentDate = Get-Date  
    $ErrorDate = $CurrentDate.AddMinutes($Minutes)  
    
      
    #Clear Errors  
    $Error.Clear()  
      
    #Prepare API and Property Bag Objects  
    $ScomAPI = New-Object -ComObject "MOM.ScriptAPI"  
    $PropertyBag = $ScomAPI.CreatePropertyBag()  
      
    #Get the files from the folder  
    $MonitoredFiles = Get-ChildItem -Path $FolderName -Recurse  
      
    #Define an array to store the objects  
    [array]$Summary = @()  
      
    foreach ($File in $MonitoredFiles) {  
      
        #Get the Last Modified Date  
        $FileDate = (Get-Item $Filer.FullName).LastWriteTime  
      
        if ($FileDate -lt $ErrorDate) {          
            $Summary += $File.FullName  
        }  
    }  
      
    if ($Summary) {          
        #The file has a LastModified Date, which is older then 24h when the variable $Summary exists  
        #Create and fill the case specific Property Bags  
        [string]$SummaryInfo = $Summary -join ";"  
        $PropertyBag.AddValue("State","Error")  
        $PropertyBag.AddValue("Files",$SummaryInfo)  
    } else {  
        #The file has a LastMofied Date, which is newer then 24h  
        $PropertyBag.AddValue("State","Healthy")  
    }  
      
    #Send the whole output to SCOM  
    $PropertyBag  
    #Used for testing  
    #$ScomAPI.Return($PropertyBag)  
    

    You can take this script, make sure it delivers the right data and create a PowerShell based monitor with it. I described hpow this can be done here:

    Monitoring Active Directory User Account Expiration using SCOM and PowerShell (Step by Step Guide)
    https://www.pohn.ch/monitor-active-directory-user-account-expiration-using-scom-and-powershell-step-by-step-guide/

    In the blogs post I intetgrated another Powershell script, but the approach is the same.

    You can also watch the video here:

    PowerShell MP Example
    https://youtu.be/--wOzKU52JE

    I hope I could help out!

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)
    Regards
    Stoyan Chalakov

    1 person found this answer helpful.

2 additional answers

Sort by: Most helpful
  1. SChalakov 10,576 Reputation points MVP Volunteer Moderator
    2022-11-25T10:17:44.953+00:00

    Hi Fadil,

    please look at the script and the property bags in both cases:

    Unhealthy: State -eq "Error"
    Healthy_ State -eq "Healthy"

    The property bags need to be exacvtly like in the scirpt:

    $PropertyBag.AddValue("State","Error")  
    

    and

     $PropertyBag.AddValue("State","Healthy")  
    

    You can use the additional prooperty bag - "Files" to post the files in the alert.

    Please let me know how this goes!

    Regards,
    Stoyan

    1 person found this answer helpful.

  2. Tal 26 Reputation points
    2022-12-01T09:36:31.007+00:00

    Hi Fadi
    here is a simple script for you, the script check if there is a file is older than 5 min in a destination folder:

    $API = New-Object -ComObject "MOM.ScriptAPI"  
    $PropertyBag = $API.CreatePropertyBag()  
    $Status = "Good"  
    $Message = "Type Good Message"  
    $GetOldestFile = Get-ChildItem "<Enter your path here>" | sort LastWriteTime | select -First 1  
    if($GetOldestFile | where-object {$_.LastWriteTime -lt (Get-Date.AddMinutes(-5)})  
    {  
            $Status = "Bad"  
            $Message = "Type an Error Message"  
    }  
    $PropertyBag.AddValue("Status",$Status)  
    $PropertyBag.AddValue("Message",$Message)  
    $PropertyBag  
    

    Don't forget to create monitor and pass the right variables for Status and Message outputs.

    My approach will be to loop through all files and create an array contains all files and at the end send a message or mail with HTML table with a list of all old files.

    here's a tip a monitor/Alert should have simple but yet informative to save time for the one who asked for the monitor, that's why for my monitors I will never use a generic message and use the variables in the script to generate a message.

    Enjoy.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.