mirror of
https://git.adityakumar.xyz/monitor.git/
synced 2024-12-22 14:22:55 +00:00
Compare commits
4 commits
1ae4746b0b
...
4b6da2e46b
Author | SHA1 | Date | |
---|---|---|---|
4b6da2e46b | |||
927be66a48 | |||
311fd173ec | |||
1ca8c4eb55 |
11 changed files with 51 additions and 2023 deletions
|
@ -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
|
|
|
@ -1 +0,0 @@
|
||||||
/nix/store/5w3dp0m37794iffsbm9vd9f1xmmhda6i-source
|
|
|
@ -1 +0,0 @@
|
||||||
/nix/store/a0jhvi8hbgb016p73a2mpfna699387is-source
|
|
|
@ -1 +0,0 @@
|
||||||
/nix/store/na7sykizsgkzh9i3wc8m8pz5xfqib2rv-source
|
|
|
@ -1 +0,0 @@
|
||||||
/nix/store/yj1wxm9hh8610iyzqnz75kvs6xl8j3my-source
|
|
|
@ -1 +0,0 @@
|
||||||
/nix/store/75fzkiz8z119lqmay567h8x3xqdcrq6k-nix-shell-env
|
|
File diff suppressed because it is too large
Load diff
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
result
|
result
|
||||||
|
.direnv
|
||||||
|
|
39
README.md
Normal file
39
README.md
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
# 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,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
|
||||||
|
|
12
monitor.py
12
monitor.py
|
@ -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", "-a", "Monitor", message])
|
||||||
|
|
||||||
|
|
||||||
websites = [
|
websites = [
|
||||||
"https://adityakumar.xyz",
|
"https://adityakumar.xyz",
|
||||||
"https://blog.adityakumar.xyz",
|
"https://blog.adityakumar.xyz",
|
||||||
|
|
Loading…
Reference in a new issue