microstack/checks/check_systemd.py
Nikolay Vinogradov 9019ad3529 Added Filebeat, NRPE and Telegraf to Microstack
- Snapped binary packages of Filebeat, NRPE and Telegraf (disabled by default)
- Added W/A of Telegraf segfault after ELF patching by snapcraft
- Implemented IPMI input tuning for Telegraf
- Allowed to run NRPE as root:root (from custom PPA)
- Implemented Filebeat, NRPE and Telegraf control scripts and config on top of snap-overlay
- Added support for checking Microstack systemd services by NRPE
- Added few generic and Microstack-specific NRPE checks
- Added possibility to override default config paths for the daemons
- Added support for in-band IPMI input to Telegraf
- Stick LMA wrappers and services naming to Microstack conventions
- Increase build timeout in .zuul conf by 30min

Change-Id: I68dbdb11248cf0c1e22e9333af3cf0f88954f557
2020-02-11 14:33:26 +00:00

39 lines
1.3 KiB
Python

#!/usr/bin/python3
#
# Copyright 2016 Canonical Ltd
#
# Author: Brad Marshall <brad.marshall@canonical.com>
#
# Based on check_upstart_job and https://zignar.net/2014/09/08/getting-started-with-dbus-python-systemd/
#
import dbus, sys
service_arg = sys.argv[1]
service_name = "%s.service" % service_arg
try:
bus = dbus.SystemBus()
systemd = bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
manager = dbus.Interface(systemd, dbus_interface='org.freedesktop.systemd1.Manager')
try:
service_unit = manager.LoadUnit(service_name)
service_proxy = bus.get_object('org.freedesktop.systemd1', str(service_unit))
service = dbus.Interface(service_proxy, dbus_interface='org.freedesktop.systemd1.Unit')
service_res = service_proxy.Get('org.freedesktop.systemd1.Unit','SubState', dbus_interface='org.freedesktop.DBus.Properties')
if service_res == 'running':
print('OK: %s is running' % service_name)
sys.exit(0)
else:
print('CRITICAL: %s is not running' % service_name)
sys.exit(2)
except dbus.DBusException as e:
print('CRITICAL: unable to find %s in systemd' % service_name)
sys.exit(2)
except dbus.DBusException as e:
print('CRITICAL: unable to connect to system for %s' % service_name)
sys.exit(2)