Initial release
ci/woodpecker/push/woodpecker Pipeline failed Details

This commit is contained in:
Benjamin Renard 2023-01-19 12:51:32 +01:00
commit 4dce16df85
Signed by: bn8
GPG Key ID: 3E2E1CE1907115BC
12 changed files with 328 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*~
.*.swp
/dist

70
.woodpecker.yml Normal file
View File

@ -0,0 +1,70 @@
clone:
git:
image: woodpeckerci/plugin-git
tags: true
pipeline:
test-pylint:
group: test
image: debian:stable-slim
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 pylint3 < /dev/null > /dev/null
- python3 -m pylint check_forgejo_upgrade
test-flake8:
group: test
image: pipelinecomponents/flake8
commands:
- flake8 check_forgejo_upgrade
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-forgejo-upgrade-*/check_forgejo_upgrade
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-forgejo-upgrade-*/check_forgejo_upgrade
- 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-forgejo-upgrade

41
README.md Normal file
View File

@ -0,0 +1,41 @@
# Monitoring plugin to check Forgejo instance upgrade status
This Icinga/Nagios check plugin permit to check Forgejo instance upgrade status by comparing the local forgejo binary version against the latest stable release.
## Installation
```
apt install git
git clone https://gitea.zionetrix.net/bn8/check_forgejo_upgrade.git /usr/local/src/check_forgejo_upgrade
mkdir -p /usr/local/lib/nagios/plugins
ln -s /usr/local/src/check_forgejo_upgrade/check_forgejo_upgrade /usr/local/lib/nagios/plugins/
echo "command[check_forgejo_upgrade]=/usr/local/lib/nagios/plugins/check_forgejo_upgrade" > /etc/nagios/nrpe.d/forgejo.cfg
service nagios-nrpe-server reload
```
## Usage
```
usage: check_forgejo_upgrade [-h] [-d] [-p PATH] [-U URL] [--rc]
optional arguments:
-h, --help show this help message and exit
-d, --debug
-p PATH, --path PATH Forgejo bin path
-U URL, --url URL Forgejo releases RSS URL
--rc Allow release candidate (default: only stable release are
considered)
```
## Copyright
Copyright (c) 2023 Benjamin Renard <brenard@zionetrix.net>
## License
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.
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.

62
build.sh Executable file
View File

@ -0,0 +1,62 @@
#!/bin/bash
QUIET_ARG=""
[ "$1" == "--quiet" ] && QUIET_ARG="--quiet"
# Enter source directory
cd $( dirname $0 )
echo "Clean previous build..."
rm -fr dist
echo "Detect version using git describe..."
VERSION="$( git describe --tags|sed 's/^[^0-9]*//' )"
echo "Create building environemt..."
BDIR=dist/check-forgejo-upgrade-$VERSION
mkdir -p $BDIR
[ -z "$QUIET_ARG" ] && RSYNC_ARG="-v" || RSYNC_ARG=""
rsync -a $RSYNC_ARG debian/ $BDIR/debian/
cp check_forgejo_upgrade $BDIR/
echo "Set VERSION=$VERSION in gitdch using sed..."
sed -i "s/^VERSION *=.*$/VERSION = '$VERSION'/" $BDIR/check_forgejo_upgrade
if [ -z "$DEBIAN_CODENAME" ]
then
echo "Retreive debian codename using lsb_release..."
DEBIAN_CODENAME=$( lsb_release -c -s )
else
echo "Use debian codename from environment ($DEBIAN_CODENAME)"
fi
echo "Generate debian changelog using gitdch..."
GITDCH_ARGS=('--verbose')
[ -n "$QUIET_ARG" ] && GITDCH_ARGS=('--warning')
if [ -n "$MAINTAINER_NAME" ]
then
echo "Use maintainer name from environment ($MAINTAINER_NAME)"
GITDCH_ARGS+=("--maintainer-name" "${MAINTAINER_NAME}")
fi
if [ -n "$MAINTAINER_EMAIL" ]
then
echo "Use maintainer email from environment ($MAINTAINER_EMAIL)"
GITDCH_ARGS+=("--maintainer-email" "$MAINTAINER_EMAIL")
fi
gitdch \
--package-name check-forgejo-upgrade \
--version "${VERSION}" \
--code-name $DEBIAN_CODENAME \
--output $BDIR/debian/changelog \
--release-notes dist/release_notes.md \
"${GITDCH_ARGS[@]}"
if [ -n "$MAINTAINER_NAME" -a -n "$MAINTAINER_EMAIL" ]
then
echo "Set Maintainer field in debian control file ($MAINTAINER_NAME <$MAINTAINER_EMAIL>)..."
sed -i "s/^Maintainer: .*$/Maintainer: $MAINTAINER_NAME <$MAINTAINER_EMAIL>/" $BDIR/debian/control
fi
echo "Build debian package..."
cd $BDIR
dpkg-buildpackage

