-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1d7c660
commit 2057549
Showing
5 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<source> | ||
type wlm_input | ||
tag oms.wlm.ad | ||
interval 14400s | ||
config_path /etc/opt/microsoft/omsagent/conf/omsagent.d/wlm_ad_pe_config.json | ||
source "AutoDiscover::ProcessEnumeration" | ||
data_type "WLM_LINUX_VM_METADATA_BLOB" | ||
ip "INFRASTRUCTUREINSIGHTS" | ||
</source> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"ServiceName" : "Apache HttpServer", | ||
"PossibleDaemons": ["httpd", "apache2"] | ||
}, | ||
{ | ||
"ServiceName" : "MongoDB", | ||
"PossibleDaemons" : ["mongodb", "mongod"] | ||
}, | ||
{ | ||
"ServiceName" : "Tomcat", | ||
"PossibleDaemons" : ["tomcat", "tomcat6", "tomcat7", "tomcat8"] | ||
}, | ||
{ | ||
"ServiceName" : "MySql", | ||
"PossibleDaemons" : ["mysql"] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#!/usr/local/bin/ruby | ||
|
||
module Fluent | ||
|
||
class WlmInput < Input | ||
Plugin.register_input('wlm_input', self) | ||
|
||
def initialize | ||
super | ||
require_relative 'wlm_source_lib' | ||
end | ||
|
||
config_param :source | ||
config_param :interval, :time, :default => nil | ||
config_param :tag, :string, :default => "oms.wlm.ad" | ||
config_param :config_path, :string, :default => "/etc/opt/microsoft/omsagent/conf/omsagent.d/wlm_ad_pe_config.json" | ||
config_param :data_type, :string, :default => "WLM_AUTO_DISCOVER" | ||
config_param :ip, :string, :default => "INFRASTRUCTURE_INSIGHTS" | ||
|
||
def configure (conf) | ||
super | ||
end | ||
|
||
def start | ||
# The WlmAutoDiscoverLib is a factory containing a list of strategies that | ||
begin | ||
@wlm_source_lib = WLM::WlmSourceLib.new(@source, @config_path) | ||
if @interval | ||
@finished = false | ||
@condition = ConditionVariable.new | ||
@mutex = Mutex.new | ||
@thread = Thread.new(&method(:run_periodic)) | ||
else | ||
get_emit_data | ||
end #if | ||
|
||
rescue => e | ||
$log.error "Error while configuring the data source. #{e}." | ||
end #begin | ||
|
||
end #start | ||
|
||
def shutdown | ||
if @interval | ||
@mutex.synchronize { | ||
@finished = true | ||
@condition.signal | ||
} | ||
@thread.join | ||
end | ||
end #shutdown | ||
|
||
def get_emit_data | ||
wrapper = nil | ||
time = Time.now.to_s | ||
begin | ||
wrapper = @wlm_source_lib.get_data(time, @data_type, @ip) | ||
rescue => e | ||
$log.error "Error while executing get_data. #{e}" | ||
end | ||
$log.info wrapper | ||
router.emit(@tag, time, wrapper) if wrapper | ||
end #get_emit_data | ||
|
||
def run_periodic | ||
@mutex.lock | ||
done = @finished | ||
until done | ||
@condition.wait(@mutex, @interval) | ||
done = @finished | ||
@mutex.unlock | ||
if !done | ||
get_emit_data | ||
end | ||
@mutex.lock | ||
end | ||
@mutex.unlock | ||
end #run_periodic | ||
|
||
end #WlmAutoDiscoverInput | ||
|
||
end # module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/usr/local/bin/ruby | ||
require 'open3' | ||
require 'json' | ||
require 'base64' | ||
|
||
module WLM | ||
class CommandHelper | ||
|
||
attr_reader :command | ||
attr_reader :command_name | ||
|
||
def initialize(command, command_name) | ||
@command = command | ||
@command_name = command_name | ||
@executed = false | ||
@is_success = false | ||
end #def | ||
|
||
def execute_command(params) | ||
Open3.popen3(command % params) { |stdin, stdout, stderr, wait_thr| | ||
@is_success = wait_thr.value.success? | ||
@stderr = stderr.read | ||
@stdout = stdout.read | ||
@executed = true | ||
} | ||
end #def | ||
|
||
def is_success? | ||
return @is_success if @executed | ||
raise "Command not executed" | ||
end #def | ||
end #class | ||
|
||
class SystemCtlCommandHelper < CommandHelper | ||
def initialize | ||
super("systemctl status %s", "SystemCtl") | ||
end #def | ||
end #class | ||
|
||
class PsCommandHelper < CommandHelper | ||
|
||
def initialize | ||
super("ps -ef | grep %s", "PS") | ||
end #def | ||
|
||
def is_success? | ||
if(super) | ||
if(@stdout.lines.count > 2) | ||
return true | ||
end #if | ||
end #if | ||
return false | ||
end #def | ||
|
||
end #class | ||
|
||
class WlmProcessEnumeration | ||
|
||
attr_reader :config | ||
attr_reader :commands | ||
|
||
def initialize(config, common=nil, commands=nil) | ||
require 'base64' | ||
require_relative 'oms_common' | ||
|
||
@common = common | ||
@common = OMS::Common unless @common | ||
@config = config | ||
@commands = commands | ||
@commands = [SystemCtlCommandHelper.new, PsCommandHelper.new] unless @commands | ||
@data_items = {} | ||
|
||
end #initialize | ||
|
||
def get_data(time, data_type, ip) | ||
@config.each do |service_config| | ||
execute_parse(service_config) | ||
end #each | ||
|
||
if(!@data_items.empty?) | ||
@data_items["TimeStamp"] = time | ||
@data_items["Host"] = @common.get_hostname | ||
@data_items["OSType"] = "Linux" | ||
auto_discovery_data = { | ||
"EncodedVMMetadata" => Base64.strict_encode64(@data_items.to_s) | ||
} | ||
return { | ||
"DataType" => data_type, | ||
"IPName" => ip, | ||
"DataItems"=> [auto_discovery_data] | ||
} | ||
end #if | ||
end #discover | ||
|
||
private | ||
def execute_parse(service_config) | ||
@commands.each do |command| | ||
raise "Invalid command" if !(command.is_a? CommandHelper) | ||
begin | ||
service_config["PossibleDaemons"].each do |daemon| | ||
command.execute_command(daemon) | ||
if(command.is_success?) | ||
@data_items["CommandName"] = command.command_name if @data_items["CommandName"].nil? | ||
@data_items[service_config["ServiceName"]] = "1" | ||
return | ||
end #if | ||
end #each service_config | ||
rescue => e | ||
$log.warn "Command: #{command.command_name} execution failed with Error: #{e}" | ||
end #begin | ||
end #each | ||
end #execute_parse | ||
|
||
end #class | ||
|
||
end #module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/local/bin/ruby | ||
require 'json' | ||
|
||
module WLM | ||
class WlmSourceLib | ||
|
||
attr_reader :method | ||
attr_reader :config | ||
|
||
def initialize(method, config_file_path, wli_source_lib = nil) | ||
#read the method and the config json | ||
@method = method | ||
|
||
config_file = File.read(config_file_path) | ||
@config = JSON.parse(config_file) | ||
|
||
@wli_source_lib = get_source_lib unless wli_source_lib | ||
|
||
end #initialize | ||
|
||
def get_data(time, data_type, ip) | ||
@wli_source_lib.get_data(time, data_type, ip) | ||
end | ||
|
||
private | ||
def get_source_lib | ||
wlm_source = nil | ||
case @method | ||
when "AutoDiscover::ProcessEnumeration" | ||
require_relative 'wlm_ad_pe_lib' | ||
source_lib = WLM::WlmProcessEnumeration.new(@config) | ||
else | ||
raise "Not a valid method #{@method}" | ||
end | ||
return source_lib | ||
end #get_discovery_strategy | ||
|
||
end #class | ||
end #module |