Select Page

Exported Alert – Delete Content of Temp Folder if Disk is Full

by 31, Oct, 2015Alerting & Custom Alerts, Blog Bites, Network Management

Automation is spouted from every blog post, whitepaper and rooftop it seems currently, with the keyword DevOps thrown in for good measure. Now some of this can be very complex, with the idea that IT departments can unburden themselves from common or garden tasks and automate them away. In this Blog Bite, I am going to show you a nice and straightforward way to perform some automation to deal with an everyday task of keeping a C: OS drive from filling up and causing immediate performance degradation.

I must highlight at the beginning that this is not a one size fits all approach and is a fix to allow some space to be reclaimed to deal with the immediacy of performance affecting a filled volume. You are still very likely to need to go on to the machines and review what further actions are needing to be done; cleanse more files, increase volume size etc.

The what, where and how… 

  • The first thing to ensure is that you have the server populated within Orion and that the C: drive is monitored.
  • Create an alert (Settings > Manage Alerts > Create New) which has the necessary Trigger Logic, such as the following, which uses Custom Properties to be more accurate per volume. Add any further logic to restrict to certain servers etc. as required. Remember you are auto deleting files here, so be clear on what qualifies for inclusion or not.
Trigger Conditions (Insight Image) - Prosperon Networks
  • The reset action is suggested to be another rule which looks for the volume to be back to a normal level i.e. not in warning or critical condition
  • Within the Alert definition wizard on the Trigger Action page add a ‘Execute a Program’ action
    • In the window that opens we need to provide the path to the PowerShell command line, which includes the 3 parameters our script needs to work correctly:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy unrestricted -command “c:\SolarWindsScripts\deletetempfiles.ps1 -ComputerName ${N=SwisEntity;M=Node.DNS} -FilePath c:\SolarWindsScripts\FolderList.csv -AlertObjectID${N=Alerting;M=AlertObjectID}”

NOTE: I have used the sub folder on C: “SolarWindsScripts” to store the PowerShell script used

It is always nice to know what has actually been achieved with this activity and therefore I am leveraging the SolarWinds® API (SWIS) to update the Alert Note field with information on how many files and how much space has been deleted.

Requirements:

  • The PowerShell script utilises WINRM in order that the file delete actions are performed by the remote server
  • The following variables need to be reviewed and adjusted to suit your environment
    • $FilePath – File Location where the CSV file is located for the filtering mechanism. The csv file contains 3 columns:
      • Folder – the folders to be included for deletion
      • OlderThan – file aging filter to exclude files older than x days
      • Exclusion – files or extensions to be excluded from deletion, and yes it does accept wildcards! (eg: *.reg). Leave empty to delete all content
  • The alert Trigger definition utilises a Custom Property on the Volume object VolCriticalThreshold and VolWarningThreshold
    • Adjust the Trigger rule to work for you
  • The API action to insert the results into the Alert Note field requires the credentials to be configured
    • Edit the PS1 file and update the information on line 91. The use of SecureString is recommended
  • One final obvious statement, ensure you enable the alert in Alert Manager to allow this to do its magic.

The main thing here is that the script has all the power, so you can extend this to other folders very easily and also with PowerShell perform tasks like emptying recycle bins for example.

I do hope you find this useful and please post back if you have an example of how this has helped you.

Custom Alert: Delete Content Of Temp Folder If Disk Is Full

Mark Roberts

Mark Roberts

Technical Director

Mark Roberts is the Technical Director at Prosperon Networks and a SolarWinds MVP. Mark has been helping customers meet their monitoring needs with SolarWinds IT Management Solutions for over 14 years.

Custom Alert: Delete Content Of Temp Folder If Disk Is Full

Related Insights From The Prosperon Blog

Not found
Share This