Compare commits

..

No commits in common. "4b6da2e46b439ed74d5cd4334c47e028aa68b240" and "1ae4746b0b94b12988ce06fdff834a51406ecb94" have entirely different histories.

11 changed files with 2023 additions and 51 deletions

19
.direnv/bin/nix-direnv-reload Executable file
View file

@ -0,0 +1,19 @@
#!/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

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

View file

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

View file

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

View file

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

View file

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

File diff suppressed because it is too large Load diff

1
.gitignore vendored
View file

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

View file

@ -1,39 +0,0 @@
# Monitor
Report website's status
## Usage
### Oneshot
```nix
nix run github:akr2002/monitor
```
### Persistent
Add the following line to your `flake.nix`
```nix
inputs.monitor.url = "github/akr2002:monitor";
```
Add the following to your `home.nix`
```nix
systemd.user.timers.monitor = {
Install.WantedBy = [ "timers.target" ];
Timer = {
OnBootSec = "1m";
OnUnitActiveSec = "1m";
Unit = "monitor.service";
};
};
systemd.user.services.monitor = {
Unit = {
Description = "A script to monitor websites.";
};
Install = {
WantedBy = [ "default.target" ];
};
Service = {
ExecStart = "${inputs.monitor.packages.${pkgs.system}.default}/bin/monitor";
};
};
```
Start:
```bash
systemctl --user start mointor.timer
```

View file

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

View file

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