Compare commits
3 commits
2023.01.19
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
bdda267a99 | ||
|
b7c13a4859 | ||
|
a9ae368521 |
7 changed files with 220 additions and 119 deletions
86
.forgejo/workflows/release.yaml
Normal file
86
.forgejo/workflows/release.yaml
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
---
|
||||||
|
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
|
||||||
|
- 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
|
||||||
|
needs:
|
||||||
|
- build
|
||||||
|
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-*/check_* release/
|
||||||
|
md5sum release/* > md5sum.txt
|
||||||
|
sha512sum release/* > sha512sum.txt
|
||||||
|
mv md5sum.txt sha512sum.txt release/
|
||||||
|
{
|
||||||
|
echo 'release_note<<EOF'
|
||||||
|
cat release_notes.md | sed 's/"/\\"/g'
|
||||||
|
echo 'EOF'
|
||||||
|
} >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Publish release on Forgejo
|
||||||
|
uses: actions/forgejo-release@v2
|
||||||
|
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
|
||||||
|
needs:
|
||||||
|
- build
|
||||||
|
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
|
||||||
|
- name: Run pre-commit
|
||||||
|
run: pre-commit run --all-files
|
|
@ -1,6 +1,53 @@
|
||||||
# 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/astral-sh/ruff-pre-commit
|
||||||
|
rev: v0.1.6
|
||||||
|
hooks:
|
||||||
|
- id: ruff
|
||||||
|
args: ["--fix"]
|
||||||
|
- repo: https://github.com/asottile/pyupgrade
|
||||||
|
rev: v3.15.0
|
||||||
|
hooks:
|
||||||
|
- id: pyupgrade
|
||||||
|
args: ["--keep-percent-format", "--py37-plus"]
|
||||||
|
- repo: https://github.com/psf/black
|
||||||
|
rev: 23.11.0
|
||||||
|
hooks:
|
||||||
|
- id: black
|
||||||
|
args: ["--target-version", "py37", "--line-length", "100"]
|
||||||
|
- repo: https://github.com/PyCQA/isort
|
||||||
|
rev: 5.12.0
|
||||||
|
hooks:
|
||||||
|
- id: isort
|
||||||
|
args: ["--profile", "black", "--line-length", "100"]
|
||||||
|
- repo: https://github.com/PyCQA/flake8
|
||||||
|
rev: 6.1.0
|
||||||
|
hooks:
|
||||||
|
- id: flake8
|
||||||
|
args: ["--max-line-length=100"]
|
||||||
|
- repo: https://github.com/codespell-project/codespell
|
||||||
|
rev: v2.2.2
|
||||||
|
hooks:
|
||||||
|
- id: codespell
|
||||||
|
args:
|
||||||
|
- --ignore-words-list=exten
|
||||||
|
- --skip="./.*,*.csv,*.json,*.ini,*.subject,*.txt,*.html,*.log,*.conf"
|
||||||
|
- --quiet-level=2
|
||||||
|
- --ignore-regex=.*codespell-ignore$
|
||||||
|
# - --write-changes # Uncomment to write changes
|
||||||
|
exclude_types: [csv, json]
|
||||||
|
- repo: https://github.com/pre-commit/mirrors-prettier
|
||||||
|
rev: v2.7.1
|
||||||
|
hooks:
|
||||||
|
- id: prettier
|
||||||
|
args: ["--print-width", "100"]
|
||||||
|
- repo: https://github.com/adrienverge/yamllint
|
||||||
|
rev: v1.32.0
|
||||||
|
hooks:
|
||||||
|
- id: yamllint
|
||||||
|
ignore: .github/
|
||||||
- repo: local
|
- repo: local
|
||||||
hooks:
|
hooks:
|
||||||
- id: pylint
|
- id: pylint
|
||||||
|
@ -9,23 +56,18 @@ repos:
|
||||||
language: system
|
language: system
|
||||||
types: [python]
|
types: [python]
|
||||||
require_serial: true
|
require_serial: true
|
||||||
- repo: https://github.com/PyCQA/flake8
|
- repo: https://github.com/PyCQA/bandit
|
||||||
rev: 6.0.0
|
rev: 1.7.5
|
||||||
hooks:
|
hooks:
|
||||||
- id: flake8
|
- id: bandit
|
||||||
args: ['--max-line-length=100']
|
args: [--skip, "B101", --recursive]
|
||||||
- repo: https://github.com/asottile/pyupgrade
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v3.3.1
|
rev: v4.4.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: pyupgrade
|
- id: check-executables-have-shebangs
|
||||||
args: ['--keep-percent-format', '--py37-plus']
|
stages: [manual]
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/shellcheck-py/shellcheck-py
|
||||||
rev: 22.12.0
|
rev: v0.10.0.1
|
||||||
hooks:
|
hooks:
|
||||||
- id: black
|
- id: shellcheck
|
||||||
args: ['--target-version', 'py37', '--line-length', '100']
|
minimum_pre_commit_version: 3.2.0
|
||||||
- repo: https://github.com/PyCQA/isort
|
|
||||||
rev: 5.11.4
|
|
||||||
hooks:
|
|
||||||
- id: isort
|
|
||||||
args: ['--profile', 'black', '--line-length', '100']
|
|
||||||
|
|
|
@ -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 < /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-esphome-devices-*/check_esphome_devices
|
|
||||||
|
|
||||||
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-esphome-devices-*/check_esphome_devices
|
|
||||||
- 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-esphome-devices
|
|
15
README.md
15
README.md
|
@ -19,18 +19,22 @@ service nagios-nrpe-server reload
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: check_esphome_devices [-h] [-d] [-H HOST] [-r RETRY_COUNT] [-D RETRY_DELAY] [-x EXCLUDE]
|
usage: check_esphome_devices [-h] [-d] [-H HOST] [-r RETRY_COUNT] [-D RETRY_DELAY]
|
||||||
|
[-t TIMEOUT] [-x EXCLUDE]
|
||||||
|
|
||||||
optional arguments:
|
options:
|
||||||
-h, --help show this help message and exit
|
-h, --help show this help message and exit
|
||||||
-d, --debug
|
-d, --debug
|
||||||
-H HOST, --host HOST ESPHome dashboard URL (default: http://127.0.0.1:6052)
|
-H HOST, --host HOST ESPHome dashboard URL (default: http://127.0.0.1:6052)
|
||||||
-r RETRY_COUNT, --retry RETRY_COUNT
|
-r RETRY_COUNT, --retry RETRY_COUNT
|
||||||
Number of retry to retreive device status (default: 4)
|
Number of retry to retrieve device status (default: 4)
|
||||||
-D RETRY_DELAY, --delay RETRY_DELAY
|
-D RETRY_DELAY, --delay RETRY_DELAY
|
||||||
Delay in second between two retry to retreive device status (default: 1s)
|
Delay in second between two retry to retrieve device status
|
||||||
|
(default: 1s)
|
||||||
|
-t TIMEOUT, --timeout TIMEOUT
|
||||||
|
Timeout in second on API requests (default: 10s)
|
||||||
-x EXCLUDE, --exclude EXCLUDE
|
-x EXCLUDE, --exclude EXCLUDE
|
||||||
Regex exclude pattern(
|
Regex exclude pattern(s)
|
||||||
```
|
```
|
||||||
|
|
||||||
## Copyright
|
## Copyright
|
||||||
|
@ -44,4 +48,3 @@ This program is free software; you can redistribute it and/or modify it under th
|
||||||
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.
|
||||||
|
|
||||||
|
|
47
build.sh
47
build.sh
|
@ -1,10 +1,13 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
QUIET_ARG=""
|
QUIET_ARG=""
|
||||||
[ "$1" == "--quiet" ] && QUIET_ARG="--quiet"
|
[[ "$1" == "--quiet" ]] && QUIET_ARG="--quiet"
|
||||||
|
|
||||||
# Enter source directory
|
# Enter source directory
|
||||||
cd $( dirname $0 )
|
cd "$( dirname "$0" )" || exit
|
||||||
|
|
||||||
|
CHECK_FILE="$( find "." -name 'check_*' ! -name '*~' -type f -executable | head -n 1 )"
|
||||||
|
PACKAGE_NAME="$( basename "$CHECK_FILE" | tr '_' '-' )"
|
||||||
|
|
||||||
echo "Clean previous build..."
|
echo "Clean previous build..."
|
||||||
rm -fr dist
|
rm -fr dist
|
||||||
|
@ -13,18 +16,18 @@ echo "Detect version using git describe..."
|
||||||
VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )"
|
VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )"
|
||||||
|
|
||||||
echo "Create building environemt..."
|
echo "Create building environemt..."
|
||||||
BDIR=dist/check-esphome-devices-$VERSION
|
BDIR="dist/$PACKAGE_NAME-$VERSION"
|
||||||
mkdir -p $BDIR
|
mkdir -p "$BDIR"
|
||||||
[ -z "$QUIET_ARG" ] && RSYNC_ARG="-v" || RSYNC_ARG=""
|
RSYNC_ARG=""
|
||||||
rsync -a $RSYNC_ARG debian/ $BDIR/debian/
|
[[ -z "$QUIET_ARG" ]] && RSYNC_ARG="-v"
|
||||||
cp check_esphome_devices $BDIR/
|
rsync -a "$RSYNC_ARG" debian/ "$BDIR/debian/"
|
||||||
|
cp "$CHECK_FILE" "$BDIR/"
|
||||||
|
|
||||||
echo "Set VERSION=$VERSION in gitdch using sed..."
|
echo "Set VERSION=$VERSION in gitdch using sed..."
|
||||||
sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" $BDIR/check_esphome_devices
|
sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" "$BDIR/$( basename "$CHECK_FILE" )"
|
||||||
|
|
||||||
if [ -z "$DEBIAN_CODENAME" ]
|
if [[ -z "$DEBIAN_CODENAME" ]]; then
|
||||||
then
|
echo "Retrieve debian codename using lsb_release..."
|
||||||
echo "Retreive 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)"
|
||||||
|
@ -32,31 +35,29 @@ fi
|
||||||
|
|
||||||
echo "Generate debian changelog using gitdch..."
|
echo "Generate debian changelog using gitdch..."
|
||||||
GITDCH_ARGS=('--verbose')
|
GITDCH_ARGS=('--verbose')
|
||||||
[ -n "$QUIET_ARG" ] && GITDCH_ARGS=('--warning')
|
[[ -n "$QUIET_ARG" ]] && GITDCH_ARGS=('--warning')
|
||||||
if [ -n "$MAINTAINER_NAME" ]
|
if [[ -n "$MAINTAINER_NAME" ]]; then
|
||||||
then
|
|
||||||
echo "Use maintainer name from environment ($MAINTAINER_NAME)"
|
echo "Use maintainer name from environment ($MAINTAINER_NAME)"
|
||||||
GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}")
|
GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}")
|
||||||
fi
|
fi
|
||||||
if [ -n "$MAINTAINER_EMAIL" ]
|
if [[ -n "$MAINTAINER_EMAIL" ]]; then
|
||||||
then
|
|
||||||
echo "Use maintainer email from environment ($MAINTAINER_EMAIL)"
|
echo "Use maintainer email from environment ($MAINTAINER_EMAIL)"
|
||||||
GITDCH_ARGS+=("--maintainer-email" "$MAINTAINER_EMAIL")
|
GITDCH_ARGS+=("--maintainer-email" "$MAINTAINER_EMAIL")
|
||||||
fi
|
fi
|
||||||
gitdch \
|
gitdch \
|
||||||
--package-name check-esphome-devices \
|
--package-name "$PACKAGE_NAME" \
|
||||||
--version "${VERSION}" \
|
--version "${VERSION}" \
|
||||||
--code-name $DEBIAN_CODENAME \
|
--code-name "$DEBIAN_CODENAME" \
|
||||||
--output $BDIR/debian/changelog \
|
--output "$BDIR"/debian/changelog \
|
||||||
--release-notes dist/release_notes.md \
|
--release-notes dist/release_notes.md \
|
||||||
"${GITDCH_ARGS[@]}"
|
"${GITDCH_ARGS[@]}"
|
||||||
|
|
||||||
if [ -n "$MAINTAINER_NAME" -a -n "$MAINTAINER_EMAIL" ]
|
if [[ -n "$MAINTAINER_NAME" ]] && [[ -n "$MAINTAINER_EMAIL" ]]; then
|
||||||
then
|
|
||||||
echo "Set Maintainer field in debian control file ($MAINTAINER_NAME <$MAINTAINER_EMAIL>)..."
|
echo "Set Maintainer field in debian control file ($MAINTAINER_NAME <$MAINTAINER_EMAIL>)..."
|
||||||
sed -i "s/^Maintainer: .*$/Maintainer: $MAINTAINER_NAME <$MAINTAINER_EMAIL>/" $BDIR/debian/control
|
sed -i "s/^Maintainer: .*$/Maintainer: $MAINTAINER_NAME <$MAINTAINER_EMAIL>/" \
|
||||||
|
"$BDIR"/debian/control
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Build debian package..."
|
echo "Build debian package..."
|
||||||
cd $BDIR
|
cd "$BDIR" || exit
|
||||||
dpkg-buildpackage
|
dpkg-buildpackage
|
||||||
|
|
|
@ -33,6 +33,7 @@ STATUS = {"OK": 0, "WARNING": 1, "CRITICAL": 2, "UNKNOWN": 3}
|
||||||
DEFAULT_HOST = "http://127.0.0.1:6052"
|
DEFAULT_HOST = "http://127.0.0.1:6052"
|
||||||
DEFAULT_RETRY_COUNT = 4
|
DEFAULT_RETRY_COUNT = 4
|
||||||
DEFAULT_RETRY_DELAY = 1
|
DEFAULT_RETRY_DELAY = 1
|
||||||
|
DEFAULT_TIMEOUT = 10
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("-d", "--debug", action="store_true", dest="debug", default=False)
|
parser.add_argument("-d", "--debug", action="store_true", dest="debug", default=False)
|
||||||
|
@ -52,7 +53,7 @@ parser.add_argument(
|
||||||
"--retry",
|
"--retry",
|
||||||
action="store",
|
action="store",
|
||||||
dest="retry_count",
|
dest="retry_count",
|
||||||
help=("Number of retry to retreive device status " f"(default: {DEFAULT_RETRY_COUNT})"),
|
help=("Number of retry to retrieve device status " f"(default: {DEFAULT_RETRY_COUNT})"),
|
||||||
type=int,
|
type=int,
|
||||||
default=DEFAULT_RETRY_COUNT,
|
default=DEFAULT_RETRY_COUNT,
|
||||||
)
|
)
|
||||||
|
@ -63,13 +64,23 @@ parser.add_argument(
|
||||||
action="store",
|
action="store",
|
||||||
dest="retry_delay",
|
dest="retry_delay",
|
||||||
help=(
|
help=(
|
||||||
"Delay in second between two retry to retreive device status "
|
"Delay in second between two retry to retrieve device status "
|
||||||
f"(default: {DEFAULT_RETRY_DELAY}s)"
|
f"(default: {DEFAULT_RETRY_DELAY}s)"
|
||||||
),
|
),
|
||||||
type=int,
|
type=int,
|
||||||
default=DEFAULT_RETRY_DELAY,
|
default=DEFAULT_RETRY_DELAY,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-t",
|
||||||
|
"--timeout",
|
||||||
|
action="store",
|
||||||
|
dest="timeout",
|
||||||
|
help=f"Timeout in second on API requests (default: {DEFAULT_TIMEOUT}s)",
|
||||||
|
type=int,
|
||||||
|
default=DEFAULT_TIMEOUT,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def exclude_pattern(value):
|
def exclude_pattern(value):
|
||||||
"""Check and compile exclusion pattern parameter"""
|
"""Check and compile exclusion pattern parameter"""
|
||||||
|
@ -106,17 +117,17 @@ def is_excluded(name):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
r = requests.get(f"{options.host}/devices")
|
r = requests.get(f"{options.host}/devices", timeout=options.timeout)
|
||||||
devices_data = r.json()
|
devices_data = r.json()
|
||||||
logging.debug("Devices data: %s (%s)", devices_data, type(devices_data))
|
logging.debug("Devices data: %s (%s)", devices_data, type(devices_data))
|
||||||
|
|
||||||
if not devices_data:
|
if not devices_data:
|
||||||
print("UNKNOWN - Fail to retreive devices using ESPHome Dashboard API")
|
print("UNKNOWN - Fail to retrieve devices using ESPHome Dashboard API")
|
||||||
sys.exit(STATUS["UNKNOWN"])
|
sys.exit(STATUS["UNKNOWN"])
|
||||||
|
|
||||||
COUNT = 0
|
COUNT = 0
|
||||||
while COUNT < options.retry_count:
|
while COUNT < options.retry_count:
|
||||||
r = requests.get(f"{options.host}/ping")
|
r = requests.get(f"{options.host}/ping", timeout=options.timeout)
|
||||||
COUNT += 1
|
COUNT += 1
|
||||||
ping_data = r.json()
|
ping_data = r.json()
|
||||||
logging.debug("Ping data: %s (%s)", ping_data, type(ping_data))
|
logging.debug("Ping data: %s (%s)", ping_data, type(ping_data))
|
||||||
|
@ -135,7 +146,7 @@ while COUNT < options.retry_count:
|
||||||
time.sleep(options.retry_delay)
|
time.sleep(options.retry_delay)
|
||||||
|
|
||||||
if not ping_data:
|
if not ping_data:
|
||||||
print("UNKNOWN - Fail to retreive devices status " "using ESPHome Dashboard API")
|
print("UNKNOWN - Fail to retrieve devices status using ESPHome Dashboard API")
|
||||||
sys.exit(STATUS["UNKNOWN"])
|
sys.exit(STATUS["UNKNOWN"])
|
||||||
|
|
||||||
UPDATE_AVAILABLE = 0
|
UPDATE_AVAILABLE = 0
|
||||||
|
|
Loading…
Reference in a new issue