Idan

Monitor File System - extend the built in UNC monitor

Recommended Posts

Hi,

I developed a small PowerShell script that monitors the number of files in a folder and returns the total number of files in the root folder, the number of files in all the subfolders, the number of folders in the root of the folder and number of folders in all the subfolders.

In additional, you can filter by file extension.

Because it's powershell, you can easily add filter a specific folder and more.

Remember, PowerShell script run on the collector and not on the server even if in the apply to you select a server.

So or install the collector on the server you want to monitor, or use UNC like \\

Also remember to allow remote PowerShell

https://www.logicmonitor.com/support/datasources/powershell-support/using-powershell-scripts-in-logicmonitor/

The active discovery script is:

$folderspath = '##FolderToMonitor##';
$SearchSExt = 'zip'
$separator = ";"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$array = $folderspath.Split($separator, $option)
$stringcount = $folderspath.Split($separator,2, $option).Count
$folder_id=0

foreach ($folder in $array) {
  $folder_id++

  $separatorext = "@"
  $option = [System.StringSplitOptions]::RemoveEmptyEntries
  $arrayext = $folder.Split($separatorext, $option)
  $folderpath =  $arrayext[0]
  $SearchSExt = $arrayext[1]
  
  If ($SearchSExt -eq '*' -or $SearchSExt -eq $null)
    {

    # write out the instance data
     Write-Host "OPFID$folder_id##$folderpath##$folderpath";
    }
    else
    {
         Write-Host "OPFID$folder_id##$folderpath##$folderpath filter ext $SearchSExt";
    }
}

 

The collector script below and it get parameter as like that

\\MyServer\MyShare\Test1@*;\\MyServer\MyShare\Test2@xml;\\MyServer\MyShare\Test3@zip;\\MyServer\MyShare\Test4@*

This will apply to $folderspath = '##FolderToMonitor##'; if you will use the device properties

So you can specify a list of folders separated by ";" and you can specify the file ext. filter by @

 

$folderspath = '##FolderToMonitor##';
$separator = ";"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$array = $folderspath.Split($separator, $option)
$stringcount = $folderspath.Split($separator,2, $option).Count
$folder_id=0

foreach ($folder in $array) {
  $folder_id++

  $separatorext = "@"
  $option = [System.StringSplitOptions]::RemoveEmptyEntries
  $arrayext = $folder.Split($separatorext, $option)
  $folderpath =  $arrayext[0]
  $SearchSExt = $arrayext[1]
  
If ($SearchSExt -eq '*' -or $SearchSExt -eq $null)
    {
        
        $TotalFiles=Get-ChildItem $folderpath -Recurse -File | Measure-Object | %{$_.Count}
        $TotalFolders= Get-ChildItem $folderpath -Recurse -Directory | Measure-Object | %{$_.Count}
        $TotalFilesInRoot=Get-ChildItem $folderpath -File | Measure-Object | %{$_.Count}
        $TotalFoldersInRoot=Get-ChildItem $folderpath -Directory  | Measure-Object | %{$_.Count}

    }
    else 
    {

              
        $TotalFiles=Get-ChildItem $folderpath -recurse -File -filter *.$SearchSExt | Measure-Object | %{$_.Count}
        $TotalFolders= Get-ChildItem $folderpath -Recurse -Directory | Measure-Object | %{$_.Count}
        $TotalFilesInRoot=Get-ChildItem $folderpath -File -filter *.$SearchSExt | Measure-Object | %{$_.Count}
        $TotalFoldersInRoot=Get-ChildItem $folderpath -Directory  | Measure-Object | %{$_.Count}

    }

Write-Host   "OPFID$folder_id.TotalFiles="$TotalFiles;
Write-Host   "OPFID$folder_id.TotalFolders="$TotalFolders;
Write-Host   "OPFID$folder_id.TotalFilesInRoot="$TotalFilesInRoot;
Write-Host   "OPFID$folder_id.TotalFoldersInRoot="$TotalFoldersInRoot;

}

 

Share this post


Link to post
Share on other sites

I have been having issues with Monitoring just a folder, I took your powerscript and added in the folder size info and then changed it to GB/TB. Published the Source to the Logic Monitor Data Source: YL7PL2 . Thanks for the script

Share this post


Link to post
Share on other sites

I was trying to convert it to list all the subfolders in the subfolder instead of just OPFID1. I can get it to work in Powershell but not in LM tells me that it found now instances. 

 

Share this post


Link to post
Share on other sites

Not not what you are trying to do, if you will post the script I can try to look into that.

Just send me also what you are trying to do as I'm not sure I understand it.

Make sure you have the right script in the auto discover too.

You can run debugging in th eLM

Share this post


Link to post
Share on other sites
On 6/5/2018 at 9:09 AM, Mcooner said:

I have been having issues with Monitoring just a folder, I took your powerscript and added in the folder size info and then changed it to GB/TB. Published the Source to the Logic Monitor Data Source: YL7PL2 . Thanks for the script

Any idea when this will be out of 'security review' ?

Share this post


Link to post
Share on other sites
On 6/5/2018 at 9:09 AM, Mcooner said:

I have been having issues with Monitoring just a folder, I took your powerscript and added in the folder size info and then changed it to GB/TB. Published the Source to the Logic Monitor Data Source: YL7PL2 . Thanks for the script

Any idea when this will be out of 'security review' ?

Share this post


Link to post
Share on other sites
On 4/5/2017 at 8:56 PM, Idan said:

The collector script below and it get parameter as like that

\\MyServer\MyShare\Test1@*;\\MyServer\MyShare\Test2@xml;\\MyServer\MyShare\Test3@zip;\\MyServer\MyShare\Test4@*

This will apply to $folderspath = '##FolderToMonitor##'; if you will use the device properties

So you can specify a list of folders separated by ";" and you can specify the file ext. filter by @

 

 

How can I configure additional paths with spaces in the folder names?

Share this post


Link to post
Share on other sites

Hi,

I didn't check it,but this is a powershell, so maybe search how to send a parameter in PowerShell with the space.

Try to modify the $folderpath and try to change it to '$folderpath' 

You can try to run some basic powershell commands before deploy it in LogicMonitor

 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.