Monitor File existence

Standard

In this blogpost I am going to take you true the steps I took to create a two state monitor which checks if a file exist.

A big thank’s to Pete Zeger and Kevin Holman for creating the VB script to check if a file exist.

You can download the script from here

Now that we have script I took the following steps to create the two state Monitor

  1. Start the “System Center operations Mananger Concole"
  2. In the “Navigation" pane, click “Administration
  3. From the “Administration” page, right click “Management Pack” and click “Create Management Pack.Create Management Pack
  4. On the “Create a Management Pack” wizard on the “General Properties” page in the “Management pack General Properties” section enter a “Name” and click “Next
  5. On the “Create a Management Pack” wizard on the “Knowledge” page in the “Knowledge” section click “Create
  6. In the “System Center Operations Manager Console” in the “Navigation” pane, click “Authoring
  7. From the “Authoring” page, expand “Management Pack Objects”, right click “Monitors” click “Unit Monitor” and click “Unit MonitorCreateUnitMonitor
  8. In the “Create a unit Monitor” wizard, on the “Monitor Type” page, in the “Select the type of monitor to create” section expand “Scripting”, “Generic” and select “Timed Script Two State Monitor
  9. In the “Create a unit Monitor” wizard, on the “Monitor Type” page, in the “Management pack” section, select the above created “Management pack” and click “Next

    CreateUnitMonitor1

  10. In the “Create a unit Monitor” wizard, on the “General” page, in the “General Properties” section enter a “Name” and “Description”.
  11. In the “Create a unit Monitor” wizard, on the “General” page, in the “General Properties” section click “Select” tot target the Monitor
  12. In the “Select Items tot target” in the “Look for” bar enter “Windows Server” and select the target “Windows Server” and click “OK

    CreateUnitMonitor2

  13. In the “Create a unit monitor” wizard, on the general page uncheck “Monitor is enabled” and click “Next

    CreateUnitMonitor3

  14. In the “Create a unit Monitor” wizard, on the “Schedule” page, click “Next
  15. In the “Create a unit monitor” wizard, on the “Script” page, in the “Enter script information” section enter the name “DoesFileExist.vbs” copy the script into the Script section. and click “NextCreateUnitMonitor4
  16. In the “Create a unit monitor” wizard, on the “Unhealthy Expression” page in the “File one or more events” section click “Insert” and  “Or groupCreateUnitMonitor5
  17. In the “Create a unit monitor” wizard, on the “Unhealthy Expression” page in the “Filter one or more events” section enter the following settings:
    • Parameter: “Property[@Name=’FolderExists’]
    • Operator: “Equals
    • Value: “No

    In the “Create a unit Monitor” wizard, on the “Unhealthy Expression” page in the “Filter one or more events” section click “Insert” and click “Expression”. Enter the following settings:

    • Parameter: “Property[@Name=’FileExists’]
    • Operator: “Equals
    • Value: “No

    Click  "Next"

    CreateUnitMonitor8

  18. In the “Create a unit monitor” wizard, on the “Healthy Expression” page in the “File one or more events” section click “Insert” and  “And groupCreateUnitMonitor7
  19. In the “Create a unit monitor” wizard, on the “Healthy Expression” page in the “Filter one or more events” section enter the following settings:
    • Parameter: “Property[@Name=’FolderExists’]
    • Operator: “Equals
    • Value: “Yes

    In the “Create a unit Monitor” wizard, on the “Healthy Expression” page in the “Filter one or more events” section click “Insert” and click “Expression”. Enter the following settings:

    • Parameter: “Property[@Name=’FileExists’]
    • Operator: “Equals
    • Value: ”

    Click “Next

    CreateUnitMonitor6

  20. In the “Create a unit monitor” wizard, on the “Configure Health” page in the “Map monitor conditions to heath state” section enter the following settings:
    • Monitor condition: “Unhealthy
    • Operation State: “Unhealthy
    • Health State: “Critical"
    • Monitor Conditions: “Healthy
    • Operation State: “Healthy
    • Health State: “Healthy

    Click “NextCreateUnitMonitor9

  21. In the “Create a unit monitor” wizard, on the “Configure alerts” page in the “Alert Setting” section. Check “Generate alerts for this monitorCreateUnitMonitor10
  22. In the “Create a unit monitor” wizard, on the “Configure Alerts” page in the “Alert properties” section enter the following settings:
    • Alert Name: “File Exist
    • Alert Description: “The following files or folders are missing:””Folder: $Data/Context/Property[@Name=’FolderExists’]$””File: $Data/Context/Property[@Name=’FileExists’]$
    • Priority: “Medium
    • Severity: “”Critical

    Configure Alerts Click “Create

