send desktop notification

This commit is contained in:
Aditya 2024-09-11 07:53:02 +05:30
parent 1ae4746b0b
commit 1ca8c4eb55
Signed by: aditya
SSH key fingerprint: SHA256:jL1IvWsjjlPtw6HvDIHfXfhO9IkIokNEyIfuFhSdoyU
10 changed files with 12 additions and 2023 deletions

View file

@ -1,19 +0,0 @@
#!/usr/bin/env bash
set -e
if [[ ! -d "/home/user/dev/monitor" ]]; then
echo "Cannot find source directory; Did you move it?"
echo "(Looking for "/home/user/dev/monitor")"
echo 'Cannot force reload with this script - use "direnv reload" manually and then try again'
exit 1
fi
# rebuild the cache forcefully
_nix_direnv_force_reload=1 direnv exec "/home/user/dev/monitor" true
# Update the mtime for .envrc.
# This will cause direnv to reload again - but without re-building.
touch "/home/user/dev/monitor/.envrc"
# Also update the timestamp of whatever profile_rc we have.
# This makes sure that we know we are up to date.
touch -r "/home/user/dev/monitor/.envrc" "/home/user/dev/monitor/.direnv"/*.rc

View file

@ -1 +0,0 @@
/nix/store/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source

View file

@ -1 +0,0 @@
/nix/store/a0jhvi8hbgb016p73a2mpfna699387is-source

View file

@ -1 +0,0 @@
/nix/store/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source

View file

@ -1 +0,0 @@
/nix/store/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source

View file

@ -1 +0,0 @@
/nix/store/75fzkiz8z119lqmay567h8x3xqdcrq6k-nix-shell-env

1
.gitignore vendored
View file

@ -1 +1,2 @@
result result
.direnv

View file

@ -13,6 +13,7 @@
inherit system; inherit system;
}; };
buildInputs = with pkgs; [ buildInputs = with pkgs; [
libnotify
(python3.withPackages(ps: with ps; [ (python3.withPackages(ps: with ps; [
ipython ipython
requests requests

View file

@ -2,15 +2,19 @@
from datetime import datetime from datetime import datetime
import requests import requests
import subprocess
def check_website(url): def check_website(url):
try: try:
response = requests.get(url) response = requests.get(url)
if response.status_code == 200: if response.status_code == 200:
log_status(f"{url} is up and running.") MESSAGE_UP = f"{url} is up and running"
log_status(MESSAGE_UP)
else: else:
log_status(f"{url} is down. Status code: {response.status_code}") MESSAGE_DOWN = f"{url} is down. Status code: {response.status_code}"
notify_user(MESSAGE_DOWN)
log_status(MESSAGE_DOWN)
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
print(f"Error: {e}") print(f"Error: {e}")
@ -20,6 +24,10 @@ def log_status(message):
log_file.write(f"{datetime.now()} - {message}\n") log_file.write(f"{datetime.now()} - {message}\n")
def notify_user(message):
subprocess.run(["notify-send", "Monitor", message])
websites = [ websites = [
"https://adityakumar.xyz", "https://adityakumar.xyz",
"https://blog.adityakumar.xyz", "https://blog.adityakumar.xyz",