Advertisement
Guest User

Untitled

a guest
Sep 4th, 2018
804
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #region HTML+CSS
  2. $Style = "<Style>"
  3. $Style += "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;Margin-left:50px;}"
  4. $Style += "TH{border-width: 1px;padding: 15px;border-style: solid;border-color: black;background-color:thistle}"
  5. $Style += "TD{border-width: 1px;padding: 2px;border-style: solid;border-color: black}"
  6. $Style += "</style>"
  7. $StaticCSS = @"
  8. <html>
  9. <head>
  10. <style type='text/css'>
  11. div.red { background-color:#B22222;
  12. float:left;
  13. text-align:right;
  14. }
  15. div.green { background-color:#32CD32;
  16. float:left;
  17. }
  18. div.free { background-color:#7FFF00;
  19. float:left;
  20. text-align:right;
  21. }
  22. div.warn { background-color: orange;
  23. float:left;
  24. font-weight: bold;
  25. }
  26. div.urgent { background-color: red;
  27. float:left;
  28. font-weight: bold;
  29. }
  30. div.serverOK{ background-color:#32CD32;
  31. float:left;
  32. }
  33. </style>
  34. </head>
  35. <body>
  36. "@
  37. #endregion
  38.  
  39. $iDandSecret = "SECRETSECRETSECRETSECRETSECRETSECRET=="
  40. $headers = @{ Authorization = "Basic $iDandSecret" }
  41. $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
  42.  
  43. if ($res)
  44. {
  45. $AccessToken = ($res.Content | ConvertFrom-Json) | Select-Object access_token -ExpandProperty access_token
  46.  
  47. $tokenheader = @{ Authorization = "Bearer $AccessToken" }
  48. [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
  49.  
  50. if ($Test)
  51. {
  52. if ($Test.connected_clients.connected_representative)
  53. {
  54. if (($Test.connected_clients.connected_representative.public_display_name).Count -ge "5")
  55. {
  56. $Table = $Test.connected_clients.connected_representative
  57. $Table = $Table | Select-Object id,user_id,username,public_display_name,support_session_count | ConvertTo-Html -Body $Style
  58.  
  59. $HTML = $StaticCSS + $FullReport
  60. $FullReport += "<h1>Bomgar licence threshold reached</h1>"
  61. $FullReport += ConvertTo-Html -Head $Style
  62. $FullReport += "<br>`n"
  63. $FullReport += "<h3>Licence threshold is set to 5, consumers follow;</h3>"
  64. $FullReport += "<br>`n"
  65. $FullReport += $Table
  66.  
  67. $Date = Get-Date -Format dd-MM-hhmm
  68.  
  69. $HTML = $StaticCSS + $FullReport
  70. $Filename = "Bomgar_$Date"
  71. Write-Output "The file name is: $Filename"
  72. $HTML | Out-File "$Filename"
  73.  
  74. if (Test-Path $Filename)
  75. {
  76.  
  77. $EmailContent = Get-Content -Path $Filename
  78.  
  79. $From = "Lowlevel-Alerts@Example.com"
  80. $To = "me@Example.com"
  81. $Subject = "Bomgar Licence $Date"
  82. $Body = $EmailContent
  83. $SMTPServer = "relay.relay.relay"
  84. $SMTPPort = "9999991"
  85. Send-MailMessage -From $From -To $To -Subject $Subject -Body ($EmailContent | Out-String) -SmtpServer $SMTPServer -Port $SMTPPort -UseSsl -BodyAsHtml
  86. Remove-Item $Filename -Force
  87.  
  88. }
  89. else
  90. {
  91. Remove-Item $Filename -Force -ErrorAction SilentlyContinue
  92. }
  93.  
  94. }
  95.  
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement