-
Notifications
You must be signed in to change notification settings - Fork 0
/
SlackNotifications.psm1
63 lines (57 loc) · 1.85 KB
/
SlackNotifications.psm1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function Send-SCCMSlackNotification {
[CmdletBinding()]
Param (
[String]$MessageID, #%msgid
[String]$ComputerName, #%msgsys
[String]$Component, #%msgcomp
[String]$Severity,#%msgsev
[String]$MessageDescription, #%msgdesc
[String]$SlackChannel = "#general"
)
Begin {
$SlackWebHook = "https://slack.com/api/chat.postMessage"
$Config = Get-SCCMSlackConfig
$SlackToken = Get-Content "$PSScriptRoot\slack.txt"
If ($Severity) {
$Severity = $Severity.Trim()
}
#Severity icons
If ($Severity -like "E") {
$SeverityIcon = ":x:" #Error
$AttachmentColor = "danger"
}
Elseif ($Severity -like "W") {
$SeverityIcon = ":warning:" #Warning
$AttachmentColor = "warning"
}
Elseif ($Severity -like "I") {
$SeverityIcon = ":information_source:" #Information
$AttachmentColor = "good"
}
}
Process {
$SlackMessage = "$SeverityIcon $($Component):"
$Attachments = @(
@{
title = "$ComputerName reports:";
color = "$AttachmentColor";
text = "$MessageDescription"
}
)
$SlackPost = @{
channel="$SlackChannel";
text="$SlackMessage";
attachments = $Attachments;
username = "SCCM Notifications"
}
$SlackHeader = @{
Authorization = "Bearer $SlackToken";
}
$SlackPostJson = $SlackPost | ConvertTo-Json
Invoke-WebRequest -Body $SlackPostJson -Method Post -Uri $SlackWebHook -Headers $SlackHeader -ContentType "application/json"
}
End {
}
}
Set-Alias -Name Send-SlackTSNotification -Value Send-SCCMSlackNotification
Export-ModuleMember -Alias * -Function *