Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:

tests:
runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [ "ubuntu-latest", "macos-latest" ]
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10" ]
fail-fast: false

env:
OS: ${{ matrix.os }}
PYTHON: ${{ matrix.python-version }}

defaults:
run:
shell: bash

name: Python ${{ matrix.python-version }} on ${{ matrix.os }}
steps:

- name: Acquire sources
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: x64
cache: 'pip'
cache-dependency-path: 'setup.py'

- name: Install prerequisites (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt install --yes libsnmp-dev snmp-mibs-downloader

- name: Install prerequisites (macOS)
if: matrix.os == 'macos-latest'
run: |
brew install net-snmp

- name: Run linter
run: |
make lint

- name: Run tests, with coverage
run: |
make test

- name: Upload coverage results to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
env_vars: OS,PYTHON
name: codecov-umbrella
fail_ci_if_error: false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.venv*
__pycache__
*.egg-info
.coverage
coverage.xml
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
$(eval venv := .venv)
$(eval pip := $(venv)/bin/pip)
$(eval python := $(venv)/bin/python)
$(eval black := $(venv)/bin/black)
$(eval isort := $(venv)/bin/isort)
$(eval pytest := $(venv)/bin/pytest)
$(eval twine := $(venv)/bin/twine)
$(eval flake8 := $(venv)/bin/pflake8)
$(eval proselint := $(venv)/bin/proselint)

setup-virtualenv:
@test -e $(python) || python3 -m venv $(venv) || python -m venv $(venv)

format: setup-virtualenv
$(pip) install --requirement=requirements-utils.txt
$(black) .
$(isort) .

lint: setup-virtualenv
$(pip) install --requirement=requirements-utils.txt
$(flake8) --exit-zero *.py
$(MAKE) proselint

proselint:
$(proselint) *.md || true

test: setup-virtualenv
$(pip) install --editable=.[test]
$(pytest)

publish: setup-virtualenv
$(pip) install build twine
$(python) -m build
$(twine) upload --skip-existing --verbose dist/*{.tar.gz,.whl}
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# check_synology [![Release](https://img.shields.io/github/release/wernerfred/check_synology.svg)](https://github.com/wernerfred/check_synology/releases)
# check_synology

[![Tests](https://github.com/wernerfred/check_synology/actions/workflows/tests.yml/badge.svg)](https://github.com/wernerfred/check_synology/actions/workflows/tests.yml)
[![Code coverage](https://codecov.io/gh/wernerfred/check_synology/branch/master/graph/badge.svg)](https://codecov.io/gh/wernerfred/check_synology)
[![Release](https://img.shields.io/github/release/wernerfred/check_synology.svg)](https://github.com/wernerfred/check_synology/releases)


## About
Expand Down Expand Up @@ -80,20 +84,18 @@ ln -s $(which check_synology) /usr/lib/nagios/plugins/check_synology

## Development

For setting up a development sandbox, you might want to follow this walkthrough.
For setting up a development sandbox and running the software tests, you might
want to follow this walkthrough.

Acquire sources:
```shell
git clone https://github.com/wernerfred/check_synology
cd check_synology
make test
```

Install program in development mode into a Python virtual environment:
```shell
python3 -m venv .venv
source .venv/bin/activate
pip install --editable=.
```
By running `make test`, a Python virtual environment will be created within the
`.venv` folder of your working tree. Use `source .venv/bin/activate` to
activate it.

## Contributors ✨

Expand Down
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[tool.black]
line-length = 120

[tool.isort]
profile = "black"
line_length = 120
multi_line_output = 3

[tool.flake8]
max-line-length = 120

[tool.pytest.ini_options]
minversion = "2.0"
addopts = "-rsfEX -p pytester --strict-markers --verbosity=3 --cov --cov-report=term-missing --cov-report=xml"
log_level = "DEBUG"
testpaths = ["testing"]
xfail_strict = true
markers = [
]

[tool.coverage.run]
omit = [
"testing/*",
]

[tool.coverage.report]
fail_under = 0
show_missing = true
5 changes: 5 additions & 0 deletions requirements-utils.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
black
isort
pyproject-flake8
flake8<5
proselint
16 changes: 15 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,30 @@ def read(path):
keywords="synology, synology-diskstation, snmp, snmpv3, monitoring, monitoring-plugin, nagios, icinga2, icinga2-plugin",
py_modules=["check_synology"],
entry_points={"console_scripts": ["check_synology = check_synology"]},
python_requires=">=3.4",
python_requires=">=3.6",
install_requires=["easysnmp>=0.2.6,<1"],
extras_require={
"test": [
"pytest<8",
"pytest-mock<4",
"pytest-cov<4",
"pysnmplib<6",
],
},
classifiers=[
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU Affero General Public License v3",
"Natural Language :: English",
"Operating System :: OS Independent",
"Environment :: Console",
"Programming Language :: Python",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: Implementation :: CPython",
"Intended Audience :: Developers",
"Intended Audience :: Education",
Expand Down
27 changes: 27 additions & 0 deletions testing/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import pytest

from testing.snmp_responder import AuthenticationInformation, MockedSynologyMibController, SnmpResponder


@pytest.fixture
def synology_mock():

auth_info = AuthenticationInformation(
userName="test-user",
authProtocol="MD5",
authKey="test-authkey",
privProtocol="AES128",
privKey="test-privkey",
)

snmpd = SnmpResponder(port=1161, auth_info=auth_info)
# snmpd = SnmpResponder(port=1161, debug_flags=["all"])
# snmpd = SnmpResponder(port=1161, debug_flags=["dsp", "msgproc", "secmod"])

snmpd.setup()
snmpd.create_context(MockedSynologyMibController())
snmpd.start_background()

yield snmpd

snmpd.stop()
Loading