Page 1 of 1

Running a Pascal Script on the start of a profile

Posted: Mon Mar 06, 2023 8:38 pm
by semaj4712
I think I have this code correct, but It does not seem to be triggering or maybe it is, but I cannot tell, ultimately I am not getting the result I would expect on the other end of this request.

Code: Select all

function OnCanRunProfile(const ProfileName: UnicodeString; var PostponeBySeconds: Integer): Boolean;
var
  ntfy_username, ntfy_password, PostData, AdditionalHeaders, URL, Response, ErrorResponse: AnsiString;
  ResultCode: Int64;
begin
  ntfy_username := 'username';
  ntfy_password := 'password';

  PostData := 'Backup of the Master Output share is starting';
  AdditionalHeaders := 'Title: Syncovery Backup Starting...'+#10#13+
                     'Priority: default'+#10#13+
                     'Tags: arrows_counterclockwise'+#10#13+
                     'Authorization: Basic ' + EncodeBase64(ntfy_username + ':' + ntfy_password)+#10#13+
                     'Content-Type: application/x-www-form-urlencoded';

  URL := 'https://ntfy.url.com/Beltzer';

  ResultCode := 0;
  Response := '';
  ErrorResponse := '';
  if SendHTTPRequest('POST', '', AdditionalHeaders, URL, PostData, ResultCode, Response, ErrorResponse) then
  begin
    // HTTP request was successful, do something with the response
  end
  else
  begin
    // HTTP request failed, do something with the error response
  end;

  Result := True; // or False, depending on your requirements
end;
Obviously username, password, and url have been redacted

Please let me know if there is any obvious issues with this code

Re: Running a Pascal Script on the start of a profile

Posted: Mon Mar 06, 2023 8:47 pm
by tobias
Hello,
can you try the following hook instead?

Code: Select all

function OnGetProfilePathBeforeListing(const isRightSide:Boolean;
        var Path,UserName,Password:UnicodeString;
        var AuthKey,AuthKeyPassword:AnsiString;
        var Port:Integer):Boolean;
This will be called as one of the first things when the profile runs. It has the advantage of being able to use the Log function like this:

Log('Calling HTTP Request Now.');

The hook you used is called by the scheduler, which means you can't use the Log function.

Re: Running a Pascal Script on the start of a profile

Posted: Mon Mar 06, 2023 9:27 pm
by semaj4712
Is there something I should be looking for in the logs, I see the Pascal script in the summary, but nothing referencing it other than that

Re: Running a Pascal Script on the start of a profile

Posted: Mon Mar 06, 2023 10:12 pm
by tobias
There should be a line saying:

"Successfully compiled the profile's script."

Other than that, you need to add logging to the script by calling the Log function.

The lines will be in the log file.

Re: Running a Pascal Script on the start of a profile

Posted: Mon Mar 06, 2023 11:25 pm
by semaj4712
I figured out the issue,

+#10#13+

should be

+#13#10+

Re: Running a Pascal Script on the start of a profile

Posted: Mon Mar 06, 2023 11:36 pm
by tobias
True! Should have spotted that myself ...