lex-grafana 0.1.1
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.
- checksums.yaml +7 -0
- data/.github/workflows/ci.yml +16 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +53 -0
- data/CHANGELOG.md +11 -0
- data/CLAUDE.md +76 -0
- data/Gemfile +11 -0
- data/lex-grafana.gemspec +30 -0
- data/lib/legion/extensions/grafana/client.rb +33 -0
- data/lib/legion/extensions/grafana/helpers/client.rb +24 -0
- data/lib/legion/extensions/grafana/runners/alerts.rb +29 -0
- data/lib/legion/extensions/grafana/runners/dashboards.rb +37 -0
- data/lib/legion/extensions/grafana/runners/datasources.rb +29 -0
- data/lib/legion/extensions/grafana/version.rb +9 -0
- data/lib/legion/extensions/grafana.rb +16 -0
- metadata +73 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 686c6e8ad86aacf569c08e9cad9f40be6e3c56ad0caebd55ee972a30e88b7f8a
|
|
4
|
+
data.tar.gz: '05895019f4775c4be40d5db39659f159ddc939aacc09bfe9cd2810d81e1f142e'
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e8c9a4d3abe0e750bf74515b5ede3ba5dd5877df9969fc1c9c08c6aafc12ff30a316c1c78dbad3ccde706098d927b5db63d4fbe92b59b8a0312374a6d7b2d6aa
|
|
7
|
+
data.tar.gz: ad98edf1dfb5531b5f02b4af6aa5754c315a0e1f339ba9da5d29a7ded606a4ded1b62232f94ffd6f729604e695c4d832e399285720227f6c2af1a144f6655c29
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
on:
|
|
3
|
+
push:
|
|
4
|
+
branches: [main]
|
|
5
|
+
pull_request:
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
ci:
|
|
9
|
+
uses: LegionIO/.github/.github/workflows/ci.yml@main
|
|
10
|
+
|
|
11
|
+
release:
|
|
12
|
+
needs: ci
|
|
13
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
14
|
+
uses: LegionIO/.github/.github/workflows/release.yml@main
|
|
15
|
+
secrets:
|
|
16
|
+
rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 3.4
|
|
3
|
+
NewCops: enable
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
|
|
6
|
+
Layout/LineLength:
|
|
7
|
+
Max: 160
|
|
8
|
+
|
|
9
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
|
10
|
+
EnforcedStyle: space
|
|
11
|
+
|
|
12
|
+
Layout/HashAlignment:
|
|
13
|
+
EnforcedHashRocketStyle: table
|
|
14
|
+
EnforcedColonStyle: table
|
|
15
|
+
|
|
16
|
+
Metrics/MethodLength:
|
|
17
|
+
Max: 50
|
|
18
|
+
|
|
19
|
+
Metrics/ClassLength:
|
|
20
|
+
Max: 1500
|
|
21
|
+
|
|
22
|
+
Metrics/ModuleLength:
|
|
23
|
+
Max: 1500
|
|
24
|
+
|
|
25
|
+
Metrics/BlockLength:
|
|
26
|
+
Max: 40
|
|
27
|
+
Exclude:
|
|
28
|
+
- 'spec/**/*'
|
|
29
|
+
|
|
30
|
+
Metrics/ParameterLists:
|
|
31
|
+
Max: 10
|
|
32
|
+
|
|
33
|
+
Metrics/AbcSize:
|
|
34
|
+
Max: 60
|
|
35
|
+
|
|
36
|
+
Metrics/CyclomaticComplexity:
|
|
37
|
+
Max: 15
|
|
38
|
+
|
|
39
|
+
Metrics/PerceivedComplexity:
|
|
40
|
+
Max: 17
|
|
41
|
+
|
|
42
|
+
Style/Documentation:
|
|
43
|
+
Enabled: false
|
|
44
|
+
|
|
45
|
+
Style/SymbolArray:
|
|
46
|
+
Enabled: true
|
|
47
|
+
|
|
48
|
+
Style/FrozenStringLiteralComment:
|
|
49
|
+
Enabled: true
|
|
50
|
+
EnforcedStyle: always
|
|
51
|
+
|
|
52
|
+
Naming/FileName:
|
|
53
|
+
Enabled: false
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.0] - 2026-03-22
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- Initial release
|
|
7
|
+
- `Helpers::Client` — Faraday connection builder with Bearer token auth
|
|
8
|
+
- `Runners::Dashboards` — list_dashboards, get_dashboard, create_dashboard, delete_dashboard
|
|
9
|
+
- `Runners::Alerts` — list_alerts, list_alert_rules, pause_alert
|
|
10
|
+
- `Runners::Datasources` — list_datasources, get_datasource, create_datasource
|
|
11
|
+
- Standalone `Client` class for use outside the Legion framework
|
data/CLAUDE.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# lex-grafana: Grafana HTTP API Integration for LegionIO
|
|
2
|
+
|
|
3
|
+
**Repository Level 4 Documentation**
|
|
4
|
+
- **Parent**: `/Users/miverso2/rubymine/legion/extensions-other/CLAUDE.md`
|
|
5
|
+
|
|
6
|
+
## Purpose
|
|
7
|
+
|
|
8
|
+
Legion extension for interacting with the Grafana HTTP API. Supports dashboard CRUD, alert management, and datasource operations.
|
|
9
|
+
|
|
10
|
+
**GitHub**: https://github.com/LegionIO/lex-grafana
|
|
11
|
+
**Gem**: `lex-grafana`
|
|
12
|
+
**Version**: 0.1.0
|
|
13
|
+
**License**: MIT
|
|
14
|
+
**Ruby**: >= 3.4
|
|
15
|
+
|
|
16
|
+
## Architecture
|
|
17
|
+
|
|
18
|
+
### Runners
|
|
19
|
+
|
|
20
|
+
| Runner | Methods | Description |
|
|
21
|
+
|--------|---------|-------------|
|
|
22
|
+
| `Dashboards` | `list_dashboards`, `get_dashboard`, `create_dashboard`, `delete_dashboard` | Dashboard CRUD |
|
|
23
|
+
| `Alerts` | `list_alerts`, `list_alert_rules`, `pause_alert` | Alert management |
|
|
24
|
+
| `Datasources` | `list_datasources`, `get_datasource`, `create_datasource` | Datasource management |
|
|
25
|
+
|
|
26
|
+
### Helpers
|
|
27
|
+
|
|
28
|
+
- `Helpers::Client` — Faraday connection factory. Connects to Grafana base URL with Bearer token auth. URL and API key resolved from kwargs or Legion::Settings.
|
|
29
|
+
|
|
30
|
+
### Standalone Client
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
client = Legion::Extensions::Grafana::Client.new(url: 'https://grafana.example.com', api_key: 'KEY')
|
|
34
|
+
client.list_dashboards
|
|
35
|
+
client.get_dashboard(uid: 'abc123')
|
|
36
|
+
client.list_alerts
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Authentication
|
|
40
|
+
|
|
41
|
+
Bearer token via `Authorization: Bearer <api_key>` header.
|
|
42
|
+
|
|
43
|
+
## Settings
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"lex-grafana": {
|
|
48
|
+
"url": "https://grafana.example.com",
|
|
49
|
+
"api_key": "vault://secret/grafana#api_key"
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## File Map
|
|
55
|
+
|
|
56
|
+
| Path | Purpose |
|
|
57
|
+
|------|---------|
|
|
58
|
+
| `lib/legion/extensions/grafana.rb` | Entry point |
|
|
59
|
+
| `lib/legion/extensions/grafana/version.rb` | Version constant |
|
|
60
|
+
| `lib/legion/extensions/grafana/helpers/client.rb` | Faraday connection factory |
|
|
61
|
+
| `lib/legion/extensions/grafana/runners/dashboards.rb` | Dashboard CRUD |
|
|
62
|
+
| `lib/legion/extensions/grafana/runners/alerts.rb` | Alert management |
|
|
63
|
+
| `lib/legion/extensions/grafana/runners/datasources.rb` | Datasource management |
|
|
64
|
+
| `lib/legion/extensions/grafana/client.rb` | Standalone Client class |
|
|
65
|
+
|
|
66
|
+
## Development
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
bundle install
|
|
70
|
+
bundle exec rspec # 15 examples, 0 failures
|
|
71
|
+
bundle exec rubocop # 0 offenses
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
**Maintained By**: Matthew Iverson (@Esity)
|
data/Gemfile
ADDED
data/lex-grafana.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/legion/extensions/grafana/version'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'lex-grafana'
|
|
7
|
+
spec.version = Legion::Extensions::Grafana::VERSION
|
|
8
|
+
spec.authors = ['Esity']
|
|
9
|
+
spec.email = ['matthewdiverson@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'LEX::Grafana'
|
|
12
|
+
spec.description = 'Used to connect Legion to Grafana'
|
|
13
|
+
spec.homepage = 'https://github.com/LegionIO/lex-grafana'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.4'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-grafana'
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-grafana/blob/main/CHANGELOG.md'
|
|
20
|
+
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
21
|
+
|
|
22
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
24
|
+
end
|
|
25
|
+
spec.bindir = 'exe'
|
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
27
|
+
spec.require_paths = ['lib']
|
|
28
|
+
|
|
29
|
+
spec.add_dependency 'faraday', '>= 2.0'
|
|
30
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'helpers/client'
|
|
4
|
+
require_relative 'runners/dashboards'
|
|
5
|
+
require_relative 'runners/alerts'
|
|
6
|
+
require_relative 'runners/datasources'
|
|
7
|
+
|
|
8
|
+
module Legion
|
|
9
|
+
module Extensions
|
|
10
|
+
module Grafana
|
|
11
|
+
class Client
|
|
12
|
+
include Helpers::Client
|
|
13
|
+
include Runners::Dashboards
|
|
14
|
+
include Runners::Alerts
|
|
15
|
+
include Runners::Datasources
|
|
16
|
+
|
|
17
|
+
attr_reader :opts
|
|
18
|
+
|
|
19
|
+
def initialize(url:, api_key: nil, **extra)
|
|
20
|
+
@opts = { url: url, api_key: api_key, **extra }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def settings
|
|
24
|
+
{ options: @opts }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def connection(**override)
|
|
28
|
+
super(**@opts, **override)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Grafana
|
|
8
|
+
module Helpers
|
|
9
|
+
module Client
|
|
10
|
+
def connection(url: nil, api_key: nil, **_opts)
|
|
11
|
+
base = url || settings.dig(:transport, :settings, :'lex-grafana', :url)
|
|
12
|
+
key = api_key || settings.dig(:transport, :settings, :'lex-grafana', :api_key)
|
|
13
|
+
Faraday.new(url: base) do |f|
|
|
14
|
+
f.request :json
|
|
15
|
+
f.response :json
|
|
16
|
+
f.headers['Authorization'] = "Bearer #{key}" if key
|
|
17
|
+
f.adapter Faraday.default_adapter
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Grafana
|
|
6
|
+
module Runners
|
|
7
|
+
module Alerts
|
|
8
|
+
def list_alerts(**opts)
|
|
9
|
+
conn = opts[:connection] || connection(**opts)
|
|
10
|
+
response = conn.get('api/alerts')
|
|
11
|
+
response.body
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def list_alert_rules(**opts)
|
|
15
|
+
conn = opts[:connection] || connection(**opts)
|
|
16
|
+
response = conn.get('api/v1/provisioning/alert-rules')
|
|
17
|
+
response.body
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def pause_alert(id:, paused:, **opts)
|
|
21
|
+
conn = opts[:connection] || connection(**opts)
|
|
22
|
+
response = conn.post("api/alerts/#{id}/pause", paused: paused)
|
|
23
|
+
response.body
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Grafana
|
|
6
|
+
module Runners
|
|
7
|
+
module Dashboards
|
|
8
|
+
def list_dashboards(**opts)
|
|
9
|
+
conn = opts[:connection] || connection(**opts)
|
|
10
|
+
response = conn.get('api/search', type: 'dash-db')
|
|
11
|
+
response.body
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def get_dashboard(uid:, **opts)
|
|
15
|
+
conn = opts[:connection] || connection(**opts)
|
|
16
|
+
response = conn.get("api/dashboards/uid/#{uid}")
|
|
17
|
+
response.body
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_dashboard(dashboard:, folder_id: nil, overwrite: false, **opts)
|
|
21
|
+
conn = opts[:connection] || connection(**opts)
|
|
22
|
+
payload = { dashboard: dashboard, overwrite: overwrite }
|
|
23
|
+
payload[:folderId] = folder_id if folder_id
|
|
24
|
+
response = conn.post('api/dashboards/db', payload)
|
|
25
|
+
response.body
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def delete_dashboard(uid:, **opts)
|
|
29
|
+
conn = opts[:connection] || connection(**opts)
|
|
30
|
+
response = conn.delete("api/dashboards/uid/#{uid}")
|
|
31
|
+
response.body
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Grafana
|
|
6
|
+
module Runners
|
|
7
|
+
module Datasources
|
|
8
|
+
def list_datasources(**opts)
|
|
9
|
+
conn = opts[:connection] || connection(**opts)
|
|
10
|
+
response = conn.get('api/datasources')
|
|
11
|
+
response.body
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def get_datasource(id:, **opts)
|
|
15
|
+
conn = opts[:connection] || connection(**opts)
|
|
16
|
+
response = conn.get("api/datasources/#{id}")
|
|
17
|
+
response.body
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def create_datasource(datasource:, **opts)
|
|
21
|
+
conn = opts[:connection] || connection(**opts)
|
|
22
|
+
response = conn.post('api/datasources', datasource)
|
|
23
|
+
response.body
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/grafana/version'
|
|
4
|
+
require 'legion/extensions/grafana/helpers/client'
|
|
5
|
+
require 'legion/extensions/grafana/runners/dashboards'
|
|
6
|
+
require 'legion/extensions/grafana/runners/alerts'
|
|
7
|
+
require 'legion/extensions/grafana/runners/datasources'
|
|
8
|
+
require 'legion/extensions/grafana/client'
|
|
9
|
+
|
|
10
|
+
module Legion
|
|
11
|
+
module Extensions
|
|
12
|
+
module Grafana
|
|
13
|
+
extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: lex-grafana
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Esity
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: faraday
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
description: Used to connect Legion to Grafana
|
|
27
|
+
email:
|
|
28
|
+
- matthewdiverson@gmail.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- ".github/workflows/ci.yml"
|
|
34
|
+
- ".gitignore"
|
|
35
|
+
- ".rspec"
|
|
36
|
+
- ".rubocop.yml"
|
|
37
|
+
- CHANGELOG.md
|
|
38
|
+
- CLAUDE.md
|
|
39
|
+
- Gemfile
|
|
40
|
+
- lex-grafana.gemspec
|
|
41
|
+
- lib/legion/extensions/grafana.rb
|
|
42
|
+
- lib/legion/extensions/grafana/client.rb
|
|
43
|
+
- lib/legion/extensions/grafana/helpers/client.rb
|
|
44
|
+
- lib/legion/extensions/grafana/runners/alerts.rb
|
|
45
|
+
- lib/legion/extensions/grafana/runners/dashboards.rb
|
|
46
|
+
- lib/legion/extensions/grafana/runners/datasources.rb
|
|
47
|
+
- lib/legion/extensions/grafana/version.rb
|
|
48
|
+
homepage: https://github.com/LegionIO/lex-grafana
|
|
49
|
+
licenses:
|
|
50
|
+
- MIT
|
|
51
|
+
metadata:
|
|
52
|
+
homepage_uri: https://github.com/LegionIO/lex-grafana
|
|
53
|
+
source_code_uri: https://github.com/LegionIO/lex-grafana
|
|
54
|
+
changelog_uri: https://github.com/LegionIO/lex-grafana/blob/main/CHANGELOG.md
|
|
55
|
+
rubygems_mfa_required: 'true'
|
|
56
|
+
rdoc_options: []
|
|
57
|
+
require_paths:
|
|
58
|
+
- lib
|
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
|
+
requirements:
|
|
61
|
+
- - ">="
|
|
62
|
+
- !ruby/object:Gem::Version
|
|
63
|
+
version: '3.4'
|
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
65
|
+
requirements:
|
|
66
|
+
- - ">="
|
|
67
|
+
- !ruby/object:Gem::Version
|
|
68
|
+
version: '0'
|
|
69
|
+
requirements: []
|
|
70
|
+
rubygems_version: 3.6.9
|
|
71
|
+
specification_version: 4
|
|
72
|
+
summary: LEX::Grafana
|
|
73
|
+
test_files: []
|