gavsto/AutomateAPI

Index operation failed

Closed this issue · 5 comments

Trying to run the command Get-AutomateComputer -Online $False | Compare-AutomateControlStatus

image

I used Connect-AutomateAPI and Connect-ControlAPI before. Verified that I have the correct monitor in Automate.

I have the same issue upon using Get-AutomateComputer -Online $False | Compare-AutomateControlStatus

Screenshot

Coincidentally Automate can currently not connect to the control API according to the Dashboard. @DrDoHicky can you confirm that?

It worked a few days ago.

Control's on 20.11.1385.7587 and Automate's on 20.0.342 (Patch 10)

I have confirmed this is a bug, it seems the latest version of Control requires an anti-forgery token. Need to do more investigation on this, DarrenDK posted this up as he'd highlighted a similiar issue with Immybot:

private string _antiForgeryToken;
private async Task RefreshAntiForgeryToken()
{
var antiForgeryResponse = await _client.GetStringAsync("/");
var matchGroups = Regex.Match(antiForgeryResponse, @"""antiForgeryToken"":""(.+?)""")?.Groups;
if (matchGroups?.Count > 0)
{
_antiForgeryToken = matchGroups[1].Value;
}
}
private async Task Post(string route, StringContent content, CancellationToken token)
{
var updatedRoute = ReplaceExtensionId(route);
content.Headers.Add(ApiKeyHeader, Helpers.GetApiToken(_extensionApiKey));
await RefreshAntiForgeryToken();
content.Headers.Add("X-Anti-Forgery-Token", _antiForgeryToken);
var res = await _client.PostAsync(updatedRoute, content, token);
var data = await res.Content.ReadAsStringAsync();
if (data.Contains("Invalid anti-forgery token"))
{
await RefreshAntiForgeryToken();
}
return res;
}

This is going to require a bit of time to fix.

This has been addressed in the large commit today.
Referencing this issue in a branch pull request #53 so that this issue can be closed when the pull is finalized.

Hello,
I believe this still may be an issue, or the Control system I am trying against is too new/old a version? (20.11.1622.7619)
According to fiddler, when calling:

https://control.somedomain.com/App_Extensions/fc234f0e-2e8e-4a1f-b977-ba41b14031f7/ReportService.ashx/GenerateReportForAutomate

Getting an unauthorized response, with a message of: Invalid anti-forgery token.

Make sure that you have the latest from the master branch.
Actually, you might want to pull from the FixVerify branch, since that is where I am developing/troubleshooting/fixing from.