Function Repository Resource:

URLMonitor (1.0.0) current version: 1.0.1 »

Source Notebook

Deploy a scheduled task for monitoring a URL

Contributed by: Harrison Boon

ResourceFunction["URLMonitor"][url,timespec]

deploys a ScheduledTask to a new anonymous cloud object, that monitors url on the schedule defined by timespec.

ResourceFunction["URLMonitor"][HTTPRequest[], timespec]

deploys a ScheduledTask to a new anonymous cloud object that monitors the HTTPRequest.

ResourceFunction["URLMonitor"][req, timespec, CloudObject[]]

deploys a ScheduledTask to the specified cloud object.

Details and Options

ResourceFunction["URLMonitor"] returns a CloudObject running a ScheduledTask.
In ResourceFunction["URLMonitor"][url, timespec], url can be a string, a URL object or a cloud object.
The URL can also be specified by an HTTPRequest
The following timespec specifications can be given:
periodrun once every period
{period}run once after the period
{period,count}run only count times ever
The following time period specifications can be given:
"Hourly"run once an hour
"Daily"run once a day
"Weekly"run once a week
"Monthly"run once a month
"Yearly"run once a year
Quantity[]run at a specified time interval
ResourceFunction["URLMonitor"] allows the following options:
"Recipients"Automaticstring or list containing emails to which error logs will be sent
"FailureTypes"Automaticlist of numbers representing http codes that are classified as errors that will be logged
"EventLog"NoneCloudObject to which all logs (failure or success) will be
written
"AlertOnChange"Falsewhether to send an email when the monitor detects a change in response status
TimeConstraintInfinitymaximum allotted time in seconds to finish URL request
"LogTemplate""`date`: URL `url` returned status code `status`"message template used for logging all monitor requests
"ErrorMessageSubject""Monitor Error Detected"email subject for an error alert
"ErrorTemplate""URL `url` generated a `status` error at `date`"message template used for error logging
"ChangeNotificationSubject""Monitor Change Detected"email subject for a status change alert
"ChangeNotificationTemplate""`date`: URL `url` change from `previousStatus` to `status`"message template used for status change alerts
With "Recipients"Automatic, the email recipient is set to $CloudUserID
With "FailureTypes"Automatic, the failure types are all numbers from 400-599 inclusive
With "EventLog"None, the monitor will not log anything.

Examples

Basic Examples (2) 

Deploy a monitor for an example URL as a CloudObject, running every hour starting now:

In[1]:=
obj = ResourceFunction["URLMonitor"]["http://example.com", Quantity[1, "Hours"]]
Out[1]=

Delete the scheduled task created in the previous line:

In[2]:=
RemoveScheduledTask[obj]
Out[2]=

Deploy a monitor that tests a URL daily as a CloudObject, sending error reports to a specific email address:

In[3]:=
obj = ResourceFunction["URLMonitor"]["http://example.com", "Daily", "Recipients" -> "errorLog@example.com"]
Out[3]=

Delete the task:

In[4]:=
RemoveScheduledTask[obj]
Out[4]=

Scope (2) 

Deploy a monitor to a named CloudObject (either existing or new):

In[5]:=
obj = ResourceFunction["URLMonitor"]["http://example.com", Quantity[1, "Hours"], CloudObject["example-monitor"]]
Out[5]=

Delete the task:

In[6]:=
RemoveScheduledTask[obj]
Out[6]=

URLMonitor can be passed an HTTPRequest instead of a URL string:

In[7]:=
req = HTTPRequest[<|"Scheme" -> "http", "Domain" -> "www.example.com"|>];
obj = ResourceFunction["URLMonitor"][req, "Weekly"]
Out[8]=

Delete the task:

In[9]:=
RemoveScheduledTask[obj]
Out[9]=

Publisher

Harrison Boon

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.1 – 30 July 2024
  • 1.0.0 – 15 July 2024

Related Resources

License Information