fluent-plugin-jfrog-metrics 0.1.0 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 880965fb77886a036bc1de886a64b1a28a81be51303981359e801d44bd425d32
4
- data.tar.gz: 895972cbf8078c299a777b31e286644200e2716514c3fc22697efa00fa2013d6
3
+ metadata.gz: 35d89c89f714cfeab9228b18f16d1933f8b38074b7df8806a4bc195125c3c69b
4
+ data.tar.gz: f10912f41f6bfc0afd9fa0834a89d2773019c9d2ba556d2867d5197240181569
5
5
  SHA512:
6
- metadata.gz: 40e81bba201bfec407c34e556843501ad9011490b6a2c55dc179fb5e2948948e05df86e2654af3c96f1ea6498f94a80771947340d850a03798b7fdc306a40fa1
7
- data.tar.gz: da1ead96440264cf9e12180fd4fca0cbffd9e838a8b8cf98f9e35dfe0876e32fa52dfa659fd7b9975175387595a007080f76ad662395a11cb70a972beb182f6c
6
+ metadata.gz: 3b0a8f44d52302a02a854626901a925da9f0b94d1b594b9c3fb1fd933d20fd68b34a8275628699f196718f219c681d6bcfaf78639861ae80c8d70001a3cf209b
7
+ data.tar.gz: a3d33863e73d03fe8658e17fd380c5635827b740bac955ede041560c85d879c6662f188c03555962a1e6e879b660c54a1d17687682587f3652b72b7c2a48d6c9
data/Gemfile CHANGED
@@ -1,8 +1,11 @@
1
- source "https://rubygems.org"
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
5
7
  group :test do
6
- gem "minitest"
7
- gem "minitest-reporters", '>= 0.5.0'
8
- end
8
+ gem 'minitest'
9
+ gem 'minitest-reporters', '>= 0.5.0'
10
+ gem 'rest-client', '>= 2.1.0'
11
+ end
data/Gemfile.lock CHANGED
@@ -11,30 +11,44 @@ GEM
11
11
  builder (3.2.4)
12
12
  concurrent-ruby (1.1.9)
13
13
  cool.io (1.7.1)
14
- fluentd (1.14.2)
14
+ domain_name (0.5.20190701)
15
+ unf (>= 0.0.5, < 1.0.0)
16
+ fluentd (1.14.5)
15
17
  bundler
16
18
  cool.io (>= 1.4.5, < 2.0.0)
17
- http_parser.rb (>= 0.5.1, < 0.8.0)
19
+ http_parser.rb (>= 0.5.1, < 0.9.0)
18
20
  msgpack (>= 1.3.1, < 2.0.0)
19
- serverengine (>= 2.2.2, < 3.0.0)
21
+ serverengine (>= 2.2.5, < 3.0.0)
20
22
  sigdump (~> 0.2.2)
21
23
  strptime (>= 0.2.4, < 1.0.0)
22
24
  tzinfo (>= 1.0, < 3.0)
23
25
  tzinfo-data (~> 1.0)
24
26
  webrick (>= 1.4.2, < 1.8.0)
25
27
  yajl-ruby (~> 1.0)
26
- http_parser.rb (0.7.0)
28
+ http-accept (1.7.0)
29
+ http-cookie (1.0.4)
30
+ domain_name (~> 0.5)
31
+ http_parser.rb (0.8.0)
32
+ mime-types (3.4.1)
33
+ mime-types-data (~> 3.2015)
34
+ mime-types-data (3.2021.1115)
27
35
  minitest (5.14.4)
28
36
  minitest-reporters (1.4.3)
29
37
  ansi
30
38
  builder
31
39
  minitest (>= 5.0)
32
40
  ruby-progressbar
33
- msgpack (1.4.2)
41
+ msgpack (1.4.5)
42
+ netrc (0.11.0)
34
43
  power_assert (2.0.1)
35
44
  rake (12.3.3)
45
+ rest-client (2.1.0)
46
+ http-accept (>= 1.7.0, < 2.0)
47
+ http-cookie (>= 1.0.2, < 2.0)
48
+ mime-types (>= 1.16, < 4.0)
49
+ netrc (~> 0.8)
36
50
  ruby-progressbar (1.11.0)