109
check_forgejo_upgrade Executable file
View File

@ -0,0 +1,109 @@
#!/usr/bin/python3
"""
Icinga/Nagios plugin to check Forgejo instance upgrade status.
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 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.
"""
import argparse
import logging
import re
import subprocess
import sys
import requests
import xmltodict
parser = argparse.ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true')
parser.add_argument(
'-p', '--path', type=str,
help='Forgejo bin path', default='forgejo')
parser.add_argument(
'-U', '--url', type=str,
help='Forgejo releases RSS URL',
default='https://forgejo.org/releases/rss.xml')
parser.add_argument(
'--rc', action='store_true', dest='include_rc',
help=(
'Allow release candidate (default: only stable release are '
'considered)')
)
options = parser.parse_args()
logging.basicConfig(level=logging.DEBUG if options.debug else logging.WARNING)
current = None
cmd = [options.path, '--version']
logging.debug(
'Command use to retreive current version of Forgejo: %s',
' '.join(cmd))
out = None
exc = None
try:
out = subprocess.check_output(cmd)
logging.debug('Output:\n%s', out)
m = re.search('version ([^ ]+) built', out.decode('utf8', errors='ignore'))
if m:
current = m.group(1)
except Exception as err:
exc = err
logging.debug('Current version: %s', current)
if not current:
print('UNKNOWN - Fail to retreive current Forgejo')
print(f'Command: {" ".join(cmd)}')
print('Output:')
print(out if out else "")
print('Exception:')
print(exc if exc else "")
sys.exit(3)
latest = None
try:
logging.debug('Get releases RSS feed from %s...', options.url)
r = requests.get(options.url)
logging.debug('Data retreive:\n%s', r.text)
data = xmltodict.parse(r.text)
for item in data['rss']['channel']['item']:
version = re.sub('^v', '', item['title'])
if not options.include_rc and '-rc' in version:
logging.debug('Ignore release candidate %s', version)
continue
latest = version
break
except Exception:
pass
logging.debug('Latest version: %s', current)
if not latest:
print(
'UNKNOWN - Fail to retreive latest Forgejo release from the project '
'RSS feed')
print(f'Current version: {current}')
sys.exit(3)
if latest == current:
print(f'OK - The latest release of Forgejo is currently used ({latest})')
sys.exit(0)
print(
'WARNING - The version of Forgejo currently used is not the latest '
f'({current} vs {latest})')
sys.exit(1)

1
debian/compat vendored Normal file
View File

@ -0,0 +1 @@
11

15
debian/control vendored Normal file
View File

@ -0,0 +1,15 @@
Source: check-forgejo-upgrade
Section: admin
Priority: optional
Maintainer: Debian Zionetrix - check-forgejo-upgrade <debian+check-forgejo-upgrade@zionetrix.net>
Build-Depends: debhelper (>> 11.0.0)
Standards-Version: 3.9.6
Package: check-forgejo-upgrade
Architecture: all
Depends: ${misc:Depends}, python3, python3-requests
Description: Monitoring plugin to check Forgejo instance upgrade status
This Icinga/Nagios check plugin permit to check Forgejo instance upgrade
status by comparing the local forgejo binary version against the latest
stable release.

20
debian/copyright vendored Normal file
View File

@ -0,0 +1,20 @@
This package was written by Benjamin Renard <brenard@zionetrix.net>.
Copyright (C) 2023 Benjamin Renard <brenard@zionetrix.net>
check-forgejo-upgrade is licensed under the GNU general public license, version 3.
check-forgejo-upgrade is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
check-forgejo-upgrade 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
check-forgejo-upgrade; see the file COPYING. If not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
On Debian systems, a copy of the GNU General Public License is available in
/usr/share/common-licenses/GPL-3 as part of the base-files package.

1
debian/dirs vendored Normal file
View File

@ -0,0 +1 @@
usr/lib/nagios/plugins

1
debian/install vendored Normal file
View File

@ -0,0 +1 @@
check_forgejo_upgrade usr/lib/nagios/plugins

4
debian/rules vendored Executable file
View File

@ -0,0 +1,4 @@
#!/usr/bin/make -f
#export DH_VERBOSE=1
%:
dh $@

1
debian/source/format vendored Normal file
View File

@ -0,0 +1 @@
1.0