diff options
Diffstat (limited to 'extra/push-examples')
-rw-r--r-- | extra/push-examples/.gitignore | 3 | ||||
-rw-r--r-- | extra/push-examples/bash-curl/index.sh | 10 | ||||
-rw-r--r-- | extra/push-examples/csharp/index.cs | 24 | ||||
-rw-r--r-- | extra/push-examples/docker/index.sh | 1 | ||||
-rw-r--r-- | extra/push-examples/go/index.go | 20 | ||||
-rw-r--r-- | extra/push-examples/java/index.java | 32 | ||||
-rw-r--r-- | extra/push-examples/javascript-fetch/index.js | 11 | ||||
-rw-r--r-- | extra/push-examples/javascript-fetch/package.json | 5 | ||||
-rw-r--r-- | extra/push-examples/php/index.php | 13 | ||||
-rw-r--r-- | extra/push-examples/powershell/index.ps1 | 9 | ||||
-rw-r--r-- | extra/push-examples/python/index.py | 10 | ||||
-rw-r--r-- | extra/push-examples/typescript-fetch/README.md | 19 | ||||
-rw-r--r-- | extra/push-examples/typescript-fetch/index.ts | 11 | ||||
-rw-r--r-- | extra/push-examples/typescript-fetch/package.json | 13 |
14 files changed, 181 insertions, 0 deletions
diff --git a/extra/push-examples/.gitignore b/extra/push-examples/.gitignore new file mode 100644 index 0000000..717394d --- /dev/null +++ b/extra/push-examples/.gitignore @@ -0,0 +1,3 @@ +java/Index.class +csharp/index.exe +typescript-fetch/index.js diff --git a/extra/push-examples/bash-curl/index.sh b/extra/push-examples/bash-curl/index.sh new file mode 100644 index 0000000..3031255 --- /dev/null +++ b/extra/push-examples/bash-curl/index.sh @@ -0,0 +1,10 @@ +#!/bin/bash +# Filename: index.sh +PUSH_URL="https://example.com/api/push/key?status=up&msg=OK&ping=" +INTERVAL=60 + +while true; do + curl -s -o /dev/null $PUSH_URL + echo "Pushed!" + sleep $INTERVAL +done diff --git a/extra/push-examples/csharp/index.cs b/extra/push-examples/csharp/index.cs new file mode 100644 index 0000000..94eecfb --- /dev/null +++ b/extra/push-examples/csharp/index.cs @@ -0,0 +1,24 @@ +using System; +using System.Net; +using System.Threading; + +/** + * Compile: C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe index.cs + * Run: index.exe + */ +class Index +{ + const string PushURL = "https://example.com/api/push/key?status=up&msg=OK&ping="; + const int Interval = 60; + + static void Main(string[] args) + { + while (true) + { + WebClient client = new WebClient(); + client.DownloadString(PushURL); + Console.WriteLine("Pushed!"); + Thread.Sleep(Interval * 1000); + } + } +} diff --git a/extra/push-examples/docker/index.sh b/extra/push-examples/docker/index.sh new file mode 100644 index 0000000..1eb43d6 --- /dev/null +++ b/extra/push-examples/docker/index.sh @@ -0,0 +1 @@ +docker run -d --restart=always --name uptime-kuma-push louislam/uptime-kuma:push "https://example.com/api/push/key?status=up&msg=OK&ping=" 60 diff --git a/extra/push-examples/go/index.go b/extra/push-examples/go/index.go new file mode 100644 index 0000000..2e518e7 --- /dev/null +++ b/extra/push-examples/go/index.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" + "net/http" + "time" +) + +func main() { + const PushURL = "https://example.com/api/push/key?status=up&msg=OK&ping=" + const Interval = 60 + + for { + _, err := http.Get(PushURL) + if err == nil { + fmt.Println("Pushed!") + } + time.Sleep(Interval * time.Second) + } +} diff --git a/extra/push-examples/java/index.java b/extra/push-examples/java/index.java new file mode 100644 index 0000000..5a77342 --- /dev/null +++ b/extra/push-examples/java/index.java @@ -0,0 +1,32 @@ +import java.net.HttpURLConnection; +import java.net.URL; + +/** + * Compile: javac index.java + * Run: java Index + */ +class Index { + + public static final String PUSH_URL = "https://example.com/api/push/key?status=up&msg=OK&ping="; + public static final int INTERVAL = 60; + + public static void main(String[] args) { + while (true) { + try { + URL url = new URL(PUSH_URL); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("GET"); + con.getResponseCode(); + con.disconnect(); + System.out.println("Pushed!"); + } catch (Exception e) { + e.printStackTrace(); + } + try { + Thread.sleep(INTERVAL * 1000); + } catch (Exception e) { + e.printStackTrace(); + } + } + } +} diff --git a/extra/push-examples/javascript-fetch/index.js b/extra/push-examples/javascript-fetch/index.js new file mode 100644 index 0000000..9d21d0d --- /dev/null +++ b/extra/push-examples/javascript-fetch/index.js @@ -0,0 +1,11 @@ +// Supports: Node.js >= 18, Deno, Bun +const pushURL = "https://example.com/api/push/key?status=up&msg=OK&ping="; +const interval = 60; + +const push = async () => { + await fetch(pushURL); + console.log("Pushed!"); +}; + +push(); +setInterval(push, interval * 1000); diff --git a/extra/push-examples/javascript-fetch/package.json b/extra/push-examples/javascript-fetch/package.json new file mode 100644 index 0000000..78aefc2 --- /dev/null +++ b/extra/push-examples/javascript-fetch/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "start": "node index.js" + } +} diff --git a/extra/push-examples/php/index.php b/extra/push-examples/php/index.php new file mode 100644 index 0000000..d08b451 --- /dev/null +++ b/extra/push-examples/php/index.php @@ -0,0 +1,13 @@ +<?php +const PUSH_URL = "https://example.com/api/push/key?status=up&msg=OK&ping="; +const interval = 60; + +while (true) { + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, PUSH_URL); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_exec($ch); + curl_close($ch); + echo "Pushed!\n"; + sleep(interval); +} diff --git a/extra/push-examples/powershell/index.ps1 b/extra/push-examples/powershell/index.ps1 new file mode 100644 index 0000000..2894e8d --- /dev/null +++ b/extra/push-examples/powershell/index.ps1 @@ -0,0 +1,9 @@ +# Filename: index.ps1 +$pushURL = "https://example.com/api/push/key?status=up&msg=OK&ping=" +$interval = 60 + +while ($true) { + $res = Invoke-WebRequest -Uri $pushURL + Write-Host "Pushed!" + Start-Sleep -Seconds $interval +} diff --git a/extra/push-examples/python/index.py b/extra/push-examples/python/index.py new file mode 100644 index 0000000..c735b29 --- /dev/null +++ b/extra/push-examples/python/index.py @@ -0,0 +1,10 @@ +import urllib.request +import time + +push_url = "https://example.com/api/push/key?status=up&msg=OK&ping=" +interval = 60 + +while True: + urllib.request.urlopen(push_url) + print("Pushed!\n") + time.sleep(interval) diff --git a/extra/push-examples/typescript-fetch/README.md b/extra/push-examples/typescript-fetch/README.md new file mode 100644 index 0000000..c2c96ce --- /dev/null +++ b/extra/push-examples/typescript-fetch/README.md @@ -0,0 +1,19 @@ +# How to run + +Node.js (ts-node) + +```bash +ts-node index.ts +``` + +Deno + +```bash +deno run --allow-net index.ts +``` + +Bun.js + +```bash +bun index.ts +``` diff --git a/extra/push-examples/typescript-fetch/index.ts b/extra/push-examples/typescript-fetch/index.ts new file mode 100644 index 0000000..bb14088 --- /dev/null +++ b/extra/push-examples/typescript-fetch/index.ts @@ -0,0 +1,11 @@ +// Supports: Deno, Bun, Node.js >= 18 (ts-node) +const pushURL : string = "https://example.com/api/push/key?status=up&msg=OK&ping="; +const interval : number = 60; + +const push = async () => { + await fetch(pushURL); + console.log("Pushed!"); +}; + +push(); +setInterval(push, interval * 1000); diff --git a/extra/push-examples/typescript-fetch/package.json b/extra/push-examples/typescript-fetch/package.json new file mode 100644 index 0000000..9d7e974 --- /dev/null +++ b/extra/push-examples/typescript-fetch/package.json @@ -0,0 +1,13 @@ +{ + "scripts": { + "ts-node": "ts-node index.ts", + "deno": "deno run --allow-net index.ts", + "bun": "bun index.ts" + }, + "devDependencies": { + "@types/node": "^20.6.0", + "ts-node": "^10.9.1", + "tslib": "^2.6.2", + "typescript": "^5.2.2" + } +} |