├── images ├── prtgslacksamplenotification.jpg ├── prtgslacknotificationsettings.png └── prtgslackwebhooknotificationsettings.png ├── LICENSE ├── PRTGSlackNotification.ps1 ├── PRTGSlackWebHookNotification.ps1 ├── PRTGSlackNotificationPSv2.ps1 ├── PRTGSlackWebHookNotificationPSv2.ps1 ├── README.md └── .gitignore /images/prtgslacksamplenotification.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WCOMAB/PRTGSlackNotification/HEAD/images/prtgslacksamplenotification.jpg -------------------------------------------------------------------------------- /images/prtgslacknotificationsettings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WCOMAB/PRTGSlackNotification/HEAD/images/prtgslacknotificationsettings.png -------------------------------------------------------------------------------- /images/prtgslackwebhooknotificationsettings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WCOMAB/PRTGSlackNotification/HEAD/images/prtgslackwebhooknotificationsettings.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 WCOM AB 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /PRTGSlackNotification.ps1: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------------------------- 2 | # Copyright (c) WCOM AB 2015. 3 | # ---------------------------------------------------------------------------------------------- 4 | # This source code is subject to terms and conditions of the The MIT License (MIT) 5 | # copy of the license can be found in the LICENSE file at the root of this distribution. 6 | # ---------------------------------------------------------------------------------------------- 7 | # You must not remove this notice, or any other, from this software. 8 | # ---------------------------------------------------------------------------------------------- 9 | Param( 10 | [string]$SlackToken, 11 | [string]$SlackChannel, 12 | [string]$SiteName, 13 | [string]$Device, 14 | [string]$Name, 15 | [string]$Status, 16 | [string]$Down, 17 | [string]$DateTime, 18 | [string]$LinkDevice, 19 | [string]$Message 20 | ) 21 | $postSlackMessage = @{ 22 | token = $SlackToken; 23 | channel = $SlackChannel; 24 | unfurl_links = "true"; 25 | username = "PRTG"; 26 | icon_url = "http://www.paessler.com/static/banner_1s_80x80.png" 27 | text = "*$($sitename)* 28 | <$($LinkDevice)|$($Device) $($Name)> 29 | Status $($Status) $($Down) on $($DateTime) 30 | ``````$($Message)``````"; 31 | } 32 | $postSlackMessage | Out-File -FilePath slack.log 33 | $postSlackMessage.text | Out-File -FilePath slack.log -Append 34 | Invoke-RestMethod -Uri https://slack.com/api/chat.postMessage -Body $postSlackMessage | Out-File -FilePath slack.log -Append 35 | -------------------------------------------------------------------------------- /PRTGSlackWebHookNotification.ps1: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------------------------- 2 | # Copyright (c) WCOM AB 2015. 3 | # ---------------------------------------------------------------------------------------------- 4 | # This source code is subject to terms and conditions of the The MIT License (MIT) 5 | # copy of the license can be found in the LICENSE file at the root of this distribution. 6 | # ---------------------------------------------------------------------------------------------- 7 | # You must not remove this notice, or any other, from this software. 8 | # ---------------------------------------------------------------------------------------------- 9 | Param( 10 | [string]$SlackWebHook, 11 | [string]$SlackChannel, 12 | [string]$SiteName, 13 | [string]$Device, 14 | [string]$Name, 15 | [string]$Status, 16 | [string]$Down, 17 | [string]$DateTime, 18 | [string]$LinkDevice, 19 | [string]$Message 20 | ) 21 | $postSlackMessage = @{ 22 | channel = $SlackChannel; 23 | unfurl_links = "true"; 24 | username = "PRTG"; 25 | icon_url = "http://www.paessler.com/static/banner_1s_80x80.png" 26 | text = "*$($sitename)* 27 | <$($LinkDevice)|$($Device) $($Name)> 28 | Status $($Status) $($Down) on $($DateTime) 29 | ``````$($Message)``````"; 30 | } | ConvertTo-Json 31 | $postSlackMessage | Out-File -FilePath slack.log 32 | $postSlackMessage.text | Out-File -FilePath slack.log -Append 33 | Invoke-RestMethod -Method Post -ContentType 'application/json' -Uri $SlackWebHook -Body $postSlackMessage | Out-File -FilePath slack.log -Append 34 | -------------------------------------------------------------------------------- /PRTGSlackNotificationPSv2.ps1: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------------------------- 2 | # Copyright (c) WCOM AB 2015. 3 | # ---------------------------------------------------------------------------------------------- 4 | # This source code is subject to terms and conditions of the The MIT License (MIT) 5 | # copy of the license can be found in the LICENSE file at the root of this distribution. 6 | # ---------------------------------------------------------------------------------------------- 7 | # You must not remove this notice, or any other, from this software. 8 | # ---------------------------------------------------------------------------------------------- 9 | Param( 10 | [string]$SlackToken, 11 | [string]$SlackChannel, 12 | [string]$SiteName, 13 | [string]$Device, 14 | [string]$Name, 15 | [string]$Status, 16 | [string]$Down, 17 | [string]$DateTime, 18 | [string]$LinkDevice, 19 | [string]$Message 20 | ) 21 | 22 | [System.Collections.Specialized.NameValueCollection] $values = New-Object 'System.Collections.Specialized.NameValueCollection' 23 | $values.Add('token', $SlackToken) 24 | $values.Add('channel', $SlackChannel) 25 | $values.Add('unfurl_links','true') 26 | $values.Add('username','PRTG') 27 | $values.Add('icon_url','http://www.paessler.com/static/banner_1s_80x80.png') 28 | $values.Add('text', "*$($sitename)* 29 | <$($LinkDevice)|$($Device) $($Name)> 30 | Status $($Status) $($Down) on $($DateTime) 31 | ``````$($Message)``````") 32 | 33 | [System.Net.WebClient] $webclient = New-Object 'System.Net.WebClient' 34 | $webclient.UploadValues('https://slack.com/api/chat.postMessage', $values) -------------------------------------------------------------------------------- /PRTGSlackWebHookNotificationPSv2.ps1: -------------------------------------------------------------------------------- 1 | # ---------------------------------------------------------------------------------------------- 2 | # Copyright (c) WCOM AB 2016. 3 | # ---------------------------------------------------------------------------------------------- 4 | # This source code is subject to terms and conditions of the The MIT License (MIT) 5 | # copy of the license can be found in the LICENSE file at the root of this distribution. 6 | # ---------------------------------------------------------------------------------------------- 7 | # You must not remove this notice, or any other, from this software. 8 | # ---------------------------------------------------------------------------------------------- 9 | Param( 10 | [string]$SlackWebHook, 11 | [string]$SlackChannel, 12 | [string]$SiteName, 13 | [string]$Device, 14 | [string]$Name, 15 | [string]$Status, 16 | [string]$Down, 17 | [string]$DateTime, 18 | [string]$LinkDevice, 19 | [string]$Message 20 | ) 21 | 22 | Add-Type -AssemblyName System.Web.Extensions 23 | function ConvertTo-Json ([Object] $value) 24 | { 25 | [System.Web.Script.Serialization.JavaScriptSerializer] $jsSerializer = New-Object 'System.Web.Script.Serialization.JavaScriptSerializer' 26 | $jsSerializer.Serialize($value) 27 | } 28 | 29 | $postSlackMessage = ConvertTo-Json(@{ 30 | channel = $SlackChannel; 31 | unfurl_links = "true"; 32 | username = "PRTG"; 33 | icon_url = "http://www.paessler.com/static/banner_1s_80x80.png" 34 | text = "*$($sitename)* 35 | <$($LinkDevice)|$($Device) $($Name)> 36 | Status $($Status) $($Down) on $($DateTime) 37 | ``````$($Message)``````"; 38 | }) 39 | 40 | $postSlackMessage | Out-File -FilePath slack.log 41 | 42 | [System.Net.WebClient] $webclient = New-Object 'System.Net.WebClient' 43 | $webclient.UploadData($SlackWebHook, [System.Text.Encoding]::UTF8.GetBytes($postSlackMessage)) | Out-File -FilePath slack.log -Append -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PRTGSlackNotification 2 | PowerShell script for sending [PRTG Network Monitoring](http://www.paessler.com/prtg) notifications to [Slack](https://slack.com/) channel 3 | 4 | ## Example 5 | ![PRTG Slack Sample Notification](https://raw.githubusercontent.com/WCOMAB/PRTGSlackNotification/master/images/prtgslacksamplenotification.jpg) 6 | 7 | ## Notifications using user token 8 | 9 | ### Installation 10 | Copy the [PRTGSlackNotification.ps1](https://github.com/WCOMAB/PRTGSlackNotification/blob/master/PRTGSlackNotification.ps1) to your `PRTG` installations `Notifications\EXE` folder i.e. `C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE` on your monitoring server. 11 | 12 | ### Configuration 13 | The notification is configured as an `EXECUTE PROGRAM` notifcation with following parameters 14 | ```powershell 15 | -SlackToken '' -SlackChannel '#prtg' -SiteName '%sitename' -Device '%device' -Name '%name' -Status '%status' -Down '%down' -DateTime '%datetime' -LinkDevice '%linkdevice' -Message '%message' 16 | ``` 17 | Replace `-SlackToken` parameter value `` with your `API token` you can find it on the [Slack Web API](https://api.slack.com/web) page. 18 | If you want to post to another channel than `#PRTG`, then just replace `-SlackChannel` parameter value with the channel of your choice. 19 | 20 | ![PRTG Notifications](https://raw.githubusercontent.com/WCOMAB/PRTGSlackNotification/master/images/prtgslacknotificationsettings.png) 21 | 22 | ## Notifications using incoming web hook 23 | Using an incoming web hook is probably the prefered way 24 | 25 | ### Installation 26 | Copy the [PRTGSlackWebHookNotification.ps1](https://github.com/WCOMAB/PRTGSlackNotification/blob/master/PRTGSlackWebHookNotification.ps1) to your `PRTG` installations `Notifications\EXE` folder i.e. `C:\Program Files (x86)\PRTG Network Monitor\Notifications\EXE` on your monitoring server. 27 | 28 | ### Configuration 29 | The notification is configured as an `EXECUTE PROGRAM` notifcation with following parameters 30 | ```powershell 31 | -SlackWebHook '' -SlackChannel '#prtg' -SiteName '%sitename' -Device '%device' -Name '%name' -Status '%status' -Down '%down' -DateTime '%datetime' -LinkDevice '%linkdevice' -Message '%message' 32 | ``` 33 | Replace `-SlackWebHook` parameter value `` with your `Webhook URL` you can setup a new one the [New Slack Incoming WebHook](https://my.slack.com/services/new/incoming-webhook/) page or pick one existing on the [Integrations](https://my.slack.com/services) page by chosing one of the existing `Incoming WebHooks`. 34 | If you want to post to another channel than `#PRTG`, then just replace `-SlackChannel` parameter value with the channel of your choice. 35 | 36 | ![PRTG Notifications](https://raw.githubusercontent.com/WCOMAB/PRTGSlackNotification/master/images/prtgslackwebhooknotificationsettings.png) -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | [Rr]eleases/ 14 | x64/ 15 | x86/ 16 | build/ 17 | bld/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | 21 | # Roslyn cache directories 22 | *.ide/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | 28 | #NUNIT 29 | *.VisualState.xml 30 | TestResult.xml 31 | 32 | # Build Results of an ATL Project 33 | [Dd]ebugPS/ 34 | [Rr]eleasePS/ 35 | dlldata.c 36 | 37 | *_i.c 38 | *_p.c 39 | *_i.h 40 | *.ilk 41 | *.meta 42 | *.obj 43 | *.pch 44 | *.pdb 45 | *.pgc 46 | *.pgd 47 | *.rsp 48 | *.sbr 49 | *.tlb 50 | *.tli 51 | *.tlh 52 | *.tmp 53 | *.tmp_proj 54 | *.log 55 | *.vspscc 56 | *.vssscc 57 | .builds 58 | *.pidb 59 | *.svclog 60 | *.scc 61 | 62 | # Chutzpah Test files 63 | _Chutzpah* 64 | 65 | # Visual C++ cache files 66 | ipch/ 67 | *.aps 68 | *.ncb 69 | *.opensdf 70 | *.sdf 71 | *.cachefile 72 | 73 | # Visual Studio profiler 74 | *.psess 75 | *.vsp 76 | *.vspx 77 | 78 | # TFS 2012 Local Workspace 79 | $tf/ 80 | 81 | # Guidance Automation Toolkit 82 | *.gpState 83 | 84 | # ReSharper is a .NET coding add-in 85 | _ReSharper*/ 86 | *.[Rr]e[Ss]harper 87 | *.DotSettings.user 88 | 89 | # JustCode is a .NET coding addin-in 90 | .JustCode 91 | 92 | # TeamCity is a build add-in 93 | _TeamCity* 94 | 95 | # DotCover is a Code Coverage Tool 96 | *.dotCover 97 | 98 | # NCrunch 99 | _NCrunch_* 100 | .*crunch*.local.xml 101 | 102 | # MightyMoose 103 | *.mm.* 104 | AutoTest.Net/ 105 | 106 | # Web workbench (sass) 107 | .sass-cache/ 108 | 109 | # Installshield output folder 110 | [Ee]xpress/ 111 | 112 | # DocProject is a documentation generator add-in 113 | DocProject/buildhelp/ 114 | DocProject/Help/*.HxT 115 | DocProject/Help/*.HxC 116 | DocProject/Help/*.hhc 117 | DocProject/Help/*.hhk 118 | DocProject/Help/*.hhp 119 | DocProject/Help/Html2 120 | DocProject/Help/html 121 | 122 | # Click-Once directory 123 | publish/ 124 | 125 | # Publish Web Output 126 | *.[Pp]ublish.xml 127 | *.azurePubxml 128 | # TODO: Comment the next line if you want to checkin your web deploy settings 129 | # but database connection strings (with potential passwords) will be unencrypted 130 | *.pubxml 131 | *.publishproj 132 | 133 | # NuGet Packages 134 | *.nupkg 135 | # The packages folder can be ignored because of Package Restore 136 | **/packages/* 137 | # except build/, which is used as an MSBuild target. 138 | !**/packages/build/ 139 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 140 | #!**/packages/repositories.config 141 | 142 | # Windows Azure Build Output 143 | csx/ 144 | *.build.csdef 145 | 146 | # Windows Store app package directory 147 | AppPackages/ 148 | 149 | # Others 150 | sql/ 151 | *.Cache 152 | ClientBin/ 153 | [Ss]tyle[Cc]op.* 154 | ~$* 155 | *~ 156 | *.dbmdl 157 | *.dbproj.schemaview 158 | *.pfx 159 | *.publishsettings 160 | node_modules/ 161 | 162 | # RIA/Silverlight projects 163 | Generated_Code/ 164 | 165 | # Backup & report files from converting an old project file 166 | # to a newer Visual Studio version. Backup files are not needed, 167 | # because we have git ;-) 168 | _UpgradeReport_Files/ 169 | Backup*/ 170 | UpgradeLog*.XML 171 | UpgradeLog*.htm 172 | 173 | # SQL Server files 174 | *.mdf 175 | *.ldf 176 | 177 | # Business Intelligence projects 178 | *.rdl.data 179 | *.bim.layout 180 | *.bim_*.settings 181 | 182 | # Microsoft Fakes 183 | FakesAssemblies/ 184 | --------------------------------------------------------------------------------