From ebd9fa11c6da104a0a92dc6fac765655fa8d9ae6 Mon Sep 17 00:00:00 2001 From: Dirk Date: Wed, 3 Aug 2016 09:09:15 +0200 Subject: [PATCH 1/3] Added PRTG Attachments and Fields --- PRTGSlackNotification.ps1 | 58 +++++++++++++++++++++++++------- PRTGSlackWebHookNotification.ps1 | 50 +++++++++++++++++++++------ 2 files changed, 85 insertions(+), 23 deletions(-) diff --git a/PRTGSlackNotification.ps1 b/PRTGSlackNotification.ps1 index cd60ba1..1ae8805 100644 --- a/PRTGSlackNotification.ps1 +++ b/PRTGSlackNotification.ps1 @@ -7,7 +7,7 @@ # You must not remove this notice, or any other, from this software. # ---------------------------------------------------------------------------------------------- Param( - [string]$SlackToken, + [string]$SlackToken, [string]$SlackChannel, [string]$SiteName, [string]$Device, @@ -16,19 +16,51 @@ Param( [string]$Down, [string]$DateTime, [string]$LinkDevice, - [string]$Message + [string]$Message, + [string]$ColorofState, + [string]$LinkSensor, + [string]$LastCheck, + [string]$StateSince, + [string]$LastMessage ) + +$attachments = ConvertTo-Json -Depth 4 @(@{ + fallback = "New notification for $($Device) - $($Name) is $($Status) $($Down). $($LinkDevice)" + title = "${Name}: Status $($Status) $($Down)" + title_link = $LinkSensor + color = $ColorofState + text = $Message + fields = @( @{ + title = "Date" + value = $DateTime + short = 1 + } + @{ + title = "Letzte Ueberpruefung" + value = $LastCheck + short = 1 + } + @{ + title = "Status seit" + value = $StateSince + short = 1 + } + @{ + title = "Letzte Meldung" + value = $LastMessage + short = 1 + } + ) + }) $postSlackMessage = @{ - token = $SlackToken; - channel = $SlackChannel; - unfurl_links = "true"; - username = "PRTG"; - icon_url = "http://www.paessler.com/static/banner_1s_80x80.png" - text = "*$($sitename)* -<$($LinkDevice)|$($Device) $($Name)> -Status $($Status) $($Down) on $($DateTime) -``````$($Message)``````"; - } + token = $SlackToken + channel = $SlackChannel + unfurl_links = "true" + username = $sitename + text = "*New notification* for <$($LinkDevice)|$($Device)>" + attachments = $attachments +} + $postSlackMessage | Out-File -FilePath slack.log $postSlackMessage.text | Out-File -FilePath slack.log -Append -Invoke-RestMethod -Uri https://slack.com/api/chat.postMessage -Body $postSlackMessage | Out-File -FilePath slack.log -Append +Invoke-RestMethod -Uri https://slack.com/api/chat.postMessage -Body $postSlackMessage | Out-File -FilePath slack.log -Append \ No newline at end of file diff --git a/PRTGSlackWebHookNotification.ps1 b/PRTGSlackWebHookNotification.ps1 index a7c82f0..f276388 100644 --- a/PRTGSlackWebHookNotification.ps1 +++ b/PRTGSlackWebHookNotification.ps1 @@ -16,18 +16,48 @@ Param( [string]$Down, [string]$DateTime, [string]$LinkDevice, - [string]$Message + [string]$Message, + [string]$ColorofState, + [string]$LinkSensor, + [string]$LastCheck, + [string]$StateSince, + [string]$LastMessage ) $postSlackMessage = @{ - channel = $SlackChannel; - unfurl_links = "true"; - username = "PRTG"; - icon_url = "http://www.paessler.com/static/banner_1s_80x80.png" - text = "*$($sitename)* -<$($LinkDevice)|$($Device) $($Name)> -Status $($Status) $($Down) on $($DateTime) -``````$($Message)``````"; - } | ConvertTo-Json + channel = $SlackChannel + unfurl_links = "true" + username = $SiteName + text = "*New notification* for <$($LinkDevice)|$($Device)>" + attachments = @( @{ + fallback = "New notification for $($Device) - $($Name) is $($Status) $($Down). $($LinkDevice)" + title = "${Name}: Status $($Status) $($Down)" + title_link = $LinkSensor + color = $ColorofState + text = $Message + #author_name = "Bobby Tables" + fields = @( @{ + title = "Date" + value = $DateTime + short = 1 + } + @{ + title = "Letzte Ueberpruefung" + value = $LastCheck + short = 1 + } + @{ + title = "Status seit" + value = $StateSince + short = 1 + } + @{ + title = "Letzte Meldung" + value = $LastMessage + short = 1 + } + ) + } ) +} | ConvertTo-Json -Depth 4 $postSlackMessage | Out-File -FilePath slack.log $postSlackMessage.text | Out-File -FilePath slack.log -Append Invoke-RestMethod -Method Post -ContentType 'application/json' -Uri $SlackWebHook -Body $postSlackMessage | Out-File -FilePath slack.log -Append From af93793ed37b4b0803614e7e36ebcfa421d33cba Mon Sep 17 00:00:00 2001 From: Dirk Date: Wed, 3 Aug 2016 09:14:24 +0200 Subject: [PATCH 2/3] Added Slack Attachments and Fields From 8853774d0b5eb215647379cd7663f0d0d48c7560 Mon Sep 17 00:00:00 2001 From: Dirk Date: Wed, 3 Aug 2016 09:15:28 +0200 Subject: [PATCH 3/3] Added Slack Attachments and Fields --- PRTGSlackNotification.ps1 | 2 +- PRTGSlackWebHookNotification.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PRTGSlackNotification.ps1 b/PRTGSlackNotification.ps1 index 1ae8805..cefa94a 100644 --- a/PRTGSlackNotification.ps1 +++ b/PRTGSlackNotification.ps1 @@ -41,7 +41,7 @@ $attachments = ConvertTo-Json -Depth 4 @(@{ short = 1 } @{ - title = "Status seit" + title = "Status seid" value = $StateSince short = 1 } diff --git a/PRTGSlackWebHookNotification.ps1 b/PRTGSlackWebHookNotification.ps1 index f276388..674350f 100644 --- a/PRTGSlackWebHookNotification.ps1 +++ b/PRTGSlackWebHookNotification.ps1 @@ -46,7 +46,7 @@ $postSlackMessage = @{ short = 1 } @{ - title = "Status seit" + title = "Status seid" value = $StateSince short = 1 }