This commit is contained in:
Kierre
2025-10-01 18:28:54 -04:00
commit 87499b859e
8 changed files with 216 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
config.toml
+11
View File
@@ -0,0 +1,11 @@
Velicense
Copyright (c) 2025 Kierre Sametti
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
1. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2. Any person or entity releasing a proprietary version of the Software must clearly state, in an easily accessible location, that they are a massive cuck. This statement does not require an explanation of any kind.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+20
View File
@@ -0,0 +1,20 @@
# velping
a pinger. it pings. this is made specifically for my needs, so you can open an issue for a feature request, but i likely won't accept it unless it's something i want.
## configuration options
### frontend
- `name`: what will show as the header on the landing page.
- `port`: what port the frontend will run on.
- `pings`: how many pings to show on the frontend
### pinging
- `allow_empty_responses`: this does NOT mean HTTP 204, but rather if the connection being suddenly closed after a request should be accepted as online. this option only exists because i run a minecraft server.
- `seconds_between_ping`: how often services should be pinged, in seconds.
### ntfy
- `enabled`: whether or not to enable ntfy.
- `server`: the server to send notifications to.
- `topic`: the ntfy topic.
### services
you can add services here, with the name of the key being the name of the service and the value being the URL to ping.
+53
View File
@@ -0,0 +1,53 @@
::selection {
background-color: #eeadb7;
color: #1e1e2e;
}
::-moz-selection {
background-color: #eeadb7;
color: #1e1e2e;
}
body {
font-family: 'Adwaita Mono', monospace;
padding-left: 20px;
padding-top: 10px;
margin: 0;
max-width: 1000px;
background-color: #1e1e2e;
color: #eeadb7;
}
.green, .green::selection, .green::-moz-selection {
color: #5cdd8b;
}
.red, .red::selection, .red::-moz-selection {
color: #dc3545;
}
.grey, .grey::selection, .grey::-moz-selection {
color: #dadada;
}
.service {
width: 400px;
height: 20px;
padding: 10px;
display: flex;
align-items: center;
border-radius: 10px;
}
.service p {
width: 33%
}
.status {
display: flex;
width: 66%
}
.status p {
width: 9px;
}
+16
View File
@@ -0,0 +1,16 @@
[frontend]
port = 4200
name = "velping"
pings = 25
[pinging]
allow_empty_responses = false
seconds_between_ping = 60
[ntfy]
enabled = false
server = "ntfy.sh"
topic = "my_velping_instance"
[services]
Google = "https://google.com/"
+65
View File
@@ -0,0 +1,65 @@
from flask import Flask, send_file, redirect, render_template
import threading
import requests
import logging
import time
import toml
config = toml.load('config.toml')
app = Flask('velping')
logging.disable(logging.CRITICAL)
uptime = {}
def ping(service):
while True:
print(f'[I] Pinging {service}')
try:
resp = requests.get(config['services'][service])
resp.raise_for_status()
if uptime[service][config['frontend']['pings'] - 1] != 'I' and config['ntfy']['enabled']:
requests.post(f'https://{config['ntfy']['server']}/{config['ntfy']['topic']}', data=f'Service {service} is online')
uptime[service].pop(0)
uptime[service].append('I')
print(f'[I] Pinging {service} worked!')
except Exception as e:
if 'Remote end closed connection without response' in str(e) and config['pinging']['allow_empty_responses']:
uptime[service].pop(0)
uptime[service].append('I')
print(f'[I] Pinging {service} worked!')
else:
if uptime[service][config['frontend']['pings'] - 1] != 'O' and config['ntfy']['enabled']:
requests.post(f'https://{config['ntfy']['server']}/{config['ntfy']['topic']}', data=f'Service {service} is offline')
uptime[service].pop(0)
uptime[service].append('O')
print(f'[E] An error happened while pinging for {service}: {e}')
time.sleep(config['pinging']['seconds_between_ping'])
for service in config['services']:
uptime[service] = []
for ping_but_different in range(config['frontend']['pings']):
uptime[service].append('?')
threading.Thread(target=ping, args=(service,)).start()
@app.errorhandler(404)
def not_found(error):
return redirect('/', 303)
@app.errorhandler(500)
def internal_error(error):
return render_template('internal_error.xht', config=config), 500
@app.route('/style.css')
def css():
return send_file('assets/style.css')
@app.route('/')
def root():
return render_template('index.xht', config=config, services=config['services'], uptime=uptime), 200
app.run(port=config['frontend']['port'], host='::')
+33
View File
@@ -0,0 +1,33 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en-gb" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ config['frontend']['name'] }}</title>
<link href="/style.css" rel="stylesheet" />
</head>
<body>
<h2>{{ config['frontend']['name'] }}</h2>
{% for service in services %}
<div class="service">
<p><b>{{ service }}</b></p>
<div class="status">
{% for ping in uptime[service] %}
{% if ping == "I" %}
<p class="green">█</p>
{% elif ping == "O" %}
<p class="red">█</p>
{% else %}
<p class="grey">█</p>
{% endif %}
{% endfor %}
</div>
</div>
{% endfor %}
</body>
</html>
+17
View File
@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en-gb" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>internal error - {{ config['frontend']['name'] }}</title>
<link href="/style.css" rel="stylesheet" />
</head>
<body>
<h2>internal error</h2>
<p>something happened on our end. <a href="/">go home?</a></p>
</body>
</html>