-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_slack_mail.ps1
52 lines (37 loc) · 1012 Bytes
/
send_slack_mail.ps1
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
. .\config.ps1
# send Slack notification
function Send-SlackNotification {
param (
[string]$message
)
$payload = @{
text = $message
} | ConvertTo-Json
Invoke-RestMethod -Uri $global:SlackWebhookUrl -Method Post -ContentType 'application/json' -Body $payload
}
# Function to send email notification
function Send-EmailNotification {
param (
[string]$message
)
$smtpBody = @{
To = $global:SmtpTo
From = $global:SmtpFrom
Subject = $global:SmtpSubject
Body = $message
SmtpServer = $global:SmtpServer
}
Send-MailMessage @smtpBody
}
# send alerts
function Send-Alert {
param (
[string]$message
)
Send-SlackNotification -message $message
Send-EmailNotification -message $message
}
# Message content
$message = "Alert: The system has been isolated due to more than 6 failed login attempts. Please love over this ip:192.168.112.23"
# Send the alert
Send-Alert -message $message