grafana 0.8.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +8 -3
  3. data/lib/grafana/admin.rb +39 -65
  4. data/lib/grafana/alerts.rb +334 -14
  5. data/lib/grafana/annotations.rb +284 -9
  6. data/lib/grafana/client.rb +38 -1
  7. data/lib/grafana/dashboard.rb +182 -39
  8. data/lib/grafana/dashboard_permissions.rb +132 -0
  9. data/lib/grafana/dashboard_versions.rb +101 -5
  10. data/lib/grafana/datasource.rb +93 -49
  11. data/lib/grafana/folder.rb +198 -0
  12. data/lib/grafana/folder_and_dashboard_search.rb +57 -0
  13. data/lib/grafana/folder_permissions.rb +155 -0
  14. data/lib/grafana/login.rb +41 -35
  15. data/lib/grafana/network.rb +128 -91
  16. data/lib/grafana/organization.rb +65 -34
  17. data/lib/grafana/organizations.rb +119 -175
  18. data/lib/grafana/playlist.rb +599 -0
  19. data/lib/grafana/preferences.rb +122 -0
  20. data/lib/grafana/tags.rb +19 -8
  21. data/lib/grafana/teams.rb +364 -0
  22. data/lib/grafana/tools.rb +44 -12
  23. data/lib/grafana/user.rb +78 -39
  24. data/lib/grafana/users.rb +104 -53
  25. data/lib/grafana/validator.rb +47 -2
  26. data/lib/grafana/version.rb +3 -3
  27. metadata +13 -38
  28. data/doc/Array.html +0 -200
  29. data/doc/Boolean.html +0 -122
  30. data/doc/FalseClass.html +0 -132
  31. data/doc/Grafana.html +0 -172
  32. data/doc/Hash.html +0 -212
  33. data/doc/Logging.html +0 -326
  34. data/doc/Object.html +0 -286
  35. data/doc/Time.html +0 -200
  36. data/doc/TrueClass.html +0 -132
  37. data/doc/_index.html +0 -380
  38. data/doc/class_list.html +0 -51
  39. data/doc/file.README.html +0 -117
  40. data/doc/file_list.html +0 -56
  41. data/doc/frames.html +0 -17
  42. data/doc/index.html +0 -117
  43. data/doc/method_list.html +0 -771
  44. data/doc/top-level-namespace.html +0 -112
