-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathping-monitor.ps1
53 lines (47 loc) · 1.37 KB
/
ping-monitor.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
53
# About: Script to ping a list of servers and log faults to Kibana/Logstash via http endpoint
# Author: Qulle
# Date: 2024-02-15
# Version: 1.0.0
$env = @{
test = "https://001.localhost:1234";
prod = "https://002.localhost:1234";
};
$endpoint = $env.test;
$headers = @{
"Accept" = "application/json";
"Content-Type" = "application/json";
};
$hostnames = @(
"SERVER001",
"SERVER002",
"SERVER003",
"COMPUTER001",
"COMPUTER002"
);
foreach($hostname in $hostnames) {
if(-not(
Test-Connection $hostname -Count 1 -ErrorAction SilentlyContinue
)) {
$timestamp = (Get-Date -Format "yyyy-MM-ddTHH:mm:ssK:fff").ToString();
$message = [ordered]@{
info = "Host not responding to PING";
pingedHostname = $hostname;
reportedBy = $env:computername;
} | ConvertTo-Json -Compress;
$body = @{
fields = @{
site = "company";
team = "maintenance";
application = "ping-monitor";
};
log = @{
level = "Error";
};
origin = "ping-monitor.ps1";
method = "script";
message = $message;
timestamp = $timestamp;
} | ConvertTo-Json;
Invoke-WebRequest -Uri $endpoint -Method POST -Body $body -Headers $headers | Out-Null;
}
}