Browse Source

Se actualiza el servicio end.point para poder lanzar exception
opcionalmente.

Maximiliano Schvindt 7 years ago
parent
commit
6548f60a91
2 changed files with 24 additions and 7 deletions
  1. 15 4
      Command/EndpointMysqlCommand.php
  2. 9 3
      Services/EndpointMysql.php

+ 15 - 4
Command/EndpointMysqlCommand.php

@@ -28,11 +28,22 @@ class EndpointMysqlCommand extends ContainerAwareCommand
 
         $json = '{"range":{"from":"2017-11-13T14:09:25.307Z","to":"2017-11-13T17:09:25.308Z"},"intervalMs":0,"targets":[{"target":"d_3_s_1_snmp_ponRxPower"}],"format":"json","maxDataPoints":10}';
         
-        $result = $endpoint->get($json,'last');
-        
-        //$result = $endpoint->get($json,'query');
 
-        print_r($result);
+        $subName = "d_1_s_1";
+        $targets = array();
+        $targets["in_bandwidth"] = array("target" => "{$subName}_inbandwidth_olt");
+        $targets["out_bandwidth"] = array("target" => "{$subName}_outbandwidth_olt");
+        
+        foreach($targets as $t) {
+
+            $data = array('targets' => array(0 => $t), 'maxDataPoints' => 10);
+            
+            $json = json_encode($data);
+            
+            $result = $endpoint->get($json,'last');
+            
+            print_r($result);
+        }
         
         print_r(PHP_EOL);
         print_r(date("Y-m-d H:i:s"));

+ 9 - 3
Services/EndpointMysql.php

@@ -3,6 +3,7 @@
 namespace StatsDBundle\Services;
 
 use Symfony\Component\DependencyInjection\ContainerInterface;
+use \Exception;
 
 /**
  * Read statistics to the statsD
@@ -36,7 +37,7 @@ class EndpointMysql
      * query = [last|query|search]
      */
     
-    public function get($json, $method = "query") 
+    public function get($json, $method = "query", $exception = false) 
     {
         if(is_null($this->location)) return array();
         
@@ -53,9 +54,14 @@ class EndpointMysql
 
         $result = curl_exec($ch);
         if (curl_errno($ch)) {
-            echo 'Error:' . curl_error($ch);
+            if($exception) {
+                curl_close($ch);
+                throw new Exception(curl_error($ch));
+            } else {
+                echo 'Error:' . curl_error($ch);
+            }
         }
-        curl_close ($ch);
+        curl_close($ch);
 
         $data = json_decode($result,true);
         if(is_array($data))