Monitor File System - extend the built in UNC monitor
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
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;
}
Andrew1
·7 years agoTried a number of normal escape characters typically used for PowerShell - no dice. Thanks
Idan
OP7 years agoHi,
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
Andrew1
·7 years agoHow can I configure additional paths with spaces in the folder names?
Michael Rodrigues
·7 years agoThis module should be out of security review now.
wanabeninja
·7 years agoAny idea when this will be out of 'security review' ?
Will Fulmer
·8 years agoAny idea when this will be out of 'security review' ?
Idan
OP8 years agoNot 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
Mcooner
·8 years agoI 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.
Idan
OP8 years agoHappy to help
Mcooner
·8 years agoI 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