initial commit

This commit is contained in:
Aditya 2024-09-10 19:44:33 +05:30
commit fde7ce49be
Signed by: aditya
SSH key fingerprint: SHA256:jL1IvWsjjlPtw6HvDIHfXfhO9IkIokNEyIfuFhSdoyU
12 changed files with 2163 additions and 0 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
.envrc Normal file
View file

@ -0,0 +1 @@
use flake

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
result

61
flake.lock Normal file
View file

@ -0,0 +1,61 @@
{
"nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1725634671,
"narHash": "sha256-v3rIhsJBOMLR8e/RNWxr828tB+WywYIoajrZKFM+0Gg=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "574d1eac1c200690e27b8eb4e24887f8df7ac27c",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

47
flake.nix Normal file
View file

@ -0,0 +1,47 @@
{
inputs = {
nixpkgs = {
url = "github:nixos/nixpkgs/nixos-unstable";
};
flake-utils = {
url = "github:numtide/flake-utils";
};
};
outputs = { nixpkgs, flake-utils, self, ... }: flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
};
buildInputs = with pkgs; [
(python3.withPackages(ps: with ps; [
ipython
requests
]))
];
monitor = pkgs.stdenv.mkDerivation {
name = "monitor";
propagatedBuildInputs = buildInputs;
dontUnpack = true;
installPhase = "install -Dm755 ${./monitor.py} $out/bin/monitor";
};
in rec {
devShell = pkgs.mkShell {
buildInputs = buildInputs;
shellHook = "";
};
systemd.services.monitor = {
enable = true;
description = "Monitor website uptime";
wantedBy = [ "multi-user.target" ];
unitConfig = {
Type = "sinmple";
};
serviceConfig = {
execStart = "${self.monitor}";
};
};
packages.default = monitor;
}
);
}

32
monitor.py Normal file
View file

@ -0,0 +1,32 @@
#!/usr/bin/env python
from datetime import datetime
import requests
def check_website(url):
try:
response = requests.get(url)
if response.status_code == 200:
log_status(f"{url} is up and running.")
else:
log_status(f"{url} is down. Status code: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
def log_status(message):
with open("/home/user/.logs/monitor.log", "a+") as log_file:
log_file.write(f"{datetime.now()} - {message}\n")
websites = [
"https://adityakumar.xyz",
"https://blog.adityakumar.xyz",
"https://git.adityakumar.xyz",
"https://forgejo.adityakumar.xyz",
"https://dsa.adityakumar.xyz",
]
for website in websites:
check_website(website)