bundles/sshmon: add check_pypi_for_new_release
All checks were successful
kunsi/bundlewrap/pipeline/head This commit looks good

This commit is contained in:
Franzi 2021-12-25 11:29:14 +01:00
parent 0ac0fe072d
commit 7cfe080e6f
Signed by: kunsi
GPG key ID: 12E3D2136B818350
6 changed files with 72 additions and 6 deletions

View file

@ -62,7 +62,7 @@ def icinga_check_for_new_release(metadata):
'mautrix-telegram': { 'mautrix-telegram': {
'services': { 'services': {
'MAUTRIX-TELEGRAM UPDATE': { 'MAUTRIX-TELEGRAM UPDATE': {
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_github_for_new_release mautrix/telegram {}'.format(metadata.get('mautrix-telegram/version')), 'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_pypi_for_new_release mautrix-telegram {}'.format(metadata.get('mautrix-telegram/version')),
'vars.notification.mail': True, 'vars.notification.mail': True,
'check_interval': '60m', 'check_interval': '60m',
}, },

View file

@ -55,7 +55,7 @@ def icinga_check_for_new_release(metadata):
'pretalx': { 'pretalx': {
'services': { 'services': {
'PRETALX UPDATE': { 'PRETALX UPDATE': {
'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_github_for_new_release pretalx/pretalx {}'.format(metadata.get('pretalx/version')), 'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_pypi_for_new_release pretalx {}'.format(metadata.get('pretalx/version')),
'vars.notification.mail': True, 'vars.notification.mail': True,
'check_interval': '60m', 'check_interval': '60m',
}, },

View file

@ -59,7 +59,7 @@ try:
else: else:
exit(2) exit(2)
else: else:
print("Currently installed version matches newest release on github") print("Currently installed version {} matches newest release on github".format(current_version))
exit(0) exit(0)
except Exception as e: except Exception as e:
print(repr(e)) print(repr(e))

View file

@ -0,0 +1,58 @@
#!/usr/bin/env python3
from sys import argv, exit
from requests import get
try:
# Arch Linux (possibly future Ubuntu releases)
from packaging.version import parse
except ModuleNotFoundError:
# Debian
from setuptools._vendor.packaging.version import parse
assert (
len(argv) >= 3
), "Usage: check_pypi_for_new_release <project> <version> [tag prefix]"
repo = argv[1]
current_version = argv[2]
if len(argv) >= 4:
tag_prefix = argv[3]
else:
tag_prefix = ""
try:
r = get(
"https://pypi.org/pypi/{}/json".format(repo),
headers={"Accept": "application/json"},
)
r.raise_for_status()
releases = r.json()['releases']
newest_release = None
for version, info in releases.items():
if version.startswith(tag_prefix):
if newest_release is None or parse(version) > parse(newest_release):
newest_release = version
assert newest_release is not None, "Could not determine latest release"
if parse(newest_release) > parse(current_version):
print(
"There is a newer version available: {} (currently installed: {})".format(
newest_release, current_version
)
)
exit(2)
else:
print("Currently installed version {} matches newest release on PyPI".format(current_version))
exit(0)
except Exception as e:
print(repr(e))
exit(3)

View file

@ -50,12 +50,13 @@ files = {
for check in { for check in {
'cpu_stats', 'cpu_stats',
'mounts',
'ram',
'github_for_new_release', 'github_for_new_release',
'http_url_for_string', 'http_url_for_string',
'https_certificate_at_url',
'http_wget', 'http_wget',
'https_certificate_at_url',
'mounts',
'pypi_for_new_release',
'ram',
'systemd_unit', 'systemd_unit',
}: }:
files["/usr/local/share/icinga/plugins/check_{}".format(check)] = { files["/usr/local/share/icinga/plugins/check_{}".format(check)] = {

View file

@ -0,0 +1,7 @@
defaults = {
'sysctl': {
'options': {
'vm.overcommit_memory': 1,
},
},
}