@@ -33,7 +33,7 @@ def get_apps(self):
33
33
else :
34
34
raise NewRelicApiException ("Error, Invalid status code %d" % (request .status_code ))
35
35
except Exception as e :
36
- raise NewRelicApiException (e )
36
+ raise NewRelicApiException (str ( e ) )
37
37
38
38
def get_app (self , app_id ):
39
39
@@ -51,16 +51,16 @@ def get_app(self, app_id):
51
51
else :
52
52
raise NewRelicApiException ("Error, Invalid status code %d" % (request .status_code ))
53
53
except Exception as e :
54
- raise NewRelicApiException (e )
54
+ raise NewRelicApiException (str ( e ) )
55
55
56
- def get_metrics (self , app_id , metric_name = None ):
56
+ def get_metrics (self , app_id , name = None ):
57
57
58
58
if app_id is None or app_id == "" :
59
59
raise NewRelicInvalidParameterException ("NewRelic application id is required!" )
60
60
61
- data = ''
62
- if metric_name is not None and metric_name .strip () != "" :
63
- data = "name=%s" % ( metric_name )
61
+ data = {}
62
+ if name is not None and name .strip () != "" :
63
+ data [ "name" ] = name
64
64
65
65
try :
66
66
request = requests .get (
@@ -73,17 +73,52 @@ def get_metrics(self, app_id, metric_name=None):
73
73
else :
74
74
raise NewRelicApiException ("Error, Invalid status code %d" % (request .status_code ))
75
75
except Exception as e :
76
- raise NewRelicApiException (e )
76
+ raise NewRelicApiException (str ( e ) )
77
77
78
- def get_metric (self , app_id , metric_name ):
78
+ def get_metric (self , app_id , names = [], values = [], start = None , end = None , summarize = False ):
79
79
80
80
if app_id is None or app_id == "" :
81
81
raise NewRelicInvalidParameterException ("NewRelic application id is required!" )
82
82
83
- if metric_name is None or metric_name == "" :
84
- raise NewRelicInvalidParameterException ("NewRelic metric name is required!" )
83
+ if len ( names ) == 0 :
84
+ raise NewRelicInvalidParameterException ("NewRelic application metric name(s) is required!" )
85
85
86
- raise NotImplementedError ("NewRelic get_metric method not implemented yet!" )
86
+ if len (values ) == 0 :
87
+ raise NewRelicInvalidParameterException ("NewRelic application metric value(s) is required!" )
88
+
89
+ data = {}
90
+ data ["names[]" ] = []
91
+ data ["values[]" ] = []
92
+
93
+ for name in names :
94
+ data ["names[]" ].append (name )
95
+
96
+ for value in values :
97
+ data ["values[]" ].append (value )
98
+
99
+ if start is not None :
100
+ data ["from" ] = start
101
+
102
+ if end is not None :
103
+ data ["to" ] = end
104
+
105
+ if summarize :
106
+ data ["summarize" ] = "true"
107
+ else :
108
+ data ["summarize" ] = "false"
109
+
110
+ try :
111
+ request = requests .get (
112
+ self .__metric_info_endpoint .format (url = self .__api_url , version = self .__api_version , app_id = app_id ),
113
+ headers = self .get_headers (),
114
+ data = data
115
+ )
116
+ if request .status_code == 200 :
117
+ return request
118
+ else :
119
+ raise NewRelicApiException ("Error, Invalid status code %d" % (request .status_code ))
120
+ except Exception as e :
121
+ raise NewRelicApiException (str (e ))
87
122
88
123
def get_headers (self ):
89
124
if self .api_key .strip () == "" :
0 commit comments