Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. <#
  2. Send Slack Notification in Disk gets below 20%
  3. Send Slack Notification in any of the gets below 20%
  4. #>
  5.  
  6.  
  7. Function SlackDiskReport {
  8. param(
  9. [Parameter(Mandatory, ValueFromPipeLine)]
  10. $disk
  11. )
  12.  
  13. process {
  14. $percentageFree = [Math]::round((($disk.freespace/$disk.size) * 100))
  15. $freeGB = [math]::round($disk.freespace /1Gb, 0)
  16.  
  17. if ($percentageFree -lt 21) {
  18.  
  19. $color= 'good'
  20. if ($percentageFree -lt 20) {
  21. $color = 'warning'
  22. }
  23.  
  24. if ($percentageFree -lt 10) {
  25. $color = 'danger'
  26. }
  27.  
  28. $msg = "{0} has {1}% free disk space ({2} GB)" -f $Env:COMPUTERNAME, $percentageFree, $freeGB
  29.  
  30. $attachment = @{
  31. 'title' = 'Disk space warning'
  32. 'color' = $color
  33. 'fallback' = $msg
  34. 'text' = $msg
  35. }
  36.  
  37. $report = @{'attachments' = @($attachment)}
  38.  
  39. $body = ConvertTo-Json -Depth 10 -InputObject $report
  40. IWR -UseBasicParsing -Uri $url -Body $body -Method Post
  41. }
  42. }
  43. }
  44.  
  45. Function FilterServicesByPrefix {
  46. param (
  47. [Parameter(Mandatory, ValueFromPipeLine)]
  48. [System.ServiceProcess.ServiceController] $service,
  49.  
  50. [Parameter(Mandatory)]
  51. [ValidateCount(1, 1000000)]
  52. [string[]] $prefix
  53. )
  54.  
  55. process {
  56. $prefix | % { if ( $service.name -match "^$_") { return $service }}
  57. }
  58. }
  59.  
  60. Function SlackServiceReport {
  61. param(
  62. [Parameter(Mandatory, ValueFromPipeLine)]
  63. [System.ServiceProcess.ServiceController] $service
  64. )
  65.  
  66. process {
  67.  
  68. if (($service.Status -ne "Running") -and ($service.StartType -eq "Automatic" )) {
  69.  
  70. $attachment = @{
  71. 'title' = $service.Name
  72. 'color' = 'danger'
  73. 'fallback' = $service.Name + " is " + $service.Status.ToString()
  74. 'text' = $service.Name + " is " + $service.Status.ToString()
  75. }
  76.  
  77. $report = @{'attachments' = @($attachment)}
  78.  
  79. $body = ConvertTo-Json -Depth 10 -InputObject $report
  80. IWR -UseBasicParsing -Uri $url -Body $body -Method Post
  81. }
  82. }
  83. }
  84.  
  85. $url = Get-Content -Path 'C:\Monitron\slackwebhookurl.txt'
  86. Get-Service | FilterServicesByPrefix -prefix @("particular", "nservicebus", "website.backend") | SendServiceReport
  87. Get-WmiObject -class Win32_logicalDisk -Filter "DeviceID='C:'" | SendDiskReport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement