This commit is contained in:
Родитель
dbacc86d44
Коммит
41e9af9509
|
@ -0,0 +1,8 @@
|
|||
/.bundle/
|
||||
/.yardoc
|
||||
/_yardoc/
|
||||
/coverage/
|
||||
/doc/
|
||||
/pkg/
|
||||
/spec/reports/
|
||||
/tmp/
|
|
@ -0,0 +1,6 @@
|
|||
source "https://rubygems.org"
|
||||
|
||||
# Specify your gem's dependencies in fluent-plugin-redfish-alert.gemspec
|
||||
gemspec
|
||||
|
||||
gem "rake", "~> 12.0"
|
|
@ -1 +1,23 @@
|
|||
TODO: Create a file called LICENSE (not LICENSE.TXT, LICENSE.md, etc.)…
|
||||
# Fluent::Plugin::Redfish::Alert
|
||||
|
||||
## Installation
|
||||
|
||||
build with gem build
|
||||
$ gem build fluent-plugin-redfish-alert.gemspec
|
||||
install with gem install
|
||||
$ gem install fluent-plugin-redfish-alert.gem
|
||||
|
||||
## Usage
|
||||
TODO: ADD MOre info
|
||||
|
||||
<filter redfish.alert>
|
||||
@type process_redfishalert
|
||||
coloregion "#{ENV['COLO_REGION']}"
|
||||
username "#{ENV['REDFISH_USERNAME']}"
|
||||
passwordFile /path/to/file
|
||||
</filter>
|
||||
|
||||
## Contributing
|
||||
|
||||
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fluent-plugin-redfish-alert.
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
require "bundler/gem_tasks"
|
||||
task :default => :spec
|
|
@ -0,0 +1,19 @@
|
|||
|
||||
Gem::Specification.new do |spec|
|
||||
spec.name = "fluent-plugin-process-redfishalert"
|
||||
spec.version = "0.1.0"
|
||||
spec.authors = ["gadelamo"]
|
||||
spec.email = ["gadelamo@microsoft.com"]
|
||||
spec.summary = "a fluentd plugin to retrieve infro from an RMC using redfish"
|
||||
spec.description = spec.summary
|
||||
spec.homepage = "https://github.com/Azure/fluent-plugin-process-redfishalert"
|
||||
spec.license = "MIT"
|
||||
|
||||
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
||||
# Specify which files should be added to the gem when it is released.
|
||||
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
||||
spec.files = `git ls-files`.split("\n")
|
||||
spec.bindir = "exe"
|
||||
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
||||
spec.require_paths = ["lib"]
|
||||
end
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
require 'fluent/plugin/filter'
|
||||
require 'json'
|
||||
require 'net/http'
|
||||
|
||||
module Fluent
|
||||
class ProcessRedfishAlert < Filter
|
||||
Fluent::Plugin.register_filter('process_redfishalert', self)
|
||||
|
||||
# config_param
|
||||
config_param :coloregion, :string
|
||||
config_param :username, :string
|
||||
config_param :passwordFile, :string
|
||||
|
||||
def configure(conf)
|
||||
super
|
||||
end
|
||||
|
||||
def start
|
||||
super
|
||||
end
|
||||
|
||||
def filter(tag, time, record)
|
||||
begin
|
||||
rmcSN = getRMCSerialNumber(record["REMOTE_ADDR"])
|
||||
if tag == "redfish.alert"
|
||||
rgSN = getRackGroupSerialNumber(record["REMOTE_ADDR"])
|
||||
end
|
||||
rescue SecurityError => se
|
||||
record["error"] = "Error calling redfish API: #{se.message}"
|
||||
end
|
||||
record["machineId"] = "SDFLEX:#{coloregion}:#{rmcSN}"
|
||||
record
|
||||
end
|
||||
|
||||
def callRedfishGetAPI(host, resourceURI)
|
||||
uri = URI.parse("https://#{host}:443/redfish/v1/#{resourceURI}")
|
||||
|
||||
https = Net::HTTP.new(uri.host, uri.port)
|
||||
https.use_ssl = true
|
||||
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||
|
||||
header = {'Content-Type': 'application/json'}
|
||||
request = Net::HTTP::Get.new(uri.request_uri, header)
|
||||
request.basic_auth(username, getPassword())
|
||||
|
||||
response = https.request(request)
|
||||
|
||||
if response.code == "200"
|
||||
return JSON.parse(response.body)
|
||||
else
|
||||
raise SecurityError
|
||||
end
|
||||
end
|
||||
|
||||
def getRMCSerialNumber(host)
|
||||
res = callRedfishGetAPI(host, "Chassis/RMC")
|
||||
return res["SerialNumber"]
|
||||
end
|
||||
|
||||
def getRackGroupSerialNumber(host)
|
||||
res = callRedfishGetAPI(host, "Chassis/RackGroup")
|
||||
return res["SerialNumber"]
|
||||
end
|
||||
|
||||
def getPassword()
|
||||
File.read(passwordFile).strip
|
||||
end
|
||||
end
|
||||
end
|
Загрузка…
Ссылка в новой задаче