@@ -0,0 +1,132 @@
1
+
2
+ module Grafana
3
+
4
+ # http://docs.grafana.org/http_api/dashboard_permissions/#dashboard-permissions-api
5
+ #
6
+ # This API can be used to update/get the permissions for a dashboard.
7
+ # Permissions with dashboardId=-1 are the default permissions for users with the Viewer and Editor roles.
8
+ # Permissions can be set for a user, a team or a role (Viewer or Editor).
9
+ # Permissions cannot be set for Admins - they always have access to everything.
10
+ #
11
+ # The permission levels for the permission field:
12
+ #
13
+ # 1 = View
14
+ # 2 = Edit
15
+ # 4 = Admin
16
+ #
17
+ module DashboardPermissions
18
+
19
+ # http://docs.grafana.org/http_api/dashboard_permissions/#get-permissions-for-a-dashboard
20
+ #
21
+ # GET /api/dashboards/id/:dashboardId/permissions
22
+ #
23
+ # Gets all existing permissions for the dashboard with the given dashboardId.
24
+ #
25
+ def dashboard_permissions(uid)
26
+
27
+ if( uid.is_a?(String) && uid.is_a?(Integer) )
28
+ raise ArgumentError.new(format('wrong type. dashboard \'uid\' must be an String (for an title name) or an Integer (for an Datasource Id), given \'%s\'', uid.class.to_s))
29
+ end
30
+ raise ArgumentError.new('missing \'uid\'') if( uid.size.zero? )
31
+
32
+ endpoint = format( '/api/dashboards/id/%s/permissions', uid )
33
+ @logger.debug( "Attempting to get dashboard permissions (GET #{endpoint})" ) if @debug
34
+
35
+ r = get( endpoint )
36
+ r['message'] = format('dashboard \'%s\' not found', uid) if(r.dig('status') == 404)
37
+ r
38
+ end
39
+
40
+ # http://docs.grafana.org/http_api/dashboard_permissions/#update-permissions-for-a-dashboard
41
+ #
42
+ # POST /api/dashboards/id/:dashboardId/permissions
43
+ #
44
+ # Updates permissions for a dashboard.
45
+ # This operation will remove existing permissions if they're not included in the request.
46
+ #
47
+ #
48
+ def update_dashboad_permissions(params)
49
+
50
+ raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
51
+ raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
52
+
53
+ v, mv = version.values
54
+ return { 'status' => 404, 'message' => format( 'folder has been supported in Grafana since version 5. you use version %s', v) } if(mv < 5)
55
+
56
+ dashboard_id = validate( params, required: true, var: 'dashboard_id', type: Integer )
57
+ permissions = validate( params, required: true, var: 'permissions' , type: Hash )
58
+
59
+ return { 'status' => 404, 'message' => 'no permissions given' } if( permissions.size.zero? )
60
+
61
+ valid_roles = %w[View Edit Admin]
62
+
63
+ c_team = permissions.dig('team')
64
+ c_user = permissions.dig('user')
65
+ team = []
66
+ user = []
67
+
68
+ unless(c_team.nil?)
69
+ check_keys = []
70
+
71
+ c_team.uniq.each do |x|
72
+ k = x.keys.first
73
+ v = x.values.first
74
+ r = validate_hash( v, valid_roles )
75
+
76
+ f_team = team(k)
77
+ team_id = f_team.dig('id')
78
+
79
+ next unless(( f_team.dig('status') == 200) && !check_keys.include?(team_id) && r == true )
80
+
81
+ check_keys << team_id
82
+
83
+ role_id = valid_roles.index(v)
84
+ role_id += 1
85
+ role_id += 1 if(v == 'Admin')
86
+
87
+ team << {
88
+ teamId: team_id,
89
+ permission: role_id
90
+ }
91
+ end
92
+ end
93
+
94
+ unless(c_user.nil?)
95
+ check_keys = []
96
+
97
+ c_user.uniq.each do |x|
98
+ k = x.keys.first
99
+ v = x.values.first
100
+ r = validate_hash( v, valid_roles )
101
+
102
+ f_user = user(k)
103
+ user_id = f_user.dig('id')
104
+
105
+ next unless(( f_user.dig('status') == 200) && !check_keys.include?(user_id) && r == true )
106
+
107
+ check_keys << user_id
108
+
109
+ role_id = valid_roles.index(v)
110
+ role_id += 1
111
+ role_id += 1 if(v == 'Admin')
112
+
113
+ user << {
114
+ userId: user_id,
115
+ permission: role_id
116
+ }
117
+ end
118
+ end
119
+
120
+ payload = {
121
+ items: team + user
122
+ }
123
+ payload.reject!{ |_, y| y.nil? }
124
+
125
+
126
+ endpoint = format('/api/dashboards/id/%s/permissions', dashboard_id)
127
+ post(endpoint, payload.to_json)
128
+ end
129
+
130
+ end
131
+
132
+ end
@@ -1,29 +1,125 @@
1
1
 
2
2
  module Grafana
3
3
 
4
- # http://docs.grafana.org/http_api/annotations/
4
+ # http://docs.grafana.org/http_api/dashboard_versions
5
5
  #
6
6
  module DashboardVersions
7
7
 
8
8
  # Get all dashboard versions
9
9
  # http://docs.grafana.org/http_api/dashboard_versions/#get-all-dashboard-versions
10
10
  # GET /api/dashboards/id/:dashboardId/versions
11
- def dashboard_all_versions( params ); end
11
+ #
12
+ #
13
+ #
14
+ #
15
+ #
16
+ #
17
+ def dashboard_all_versions( params )
18
+
19
+ raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
20
+ raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
21
+
22
+ # v, mv = version.values
23
+ # return { 'status' => 404, 'message' => format( 'dashboard has been supported in Grafana since version 5. you use version %s', v) } if(mv < 5)
24
+
25
+ dashboard_id = validate( params, required: true , var: 'dashboard_id', type: Integer )
26
+ start = validate( params, required: false, var: 'start' , type: Integer )
27
+ limit = validate( params, required: false, var: 'limit' , type: Integer )
28
+
29
+ api = []
30
+ api << format( 'start=%s', start ) unless( start.nil? )
31
+ api << format( 'limit=%s', limit ) unless( limit.nil? )
32
+ api = api.join( '&' )
33
+
34
+ endpoint = format('/api/dashboards/id/%s/versions?%s', dashboard_id, api)
35
+ get(endpoint)
36
+ end
12
37
 
