-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0f8f128
Showing
9 changed files
with
407 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# SPDX-FileCopyrightText: 2025 Ruslan Mstoi <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
name: Python Lint and Test | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python 3.13 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.13' | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Lint | ||
run: | | ||
flake8 . --count --show-source --statistics | ||
isort *.py --diff | ||
- name: Test with pytest | ||
run: | | ||
pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# SPDX-FileCopyrightText: 2025 Ruslan Mstoi <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
name: REUSE Compliance Check | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
reuse-compliance-check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: REUSE Compliance Check | ||
uses: fsfe/reuse-action@v5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
|
||
Copyright (c) 2025 Ruslan Mstoi | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// SPDX-FileCopyrightText: 2025 Ruslan Mstoi <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
= Website monitor | ||
|
||
:toc: | ||
|
||
A program that monitors the availability of many websites over the network, | ||
produces metrics about these and stores the metrics into a PostgreSQL database. | ||
|
||
= Install dependencies | ||
|
||
To install needed Python packages | ||
|
||
`python3 -m pip install -r requirements.txt` | ||
|
||
= Usage | ||
|
||
All of the default configuration settings are in `config.yaml` file. To use different | ||
configuration settings yaml file pass it as an arument of -c option. | ||
|
||
To change PostgreSQL database settings modify db.conninfo and db.table_name | ||
attributes. | ||
|
||
To add new sites to monitor add them to the `sites` list. Set as needed check | ||
interval and regular expression pattern to check in the returned page. | ||
|
||
To start site monitor | ||
|
||
`./wsmon.py` | ||
|
||
Press Ctrl-C to stop `wsmon.py` | ||
|
||
== Site check failure | ||
|
||
If website check fails the error info will be saved to the database. Failing | ||
site will be checked again max_retry times. | ||
|
||
== Unit tests | ||
|
||
Use `pytest` to run unit tests: | ||
|
||
`pytest .` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-FileCopyrightText: 2025 Ruslan Mstoi <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
# database related variables | ||
db: | ||
# name of table used for site monitor results | ||
table_name: "wsmon_results" | ||
|
||
# connection info, parameter to psycopg.AsyncConnection.connect | ||
conninfo: | ||
dbname: "wsmon" | ||
host: "localhost" | ||
port: 5432 | ||
# "user": "user", | ||
# "password": "password", | ||
|
||
# websites to monitor | ||
sites: | ||
- url: "https://www.brokenwebsitedoesnotexist.com" | ||
check_interval: 5 | ||
- url: "https://www.google.com" | ||
check_interval: 10 | ||
pattern: ".*ogle" | ||
- url: "http://python.org" | ||
check_interval: 15 | ||
pattern: "\\d+" | ||
- url: "https://www.yahoo.com" | ||
check_interval: 30 | ||
pattern: "zzz" | ||
- url: "https://github.com" | ||
check_interval: 10 | ||
- url: "https://www.stackoverflow.com" | ||
check_interval: 300 | ||
- url: "https://www.linkedin.com" | ||
check_interval: 100 | ||
|
||
# max time to retry a failing website monitor | ||
max_retry: 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
|
||
# SPDX-FileCopyrightText: 2025 Ruslan Mstoi <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
set -x | ||
|
||
files="wsmon.py test_wsmon.py" | ||
|
||
isort $files | ||
flake8 $files | ||
reuse lint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-FileCopyrightText: 2025 Ruslan Mstoi <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
aiohttp | ||
psycopg | ||
pyyaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# SPDX-FileCopyrightText: 2025 Ruslan Mstoi <[email protected]> | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from wsmon import WSData | ||
|
||
# WSData default test arguments | ||
url = "http://testsite.io" | ||
check_interval = 111 | ||
pattern = r'(.*) example' | ||
|
||
|
||
def test_wsdata_init(): | ||
site = WSData(url, check_interval, pattern) | ||
assert site.url == url | ||
assert site.check_interval == check_interval | ||
assert site.pattern == pattern | ||
|
||
|
||
def test_wsdata_init_default(): | ||
"""Test default arguments""" | ||
site = WSData(url) | ||
assert site.url == url | ||
assert site.check_interval == 5 | ||
assert site.pattern is None | ||
|
||
|
||
def test_wsdata_str(): | ||
site = WSData(url, check_interval, pattern) | ||
expect_str = ("url=%s check_interval=%s pattern=%r" % | ||
(url, check_interval, pattern)) | ||
assert str(site) == expect_str |
Oops, something went wrong.