Merge lp:~brad-marshall/charms/precise/nrpe-external-master/add-systemd-nagios-check into lp:charms/nrpe-external-master

Proposed by Brad Marshall
Status: Merged
Merged at revision: 42
Proposed branch: lp:~brad-marshall/charms/precise/nrpe-external-master/add-systemd-nagios-check
Merge into: lp:charms/nrpe-external-master
Diff against target: 43 lines (+39/-0)
1 file modified
files/check_systemd.py (+39/-0)
To merge this branch: bzr merge lp:~brad-marshall/charms/precise/nrpe-external-master/add-systemd-nagios-check
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Approve
Review Queue (community) automated testing Approve
Review via email: mp+294086@code.launchpad.net

Description of the change

Add systemd nagios check

To post a comment you must log in.
Revision history for this message
Review Queue (review-queue) wrote :

The results (PASS) are in and available here: http://juju-ci.vapour.ws:8080/job/charm-bundle-test-lxc/4101/

review: Approve (automated testing)
Revision history for this message
Review Queue (review-queue) wrote :

The results (PASS) are in and available here: http://juju-ci.vapour.ws:8080/job/charm-bundle-test-aws/4115/

review: Approve (automated testing)
Revision history for this message
Stuart Bishop (stub) :
review: Approve
Revision history for this message
Stuart Bishop (stub) wrote :

Looks good.

The new file does nothing until the charm adds a check that makes use of it.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'files/check_systemd.py'
2--- files/check_systemd.py 1970-01-01 00:00:00 +0000
3+++ files/check_systemd.py 2016-05-09 05:00:31 +0000
4@@ -0,0 +1,39 @@
5+#!/usr/bin/python3
6+#
7+# Copyright 2016 Canonical Ltd
8+#
9+# Author: Brad Marshall <brad.marshall@canonical.com>
10+#
11+# Based on check_upstart_job and https://zignar.net/2014/09/08/getting-started-with-dbus-python-systemd/
12+#
13+
14+import dbus, sys
15+
16+service_arg = sys.argv[1]
17+service_name = "%s.service" % service_arg
18+
19+try:
20+ bus = dbus.SystemBus()
21+ systemd = bus.get_object('org.freedesktop.systemd1', '/org/freedesktop/systemd1')
22+ manager = dbus.Interface(systemd, dbus_interface='org.freedesktop.systemd1.Manager')
23+ try:
24+ service_unit = manager.LoadUnit(service_name)
25+ service_proxy = bus.get_object('org.freedesktop.systemd1', str(service_unit))
26+ service = dbus.Interface(service_proxy, dbus_interface='org.freedesktop.systemd1.Unit')
27+ service_res = service_proxy.Get('org.freedesktop.systemd1.Unit','ActiveState', dbus_interface='org.freedesktop.DBus.Properties')
28+
29+ if service_res == 'active':
30+ print('OK: %s is running' % service_name)
31+ sys.exit(0)
32+ else:
33+ print('CRITICAL: %s is not running' % service_name)
34+ sys.exit(2)
35+
36+ except dbus.DBusException as e:
37+ print('CRITICAL: unable to find %s in systemd' % service_name)
38+ sys.exit(2)
39+
40+except dbus.DBusException as e:
41+ print('CRITICAL: unable to connect to system for %s' % service_name)
42+ sys.exit(2)
43+

Subscribers

People subscribed via source and target branches

to all changes: