diff --git a/bundles/octoprint/files/check_octoprint_update b/bundles/octoprint/files/check_octoprint_update new file mode 100644 index 0000000..c65604e --- /dev/null +++ b/bundles/octoprint/files/check_octoprint_update @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +from requests import get +from sys import exit + +api_key = '${api_key}' + +try: + json = get('http://[::1]:22030/plugin/softwareupdate/check', headers={'X-Api-Key': api_key}).json() +except Exception as e: + print(repr(e)) + exit(3) + +updates = set() +errors = set() + +for identifier, info in json['information'].items(): + if info['updateAvailable']: + updates.add(info['displayName']) + +if not json['environment']['supported']: + errors.add('OctoPrint runs in an unsupported environment!') + +if not json['storage']['sufficient']: + errors.add('OctoPrint reports insufficient storage!') + + +for error in sorted(errors): + print(error) + +if len(updates) > 0: + print('Updates available: {}'.format(', '.join(sorted(updates)))) + + +if len(errors) > 0: + exit(2) +elif len(updates) > 0: + exit(1) +else: + print('OK') + exit(0) diff --git a/bundles/octoprint/items.py b/bundles/octoprint/items.py index 86674ef..3cce0e8 100644 --- a/bundles/octoprint/items.py +++ b/bundles/octoprint/items.py @@ -35,4 +35,11 @@ files = { '/opt/octoprint/systemd-wrapper': { 'mode': '0755', }, + '/usr/local/share/icinga/plugins/check_octoprint_update': { + 'mode': '0755', + 'content_type': 'mako', + 'context': { + 'api_key': node.metadata.get('octoprint', {}).get('api_key', ''), + }, + }, } diff --git a/bundles/octoprint/metadata.py b/bundles/octoprint/metadata.py index 2e9c340..6471333 100644 --- a/bundles/octoprint/metadata.py +++ b/bundles/octoprint/metadata.py @@ -18,3 +18,22 @@ defaults = { }, }, } + + +@metadata_reactor +def icinga(metadata): + if not metadata.get('octoprint/api_key', None): + return {} + + return { + 'icinga2_api': { + 'octoprint': { + 'services': { + 'OCTOPRINT UPDATE': { + 'command_on_monitored_host': '/usr/local/share/icinga/plugins/check_octoprint_update', + 'retry_interval': '60m', + }, + }, + }, + }, + } diff --git a/nodes/home/octoprint-vielschichtigkeit.py b/nodes/home/octoprint-vielschichtigkeit.py index 5a34d6d..8c2702b 100644 --- a/nodes/home/octoprint-vielschichtigkeit.py +++ b/nodes/home/octoprint-vielschichtigkeit.py @@ -38,6 +38,9 @@ nodes['home.octoprint-vielschichtigkeit'] = { }, }, }, + 'octoprint': { + 'api_key': vault.decrypt('encrypt$gAAAAABfuWtDp0xeUSNZwi8PzhgxvheK1rdhThlPwZSweXZaUNzDF2BlfOwuMvW-vSxHjTJoyCnxzCAAytIBf0iXgdyeCafvbB43ogBaQK52HAahQNP4506-h02BKgiMdIghUmc1ZOUT'), + }, 'raspberrypi': { 'camera': True, },