diff --git a/README.md b/README.md index e69de29..f929963 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,67 @@ +# lego-monitoring + +Simple system monitoring service. Sends alerts in Telegram. Currently supports monitoring: +* CPU/RAM/network usage +* temperature readings +* [vulnix](https://github.com/nix-community/vulnix) readings (NixOS only) + +## Setup + +### NixOS + +Only flake-based setups are supported. + +Include the module in your `flake.nix`: + +```nix +{ + inputs = { + # ... your other inputs ... + lego-monitoring = { + url = "git+https://gitlab.altau.su/lego/lego-monitoring.git"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { + nixpkgs, + lego-monitoring, + ... + }: { + # change `yourhostname` to your actual hostname + nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem { + # change to your system: + system = "x86_64-linux"; + modules = [ + lego-monitoring.nixosModules.default + ./configuration.nix + # ... your other modules ... + ]; + }; + }; +} +``` + +See [docs/nixos-options.md](docs/nixos-options.md) for available configuration options. + +### Non-NixOS + +Requires [uv](https://github.com/astral-sh/uv), systemd. + +```bash +cd /opt +git clone https://gitlab.altau.su/lego/lego-monitoring.git +cd lego-monitoring +uv sync +cp config.example.json config.json +``` + +Edit `config.json` to suit your usage scenario. The default configuration only sends alerts on service's start and stop. +You may refer to the NixOS option documentation, as its options are the same, except JSON uses snake_case instead of lowerCamelCase. + +Then enable and start the service: + +```bash +ln -s /opt/lego-monitoring/lego-monitoring.service /etc/systemd/system/lego-monitoring.service +systemctl enable --now lego-monitoring +``` diff --git a/config.example.json b/config.example.json new file mode 100644 index 0000000..b875087 --- /dev/null +++ b/config.example.json @@ -0,0 +1,15 @@ +{ + "log_level": "INFO", + "enabled_check_sets": [ + "start", + "stop", + "remind" + ], + "telegram": { + "creds_secret_path": "/opt/lego-monitoring/tg-creds.txt", + "roomId": "0" + }, + "checks": { + + } +} diff --git a/docs/nixos-options.md b/docs/nixos-options.md index 296d9c6..63bb9f9 100644 --- a/docs/nixos-options.md +++ b/docs/nixos-options.md @@ -28,7 +28,16 @@ boolean -List of enabled check sets\. Each check set is a module which checks something and generates alerts based on check results\. +List of enabled check sets\. Each check set is a module which checks something and generates alerts based on check results\. Available check sets: + + - start – send an alert when lego-monitoring is started + - stop – send an alert when lego-monitoring is stopped + - remind – periodically (daily by default) remind about ongoing unresolved alerts + - cpu – alerts when CPU usage is above threshold + - ram – alerts when RAM usage is above threshold + - temp – alerts when temperature readings are above thresholds + - net – alerts when network usage is above threshold + - vulnix – periodically scans system for known CVEs, alerts if any are found (NixOS only) diff --git a/lego-monitoring.service b/lego-monitoring.service new file mode 100644 index 0000000..8d5db50 --- /dev/null +++ b/lego-monitoring.service @@ -0,0 +1,12 @@ +[Unit] +Description=Lego-monitoring service +StartLimitBurst=3 +StartLimitIntervalSec=20 + +[Service] +ExecStart=/opt/lego-monitoring/.venv/bin/lego-monitoring -c /opt/lego-monitoring/config.json +Restart=on-failure +RestartSec=5 + +[Install] +WantedBy=multi-user.target diff --git a/modules/options.nix b/modules/options.nix index 6cf9a24..ad92929 100644 --- a/modules/options.nix +++ b/modules/options.nix @@ -38,7 +38,16 @@ in "vulnix" ]); default = [ ]; - description = "List of enabled check sets. Each check set is a module which checks something and generates alerts based on check results."; + description = '' + List of enabled check sets. Each check set is a module which checks something and generates alerts based on check results. Available check sets: + * start -- send an alert when lego-monitoring is started + * stop -- send an alert when lego-monitoring is stopped + * remind -- periodically (daily by default) remind about ongoing unresolved alerts + * cpu -- alerts when CPU usage is above threshold + * ram -- alerts when RAM usage is above threshold + * temp -- alerts when temperature readings are above thresholds + * net -- alerts when network usage is above threshold + * vulnix -- periodically scans system for known CVEs, alerts if any are found (NixOS only)''; }; telegram = { diff --git a/pyproject.toml b/pyproject.toml index b28402e..f12c2d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "lego-monitoring" -version = "0.1.0" +version = "1.0.0" description = "Monitoring software for the lego server" readme = "README.md" requires-python = ">=3.12" diff --git a/uv.lock b/uv.lock index bc590c7..16c8603 100644 --- a/uv.lock +++ b/uv.lock @@ -22,7 +22,7 @@ wheels = [ [[package]] name = "lego-monitoring" -version = "0.1.0" +version = "1.0.0" source = { editable = "." } dependencies = [ { name = "alt-utils" },