-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathits_alive.ps1
71 lines (59 loc) · 1.62 KB
/
its_alive.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
$cfg = Get-Content "./config.json" | ConvertFrom-Json
$watch_requests = Import-Csv -Path $cfg.watch_file
function Send-Pushover {
param (
# The API key for Pushover
[Parameter(Mandatory)]
[string]
$APIKey,
# API URL
[Parameter(Mandatory)]
[string]
$URL,
# The API user identifier key.
[Parameter(Mandatory)]
[string]
$APIUserKey,
# Device name / type.
[Parameter()]
[string]
$Device,
# Title
[Parameter(Mandatory)]
[string]
$Title,
# Message
[Parameter(Mandatory)]
[string]
$Message
)
$rest_params = @{
Method = "Post"
URI = "$URL"
StatusCodeVariable = "scv"
Body = @{
"token" = $APIKey
"user" = $APIUserKey
"device" = $Device
"title" = $Title
"message" = $Message
}
}
$rest_result = Invoke-RestMethod @rest_params
Return $result
}
foreach ( $row in $watch_requests ) {
if ( $row.Status -eq "Watching" ) {
$result = ping $row.IP -c 1
$code = $?
if ( $code ) {
$row.LastResult = "Alive"
$row.Status = "Done"
Send-Pushover -APIKey $cfg.api_key -APIUserKey $cfg.user_key -URL $cfg.api_url -Device "iphone" -Title "It's Alive!" -Message "$($row.Name) is alive and responding to pings!"
}
else {
$row.LastResult = "Failed"
}
}
}
$watch_requests | Export-Csv -Path $cfg.watch_file -NoTypeInformation