13
38
  # Get dashboard version
14
39
  # http://docs.grafana.org/http_api/dashboard_versions/#get-dashboard-version
15
40
  # GET /api/dashboards/id/:dashboardId/versions/:id
16
- def dashboard_version( params ); end
41
+ def dashboard_version( params )
42
+
43
+ raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
44
+ raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
45
+
46
+ v, mv = version.values
47
+ return { 'status' => 404, 'message' => format( 'folder has been supported in Grafana since version 5. you use version %s', v) } if(mv < 5)
48
+
49
+ dashboard_id = validate( params, required: true, var: 'dashboard_id', type: Integer )
50
+ version = validate( params, required: true, var: 'version' , type: Integer )
51
+
52
+ endpoint = format('/api/dashboards/id/%s/versions/%s', dashboard_id, version)
53
+
54
+ r = get(endpoint)
55
+
56
+ r['message'] = format('no dashboard version \'%s\' for dashboard \'%s\' found', version, dashboard_id) if(r.dig('status') == 404)
57
+ r['message'] = format('no dashboard version \'%s\' for dashboard \'%s\' found', version, dashboard_id) if(r.dig('status') == 500)
58
+ r
59
+ end
17
60
 
18
61
  # Restore dashboard
19
62
  # http://docs.grafana.org/http_api/dashboard_versions/#restore-dashboard
20
63
  # POST /api/dashboards/id/:dashboardId/restore
21
- def restore_dashboard( params ); end
64
+ def restore_dashboard( params )
65
+
66
+ raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
67
+ raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
68
+
69
+ # v, mv = version.values
70
+ # return { 'status' => 404, 'message' => format( 'folder has been supported in Grafana since version 5. you use version %s', v) } if(mv < 5)
71
+
72
+ dashboard_id = validate( params, required: true, var: 'dashboard_id', type: Integer )
73
+ version = validate( params, required: true, var: 'version' , type: Integer )
74
+
75
+ endpoint = format('/api/dashboards/id/%s/restore', dashboard_id)
76
+
77
+ payload = {
78
+ version: version
79
+ }
80
+
81
+ post(endpoint, payload.to_json)
82
+ end
22
83
 
23
84
  # Compare dashboard versions
24
85
  # http://docs.grafana.org/http_api/dashboard_versions/#compare-dashboard-versions
25
86
  # POST /api/dashboards/calculate-diff
26
- def compare_dashboard_version( params ); end
87
+ def compare_dashboard_version( params )
88
+
89
+ raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
90
+ raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
91
+
92
+ base = validate( params, required: true , var: 'base' , type: Hash )
93
+ new = validate( params, required: true , var: 'new' , type: Hash )
94
+ diff_type = validate( params, required: false, var: 'diff_type', type: String ) || 'json'
95
+
96
+ base_dashboard_id = validate( base, required: true , var: 'dashboard_id', type: Integer )
97
+ base_dashboard_version = validate( base, required: true , var: 'version' , type: Integer )
98
+ new_dashboard_id = validate( new , required: true , var: 'dashboard_id', type: Integer )
99
+ new_dashboard_version = validate( new , required: true , var: 'version' , type: Integer )
100
+
101
+ valid_diff_type = %w[json basic]
102
+
103
+ r = validate_hash(diff_type, valid_diff_type)
104
+
105
+ return r unless(r == true)
106
+
107
+ payload = {
108
+ base: {
109
+ dashboardId: base_dashboard_id,
110
+ version: base_dashboard_version
111
+ },
112
+ new: {
113
+ dashboardId: new_dashboard_id,
114
+ version: new_dashboard_version
115
+ },
116
+ diffType: diff_type
117
+ }
118
+
119
+ endpoint = '/api/dashboards/calculate-diff'
120
+
121
+ post(endpoint, payload.to_json)
122
+ end
27
123
 
28
124
  end
29
125
 
@@ -20,12 +20,7 @@ module Grafana
20
20
 
