Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region HTML+CSS
- $Style = "<Style>"
- $Style += "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;Margin-left:50px;}"
- $Style += "TH{border-width: 1px;padding: 15px;border-style: solid;border-color: black;background-color:thistle}"
- $Style += "TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black}"
- $Style += "</style>"
- $StaticCSS = @"
- <html>
- <head>
- <style type='text/css'>
- div.red { background-color:#B22222;
- float:left;
- text-align:right;
- }
- div.green { background-color:#32CD32;
- float:left;
- }
- div.free { background-color:#7FFF00;
- float:left;
- text-align:right;
- }
- div.warn { background-color: orange;
- float:left;
- font-weight: bold;
- }
- div.urgent { background-color: red;
- float:left;
- font-weight: bold;
- }
- div.serverOK{ background-color:#32CD32;
- float:left;
- }
- </style>
- </head>
- <body>
- "@
- #endregion
- $iDandSecret = "SECRETSECRETSECRETSECRETSECRETSECRET=="
- $headers = @{ Authorization = "Basic $iDandSecret" }
- $res = Invoke-WebRequest -Uri "https://bomgar.example.com/oauth2/token" -Headers $headers -Body grant_type=client_credentials -ContentType application/x-www-form-urlencoded -Method Post
- if ($res)
- {
- $AccessToken = ($res.Content | ConvertFrom-Json) | Select-Object access_token -ExpandProperty access_token
- $tokenheader = @{ Authorization = "Bearer $AccessToken" }
- [xml]$Test = Invoke-WebRequest -Uri "https://bomgar.example.com/api/command?action=get_connected_clients&type=representative" -Headers $tokenheader -ContentType application/x-www-form-urlencoded -Method Post
- if ($Test)
- {
- if ($Test.connected_clients.connected_representative)
- {
- if (($Test.connected_clients.connected_representative.public_display_name).Count -ge "5")
- {
- $Table = $Test.connected_clients.connected_representative
- $Table = $Table | Select-Object id,user_id,username,public_display_name,support_session_count | ConvertTo-Html -Body $Style
- $HTML = $StaticCSS + $FullReport
- $FullReport += "<h1>Bomgar licence threshold reached</h1>"
- $FullReport += ConvertTo-Html -Head $Style
- $FullReport += "<br>`n"
- $FullReport += "<h3>Licence threshold is set to 5, consumers follow;</h3>"
- $FullReport += "<br>`n"
- $FullReport += $Table
- $Date = Get-Date -Format dd-MM-hhmm
- $HTML = $StaticCSS + $FullReport
- $Filename = "Bomgar_$Date"
- Write-Output "The file name is: $Filename"
- $HTML | Out-File "$Filename"
- if (Test-Path $Filename)
- {
- $EmailContent = Get-Content -Path $Filename
- $From = "Lowlevel-Alerts@Example.com"
- $To = "me@Example.com"
- $Subject = "Bomgar Licence $Date"
- $Body = $EmailContent
- $SMTPServer = "relay.relay.relay"
- $SMTPPort = "9999991"
- Send-MailMessage -From $From -To $To -Subject $Subject -Body ($EmailContent | Out-String) -SmtpServer $SMTPServer -Port $SMTPPort -UseSsl -BodyAsHtml
- Remove-Item $Filename -Force
- }
- else
- {
- Remove-Item $Filename -Force -ErrorAction SilentlyContinue
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement