grafana 0.8.5 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/Array.html +1 -1
- data/doc/Boolean.html +1 -1
- data/doc/FalseClass.html +1 -1
- data/doc/Grafana.html +1 -1
- data/doc/Hash.html +1 -1
- data/doc/Logging.html +1 -1
- data/doc/Object.html +1 -1
- data/doc/Time.html +1 -1
- data/doc/TrueClass.html +1 -1
- data/doc/_index.html +1 -1
- data/doc/file.README.html +1 -1
- data/doc/index.html +1 -1
- data/doc/top-level-namespace.html +1 -1
- data/lib/grafana/annotations.rb +282 -9
- data/lib/grafana/dashboard.rb +1 -1
- data/lib/grafana/network.rb +36 -5
- data/lib/grafana/tags.rb +16 -0
- data/lib/grafana/tools.rb +35 -2
- data/lib/grafana/validator.rb +14 -1
- data/lib/grafana/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38822e4c5e4736d2a9c4cd1b02808c47911b095a
|
4
|
+
data.tar.gz: 71005a3574b3807b1a56b0f418b93b79cd46f9f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a409a9d25cdc6652ec48a3e8204c1ca698cd62a92858989f55eaf8cf592bf510bef17ce7797c6e5312d22e571d015d39daf6f707f0ac12ad9ed3d7317b12900f
|
7
|
+
data.tar.gz: 65e0824ae33a7fda051ec58ac1858e3b3e5c89feb43944685016ac478ced09e2a6cc9e8fb894057617c376c60552bac34f85d9fe21fdc14427f106d36ed725c8
|
data/doc/Array.html
CHANGED
@@ -190,7 +190,7 @@
|
|
190
190
|
</div>
|
191
191
|
|
192
192
|
<div id="footer">
|
193
|
-
Generated on
|
193
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
194
194
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
195
195
|
0.9.11 (ruby-2.2.8).
|
196
196
|
</div>
|
data/doc/Boolean.html
CHANGED
@@ -112,7 +112,7 @@ href="https://stackoverflow.com/questions/3028243/check-if-ruby-object-is-a-bool
|
|
112
112
|
</div>
|
113
113
|
|
114
114
|
<div id="footer">
|
115
|
-
Generated on
|
115
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
116
116
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
117
117
|
0.9.11 (ruby-2.2.8).
|
118
118
|
</div>
|
data/doc/FalseClass.html
CHANGED
@@ -122,7 +122,7 @@
|
|
122
122
|
</div>
|
123
123
|
|
124
124
|
<div id="footer">
|
125
|
-
Generated on
|
125
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
126
126
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
127
127
|
0.9.11 (ruby-2.2.8).
|
128
128
|
</div>
|
data/doc/Grafana.html
CHANGED
@@ -162,7 +162,7 @@
|
|
162
162
|
</div>
|
163
163
|
|
164
164
|
<div id="footer">
|
165
|
-
Generated on
|
165
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
166
166
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
167
167
|
0.9.11 (ruby-2.2.8).
|
168
168
|
</div>
|
data/doc/Hash.html
CHANGED
@@ -202,7 +202,7 @@ useableTags = tags.filter( 'fii' )</p>
|
|
202
202
|
</div>
|
203
203
|
|
204
204
|
<div id="footer">
|
205
|
-
Generated on
|
205
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
206
206
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
207
207
|
0.9.11 (ruby-2.2.8).
|
208
208
|
</div>
|
data/doc/Logging.html
CHANGED
@@ -316,7 +316,7 @@
|
|
316
316
|
</div>
|
317
317
|
|
318
318
|
<div id="footer">
|
319
|
-
Generated on
|
319
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
320
320
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
321
321
|
0.9.11 (ruby-2.2.8).
|
322
322
|
</div>
|
data/doc/Object.html
CHANGED
@@ -276,7 +276,7 @@ multi_hash = multi_hash.deep_string_keys</p>
|
|
276
276
|
</div>
|
277
277
|
|
278
278
|
<div id="footer">
|
279
|
-
Generated on
|
279
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
280
280
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
281
281
|
0.9.11 (ruby-2.2.8).
|
282
282
|
</div>
|
data/doc/Time.html
CHANGED
@@ -190,7 +190,7 @@
|
|
190
190
|
</div>
|
191
191
|
|
192
192
|
<div id="footer">
|
193
|
-
Generated on
|
193
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
194
194
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
195
195
|
0.9.11 (ruby-2.2.8).
|
196
196
|
</div>
|
data/doc/TrueClass.html
CHANGED
@@ -122,7 +122,7 @@
|
|
122
122
|
</div>
|
123
123
|
|
124
124
|
<div id="footer">
|
125
|
-
Generated on
|
125
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
126
126
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
127
127
|
0.9.11 (ruby-2.2.8).
|
128
128
|
</div>
|
data/doc/_index.html
CHANGED
@@ -370,7 +370,7 @@
|
|
370
370
|
</div>
|
371
371
|
|
372
372
|
<div id="footer">
|
373
|
-
Generated on
|
373
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
374
374
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
375
375
|
0.9.11 (ruby-2.2.8).
|
376
376
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -107,7 +107,7 @@ href="https://github.com/[USERNAME]/grafana">github.com/[USERNAME]/grafana</a>.<
|
|
107
107
|
</div></div>
|
108
108
|
|
109
109
|
<div id="footer">
|
110
|
-
Generated on
|
110
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
111
111
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
112
112
|
0.9.11 (ruby-2.2.8).
|
113
113
|
</div>
|
data/doc/index.html
CHANGED
@@ -107,7 +107,7 @@ href="https://github.com/[USERNAME]/grafana">github.com/[USERNAME]/grafana</a>.<
|
|
107
107
|
</div></div>
|
108
108
|
|
109
109
|
<div id="footer">
|
110
|
-
Generated on
|
110
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
111
111
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
112
112
|
0.9.11 (ruby-2.2.8).
|
113
113
|
</div>
|
@@ -102,7 +102,7 @@
|
|
102
102
|
</div>
|
103
103
|
|
104
104
|
<div id="footer">
|
105
|
-
Generated on
|
105
|
+
Generated on Wed Dec 13 06:51:14 2017 by
|
106
106
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
107
107
|
0.9.11 (ruby-2.2.8).
|
108
108
|
</div>
|
data/lib/grafana/annotations.rb
CHANGED
@@ -1,39 +1,312 @@
|
|
1
1
|
|
2
2
|
module Grafana
|
3
3
|
|
4
|
-
#
|
4
|
+
# This is the API documentation for the new Grafana Annotations feature released in Grafana 4.6.
|
5
|
+
# Annotations are saved in the Grafana database (sqlite, mysql or postgres).
|
6
|
+
#
|
7
|
+
# Annotations can be global annotations that can be shown on any dashboard by configuring an annotation
|
8
|
+
# data source - they are filtered by tags.
|
9
|
+
#
|
10
|
+
# Or they can be tied to a panel on a dashboard and are then only shown on that panel.
|
11
|
+
#
|
12
|
+
# original API Documentation can be found under: http://docs.grafana.org/http_api/annotations/
|
5
13
|
#
|
6
14
|
module Annotations
|
7
15
|
|
8
16
|
# Find Annotations
|
9
17
|
# http://docs.grafana.org/http_api/annotations/#find-annotations
|
10
|
-
#
|
11
|
-
|
18
|
+
#
|
19
|
+
# @param [Hash] params
|
20
|
+
# @option params [Integer] from: epoch datetime in milliseconds. Optional.
|
21
|
+
# @option params [Integer] to: epoch datetime in milliseconds. Optional.
|
22
|
+
# @option params [Integer] limit: number. Optional - default is 10. Max limit for results returned.
|
23
|
+
# @option params [Integer] alertId: number. Optional. Find annotations for a specified alert.
|
24
|
+
# @option params [Mixed] dashboard: number. Optional. Find annotations that are scoped to a specific dashboard
|
25
|
+
# @option params [Integer] panel_id: number. Optional. Find annotations that are scoped to a specific panel
|
26
|
+
# @option params [Array] tags: string. Optional. Use this to filter global annotations. Global annotations are annotations from an annotation data source that are not connected specifically to a dashboard or panel. To do an “AND” filtering with multiple tags, specify the tags parameter multiple times e.g.
|
27
|
+
#
|
28
|
+
# @example
|
29
|
+
# params = {
|
30
|
+
# limit: 5,
|
31
|
+
# tags: [ 'spec', 'test' ]
|
32
|
+
# }
|
33
|
+
# find_annotation( params )
|
34
|
+
#
|
35
|
+
# @return [Array]
|
36
|
+
#
|
37
|
+
def find_annotation( params )
|
38
|
+
|
39
|
+
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
40
|
+
raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
|
41
|
+
|
42
|
+
dashboard = validate( params, required: false, var: 'dashboard' )
|
43
|
+
from = validate( params, required: false, var: 'from', type: Integer )
|
44
|
+
to = validate( params, required: false, var: 'to', type: Integer )
|
45
|
+
limit = validate( params, required: false, var: 'limit', type: Integer ) || 10
|
46
|
+
alert_id = validate( params, required: false, var: 'alert_id', type: Integer )
|
47
|
+
panel_id = validate( params, required: false, var: 'panel_id', type: Integer )
|
48
|
+
tags = validate( params, required: false, var: 'tags', type: Array )
|
49
|
+
|
50
|
+
if( dashboard.is_a?(String) )
|
51
|
+
|
52
|
+
dashboard = search_dashboards( query: dashboard )
|
53
|
+
|
54
|
+
return { 'status' => 404, 'message' => format( 'No Dashboard \'%s\' found', dashboard) } if( dashboard.nil? || dashboard.dig('status').to_i != 200 )
|
55
|
+
|
56
|
+
dashboard = dashboard.dig('message').first unless( dashboard.nil? && dashboard.dig('status').to_i == 200 )
|
57
|
+
dashboard = dashboard.dig('id') unless( dashboard.nil? )
|
58
|
+
|
59
|
+
return { 'status' => 404, 'message' => format( 'No Dashboard \'%s\' found', dashboard) } if( dashboard.nil? )
|
60
|
+
end
|
61
|
+
|
62
|
+
api = []
|
63
|
+
api << format( 'from=%s', from ) unless( from.nil? )
|
64
|
+
api << format( 'to=%s', to ) unless( to.nil? )
|
65
|
+
api << format( 'limit=%s', limit ) unless( limit.nil? )
|
66
|
+
api << format( 'alertId=%s', alert_id ) unless( alert_id.nil? )
|
67
|
+
api << format( 'panelId=%s', panel_id ) unless( panel_id.nil? )
|
68
|
+
api << format( 'dashboardId=%s', dashboard ) unless( dashboard.nil? )
|
69
|
+
|
70
|
+
unless( tags.nil? )
|
71
|
+
tags = tags.join( '&tags=' ) if( tags.is_a?( Array ) )
|
72
|
+
api << format( 'tags=%s', tags )
|
73
|
+
end
|
74
|
+
api = api.join( '&' )
|
75
|
+
|
76
|
+
endpoint = format( '/api/annotations/?%s' , api )
|
77
|
+
|
78
|
+
@logger.debug("Attempting to search for annotations (GET #{endpoint})") if @debug
|
79
|
+
|
80
|
+
get( endpoint )
|
81
|
+
end
|
12
82
|
|
13
83
|
# Create Annotation
|
84
|
+
#
|
85
|
+
# Creates an annotation in the Grafana database.
|
86
|
+
# The dashboard_id and panel_id fields are optional.
|
87
|
+
# If they are not specified then a global annotation is created and can be queried in any dashboard that adds
|
88
|
+
# the Grafana annotations data source.
|
89
|
+
#
|
90
|
+
# When creating a region annotation the response will include both id and endId, if not only id.
|
91
|
+
#
|
14
92
|
# http://docs.grafana.org/http_api/annotations/#create-annotation
|
15
93
|
# POST /api/annotations
|
16
|
-
|
94
|
+
#
|
95
|
+
#
|
96
|
+
# @param [Hash] params
|
97
|
+
# @option params [Mixed] dashboard
|
98
|
+
# @option params [Integer] panel_id
|
99
|
+
# @option params [Integer] time:
|
100
|
+
# @option params [Integer] time_end:
|
101
|
+
# @option params [Boolean] region:
|
102
|
+
# @option params [Array] tags:
|
103
|
+
# @option params [String] text:
|
104
|
+
#
|
105
|
+
# @example
|
106
|
+
# params = {
|
107
|
+
# time: Time.now.to_i,
|
108
|
+
# tags: [ 'spec', 'test' ],
|
109
|
+
# text: 'test annotation'
|
110
|
+
# }
|
111
|
+
# create_annotation( params )
|
112
|
+
#
|
113
|
+
# @return [Hash]
|
114
|
+
#
|
115
|
+
def create_annotation( params )
|
116
|
+
|
117
|
+
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
118
|
+
raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
|
119
|
+
|
120
|
+
dashboard = validate( params, required: false, var: 'dashboard' )
|
121
|
+
panel_id = validate( params, required: false, var: 'panel_id', type: Integer )
|
122
|
+
time = validate( params, required: false, var: 'time', type: Integer ) || Time.now.to_i
|
123
|
+
time_end = validate( params, required: false, var: 'time_end', type: Integer )
|
124
|
+
region = validate( params, required: false, var: 'region', type: Boolean )
|
125
|
+
tags = validate( params, required: true, var: 'tags', type: Array )
|
126
|
+
text = validate( params, required: true, var: 'text', type: String )
|
127
|
+
|
128
|
+
if( dashboard.is_a?(String) )
|
129
|
+
|
130
|
+
dashboard = search_dashboards( query: dashboard )
|
131
|
+
|
132
|
+
return { 'status' => 404, 'message' => format( 'No Dashboard \'%s\' found', dashboard) } if( dashboard.nil? || dashboard.dig('status').to_i != 200 )
|
133
|
+
|
134
|
+
dashboard = dashboard.dig('message').first unless( dashboard.nil? && dashboard.dig('status').to_i == 200 )
|
135
|
+
dashboard = dashboard.dig('id') unless( dashboard.nil? )
|
136
|
+
|
137
|
+
return { 'status' => 404, 'message' => format( 'No Dashboard \'%s\' found', dashboard) } if( dashboard.nil? )
|
138
|
+
end
|
139
|
+
|
140
|
+
unless( time_end.nil? )
|
141
|
+
return { 'status' => 404, 'message' => format( '\'end_time\' can\'t be lower then \'time\'' ) } if( time_end < time )
|
142
|
+
end
|
143
|
+
|
144
|
+
endpoint = '/api/annotations'
|
145
|
+
payload = {
|
146
|
+
dashboardId: dashboard,
|
147
|
+
panelId: panel_id,
|
148
|
+
time: time,
|
149
|
+
timeEnd: time_end,
|
150
|
+
isRegion: region,
|
151
|
+
tags: tags,
|
152
|
+
text: text
|
153
|
+
}
|
154
|
+
payload.reject!{ |_k, v| v.nil? }
|
155
|
+
|
156
|
+
post(endpoint, payload.to_json)
|
157
|
+
end
|
17
158
|
|
18
159
|
# Create Annotation in Graphite format
|
160
|
+
#
|
161
|
+
# Creates an annotation by using Graphite-compatible event format.
|
162
|
+
# The when and data fields are optional.
|
163
|
+
# If when is not specified then the current time will be used as annotation’s timestamp.
|
164
|
+
# The tags field can also be in prior to Graphite 0.10.0 format (string with multiple tags being separated by a space).
|
165
|
+
#
|
19
166
|
# http://docs.grafana.org/http_api/annotations/#create-annotation-in-graphite-format
|
20
167
|
# POST /api/annotations/graphite
|
21
|
-
|
168
|
+
#
|
169
|
+
# @param [Hash] params
|
170
|
+
# @option params [Integer] what
|
171
|
+
# @option params [Integer] when
|
172
|
+
# @option params [Array] tags
|
173
|
+
# @option params [String] data
|
174
|
+
#
|
175
|
+
# @example
|
176
|
+
# params = {
|
177
|
+
# what: 'spec test graphite annotation',
|
178
|
+
# when: Time.now.to_i,
|
179
|
+
# tags: [ 'spec', 'test' ],
|
180
|
+
# text: 'test annotation'
|
181
|
+
# }
|
182
|
+
# create_annotation_graphite( params )
|
183
|
+
#
|
184
|
+
# @return [Hash]
|
185
|
+
#
|
186
|
+
def create_annotation_graphite( params )
|
187
|
+
|
188
|
+
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
189
|
+
raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
|
190
|
+
|
191
|
+
what = validate( params, required: true, var: 'what', type: String )
|
192
|
+
time_when = validate( params, required: false, var: 'when', type: Integer ) || Time.now.to_i
|
193
|
+
tags = validate( params, required: true, var: 'tags', type: Array )
|
194
|
+
text = validate( params, required: true, var: 'text', type: String )
|
195
|
+
|
196
|
+
endpoint = '/api/annotations/graphite'
|
197
|
+
payload = {
|
198
|
+
what: what,
|
199
|
+
when: time_when,
|
200
|
+
tags: tags,
|
201
|
+
text: text
|
202
|
+
}
|
203
|
+
payload.reject!{ |_k, v| v.nil? }
|
204
|
+
|
205
|
+
post(endpoint, payload.to_json)
|
206
|
+
end
|
22
207
|
|
23
208
|
# Update Annotation
|
209
|
+
#
|
24
210
|
# http://docs.grafana.org/http_api/annotations/#update-annotation
|
25
|
-
#
|
26
|
-
|
211
|
+
#
|
212
|
+
# @param [Hash] params
|
213
|
+
# @option params [Integer] annotation
|
214
|
+
# @option params [Integer] time
|
215
|
+
# @option params [Integer] time_end
|
216
|
+
# @option params [Boolean] region
|
217
|
+
# @option params [Array] tags
|
218
|
+
# @option params [String] text
|
219
|
+
#
|
220
|
+
# @example
|
221
|
+
# params = {
|
222
|
+
# annotation: 1,
|
223
|
+
# tags: [ 'deployment' ],
|
224
|
+
# text: 'git tag #1234'
|
225
|
+
# }
|
226
|
+
# update_annotation( params )
|
227
|
+
#
|
228
|
+
# @return [Hash]
|
229
|
+
#
|
230
|
+
def update_annotation( params )
|
231
|
+
|
232
|
+
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
233
|
+
raise ArgumentError.new('missing \'params\'') if( params.size.zero? )
|
234
|
+
|
235
|
+
annotation_id = validate( params, required: true, var: 'annotation', type: Integer )
|
236
|
+
time = validate( params, required: false, var: 'time', type: Integer )
|
237
|
+
time_end = validate( params, required: false, var: 'time_end', type: Integer )
|
238
|
+
region = validate( params, required: false, var: 'region', type: Boolean )
|
239
|
+
tags = validate( params, required: false, var: 'tags', type: Array )
|
240
|
+
text = validate( params, required: false, var: 'text', type: String )
|
241
|
+
|
242
|
+
unless( time_end.nil? )
|
243
|
+
return { 'status' => 404, 'message' => format( '\'end_time\' can\'t be lower then \'time\'' ) } if( time_end < time )
|
244
|
+
end
|
245
|
+
|
246
|
+
endpoint = format( '/api/annotations/%d', annotation_id)
|
247
|
+
payload = {
|
248
|
+
time: time,
|
249
|
+
timeEnd: time_end,
|
250
|
+
isRegion: region,
|
251
|
+
text: text,
|
252
|
+
tags: tags
|
253
|
+
}
|
254
|
+
payload.reject!{ |_k, v| v.nil? }
|
255
|
+
|
256
|
+
put(endpoint, payload.to_json)
|
257
|
+
end
|
27
258
|
|
28
259
|
# Delete Annotation By Id
|
260
|
+
#
|
261
|
+
# Deletes the annotation that matches the specified id.
|
262
|
+
#
|
29
263
|
# http://docs.grafana.org/http_api/annotations/#delete-annotation-by-id
|
30
264
|
# DELETE /api/annotation/:id
|
31
|
-
|
265
|
+
#
|
266
|
+
# @param [Integer] annotation_id
|
267
|
+
#
|
268
|
+
# @example
|
269
|
+
# delete_annotation( 1 )
|
270
|
+
#
|
271
|
+
# @return [Hash]
|
272
|
+
#
|
273
|
+
def delete_annotation( annotation_id )
|
274
|
+
|
275
|
+
raise ArgumentError.new(format('wrong type. user \'annotation_id\' must be an Integer, given \'%s\'', annotation_id.class.to_s)) unless( annotation_id.is_a?(Integer) )
|
276
|
+
raise ArgumentError.new('missing \'annotation_id\'') if( annotation_id.size.zero? )
|
277
|
+
raise ArgumentError.new('\'annotation_id\' can not be 0') if( annotation_id.zero? )
|
278
|
+
|
279
|
+
endpoint = format( '/api/annotation/%d', annotation_id )
|
280
|
+
|
281
|
+
delete(endpoint)
|
282
|
+
end
|
32
283
|
|
33
284
|
# Delete Annotation By RegionId
|
285
|
+
#
|
286
|
+
# Deletes the annotation that matches the specified region id.
|
287
|
+
# A region is an annotation that covers a timerange and has a start and end time.
|
288
|
+
# In the Grafana database, this is a stored as two annotations connected by a region id.
|
289
|
+
#
|
34
290
|
# http://docs.grafana.org/http_api/annotations/#delete-annotation-by-regionid
|
35
291
|
# DELETE /api/annotation/region/:id
|
36
|
-
|
292
|
+
#
|
293
|
+
# @param [Integer] region_id
|
294
|
+
#
|
295
|
+
# @example
|
296
|
+
# delete_annotation_by_region( 1 )
|
297
|
+
#
|
298
|
+
# @return [Hash]
|
299
|
+
#
|
300
|
+
def delete_annotation_by_region( region_id )
|
301
|
+
|
302
|
+
raise ArgumentError.new(format('wrong type. user \'region_id\' must be an Integer, given \'%s\'', region_id.class.to_s)) unless( region_id.is_a?(Integer) )
|
303
|
+
raise ArgumentError.new('missing \'region_id\'') if( region_id.size.zero? )
|
304
|
+
# raise ArgumentError.new('\'region_id\' can not be 0') if( region_id.zero? )
|
305
|
+
|
306
|
+
endpoint = format( '/api/annotation/region/%d', region_id )
|
307
|
+
|
308
|
+
delete(endpoint)
|
309
|
+
end
|
37
310
|
|
38
311
|
end
|
39
312
|
|
data/lib/grafana/dashboard.rb
CHANGED
@@ -149,7 +149,7 @@ module Grafana
|
|
149
149
|
tags = validate( params, required: false, var: 'tags' )
|
150
150
|
|
151
151
|
api = []
|
152
|
-
api << format( 'query=%s', CGI.escape( query ) ) unless
|
152
|
+
api << format( 'query=%s', CGI.escape( query ) ) unless( query.nil? )
|
153
153
|
api << format( 'starred=%s', starred ? 'true' : 'false' ) unless( starred.nil? )
|
154
154
|
|
155
155
|
unless( tags.nil? )
|
data/lib/grafana/network.rb
CHANGED
@@ -3,31 +3,62 @@ module Grafana
|
|
3
3
|
|
4
4
|
module Network
|
5
5
|
|
6
|
+
# GET request
|
7
|
+
#
|
8
|
+
# @param endpoint [String]
|
9
|
+
#
|
6
10
|
def get( endpoint )
|
7
|
-
|
8
11
|
request( 'GET', endpoint )
|
9
12
|
end
|
10
13
|
|
14
|
+
# POST request
|
15
|
+
#
|
16
|
+
# @param endpoint [String]
|
17
|
+
# @param data [Hash]
|
18
|
+
#
|
11
19
|
def post( endpoint, data )
|
12
|
-
|
13
20
|
request( 'POST', endpoint, data )
|
14
21
|
end
|
15
22
|
|
23
|
+
# PUT request
|
24
|
+
#
|
25
|
+
# @param endpoint [String]
|
26
|
+
# @param data [Hash]
|
27
|
+
#
|
16
28
|
def put( endpoint, data )
|
17
|
-
|
18
29
|
request( 'PUT', endpoint, data )
|
19
30
|
end
|
20
31
|
|
32
|
+
# PATCH request
|
33
|
+
#
|
34
|
+
# @param endpoint [String]
|
35
|
+
# @param data [Hash]
|
36
|
+
#
|
21
37
|
def patch( endpoint, data )
|
22
|
-
|
23
38
|
request( 'PATCH', endpoint, data )
|
24
39
|
end
|
25
40
|
|
41
|
+
# DELETE request
|
42
|
+
#
|
43
|
+
# @param endpoint [String]
|
44
|
+
#
|
26
45
|
def delete( endpoint )
|
27
|
-
|
28
46
|
request( 'DELETE', endpoint )
|
29
47
|
end
|
30
48
|
|
49
|
+
|
50
|
+
private
|
51
|
+
# helper function for all request methods
|
52
|
+
#
|
53
|
+
# @param method_type [String]
|
54
|
+
# @param endpoint [String]
|
55
|
+
# @param data [Hash]
|
56
|
+
#
|
57
|
+
# @example
|
58
|
+
#
|
59
|
+
#
|
60
|
+
# @return [Hash]
|
61
|
+
#
|
31
62
|
def request( method_type = 'GET', endpoint = '/', data = {} )
|
32
63
|
|
33
64
|
raise 'try first login()' if @api_instance.nil?
|
data/lib/grafana/tags.rb
CHANGED
@@ -3,8 +3,24 @@ module Grafana
|
|
3
3
|
module Tags
|
4
4
|
|
5
5
|
# expand the Template Tags
|
6
|
+
# helper function to expand the Dashboard Tags with an own Array of Tags
|
6
7
|
#
|
8
|
+
# @param params [Hash] params
|
9
|
+
# @option params [Hash] dashboard
|
10
|
+
# @option params [Array] additional_tags
|
7
11
|
#
|
12
|
+
# @example
|
13
|
+
# params = {
|
14
|
+
# dashboard: {
|
15
|
+
# rows: [
|
16
|
+
#
|
17
|
+
# ]
|
18
|
+
# },
|
19
|
+
# additional_tag: [ 'tag1', 'tag2' ]
|
20
|
+
# }
|
21
|
+
# expand_tags( params )
|
22
|
+
#
|
23
|
+
# @return [Hash]
|
8
24
|
#
|
9
25
|
def expand_tags( params )
|
10
26
|
|
data/lib/grafana/tools.rb
CHANGED
@@ -3,6 +3,15 @@ module Grafana
|
|
3
3
|
|
4
4
|
module Tools
|
5
5
|
|
6
|
+
# return a slugged string for Grafana Dashboards
|
7
|
+
#
|
8
|
+
# @param text [String] text
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# slug( 'test dashboard' )
|
12
|
+
#
|
13
|
+
# @retunr [String]
|
14
|
+
#
|
6
15
|
def slug( text )
|
7
16
|
|
8
17
|
raise ArgumentError.new(format('wrong type. \'text\' must be an String, given \'%s\'', text.class.to_s)) unless( text.is_a?(String) )
|
@@ -23,7 +32,23 @@ module Grafana
|
|
23
32
|
text.downcase
|
24
33
|
end
|
25
34
|
|
26
|
-
|
35
|
+
# regenerate Row Ids in the Dashboard
|
36
|
+
# usefull for an automatic generated Dashboard
|
37
|
+
#
|
38
|
+
# @param params [Hash] params
|
39
|
+
#
|
40
|
+
# @example
|
41
|
+
# params = {
|
42
|
+
# dashboard: {
|
43
|
+
# rows: [
|
44
|
+
#
|
45
|
+
# ]
|
46
|
+
# }
|
47
|
+
# }
|
48
|
+
# regenerate_template_ids( params )
|
49
|
+
#
|
50
|
+
# @return [Hash]
|
51
|
+
#
|
27
52
|
def regenerate_template_ids( params )
|
28
53
|
|
29
54
|
raise ArgumentError.new(format('wrong type. \'params\' must be an Hash, given \'%s\'', params.class.to_s)) unless( params.is_a?(Hash) )
|
@@ -49,7 +74,15 @@ module Grafana
|
|
49
74
|
JSON.generate( params )
|
50
75
|
end
|
51
76
|
|
52
|
-
|
77
|
+
# check, it an String a valid Json
|
78
|
+
#
|
79
|
+
# @param json [String] json
|
80
|
+
#
|
81
|
+
# @example
|
82
|
+
# valid_json?( json )
|
83
|
+
#
|
84
|
+
# @return [Boolean]
|
85
|
+
#
|
53
86
|
def valid_json?( json )
|
54
87
|
begin
|
55
88
|
JSON.parse( json )
|
data/lib/grafana/validator.rb
CHANGED
@@ -4,7 +4,20 @@ module Grafana
|
|
4
4
|
# namespace for validate options
|
5
5
|
module Validator
|
6
6
|
|
7
|
-
# validate
|
7
|
+
# validate some parameters
|
8
|
+
#
|
9
|
+
# @param params [Hash]
|
10
|
+
# @param options [Hash]
|
11
|
+
# @option options [Boolean] requiered
|
12
|
+
# @option options [String] var
|
13
|
+
# @option options [Class] type
|
14
|
+
#
|
15
|
+
# @example
|
16
|
+
# default = validate( params, required: false, var: 'default', type: Boolean )
|
17
|
+
# name = validate( params, required: true, var: 'name', type: String )
|
18
|
+
#
|
19
|
+
# @return [Mixed]
|
20
|
+
#
|
8
21
|
def validate( params, options )
|
9
22
|
required = options.dig(:required) || false
|
10
23
|
var = options.dig(:var)
|
data/lib/grafana/version.rb
CHANGED