21
21
  datasources = get( endpoint )
22
22
 
23
- if datasources.nil? || datasources.dig('status').to_i != 200
24
- return {
25
- 'status' => 404,
26
- 'message' => 'No Datasources found'
27
- }
28
- end
23
+ return { 'status' => 404, 'message' => 'No Datasources found' } if( datasources.nil? || datasources == false || datasources.dig('status').to_i != 200 )
29
24
 
30
25
  datasources = datasources.dig('message')
31
26
 
@@ -39,6 +34,8 @@ module Grafana
39
34
 
40
35
  # Get a single datasources by Id or Name
41
36
  #
37
+ # @param [Mixed] datasource_id Datasource Name (String) or Datasource Id (Integer)
38
+ #
42
39
  # @example
43
40
  # datasource( 1 )
44
41
  # datasource( 'foo' )
@@ -47,7 +44,9 @@ module Grafana
47
44
  #
48
45
  def datasource( datasource_id )
49
46
 
50
- raise ArgumentError.new(format('wrong type. user \'datasource_id\' must be an String (for an Datasource name) or an Integer (for an Datasource Id), given \'%s\'', datasource_id.class.to_s)) if( datasource_id.is_a?(String) && datasource_id.is_a?(Integer) )
47
+ if( datasource_id.is_a?(String) && datasource_id.is_a?(Integer) )
48
+ raise ArgumentError.new(format('wrong type. \'datasource_id\' must be an String (for an Datasource name) or an Integer (for an Datasource Id), given \'%s\'', datasource_id.class.to_s))
49
+ end
51
50
  raise ArgumentError.new('missing \'datasource_id\'') if( datasource_id.size.zero? )
52
51
 
53
52
  if(datasource_id.is_a?(String))
@@ -55,12 +54,7 @@ module Grafana
55
54
  datasource_id = data.keys.first if( data )
56
55
  end
57
56
 
58
- if( datasource_id.nil? )
59
- return {
60
- 'status' => 404,
61
- 'message' => format( 'No Datasource \'%s\' found', datasource_id)
62
- }
63
- end
57
+ return { 'status' => 404, 'message' => format( 'No Datasource \'%s\' found', datasource_id) } if( datasource_id.nil? )
64
58
 
65
59
  raise format('DataSource Id can not be 0') if( datasource_id.zero? )
66
60
 
@@ -82,14 +76,29 @@ module Grafana
82
76
  # merge an current existing datasource configuration with the new values
83
77
  #
84
78
  # @param [Hash] params
85
- # @option params [Hash] data
86
- # @option params [Mixed] datasource Datasource Name (String) or Datasource Id (Integer)
79
+ # @option params [Mixed] name Name or Id of the current existing Datasource (required)
80
+ # @option params [Mixed] organisation Name or Id of an existing Organisation
81
+ # @option params [String] type Datasource Type - (required) (grafana graphite cloudwatch elasticsearch prometheus influxdb mysql opentsdb postgres)
82
+ # @option params [String] new_name New Datasource Name
83
+ # @option params [String] database Datasource Database
84
+ # @option params [String] access (proxy) Acess Type
85
+ # @option params [Boolean] default (false)
86
+ # @option params [String] user
87
+ # @option params [String] password
88
+ # @option params [String] url Datasource URL
89
+ # @option params [Hash] json_data
90
+ # @option params [String] basic_user
91
+ # @option params [String] basic_password
87
92
  #
88
93
  # @example
89
- # update_datasource(
90
- # datasource: 'graphite',
91
- # data: { url: 'http://localhost:2003' }
92
- # )
94
+ # params = {
95
+ # name: 'graphite',
96
+ # new_name: 'influx',
97
+ # organisation: 'Main Org.',
98
+ # type: 'influxdb',
99
+ # url: 'http://localhost:8090'
100
+ # }
101
+ # update_datasource( params )
93
102
  #
94
103
  # @return [Hash]
95
104
  #
@@ -98,24 +107,76 @@ module Grafana
98
107
  raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
99
108
  raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
100
109
 
