Compare commits
2 commits
2023.12.19
...
main
Author | SHA1 | Date | |
---|---|---|---|
437e16f327 | |||
bf26acb831 |
8 changed files with 179 additions and 103 deletions
83
.forgejo/workflows/release.yaml
Normal file
83
.forgejo/workflows/release.yaml
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
---
|
||||||
|
name: Build and publish Debian package
|
||||||
|
on: [create]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/brenard/debian-python-deb:latest
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Build Debian package
|
||||||
|
env:
|
||||||
|
MAINTAINER_NAME: ${{ vars.MAINTAINER_NAME }}
|
||||||
|
MAINTAINER_EMAIL: ${{ vars.MAINTAINER_EMAIL }}
|
||||||
|
DEBIAN_CODENAME: ${{ vars.DEBIAN_CODENAME }}
|
||||||
|
run: |
|
||||||
|
echo "${{ secrets.GPG_KEY }}"|base64 -d|gpg --import
|
||||||
|
./build.sh
|
||||||
|
rm -fr dist/check_syncthing-*
|
||||||
|
mv check_syncthing dist/
|
||||||
|
- name: Upload Debian package files
|
||||||
|
uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
path: dist
|
||||||
|
|
||||||
|
publish-forgejo:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/brenard/debian-python-deb:latest
|
||||||
|
steps:
|
||||||
|
- name: Download Debian package files
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
|
||||||
|
- name: Create the release
|
||||||
|
id: create-release
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
mkdir release
|
||||||
|
mv *.deb release/
|
||||||
|
mv check_syncthing release/
|
||||||
|
md5sum release/* > md5sum.txt
|
||||||
|
sha512sum release/* > sha512sum.txt
|
||||||
|
mv md5sum.txt sha512sum.txt release/
|
||||||
|
{
|
||||||
|
echo 'release_note<<EOF'
|
||||||
|
cat release_notes.md
|
||||||
|
echo 'EOF'
|
||||||
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Publish release on Forgejo
|
||||||
|
uses: actions/forgejo-release@v1
|
||||||
|
with:
|
||||||
|
direction: upload
|
||||||
|
url: https://gitea.zionetrix.net
|
||||||
|
token: ${{ secrets.forgejo_token }}
|
||||||
|
release-dir: release
|
||||||
|
release-notes: ${{ steps.create-release.outputs.release_note }}
|
||||||
|
|
||||||
|
publish-aptly:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/brenard/aptly-publish:latest
|
||||||
|
steps:
|
||||||
|
- name: "Download Debian package files"
|
||||||
|
uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: dist
|
||||||
|
|
||||||
|
- name: "Publish Debian package on Aptly repository"
|
||||||
|
uses: https://gitea.zionetrix.net/bn8/aptly-publish@master
|
||||||
|
with:
|
||||||
|
api_url: ${{ vars.apt_api_url }}
|
||||||
|
api_username: ${{ vars.apt_api_username }}
|
||||||
|
api_password: ${{ secrets.apt_api_password }}
|
||||||
|
repo_name: ${{ vars.apt_repo_name }}
|
||||||
|
path: "./"
|
||||||
|
source_name: ${{ vars.apt_source_name }}
|
21
.forgejo/workflows/tests.yaml
Normal file
21
.forgejo/workflows/tests.yaml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
---
|
||||||
|
name: Run tests
|
||||||
|
on: [push]
|
||||||
|
jobs:
|
||||||
|
test-precommit:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: docker.io/brenard/python-pre-commit:latest
|
||||||
|
steps:
|
||||||
|
- name: Check out repository code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Install python dependencies
|
||||||
|
env:
|
||||||
|
DEBIAN_FRONTEND: noninteractive
|
||||||
|
run: |
|
||||||
|
apt-get -qq update
|
||||||
|
apt-get -qq -y install --no-install-recommends python3-requests python3-dateutil
|
||||||
|
- name: Run pre-commit
|
||||||
|
run: pre-commit run --all-files
|
|
@ -1,37 +1,64 @@
|
||||||
# Pre-commit hooks to run tests and ensure code is cleaned.
|
# Pre-commit hooks to run tests and ensure code is cleaned.
|
||||||
# See https://pre-commit.com for more information
|
# See https://pre-commit.com for more information
|
||||||
|
---
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: v3.15.0
|
rev: v0.1.6
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: ruff
|
||||||
args: ['--keep-percent-format', '--py37-plus']
|
args: ["--fix"]
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
rev: 23.11.0
|
rev: v3.15.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: pyupgrade
|
||||||
args: ['--target-version', 'py37', '--line-length', '100']
|
args: ["--keep-percent-format", "--py37-plus"]
|
||||||
- repo: https://github.com/PyCQA/isort
|
- repo: https://github.com/psf/black
|
||||||
rev: 5.12.0
|
rev: 23.11.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: isort
|
- id: black
|
||||||
args: ['--profile', 'black', '--line-length', '100']
|
args: ["--target-version", "py37", "--line-length", "100"]
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- repo: https://github.com/PyCQA/isort
|
||||||
rev: 6.1.0
|
rev: 5.12.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: isort
|
||||||
args: ['--max-line-length=100']
|
args: ["--profile", "black", "--line-length", "100"]
|
||||||
- repo: local
|
- repo: https://github.com/PyCQA/flake8
|
||||||
hooks:
|
rev: 6.1.0
|
||||||
- id: pylint
|
hooks:
|
||||||
name: pylint
|
- id: flake8
|
||||||
entry: pylint
|
args: ["--max-line-length=100"]
|
||||||
language: system
|
- repo: https://github.com/codespell-project/codespell
|
||||||
types: [python]
|
rev: v2.2.2
|
||||||
require_serial: true
|
hooks:
|
||||||
- repo: https://github.com/PyCQA/bandit
|
- id: codespell
|
||||||
rev: 1.7.5
|
args:
|
||||||
hooks:
|
- --ignore-words-list=exten
|
||||||
- id: bandit
|
- --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf"
|
||||||
args: [--skip, "B101", --recursive, "mylib"]
|
- --quiet-level=2
|
||||||
|
- --ignore-regex=.*codespell-ignore$
|
||||||
|
# - --write-changes # Uncomment to write changes
|
||||||
|
exclude_types: [csv, json]
|
||||||
|
- repo: https://github.com/adrienverge/yamllint
|
||||||
|
rev: v1.32.0
|
||||||
|
hooks:
|
||||||
|
- id: yamllint
|
||||||
|
ignore: .github/
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||||
|
rev: v2.7.1
|
||||||
|
hooks:
|
||||||
|
- id: prettier
|
||||||
|
args: ["--print-width", "100"]
|
||||||
|
- repo: local
|
||||||
|
hooks:
|
||||||
|
- id: pylint
|
||||||
|
name: pylint
|
||||||
|
entry: pylint
|
||||||
|
language: system
|
||||||
|
types: [python]
|
||||||
|
require_serial: true
|
||||||
|
- repo: https://github.com/PyCQA/bandit
|
||||||
|
rev: 1.7.5
|
||||||
|
hooks:
|
||||||
|
- id: bandit
|
||||||
|
args: [--skip, "B101", --recursive]
|
||||||
minimum_pre_commit_version: 3.2.0
|
minimum_pre_commit_version: 3.2.0
|
||||||
|
|
|
@ -1,63 +0,0 @@
|
||||||
clone:
|
|
||||||
git:
|
|
||||||
image: woodpeckerci/plugin-git
|
|
||||||
tags: true
|
|
||||||
|
|
||||||
pipeline:
|
|
||||||
tests:
|
|
||||||
image: brenard/python-pre-commit:latest
|
|
||||||
commands:
|
|
||||||
- DEBIAN_FRONTEND=noninteractive apt-get -qq update < /dev/null > /dev/null
|
|
||||||
- DEBIAN_FRONTEND=noninteractive apt-get -qq -y install --no-install-recommends python3-requests python3-dateutil < /dev/null > /dev/null
|
|
||||||
- pre-commit run --all-files
|
|
||||||
|
|
||||||
build:
|
|
||||||
image: brenard/debian-python-deb
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
commands:
|
|
||||||
- echo "$GPG_KEY"|base64 -d|gpg --import
|
|
||||||
- ./build.sh --quiet
|
|
||||||
secrets: [ maintainer_name, maintainer_email, gpg_key, debian_codename ]
|
|
||||||
|
|
||||||
publish-dryrun:
|
|
||||||
group: publish
|
|
||||||
image: alpine
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
commands:
|
|
||||||
- ls dist/* dist/check-syncthing-*/check_syncthing
|
|
||||||
|
|
||||||
publish-gitea:
|
|
||||||
group: publish
|
|
||||||
image: plugins/gitea-release
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
settings:
|
|
||||||
api_key:
|
|
||||||
from_secret: gitea_token
|
|
||||||
base_url: https://gitea.zionetrix.net
|
|
||||||
note: dist/release_notes.md
|
|
||||||
files:
|
|
||||||
- dist/check-syncthing-*/check_syncthing
|
|
||||||
- dist/*.deb
|
|
||||||
checksum:
|
|
||||||
- md5
|
|
||||||
- sha512
|
|
||||||
|
|
||||||
publish-apt:
|
|
||||||
group: publish
|
|
||||||
image: brenard/aptly-publish
|
|
||||||
when:
|
|
||||||
event: tag
|
|
||||||
settings:
|
|
||||||
api_url:
|
|
||||||
from_secret: apt_api_url
|
|
||||||
api_username:
|
|
||||||
from_secret: apt_api_username
|
|
||||||
api_password:
|
|
||||||
from_secret: apt_api_password
|
|
||||||
repo_name:
|
|
||||||
from_secret: apt_repo_name
|
|
||||||
path: dist
|
|
||||||
source_name: check-syncthing
|
|
7
.yamllint.yml
Normal file
7
.yamllint.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
extends: default
|
||||||
|
|
||||||
|
rules:
|
||||||
|
line-length:
|
||||||
|
max: 100
|
||||||
|
level: warning
|
11
README.md
11
README.md
|
@ -8,9 +8,10 @@ This Icinga/Nagios check plugin permit to check Syncthing status :
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
First, generate and retreive the REST API key from Syncthing web interface:
|
First, generate and retrieve the REST API key from Syncthing web interface:
|
||||||
- in Actions menu, click on Configuration
|
|
||||||
- in General tab, under API key, click on Generate button and copy the key
|
- in Actions menu, click on Configuration
|
||||||
|
- in General tab, under API key, click on Generate button and copy the key
|
||||||
|
|
||||||
```
|
```
|
||||||
API_KEY=n6RseK3HWY5LJ29PzNSUJbmK4XKHa5uV
|
API_KEY=n6RseK3HWY5LJ29PzNSUJbmK4XKHa5uV
|
||||||
|
@ -67,6 +68,6 @@ Copyright (c) 2023 Benjamin Renard <brenard@zionetrix.net>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
|
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
|
|
2
build.sh
2
build.sh
|
@ -24,7 +24,7 @@ sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" $BDIR/check_syncthing
|
||||||
|
|
||||||
if [ -z "$DEBIAN_CODENAME" ]
|
if [ -z "$DEBIAN_CODENAME" ]
|
||||||
then
|
then
|
||||||
echo "Retreive debian codename using lsb_release..."
|
echo "Retrieve debian codename using lsb_release..."
|
||||||
DEBIAN_CODENAME=$( lsb_release -c -s )
|
DEBIAN_CODENAME=$( lsb_release -c -s )
|
||||||
else
|
else
|
||||||
echo "Use debian codename from environment ($DEBIAN_CODENAME)"
|
echo "Use debian codename from environment ($DEBIAN_CODENAME)"
|
||||||
|
|
|
@ -78,7 +78,7 @@ def call_api(uri, method=None, data=None, headers=None, what=None):
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except Exception: # pylint: disable=broad-exception-caught
|
except Exception: # pylint: disable=broad-exception-caught
|
||||||
print(f"UNKNOWN - Fail to retreive {what if what else 'data'} from Syncthing REST API")
|
print(f"UNKNOWN - Fail to retrieve {what if what else 'data'} from Syncthing REST API")
|
||||||
if data:
|
if data:
|
||||||
print(f"Request data: {json.dumps(data, indent=2)}")
|
print(f"Request data: {json.dumps(data, indent=2)}")
|
||||||
logging.exception("Error on requesting %s %s", method, uri)
|
logging.exception("Error on requesting %s %s", method, uri)
|
||||||
|
|
Loading…
Reference in a new issue