Automation
How To Set Up Push Notifications In Uptime Kuma To Monitor External Systems

How To Set Up Push Notifications In Uptime Kuma To Monitor External Systems

What I find great about push notifications is I can setup 24hr monitoring of a system without the requirement to always be connected to the network on which the system resides through a VPN connection.

Uptime Kuma is a feature-rich yet simple to use uptime monitoring tool. It will allow you to monitor your servers and services uptime and also notify you in case of downtime. A simple search will find many tutorials and guides on the installation and setup so I won’t be covering that here.

Of the many types of monitoring it supports, it will be the Push Monitor that I will be concentrating on.

Using push monitors you can monitor any servers that aren’t reachable from the internet but are able to reach the internet. Servers behind a NAT, or having outgoing internet access only using a proxy for instance.

Of course, the reverse is also a requirement. Your Uptime Kuma instance must also be visible to the internet. For this you will probably require the use of a reverse proxy manager such as Traefik or Nginx Proxy Manager.

After selecting to ‘Add New Monitor’, select ‘Push’ in the Monitor Type drop down list.

You will then be presented with a Push URL which can be copied to clipboard. This will be required in the next steps in which I’ll cover how to call this URL every 60 seconds on Windows and Linux systems.

Calling Uptime Kuma from Linux based systems

Calling Uptime Kuma from Linux based systems is as simple as setting up a cronjob to curl the provided url every minute.

My preference is to create the cronjob as a file inside the /etc/cron.d directory. This in an example of achieving that from the command line:

echo "* * * * * root curl -sk <paste_url here>" > /etc/cron.d/push_monitor

Calling Uptime Kuma from Windows systems

I’ve tried and tested a couple of methods of achieving this in Windows. The following method of creating a one-line powershell script and then running it as a scheduled task seems to be the most reliable method.

Start by opening notepad and enter the following (replacing <paste_url_here> with the provide url from Uptime Kuma):
Invoke-WebRequest -URI "<paste_url_here>"

Save as a .ps1 file in a directory of your choosing. For simplicity, I will save it in the users documents folder.
C:\Users\<user>\Documents with the filename push_monitor.ps1

The next step is to create the scheduled task that will run the script every 1 minute.
Whilst this can be done manually using the task scheduler user interface (type taskschd.msc at the run command), I have provided some powershell code that can be used to achieve this.

Open an elevated powershell window and copy/paste the following (replace the working directory path on the first line with the correct path to your user documents).

$action = New-ScheduledTaskAction `
	-Execute 'powershell.exe' `
	-Argument '-NoProfile -ExecutionPolicy Bypass -File .\push_monitor.ps1' `
	-WorkingDirectory 'C:\Users\<user>\Documents'
	# Replace working directory with correct path
$trigger1 = New-ScheduledTaskTrigger `
	-Daily `
	-At (Get-Date)
$trigger_interval = New-ScheduledTaskTrigger `
	-Once `
	-At (Get-Date) `
	-RepetitionInterval (New-TimeSpan -Minutes 1)
$trigger1.Repetition = $trigger_interval.Repetition
$trigger2 = Get-CimClass "MSFT_TaskRegistrationTrigger" `
    -Namespace "Root/Microsoft/Windows/TaskScheduler"
$principal = New-ScheduledTaskPrincipal `
	-UserID "NT AUTHORITY\SYSTEM" `
	-LogonType ServiceAccount `
	-RunLevel Highest
$settings = New-ScheduledTaskSettingsSet `
	-MultipleInstances IgnoreNew `
	-DontStopOnIdleEnd `
	-Hidden
Register-ScheduledTask `
	-TaskName 'Push Monitor' `
	-Action $action `
	-Trigger @($trigger1, $trigger2) `
	-Settings $settings `
	-Principal $principal

Leave a Reply

Your email address will not be published. Required fields are marked *