101
- data = validate( params, required: true, var: 'data', type: Hash )
102
- datasource = validate( params, required: true, var: 'datasource' )
110
+ name = validate( params, required: true , var: 'name' )
111
+ organisation = validate( params, required: false, var: 'organisation' )
112
+ type = validate( params, required: false, var: 'type', type: String )
113
+ new_name = validate( params, required: false, var: 'new_name', type: String )
114
+ database = validate( params, required: false, var: 'database', type: String )
115
+ access = validate( params, required: false, var: 'access', type: String ) || 'proxy'
116
+ default = validate( params, required: false, var: 'default', type: Boolean ) || false
117
+ user = validate( params, required: false, var: 'user', type: String )
118
+ password = validate( params, required: false, var: 'password', type: String )
119
+ url = validate( params, required: false, var: 'url', type: String )
120
+ json_data = validate( params, required: false, var: 'json_data', type: Hash )
121
+ ba_user = validate( params, required: false, var: 'basic_user', type: String )
122
+ ba_password = validate( params, required: false, var: 'basic_password', type: String )
123
+ basic_auth = false
124
+ basic_auth = true unless( ba_user.nil? && ba_password.nil? )
125
+ org_id = nil
126
+
127
+ if( name.is_a?(String) && name.is_a?(Integer) )
128
+ raise ArgumentError.new(format('wrong type. \'name\' must be an String (for an Datasource name) or an Integer (for an Datasource Id), given \'%s\'', name.class.to_s))
129
+ end
130
+ if( organisation )
131
+ if( organisation.is_a?(String) && organisation.is_a?(Integer) )
132
+ raise ArgumentError.new(format('wrong type. \'organisation\' must be an String (for an Organisation name) or an Integer (for an Organisation Id), given \'%s\'', organisation.class.to_s))
133
+ end
103
134
 
104
- raise ArgumentError.new(format('wrong type. user \'datasource\' must be an String (for an Datasource name) or an Integer (for an Datasource Id), given \'%s\'', datasource.class.to_s)) if( datasource.is_a?(String) && datasource.is_a?(Integer) )
135
+ org = organization( organisation )
136
+ org_id = org.dig('id')
105
137
 
106
- existing_ds = datasource(datasource)
138
+ return { 'status' => 404, 'message' => format('Organization \'%s\' not found', organization) } if( org.nil? || org.dig('status').to_i != 200 )
139
+ end
107
140
 
141
+ existing_ds = datasource(name)
108
142
  existing_ds.reject! { |x| x == 'status' }
109
143
  existing_ds = existing_ds.deep_string_keys
110
-
111
144
  datasource_id = existing_ds.dig('id')
112
145
 
146
+ return { 'status' => 404, 'message' => format('No Datasource \'%s\' found', name) } if( datasource_id.nil? )
147
+
148
+ raise format('Data Source Id can not be 0') if( datasource_id.zero? )
149
+
150
+ unless( type.nil? )
151
+ valid_types = %w[grafana graphite cloudwatch elasticsearch prometheus influxdb mysql opentsdb postgres]
152
+ raise ArgumentError.new(format('wrong datasource type. only %s allowed, given \%s\'', valid_types.join(', '), type)) if( valid_types.include?(type.downcase) == false )
153
+ end
154
+
155
+ data = {
156
+ id: datasource_id,
157
+ orgId: org_id,
158
+ name: new_name,
159
+ type: type,
160
+ access: access,
161
+ url: url,
162
+ password: password,
163
+ user: user,
164
+ database: database,
165
+ basicAuth: basic_auth,
166
+ basicAuthUser: ba_user,
167
+ basicAuthPassword: ba_user,
168
+ isDefault: default,
169
+ jsonData: json_data
170
+ }
171
+ data.reject!{ |_k, v| v.nil? }
172
+
113
173
  payload = data.deep_string_keys
114
174
  payload = existing_ds.merge(payload).deep_symbolize_keys
115
175
 
116
176
  endpoint = format('/api/datasources/%d', datasource_id )
177
+
117
178
  @logger.debug("Updating data source Id #{datasource_id} (GET #{endpoint})") if @debug
118
- logger.debug(payload.to_json) if(@debug)
179
+ # logger.debug(payload.to_json) if(@debug)
119
180
 
120
181
  put( endpoint, payload.to_json )
121
182
  end
@@ -125,11 +186,8 @@ module Grafana
125
186
  # @param [Hash] params
126
187
  # @option params [String] type Datasource Type - (required) (grafana graphite cloudwatch elasticsearch prometheus influxdb mysql opentsdb postgres)
