Merge lp:~macgreagoir/charms/precise/nrpe-external-master/upstart-critical into lp:charms/nrpe-external-master

Proposed by Mick Gregg
Status: Merged
Merged at revision: 40
Proposed branch: lp:~macgreagoir/charms/precise/nrpe-external-master/upstart-critical
Merge into: lp:charms/nrpe-external-master
Diff against target: 57 lines (+14/-7)
1 file modified
files/check_upstart_job (+14/-7)
To merge this branch: bzr merge lp:~macgreagoir/charms/precise/nrpe-external-master/upstart-critical
Reviewer Review Type Date Requested Status
Charles Butler (community) Approve
Adam Israel (community) Approve
Review via email: mp+254597@code.launchpad.net

Description of the change

When a service is stopped an exception is thrown when trying to GetInstance() for its job. This needs to be caught to allow the calling block to return CRITICAL.

Related, the length of states[] in the exception block needs to be checked for 0, rather than assuming to use an empty array, where length of zero will equal a running count of zero.

To post a comment you must log in.
Revision history for this message
Adam Israel (aisrael) wrote :

Hi Mick,

I had the opportunity to review this merge proposal today. All of my checks are passing, and I've confirmed that the fix works as intended.

Thanks for your work on this! +1

review: Approve
Revision history for this message
Charles Butler (lazypower) wrote :

+1 on this, LGTM

Thanks for the contribution. I've pushed this to the charm store, and it should be available immediately.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'files/check_upstart_job'
2--- files/check_upstart_job 2014-11-18 01:23:42 +0000
3+++ files/check_upstart_job 2015-03-30 16:08:04 +0000
4@@ -18,16 +18,21 @@
5 self._bus = dbus.SystemBus()
6 self._upstart = self._bus.get_object('com.ubuntu.Upstart',
7 '/com/ubuntu/Upstart')
8+
9 def get_job(self, job_name):
10 path = self._upstart.GetJobByName(job_name,
11 dbus_interface='com.ubuntu.Upstart0_6')
12 return self._bus.get_object('com.ubuntu.Upstart', path)
13
14 def get_properties(self, job):
15- path = job.GetInstance([], dbus_interface='com.ubuntu.Upstart0_6.Job')
16- instance = self._bus.get_object('com.ubuntu.Upstart', path)
17- return instance.GetAll('com.ubuntu.Upstart0_6.Instance',
18- dbus_interface=dbus.PROPERTIES_IFACE)
19+ try:
20+ path = job.GetInstance([],
21+ dbus_interface='com.ubuntu.Upstart0_6.Job')
22+ instance = self._bus.get_object('com.ubuntu.Upstart', path)
23+ return instance.GetAll('com.ubuntu.Upstart0_6.Instance',
24+ dbus_interface=dbus.PROPERTIES_IFACE)
25+ except:
26+ return None
27
28 def get_job_instances(self, job_name):
29 job = self.get_job(job_name)
30@@ -41,10 +46,10 @@
31 try:
32 upstart = Upstart()
33 try:
34- job = upstart.get_job(sys.argv[1])
35+ job = upstart.get_job(sys.argv[1])
36 props = upstart.get_properties(job)
37
38- if props['state'] == 'running':
39+ if props and props['state'] == 'running':
40 print 'OK: %s is running' % sys.argv[1]
41 sys.exit(0)
42 else:
43@@ -55,6 +60,9 @@
44 instances = upstart.get_job_instances(sys.argv[1])
45 propses = [upstart.get_job_instance_properties(instance) for instance in instances]
46 states = dict([(props['name'], props['state']) for props in propses])
47+ if len(states) == 0:
48+ print 'CRITICAL: 0 instances of %s running' % sys.argv[1]
49+ sys.exit(2)
50 if len(states) != states.values().count('running'):
51 not_running = []
52 for name in states.keys():
53@@ -69,4 +77,3 @@
54 except dbus.DBusException as e:
55 print 'CRITICAL: failed to get properties of \'%s\' from upstart' % sys.argv[1]
56 sys.exit(2)
57-

Subscribers

People subscribed via source and target branches

to all changes: