Merge lp:~paulgear/charms/trusty/ntp/fix-trusty-exceptions-psutil-1.2.x into lp:charms/trusty/ntp

Proposed by Paul Gear
Status: Merged
Merged at revision: 21
Proposed branch: lp:~paulgear/charms/trusty/ntp/fix-trusty-exceptions-psutil-1.2.x
Merge into: lp:charms/trusty/ntp
Diff against target: 33 lines (+6/-3)
1 file modified
files/nagios/check_ntpmon.py (+6/-3)
To merge this branch: bzr merge lp:~paulgear/charms/trusty/ntp/fix-trusty-exceptions-psutil-1.2.x
Reviewer Review Type Date Requested Status
Tim Van Steenburgh (community) Approve
Adam Israel (community) Approve
Review via email: mp+260080@code.launchpad.net

Description of the change

Trusty has python-psutils 1.2.x; check_ntpmon.py was written against 2.1.x. This allows the code to work with both versions of psutils.

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

Hi Paul,

Thanks for your work on this! I had the opportunity to review this merge proposal today. This is a pretty straightforward modification, and I'm happy to see this issue fixed. You have my +1.

Thanks again!

review: Approve
Revision history for this message
Adam Collard (adam-collard) :
22. By Paul Gear

Change name of check variable to more accurately reflect purpose

Revision history for this message
Tim Van Steenburgh (tvansteenburgh) wrote :

+1 LGTM, thanks Paul!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'files/nagios/check_ntpmon.py'
--- files/nagios/check_ntpmon.py 2015-04-27 13:24:11 +0000
+++ files/nagios/check_ntpmon.py 2015-05-30 22:50:13 +0000
@@ -422,10 +422,13 @@
422 """Look for ntpd or xntpd in the process table and save its process object."""422 """Look for ntpd or xntpd in the process table and save its process object."""
423 if names is None:423 if names is None:
424 names = ["ntpd", "xntpd"]424 names = ["ntpd", "xntpd"]
425 # Check for old psutil per http://grodola.blogspot.com.au/2014/01/psutil-20-porting.html
426 self.PSUTIL2 = psutil.version_info >= (2, 0)
425 self.proc = None427 self.proc = None
426 for proc in psutil.process_iter():428 for proc in psutil.process_iter():
427 try:429 try:
428 if proc.name() in names:430 name = proc.name() if self.PSUTIL2 else proc.name
431 if name in names:
429 self.proc = proc432 self.proc = proc
430 break433 break
431 except psutil.Error:434 except psutil.Error:
@@ -438,7 +441,8 @@
438 return -1441 return -1
439 try:442 try:
440 now = time.time()443 now = time.time()
441 start = int(self.proc.create_time())444 create_time = self.proc.create_time() if self.PSUTIL2 else self.proc.create_time
445 start = int(create_time)
442 return now - start446 return now - start
443 except psutil.Error:447 except psutil.Error:
444 return -1448 return -1
@@ -541,4 +545,3 @@
541545
542if __name__ == "__main__":546if __name__ == "__main__":
543 main()547 main()
544

Subscribers

People subscribed via source and target branches

to all changes: