0 votes

I am setting up a custom script to do a remote web call (HTTP post) using Invoke-Webrequest.

I have it working, but how can I have Adaxes send an email or retry if the remote HTTP server is down or unreachable during the attempted call?

This is the error that would be output from a failed attempt in this case.

Unable to connect to the remote server. For example:

Invoke-WebRequest -URI someunreachable.com

The site has to have a valid DNS name obviously, but let's assume the site does but it is just unreachable for some reason (network, web services down, etc)

by (320 points)

1 Answer

0 votes
by (3.6k points)

Hello,

To send e-mail messages from scripts executed in Adaxes, you can use the SendMail method of the predefined $Context variable. To retry a web request for a certain number of attempts or until it is successful, you can use the following script. In the script:

$waitTimeInterval – specifies how many seconds will the script wait before the next attempt.

$retryCount – specifies the maximum number of attempts.

$waitTimeInterval = 5 # TODO: modify me
$retryCount = 10 # TODO: modify me

do
{
    try
    { 
        $response = Invoke-WebRequest -Uri "http://host.domain.com"
    }
    catch
    {
        $retryCount--
        Start-Sleep -Seconds $waitTimeInterval
    }
}
while ($response.StatusCode -ne 200 -and $retryCount -gt 0)

Please note, that by default, the timeout for PowerShell script execution in Adaxes is 10 minutes. For detailed information, please see https://www.adaxes.com/help/?ManageBusinessRules.IncreaseScriptTimeout.html.

Related questions

0 votes
1 answer

Hi, Is there anyway to get a listing of the currently running jobs? If not, feature request :) Also, when you update the web portal, one feature requested by some of ... (in IE), so users sometimes press multiple times thinking it has failed to run. regards

asked Jun 19, 2013 by firegoblin (1.6k points)
0 votes
1 answer

Hi, I was just wondering if there was a way to force the format of the date picker value in the web approval interface. We have operation that are very time specific ... like that in the web interface. Example of the problem: Thank you, Jean-Simon Tremblay

asked Dec 3, 2021 by jsimon.tremblay (20 points)
0 votes
1 answer

I'm currently receiving the below error when trying to remove or add actions to a web interface's homepage. I only get the error on this specific dashboard, others are ... the web interface there. I'm currently running Adaxes version 2021.1 if that helps

asked May 21, 2021 by richarddewis (260 points)
0 votes
1 answer

Hi team, I have a few questions about approval flows How can I send approval to individual user (stored in an custom attribute)? How can I do actions based on request is ... -> set accountExpire +6 Months if denied -> do nothing and account will expire

asked Mar 13 by wintec01 (1.1k points)
0 votes
1 answer

Hi all, I wanted to ask community if you are experiencing same behavior: Add a primary group owner to a security group in ADAXES console. Make sure Can update membership using ... list is checked? In my case it is CHECKED for some reason. Thanks all!

asked Dec 13, 2023 by mega128 (20 points)
3,346 questions
3,047 answers
7,782 comments
544,986 users