Powershell - Get profile status

English Support for Syncovery on Windows.
Post Reply
redone
Posts: 1
Joined: Thu Jun 08, 2023 3:14 pm

Powershell - Get profile status

Post by redone »

Hey there,

is there any way to get the current sync-profile status with powershell?

We know, there is a monitoring possibility in syncovery, but we want a solution, which works independently of the configuration from syncovery.

Thanks!

tobias
Posts: 1668
Joined: Tue Mar 31, 2020 7:37 pm

Re: Powershell - Get profile status

Post by tobias »

Hello,
you can turn on the web GUI on the Cloud tab sheet in Syncovery (in the Windows version) and then access
http://localhost:8999/profilelist.json

You can also have the program send HTTP requests with status info.

One way is using a PascalScript: https://www.syncovery.com/pascalscript/
Here's two example scripts, which you can add via Program Settings -> Advanced -> Global PascalScript in Syncovery.

The first one posts progress info via HTTP. It requires Syncovery 10.5.7 or later:

Code: Select all

const NotifyURL='https://www.syncovery.com/notify.php';
      APIKey='xjhbdflgiuhdagluydfbydfvfg';

var lastprogress:Double;

function OnProgress(const ProfileName,ProgressText:UnicodeString):Boolean;
var OK:Boolean;
    ResultCode:Int64;
    PostData,Response,ErrorResponse:AnsiString;
begin
  if NowUTC<lastprogress+1/24/60 then
     Exit;

  lastprogress:=NowUTC;
  
  PostData:='{'+
        '  "alerts":['+
        '    {'+
        '      "alerttoolname":"Syncovery",'+
        '      "title":"Progress for '+ProfileName+'",'+
        '      "body":"'+ProgressText+'"'+
        '    }'+
        '  ]'+
        '}';

  OK:=SendHTTPRequest('POST',
                      'application/json',
                      'Authorization: Basic '+APIKey,
                      NotifyURL,
                      PostData,
                      ResultCode,
                      Response,
                      ErrorResponse);
  end;
The second one posts the final profile results via HTTP:

Code: Select all

const NotifyURL='https://www.syncovery.com/notify.php';
      APIKey='xjhbdflgiuhdagluydfbydfvfg';


function OnProfileResults(const FilesCopiedL2R,FilesCopiedR2L:Integer;
        const FilesToCopyL2R,FilesToCopyR2L:Integer;
        const BytesCopiedL2R,BytesCopiedR2L:Int64;
        const ResultString:UnicodeString;
        const Error:Boolean):Boolean;
var OK:Boolean;
    ResultCode:Int64;
    PostData,Response,ErrorResponse:AnsiString;
begin

  PostData:='{'+
        '  "alerts":['+
        '    {'+
        '      "alerttoolname":"Syncovery",'+
        '      "title":"Job Result for '+ProfileName+'",'+
        '      "body":"'+ResultString+'",';

  if Error then
     PostData:=PostData+
        '      "severity":1'
  else
     PostData:=PostData+
        '      "severity":0';

  PostData:=PostData+
        '    }'+
        '  ]'+
        '}';

  OK:=SendHTTPRequest('POST',
                      'application/json',
                      'Authorization: Basic '+APIKey,
                      NotifyURL,
                      PostData,
                      ResultCode,
                      Response,
                      ErrorResponse);
  end;

The other way to send HTTP status is built-in, documentation below.

You need to add these lines to the [Main] section of the BackupClient.ini file:
SendProgressStatusURL=https://your.reporting.url/yourscript.php
SendProgressStatusFormat=JSON
SendProgressStatusUsername=xxxxx
SendProgressStatusPassword=yyyyyy
SendProgressStatusDeviceID=item-agent-test01

It will send various events as JSON info. Some of them you will want to ignore, others you will want to process.

One JSON field is the eventCategory. These are the numbers:
lcServiceStartStop=1;
lcSchedulerStartStop=2;
lcServiceError=3;
lcApplicationError=4;
lcGeneralWarnings=5;
lcProfileStarted=6;
lcProfileCompletedWithoutErrors=7;
lcProfileCompletedWithErrors=8;
lcProfileRunGeneralError=9;
lcProfileRunWarnings=10;
lcProfileModified=11;

There are also msgNumbers but I don't have a list, you will see. They correspond to the text in the description.

For lcProfileStarted and lcProfileModified, the eventDescr contains one line of plain text, then an empty line, and then the profile XML.

Post Reply