]> arthur.barton.de Git - netdata.git/commitdiff
escape characters in `_line()`
authorpaulfantom <paulfantom@gmail.com>
Thu, 23 Jun 2016 15:00:05 +0000 (17:00 +0200)
committerpaulfantom <paulfantom@gmail.com>
Thu, 23 Jun 2016 15:00:05 +0000 (17:00 +0200)
python.d/example.chart.py
python.d/python_modules/base.py

index 18c72032eb5a4930983a9ecce225daebae3308d6..ddf13c8c495cf3c1318e85be4dc63fa51233ae4a 100644 (file)
@@ -22,15 +22,15 @@ class Service(BaseService):
         return True
     
     def create(self):
-        chart = "CHART example.python_random '' 'A random number' 'random number' random random line " + \
-                str(self.priority) + " " + \
-                str(self.update_every) + "\n" + \
-                "DIMENSION random1 '' absolute 1 1"
-        print(chart)
+        self.chart("example.python_random", '', 'A random number', 'random number',
+                   'random', 'random', 'line', self.priority, self.update_every)
+        self.dimension('random1', '', 'absolute', 1, 1)
+        self.commit()
         return True
     
     def update(self, interval):
-        chart = "BEGIN example.python_random "+str(interval)+"\n"
-        chart += "SET random1 = "+str(random.randint(0,100))+"\n"
-        print(chart + "END")
+        self.begin("example.python_random", interval)
+        self.set("random1", random.randint(0, 100))
+        self.end()
+        self.commit()
         return True
index f411e2fe9ea71e27d1b51f4cbf99fb71766daa90..6796d9e0fb05c75accc84b75d043c6ed57ec9593 100644 (file)
@@ -137,20 +137,22 @@ class BaseService(threading.Thread):
                 else:
                     time.sleep(self.timetable['freq'])
 
-    def _line(self, *params):
+    def _line(self, instruction, *params):
         """
         Converts *params to string and joins them with one space between every one.
         :param params: str/int/float
         """
+        self.data_stream += instruction + " "
         for p in params:
+            p = str(p)
             if len(p) == 0:
-                p = "''"
-            self.data_stream += str(p)
-            self.data_stream += " "
+                p = ""
+            self.data_stream += "'" + p
+            self.data_stream += "' "
         self.data_stream += "\n"
 
-    def chart(self, type_id, name="''", title="''", units="''", family="''",
-              category="''", charttype="line", priority="''", update_every="''"):
+    def chart(self, type_id, name="", title="", units="", family="",
+              category="", charttype="line", priority="", update_every=""):
         """
         Defines a new chart.
         :param type_id: str
@@ -211,7 +213,7 @@ class BaseService(threading.Thread):
             int(microseconds)
         except TypeError:
             self.error("malformed begin statement: microseconds are not a number:", microseconds)
-            microseconds = "''"
+            microseconds = ""
 
         self._line("BEGIN", type_id, microseconds)
         return True
@@ -237,7 +239,7 @@ class BaseService(threading.Thread):
     def end(self):
         self._line("END")
 
-    def send(self):
+    def commit(self):
         """
         Upload new data to netdata
         """