mirror of
https://git.adityakumar.xyz/monitor.git/
synced 2025-01-06 21:22:52 +00:00
Compare commits
No commits in common. "4b6da2e46b439ed74d5cd4334c47e028aa68b240" and "1ae4746b0b94b12988ce06fdff834a51406ecb94" have entirely different histories.
4b6da2e46b
...
1ae4746b0b
11 changed files with 2023 additions and 51 deletions
.direnv
bin
flake-inputs
5w3dp0m37794iffsbm9vd9f1xmmhda6i-sourcea0jhvi8hbgb016p73a2mpfna699387is-sourcena7sykizsgkzh9i3wc8m8pz5xfqib2rv-sourceyj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfaflake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
19
.direnv/bin/nix-direnv-reload
Executable file
19
.direnv/bin/nix-direnv-reload
Executable 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
|
1
.direnv/flake-inputs/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source
Symbolic link
1
.direnv/flake-inputs/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source
|
1
.direnv/flake-inputs/a0jhvi8hbgb016p73a2mpfna699387is-source
Symbolic link
1
.direnv/flake-inputs/a0jhvi8hbgb016p73a2mpfna699387is-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/a0jhvi8hbgb016p73a2mpfna699387is-source
|
1
.direnv/flake-inputs/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
Symbolic link
1
.direnv/flake-inputs/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
|
1
.direnv/flake-inputs/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
Symbolic link
1
.direnv/flake-inputs/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
|
1
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa
Symbolic link
1
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa
Symbolic link
|
@ -0,0 +1 @@
|
|||
/nix/store/75fzkiz8z119lqmay567h8x3xqdcrq6k-nix-shell-env
|
1997
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
Normal file
1997
.direnv/flake-profile-a5d5b61aa8a61b7d9d765e1daf971a9a578f1cfa.rc
Normal file
File diff suppressed because it is too large
Load diff
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1 @@
|
|||
result
|
||||
.direnv
|
||||
|
|
39
README.md
39
README.md
|
@ -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
|
||||
```
|
|
@ -13,7 +13,6 @@
|
|||
inherit system;
|
||||
};
|
||||
buildInputs = with pkgs; [
|
||||
libnotify
|
||||
(python3.withPackages(ps: with ps; [
|
||||
ipython
|
||||
requests
|
||||
|
|
12
monitor.py
12
monitor.py
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue