Skip to content

Commit

Permalink
Add instance_type and organization labels
Browse files Browse the repository at this point in the history
  • Loading branch information
rwunderer committed Dec 7, 2023
1 parent dcca836 commit f707d09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fluent-plugin-wodby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |spec|
spec.name = "fluent-plugin-wodby"
spec.version = "0.1.8"
spec.version = "0.2.0"
spec.authors = ["Robert Wunderer"]
spec.email = ["robert@ramsalt.com"]

Expand Down
21 changes: 21 additions & 0 deletions lib/fluent/plugin/filter_wodby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,22 @@ def filter(tag, time, record)
record['wodby.instance_query'] = namespace
instance = get_instance(namespace)
app = get_app(instance['app_id'])
org = get_org(app['org_id'])

@instance_map[namespace] = {
'name' => "#{app['name']}.#{instance['name']}",
'title' => "#{app['title']} - #{instance['title']}",
'type' => instance['type'],
'organization' => org['title'],
'organization_name' => org['name'],
}
end

record['wodby.instance'] = @instance_map[namespace]['name']
record['wodby.instance_title'] = @instance_map[namespace]['title']
record['wodby.instance_type'] = @instance_map[namespace]['type']
record['wodby.organization'] = @instance_map[namespace]['organization']
record['wodby.organization_name'] = @instance_map[namespace]['organization_name']
else
log.info "No namespace found"
log.info record
Expand Down Expand Up @@ -86,6 +93,20 @@ def get_app(app_id)

app
end

def get_org(org_id)
begin
response = RestClient.get(
"https://api.wodby.com/api/v3/orgs/#{org_id}",
headers={'X-API-KEY': @api_key}
)
org = JSON.parse(response)
rescue RestClient::ExceptionWithResponse
org = {}
end

org
end
end
end
end

0 comments on commit f707d09

Please sign in to comment.