Remote Monitor – Trigger an alert when a profile goes above a certain size, including setup tips for Remote Monitors!

2018-07-03T10:02:00+00:00July 3rd, 2018|

This is a Remote Monitor that can function in Automate, that will trigger certain keywords that can be detected upon if the profile sizes go above a certain size. I have two monitors here, pick whichever you need depending on your requirements. The first will output all profiles and sizes, the second will only output profiles that are over the threshold. Both will still trigger an error if a profile is over size, this decision is more about the information you want returned in the monitor:

Monitor 1 – Pull back all profile sizes, regardless of size

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -command "& {$ErrorActionPreference = 'SilentlyContinue';$emptyOutput = \"\";[email protected]();$thresholdInGB = \"50\";dir c:\users | foreach -begin {} -process{$size=(dir $_.FullName -recurse -force -ea silentlycontinue | Measure-Object ‘length’ -sum -Maximum).sum;If (($size/1GB) -gt $thresholdInGB){$var1 = \"ErrorCritical\"}else{$var1 = \"ProfileOK\"};$arrayresult += (\"{0:n2}\" -f ($size/1GB) +\" GB\",$_.fullname,$var1);};$final = ($arrayresult) -join \"~\";Write-Output $final;}"

Monitor 2 – Pull back only profile where profile size is over the threshold

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -command "& {$ErrorActionPreference = 'SilentlyContinue';$emptyOutput = \"\";[email protected]();$thresholdInGB = \"50\";dir c:\users | foreach -begin {} -process{$size=(dir $_.FullName -recurse -force -ea silentlycontinue | Measure-Object ‘length’ -sum -Maximum).sum;If (($size/1GB) -gt $thresholdInGB){$var1 = \"ErrorCritical\"}else{$var1 = \"ProfileOK\"};If ($var1 -eq \"ErrorCritical\"){$arrayresult += (\"{0:n2}\" -f ($size/1GB) +\" GB\",$_.fullname,$var1)}Else{};};$final = ($arrayresult) -join \"~\";if ($arrayresult){}Else{$Final = \"Profile Sizes OK\"};Write-Output $final;}"

Step 1 – Decide on a threshold

Because of the nature of this monitor, the threshold has to be built within the Powershell. It is possible to extrapolate the threshold into a client based EDF, this is beyond the scope of this article though. If you want to discuss that come ping me in the LabTechGeek Slack (@Gavsto). Once you have decided on a threshold, modify the code above to include it (Variable is $thresholdinGB and is currently set at 50 in the example).

Pro Hint – you can copy the above code and paste it directly into a command prompt to test it – this is how I test all my Remote Monitors that have Powershell in because this is how Automate executes them

Step 2 – Configure and Test on a few agents

  1. Find an agent, Right click, Monitors, Create Monitor (Don’t select Create Monitor with Wizard).
  2. Call the monitor name something reasonable, I have my own standard for this – DISK – Profile size check for User Profile – Custom (MyMSP)
    1. I always tag any custom monitors with the word custom so I can easily filter my monitors and see which ones were manually created
  3. Go to the alerting tab, set whatever alert template you want to use (Default – Do Nothing) for now, I’ll touch on this later
    1. If you want to modify the Alert Message Subject On Success, make sure you set it to be identical to the failure subject too.
  4. Set a ticket category
  5. In the configuration tab, choose Monitor Type > External EXE Check. Paste your code in the Executable / Arguments box.
  6. Choose an interval for the top right – this value is in seconds. I think every 3 days is reasonable, so 259200
  7. Set the condition to Does Not Contain and in the result box put ErrorCritical
    1. Remember, on remote monitors we test for GOOD conditions which is why this is a Does Not Contain
  8. Choose Test on the bottom right hand corner, and ensure a result comes back that you would expect. The output looks a bit like this:
    1. 0.16 GB C:\users\Administrator ProfileOK~0.00 GB C:\users\administrator.DOMAIN ProfileOK~0.20 GB C:\users\bob.geldof ProfileOK~9.13 GB C:\users\ed.sheeran ProfileOK~7.51 GB
  9. Once happy, click “Add new” in the bottom right hand corner.
  10. A good Admin always tests extensively, test this against different clients and different machines with different OSes.

Step 3 – Deploy to all machines that need it

There are numerous ways to deploy this to all Windows Workstations, everyone has their own preferences. I prefer to apply to the Default Service Plan groups, and then limit the scope via a search. This allows me to see most remote monitors in one location. Before we do this, lets check the groups area to see how we will deploy.

  1. Go into groups, and open the Service Plan Group that contains your workstations. Mine is Service Plans > Windows Workstations > Managed 8×5
  2. Go to the Computers Tab
  3. Go to the Remote Monitors Tab
  4. Click on one of the Remote Monitors in the bottom pane. Notice how in the top configuration there is an option to Limit To. When this Dropdown is selected, the Remote Monitor you set this on will only apply to agents that meet the Criteria of the search you select.
  5. Re-open one of the agents you have tested the remote monitor on, Right click the “Gear” Icon in the top panel, and go to monitors
  6. Right click the monitor we created before, and choose Send to Groups
  7. Find the Service Plan group we identified before, tick the group and click send.
  8. Immediately go back to the Service Plan group and open it again, go back into Computers Tab and then Remote Monitors Tab
  9. Single click the monitor that we just sent here. In the Limit To dropdown, choose Computer Types\Computers – Windows Desktop and click Update (middle bottom right)

Step 4 – Monitoring the Deployment

It will take a good few minutes for the monitor to be installed on all the agents. The best way to monitor them is to do the following:

  1. In the Main UI Windows, Go to Automate and open Monitors
  2. Click on the “System Monitors” Tab (A System Monitor is a Remote Monitor)
  3. Ensure the results are not filtered (top right)
  4. In the monitor name column, type in %profile% and hit enter
  5. You should see a list of your test monitors at a minimum
  6. Keep hitting refresh until the monitors start to show up
  7. Please note – the monitor status information may not populate immediately, if all the Remote Monitors have appeared but none have Monitor Status Information, just leave it a few more minutes

When using Powershell monitors, especially ones that are deployed to many agents it’s important to manually scan down the monitor status information, to make sure that the majority or all of them are working as expected. Working with Powershell, it’s easy to come up with some Powershell that only works in certain situations etc. This view is great to see all monitors in one go (Hint, set the Page Size in the top right to something like 2000)

Step 5 – Gimme my tickets

Once you are happy that the majority of failures are legitimate failures:

  1. Open the group we set the remote monitor on
  2. Computers Tab, Remote Monitors Tab, Single select the remote monitor we have setup
  3. Set the Alert Template (top right), Default – Create Automate Ticket.
  4. Click Update

This will reset the remote monitor and deploy it with the alert template in. This time when the failures trigger you should get tickets.

I hope this has been informative!

 

 

 

Leave A Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.