37
- serverengine (2.2.4)
51
+ serverengine (2.2.5)
38
52
  sigdump (~> 0.2.2)
39
53
  sigdump (0.2.4)
40
54
  strptime (0.2.5)
@@ -44,6 +58,9 @@ GEM
44
58
  concurrent-ruby (~> 1.0)
45
59
  tzinfo-data (1.2021.5)
46
60
  tzinfo (>= 1.0.0)
61
+ unf (0.1.4)
62
+ unf_ext
63
+ unf_ext (0.0.8)
47
64
  webrick (1.7.0)
48
65
  yajl-ruby (1.4.1)
49
66
 
@@ -56,6 +73,7 @@ DEPENDENCIES
56
73
  minitest
57
74
  minitest-reporters (>= 0.5.0)
58
75
  rake (~> 12.0)
76
+ rest-client (>= 2.1.0)
59
77
  test-unit (~> 3.0)
60
78
 
61
79
  BUNDLED WITH
data/README.md CHANGED
@@ -73,14 +73,24 @@ wget https://raw.githubusercontent.com/jfrog/metrics/master/splunk/splunk_metric
73
73
 
74
74
  #### Configuration parameters
75
75
  Integration is done by setting up Xray. Obtain JPD url and access token for API. Configure the source directive parameters specified below
76
- * **tag** (string) (required): The value is the tag assigned to the generated events.
77
- * **jpd_url** (string) (required): JPD url required to pull Xray SIEM violations
78
- * **apikey** (string) (required): API Key is the [Artifactory API Key](https://www.jfrog.com/confluence/display/JFROG/User+Profile#UserProfile-APIKey) for authentication
76
+ * **tag** (string) (required): The value is the tag assigned to the generated metrics.
77
+ * **jpd_url** (string) (required): JPD url required to pull metrics, (note - if deployed on K8s use the localhost and port number combination per sidecar)
79
78
  * **username** (string) (required): USER is the Artifactory username for authentication
79
+ * **apikey** (string) (required if token is not used, do refer Note section for specifics): API Key is the [Artifactory API Key](https://www.jfrog.com/confluence/display/JFROG/User+Profile#UserProfile-APIKey) for authentication
80
+ * **token** (string) (required if apikey is not used, do refer Note section for specifics): Admin token is the [Artifactory Scoped Tokens](https://www.jfrog.com/confluence/display/JFROG/Access+Tokens#AccessTokens-GeneratingAdminTokens) for authentication
80
81
  * **metric_prefix** (string) (required): This values pulls the specific metrics. Values can be - jfrog.artifactory, jfrog.xray
81
82
  * **interval** (integer) (optional): Wait interval between pulling new events
82
83
  * Default value: `60`
83
-
84
+ * **common_jpd** (true / false) (optional): This flag should be set as true only for non-kubernetes installations or installations where JPD base URL is same to access both Artifactory and Xray,
85
+ * ex: https://sample_base_url/artifactory or https://sample_base_url/xray
86
+ * Default value: false
87
+
88
+ Note:
89
+
90
+ * For Artifactory v7.4 and below only API Key must be used,
91
+ * For Artifactory v7.4 to 7.29 either Token or API Key can be used,
92
+ * For Artifactory v7.30 and above token only must be used.
93
+
84
94
  ## Copyright
85
95
  * Copyright(c) 2020 - JFrog
86
96
  * License
@@ -3,12 +3,12 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
4
  Gem::Specification.new do |spec|
5
5
  spec.name = 'fluent-plugin-jfrog-metrics'
6
- spec.version = '0.1.0'
7
- spec.authors = ['MahithaB, VasukiN']
8
- spec.email = ['60710901+MahithaB@users.noreply.github.com']
6
+ spec.version = '0.1.2'
7
+ spec.authors = ['MahithaB, VasukiN, GiriR']
8
+ spec.email = ['cpe-support@jfrog.com']
9
9
 
10
- spec.summary = %q{Fluentd Plugin for converting one metrics form of data to another, this is from Prometheus format to Splunk HEC required format}
11
- spec.description = %q{Fluentd Plugin for converting one metrics form of data to another, this is from Prometheus format to Splunk HEC required format}
10
+ spec.summary = %q{Fluentd Plugin for converting JFrog Artifactory, Xray generated metrics (Prometheus Exposition Format) to target observability platform format (Splunk HEC)}
11
+ spec.description = %q{Fluentd Plugin for converting JFrog Artifactory, Xray generated metrics (Prometheus Exposition Format) to target observability platform format (Splunk HEC)}
12
12
  spec.homepage = 'https://github.com/jfrog/jfrog-fluentd-plugins/tree/main/fluent-plugin-jfrog-metrics'
13
13
  spec.license = 'Apache-2.0'
14
14
 
@@ -32,8 +32,10 @@ module Fluent
32
32
  config_param :jpd_url, :string, default: ''
33
33
  config_param :username, :string, default: ''
34
34
  config_param :apikey, :string, default: ''
35
+ config_param :token, :string, default: ''
35
36
  config_param :interval, :time, default: 10
36
37
  config_param :metric_prefix, :string, default: ''
38
+ config_param :common_jpd, :bool, default: false
37
39
 
38
40
  # `configure` is called before `start`.
39
41
  # 'conf' is a `Hash` that includes the configuration parameters.
@@ -42,11 +44,11 @@ module Fluent
42
44
  super
43
45
  raise Fluent::ConfigError, 'Must define the tag for metrics data.' if @tag == ''
44
46
 
45
- raise Fluent::ConfigError, 'Must define the jpd_url to scrape metrics' if @jpd_url == ''
47
+ raise Fluent::ConfigError, 'Must define the jpd_url to scrape metrics.' if @jpd_url == ''
46
48
 
47
- raise Fluent::ConfigError, 'Must define the username for authentication' if @username == ''
49
+ raise Fluent::ConfigError, 'Must define the username for authentication.' if @username == ''
48
50
 
49
- raise Fluent::ConfigError, 'Must define the apikey to use for authentication.' if @apikey == ''
51
+ raise Fluent::ConfigError, 'Must define the apikey or token for authentication.' if @token == '' && @apikey == ''
50
52
 
51
53
  raise Fluent::ConfigError, 'Must define the interval to use for gathering the metrics.' if @interval == ''
52
54
 
@@ -77,8 +79,12 @@ module Fluent
77
79
 
78
80
  def do_execute
79
81
  puts('Executing metrics collection')
80
- metrics_helper = MetricsHelper.new(@metric_prefix, @jpd_url, @username, @apikey)
82
+ metrics_helper = MetricsHelper.new(@metric_prefix, @jpd_url, @username, @apikey, @token, @common_jpd)
81
83
  platform_metrics = metrics_helper.get_metrics
84
+ additional_metrics = metrics_helper.get_additional_metrics
85
+ if !additional_metrics.nil? && additional_metrics != ''
86
+ platform_metrics += additional_metrics.to_s
87
+ end
82
88
  parser = MetricsParser.new(@metric_prefix, router, @tag)
83
89
  parser.emit_parsed_metrics(platform_metrics)
84
90
  end
@@ -1,12 +1,17 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'rest-client'
3
4
 
4
5
  class MetricsHelper
5
- def initialize(metric_prefix, jpd_url, username, apikey)
6
+ @@obs_endpoint_exists = false
7
+
8
+ def initialize(metric_prefix, jpd_url, username, apikey, token, common_jpd)
6
9
  @metric_prefix = metric_prefix
7
10
  @jpd_url = jpd_url
8
11
  @username = username
9
12
  @apikey = apikey
13
+ @token = token
14
+ @common_jpd = common_jpd
10
15
  end
11
16
 
12
17
  def get_metrics
@@ -19,22 +24,62 @@ class MetricsHelper
19
24
  else
20
25
  "#{@jpd_url}/artifactory/api/v1/metrics"
21
26
  end
22
- execute_rest_call(url, @username, @apikey)
27
+ if !@token.nil? && @token != ''
28
+ execute_rest_call(url, @username, nil, @token, false, true)
29
+ elsif !@apikey.nil? && @apikey != ''
30
+ execute_rest_call(url, @username, @apikey, nil, false, false)
31
+ end
32
+
33
+ end
34
+
35
+ def get_additional_metrics
36
+ if (@metric_prefix == 'jfrog.artifactory' || @common_jpd == false) && !@token.nil? && @token != ''
37
+ puts 'Executing additional metrics collection'
38
+ url = "#{@jpd_url}/observability/api/v1/metrics"
39
+ check_endpoint(url, @token) if @@obs_endpoint_exists == nil? || !@@obs_endpoint_exists
40
+ execute_rest_call(url, @username, nil, @token, true, true) if @@obs_endpoint_exists
41
+ end
23
42
  end
24
43
 
25
- def execute_rest_call(url, user, password)
44
+ def check_endpoint(url, token)
26
45
  response = RestClient::Request.new(
27
46
  method: :get,
28
47
  url: url,
29
- user: user,
30
- password: password
48
+ headers: { Authorization: "Bearer #{token}" }
31
49
  ).execute do |response, request, result|
50
+ @@obs_endpoint_exists = true if response.code == 200
51
+ puts "#{url} exists? -> #{@@obs_endpoint_exists}, storing the result for next executions"
52
+ end
53
+ end
54
+
55
+ def execute_rest_call(url, user, password, token, ignore_exception, use_token)
56
+ request = if use_token == true
57
+ RestClient::Request.new(
58
+ method: :get,
59
+ url: url,
60
+ headers: { Authorization: "Bearer #{token}" }
61
+ )
62
+ else
63
+ RestClient::Request.new(
64
+ method: :get,
65
+ url: url,
66
+ user: user,
67
+ password: password
68
+ )
69
+ end
70
+
71
+ request.execute do |response, request, result|
32
72
  case response.code
33
73
  when 200
34
74
  return response.body
35
75
  else
36
- raise Fluent::ConfigError, 'Cannot fetch #{@metric_prefix} metrics'
76
+ if ignore_exception == true
77
+ return ''
78
+ else
79
+ raise Fluent::ConfigError, 'Cannot fetch #{@metric_prefix} metrics'
80
+ end
37
81
  end
38
82
  end
39
83
  end
84
+
40
85
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-jfrog-metrics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
- - MahithaB, VasukiN
8
- autorequire:
7
+ - MahithaB, VasukiN, GiriR
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-14 00:00:00.000000000 Z
11
+ date: 2022-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,10 +72,10 @@ dependencies:
72
72
  - - "<"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '2'
75
- description: Fluentd Plugin for converting one metrics form of data to another, this
76
- is from Prometheus format to Splunk HEC required format
75
+ description: Fluentd Plugin for converting JFrog Artifactory, Xray generated metrics
76
+ (Prometheus Exposition Format) to target observability platform format (Splunk HEC)
77
77
  email:
78
- - 60710901+MahithaB@users.noreply.github.com
78
+ - cpe-support@jfrog.com
79
79
  executables: []
80
80
  extensions: []
81
81
  extra_rdoc_files: []
@@ -103,7 +103,7 @@ homepage: https://github.com/jfrog/jfrog-fluentd-plugins/tree/main/fluent-plugin
103
103
  licenses:
104
104
  - Apache-2.0
105
105
  metadata: {}
106
- post_install_message:
106
+ post_install_message:
107
107
  rdoc_options: []
108
108
  require_paths:
109
109
  - lib
@@ -118,11 +118,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  - !ruby/object:Gem::Version
119
119
  version: '0'
120
120
  requirements: []
121
- rubygems_version: 3.0.3
122
- signing_key:
121
+ rubygems_version: 3.1.6
122
+ signing_key:
123
123
  specification_version: 4
124
- summary: Fluentd Plugin for converting one metrics form of data to another, this is
125
- from Prometheus format to Splunk HEC required format
124
+ summary: Fluentd Plugin for converting JFrog Artifactory, Xray generated metrics (Prometheus
125
+ Exposition Format) to target observability platform format (Splunk HEC)
126
126
  test_files:
127
127
  - spec/fixtures/files/creds.rb
128
128
  - spec/fixtures/files/sample_artifactory_metrics.txt