MaxSem has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/50376


Change subject: Fix exception handling, lint
......................................................................

Fix exception handling, lint

Change-Id: I5748b374f37d886c80a66afc6bf6a91f22058a50
---
M files/nagios/check_solr
1 file changed, 13 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/76/50376/1

diff --git a/files/nagios/check_solr b/files/nagios/check_solr
index bcf3f3d..cab3499 100755
--- a/files/nagios/check_solr
+++ b/files/nagios/check_solr
@@ -1,7 +1,6 @@
 #!/usr/bin/env python
 
 import urllib2
-import sqlite3
 import xml.etree.ElementTree as ET
 from optparse import OptionParser
 import json
@@ -32,6 +31,7 @@
 warnings = []
 unknowns = []
 
+
 def http_get(path):
     url = 'http://' + host + '/solr/' + path
     return urllib2.urlopen(url, None, cmd_options.timeout).read()
@@ -46,12 +46,12 @@
         warnings.append(message % (value, limits[1]))
 
 
-def check_stat(entry, statName, limits, stat_name):
+def check_stat(entry, stat, limits, stat_name):
     if limits == None:
         return
     stats = entry.find('stats')
     for node in stats.getiterator('stat'):
-        if node.attrib['name'] == statName:
+        if node.attrib['name'] == stat:
             check_value(node.text, limits, stat_name + ' is %s (gt %s)')
             return
     unknowns.append('Parameter "%s" not found in response' % stat)
@@ -125,16 +125,22 @@
     return 0
 
 
+def format_exception(ex):
+    return '%s: %s' % (type(ex).__name__, ex)
+
+
 try:
     check_all_stats()
     check_replication()
 
-except Exception as err:
-    (e, ) = err.args
-    if isinstance(err, urllib2.URLError) and e.errno == 115:
+except urllib2.URLError as ex:
+    (e, ) = ex.args
+    if e.errno == 115:
         msg = 'Request timeout after %ds' % cmd_options.timeout
     else:
-        msg = '%s: %s' % (type(err).__name__, e)
+        msg = format_exception(ex)
     unknowns.append(msg)
+except Exception as ex:
+    unknowns.append(format_exception(ex))
 
 exit(process_results())

-- 
To view, visit https://gerrit.wikimedia.org/r/50376
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5748b374f37d886c80a66afc6bf6a91f22058a50
Gerrit-PatchSet: 1
Gerrit-Project: operations/puppet
Gerrit-Branch: production
Gerrit-Owner: MaxSem <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to