From 8e54d6eb2333a3751469d3f3746763df989272c9 Mon Sep 17 00:00:00 2001 From: Franziska Kunsmann Date: Sat, 9 Jan 2021 11:03:23 +0100 Subject: [PATCH] add monitoring for freifunk nodes --- bundles/icinga2/files/check_freifunk_node | 78 +++++++++++++++++++ .../icinga2/files/icinga2/check_commands.conf | 7 ++ bundles/icinga2/items.py | 3 + nodes/home/winkeeinhorn-1.py | 25 ++++++ nodes/home/winkeeinhorn-2.py | 25 ++++++ nodes/home/winkeeinhorn-vm.py | 25 ++++++ 6 files changed, 163 insertions(+) create mode 100644 bundles/icinga2/files/check_freifunk_node create mode 100644 nodes/home/winkeeinhorn-1.py create mode 100644 nodes/home/winkeeinhorn-2.py create mode 100644 nodes/home/winkeeinhorn-vm.py diff --git a/bundles/icinga2/files/check_freifunk_node b/bundles/icinga2/files/check_freifunk_node new file mode 100644 index 0000000..2723f13 --- /dev/null +++ b/bundles/icinga2/files/check_freifunk_node @@ -0,0 +1,78 @@ +#!/usr/bin/env python3 + +from requests import get +from sys import argv, exit + +meshviewer_url = argv[1] +node_id = argv[2] +node = None + +try: + for n in get(meshviewer_url).json()['nodes']: + if node_id == n['node_id']: + node = n + break + + if not node: + print('CRITICAL: Node {} not found in {}'.format( + node_id, + meshviewer_url, + )) + exit(2) + + if not node['is_online']: + print('CRITICAL: Node "{}" is offline!'.format( + node['hostname'], + )) + exit(2) + + crit = set() + warn = set() + if node['loadavg'] > 1: + warn.add('has high load: {}'.format( + node['loadavg'], + )) + + if node['rootfs_usage'] > 0.9: + crit.add('rootfs usage is {}%'.format( + int(node['rootfs_usage']*100) + )) + elif node['rootfs_usage'] > 0.8: + warn.add('rootfs usage is {}%'.format( + int(node['rootfs_usage']*100) + )) + + if node['memory_usage'] > 0.9: + crit.add('ram usage is {}%'.format( + int(node['memory_usage']*100) + )) + elif node['memory_usage'] > 0.8: + warn.add('ram usage is {}%'.format( + int(node['memory_usage']*100) + )) + + + for line in sorted(crit): + print('CRITICAL: Node "{}" {}'.format( + node['hostname'], + line, + )) + + for line in sorted(warn): + print('WARNING: Node "{}" {}'.format( + node['hostname'], + line, + )) + + if crit: + exit(2) + elif warn: + exit(1) + else: + print('Node "{}" reports no errors'.format( + node['hostname'], + )) + exit(0) +except Exception as e: + print(repr(e)) + exit(3) diff --git a/bundles/icinga2/files/icinga2/check_commands.conf b/bundles/icinga2/files/icinga2/check_commands.conf index 0d79cc5..92bddaa 100644 --- a/bundles/icinga2/files/icinga2/check_commands.conf +++ b/bundles/icinga2/files/icinga2/check_commands.conf @@ -25,6 +25,13 @@ object CheckCommand "dummy_hostalive" { command = [ "true" ] } +object CheckCommand "check_freifunk_node" { + import "plugin-check-command" + import "ipv4-or-ipv6" + + command = [ "/usr/local/share/icinga/plugins/check_freifunk_node", "$url$", "$id$" ] +} + object CheckCommand "check_http_wget" { import "plugin-check-command" import "ipv4-or-ipv6" diff --git a/bundles/icinga2/items.py b/bundles/icinga2/items.py index c39a0f7..bba9b1a 100644 --- a/bundles/icinga2/items.py +++ b/bundles/icinga2/items.py @@ -86,6 +86,9 @@ files = { 'mode': '0755', 'content_type': 'mako', }, + '/usr/local/share/icinga/plugins/check_freifunk_node': { + 'mode': '0755', + }, '/etc/sshmon.priv': { 'content': repo.vault.decrypt_file(join('sshmon', 'sshmon.key.vault')), 'owner': 'nagios', diff --git a/nodes/home/winkeeinhorn-1.py b/nodes/home/winkeeinhorn-1.py new file mode 100644 index 0000000..063b25a --- /dev/null +++ b/nodes/home/winkeeinhorn-1.py @@ -0,0 +1,25 @@ +nodes['home.winkeeinhorn-1'] = { + 'dummy': True, + 'metadata': { + 'interfaces': { + 'default': { + 'ips': { + '172.19.138.11', + }, + 'dhcp': True, + 'mac': 'f4:06:8d:df:05:60', + }, + }, + 'icinga2_api': { + 'freifunk': { + 'services': { + 'NODE HEALTH': { + 'check_command': 'check_freifunk_node', + 'vars.url': 'https://map.freifunk-mwu.de/data/meshviewer.json', + 'vars.id': 'f4068ddf055f', + }, + }, + }, + }, + }, +} diff --git a/nodes/home/winkeeinhorn-2.py b/nodes/home/winkeeinhorn-2.py new file mode 100644 index 0000000..e9dfa44 --- /dev/null +++ b/nodes/home/winkeeinhorn-2.py @@ -0,0 +1,25 @@ +nodes['home.winkeeinhorn-2'] = { + 'dummy': True, + 'metadata': { + 'interfaces': { + 'default': { + 'ips': { + '172.19.138.12', + }, + 'dhcp': True, + 'mac': 'f4:06:8d:df:03:38', + }, + }, + 'icinga2_api': { + 'freifunk': { + 'services': { + 'NODE HEALTH': { + 'check_command': 'check_freifunk_node', + 'vars.url': 'https://map.freifunk-mwu.de/data/meshviewer.json', + 'vars.id': 'f4068ddf0337', + }, + }, + }, + }, + }, +} diff --git a/nodes/home/winkeeinhorn-vm.py b/nodes/home/winkeeinhorn-vm.py new file mode 100644 index 0000000..21832a2 --- /dev/null +++ b/nodes/home/winkeeinhorn-vm.py @@ -0,0 +1,25 @@ +nodes['home.winkeeinhorn-vm'] = { + 'dummy': True, + 'metadata': { + 'interfaces': { + 'default': { + 'ips': { + '172.19.138.10', + }, + 'dhcp': True, + 'mac': '42:86:56:de:00:90', + }, + }, + 'icinga2_api': { + 'freifunk': { + 'services': { + 'NODE HEALTH': { + 'check_command': 'check_freifunk_node', + 'vars.url': 'https://map.freifunk-mwu.de/data/meshviewer.json', + 'vars.id': '525400b04e4d', + }, + }, + }, + }, + }, +}