From f562e898731b16b90689c7cd5fa271d1b369ef35 Mon Sep 17 00:00:00 2001 From: Robert Frank Date: Wed, 23 Aug 2017 09:49:17 +0100 Subject: [PATCH] Allow absolute paths in nrpe plugin configurations. Add support for absolute plugin paths to generic nrpe check. Add support for absolute plugin paths to postgresql check. --- templates/nrpe-check_generic.cfg.erb | 7 ++++++- templates/plugins/check_postgres-sudoers.erb | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/templates/nrpe-check_generic.cfg.erb b/templates/nrpe-check_generic.cfg.erb index a4a0dfb8..4040ff88 100644 --- a/templates/nrpe-check_generic.cfg.erb +++ b/templates/nrpe-check_generic.cfg.erb @@ -1,2 +1,7 @@ # Configuration for <%= @title %> (from the generic template) -command[<%= @command %>]=<% if @sudo %>sudo <% if @sudo_user %>-u <%= @sudo_user %> <% end %><% end %><%= scope.lookupvar('nagios::client::plugin_dir') %>/<%= @plugin %><% if @args.to_s != '' %> <%= @args %><% end %> +<%- +require 'pathname' +plugincmd = Pathname.new(@plugin).absolute? ? @plugin : "#{scope.lookupvar('nagios::client::plugin_dir')}/#{@plugin}" +sudooption = @sudo ? ('sudo ' + (@sudo_user ? "-u #{@sudo_user} " : '')) : '' +-%> +command[<%= @command %>]=<%= sudooption %><%= plugincmd %><% if @args %> <%= @args %><% end %> diff --git a/templates/plugins/check_postgres-sudoers.erb b/templates/plugins/check_postgres-sudoers.erb index 38e32f3d..1ec7d33d 100644 --- a/templates/plugins/check_postgres-sudoers.erb +++ b/templates/plugins/check_postgres-sudoers.erb @@ -1,2 +1,6 @@ Defaults !requiretty -<%= scope['nagios::client::nrpe_user'] %> ALL = (<%= @privileged_user %>) NOPASSWD: <%= scope['nagios::client::plugin_dir'] %>/<%= @plugin %> +<%- +require 'pathname' +plugincmd = Pathname.new(@plugin).absolute? ? @plugin : "#{scope['nagios::client::plugin_dir']}/#{@plugin}" +-%> +<%= scope['nagios::client::nrpe_user'] %> ALL = (<%= @privileged_user %>) NOPASSWD: <%= plugincmd %>