127
188
  # @option params [String] name Datasource Name - (required)
128
- # @option params [String] database Datasource Database - (required)
129
189
  # @option params [String] access (proxy) Acess Type - (required) (proxy or direct)
130
190
  # @option params [Boolean] default (false)
131
- # @option params [String] user
132
- # @option params [String] password
133
191
  # @option params [String] url Datasource URL - (required)
134
192
  # @option params [Hash] json_data
135
193
  # @option params [Hash] json_secure
@@ -140,7 +198,6 @@ module Grafana
140
198
  # params = {
141
199
  # name: 'graphite',
142
200
  # type: 'graphite',
143
- # database: 'graphite',
144
201
  # url: 'http://localhost:8080'
145
202
  # }
146
203
  # create_datasource(params)
@@ -148,7 +205,6 @@ module Grafana
148
205
  # params = {
149
206
  # name: 'graphite',
150
207
  # type: 'graphite',
151
- # database: 'graphite',
152
208
  # default: true,
153
209
  # url: 'http://localhost:8080',
154
210
  # json_data: { graphiteVersion: '1.1' }
@@ -177,14 +233,11 @@ module Grafana
177
233
  raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
178
234
  raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
179
235
 
180
- type = validate( params, required: true, var: 'type', type: String )
181
- name = validate( params, required: true, var: 'name', type: String )
182
- database = validate( params, required: true, var: 'database', type: String )
236
+ type = validate( params, required: true , var: 'type', type: String )
237
+ name = validate( params, required: true , var: 'name', type: String )
183
238
  access = validate( params, required: false, var: 'access', type: String ) || 'proxy'
184
239
  default = validate( params, required: false, var: 'default', type: Boolean ) || false
185
- user = validate( params, required: false, var: 'user', type: String )
186
- password = validate( params, required: false, var: 'password', type: String )
187
- url = validate( params, required: true, var: 'url', type: String )
240
+ url = validate( params, required: true , var: 'url', type: String )
188
241
  json_data = validate( params, required: false, var: 'json_data', type: Hash )
189
242
  json_secure = validate( params, required: false, var: 'json_secure', type: Hash )
190
243
  ba_user = validate( params, required: false, var: 'basic_user', type: String )
@@ -209,14 +262,8 @@ module Grafana
209
262
  jsonData: json_data,
210
263
  secureJsonData: json_secure
211
264
  }
212
-
213
265
  payload.reject!{ |_k, v| v.nil? }
214
266
 
215
- if( @debug )
216
- logger.debug("Creating data source: #{name} (database: #{database})")
217
- logger.debug( payload.to_json )
218
- end
219
-
220
267
  endpoint = '/api/datasources'
221
268
  post(endpoint, payload.to_json)
222
269
  end
@@ -233,7 +280,9 @@ module Grafana
233
280
  #
234
281
  def delete_datasource( datasource_id )
235
282
 
236
- raise ArgumentError.new(format('wrong type. user \'datasource_id\' must be an String (for an Datasource name) or an Integer (for an Datasource Id), given \'%s\'', datasource_id.class.to_s)) if( datasource_id.is_a?(String) && datasource_id.is_a?(Integer) )
283
+ if( datasource_id.is_a?(String) && datasource_id.is_a?(Integer) )
284
+ raise ArgumentError.new(format('wrong type. \'datasource_id\' must be an String (for an Datasource name) or an Integer (for an Datasource Id), given \'%s\'', datasource_id.class.to_s))
285
+ end
237
286
  raise ArgumentError.new('missing \'datasource_id\'') if( datasource_id.size.zero? )
238
287
 
239
288
  if(datasource_id.is_a?(String))
@@ -241,12 +290,7 @@ module Grafana
241
290
  datasource_id = data.keys.first if( data )
242
291
  end
243
292
 
244
- if( datasource_id.nil? )
245
- return {
246
- 'status' => 404,
247
- 'message' => format( 'No Datasource \'%s\' found', datasource_id)
248
- }
249
- end
293
+ return { 'status' => 404, 'message' => format( 'No Datasource \'%s\' found', datasource_id) } if( datasource_id.nil? )
250
294
 
251
295
  raise format('Data Source Id can not be 0') if( datasource_id.zero? )
252
296