Subject: |
RE: Powershell V2 to get events |
Author: |
Renee Wayland |
Posted: |
2017-07-19 14:31 |
I answered my own question and now have this working. This is not the finished product but it will get the event details for a specific evid.
param($evid,$URL,$username,$password)
$pair = "${username}:${password}"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }
$DATA= '{"evid":"' + $evid + '"}'
$DATA='['+$DATA+']'
$JSON = '{"action":"EventsRouter","method":"detail","data":' + $DATA + ', "tid":1}'
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$URI1 = "$URL/zport/dmd/evconsole_router"
$request = [System.Net.HttpWebRequest]::Create($URI1)
$request.ServicePoint.ConnectionLimit =10;
$conn=$request.ServicePoint.CurrentConnections
$UserAgent = "AO Agent";
$request.UserAgent = $("{0} (PowerShell {1}; .NET CLR {2}; {3})" -f $UserAgent, $(if($Host.Version){$Host.Version}else{"1.0"}),
[Environment]::Version,
[Environment]::OSVersion.ToString().Replace("Microsoft Windows ", "Win"));
$request.PreAuthenticate = $false;
$request.Headers.Add("Authorization", "Basic $base64")
$request.Pipelined = $true;
#$request.UnsafeAuthenticatedConnectionSharing = $true;
$request.AllowAutoRedirect = $true;
$request.Method = "POST";
$request.ContentType = "application/json";
$request.Accept = "application/json";
$request.KeepAlive = $true;
$request.ServicePoint.MaxIdleTime = 5000;
$request.ServicePoint.ConnectionLeaseTimeout = 5000;
$request.ServicePoint.Expect100Continue = "false"
$request.ContentLength = $JSON.Length
write-output "request is"
$request
try
{
$requestStream = $request.GetRequestStream()
$streamWriter = New-Object System.IO.StreamWriter($requestStream)
$streamWriter.Write($JSON)
#$requestStream.Close();
# $streamWriter.Dispose();
}
catch [System.Net.WebException] {
$Request = $_.Exception
Write-host "Exception caught: $Request"
}
finally
{
if ($null -ne $streamWriter) { $streamWriter.Dispose() }
if ($null -ne $requestStream) { $requestStream.Dispose() }
}
$response = $request.GetResponse()
$requestStream = $response.GetResponseStream()
$readStream = New-Object System.IO.StreamReader $requestStream
$results=$readStream.ReadToEnd()
write-output "results"
$results
------------------------------
Renee
------------------------------
Subject: |
RE: Powershell V2 to get events |
Author: |
Jane Curry |
Posted: |
2017-08-02 10:16 |
It isn't in Powershell but Python; however you might look at
https://gist.github.com/jcurry/ebb20c6665ba249bce55 on Gist for a parameterised script to drag events out of Zenoss using the JSON API.
Cheers,
Jane
------------------------------
Jane Curry
Skills 1st United Kingdom
jane.curry@skills-1st.co.uk
------------------------------