Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- Send Slack Notification in Disk gets below 20%
- Send Slack Notification in any of the gets below 20%
- #>
- Function SlackDiskReport {
- param(
- [Parameter(Mandatory, ValueFromPipeLine)]
- $disk
- )
- process {
- $percentageFree = [Math]::round((($disk.freespace/$disk.size) * 100))
- $freeGB = [math]::round($disk.freespace /1Gb, 0)
- if ($percentageFree -lt 21) {
- $color= 'good'
- if ($percentageFree -lt 20) {
- $color = 'warning'
- }
- if ($percentageFree -lt 10) {
- $color = 'danger'
- }
- $msg = "{0} has {1}% free disk space ({2} GB)" -f $Env:COMPUTERNAME, $percentageFree, $freeGB
- $attachment = @{
- 'title' = 'Disk space warning'
- 'color' = $color
- 'fallback' = $msg
- 'text' = $msg
- }
- $report = @{'attachments' = @($attachment)}
- $body = ConvertTo-Json -Depth 10 -InputObject $report
- IWR -UseBasicParsing -Uri $url -Body $body -Method Post
- }
- }
- }
- Function FilterServicesByPrefix {
- param (
- [Parameter(Mandatory, ValueFromPipeLine)]
- [System.ServiceProcess.ServiceController] $service,
- [Parameter(Mandatory)]
- [ValidateCount(1, 1000000)]
- [string[]] $prefix
- )
- process {
- $prefix | % { if ( $service.name -match "^$_") { return $service }}
- }
- }
- Function SlackServiceReport {
- param(
- [Parameter(Mandatory, ValueFromPipeLine)]
- [System.ServiceProcess.ServiceController] $service
- )
- process {
- if (($service.Status -ne "Running") -and ($service.StartType -eq "Automatic" )) {
- $attachment = @{
- 'title' = $service.Name
- 'color' = 'danger'
- 'fallback' = $service.Name + " is " + $service.Status.ToString()
- 'text' = $service.Name + " is " + $service.Status.ToString()
- }
- $report = @{'attachments' = @($attachment)}
- $body = ConvertTo-Json -Depth 10 -InputObject $report
- IWR -UseBasicParsing -Uri $url -Body $body -Method Post
- }
- }
- }
- $url = Get-Content -Path 'C:\Monitron\slackwebhookurl.txt'
- Get-Service | FilterServicesByPrefix -prefix @("particular", "nservicebus", "website.backend") | SendServiceReport
- Get-WmiObject -class Win32_logicalDisk -Filter "DeviceID='C:'" | SendDiskReport
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement