Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

Commit

Permalink
Merge pull request #20 from robertvargason/plugin.nrpe.conf_dir_path
Browse files Browse the repository at this point in the history
add support for plugin.nrpe.conf_path
  • Loading branch information
ploubser committed Oct 14, 2015
2 parents 2d5d4d9 + ab15a4f commit 0aa09d2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions agent/nrpe.rb
Expand Up @@ -90,6 +90,8 @@ def self.all_command_plugins

if config.pluginconf["nrpe.conf_file"]
fnames << "#{fdir}/#{config.pluginconf['nrpe.conf_file']}"
elsif config.pluginconf["nrpe.conf_path"]
fnames |= Dir.glob(config.pluginconf["nrpe.conf_path"].split(':').map{|fdir| "#{fdir}/*.cfg"})
else
fnames |= Dir.glob("#{fdir}/*.cfg")
end
Expand Down
23 changes: 19 additions & 4 deletions spec/agent/nrpe_agent_spec.rb
Expand Up @@ -53,7 +53,7 @@

describe "#plugin_for_command" do
let(:config){mock}
let(:pluginconf){{"nrpe.conf_dir" => "/foo", "nrpe.conf_file" => "bar.cfg"}}
let(:pluginconf){{"nrpe.conf_dir" => "/foo", "nrpe.conf_file" => "bar.cfg", "nrpe.conf_path" => "/foo:/bar"}}

before :each do
config.stubs(:pluginconf).returns(pluginconf)
Expand All @@ -72,8 +72,9 @@
MCollective::Agent::Nrpe.plugin_for_command("command",["60","100"]).should == "run 60 100"
end

it "should return the command from nrpe.conf_dir if it is set and nrpe.conf_file is unset" do
it "should return the command from nrpe.conf_dir if it is set and nrpe.conf_file and nrpe.conf_path is unset" do
pluginconf["nrpe.conf_file"] = nil
pluginconf["nrpe.conf_path"] = nil
Dir.expects(:glob).with("/foo/*.cfg").returns(["/foo/baz.cfg", "/foo/bar.cfg"])
File.expects(:exist?).with("/foo/baz.cfg").returns(true)
File.expects(:readlines).with("/foo/baz.cfg").returns(["command[fake_command]=donotrun"])
Expand All @@ -82,16 +83,30 @@
MCollective::Agent::Nrpe.plugin_for_command("command", []).should == "run"
end

it "should return the command from nrpe.conf_path if it is set and nrpe.conf_file is unset" do
pluginconf["nrpe.conf_file"] = nil
Dir.expects(:glob).with(["/foo/*.cfg","/bar/*.cfg"]).returns(["/foo/baz.cfg", "/foo/bar.cfg","/bar/baz.cfg"])
File.expects(:exist?).with("/foo/baz.cfg").returns(true)
File.expects(:readlines).with("/foo/baz.cfg").returns(["command[fake_command]=donotrun"])
File.expects(:exist?).with("/foo/bar.cfg").returns(true)
File.expects(:readlines).with("/foo/bar.cfg").returns(["command[other_fake_command]=donotrun"])
File.expects(:exist?).with("/bar/baz.cfg").returns(true)
File.expects(:readlines).with("/bar/baz.cfg").returns(["command[command]=run"])
MCollective::Agent::Nrpe.plugin_for_command("command", []).should == "run"
end

it "should return the nil if no matching command is found in nrpe.conf_dir" do
pluginconf["nrpe.conf_file"] = nil
pluginconf["nrpe.conf_path"] = nil
Dir.expects(:glob).with("/foo/*.cfg").returns(["/foo/bar.cfg"])
File.expects(:exist?).with("/foo/bar.cfg").returns(true)
File.expects(:readlines).with("/foo/bar.cfg").returns(["command[fake_command]=run"])
MCollective::Agent::Nrpe.plugin_for_command("command", []).should == nil
end

it "should return the command from /etc/nagios/nrpe.d if nrpe.conf_dir is unset" do
it "should return the command from /etc/nagios/nrpe.d if nrpe.conf_dir and nrpe.conf_path is unset" do
pluginconf["nrpe.conf_dir"] = nil
pluginconf["nrpe.conf_path"] = nil
File.expects(:exist?).with("/etc/nagios/nrpe.d/bar.cfg").returns(true)
File.expects(:readlines).with("/etc/nagios/nrpe.d/bar.cfg").returns(["command[command]=run"])
MCollective::Agent::Nrpe.plugin_for_command("command", []).should == "run"
Expand Down Expand Up @@ -120,7 +135,7 @@

describe "#runallcommands" do
let(:config){mock}
let(:pluginconf){{"nrpe.conf_dir" => "/foo", "nrpe.conf_file" => "bar.cfg"}}
let(:pluginconf){{"nrpe.conf_dir" => "/foo", "nrpe.conf_file" => "bar.cfg", "nrpe.conf_path" => "/foo:/bar"}}

before :each do
config.stubs(:pluginconf).returns(pluginconf)
Expand Down

0 comments on commit 0aa09d2

Please sign in to comment.