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

Subscribers

People subscribed via source and target branches

to all changes: