This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Exported Alert - Delete Content Of Temp Folder If disk Is Full

Automation is spouted from every blog post, whitepaper and roof top 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.    

Delete Content Of Temp Folder If disk Is Full.png

  • 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.
    1. 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:

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

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.

Kind Regards,

Mark Roberts

Prosperon - UK SolarWinds Partners

Installation | Consultancy | Training | Licenses

facebook_icon.jpglinkedin.pngblogger.pngtwitter-icon.jpg

Delete Temp Folder - Alert Action.zip