[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a

Gerhard Lausser gerhard.lausser at consol.de
Tue Feb 28 22:16:51 UTC 2012


The following commit has been merged in the debian/master branch:
commit baaa954f748ba04428f43faecd402e55470af0f1
Author: Gerhard Lausser <gerhard.lausser at consol.de>
Date:   Sat Jan 28 19:12:45 2012 +0100

    Enh: make livestatus module more robust against malformed queries

diff --git a/shinken/modules/livestatus_broker/livestatus_response.py b/shinken/modules/livestatus_broker/livestatus_response.py
index 434e04e..a39acc5 100644
--- a/shinken/modules/livestatus_broker/livestatus_response.py
+++ b/shinken/modules/livestatus_broker/livestatus_response.py
@@ -114,21 +114,22 @@ class LiveStatusResponse:
                         if hasattr(item, attribute):
                             value = getattr(item.__class__, attribute).im_func.default
                         else:
-                            value = getattr(item.__class__, attribute).im_func.default
+                            # If nothing else helps, leave the column blank
+                            value = ''
                     if isinstance(value, list):
                         l.append(self.separators[2].join(str(x) for x in value))
                     elif isinstance(value, bool):
                         if value == True:
-                            l.append("1")
+                            l.append('1')
                         else:
-                            l.append("0")
+                            l.append('0')
                     else:
                         try:
                             l.append(str(value))
                         except UnicodeEncodeError:
-                            l.append(value.encode("utf-8", "replace"))
+                            l.append(value.encode('utf-8', 'replace'))
                         except Exception:
-                            l.append("")
+                            l.append('')
                 lines.append(self.separators[1].join(l))
             if len(lines) > 0:
                 if self.columnheaders != 'off' or not query_with_columns:
@@ -161,14 +162,19 @@ class LiveStatusResponse:
                             #print "FALLBACK: %s.%s" % (type(item), attribute)
                             value = getattr(item.__class__, attribute).im_func.default
                         else:
-                            value = getattr(item.__class__, attribute).im_func.default
+                            value = ''
                     if isinstance(value, bool):
                         if value == True:
                             rows.append(1)
                         else:
                             rows.append(0)
                     else:
-                        rows.append(value)
+                        try:
+                            rows.append(value)
+                        except UnicodeEncodeError:
+                            rows.append(value.encode('utf-8', 'replace'))
+                        except Exception:
+                            rows.append('')
                 lines.append(rows)
             if self.columnheaders == 'on':
                 if len(aliases) > 0:
diff --git a/test/test_livestatus.py b/test/test_livestatus.py
index e503b6e..7e49c78 100755
--- a/test/test_livestatus.py
+++ b/test/test_livestatus.py
@@ -361,6 +361,42 @@ ResponseHeader: fixed16
             print nagresponse
             self.assert_(self.lines_equal(response, nagresponse))
 
+    def test_bad_column(self):
+        self.print_header()
+        now = time.time()
+        objlist = []
+        for host in self.sched.hosts:
+            objlist.append([host, 0, 'UP'])
+        for service in self.sched.services:
+            objlist.append([service, 0, 'OK'])
+        self.scheduler_loop(1, objlist)
+        self.update_broker()
+        request = """GET services
+Columns: host_name wrdlbrmpft description 
+Filter: host_name = test_host_0
+OutputFormat: csv
+KeepAlive: on
+ResponseHeader: off
+"""
+        response, keepalive = self.livestatus_broker.livestatus.handle_request(request)
+        print response
+        good_response = """test_host_0;;test_ok_0
+"""
+        self.assert_(response == good_response)
+        request = """GET services
+Columns: host_name wrdlbrmpft description 
+Filter: host_name = test_host_0
+OutputFormat: python
+KeepAlive: on
+ResponseHeader: off
+"""
+        response, keepalive = self.livestatus_broker.livestatus.handle_request(request)
+        print response
+        good_response = """[[u'test_host_0', u'', u'test_ok_0']]
+"""
+        self.assert_(response == good_response)
+
+
 
 
     def test_servicesbyhostgroup(self):

-- 
UNNAMED PROJECT



More information about the Pkg-nagios-changes mailing list