Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exporting command definition from check manifest? #53

Open
raiblue opened this issue Apr 21, 2015 · 1 comment
Open

Exporting command definition from check manifest? #53

raiblue opened this issue Apr 21, 2015 · 1 comment

Comments

@raiblue
Copy link

raiblue commented Apr 21, 2015

Hi,
I'm trying to add new checks. My definitions (for example that manifests/check/tcp.pp below) work good:

define nagios::check::tcp (
$ensure = undef,
$args,
) {

Required plugin

if $ensure != 'absent' {
Package <| tag == 'nagios-plugins-tcp' |>
}

nagios::client::nrpe_file { "check_tcp_${title}":
ensure => $ensure,
args => $args,
plugin => "check_tcp",
}

nagios::service { "check_tcp_${title}${::nagios::client::host_name}":
ensure => $ensure,
check_command => "check_nrpe_tcp
${title}",
service_description => "${title}",
servicegroups => $servicegroups,
check_period => $check_period,
contact_groups => $contact_groups,
first_notification_delay => $first_notification_delay,
notification_period => $notification_period,
max_check_attempts => $max_check_attempts,
use => $use,
}
}

And I call that definition like that:

nagios::check::tcp { 'sonar':
args => hiera(nagios::check::sonar::args,"-p 9002"),
}

No problem up to here: Nrpe check is created on the client side and service definition is created on the server side as expected. My problem is, I have to add the command definition to manifests/server.pp manually to get it created on server side:

nagios_command { 'check_nrpe_tcp_sonar':
command_line => "${nrpe} -c check_tcp_sonar",
}

How can I do it from check manifest (manifests/check/tcp.pp) automaticaly? I tried nagios_command and @@nagios_command but i couldn't do what I need. I need something like nagios::service. Is it also supported in module? Could somebody help?

@raiblue
Copy link
Author

raiblue commented May 6, 2015

Hi again,
I worked out this problem by creating a command.pp (like service.pp) as follows:

define nagios::command (
$ensure = undef,
$server = $nagios::client::server,
$host_name = $nagios::client::host_name,
$nrpe = "$USER1$/check_nrpe -H $HOSTADDRESS$",
$command_line,
) {

@@nagios_command { $title:
command_line => $command_line,
tag => regsubst($server,'^(.+)$','nagios-\1'),
}
}

After that, i could be able to use it in my tcp check manifest:

define nagios::check::tcp (
$ensure = undef,
$nrpe = "$USER1$/check_nrpe -H $HOSTADDRESS$",
$args,
) {

Required plugin

if $ensure != 'absent' {
Package <| tag == 'nagios-plugins-tcp' |>
}

nagios::client::nrpe_file { "check_tcp_${title}":
ensure => $ensure,
args => $args,
plugin => 'check_tcp',
}

nagios::service { "check_tcp_${title}${::nagios::client::host_name}":
ensure => $ensure,
check_command => "check_nrpe_tcp
${title}",
service_description => "${title}",
servicegroups => $servicegroups,
check_period => $check_period,
contact_groups => $contact_groups,
first_notification_delay => $first_notification_delay,
notification_period => $notification_period,
max_check_attempts => $max_check_attempts,
use => $use,
}

nagios::command { "check_nrpe_tcp_${title}":
ensure => $ensure,
command_line => "${nrpe} -c check_tcp_${title}",
}
}

And calling them as usual:

nagios::check::tcp { 'nexus':
args => hiera(nagios::check::nexus::args,"-p 8081"),
}
nagios::check::tcp { 'sonar':
args => hiera(nagios::check::sonar::args,"-p 9002"),
}

No need to write them in server.pp, my custom commands are created based on titles and exported to nagios_commands.cfg directly :)

I wonder why something like command.pp is not included in the module. It would provide convenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant