Skip to content

Commit

Permalink
updates to alerts
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Dec 30, 2023
1 parent 4240592 commit 4a8cd41
Show file tree
Hide file tree
Showing 5 changed files with 287 additions and 201 deletions.
9 changes: 3 additions & 6 deletions ExecScheduledCommand/run.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ Write-Host 'started task'
try {
try {
$results = & $QueueItem.command @commandParameters
}
catch {
} catch {
$results = "Task Failed: $($_.Exception.Message)"

}
Expand All @@ -31,8 +30,7 @@ try {
if ($StoredResults.Length -gt 64000 -or $task.Tenant -eq 'AllTenants') {
$StoredResults = @{ Results = 'The results for this query are too long to store in this table, or the query was meant for All Tenants. Please use the options to send the results to another target to be able to view the results. ' } | ConvertTo-Json -Compress
}
}
catch {
} catch {
$errorMessage = $_.Exception.Message
if ($task.Recurrence -gt 0) { $State = 'Failed - Planned' } else { $State = 'Failed' }
Update-AzDataTableEntity @Table -Entity @{
Expand Down Expand Up @@ -71,8 +69,7 @@ if ($task.Recurrence -le '0' -or $task.Recurrence -eq $null) {
Results = "$StoredResults"
TaskState = 'Completed'
}
}
else {
} else {
$nextRun = (Get-Date).AddDays($task.Recurrence)
$nextRunUnixTime = [int64]($nextRun - (Get-Date '1/1/1970')).TotalSeconds
Update-AzDataTableEntity @Table -Entity @{
Expand Down
29 changes: 2 additions & 27 deletions Modules/CIPPCore/Public/Get-CIPPGeoIPLocation.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,7 @@ function Get-CIPPGeoIPLocation {
param (
[string]$IP
)

if ($IP -match '^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:\d+$') {
$IP = $IP -replace ':\d+$', '' # Remove the port number if present
}

$partitionKey = "GeoIP"
$IPAsint = [System.Numerics.BigInteger]::Zero
$ipAddress = [System.Net.IPAddress]::Parse($IP)
if ($ipAddress.AddressFamily -eq [System.Net.Sockets.AddressFamily]::InterNetworkV6) {
$partitionKey = "GeoIPv6"
$bytes = $ipAddress.GetAddressBytes()
for ($i = 0; $i -lt $bytes.Length; $i++) {
$IPAsint = $IPAsint -shl 8 -bor $bytes[$i]
}
}
else {
$IP.Split(".") | ForEach-Object {
$IPAddressByte = 0
[int]::TryParse($_, [ref] $IPAddressByte) | Out-Null
$IPAsint = ([long]($IPAsint -shl 8)) -bor [byte]$_
}
}

$CTX = New-AzDataTableContext -TableName geoipdb -ConnectionString 'TableEndpoint=https://cyberdraingeoipdb.table.core.windows.net/;SharedAccessSignature=sv=2022-11-02&ss=t&srt=o&sp=rl&se=2025-08-08T21:05:23Z&st=2023-08-08T13:05:23Z&spr=https&sig=89Bmk2Un89xqNzZPLkryFnLRCjHs9rCWGUJjhvf5mso%3D'
$GeoTable = @{ Context = $CTX }
$location = (Get-CIPPAzDataTableEntity @GeoTable -Filter "PartitionKey eq '$partitionKey' and RowKey le '$IPAsint' and ipTo ge '$IPAsint'") | Select-Object -Last 1

$location = Invoke-RestMethod "https://geoipdb.azurewebsites.net/api/GetIPInfo?IP=$IP"
if ($location.status -eq 'FAIL') { throw "Could not get location for $IP" }
return $location
}
Loading

0 comments on commit 4a8cd41

Please sign in to comment.