Now that the two state monitor is created it’s time to configure the monitor.

  1. Start the “System Center Operations Manager” Console.
  2. In the “Navigation" pane, click “Authoring
  3. From the “Authoring” page, expand “Management Pack Objects” and select “Monitors
  4. In the “Look for..” enter the Name of the above created monitor Monitor File Exists
  5. Right click on the two state Monitors name and click “Properties
  6. On the “<Name> File Exist Properties” page, select the “Script” tab Script
  7. On the “<Name> File Exist Propertis” page, on the “Script” tab click “Parameters
  8. On the “Script – DoesFileExist.vbs” page, in the “Parameters” section en the following lines:
    • ”C:\test” “test.txt”Enter Parameters 

    Click “OK

  9. On the “<Name> File Exist Properties” page, on the “Script” tab click “Apply” and click “OK

Now that we have the parameters Configured we have to override the monitor to be used for a certain computer.

  1. Start the “System Center Operations Manager” Console
  2. In the “Navigation" pane, click “Authoring
  3. From the “Authoring” page, expand “Management Pack Objects” and select “Monitors
  4. In the “Look for..” enter the Name of the above created monitor
  5. Expand “Windows Server” and right click “<Name> File Exist Monitor” click “Overrides”, “Override the Monitor” and click “For al specific object of class: Windows ServerOverride Monitor
  6. In the “Select Object” pane in the the “Text string” bar enter the computer name where you want to override the monitor for. In the “Matching objects” display select the computer and click “OKSelect Object
  7. On the “Overrides Properties” page in the “Override-controlled parameters” change the following settings:
    • select “Parameter Name”: “Enable
    • change the “Override Value”: to “True 

    Click “Apply” and click “OK

The result should look something like this:

  • When the file doesn’t existsFile Not Exist
  • When the file and the folder doesn’t exists:File and Folder Not Exist
  • When the file and the folder exists:File Exist

13 thoughts on “Monitor File existence

  1. SomB

    Roel – thanks for posting these step by step instructions. I am assuming the Parameters for the “DoesFileExist.vbs” is where you would enter in the full path to the monitored folder and monitored file? I apply these steps, and when I perform the override to be applied to the Windows server, I see the monitor applied in the Health Explorer, but its an empty Green Circle with no check mark or critical icon. What do you think can be the problem?

    • Hi
      Thanks for your comment.
      In the parameters for the “DoesFileExist.vbs” you enter a rule between double quote “The path to your file” and on the next line between qoute “The file you want to monitor”
      Do you see errors in the eventlog on the server where the files are?

      Greetings Roel Knippen

  2. SomB

    Thanks for your response back. I was able to get the Green Circle to go away and now it has a Green CheckMark. But when I test the rule by either deleting the “test” folder located on c:\test or by deleting the “test.txt”, the monitor doesn’t see that change and it always has the Green Circle with checkmark. This is the error I see in the event logs.
    **************************************************
    The process started at 9:10:00 AM failed to create System.PropertyBagData. Errors found in output:

    C:\Program Files\Microsoft Monitoring Agent\Agent\Health Service State\Monitoring Host Temporary Files 5137\20124\DoesFileExist.vbs(25, 23) Microsoft VBScript compilation error: Expected end of statement

    Command executed: “C:\Windows\system32\cscript.exe” /nologo “DoesFileExist.vbs” ”C:\test” “test.txt”
    Working Directory: C:\Program Files\Microsoft Monitoring Agent\Agent\Health Service State\Monitoring Host Temporary Files 5137\20124\

    One or more workflows were affected by this.

  3. SomB

    Roel – looks like when I copy and pasted the script from your website to the Script field within SCOM, it added some weird characters to the text which was causing the previous error. So now I get a different error message. I have confirmed all the settings are the same as in your screenshots. I have only changed the path of the folder and test.txt to the F drive thinking that maybe permissions was interfering with my testing.

    The process started at 10:20:00 AM failed to create System.PropertyBagData. Errors found in output:

    C:\Program Files\Microsoft Monitoring Agent\Agent\Health Service State\Monitoring Host Temporary Files 5137\20376\DoesFileExist.vbs(24, 1) Microsoft VBScript runtime error: Subscript out of range

    Command executed: “C:\Windows\system32\cscript.exe” /nologo “DoesFileExist.vbs” ”F:\Somtest” “test.txt”
    Working Directory: C:\Program Files\Microsoft Monitoring Agent\Agent\Health Service State\Monitoring Host Temporary Files 5137\20376\

  4. SomB

    Roel – I got this to work. The issue was with formatting. I re-did all the steps manually and typed in the code and parameter settings into scom. It works well. thanks

    • Hi,
      Good to here that it’s working. I will update the script this wekend and make sure that it available for download.
      Have a good wekend
      Greetings Roel Knippen

Leave a Reply

Your email address will not be published. Required fields are marked *